Imagine you run a big web cache. You have n servers, and for each key you decide where it lives with the obvious trick: server = hash(key) mod n. Cheap, fast, evenly spread. Then one server dies, or you add a new one — and n changes.
Now almost every key maps somewhere new. A cache that was warm goes cold all at once; databases stampede; users wait. Changing a single machine should not reshuffle the whole world, yet plain modulo hashing does exactly that.
Consistent hashing fixes this with one beautifully simple move: instead of dividing by n, place both servers and keys on a circle. Add or remove a server and only the keys in its immediate neighborhood — about 1/n of them — ever have to move.
Comments
Loading comments...