Replicas disagree, then converge
Eventual consistency is a convergence guarantee: absent new writes, all replicas agree in finite time, and last-write-wins resolves disagreements by timestamp.
Three copies look safe — until two clients write at the same time and the copies disagree.
Scene 07
Replicas disagree, then converge
- Watch
- Try it
- Predict
- Capture
Two clients write the same key at almost the same instant. The scene auto-advances through three phases: concurrent writes → diverged → converged. Watch the replica boxes — at the end, both hold the same value, picked by last-write-wins.
Highlighted lines are the ones running in the diagram right now.
def write(key, value):ts = client_clock.now_ms() # client-supplied timestampself.cells[key] = (value, ts)gossip.enqueue(key, value, ts)return OK # acknowledged before peers have it
def read(key):# no consensus, no quorum yet — just local statevalue, ts = self.cells[key]return value# R_A returns qty=2 ; R_B returns qty=5 — both 'correct'# from their local view; the cluster disagrees with itself.
def LWW(values):# values = [(v1, ts1), (v2, ts2), ...]return argmax(values, key=lambda v_ts: v_ts[1])def reconcile(key, peer):mine = self.cells[key]theirs = peer.cells[key]winner = LWW([mine, theirs])self.cells[key] = winnerpeer.cells[key] = winner # converged
Where this sits in Build a wide-column store (Cassandra / DynamoDB family)
Scene 07 of 13, in the Replication act — Copies on the next RF servers; eventual consistency under concurrent writes.. Concurrent writes hit replicas at different times; for a moment they disagree, but they converge under LWW.
Up next. If we want to be sure a read sees the latest write, we need to count replicas — not trust LWW alone.
All 13 scenes in Build a wide-column store (Cassandra / DynamoDB family) · Every curriculum