~/posts/systems-design/consistent-hashing-explained.md

Consistent Hashing, Explained Visually

When you add or remove a node from a cluster, consistent hashing ensures only K/n keys need to move — not all of them. Here's why that matters at scale.

7 min read by admin consistent-hashing distributed-systems scalability sharding
~/posts/systems-design/consistent-hashing-explained.md $ cat consistent-hashing-explained.md

The Problem with Naive Sharding

If you shard by key % N, adding one node changes N, which remaps almost every key. You'd need to redistribute nearly your entire dataset.

The Hash Ring

Consistent hashing maps both keys and nodes onto a ring (a circular hash space 0–2³²). Each key is owned by the first node clockwise from it on the ring. Add a node: only the keys between the new node and its predecessor need to move.

Virtual Nodes

Real consistent hashing uses virtual nodes (vnodes): each physical node gets dozens of positions on the ring. This smooths load distribution and means removing one node spreads its keys across all remaining nodes rather than dumping them on one neighbour.