CodePark/ questions / Caching layers & CDNs
START PRACTICINGPRACTICE
Backend question · System design & architecture › Caching layers & CDNs

A cache cluster routes keys with hash(key) % N. You grow it from 4 to 5 nodes. Roughly what fraction of keys now map to a different node?

About 80%

About 80% of keys move. A key stays on the same node only when h % 4 == h % 5. This is true for only 4 out of every 20 hash values (0, 1, 2 and 3). So about 80% of keys move, and the cache becomes mostly cold (empty of useful data).

"About 20%" is tempting, but that is what consistent hashing would move: about 1/5 of the keys. This big difference is exactly why caches use consistent hashing.