Key-Value Store: Replication
Quorum reads and writes.
Each key is stored on three nodes. When we write, must all three confirm? When we read, must we ask all three? A quorum lets us choose.

- Three copies of each key
- Wait for all?
- A quorum
N, W and R
Three numbers describe a quorum. N is the number of copies, here three. W is how many must confirm a write. R is how many we read from. If W plus R is greater than N, every read overlaps with the latest write on at least one node, so reads see the newest value.
| key | value |
|---|---|
| N | copies, e.g. 3 |
| W | must confirm a write |
| R | nodes we read from |
| W + R > N | reads see the latest |
Why the overlap works
Let's check it. Three replicas. A write with W equals two updates only two of them, leaving one stale. A read with R equals two asks two replicas, and keeps the newest version. Run it. Whichever pair we read from, at least one is fresh, so we always get version two.
from itertools import combinations
replicas = {"n1": (1, "old"), "n2": (1, "old"), "n3": (1, "old")}
for node in ["n1", "n2"]: # W = 2
replicas[node] = (2, "new")
for pair in combinations(replicas, 2): # R = 2
newest = max(replicas[n] for n in pair)
print(pair, "->", newest)('n1', 'n2') -> (2, 'new')
('n1', 'n3') -> (2, 'new')
('n2', 'n3') -> (2, 'new')Tuning the quorum
Different settings suit different needs. W equals three and R equals one makes reads fast, but writes fail if any node is down. W equals one and R equals three does the opposite. W equals two and R equals two is the common balance. And W plus R less than or equal to N is fastest, but reads may be stale.
| Setting | Behaviour |
|---|---|
| W=3, R=1 | fast reads, fragile writes |
| W=1, R=3 | fast writes, slow reads |
| W=2, R=2 | balanced, consistent |
| W+R ≤ N | fastest, may be stale |
Summary
Quorums let a key value store tune consistency. When W plus R is greater than N, reads always overlap the latest write. Next, the patterns that kept coming back in every case study.
Key takeaways- N copies
- W + R > N
- Tune per use