Copies on the next N servers — replication factor RF across clockwise replicas
Writing each key to RF distinct successive servers clockwise on the ring means losing one server still leaves RF-1 copies and zero data loss.
Vnodes spread the load evenly, but the dead node's data is still lost — we need copies.
Scene 06
Copies on the next N servers
- Watch
- Try it
- Predict
- Capture
The ring is back — eight servers, one token each so the replicas are easy to read (vnodes return next scene). Watch the featured key light up its primary owner and then fan to the next two servers clockwise — three copies, three distinct boxes.
Highlighted lines are the ones running in the diagram right now.
def replicasFor(key, RF):primary = ring.successor(hash(key))seen = {primary}out = [primary]cursor = primarywhile len(out) < RF:cursor = ring.successor(cursor.token + 1)if cursor.physical_node not in seen:seen.add(cursor.physical_node)out.append(cursor)return out # RF distinct PHYSICAL nodes, not vnodes
def read(key, RF):replicas = replicasFor(key, RF)for r in replicas:if r.alive():return r.get(key) # no failover stepraise NoLiveReplicas # all RF copies down
def write(key, value, RF):replicas = replicasFor(key, RF)for r in replicas:r.put(key, value) # k* disk, k* network# tolerates RF - 1 simultaneous deaths with zero loss;# at RF=1 a single death takes the only copy with it.
Where this sits in Build a wide-column store (Cassandra / DynamoDB family)
Scene 06 of 13, in the Replication act — Copies on the next RF servers; eventual consistency under concurrent writes.. Store each key on the next RF distinct servers clockwise so a node death loses no data.
Up next. Three copies look safe — until two clients write at the same time and the copies disagree.
All 13 scenes in Build a wide-column store (Cassandra / DynamoDB family) · Every curriculum