Time to put the two schemes on the same scale. Grow from three nodes to four and count the keys that move under each. The ring moves one key where modulo moves eight - the whole point of the project in a single comparison.
Compare keys moved when a node joins and then leaves - ring versus modulo hashing.
This is the headline result, measured. The same event - a fourth node joins a cluster of
three - costs the ring 1 reassigned key and costs modulo hashing 8. Remove that
node again and the story is symmetric: the ring moves the single key back while modulo
reshuffles 8 once more. Both schemes still place all twelve keys and both spread them
across the nodes; the difference is entirely in the churn. On the ring, only orange
moves, because only orange sits in the new node’s arc. Under modulo, changing the
divisor reshuffles two thirds of everything, in either direction.
Scale that up and the gap is the whole reason consistent hashing exists. With K keys
and N nodes, adding or removing a node moves about K/N keys on the ring - the keys in
one node’s arc - while modulo moves on the order of K keys, nearly all of them. For a
cache in front of a database, that is the difference between a brief flurry of misses and
a full cache flush that hammers the database every time the cluster resizes. You have now
built and proven the core of a consistent hash ring.
// Ring add: MovedKeys(before, after) from lesson 13 -> 1.// Modulo add: MovedCount(keys, 3, 4) from lesson 4 -> 8.// Ring remove: MovedKeys the other direction -> 1.// Modulo remove: MovedCount(keys, 4, 3) -> 8.// Same events, two very different costs, in both directions.