Sub topic 8
Quorums: tuning N, R and W
This chapter assumes you know what replication is, can read simple Python, and have met linearizability and eventual consistency in earlier chapters. It covers how quorum reads and writes trade consistency against latency and availability.
The three numbers
A quorum system replicates each key on N nodes. Two parameters control how many nodes must respond:
- N is the number of replicas that store each key.
- W is the number of replicas that must acknowledge a write before it counts as successful.
- R is the number of replicas the client must hear from before a read returns.
The coordinator sends each operation to all N replicas. It waits for only W acknowledgements on a write, or R responses on a read. The remaining replicas catch up later.
The overlap condition
If R + W > N, every read set shares at least one replica with the most recent successful write set. The read therefore contacts at least one node that holds the latest acknowledged write.
def quorums_overlap(n, r, w):
"""True if every read quorum must intersect every write quorum."""
return r + w > n
print(quorums_overlap(3, 2, 2)) # True
print(quorums_overlap(3, 1, 1)) # FalseWith N=3, W=2 and R=2, a write reaches at least two nodes and a read asks at least two. Any two groups of two out of three must share a node.
The read sees x=1 from replica 2 and x=0 from replica 3. The coordinator must pick the newer value, so each value carries a version number or timestamp.
Tuning the trade-off
| N | R | W | Behavior |
|---|---|---|---|
| 3 | 2 | 2 | Balanced. Overlap holds. Tolerates one slow or failed node for both reads and writes. |
| 3 | 1 | 3 | Fast reads. Writes fail if any replica is down. |
| 3 | 3 | 1 | Fast writes. Reads fail if any replica is down. |
| 3 | 1 | 1 | No overlap. Fastest, but reads can be stale (eventual consistency). |
Raising R or W improves the chance of reading fresh data but raises latency, because the operation waits for slower replicas. It also lowers availability, because more nodes must be reachable.
Limits of the overlap rule
R + W > N does not give you linearizability by itself. Common failure modes include:
- Sloppy quorums. If some replicas are unreachable, a system may write to other nodes temporarily (hinted handoff). The W nodes then need not be among the N home replicas, so the overlap guarantee no longer holds.
- Failed writes. A write that reaches fewer than W nodes returns an error, but the value may remain on some replicas. Later reads may or may not return it.
- Concurrent writes. Two writes to the same key can reach replicas in different orders. Without versioning or conflict resolution, replicas can disagree.
- Read-then-write races. A read that overlaps an in-progress write can return either value. A later read can then return the older one, which violates linearizability.
- Clock-based ordering. If "newest" is decided by wall-clock timestamps, clock skew can make an older write win.
Systems that need linearizable behavior typically add read repair with careful versioning, or use consensus (covered in a later chapter).
Exercise
A store uses N=5 and W=3. What is the smallest R that guarantees read and write quorums overlap? If two replicas are down, can writes and reads still succeed with that R?
Show answer
R + W > N requires R > 2, so R=3. With two replicas down, three remain, which is enough for both W=3 and R=3, so both operations still succeed. If a third replica fails, both writes and reads become unavailable.