Skip to content
BytePatterns

Design a Key-Value Store

System Design Cases: lesson 16 of 20

Three copies, two acks, two reads — the sets have to overlap.

Lesson 16 of 20 · 7 min

Design a Key-Value Store

Step 1 of 11

The key is hashed to a partition, and that partition lives on three machines, not one.

The Idea

Store a value on three machines and still answer correctly while one of them is unreachable. Keys are hashed into partitions, each partition is replicated, and a quorum decides what counts as done.

Real-World Example

Three copies of the same register kept in three offices. Reading two of them is safe as long as every change also reached two, because then no pair of offices can both be out of date.

N = 3 replicas    W = 2 acks    R = 2 reads
put(k, v): send to 3, return once 2 acknowledge
get(k):    read 2, take the higher version,
           repair the stale replica in the background

The Tradeoff

Raising W buys durability and costs write availability; lowering it makes writes cheap and hands you two versions to reconcile later. Quorum is a dial between those, not an escape from them.

Your turn

Put the steps in the right order.

  1. Return the higher version to the caller
  2. Hash the key to its partition and find the three replicas
  3. Repair the stale replica in the background
  4. Read from two replicas and compare their versions

Mini quiz

1 / 3

R + W > N guarantees that:

New lessons land every few weeks

Leave an address and we will tell you when the next one is up. That is the only reason we will use it.

One address, stored so we can email you. Nothing else, ever.