Try
↑ ↓ move↵ openesc close

Interview prep / Consistent hashing

Senior · Consistent hashing · System design interview question

You are designing partitioning for a distributed key-value store that must grow and survive node failures without downtime. How do you use consistent hashing, and what else do you need?

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

A strong answer

Use a ring with virtual nodes so that adding or removing a node moves a small, spread-out share of the data and load stays reasonably even. Weight virtual node counts by machine capacity.

Then cover what the ring does not provide:

  • Replication on the next distinct physical nodes clockwise, respecting racks or zones.
  • Membership and failure detection, so every node has a consistent enough view of the ring. Gossip is a common mechanism.
  • Data movement when membership changes: stream the affected ranges to new owners in the background, throttled so that it does not hurt foreground traffic, and only switch ownership when the data is there.
  • Handling temporary failures separately from permanent ones, so a brief outage does not trigger a full rebalance.
  • Hot keys, which hashing cannot spread. Use caching in front, splitting a key into parts, or special handling.
  • Operational visibility: per-node key counts, request rates, and the imbalance over time.

Pin down the consistency model and how clients find the ring, since the ring alone answers neither.

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