Vnodes flatten the lumpy ring
Many small ring positions per physical server make arc sizes uniform by averaging, and spread a dead node's load across all survivors instead of crushing one neighbour.
The ring is great in theory, but with one position per server those arcs were wildly unequal — and worse, a dead server dumped its entire arc onto a single clockwise neighbour. We need to chop each server's stake into many small pieces.
Scene 05
Vnodes flatten the lumpy ring
- Watch
- Try it
- Predict
- Capture
Same 8 servers as scene 4 — but each one now holds 4 small wedges scattered around the ring. The variance bar up top is what to watch: arcs are far closer to the ideal 45° share, and no single neighbour is on the hook for a whole server's worth of keys anymore.
Highlighted lines are the ones running in the diagram right now.
def tokensForNode(nodeId, vnodeCount):out = []for i in range(vnodeCount):# pure arithmetic, no rng — same answer every rendert = ((nodeId * 1009 + i * 2017) * 137) mod 360out.append(t)return sorted(out)# ring tokens = union of tokensForNode(n, k) for every node n
def loadVariance(nodes, vnodeCount):arcs = [] # (owner, size) per ring slicefor token in sorted(all_tokens(nodes, vnodeCount)):arcs.append((owner(token), arc_size(token)))per_node_total = sum_by_owner(arcs)return stddev(per_node_total) / mean(per_node_total)# law of large numbers: each node's stake is a sum of# vnodeCount random arcs, so variance ~ 1 / sqrt(vnodeCount).# 1 -> ~50% ; 4 -> ~20% ; 64 -> ~5%.
def absorbDeadNode(dead):for vnode in dead.tokens:# each greyed wedge hands its keys to its own# clockwise successor — a different physical node# than the previous wedge, when vnodeCount is high.successor = ring.successor(vnode + 1)successor.adopt(vnode.keys)# 1 token -> 1 successor crushed# 64 tokens -> ~64 successors each take 1/64 of the load
Where this sits in Build a wide-column store (Cassandra / DynamoDB family)
Scene 05 of 13, in the The ring act — Consistent hashing + vnodes — adding a server moves only ~1/N of keys.. Give each physical server many small ring positions; arcs become uniform and deaths spread their load.
Up next. Vnodes spread the load evenly, but the dead node's data is still lost — we need copies.
All 13 scenes in Build a wide-column store (Cassandra / DynamoDB family) · Every curriculum