Why use consistent hashing to distribute keys across cache nodes?
Options
- It encrypts the keys that are stored in the cache
- A node change remaps only about 1/N of the keys (Correct option)
- It guarantees perfect balance without virtual nodes
- It removes the need for replication entirely
Answer
Adding or removing a node remaps only about 1/N of keys instead of nearly all
Why
With hash(key) % N, adding one server changes N, so almost every key suddenly maps to a different server: the whole cache is effectively lost.
Consistent hashing places servers and keys on a circle; each key goes to the next server clockwise. Adding a server only takes over the keys between it and its neighbor, about 1/N of them.
'Virtual nodes' (several points per server) spread the load evenly.
Remember
Consistent hashing = adding a node moves few keys.