Tunable consistency and quorums
Mathematical quorum overlap ($R + W > N$), replication factor, and anti-entropy repair.
What you will learn
- Describe a masterless, Dynamo-style store and its , and settings.
- Choose and for fast reads, fast writes or availability, with .
- Explain how replicas are repaired and how conflicting writes are resolved.
Masterless distributed architecture (Dynamo model)
In Dynamo-style systems (Amazon's Dynamo, and Cassandra and Riak, which borrow its techniques), there is no single primary. Nodes are peers on a consistent-hashing ring, and any node can coordinate a read or write for any key.
To trade latency, durability and consistency against each other, these systems expose tunable quorum parameters:
- (replication factor): How many nodes store a copy of each item.
- (write quorum): How many replicas must acknowledge a write before it succeeds.
- (read quorum): How many replicas must answer a read.
Each operation waits for its or fastest replicas, so its latency is set by the slowest of those. Cassandra exposes the same idea as consistency levels: ONE, QUORUM (a majority, of the replicas) and ALL.
The quorum condition:
If
then by the pigeonhole principle any replicas you read include at least one of the that acknowledged the latest write, so a read normally sees that write. Vogels calls this strong consistency, but it is not linearizability: Abadi notes that Dynamo-style systems fall short of full consistency even when (concurrent writes and sloppy quorums, below, are two reasons).
Common configurations with
| Strategy | Read and write sets overlap? | Writes survive | Reads survive | ||
|---|---|---|---|---|---|
| Quorum | 2 | 2 | Yes () | 1 node down | 1 node down |
| Fast writes | 1 | 3 | Yes () | 2 nodes down | No node down |
| Fast reads | 3 | 1 | Yes () | No node down | 2 nodes down |
| Highly available | 1 | 1 | No (): stale reads possible | 2 nodes down | 2 nodes down |
Conflict resolution and repair
Replicas drift apart (a write missed a replica, a node was down), so these systems repair them:
- Read repair: During a read, replicas that return stale data are updated with the newer value, repairing them at a convenient moment instead of waiting for background repair.
- Hinted handoff: If a replica is temporarily unreachable, the write goes to another node along with a "hint"; when the replica returns, the hint is replayed to it. Dynamo combines this with a sloppy quorum: writes go to the first healthy nodes on the ring, which keeps writes available during failures but means the quorum is not always the "home" replicas.
- Anti-entropy with Merkle trees: Replicas build hash trees over their key ranges, where each leaf is a hash of a key's value, and compare them; only the branches whose hashes differ need to be synchronized.
- Last-write-wins vs vector clocks: Cassandra resolves conflicting updates by timestamp (last write wins), so it asks operators to keep clocks synchronized with NTP; clock skew can make the "wrong" write win. Dynamo instead tracks causality with vector clocks and keeps concurrent versions for the application to merge.
Tunable quorum consistency (R + W > N)
Because R + W (4) > N (3), any 2 replicas you read include at least one of the 2 that acknowledged the latest write (the pigeonhole principle), so reads normally see it. It is not a guarantee of linearizability: concurrent writes and failures can still produce surprises.
Key takeaways
- Every operation waits for its or fastest replicas; with a read normally sees the latest write, though this is still not linearizability.
- Raising makes writes slower and less available; raising does the same to reads; is the most available and can read stale data.
- Read repair, hinted handoff (with a sloppy quorum) and Merkle-tree anti-entropy bring replicas back in line.
- Last-write-wins depends on synchronized clocks; vector clocks keep concurrent versions for the application to merge.
Sources
- System Design Primer: Consistency patterns
- DeCandia et al., "Dynamo: Amazon's Highly Available Key-value Store" (SOSP 2007)
- Apache Cassandra documentation: Dynamo (replication, consistency levels, repair)
- Werner Vogels, "Eventually Consistent - Revisited" (2008)
- Daniel Abadi, "Consistency Tradeoffs in Modern Distributed Database System Design" (2012)
Adapted from The System Design Primer by Donne Martin, licensed under CC BY 4.0. Changes were made.