Consistent hashing
Consistent hashing explained: why hash-mod-N breaks when servers change, the hash ring, how adding or removing a node moves only a small share of keys, virtual nodes for balance, replication, a working Python implementation, and where it is used in practice.
CodexBash, , 5 min read
When data is spread across several cache or database servers, each key must go to a predictable server. The obvious method, hash(key) % N for N servers, works perfectly until N changes. Add a fifth server to four, and almost every key now maps somewhere different, so a cache cluster suddenly misses nearly everything and floods the database. Consistent hashing is the technique that lets servers join and leave while moving only a small fraction of keys. It underpins distributed caches, Cassandra, DynamoDB-style stores and many load balancers. This article explains it and builds one.
Sign in to read the rest
The whole 5 minute article is free with an account, along with every problem, lesson and tutorial. No card.