Try
↑ ↓ move↵ openesc close

Interview prep / Consistent hashing

Mid · Consistent hashing · System design interview question

You maintain a group of 12 proxies and must route each client id to one of them. Two proxies have twice the CPU of the others. Would you use a ring with virtual nodes or rendezvous hashing?

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

A strong answer

For 12 nodes I would choose rendezvous hashing.

Rendezvous scores every node for the key with hash(key, node) and picks the highest. With 12 nodes that is 12 cheap hashes per lookup. It needs no ring and no virtual-node count to tune. When a proxy leaves, only the keys it won move, and each goes to its runner-up.

Weights are exact. Use the score −w / ln(h), where h is the hash scaled to (0, 1) and w is the node's weight. A node then wins with probability proportional to w, so the two big proxies take twice the share of the others, with no rounding.

On a ring, weights are expressed by giving a node proportionally more points. Balance then depends on the point count, since the load of a node varies like one over the square root of its points. To get the weights right within a few percent you need hundreds of points per node, and a ring to store and rebuild.

The ring wins when the node count is large. A lookup that is a binary search over points beats hashing 1,000 nodes for every key. At very high lookup rates, a precomputed table such as Maglev's gives constant-time lookups and near-perfect balance, at the cost of rebuilding it on 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