Skip to content
SD-12 · Back to the write-up

Design a Key-Value Store

Hash keys onto a ring of virtual nodes, keep 3 copies in 3 zones, answer after 2 of them agree, and repair the third in the background.

Follow a request

Clients
Coordination
Storage, 3 zones
Background
Client serviceClient library
CoordinatorStateless, many
MembershipGossip + ring
Replica AZone a node
Replica BZone b node
Replica CZone c node
Anti-entropyMerkle trees
SnapshotsObject storage
1client → coord · GET cart:42A service reads the cart at the default quorum.1 / 7

The numbers, at a glance

For every write……there are 4 reads
1 write ≈ 200,000/s at peak4 reads ≈ 800,000/s
Replication multiplies workOperations per second at peak
Each node owns a sliver1 of 60 nodes, 256 tokens each
So when it dies, 59 others each take about 1/59 of its load.

A quorum write, in order

N = 3, W = 2. The coordinator answers after 2 acks; the third replica finishes in the background.

Client
Coordinator
Replica A
Replica B
Replica C
1 PUT key + context
2 write v6
3 write v6
4 write v6
5 ack (log synced)
6 ack (log synced)
7 204 + new context
8 late ack
RequestResponseAsync, does not block

Who accepts a write

The decision this question is really about.

Leader per range
Strong, pauses
PUT
leader in zone a
followers b, c
leader dies → 5 s pause
+ Linearizable; no conflicts.− Writes pause on failover; one zone takes every write.
Chain
Slow tail
PUT
headmiddletail
one slow link = slow writes
+ Strong; simple reads.− 3 hops per write; a slow node slows all.
Leaderless quorum
Our pick
PUT
ABC (late)
ack after W = 2
+ Any 2 of 3 answer; no failover.− Versions, siblings and repair needed.

How it grows

Add a box only when a number forces you to. Highlighted boxes are new at each stage.

Stage 1 · ≈ 20,000 ops/sMake it work
Client
Single node
One node: commit log, memtable, SSTables.
Stage 2 · ≈ 1,000,000 ops/s, 1 copySplit the keys
Client
CoordinatorsGossip membership
Storage nodes × 20
Consistent hashing with 256 virtual nodes over 20 nodes.
Stage 3 · ≈ 1,000,000 ops/s, 3 copiesReplicate
Client
CoordinatorsGossip membership
Zone a × 20Zone b × 20Zone c × 20
N = 3 across zones, R = 2, W = 2, hinted handoff.
Stage 4 · 1M ops/s, kept correctKeep it correct
Client
CoordinatorsGossip membership
Zone aZone bZone c
Anti-entropySnapshotsMonitoring
Merkle repair, snapshots and monitoring.
Was this walkthrough useful?Your vote tells us what to improve next.