What consistent hashing is for, and the ring concept
coreintermediateConsistent hashing is a way to map both data (keys) and servers (nodes) onto the same circular hash space, called a ring, so that each key belongs to whichever node comes next on the ring in clockwise order. It solves a specific problem with plain "hash(key) % N" routing: with modulo hashing, adding or removing a single server changes the result of the modulo for almost every key, so almost every key gets remapped to a different server at once. On a ring, only the keys that fall between the changed node and its neighbor move — everyone else keeps pointing at the same node they always did. That is why it shows up anywhere a distributed cache, a partitioned datastore, or a load balancer needs to route the same key to the same node consistently, even as nodes come and go.
Think of it as
Picture a circular parking garage with numbered spots running 0 to 359 all the way around, and imagine security guards posted at fixed spots around that circle. Every car (a key) drives to its assigned spot number and then walks clockwise to the nearest guard — that guard owns it. If one guard goes home sick, only the cars between that guard's spot and the previous guard's spot need to walk further, to the next guard around the circle; every other car's nearest guard hasn't changed at all. Compare that to a system where cars are assigned to guards by "spot number mod number-of-guards" — remove one guard and that division changes for almost every car, so almost everyone has to find a new guard.
What we're doing: Place three nodes and one key on a ring, and find which node owns the key.
- 9
- "user:42" hashes to 75, which is not a node position — the lookup keeps walking clockwise.
- 13
- The first node reached clockwise from 75 is Node B at 160, so Node B owns this key.
- 17
- "user:99" at 310 wraps around past the 360/0 boundary before reaching Node A at 40 — the ring is circular, so lookups wrap.
Why this works: The mechanical lookup — hash the key, walk clockwise, wrap at the boundary — is the entire algorithm; everything else (virtual nodes, rebalancing) builds on this one operation.
Forgetting the ring wraps around, and stopping the clockwise walk at the highest hash value
Wrong
Better
What you see: Keys that hash above the last node's position on the ring get no owner at all (a None/null result) instead of wrapping to the first node.
Why: A ring has no start or end — position 359 is adjacent to position 0, not a dead end — so a correct implementation must wrap the search back to the smallest node position instead of returning nothing.
- hash(key) % N
- Routing depends on the current node count N
- Adding/removing a node remaps nearly all keys
- Every lookup needs to know N upfront
- Consistent hashing (ring)
- Routing depends only on ring position
- Only keys near the changed node remap
- Lookup only needs the ring, not N
Modulo hashing vs. ring-based consistent hashing
Remember: Ring-based lookup (hash the key, walk clockwise to the next node) means only the keys near a changed node move when that node joins or leaves — unlike hash(key) % N, where changing N remaps nearly everything.
See also: virtual nodes · node changes and key movement · choosing shard keys · partitioning as a decision

