In this lesson · topic 2 of 7
Topic 2
Overlap, and the k-th fastest reply
6 min read
The overlap rule
Take N replicas. A write is acknowledged by W of them, so those W hold the new value. A read asks R of them. If R plus W is greater than N, the read set and the write set cannot be disjoint, because together they would need more than N distinct replicas. At least one replica in the read set has the new value, and the reader picks the newest version among the answers.
This is the idea in Gifford’s paper on weighted voting. Step through a concrete case below.
Why R plus W above N makes reads see writes
Step 1 / 4- N
- 5
Five replicas hold version 1
N is 5. Every replica has the same value, version 1.
A write with W = 3
The write goes to all five, but replicas 4 and 5 are slow today. Replicas 1, 2 and 3 reply, so the write is acknowledged with version 2 on three replicas. The other two will catch up later.
A read with R = 2 can miss it
The read asks two replicas and the two fastest happen to be 4 and 5. Both say version 1. R plus W is 5, which is not above N, so there is no promise the sets overlap. This read is stale.
A read with R = 3 cannot
Now the read must hear from three replicas. Three replicas out of five cannot all be outside the three that took the write, because only two are left. At least one replica has version 2, and the reader takes the highest version.
- Five replicas hold version 1. N is 5. Every replica has the same value, version 1. N: 5.
- A write with W = 3. The write goes to all five, but replicas 4 and 5 are slow today. Replicas 1, 2 and 3 reply, so the write is acknowledged with version 2 on three replicas. The other two will catch up later. W: 3; replicas with v2: 3 of 5.
- A read with R = 2 can miss it. The read asks two replicas and the two fastest happen to be 4 and 5. Both say version 1. R plus W is 5, which is not above N, so there is no promise the sets overlap. This read is stale. R + W: 2 + 3 = 5; returned: v1, stale.
- A read with R = 3 cannot. Now the read must hear from three replicas. Three replicas out of five cannot all be outside the three that took the write, because only two are left. At least one replica has version 2, and the reader takes the highest version. R + W: 3 + 3 = 6; returned: v2, fresh.
Common choices follow from the rule. With N equal to three, R and W both two is a majority quorum. With W equal to N and R equal to one, reads are cheap and writes need every replica. With R equal to N and W equal to one, the reverse.
A quorum waits for the k-th fastest reply
The coordinator sends the request to all N replicas at once, then waits until W replies for a write or R replies for a read. So the latency of an operation is the time of the k-th fastest reply, with k being W or R.
That has a useful consequence. If one replica is slow, a quorum smaller than the number of fast replicas never waits for it. And a harsh one. Ask for one more reply than there are fast replicas, and latency jumps to the slow replica’s, since there is nothing else to wait for.
Failures cost availability
A replica that is down cannot reply. An operation needs k replies, so it succeeds only if at least k of the N replicas are reachable. If each replica is unreachable with probability p, the chance of success is the chance that at least k out of N are up, which is a binomial tail. Larger k means a lower chance. Majority quorums survive a minority of failures. Needing every replica survives none.
Sloppy quorums and hinted handoff
Strict quorums insist that the replies come from the N replicas that own the item. A sloppy quorum relaxes that. When some owners are unreachable, the write goes to other healthy nodes, which count toward W. Those stand-ins keep a note of who the write was for. When the owner comes back, the stand-in hands it over. That is hinted handoff. Writes then succeed in far more situations.
The cost is the overlap guarantee. A read still asks the owners, and the write may be sitting on stand-ins that the read does not ask. R plus W can exceed N and a read can still miss the write, until the hint is delivered. A sloppy quorum is a choice for availability over freshness.
Read repair
Replicas that miss writes stay behind. Read repair closes the gap lazily. When a read sees that some replicas returned an older version, it writes the newest value back to them. Items that are read often get healed quickly. Items nobody reads stay stale, so systems also run a background pass that compares replicas, which is outside this lab.