Aller au contenu principal

Everyone Picks the Same Winner: Rendezvous Hashing

· 9 minutes de lecture
Clustron Team
Ingénierie des systèmes distribués

Every distributed store has to answer one question before it can do anything with a key: which node owns it? The answer has to be the same answer on every client and every node, computed independently and without coordination, or a request cannot be routed in a single hop and two nodes might both think they own the same data. Fixed hash slots and the consistent-hashing ring are the two placement schemes most stores reach for, and both work — but there is a third that is simpler than either, and it comes with a rebalancing property the ring has to work hard, with virtual nodes, to imitate.

It is called rendezvous hashing, or highest-random-weight (HRW) hashing, and the whole idea fits in one sentence: for a given key, compute a score from the pair (key, node) for every node in the cluster, and the node with the highest score owns the key. That is the entire mechanism. There is no ring to place tokens on, no slot table to assign and hand out, no virtual nodes to tune — just a scoring function and a max.

What makes it work as a distributed placement scheme is that every participant computes the same scores. Given the same key and the same membership list, a client in one data center and a node in another independently run hash(key, node) for each node, take the maximum, and land on the identical owner. The agreement is not negotiated; it is a mathematical consequence of running the same function over the same inputs.

The mechanism, and why the winner is stable​

To place a key, you iterate every node, mix the key and the node's identity into a hash, and keep the node whose hash came out largest. The hash spreads keys uniformly across nodes because, for a well-distributed hash, each node is equally likely to be the top scorer for any given key.

// Rendezvous hashing: the owner is simply the highest-scoring node.
Node Owner(string key, IReadOnlyList<Node> nodes) {
Node best = null; ulong bestScore = 0;
foreach (var n in nodes) {
ulong score = Hash64(key, n.Id); // deterministic per (key, node)
if (score > bestScore) { bestScore = score; best = n; }
}
return best; // everyone computes the same winner
}

The interesting property is what happens to that max when membership changes, because that is where placement schemes live or die. Remove a node and the only keys affected are the ones it actually owned — for every other key, the winner was some other node, and removing a loser cannot change which node had the highest score. The orphaned keys do not pile onto one neighbor either: each independently falls to whichever surviving node had the second-highest score, and since those second-place finishers are themselves uniformly distributed, the departed node's load scatters evenly across all the survivors. Add a node and it becomes the winner only for the keys where its score now beats every incumbent — roughly 1/N of all keys, pulled evenly from every existing node. In both directions, the amount of data that moves is the theoretical minimum, with no virtual nodes required to smooth it out.

score = hash(key, node) — highest wins; the ranking is the replica ordernode Areplica 3node Bwinner → replica 1 (owner)node Creplica 4node Dreplica 2 (first failover)remove B and this key re-homes to D, its next-highest score — and no other key movesevery node computes the same four scores, so every node agrees on the same ranking

Replica placement for free​

A store almost never wants just the owner — it wants a set of replicas and an order to try them in. Rendezvous hashing hands this over with no extra machinery: instead of taking only the top scorer, take the top K scorers, and those are the K replicas. Better still, they come ranked — highest score is the primary, second is the first failover, and so on down a deterministic preference list that every node computes identically.

That ranked list is exactly what failover and recovery want. When the primary is down, the next-highest scorer is the agreed-upon place to go, with no election and no lookup — and a node rebuilding an owner from its replicas knows precisely which nodes should hold the copies because it can recompute the same top-K for every key. The preference list also degrades gracefully under partition cutover: removing a node simply shifts every key that named it up one slot in its own ranking, which is the minimal, local change you want.

Weights for uneven hardware​

Real clusters are not uniform — some nodes have more memory or faster disks and should own proportionally more data. Plain rendezvous hashing splits load evenly, which is wrong when capacity is not. Weighted rendezvous hashing fixes this by transforming the raw hash into a score whose distribution is biased by a per-node weight, so a node with twice the weight wins roughly twice as many keys. The transform (a standard form maps the hash into the unit interval and scores it as weight / -ln(h)) preserves the two properties that matter: the ranking is still deterministic across all participants, and a membership change still moves only the minimum set of keys. It is the placement-layer answer to capacity skew, complementary to how a store handles a hot key at the access layer.

The one real cost​

Nothing is free, and rendezvous hashing's price is on the lookup: scoring every node is O(N) per key, where a ring lookup is O(log V). For clusters of tens to a few hundred nodes this is a handful of hash computations and genuinely negligible — the scores can even be cached per key. It stops being negligible at very large scale, which is where hierarchical (skeleton) rendezvous hashing comes in: arrange nodes into a tree and score level by level, which recovers an O(log N) lookup while keeping the near-ideal rebalancing. For most stores the flat version is more than enough, and its simplicity — one function, no token map to distribute, replica order included — is worth more than shaving a few microseconds off a routing decision.

Wrap-up​

Rendezvous hashing routes a key by scoring every node with hash(key, node) and picking the maximum, and because every participant runs the same function over the same membership, they all reach the same owner with no coordination and no shared token table. Its rebalancing is near-ideal: a departure moves only the departed node's keys, spread evenly to second-place finishers, and an arrival claims only its fair new share. Take the top K scorers and you have a ranked replica set and a failover order for free; weight the scores and uneven hardware falls into line. The cost is an O(N) lookup, which is nothing until the cluster is large and, even then, a tree brings it back to O(log N). For a store that would rather compute its placement than distribute and maintain it, that is a very good trade.