Notes
Leaderless
In leaderless replication, each key lives on N replicas, here three. A write is sent to all three in parallel, by the client or a coordinator node. There's no leader to fail over, which is the appeal. But some of those writes will be slow or fail. When is the write 'done'?
- no leader, no failover
- each key lives on N replicas
- (here N = 3)
- the client (or a coordinator)
- sends the write to all N
- in parallel
- Dynamo, Cassandra, Riak
W
W is how many replicas must confirm before the write counts. With N three and W two, A and B say ok, and the client reports success even though C was down and still has the old value. W of one is fast but fragile; W equal to N is safest, but one dead replica blocks every write.
- wait for W acknowledgements
- then tell the user "saved"
- N = 3, W = 2:
- A ok, B ok → success
- C was down, still missing v2
- W = 1: fast, fragile
- W = N: safe, any failure blocks
R
R is how many replicas a read asks. With R two, the read happens to reach B and C. B has version two, C still has version one. Each value carries a version, so the client returns the newest, version two. The stale replica was outvoted.
- ask R replicas, take the
- value with the newest version
- N = 3, R = 2:
- B says v2, C says v1
- → return v2
- versions: timestamps or
- vector clocks (episode 32)
The overlap
Here's the whole trick. If R plus W is greater than N, any set of R replicas must share at least one member with any set of W replicas. Two plus two is four, more than three, so the read set always includes someone who saw the latest write. That one up-to-date replica is enough, because the newest version wins.
N = 3 W = 2 R = 2
write set: {A, B}
read set: {B, C}
overlap: {B} ← has v2
R + W > N ⇒ any read set
shares at least one replica
with the last write set Tuning
Now you can tune. Two and two is the balanced default. Read-heavy? W three, R one: reads hit a single node, writes need everyone. Write-heavy? W one, R three. Or W one, R one: fastest, but no overlap, so you're back to eventual consistency. Cassandra lets you choose per query with levels like ONE, QUORUM and ALL.
- N=3 W=2 R=2 balanced (common)
- N=3 W=3 R=1 fast reads,
- writes need all
- N=3 W=1 R=3 fast writes,
- reads ask all
- N=3 W=1 R=1 fastest, no overlap
- = eventual
- Cassandra: QUORUM, ONE, ALL
- per query
Read repair
What about C, still holding version one? Two repair mechanisms. Read repair: the read that noticed C was stale writes version two back to it. And anti-entropy: a background process compares replicas using hash trees and copies over any differences. Together, stale copies don't live forever.
- read repair: a read that sees
- a stale replica writes the
- newest value back to it
- anti-entropy: background job
- compares replicas (Merkle
- trees) and copies differences
- stale data does not live forever
Hinted handoff
When replicas are down, some systems use a sloppy quorum: another node temporarily stores the write for C with a hint, and hands it off when C comes back. That keeps writes available during outages. The catch: the W nodes that acknowledged may not be the key's usual replicas, so the overlap guarantee quietly disappears.
- C is down; to keep accepting
- writes, another node stores
- C’s copy with a "hint"
- when C returns, the hint is
- handed off to it
- great availability, but W
- nodes may not be the "home"
- N, so overlap is not guaranteed
The limits
Be careful in interviews: quorums alone are not strong consistency. Two clients writing the same key at once can still conflict, and last-write-wins silently drops one. A write that failed on some replicas can still be read from others. Sloppy quorums break the overlap. And timestamp versions break when clocks drift.
- • concurrent writes to the same
- key still conflict (last-write-
- wins can drop one)
- • a write that failed on some
- replicas may still be read
- • sloppy quorums break overlap
- • clock skew breaks timestamps
- ≠ linearizable by itself
Decision
Use quorum-based stores when you have heavy writes, several regions and don't want a single leader as a bottleneck: Cassandra, DynamoDB, Scylla. Tune per query: quorum for user-facing reads, one for analytics events. But if you need uniqueness or locks, you need consensus, which is episode thirty-one.
- high write volume, many
- regions, no single leader
- bottleneck: Cassandra,
- DynamoDB, ScyllaDB, Riak
- tunable per query:
- QUORUM for profile reads,
- ONE for analytics events
- need uniqueness or locks?
- → consensus (episode 31)
Say it like this
The interview answer. Each key on N replicas; writes wait for W acks, reads ask R replicas; with R plus W greater than N, a read always overlaps the latest write and the newest version wins. Stale copies heal through read repair, anti-entropy and hinted handoff. Then name the limits: concurrent conflicts and clock skew.
- "How do you keep replicas
- consistent without a leader?"
- N replicas, write to W,
- read from R, R + W > N
- → overlap, newest version wins
- repair: read repair,
- anti-entropy, hinted handoff
- limits: conflicts, clocks