Try
↑ ↓ move↵ openesc close

Interview prep / Consistent hashing

Junior · Consistent hashing · System design interview question

What are virtual nodes in consistent hashing, and what problem do they solve?

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

A strong answer

A virtual node is one of several points a physical node places on the ring, typically by hashing the node's name together with a counter.

With one point per node, the gaps between points are random lengths, so some nodes own long arcs and many keys while others own short arcs and few. Load is uneven by luck alone.

With many points per node, each node owns many small arcs scattered around the ring. Random variation averages out and each node's total share gets closer to fair. A leaving node also hands its keys to many different neighbours instead of one, so no single survivor takes the whole load.

Virtual nodes also let you weight nodes: give a more powerful machine more points.

The cost is a larger ring to store and update, and more work to rebuild after a change.

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