concept

Consistent Hashing

A hashing scheme where adding or removing a node remaps only a small fraction of keys, instead of nearly all of them.

partitioningshardingcaching

With naive hash(key) % N, changing N from 4 to 5 remaps roughly 80% of keys. For a cache that means a near-total miss storm; for a data store it means moving almost everything.

Consistent hashing maps both keys and nodes onto a ring; a key belongs to the next node clockwise. Adding a node steals keys only from its immediate neighbour, so roughly 1/N of keys move. Virtual nodes — placing each physical node at many ring positions — fix the load imbalance that a plain ring produces.

Where you meet it: distributed caches, sharded data stores, and load balancers doing session affinity. It is also the reason a cache cluster can be resized without an outage, which is not true of a modulo-partitioned one.