Consistent Hashing
Plain hash % n reshuffles almost everything when the cluster changes size. Consistent hashing makes only a small slice move.
Intermediate
n shards owns a key is hash(key) % n. This works fine until n changes. Going from 4 shards to 5 changes the modulo result for nearly every key at once — almost the entire dataset has to move, even though only one shard was added.
hash(user) % 4 = shard # 4 shards
hash(user) % 5 = shard # 5 shards — a completely different assignment for almost every user
Ring positions (out of 0-359 for illustration):
Node A: 40 Node B: 150 Node C: 280
Key "order_918" hashes to 95 -> owned by Node B (first node clockwise from 95)
Key "order_204" hashes to 310 -> owned by Node A (wraps around past 360 back to 40)
Adding Node D at position 100:
Only keys between 40 and 100 (previously owned by Node B) now move to Node D.
Everything else on the ring is unaffected.
NodeA-1, NodeA-2, ... NodeA-20), scattering its presence across many points instead of one.| Benefit of virtual nodes | Why it helps |
|---|---|
| More even load distribution | With many virtual points per node, the law of large numbers smooths out the ring, so no single physical node gets an outsized arc by bad luck. |
| Smoother recovery from a failed node | When one node fails, its many small virtual slices spread the recovered load across many other nodes instead of dumping it all onto one neighbor. |
| Heterogeneous hardware support | A more powerful node can simply be given more virtual node identifiers than a weaker one, taking a proportionally larger share of the ring. |