Try
↑ ↓ move↵ openesc close

Interview prep / Consistent hashing

Senior · Consistent hashing · System design interview question

A cache fleet of 1,000 nodes uses a ring with 100 virtual nodes each, and the busiest node holds about 30 percent more keys than average. The team proposes 1,000 virtual nodes. Evaluate the proposal.

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

A strong answer

First check that the observation matches theory. A node with V points has a relative load spread of about 1 / √V, which is 10 percent for V = 100. Among 1,000 nodes the busiest is about 3.2 standard deviations above the mean, so roughly 1 + 3.2 × 0.10 = 1.32. The 30 percent is expected, not a bug.

At V = 1,000 the spread drops to 3.2 percent and the busiest node to about 10 percent above average. That helps, but the cost grows tenfold. The ring goes from 100,000 to 1,000,000 entries. At 16 bytes an entry that is 16 MB in every client, and every membership change rebuilds it. A node joining takes many tiny ranges from many sources, which is harder to stream and track than a few large ones.

Alternatives to weigh:

  • Provision memory 30 percent above average and accept the imbalance. This is cheap if memory is cheap.
  • Use consistent hashing with bounded loads, which caps every node at a chosen multiple of the average and gives a provable bound.
  • Use a precomputed table such as Maglev's, which balances almost perfectly.

Whichever you choose, remember that this is key balance. Hot keys and request balance are separate problems, so check request rates per node before spending on key balance.

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