Quorums
Overview
In leaderless replication (Dynamo-style systems such as Cassandra and Riak), any replica can accept reads and writes. How do you make sure a read sees a recent write when some replicas may have missed it? With quorums: require enough replicas to take part in each write and each read that the two groups must overlap.
N, W and R
- N: how many replicas store each key (commonly 3).
- W: how many replicas must acknowledge a write before it counts as successful.
- R: how many replicas must answer a read.
The coordinator sends each request to all N replicas and waits for W (or R) responses. Every value carries a version (a timestamp or version vector); on a read, the coordinator returns the newest version among the replies.
The overlap rule
If W + R > N, any set of W replicas and any set of R replicas share at least one replica. So at least one replica in every read has the latest acknowledged write.
With N = 3, W = 2, R = 2: two replicas have the write, any two you read include at least one of them.
Tuning
| Setting (N = 3) | Effect |
|---|---|
| W = 2, R = 2 | Balanced; tolerates 1 failure for reads and writes |
| W = 3, R = 1 | Fast reads; a single slow or failed replica blocks writes |
| W = 1, R = 3 | Fast writes; reads need all replicas |
| W = 1, R = 1 | Fastest and most available; reads may be stale (W + R ≤ N) |
Lower values reduce latency because the coordinator waits only for the fastest replies, and they keep working when more replicas are down. That’s why quorums are described as tunable consistency: Cassandra exposes levels such as ONE, QUORUM, LOCAL_QUORUM (majority within the local data centre) and ALL.
Keeping replicas in sync
Replicas that miss writes must catch up eventually:
- Read repair: when a read sees an outdated replica, the coordinator writes the newest value back to it.
- Hinted handoff: if a replica is down during a write, another node stores a “hint” and delivers the write when the replica returns. (Some systems also count these temporary holders toward W, called a sloppy quorum, which improves availability but weakens the overlap guarantee.)
- Anti-entropy: background processes compare replicas, often with Merkle trees (hash trees that quickly find which ranges differ), and copy missing data.
Limits of quorums
W + R > N gives a strong overlap, but not full linearizability:
- concurrent writes to the same key can both succeed on different replicas; resolving them by timestamp (last write wins) can drop one, especially with clock skew,
- a write that failed (fewer than W acks) may still have reached some replicas and later “appear”,
- sloppy quorums can break the overlap during failures.
For operations that need a single winner, such as claiming a username or decrementing stock, use a leader-based or consensus-backed store, or conditional writes (compare-and-set) if the database supports them.
Majorities everywhere
The same majority idea appears in leader-based systems: Raft and Paxos commit an entry once a majority of nodes have it, and a new leader needs votes from a majority. Because any two majorities overlap, the new leader always knows about every committed entry. That’s why clusters run with an odd number of nodes (3 or 5): 5 nodes tolerate 2 failures; 6 nodes still tolerate only 2.
In an interview
For a Dynamo-style store: “Replication factor 3 across three zones; writes and reads at QUORUM, so W + R > N and we tolerate one replica down. For the high-volume, staleness-tolerant counters we use ONE.” Then mention read repair and anti-entropy if asked how replicas converge.
Recap
Quorums use N replicas, W write acknowledgements and R read replies; when W + R > N, reads overlap the latest write. Smaller W and R trade consistency for speed and availability. Read repair, hinted handoff and anti-entropy keep replicas converging. Quorums don’t resolve concurrent writes on their own, so use consensus or conditional writes where one winner is required.
Tune the quorum
A key-value store keeps N = 5 replicas of every key. (a) Which (W, R) settings guarantee that every read overlaps the latest successful write? Give two examples. (b) For a write-heavy metrics workload where occasional stale reads are fine, what would you choose? (c) For user balances, what would you choose, and how many replica failures can reads and writes each tolerate? (d) Why can a quorum system still return stale data in practice?
(a)
(b)
(c)
(d)(a) Any W + R > N, i.e. W + R >= 6: e.g. W=3, R=3 (balanced) or W=5, R=1
(fast reads, slow and fragile writes) or W=1, R=5.
(b) W=1 or 2, R=1: writes and reads are fast and survive several failures; W + R <= N,
so reads may be stale for a moment, which metrics tolerate.
(c) W=3, R=3 (majority both ways). Writes tolerate 2 failed replicas (need 3 of 5);
reads tolerate 2 failed replicas too. For real money movement you'd also want
a single serialisation point (leader/consensus) or conditional writes, because
quorums alone don't prevent two concurrent writers from conflicting.
(d) Sloppy quorums/hinted handoff can write to nodes outside the key's usual replica
set; a write that failed overall may still have reached some replicas; concurrent
writes resolved by last-write-wins with skewed clocks; and replicas that come back
after failure may be stale until read repair or anti-entropy fixes them.Summary
- N is the number of replicas, W the acknowledgements a write needs, R the replies a read needs.
- If W + R > N, every read set overlaps every write set, so a read sees the latest acknowledged write.
- Majority quorums (W = R = ⌊N/2⌋ + 1) tolerate a minority of failed replicas for both reads and writes.
- Smaller W or R means lower latency and more availability, at the cost of possibly stale reads.
- Read repair, hinted handoff and anti-entropy keep leaderless replicas converging.