Distributed Systems

Consistent Hashing

Also known as: hash ring, ring hashing

Definition

Consistent hashing maps keys and nodes onto the same circular hash space, assigning each key to the next node clockwise. Adding or removing a node relocates only the keys in its immediate arc — roughly K/N of them — instead of remapping nearly every key as modulo hashing does.

Last reviewed · Part of the Architecture Glossary

In practice

The problem it solves is stated most clearly by the alternative. With node = hash(key) % N, growing a cache tier from 8 to 9 nodes changes the destination of roughly 89% of keys — every one of them a miss, all at once, straight through to the database. That is a cache stampede triggered by a capacity increase.

On a hash ring, the new node claims one arc. Only the keys in that arc move: about 1/9 of them. The other 8/9 stay put and stay warm.

Virtual nodes are the part that makes it work in production. Placing each physical node at one ring position gives wildly uneven arcs; placing it at 100–256 positions smooths the distribution and makes the load a departing node sheds spread across all survivors rather than dumping onto its single clockwise neighbour.

When it matters

Memcached and Redis client-side sharding, Cassandra and DynamoDB partitioning, request routing to stateful services, and any sharded tier that will be resized while serving traffic.

Common mistake

Assuming the ring solves skew. It distributes keys evenly, not traffic — one celebrity key still lands on one node. Uneven access needs a different fix: key splitting, a local cache in front, or dedicated handling for the hot tail.

See also

Go deeper