System Design · Architecture under constraints
How does consistent hashing work and why is it useful?
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.
hash("user:42") -> position on ring
walk clockwise -> first node position
that node owns the keyVirtual 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.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1Why does modulo hashing cause so much remapping?
- 2How many virtual nodes would you use and why?
- 3Does consistent hashing solve hot-key problems?
- 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.