Try
↑ ↓ move↵ openesc close

Interview prep / Consistent hashing

Mid · Consistent hashing · System design interview question

How would you choose the number of virtual nodes per server? What do you gain and lose by raising it?

Sketch your own answer first, then compare it with the one below.

A strong answer

Raising the count improves balance. The busiest node's share gets closer to the average as more points are averaged. Removal is also gentler, because a failed node's keys spread over many neighbours.

The costs are real:

  • Ring size and memory grow with nodes times virtual nodes.
  • Rebuilding or updating the sorted structure after a change takes longer, and replicating the ring metadata to clients takes more bandwidth.
  • When replicas go on the next distinct physical nodes, more points make the walk to find distinct nodes touch more entries.
  • Rebalancing data when a node joins involves many small ranges from many sources, which can be more operationally complicated than a few large transfers.

The returns diminish: past some point the extra balance is not worth the overhead. A defensible approach is to pick the smallest count that keeps imbalance within a target, measured with your key distribution, and to weight by machine capacity.

Balancing keys is not balancing requests, so hot keys stay a separate problem.

Sources

Learn it by running it

The consistent hashing lesson explains the mechanism behind this question, and its lab lets you change the parameters and watch the effect.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms