← Playground

Consistent Hashing

royhp.com

Consistent hashing maps both servers and keys onto the same ring — a hash space of 0 … 2³². Each key is owned by the first node clockwise from it. The payoff: add or remove a node and only the keys in that one node's slice get remapped — not the whole keyspace — which is why distributed caches, sharded databases and load balancers rely on it.

Click the ring to add a node · click a node marker to remove it · hover or drag across a slice to see what it owns.

Try this: with 1 virtual node per server the slices are lumpy — watch the load bars. Drag virtual nodes up and the bars flatten as each server scatters into many small arcs (the load spread falls toward 0%). Then add or remove a node: the Last remap readout shows only ≈ 1 / N of keys move — highlighted on the ring — versus plain hash mod N where almost everything reshuffles. The same trick shards Memcached/Redis clients, partitions Cassandra and DynamoDB, and routes requests across CDN nodes and load balancers.