Course contents

05. Distributed Databases Lesson 10 of 10

Quorum Reads and Writes

Tune N, W and R: see why W + R > N makes reads overlap writes, how many failures a quorum survives, and why latency follows the slowest replica needed.

16 minAdvanced9 steps
Loading the interactive simulation…
Loading the knowledge check…

Summary

  • N replicas hold each key; a write waits for W confirmations, a read for R answers.
  • If W + R > N, every read quorum shares at least one replica with every write quorum.
  • Majority quorums (W = R = ⌊N/2⌋ + 1) tolerate a minority of failed replicas for both reads and writes.
  • A quorum waits for its W-th or R-th fastest member; W = N makes every write as slow as the slowest replica.
  • Sloppy quorums, partial failures and concurrent writes mean quorums are not linearizability.
Deep diveHow it works, trade-offs, failure modes, misconceptions and the interview angle.

What it is

In a replicated store each key lives on N replicas. A write quorum is the number of replicas, W, that must confirm a write before the client is told it succeeded; a read quorum is the number of replicas, R, whose answers a read waits for. Choosing W and R per request (Cassandra calls them consistency levels: ONE, QUORUM, ALL, LOCAL_QUORUM …) tunes each operation between speed, availability and freshness.

Why it exists

Waiting for every replica (W = N) is safe but slow and fragile: one slow replica slows every write, one dead replica stops them. Waiting for one (W = 1) is fast and available, but a read may hit a replica that hasn't got the write yet. Quorums sit between the two, and the arithmetic tells you exactly what you get.

How it works

Write. The coordinator sends the write to all N replicas in parallel and answers the client as soon as W have confirmed. The remaining replicas still apply it; the client just doesn't wait for them.

Read. The coordinator asks replicas (all N, or R of them plus a spare) and returns the newest version among the first R answers. Versions come from timestamps or version vectors attached to every value.

Overlap: W + R > N. If a write reached W replicas and a read asks R, the two sets must share at least one replica whenever W + R > N: there are not enough replicas for them to be disjoint. That replica has the latest acknowledged write, and because the read picks the newest version, the read sees it. With N = 3, W = 2, R = 2 gives 4 > 3. With W = 1, R = 1 (2 ≤ 3) the write and the read can land on different replicas, and the read can be stale right after a successful write.

Fault tolerance. Writes keep working while at least W replicas are reachable, reads while at least R are. A majority quorum, W = R = ⌊N/2⌋ + 1, satisfies W + R > N and tolerates ⌊(N − 1)/2⌋ failures for both: one for N = 3, two for N = 5. W = N tolerates none for writes; R = N none for reads.

Latency is an order statistic. A quorum waits for its W-th (or R-th) fastest member. With replicas answering after 5, 11 and 50 ms, W = 2 answers at 11 ms and W = 3 at 50 ms. Majority quorums hide one slow replica (a garbage-collection pause, a far zone); W = N exposes every write to the slowest one. This is why quorum systems often keep replicas in nearby zones and use LOCAL_QUORUM within a region.

Read repair. When a read sees an older version on some replica, the coordinator writes the newest value back to it. This narrows the window in which later reads with smaller R would see stale data.

Sloppy quorums and hinted handoff. If home replicas are unreachable, a Dynamo-style store may accept the write on other nodes, with a hint saying where it belongs, and count those toward W. That keeps writes available, but a read of the home replicas need not overlap those stand-ins, so W + R > N no longer guarantees anything until hinted handoff moves the data home. (Cassandra does not count hints toward the consistency level, except at level ANY.)

When to use it

  • Leaderless stores (Cassandra, ScyllaDB, Riak, DynamoDB internally) where you want per-request control over consistency and availability.
  • Majority quorums for data that should survive a replica failure without failover and be read back reliably.
  • Smaller W or R deliberately for data where staleness is acceptable and latency matters: counters, feeds, telemetry.

When not to

  • When you need linearizability (compare-and-set, uniqueness, leases, "exactly one winner"). Quorums alone don't provide it; use consensus (Raft, Paxos) or a single leader.
  • Across distant regions on the hot path. A global quorum waits for remote replicas; LOCAL_QUORUM plus asynchronous cross-region replication is the usual compromise.
  • W = N or R = N unless you accept that any single failure blocks that operation.

Trade-offs

