W plus R greater than N — quorum overlap and read-your-writes

If write replicas (W) plus read replicas (R) exceed RF, every read intersects every write on at least one replica — that's the geometric condition for read-your-writes.

Previously

If we want to be sure a read sees the latest write, we need to count replicas — not trust LWW alone.

Scene 08

Tunable consistency — W + R > N

  1. Watch
  2. Try it
  3. Predict
  4. Capture
mode: with-quorumn0n1n2n3n4n5n6n7user-42R1R2R3WRWRWRQUORUM VERDICTSTALE possible · sets may missW=1 + R=1 = 2 ≤ N=3rule: W+R > N guarantees overlap.RF=3 · W=ONE · R=ONE · W+R=2 ≤ N=3
W = how many replicas the write must reach
R = how many replicas the read must reach
quorum: smallest majority (RF=3 → 2). W+R > N → guaranteed overlap.
verdict: W+R ≤ N → sets may not overlap → stale read possible
What to watch for

Three replicas hold this key. W is the number of replicas a write must reach; R is the number a read must reach. At W=ONE, R=ONE the verdict says STALE possible — the write set and the read set don't have to overlap.

Implementation

Highlighted lines are the ones running in the diagram right now.

Coordinator.put
fan out the write to RF replicas; ack when W reply
def put(key, value, W):
replicas = ring.replicas_for(key) # RF nodes
ts = now()
for r in replicas:
send_async(r, Write(key, value, ts))
# block until W of RF acks come back
acks = wait_for(replicas, count=W)
if len(acks) < W:
return Unavailable
return Ack
Coordinator.get
ask R replicas; pick the freshest by timestamp
def get(key, R):
replicas = ring.replicas_for(key)
for r in replicas:
send_async(r, Read(key))
# block until R of RF responses arrive
responses = wait_for(replicas, count=R)
if len(responses) < R:
return Unavailable
winner = max(responses, key=lambda x: x.ts)
return winner.value
Coordinator.verdict
the geometric condition the verdict box reads off
def verdict(W, R, N):
# any read set of size R and any write set of
# size W are subsets of the N replicas; if their
# sizes sum to more than N they cannot be disjoint
if W + R > N:
return 'strong' # at least one shared replica
return 'stale-possible'

Where this sits in Build a wide-column store (Cassandra / DynamoDB family)

Scene 08 of 13, in the Tunable & CAP act — W+R>N for strong reads; per-request choice between A and C under partition.. Make every read overlap every write on at least one replica by sliding two knobs.

Up next. W+R>N works in steady state — but during a network partition, the cluster splits in two and not every side can reach a majority.

All 13 scenes in Build a wide-column store (Cassandra / DynamoDB family) · Every curriculum

Built with Arqly
Every scene in Build a wide-column store (Cassandra / DynamoDB family) builds on the one before it.All 13 Build a wide-column store (Cassandra / DynamoDB family) scenes