WEBBOOK CHAPTER

MongoDB 8.2, 입문에서 시니어까지: 36장. Shard Key 설계 리뷰

36장. Shard Key 설계 리뷰

월 3천만 order, 상위 0.1% 고객이 35% traffic, 최근 주문 조회·idempotency lookup·시간 분석 요구를 가정한다. 후보 key별 cardinality, frequency, monotonicity, targeted query 비율, write distribution, zone 요구를 표로 비교한다.

hashed customerId는 write 분산에 유리하지만 customer range 정렬과 zone 요구에 제약이 있다. {customerId:1,createdAt:1}는 고객 단위 locality를 주지만 celebrity customer hotspot을 만들 수 있다. 업무 key unique 제약이 shard key prefix와 어떻게 어울리는지 확인한다.

sharding 승인 전 단일 replica set의 CPU, storage, working set, throughput, initial sync, maintenance window 한계가 실측됐는지 본다. resharding이 가능해도 data movement, oplog, disk, application 영향을 런북에 넣는다.