Why is assigning keys to servers with hash(key) mod N a problem when the number of servers changes?
Sketch your own answer first, then compare it with the one below.
A strong answer
With a fixed N the rule is simple and spreads keys evenly. The trouble is that the answer depends on N itself. Change N and the remainder of almost every key changes, so almost every key maps to a different server.
For a cache, that means a flood of misses at the moment you add or lose a server, all landing on the backing store. For a data store, it means moving most of the data across the network for a small change.
The ideal rule moves only about the share of keys the new server needs, roughly one over the new server count, and nothing else. Consistent hashing achieves this by making a key's owner depend on where the key and the servers sit on a ring, not on how many servers there are.
Mod N is still fine for a cluster whose size almost never changes.
Sources
- David Karger, Eric Lehman, Tom Leighton, Rina Panigrahy, Matthew Levine, Daniel Lewin (1997). Consistent Hashing and Random Trees: Distributed Caching Protocols for Relieving Hot Spots on the World Wide Web.