Sub topic 8
Tunable consistency with read and write quorums
This chapter assumes you know how a key's replica set is chosen (the preference list from the hash ring) and the basics of consistency trade-offs. It covers how a leaderless store lets each request choose how many replicas must respond.
The three numbers
Each key is stored on N replicas. Two more settings control each request:
- N is the replication factor, the number of replicas holding the key.
- W is how many replicas must acknowledge a write before the coordinator reports success.
- R is how many replicas must answer a read before the coordinator returns a result.
The coordinator still sends every write to all N replicas. W only decides how many acknowledgments it waits for. The rest of the replicas catch up in the background.
Why R + W > N matters
If R + W > N, any set of R replicas and any set of W replicas must share at least one node. A read therefore reaches at least one replica that saw the latest successful write. The coordinator compares versions among the responses and returns the newest.
def is_overlapping_quorum(n: int, r: int, w: int) -> bool:
"""True when every read quorum must intersect every write quorum."""
return r + w > n
print(is_overlapping_quorum(3, 2, 2)) # True
print(is_overlapping_quorum(3, 1, 1)) # FalseCommon configurations
| N | W | R | Behavior |
|---|---|---|---|
| 3 | 2 | 2 | Balanced. Tolerates one slow or failed replica for both reads and writes. |
| 3 | 3 | 1 | Fast reads. Writes fail if any replica is down. |
| 3 | 1 | 3 | Fast writes. Reads fail if any replica is down. |
| 3 | 1 | 1 | Lowest latency and highest availability. Reads can be stale. |
Raising W or R increases latency, because the request waits for slower replicas, and reduces availability, because more replicas must be reachable. Lowering them does the opposite. This is the latency and availability side of the PACELC trade-off, exposed as a per-request knob.
Common errors
- Assuming overlap means linearizability. Overlap only guarantees that a read contacts a replica holding the latest completed write. It does not cover a write still in progress, concurrent writes, or clock-based conflict resolution. A read that overlaps a partial write can return the new value, and a later read can return the old one.
- Forgetting sloppy quorums. With hinted handoff, the W acknowledgments may come from stand-in nodes outside the preference list. The overlap guarantee then no longer holds until hints are delivered.
- Counting failed writes as absent. If a write reaches fewer than W replicas, the client sees an error. The write may still exist on some replicas and surface in later reads. Treat a failed write as having an unknown outcome.
- Ignoring version comparison. Overlap only gets the latest value into the read set. The coordinator still needs vector clocks to pick the newest one, or to return siblings when versions are concurrent.
Choosing values
Start from the workload. A shopping cart that must always accept writes suits W=1 or W=2. A read-heavy catalog suits R=1 with W=N. When you tune per request, expose R and W in the client API so callers can choose for each operation.
Exercise
A store has N=5. A team sets W=3 and R=2. Does every read quorum intersect every write quorum? If not, what is the smallest R that fixes it with W=3?
Show answer
No. R + W = 5, which is not greater than N=5, so a read can contact only the two replicas that missed the write. With W=3, the smallest R that works is 3, since 3 + 3 = 6 > 5.
Exercise
With N=3, W=2, R=2, one replica is down. Can the store still serve reads and writes? What happens if two replicas are down?
Show answer
With one replica down, two remain, which satisfies both W=2 and R=2, so reads and writes succeed. With two down, only one replica remains, so both reads and writes fail unless a sloppy quorum accepts stand-in nodes.