
Replication improves availability, but a client needs a rule for how many replicas must acknowledge a write or answer a read. Quorum reads and writes use overlapping replica sets so a read can discover a recent write without contacting every node. Continue from consistency models, CAP theorem, and database replication.
Table of Contents
Open Table of Contents
The N, R, W Model
Let N be replicas for a key, W the acknowledgements required for a write, and R the replicas queried for a read. If R + W > N, the read and write sets overlap in a failure-free model. For N = 3, W = 2, and R = 2, at least one read replica should contain the write.
flowchart TD
A[Client write] --> B[Replica 1]
A --> C[Replica 2]
A --> D[Replica 3]
B --> E{W acknowledgements}
C --> E
E --> F[Write succeeds]
G[Read R replicas] --> B
G --> C
B --> H[Compare versions]
C --> H
Quorum is not automatically linearizability. Concurrent writes may have conflicting versions, clocks can be wrong, and a read may return before repair completes. Define whether versions use a leader sequence, logical timestamp, vector clock, or application merge function.
Overlap and Consistency
Larger W favors durable writes and smaller R favors low-latency reads; the reverse favors read freshness. A “majority” quorum is a policy, not a universal number. Membership changes, hinted handoff, and sloppy quorum can change which nodes acknowledge a request.
If a read sees two versions, return the deterministic winner only when that is safe. For user profiles, last-write-wins may be acceptable; for shopping-cart items, merge operations or preserve both updates. Read repair writes the fresher version back to stale replicas, while anti-entropy repairs replicas that are never read.
Failures and Repair
When a replica is down, hinted handoff stores its write on a temporary node. The hint must have an expiry and be replayed after the target returns. If quorum cannot be reached, fail the operation or use a clearly documented degraded mode; silently lowering W changes the durability contract.
Track replica divergence, quorum failures, repair backlog, and stale-read rate. During a rolling membership change, calculate quorums against the active topology and test the transition; otherwise a mathematically valid old quorum can overlap with no current replica.
Choosing Quorum Sizes
For a write-heavy counter, W=1, R=N can reduce write latency but puts more work on reads and repair. For a read-heavy catalog, W=2, R=1 may be a good availability trade-off if stale catalog data is acceptable. For balances and ownership, prefer a leader or linearizable store instead of relying on eventual quorum reads.
Interview Questions
1. Why does R + W > N matter?
It guarantees an overlapping replica between a read set and a write set when all sets come from the same membership view. That overlap lets the reader observe the write’s version. It does not resolve concurrent conflicts or protect against topology changes by itself.
2. What is a sloppy quorum?
It allows healthy non-preferred nodes to acknowledge when the natural replica set is unavailable. This improves availability but weakens locality and can increase recovery work. Hinted handoff later moves the data to the intended replicas.
3. How does read repair work?
The coordinator compares versions returned by the read replicas and asynchronously writes the newest or merged value to stale replicas. It reduces divergence on hot keys. Anti-entropy remains necessary for cold keys that are rarely read.
4. Can quorum guarantee strong consistency?
Only with additional assumptions such as a single ordering authority, strict membership, and appropriate read/write coordination. Eventual stores often use quorum for probabilistic freshness while allowing concurrent versions. State the exact read guarantee rather than calling every quorum system strongly consistent.
5. What happens during a network partition?
The system chooses whether to reject requests that cannot reach quorum or accept them on an incomplete set. Rejecting protects the configured consistency/durability promise; accepting requires reconciliation and can create conflicts. This is a concrete CAP trade-off.
Conclusion
Quorum math is a starting point: N, R, and W describe overlap, while versions, membership, and repair determine correctness in production. Choose sizes from the business’s stale-read and write-latency tolerance, and monitor divergence and repair rather than assuming quorum is magic.
References
YouTube Videos
- “Quorum Reads and Writes in Distributed Systems” - Hussein Nasser [https://www.youtube.com/watch?v=Ibf7wKf8MqU]