In this lesson · topic 6 of 7
Topic 6
Rendezvous hashing and Maglev tables
7 min read
A ring is one way to keep ownership stable while membership changes. Two other designs reach the same goal with a different structure, and each fixes a problem the ring has.
Rendezvous hashing: highest score wins
For a key, compute a score for every node, such as hash(key, node). The node with the highest score owns the key. There is no ring and no virtual nodes. Every client with the same node list computes the same winner.
When a node leaves, a key moves only if that node was its top scorer, and it then goes to its second-best. All other keys keep their winner. When a node joins, a key moves only if the newcomer’s score beats its current winner’s, which happens to about 1 key in N + 1. Balance is even in expectation, with no virtual-node tuning, because every key makes an independent draw.
The price is the lookup. A ring lookup is a binary search over the points. Rendezvous computes a hash for every node, so 8 nodes means 8 hashes per lookup and 1,000 nodes means 1,000. That is fine for small clusters and costly for large ones.
Two things come easily. Replication: take the top k scorers, and they are k distinct nodes with no skipping of repeated points. Weights: use the score −w / ln(h), where h is a uniform hash in (0, 1) and w is the node’s weight. A node then wins with probability w divided by the sum of weights, so a node with weight 2 gets twice the keys.
Predict first
The scheme comes from Thaler and Ravishankar, who called it highest random weight hashing.
Maglev: a table with near-perfect balance
The Maglev software load balancer needs two things. Backends must get very even shares of connections, and a change in the backend set should disturb few flows. Its answer is a lookup table.
Choose a prime table size M. In the paper’s experiments it is 65,537 by default, or 655,373 for the larger setting. Each backend gets its own order of preference over table slots, built from two hashes of its name, an offset and a skip: its i-th preferred slot is (offset + i × skip) mod M. Because M is prime, the order visits every slot. Backends then take turns. Each claims its next preferred slot that is still free, until the table is full.
Turn-taking is what produces the balance. Every backend claims within one slot of the same number of entries. With M = 65,537 and 1,000 backends, each gets 65 or 66 slots. A packet’s flow hash picks a slot, and the slot names the backend. Lookup is one array read.
The paper compares this with Karger-style rings and rendezvous hashing at M = 65,537 and 1,000 backends. To carry the imbalanced traffic, the ring and rendezvous clusters would need to be overprovisioned by 29.7 and 49.5 percent. Maglev needs almost none.
The cost moves to membership change. When a backend fails, the table is rebuilt, and some entries that did not belong to the failed backend change. A larger table changes fewer entries, but building it takes longer, from 1.8 ms at 65,537 slots to 22.9 ms at 655,373. Maglev accepts the disturbance because each balancer also keeps a connection-tracking table, which pins existing flows to their backend.
Sources
- David G. Thaler and Chinya V. Ravishankar, Using Name-Based Mappings to Increase Hit Rates, IEEE/ACM Transactions on Networking, 1998.
- Daniel E. Eisenbud and colleagues, Maglev: A Fast and Reliable Software Network Load Balancer, USENIX NSDI, 2016.