Sharding by key mod n is a disaster: add one server and almost every key remaps. Consistent hashing puts nodes and keys on a ring; a key belongs to the next node clockwise. Add a node and only the keys in its arc move — about 1/n of them. Here adding a node at position 30 moves the key at 15 (from node 50 to 30) but leaves the key at 60 on node 90.
The demo assigns keys to nodes on a ring, then adds a node and checks only the nearby key moved: live demo
“Consistent hashing balances load perfectly.” — a plain ring is lumpy; real systems add virtual nodes (many ring points per server) to smooth it. cited
Elastic sharding with minimal churn. data structure
On i-13 (nodes 10,50,90), adding node 30 moves key 15 (50→30) but key 60 stays on 90: