Consistent hashing
The classic way to split is computing hash(key) % N, where N is the number of nodes. The problem shows up when adding or removing a node: N changes and almost every key moves to another node. With 4 nodes, going to 5 moves about 80% of keys. It's like numbering seats by guest count: if 1 more arrives, almost everyone has to change seats. Moving that much data is very inefficient.
Consistent hashing is a scheme that doesn't depend on the number of nodes: it places each node at a position on an abstract circle, the hash ring. That way servers can be added or removed without rearranging every key or touching every server. Only K/N keys need to move, where K is the number of keys and N the number of nodes. It's like kids in a circle: if a new one joins, only those next to them shift.
The ring's big advantage shows when the number of nodes changes. If a node is added, it only receives the keys between it and the previous node; the rest stays the same. If one is removed, its keys go to the next one on the ring. In both cases only a fraction moves. It's like a round table: if someone joins, only the 2 people next to them shift.
The ring also helps with replication: each piece of data is copied to the next N nodes clockwise, so if 1 fails, the copy is on its neighbor. Consistent hashing is used by systems like Amazon DynamoDB, Apache Cassandra, Discord and Akamai's CDN. It's like leaving a spare house key with the neighbor on your right and the next one: if one isn't home, the other lets you in.
