System Design · Architecture under constraints

How does consistent hashing work and why is it useful?

Mediumconsistent hashingvirtual nodespartitioningUpdated Oct 2026
Quiz this track

Short answer

Consistent hashing maps keys and nodes onto a ring so adding or removing a node moves only a small fraction of keys. Virtual nodes improve balance and distribute load.

With modulo hashing, changing the number of nodes remaps almost every key, which is disastrous for caches and shard placement. Consistent hashing places nodes and keys on the same circular hash space. A key belongs to the first node clockwise from its position, so a membership change affects only the adjacent range.

text
hash("user:42") -> position on ring
walk clockwise -> first node position
that node owns the key
Keys and nodes share one hash space. Membership changes move only the keys in the affected arc.

Virtual nodes

  • A physical node is represented by many points on the ring, often 100 or more
  • More points smooth out uneven key distribution and reduce hotspots
  • When a node leaves, its virtual nodes are spread across the remaining nodes
  • Replication places each key on the next N distinct physical nodes clockwise
  • Weighting a node with more virtual nodes gives it more load, which helps heterogeneous hardware

Consistent hashing does not eliminate hotspots. A single very hot key still lands on one node, and a poorly chosen key can overload a shard. It also does not provide strong consistency; replicas still need a quorum or leader protocol. The benefit is minimal data movement and stable ownership during scaling.

Consistent hashing is used in cache clusters, sharded stores and some load balancers. If the key space is small or the node count is fixed, a simple lookup table may be easier to reason about and just as effective.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1Why does modulo hashing cause so much remapping?
  2. 2How many virtual nodes would you use and why?
  3. 3Does consistent hashing solve hot-key problems?
  4. 4How do replicas choose their placement on the ring?

Say it in the interview

Consistent hashing puts keys and nodes on a ring so a membership change only moves the keys in one arc instead of remapping everything. Virtual nodes give each physical node many positions, which balances load and spreads the impact of a departure. It does not fix a single hot key or provide consistency, so those need separate mechanisms. I use it when stable ownership and low data movement matter more than simplicity.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live System Design mock interview and get scored feedback on depth, clarity and confidence.