Setting (N = 3) Overlap Tolerates for writes / reads Latency Typical use
W = 1, R = 1 No 2 / 2 Fastest replica Telemetry, caches, counters
W = 2, R = 2 Yes 1 / 1 Second-fastest General default (QUORUM)
W = 3, R = 1 Yes 0 / 2 Writes: slowest Read-heavy, rare writes
W = 1, R = 3 Yes 2 / 0 Reads: slowest Write-heavy, rare reads
Sloppy W = 2 Not guaranteed Writes almost always succeed Second-fastest reachable Maximum write availability

Alternatives

  • Single leader with synchronous or semi-synchronous replicas: one place orders writes; reads from the leader are fresh.
  • Consensus (Raft, Paxos): majorities as well, but with a leader and a log, which gives linearizable reads and writes.
  • Multi-leader replication: writes everywhere with asynchronous convergence and explicit conflict resolution.

Failure modes

  • Stale reads with W + R ≤ N, by design, often misconfigured by accident (writes at ONE, reads at ONE).
  • Partial writes. A write that reached fewer than W replicas is reported as failed, but the replicas that applied it keep it; later reads may or may not return it. The client cannot tell.
  • Concurrent writes. Two writes to the same key can each reach a quorum; the store must keep siblings or pick one (LWW), possibly losing an acknowledged write.
  • Sloppy quorum gaps. Writes accepted on stand-in nodes are invisible to strict reads until handoff, and lost if the stand-in fails first.
  • Tail latency. A slow replica raises latency for every operation that needs it, most visibly at W = N or R = N.

In production

Cassandra and ScyllaDB expose consistency levels per query; most applications use LOCAL_QUORUM for both reads and writes with replication factor 3 per data centre. Read paths often add speculative retry (ask another replica if one is slow) to cut tail latency. Riak exposes N, R, W per bucket or request. DynamoDB uses quorum-style replication internally and offers eventually or strongly consistent reads. Monitor per-replica latency, hint backlogs and repair progress; schedule anti-entropy repair so replicas that missed writes catch up.

Common misconceptions

  • "W + R > N means strong consistency." It gives overlap with the latest acknowledged write under strict quorums. Sloppy quorums, partial writes and concurrent writes still allow anomalies; it is not linearizability.
  • "Higher W is always safer." W = N makes every write fail when one replica is down.
  • "A quorum is as fast as the average replica." It is as fast as its W-th or R-th fastest member.
  • "Quorum means majority." A quorum is any W and R you choose; majority is one common choice.

Interview angle

When a design uses a Dynamo-style store, state N, W and R and the reason: "RF 3, LOCAL_QUORUM for writes and reads: W + R = 4 > 3, tolerates one replica down per data centre, latency is the second-fastest local replica." Then name the limits: sloppy quorums and hinted handoff, read repair and anti-entropy for convergence, and that uniqueness or compare-and-set needs consensus or a lightweight transaction.

Model assumptions

The engine parts of this lesson are a simplified model, not a benchmark. The app sends 100 writes per second (Poisson arrivals, 50 keys with Zipf popularity) to Replica A, which coordinates. Every replica has 16 connections and a 10 ms mean write (lognormal, cv 0.3). A is 2 ms from the app, Replica B 5 ms from A, Replica C 40 ms from A in another zone. W counts A's own copy: W = 1 is asynchronous replication (A answers after its own write), W = 2 waits for the first of B and C to apply the write, W = 3 for both. A write copy takes the hop to the replica plus 1 ms to apply, and the confirmation takes the hop back; A counts its own copy and answers when the W-th confirmation reaches it, holding one of its connections until then. A replica that is down never confirms (A notices at once, without a timeout) and misses the writes of its outage. In the W + R ≤ N step a separate reader reads the same keys from Replica C alone (R = 1, 10 ms away); a read is counted as stale when C has not yet applied a write A had already acknowledged for that key. The engine has no read quorums, versions, read repair, hints or stand-in nodes, so the R = 2 read with read repair and the sloppy quorum are scripted illustrations with the same one-way times (plus a 1 ms apply time), with traffic paused. Numbers show behaviour and orders of magnitude only.

