Read and write quorum simulator
In leaderless databases such as Cassandra and Dynamo, a write is stored on several replicas and counts as done once W of them confirm it, and a read asks R of them. Choose N, R and W, send writes and reads, take replicas down, and see which settings let a read come back with old data.
Last acknowledged write: version 0. 3 of 3 replicas up. Replicas shaded darker are behind it.
- Quorums overlap (R + W > N)
- yes
- Read sets that miss version 0
- 0 of 3
- Reads, stale
- 0, 0
- Operations refused
- 0
- –Writes, reads and repairs are listed here, with the replicas each one reached.
How to use the simulator
Each card is a replica, showing the version and value it stores. A write goes to every replica that is up; the first W to store it make it succeed, and the copies to the others stay in flight until you deliver them. A read asks R replicas at random and returns the highest version it sees. The side panel counts, from the current state, how many of the possible read sets would miss the last acknowledged write.
- Set R = 1 and W = 1, write, and read a few times without delivering the copies: some reads return the old value.
- Set R = 2 and W = 2 with three replicas: no read set misses the write, whichever replicas the write reached first.
- Take a replica down and write: it misses the write and stays behind after it comes back until a read repair or anti-entropy fixes it.
- Send a write that fails part-way and read repeatedly with read repair off: the reads flip between the old value and the one the client was told had failed.
What is a quorum?
A quorum is the number of replicas that must take part in an operation for it to count. In leaderless replication each item is stored on N replicas; a client, or a coordinator node acting for it, sends every write to all of them and treats it as successful once W confirm it, and sends a read to R of them and keeps the newest answer. No replica is in charge, so any of them can accept writes, and a few can be slow or down without stopping the system.
R and W trade against each other. A small W makes writes fast and available; a small R does the same for reads. How small they can be before reads start returning old data depends on N.
Why R + W > N works
If R + W > N, a read set and a write set cannot be disjoint: together they would need more than N distinct replicas. So every read reaches at least one replica that stored the last successful write, and choosing the highest version returns it. If R + W ≤ N, there is a read set that misses it entirely. The model was checked by trying every pair of subsets for N up to 7.
Settings and what they cost, for replicas that are each up 99% of the time, independently. "Stale" is the chance that a read issued just after a write was acknowledged, before any further copies arrive, misses it; it equals C(N − W, R) / C(N, R), and the simulated column comes from running the model:
| N | R | W | Overlap | Stale (exact) | Stale (simulated) | Reads unavailable | Writes unavailable |
|---|---|---|---|---|---|---|---|
| 3 | 1 | 1 | no | 66.7% | 66.5% | under 0.0001% | under 0.0001% |
| 3 | 1 | 3 | yes | 0.0% | 0.0% | under 0.0001% | 2.9701% |
| 3 | 3 | 1 | yes | 0.0% | 0.0% | 2.9701% | under 0.0001% |
| 3 | 2 | 2 | yes | 0.0% | 0.0% | 0.0298% | 0.0298% |
| 5 | 1 | 1 | no | 80.0% | 80.0% | under 0.0001% | under 0.0001% |
| 5 | 2 | 2 | no | 30.0% | 30.2% | under 0.0001% | under 0.0001% |
| 5 | 3 | 3 | yes | 0.0% | 0.0% | 0.0010% | 0.0010% |
| 5 | 2 | 4 | yes | 0.0% | 0.0% | under 0.0001% | 0.0980% |
R = 1 with W = N makes reads cheap but lets one failed replica block every write; R = N with W = 1 does the opposite. A majority on both sides, such as 2 and 2 of 3, tolerates one failure for reads and writes alike, with each unavailable only 0.0298% of the time here.
How stale is a partial quorum?
With R + W ≤ N the system is eventually consistent: the write keeps spreading after it is acknowledged, so the chance of a stale read falls quickly with time. Peter Bailis and colleagues called this probabilistically bounded staleness and measured it with latency distributions from production systems. The same calculation with a made-up distribution, each copy arriving after an exponentially distributed delay averaging 10 ms, gives the chance that a read t milliseconds after the acknowledgement returns the new value, with N = 3:
| R, W | t = 0 ms | t = 5 ms | t = 10 ms | t = 20 ms | t = 50 ms |
|---|---|---|---|---|---|
| R = 1, W = 1 | 33.4% | 59.5% | 75.3% | 91.0% | 99.5% |
| R = 2, W = 1 | 66.7% | 87.8% | 95.4% | 99.4% | 100.0% |
| R = 1, W = 2 | 66.6% | 79.7% | 87.7% | 95.5% | 99.8% |
| R = 2, W = 2 (overlapping) | 100.0% | 100.0% | 100.0% | 100.0% | 100.0% |
With R = W = 1, a read right after the acknowledgement sees the write only 33.4% of the time, about one chance in three of asking the one replica that has it, but 99.5% after 50 ms. Whether that is acceptable depends on the application: a social feed can show a like a moment late, a bank balance should not.
What quorums do not guarantee
R + W > N is about the overlap of sets, not about atomicity. Several things still go wrong:
- Failed writes are not rolled back. A write that reached fewer than W replicas is reported as failed but stays on the replicas it reached, and a later read may return it. With N = 3 and R = W = 2, after a write that reached one replica, twelve reads in the model returned versions 2, 2, 2, 1, 2, 1, 1, 2, 1, 1, 1, 2: a value the client was told had failed, appearing and disappearing.
- Read repair settles it, one way. With read repair, the first read that sees the newer version writes it to the replica it asked, and from then on every read set overlaps with it: the same twelve reads returned 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2. The failed write has quietly succeeded.
- Concurrent writes conflict. Two clients writing at once may each reach a different W replicas. Last write wins by timestamp keeps one and silently drops the other; Dynamo instead keeps both as siblings tagged with vector clocks and lets the application merge them.
- Sloppy quorums break the overlap. If the home replicas are unreachable and the write is accepted by stand-in nodes, a read of the home replicas can miss it until hinted handoff delivers it.
- Reads are not linearizable. A read concurrent with a write can return the new value while a later read returns the old one. Making quorum reads linearizable requires the reader to finish read repair before returning, and even then writes need more than last write wins.
Quorums in real systems
Amazon's 2007 Dynamo paper describes N, R and W as configurable per application, with (3, 2, 2) as the common choice, a sloppy quorum over the first N healthy nodes on the consistent-hash ring, hinted handoff and Merkle-tree anti-entropy. Apache Cassandra and Riak follow the same design. Cassandra lets each request choose a consistency level, ONE, QUORUM (a majority, n/2 + 1, of the replicas), ALL or LOCAL_QUORUM for a majority within one datacenter, and its documentation describes this as a version of Dynamo's R + W > N mechanism.
Consensus protocols use quorums too, but differently. Paxos and Raft need a majority to accept each entry and a majority to elect a leader, so any two majorities overlap and a new leader always knows about every committed entry. Flexible Paxos (Howard, Malkhi and Spiegelman, 2016) showed that only the election and replication quorums need to intersect, not two replication quorums, which allows smaller replication quorums in exchange for larger election quorums.
History
David Gifford introduced quorum-based replication in "Weighted Voting for Replicated Data" at SOSP in 1979, from work at Xerox PARC: each copy of a file holds a number of votes, a read must collect r votes and a write w votes, and r + w greater than the total number of votes ensures every read sees the latest write. Robert Thomas published a majority-consensus approach the same year. The idea returned to prominence in 2007 with Amazon's Dynamo, which used it for availability rather than correctness, and in 2012 Bailis and colleagues quantified how stale partial quorums are in practice.
Quorum questions and answers
What does R + W > N mean?
N is the number of replicas that store each item, W the number that must confirm a write before it counts as successful, and R the number a read asks. If R + W > N, any set of R replicas shares at least one replica with any set of W, so every read reaches at least one replica that has the latest successful write, and returns it by picking the highest version.
What happens if R + W is not greater than N?
A read can miss a write that has already been acknowledged. With N = 3 and R = W = 1, a read straight after a write that has reached only one replica returns the old value 66.7% of the time (the model measured 66.5%). The copies keep spreading, so the chance falls with every millisecond: this is eventual consistency.
Does a quorum guarantee strong consistency?
Not by itself. R + W > N guarantees that a read sees the latest successful write, but a write that fails part-way is not rolled back from the replicas it reached, so later reads may or may not return it. Concurrent writes resolved by last-write-wins can lose one of them, and sloppy quorums break the overlap. Linearizable reads also need read repair to finish before the read returns, or a consensus protocol.
What is a sloppy quorum?
When some of an item’s N home replicas are unreachable, Amazon’s Dynamo accepts the write on other nodes that are reachable, with a hint saying where it belongs, and hands it back once the home node recovers (hinted handoff). Writes stay available during failures, but the W nodes that took a write may not overlap with the R home nodes a read asks, so R + W > N no longer guarantees fresh reads.
What quorum settings do Cassandra and Dynamo use?
Dynamo’s paper reports (N, R, W) = (3, 2, 2) as the common configuration. Cassandra sets consistency per request: ONE, QUORUM (a majority, n/2 + 1 rounded down, of the replicas), ALL, and LOCAL_QUORUM, a majority within the local datacenter. Reading and writing at QUORUM gives R + W > N.
What is read repair?
When a read sees replicas with different versions, the coordinator writes the newest version back to the ones that were behind. It speeds up convergence and, after a failed write, stops reads from flipping between versions: in this page’s model, twelve reads after a write that reached one replica of three returned versions 2, 2, 2, 1, 2, 1, 1, 2, 1, 1, 1, 2 without read repair and 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 with it.
Further reading
- Gifford, SOSP 1979Weighted voting for replicated dataThe original quorum scheme for reads and writes.
- DeCandia et al., SOSP 2007Dynamo: Amazon's highly available key-value storeSloppy quorums, hinted handoff, vector clocks and anti-entropy.
- Bailis et al., VLDB 2012Probabilistically bounded staleness for practical partial quorumsHow stale eventually consistent reads are, measured and modelled.
- Apache Cassandra documentationDynamoReplication, tunable consistency levels and hinted handoff in Cassandra.
- Howard, Malkhi and Spiegelman, 2016Flexible Paxos: quorum intersection revisitedWhich consensus quorums really need to overlap.