core practice · system design prompt

Consistent-hash key router

Design a key router for a sharded cache using consistent hashing with virtual nodes. Show how add/remove of a node redistributes keys.

The mechanism

Consistent hashing maps both servers and keys onto a ring so that when you add or remove a server, only about 1/N of the keys move (instead of nearly all of them). Use "virtual nodes" — multiple ring positions per server — to spread load evenly.

Study Consistent Hashing

Expected evidence

Ring diagram + the algorithm for routing a key + the % of keys that move when N→N+1 nodes.

Try this drill in the practice workspace →

Hints when you need them
  • Without vnodes the distribution is lumpy.
  • Hash the node id with k different seeds for vnodes.

Check the sources

Browse all practice briefs