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.

Previously

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

  1. Watch
  2. Try it
  3. Predict
  4. Capture
mode: with-replicasABCDEFGHuser-42R1R2R3ARC SIZES (deg)A45°B45°C45°D45°E45°F45°G45°H45°ideal: 45° · range: 45–45°RF = 3 · 3 distinct replicasRF=3 · key copied to 3 distinct servers
What to watch for

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.

Continue unlocks when the animation finishes.
Implementation

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

Replication.replicasFor
walk the ring clockwise picking the next RF distinct nodes
def replicasFor(key, RF):
primary = ring.successor(hash(key))
seen = {primary}
out = [primary]
cursor = primary
while 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
Coordinator.read
answer a read from the first live replica
def read(key, RF):
replicas = replicasFor(key, RF)
for r in replicas:
if r.alive():
return r.get(key) # no failover step
raise NoLiveReplicas # all RF copies down
Coordinator.write
write goes to all RF replicas; durable while RF-1 are alive
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

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