Scrivio Interview library
ConceptIntermediate7 min read · updated 12 November 2026

Compare consistent hashing with virtual nodes, rendezvous (highest random weight) hashing and jump consistent hashing for choosing a cache or shard node. Where would you use each?

A ring with virtual nodes is the well-known choice: it supports weights and the removal of any node, but memory and lookup cost grow with the number of virtual points. Rendezvous hashing scores every node with hash(key, node) and picks the highest, giving an even spread and minimal movement with no ring, at O(N) per lookup, which is fine for tens of nodes. Jump consistent hash needs no memory and runs in O(log N), but nodes are numbered 0 to N-1 and can only be added or removed at the end, which suits shard numbers better than cache hosts. All three move about 1/N of the keys when N changes.

Why this question is asked

Once we know that hash(key) % N moves most keys when N changes, the next question is which alternative to use. There are three classic answers, and each fits a different situation. Interviewers ask this comparison to see whether we understand how each algorithm works well enough to reason about its limits, rather than reaching for the ring every time. In this answer, we will recap what all three guarantee, explain each algorithm with code, compare them, and work out where each one fits.

1What All Three Guarantee

Each algorithm maps a key to one of N nodes so that keys spread evenly and, when N changes by one, only about 1/N of the keys change owner. That is the property modulo hashing lacks: going from 10 to 11 nodes with % N moves about 91 percent of keys, while any of these three moves about 9 percent. They differ in memory, lookup speed, support for weights, and above all in which nodes can be removed.

2A Ring With Virtual Nodes

The ring places each node at V points on a circle of hash values and assigns each key to the first point clockwise from its hash. It is stored as a sorted map from position to node, so a lookup is a binary search, O(log(N*V)), and memory holds N*V entries. Any node can be removed: its points disappear and its keys pass to the next points clockwise, which belong to many different nodes. Weights are natural: a node with twice the capacity gets twice the points. This flexibility is why the ring is used by Cassandra, many memcached clients and Envoy's ring hash load balancer. Its costs are the memory for the points, a few hundred thousand entries for a large cluster, and a slightly uneven split unless V is large.

3Rendezvous Hashing

Rendezvous hashing, also called highest random weight hashing, needs no ring at all. For a key, we compute a score for every node, hash(key, node), and pick the node with the highest score. Every client computes the same scores, so they all agree.

Java
String rendezvous(String key, List<String> nodes) {
String best = null; long bestScore = Long.MIN_VALUE;
for (String node : nodes) {
long score = hash64(key + "|" + node); // a well-mixed 64-bit hash
if (score > bestScore) { bestScore = score; best = node; }
}
return best;
}
// nodes [a, b, c]: scores for "user-42" a=17, b=93, c=41 (illustrative) -> b
// remove b: highest of the rest is c -> only keys that were on b move

Notice why movement is minimal. When a node is removed, a key whose winner was another node keeps that winner, because its score did not change and it was already the highest. Only keys that were on the removed node move, each to its second-highest node, which spreads them evenly over the survivors. When a node is added, it wins only the keys for which its new score is the highest, about 1/(N+1) of them. Weights are possible with a scoring formula that scales by node weight. The cost is O(N) hashing per lookup: trivial for 10 or 50 nodes, noticeable for thousands of nodes at high request rates.

4Jump Consistent Hash

Jump consistent hash, published by Lamping and Veach at Google, maps a 64-bit key to a bucket number from 0 to N-1 using a short loop and no memory at all.

Java
static int jump(long key, int buckets) {
long b = -1, j = 0;
while (j < buckets) {
b = j;
key = key * 2862933555777941757L + 1; // linear congruential step
j = (long) ((b + 1) * ((double) (1L << 31) / (double) ((key >>> 33) + 1)));
}
return (int) b;
}
jump(hash64("user-42"), 10); // a bucket in 0..9
jump(hash64("user-42"), 11); // the same bucket, or 10 for about 1 key in 11

