Why it matters

Consistent hashing is core distributed systems knowledge. It appears in load balancers, caches, and databases. Understanding it explains rebalancing behavior across many systems.

Advertisement

The architecture

Ring: values 0 to 2^32 - 1 (or similar). Both keys and node identifiers hash to positions on the ring. A key belongs to the first node clockwise from its position.

Adding a node: only keys between the new node and its predecessor move. Removing a node: keys move to the successor.

Consistent hashing modelRinghash spaceNodeshashed to positionsKeysassigned clockwiseVirtual nodes (200-1000 per real node) smooth out uneven distribution
Hash ring layout.
Advertisement

How it works end to end

Virtual nodes: each real node gets many (200-1000) virtual positions on the ring. This smooths distribution and lets you weight nodes (bigger nodes get more virtual positions).

Rendezvous hashing (HRW): alternative that computes hash(key, node) for each node and picks max. Simpler for small clusters, better distribution guarantees.

Applications: caching layers (avoid mass invalidation on scale change), distributed databases (partition assignment), load balancers (sticky sessions).