Which server holds a key
Illustrative exampleNumbers here are illustrative: round figures to reason with, not measurements.
Hash mod N breaks the brief’s first requirement. Going from 60 servers to 61, a key stays put only when both remainders agree, about one key in 61, so about 98% of keys move and nearly every read misses.
Use fixed hash slots: CRC16 of the key, or of its {hash tag}, mod 16384, and a small table from slots to servers (Redis Cluster specification (opens in a new tab)). A key’s slot doesn’t change when servers do. Four new servers each take a few slots from every server, moving about 6% of keys; a dead server’s slots, about 1/60 of the keys, go to the others. A ring with many points per server, or rendezvous hashing, passes too.
| Compared on | Hash mod N | Ring | Fixed slots | Rendezvous |
|---|---|---|---|---|
| Keys moved when one server joins 60 | About 98% | About 1/61 | About 1/61 | About 1/61 |
| Even load | Yes | With many points per server | Yes; slots can be moved | Yes |
| Moving load on purpose | Not possible | Awkward | Easy: move a slot | Awkward |
- A service stores
user:42: CRC16 gives slot 15880, and the table says server B owns it. - Every reader computes the same slot, so it asks server B too.
- Server B dies: its slots go to the others, and only its keys change owner.
Read:Learn: Partitioning, sharding and consistent hashingLearn: Redis
Keep reading+1 min
Why a ring needs many points per server
With one point per server, the arcs between neighbours vary a lot, so some servers own several times what others do. Hashing each server to, for example, a couple of hundred points evens the arcs out, and a new server takes a little from every server instead of everything from one neighbour.
Jump consistent hash
Jump hash maps a key to one of N numbered buckets with no table at all (Lamping and Veach (opens in a new tab)). Its catch is that buckets must be numbered in sequence, so removing one in the middle needs a table from buckets to servers anyway; the paper says it suits data storage better than web caching.