The idea is that as the bucket count grows from 1 to N, each key 'jumps' to the new bucket with probability 1/(new count), and the loop skips ahead directly to the next jump, so it runs in O(log N) steps. The result is an almost perfectly even split with no stored state. But there is a hard restriction: buckets are numbered, and the only changes that preserve the guarantee are adding bucket N or removing the last bucket. If bucket 3 out of 10 fails, we cannot remove just bucket 3. So jump hash suits cases where the numbers are stable, such as shard ids in a storage system that maps shard numbers to replicated servers, rather than individual cache hosts that come and go.

5Comparing Them

Put side by side, the differences come down to state, lookup cost and which changes they allow.

Ring, rendezvous and jump hashing
PropertyRing + virtual nodesRendezvous (HRW)Jump consistent hash
Lookup costO(log(N*V))O(N)O(log N)
MemoryN*V pointsNode list onlyNone
Remove any nodeYesYesNo, only the last bucket
WeightsMore points per nodeWeighted score formulaNot directly
BalanceGood with large VVery goodNear perfect
Keys moved when N changesAbout 1/NAbout 1/NAbout 1/N

6Where Each One Fits

For a cache cluster or a set of service instances, where any host can fail or be replaced at any time and hosts may differ in size, I would use rendezvous hashing when the node count is in the tens, because it is simple, needs no ring, and spreads a failed node's keys evenly. For hundreds or thousands of nodes, or very high lookup rates, I would use a ring with virtual nodes, because lookups stay logarithmic.

For mapping keys to shard numbers in a storage system, where the shard count grows deliberately and shards themselves are replicated so they never simply disappear, jump hash is excellent: tiny, fast and perfectly balanced. The usual design is jump hash from key to shard number, then a separate table from shard number to the servers holding it, so a failed server is replaced inside the shard without changing any key's shard. The choice therefore depends on node churn, the number of nodes, and whether arbitrary nodes can fail.

7Follow-up questions

Can rendezvous hashing scale to many nodes?

Yes, with a hierarchy: group nodes into, say, 30 groups, pick a group by rendezvous, then a node within the group by rendezvous. Lookups cost O(groups + group size) instead of O(N), while keeping minimal movement.

Why does jump hash need a 64-bit integer key?

The algorithm uses the key as the seed of a random number generator, so it needs a number. Strings are first hashed to 64 bits with a well-mixed hash, and the quality of that hash still matters.

Which of these does a load balancer use?

Several. Envoy, for example, offers ring hash and Maglev, which is a table-based variant designed for fast lookups and even balance with minimal disruption. The same trade-offs apply.

8Conclusion

In this answer, we compared three consistent hashing algorithms that all move about 1/N of keys when N changes. The ring with virtual nodes supports weights and arbitrary removal at the cost of memory and logarithmic lookups. Rendezvous hashing scores every node and picks the highest, with even spread and minimal movement but O(N) lookups, which suits tens of nodes. Jump consistent hash uses no memory and O(log N) time but only allows adding or removing the last bucket, so it suits numbered shards rather than cache hosts.

What to say in the interviewAbout 100 seconds aloud

Open with

All three solve the problem that hash mod N moves most keys when N changes; each moves only about 1/N. The ring with virtual nodes places every node at many points on a hash circle and gives a key to the next point clockwise.

Then, if they want more

It is well known, supports weights by giving bigger nodes more points, and any node can be removed, with its keys spreading over many neighbours. The cost is memory, N times V points, and a logarithmic lookup. Rendezvous hashing has no ring: for each key I score every node with hash of key and node and pick the highest.

Removing a node only moves the keys it owned, each to its second-best node, so the spread stays even, but the lookup is O(N), which is fine for tens of nodes.

Jump consistent hash is a tiny loop with no memory and O(log N) time and near-perfect balance, but nodes are bucket numbers 0 to N minus 1 and I can only add or remove at the end, so I can't take out node 3 when it fails.

So for a cache cluster with tens of hosts that can fail anytime, I'd pick rendezvous; for hundreds of hosts or very hot lookups, a ring with virtual nodes; and for mapping keys to shard numbers in a storage system, where shards are replicated and grow deliberately, jump hash, plus a table from shard number to servers.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Compare consistent hashing with virtual nodes, rendezvous (highest random weight)...": https://scrivio-interview-library.netlify.app/databases/partitioning-and-sharding/529f206a12/