Sub topic 8
Quorums: tuning N, R and W
This chapter assumes you know what replication is, have read the chapters on linearizability and eventual consistency, and can read simple Python. A quorum system lets a replicated store trade read cost, write cost, and consistency by choosing how many replicas must answer each operation.
The three parameters
A leaderless store such as Dynamo, Cassandra, or Riak keeps each key on several replicas. Three numbers describe the policy:
- N is the number of replicas that hold each key.
- W is the number of replicas that must acknowledge a write before the client is told it succeeded.
- R is the number of replicas that must answer a read before the coordinator returns a result.
The coordinator still sends every write to all N replicas. It only waits for W acknowledgments. The remaining replicas receive the write later, or never, if they are down.
Why R + W > N matters
Suppose a write was acknowledged by W replicas. A later read contacts R replicas. If R + W > N, the two sets must share at least one replica, by the pigeonhole principle. That shared replica holds the latest acknowledged write, so the read can see it.
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, R = 2, W = 2, any two replicas out of three include at least one replica from any other pair. With R = 1 and W = 1, a read can land on a replica the write never reached.
The read must also pick the right answer among the R replies. It compares version metadata, such as timestamps or vector clocks, and returns the newest value. Overlap only guarantees that the newest value is among the replies. It does not pick it for you.
Common configurations
| N | R | W | Overlap | Behavior |
|---|---|---|---|---|
| 3 | 2 | 2 | Yes | Balanced. Tolerates one unavailable replica for reads and writes. |
| 3 | 1 | 3 | Yes | Fast reads. Writes fail if any replica is down. |
| 3 | 3 | 1 | Yes | Fast writes. Reads fail if any replica is down. |
| 3 | 1 | 1 | No | Fastest and most available. Stale reads are expected. |
| 5 | 3 | 3 | Yes | Tolerates two unavailable replicas. More replicas to pay for. |
Lowering W makes writes faster and more available, but each acknowledged write is on fewer machines, so it is easier to lose. Lowering R does the same for reads. You choose which side to make cheap based on the read/write ratio of your workload.
Availability arithmetic
An operation succeeds only if enough replicas are reachable. With N replicas, writes tolerate N − W failures and reads tolerate N − R failures. When R + W = N + 1, as in 2 + 2 over 3 or 3 + 3 over 5, both sides tolerate the same number of failures, which is the usual default for this reason.
def tolerated_failures(n, r, w):
return {"reads": n - r, "writes": n - w}
print(tolerated_failures(3, 2, 2)) # {'reads': 1, 'writes': 1}
print(tolerated_failures(5, 3, 3)) # {'reads': 2, 'writes': 2}What quorums do not give you
Overlapping quorums are necessary for strong reads but not sufficient. The tutorial's earlier example showed that R + W > N alone does not make a system linearizable. Several failure modes remain.
Concurrent writes
Two clients can write the same key at the same time through different coordinators. Each reaches W replicas, and different replicas may see them in different orders. Quorum overlap says nothing about which write wins. You need a conflict rule such as last-write-wins, vector clocks, or a CRDT, covered in later chapters.
Sloppy quorums and hinted handoff
In a strict quorum, the W acknowledgments come from the N replicas that own the key. A sloppy quorum, used by Dynamo-style systems for availability, accepts acknowledgments from any reachable nodes. If an owner is down, another node holds the write temporarily as a hint and forwards it later. The count W is satisfied, but the overlap argument breaks, because the read quorum may contact the owners and miss the stand-in node. Sloppy quorums keep writes available during failures but give up the R + W > N guarantee until hints are delivered.
Partial failures of writes
If a write reaches fewer than W replicas, the client sees an error. The write is not rolled back. The replicas that did accept it keep the new value, and a later read may return it. A failed write can therefore appear to take effect afterwards.
Stale reads during repair
A read may return the new value from one replica while another still holds the old one. If the next read contacts a different set of replicas, the first read's value can seem to disappear. Overlap holds for each operation individually, but without extra mechanisms, such as read repair that writes back the newest value before returning, two successive reads can go backwards in time.
Clocks and membership
If versions are picked by timestamps, clock skew between coordinators can make an older write look newer. If cluster membership changes, for example when a node joins or leaves, the set of replicas for a key changes, and old and new quorums may not overlap during the transition.
Making quorums stronger
Systems add mechanisms on top of the basic rule:
- Read repair. After a read, the coordinator sends the newest value to any contacted replica that returned an older one.
- Anti-entropy. Background processes compare replicas, often using Merkle trees, and copy missing updates.
- Versioning with vector clocks. Replicas keep concurrent versions, called siblings, and return them all so the application can merge them.
- Consensus. If you need linearizability, use a protocol such as Raft or Paxos, which orders writes through a leader or proposer instead of relying only on counting acknowledgments.
Choosing values in practice
Start from the workload:
- Read-heavy with rare writes: choose R = 1 and W = N if you can accept that writes block when any replica is down.
- Write-heavy with rare reads: choose W = 1 and R = N, with the same trade-off reversed.
- Mixed and availability matters: choose majorities for both, R = W = ⌊N/2⌋ + 1.
- Staleness is acceptable: choose R + W ≤ N and rely on eventual convergence.
Per-request tuning is common. Cassandra, for example, lets each query select a consistency level such as ONE, QUORUM, or ALL. You can write at QUORUM and read at ONE for a dashboard that tolerates staleness, then read at QUORUM for a check that must see recent data.
Exercise
A key is stored with N = 5, W = 3, R = 2. Do read and write quorums always overlap? How many replica failures can writes tolerate? A reader reports seeing a value disappear between two reads even though a configuration like this was used. Give one possible cause.
Show answer
R + W = 5, which is not greater than N = 5, so quorums do not always overlap. A read can contact the two replicas that missed the last write. Writes tolerate N − W = 2 failures. The value can disappear because the first read reached a replica with the new value and the second reached two replicas without it. Raising R to 3 would guarantee overlap. Read repair would also reduce going backwards, though it would not remove the problem completely.
Exercise
Why does a sloppy quorum with W = 2 and R = 2 over N = 3 fail to guarantee that a read sees the latest acknowledged write?
Show answer
In a sloppy quorum, the two acknowledgments can come from nodes that are not among the key's three owners, for example when two owners are unreachable. The write is held there as a hint. A read that contacts the owners can find none of the nodes that stored the write, so overlap is not guaranteed until the hints are handed off.