Zum Hauptinhalt springen

Why R + W > N: Quorums and the Consistency You Can Compute

· 10 Minuten Lesezeit
Clustron Team
Engineering für verteilte Systeme

Replication solves durability and creates a problem in the same stroke. Keep three copies of a key and no single disk or node failure can lose it — but now a client that wants to read the key has three places it could ask, and those three places do not always agree. A write that has reached two of the copies but not yet the third leaves one replica a version behind, and a client that happens to read that third replica gets a value that is simply wrong: superseded, stale, gone in the eyes of everyone else.

The two obvious answers are both bad. Read from one replica — the nearest, the fastest — and you have no guarantee it is the one that saw the latest write; you have traded correctness for speed. Read from all the replicas on every read, and write to all of them on every write, and you are once again as slow and as fragile as if you had never replicated: one slow or dead replica stalls every operation, which is the opposite of what replication was for. Somewhere between "ask one" and "ask everyone" there has to be a rule that buys correctness without buying the full cost.

The quorum model is that rule, and it is almost startlingly simple. Pick how many replicas a write must reach before it is acknowledged — call it W — and how many a read must consult before it answers — call it R — out of N total copies. Then impose one condition: R + W > N. That inequality is the whole mechanism. It does not require a leader, it does not require contacting everyone, and it guarantees that every read observes the most recent acknowledged write.

The overlap is pigeonhole, not luck​

Why does R + W > N give you anything? Because of where the read and write sets can sit. A write is acknowledged once W replicas have it. A read gathers responses from R replicas. Both sets are drawn from the same N copies. If R + W is greater than N, the two sets cannot be disjoint — there is no room for R replicas and W replicas to avoid each other inside a pool of only N — so at least one replica is in both sets. That replica received the write and is being read, which means the read is guaranteed to see at least one copy carrying the latest acknowledged value.

Seeing it is not quite keeping it: the read gathers R responses and some of them may be stale, from replicas that were not in the write set. So the read does not trust the first answer; it compares the versions of the R responses it got and keeps the newest, using the same per-key version or hybrid logical clock that resolves any replication conflict. The overlap guarantees the newest value is present among the responses; the version comparison guarantees it is the one returned. Together they turn "ask a subset" into "answer as if you asked everyone."

overlapWrite W=2R1 · v2R2 · v2R3 · v1missed the write — stalegot the writegot the writeRead R=2R2 · v2R3 · v1read consults R2 & R3 → keeps newest by version → v2 ✓R + W = 2 + 2 = 4 > N = 3 ⇒ the two sets must share R2

One knob, tuned three ways​

The elegance of the model is that W and R are dials on the same replicas, and sliding them trades read cost against write cost while R + W > N keeps consistency intact.

  • W = N, R = 1. Writes go to every copy; a read consults just one. Reads are as cheap and fast as possible, writes are the slowest and least available. This is the setting for read-heavy, write-rarely data — a config blob, a feature flag — where you want reads to touch one replica and never wait.
  • W = 1, R = N. The mirror image: a write acknowledges as soon as one replica has it, and the cost moves to the read, which must consult all N to be sure it finds that one. Good for write-heavy ingestion where reads are rare and can afford to gather everyone.
  • W = R = majority. With W = R = ⌊N/2⌋ + 1, both sets are a majority, their sum exceeds N by construction, and no single operation waits on all N. This is the balanced default, and it has a second virtue the lopsided settings lack: it keeps working when a minority of replicas is down.
int N = 3;
int W = N / 2 + 1; // 2 — a majority must ack the write
int R = N / 2 + 1; // 2 — a majority must answer the read
// R + W = 4 > N = 3 ⇒ read set and write set always intersect.

// Write: send to all N, acknowledge as soon as W confirm (ignore the slowest N-W).
await WaitForAcks(replicas, required: W);

// Read: query all N, answer as soon as R respond, keep the newest version seen.
var answers = await WaitForResponses(replicas, required: R);
var fresh = answers.MaxBy(a => a.Version); // the overlap guarantees it is current

That "ignore the slowest N−W" is not a footnote — it is a tail-latency win. A write with W = 2 out of N = 3 acknowledges as soon as the two fastest replicas confirm, so one slow or stalled replica never gates the operation. A quorum is, among other things, a way to stop waiting on the straggler that a write-to-all would force you to wait for.

What a majority survives, and what the model does not promise​

The failure math is the reason majority quorums are the common choice. With W = R = ⌊N/2⌋ + 1, the cluster tolerates ⌊(N−1)/2⌋ replica failures and still assembles both quorums: N = 3 survives one failure, N = 5 survives two. Lose more than that and you can no longer form a quorum, at which point the system correctly refuses the operation rather than returning a value it cannot vouch for — the same honest unavailability that sizing replicas for durability is meant to keep you out of.

Be clear about what R + W > N does and does not buy. It guarantees a read sees the latest acknowledged write — strong enough for read-your-writes and monotonic reads. It does not, by itself, give you full linearizability: two clients writing the same key concurrently can both reach quorum, and the model does not order them for you, so it falls back on version/HLC last-write-wins to pick a survivor — and the loser is simply gone unless you reconcile with richer merge logic. Quorums also leave stale replicas stale: the overlap means a read finds the fresh value, not that the lagging replicas get fixed. That is why quorum systems pair naturally with read repair and background anti-entropy — the read that noticed a stale replica in its R set is the cheapest possible moment to push the fresh value back to it.

Wrap-up​

A quorum answers the question replication forces on you — how many copies must I consult to trust what I read — with one inequality. Require that writes reach W replicas, reads consult R, and R + W > N, and the read set and write set are forced to overlap on at least one replica, the one holding the newest acknowledged value, which a version comparison among the responses then returns. The same two dials tune the same replicas from read-fast (small R) to write-fast (small W) without ever breaking consistency, a majority setting keeps both quorums available through a minority of failures, and acknowledging after the fastest W or R responses turns replication from a tax on the tail into a defense against it. What it gives is a read that never trails the last committed write; what it leaves for other mechanisms is ordering concurrent writers and healing the replicas that fell behind. Consistency, in the quorum model, is not a property you hope for — it is a property you compute, from three numbers and a greater-than sign.