- key-value: Disk IO를 사용하는게 아니라 cache(RAM)를 사용하여 performance을 높임
- Relational: ACID, normalization의 특성때문에 accuracy가 높음 (use case: 금융 거래)
- Graph: relationship 때문에 관계에만 집중적인 저장 방식 (use cases: 비행기 노선,
SNS 친구 관계, 추천 서비스)
- Document: 데이터 구조가 변경돼도 에러 없이 잘 되기 때문에 분산 처리 가능
However, 일관성(Consistency)는 상대적으로 부족함 (use cases: 실시간 채팅, 온라인 게임)
- Column-family: table-row마다 column이 달라도 상관 없기 때문에 중복이 가능하며 분산/복제 처리 가능
정확성&일관성 중요 -> 2, 4
정확성은 부족해도 입출력이 많다 -> 4
- Two-phase commit: 분산 DB에서 트랜잭션을 처리하기 위한 방법
- two-phase commit (Coordinator), Saga pattern, (if shared DB) queryRunner, Message Queue
- Concurrency
- problem: Race conditions(conflicts, deadlock)
- solution
- optimistic lock: 테이블 컬럼 or 해시코드 or 타임스탬프를 이용하여 conflict를 예방. (pros: performance, cons: manual rollback)
- pessimistic lock: 트랜잭션 단위로 locking하여 conflict를 예방. (pros: auto-rollback, cons: peroformance)
- 조회 성능
- 인덱스: 서비스 중 조회가 많이 될 것 같고 중복 튜플이 적은(=컬럼 카디날리티가 높은) column을 선택.
- the number of unique values in a column of a database table
1. Relational DataBase
RDB
- NoSQL
- 비정형 데이터를 처리하는 비관계형 DB
- 종류
- key-value: Memcached, Redis
- wide columnar: Hbase, Cassandra
- document: MongoDB
- graph: Neo4j
- 특징
- 데이터 간 관계를 정의하지 않음 → JOIN X
- 페타바이트급 대용량 데이터 저장
- scale-out: 분산 DB
- 테이블 스키마가 유동적