Quorums

Topic 5 of 9 in Week 5: Distributed systems and service communication9 min readIntermediateFree course

Overview

In leaderless replication (Dynamo-style systems such as Cassandra and Riak), any replica can accept reads and writes. How do you make sure a read sees a recent write when some replicas may have missed it? With quorums: require enough replicas to take part in each write and each read that the two groups must overlap.

N, W and R

Quorum reads and writes. A coordinator writes to three replicas with W equals 2: replicas 1 and 2 acknowledge and have version v2, while replica 3 is late or failed and still has v1. A read with R equals 2 asks any two replicas, and any two include at least one with v2, so the coordinator returns the newest version. N equals 3, W equals 2 and R equals 2 tolerates one slow or failed replica for both reads and writes. W equals 1 and R equals 1 is fastest but may read stale data; W equals N makes writes fail if any replica is down.

  • N: how many replicas store each key (commonly 3).
  • W: how many replicas must acknowledge a write before it counts as successful.
  • R: how many replicas must answer a read.

The coordinator sends each request to all N replicas and waits for W (or R) responses. Every value carries a version (a timestamp or version vector); on a read, the coordinator returns the newest version among the replies.

The overlap rule

If W + R > N, any set of W replicas and any set of R replicas share at least one replica. So at least one replica in every read has the latest acknowledged write.

With N = 3, W = 2, R = 2: two replicas have the write, any two you read include at least one of them.

Tuning

Setting (N = 3) Effect
W = 2, R = 2 Balanced; tolerates 1 failure for reads and writes
W = 3, R = 1 Fast reads; a single slow or failed replica blocks writes
W = 1, R = 3 Fast writes; reads need all replicas
W = 1, R = 1 Fastest and most available; reads may be stale (W + R ≤ N)

Lower values reduce latency because the coordinator waits only for the fastest replies, and they keep working when more replicas are down. That’s why quorums are described as tunable consistency: Cassandra exposes levels such as ONE, QUORUM, LOCAL_QUORUM (majority within the local data centre) and ALL.

Keeping replicas in sync

Replicas that miss writes must catch up eventually:

  • Read repair: when a read sees an outdated replica, the coordinator writes the newest value back to it.
  • Hinted handoff: if a replica is down during a write, another node stores a “hint” and delivers the write when the replica returns. (Some systems also count these temporary holders toward W, called a sloppy quorum, which improves availability but weakens the overlap guarantee.)
  • Anti-entropy: background processes compare replicas, often with Merkle trees (hash trees that quickly find which ranges differ), and copy missing data.

Limits of quorums

W + R > N gives a strong overlap, but not full linearizability:

  • concurrent writes to the same key can both succeed on different replicas; resolving them by timestamp (last write wins) can drop one, especially with clock skew,
  • a write that failed (fewer than W acks) may still have reached some replicas and later “appear”,
  • sloppy quorums can break the overlap during failures.

For operations that need a single winner, such as claiming a username or decrementing stock, use a leader-based or consensus-backed store, or conditional writes (compare-and-set) if the database supports them.

Majorities everywhere

The same majority idea appears in leader-based systems: Raft and Paxos commit an entry once a majority of nodes have it, and a new leader needs votes from a majority. Because any two majorities overlap, the new leader always knows about every committed entry. That’s why clusters run with an odd number of nodes (3 or 5): 5 nodes tolerate 2 failures; 6 nodes still tolerate only 2.

In an interview

For a Dynamo-style store: “Replication factor 3 across three zones; writes and reads at QUORUM, so W + R > N and we tolerate one replica down. For the high-volume, staleness-tolerant counters we use ONE.” Then mention read repair and anti-entropy if asked how replicas converge.

Recap

Quorums use N replicas, W write acknowledgements and R read replies; when W + R > N, reads overlap the latest write. Smaller W and R trade consistency for speed and availability. Read repair, hinted handoff and anti-entropy keep replicas converging. Quorums don’t resolve concurrent writes on their own, so use consensus or conditional writes where one winner is required.

Exercise

Tune the quorum

A key-value store keeps N = 5 replicas of every key. (a) Which (W, R) settings guarantee that every read overlaps the latest successful write? Give two examples. (b) For a write-heavy metrics workload where occasional stale reads are fine, what would you choose? (c) For user balances, what would you choose, and how many replica failures can reads and writes each tolerate? (d) Why can a quorum system still return stale data in practice?

Text
(a)
(b)
(c)
(d)

Summary

  • N is the number of replicas, W the acknowledgements a write needs, R the replies a read needs.
  • If W + R > N, every read set overlaps every write set, so a read sees the latest acknowledged write.
  • Majority quorums (W = R = ⌊N/2⌋ + 1) tolerate a minority of failed replicas for both reads and writes.
  • Smaller W or R means lower latency and more availability, at the cost of possibly stale reads.
  • Read repair, hinted handoff and anti-entropy keep leaderless replicas converging.