How to read this demonstration.

  • Actual engine simulation: the write path for W = 1, 2 and 3 (own write, copy to the replicas, apply, confirmation back, the W-th confirmation answers), a replica going down, and the stale-read counter for a separate reader that reads Replica C alone (R = 1).
  • Scripted animation: the R = 2 read, read repair, and the sloppy quorum with hinted handoff (including its partition); these steps pause traffic and play packets.
  • Hybrid demonstration: the W + R ≤ N step: the stale reads come from the engine, the arithmetic about overlap is explained in text.
  • Simplified model: one coordinator, three replicas, fixed distances, no versions: a read is stale when the replica has not yet applied a write the coordinator already confirmed.
  • Time compression: slow motion (about 0.08 to 0.12 times real time, and 0.025 for the scripted illustrations) so the packets can be followed.
  • Not supported by the simulation: read quorums (the engine has no R > 1 reads: the R = 2 behaviour is scripted), read repair, hinted handoff and stand-in nodes, version vectors or timestamps, anti-entropy, network partitions, Raft or any consensus protocol.
The lesson as textEvery step of the simulation, written out.
  1. 1. Three copies, one acknowledgement

    Every key is stored on N = 3 replicas: A, B and C. Replica C sits in another zone, 40 ms away. The app sends 100 writes per second to Replica A, which coordinates each write: it stores it and sends a copy to B and C.

    How many replicas must confirm before the client hears "saved"? That number is W. Here W = 1: A answers as soon as its own copy is written, and B and C catch up afterwards. Writes are fast, but for a moment only one machine has the new value.

    Scene: The app writes to Replica A, which answers after its own write and replicates to B (5 ms away) and C (40 ms away) in the background. Writes are fast and none fail.

    Key idea: N is how many replicas hold a key; W is how many must confirm a write before it counts as done.

  2. 2. Wait for all three: as slow as the slowest

    Now W = 3 = N: A answers only when every replica has the write. A client that hears "saved" knows all three copies exist.

    Look at P95: it jumps by about 80 ms, because every write now waits for Replica C in the far zone: the copy takes 40 ms to get there and the acknowledgement 40 ms to come back. B answers in about 10 ms, but that doesn’t help: a quorum’s latency is the latency of its W-th fastest member, and with W = N that is always the slowest one.

    Scene: Replica A now answers only after B and C have the write. Every write waits for Replica C, 40 ms away each way, so P95 latency rises by about 80 ms.

    Key idea: Write latency is set by the W-th fastest replica. With W = N, the slowest replica sets the pace for every write.

  3. 3. One replica down, every write fails

    One second in, Replica C crashes. With W = 3 a write needs three confirmations and only two replicas are left, so every write fails (the red error packets). The data is still safe on A and B; the system just refuses to call any write done.

    W = N means the write path is only as available as the least available replica.

    Scene: Replica C goes offline one second in. From then on every write fails, because Replica A waits for three confirmations and only A and B can give one.

    Key idea: With W = N, losing any single replica makes all writes fail.

  4. 4. Wait for a majority

    C is repaired and we set W = 2: a majority of three. A stores the write and sends it to B and C at the same time; as soon as one of them has applied it, A’s own copy plus that one make two, and A answers.

    B is 5 ms away and C 40 ms, so B’s acknowledgement nearly always completes the quorum. Watch P95: it drops back to within about 10 ms of W = 1, some 70 ms below W = 3. C still receives every write (the purple packets keep flowing to it); the client just no longer waits for it.

    The slow replica has dropped out of the write latency: the answer now waits for the second-fastest copy, not the slowest.

    Scene: Replica A answers once its own copy and one replica have the write. B, 5 ms away, nearly always completes the quorum, so P95 falls back to within about 10 ms of W = 1; C still receives every write.

    Key idea: A majority quorum answers as soon as W replicas confirm, so one slow replica no longer slows every write.

  5. 5. Lose one replica, keep writing

    One second in, Replica C crashes again, this time with W = 2. A keeps sending every write to B and to C. C never answers, but A and B are already two copies, so every write succeeds, just as fast as before: no errors at all.

    With N = 3 and W = 2, writes tolerate one failed replica. In general a majority quorum on N replicas tolerates ⌊(N − 1) / 2⌋ failures: one for N = 3, two for N = 5.

    C is now missing every write made while it is down, among them the latest value of our key, v2. Remember that for the next step.

    Scene: Replica C goes offline one second in. With W = 2 every write still succeeds on A and B, with unchanged latency; C misses the writes made while it is down.

    Key idea: Majority quorums keep accepting writes while a minority of replicas is down.

  6. 6. W + R > N: reads and writes overlap

    C is back, still holding the old v1. A read with R = 2 needs answers from two replicas. The simulation has no read quorums, so this read is a scripted illustration (traffic paused). A uses its own copy, asks B and C, and returns the newest version among the first two answers: v2 from A and B, after about 17 ms.

    Why is that guaranteed? Any 2 replicas a read picks and any 2 a write picked must share at least one, because W + R = 4 > N = 3. At least one replica in every read quorum has the latest acknowledged write.

    C’s answer arrives later with v1. A notices it is stale and sends C the new value: read repair. Note the read paid for the second-fastest replica, just like the write.

    Scene: Scripted: a read with R = 2. Replica A combines its own v2 with B’s v2 and answers after about 17 ms. C answers later with v1, and A repairs C by sending it v2.

    Key idea: If W + R > N, every read quorum overlaps every write quorum, so a read sees the latest acknowledged write.

  7. 7. Fast, but no overlap

    Back on the simulated cluster, tempted by speed: W = 1 (A acknowledges after its own copy) and a reader that reads the same 50 keys from Replica C alone, R = 1, 100 times per second.

    Every write needs about 40 ms to reach C, and reads that land in that window return the previous value although the new one was already acknowledged: the stale reads tile climbs steadily, about a quarter of all reads on C. W + R = 2 ≤ N = 3: the replica that took the write and the replica that served the read need not overlap.

    The arithmetic predicts the fix exactly. With W = 2 the same reads are still stale, because the write quorum {A, B} need not include C (2 + 1 = 3, not more than 3). With W = 3 they never are (3 + 1 > 3), at the price of the slow writes from step 2.

    W + R ≤ N can be the right call (a view counter, a feed that may lag), as long as it is a decision and not an accident.

    Scene: Replica A acknowledges each write after its own copy. A reader reads the same keys from Replica C alone; reads that arrive before a write reaches C return the old value, and the stale-read counter climbs.

    Key idea: With W + R ≤ N reads can miss acknowledged writes: you trade consistency for latency and availability.

  8. 8. Sloppy quorums break the overlap

    Back to W = 2, R = 2, and back to a scripted illustration (traffic paused): the simulation has no stand-in nodes or hints. A network partition cuts A off from B and C (drawn with packets only: the simulation has no partitions). A strict quorum would fail the write. Some Dynamo-style stores use a sloppy quorum instead: A writes v4 to itself and to Node D, a node that is not one of the key’s three home replicas, with a hint “this belongs to B”. Two acknowledgements: "saved".

    The partition heals. A read coordinated by C asks C and B: two replicas, R = 2, and both still hold v3. The read is stale although W + R > N, because the write quorum {A, D} and the read quorum {B, C} share no node. Only when D hands the hint over to B (hinted handoff, the last packet) does the overlap hold again.

    Sloppy quorums buy write availability; they quietly give up the overlap guarantee until handoff completes.

    Scene: Scripted: B and C are unreachable, so A writes v4 to itself and to stand-in Node D with a hint for B. After the partition heals, a read of C and B returns the older v3. Later D hands v4 over to B.

    Key idea: W + R > N only guarantees overlap among the home replicas. Sloppy quorums count stand-ins, so reads can miss writes until hinted handoff.

  9. 9. Choosing N, W and R

    We are back on the simulated cluster with W = 3 and 100 writes per second (the reader is gone), so you can try failures in the sandbox.

    The dial: W + R > N gives reads that overlap the latest acknowledged write (with strict quorums). W = R = majority tolerates a minority of failed replicas for both reads and writes. Lower W or R buys latency and availability at the price of stale reads. And every quorum waits for its W-th or R-th fastest member, so one slow replica hurts only when the quorum needs it.

    Quorums are not linearizability: concurrent writes, sloppy quorums and partially failed writes can still produce surprises. For strict guarantees, use consensus (Raft, Paxos).

    Scene: All three replicas are healthy. The app writes 100 times per second; Replica A waits for all three copies (W = 3), so each write takes about 80 ms longer than a local write.

    Key idea: Pick W and R per workload: W + R > N for read-your-writes overlap, majorities for fault tolerance, smaller values for speed.