Build a hash ring that distributes keys across nodes uniformly and minimizes key migration when the cluster topology changes. Naive modulo hashing remaps almost every key on each change — consistent hashing limits disruption to only 1/N of keys.
1. The Ring. Imagine a circle from 0 → 2³². Every node and every key is hashed onto this circle. A key "belongs" to the first node it encounters walking clockwise.
2. Virtual Nodes. Each physical node occupies 100–200 positions on the ring (with suffixes like node-A#42). This smooths out distribution dramatically.
3. Minimal Disruption. When you add or remove a node, only ~1/N of keys need to move — the ones that were "owned" by that node. With modulo hashing, almost all keys remap.
Add a node to the ring with virtual node positions. Should be idempotent.
Remove a node. Only its keys should move to the next clockwise node. No-op for unknown nodes.
Return the responsible node. Must be deterministic. Return None / null on empty ring.
| Metric | Yours | Ideal |
|---|
10 functional checks covering CRUD, edge cases, and determinism.
| Test | Got | Expected |
|---|
10,000 keys across 10 nodes. Lower CV = more uniform.
The hardest phase — how many keys move when the ring changes?
50 nodes, 20K lookups — does the ring hold up at scale?
3,000 get_node calls benchmarked with microsecond precision.