Consistent Hashing Visualizer — Ring, Virtual Nodes, Key Moves
- This tool runs entirely in your browser. Nothing you enter or upload is sent to a server.
Cluster
- Node A
- Node B
- Node C
Hash ring
Ticks are virtual nodes; dots are keys, coloured by the node that owns them. A key belongs to the first tick clockwise from its hash.
Keys per node
| Node | Keys | Share | Share bar |
|---|---|---|---|
| Node A | 131 | 65.5% | |
| Node B | 53 | 26.5% | |
| Node C | 16 | 8% |
Largest node holds 65.5% of keys, smallest 8%. More virtual nodes even out the ring: each node then owns many small arcs instead of a few big ones.
Last change
Add or remove a node to see how many keys move.
About this tool
Consistent hashing answers one question: when you spread keys across a set of servers and a server joins or leaves, how many keys have to move? With the obvious scheme, hash(key) mod N, almost every key changes server when N changes, because the remainder of nearly every hash changes. With a hash ring, both servers and keys are hashed onto a circle and each key belongs to the first server clockwise from it, so adding a server only takes keys from its neighbour and removing one only hands its keys to the next server round. Roughly 1/N of the keys move instead of nearly all of them.
This visualizer draws the ring. Each node owns a number of virtual nodes, which are extra points on the circle; the slider sets how many. With a handful of virtual nodes per server the ring is lumpy and one server can own half the keys by bad luck, as the default of 10 often shows. Slide up to 50 or 100 and the shares even out; the node table under the ring shows the count and percentage each node holds plus a balance line with the largest and smallest share. Press Add node or remove one and the Last change panel reports exactly how many of the keys changed owner, next to how many would have changed under hash mod N with the same key set.
Try it with 200 keys and 3 nodes. Adding a fourth moves roughly a quarter of the keys, all of them to the new node, while mod N would have moved about three quarters. Removing a node moves only the keys that node held. That property is why memcached clients, Cassandra, DynamoDB and most CDNs use a ring: a cache does not empty itself when one server is replaced, and a database can grow a node at a time without a global reshuffle. Hover any key to see which node owns it.
The hashes are real: every position comes from FNV-1a, a fast non-cryptographic hash, applied to the node name plus the virtual node index or to the key. Nothing is random, so the same inputs always produce the same ring and the counts you see are reproducible in an interview answer. The demo runs entirely in your browser.
| Nodes before | Consistent hashing | Hash mod N |
|---|---|---|
| 2 | about 33.3% | about 67% |
| 3 | about 25% | about 75% |
| 4 | about 20% | about 80% |
| 5 | about 16.7% | about 83% |
| 8 | about 11.1% | about 89% |
| 10 | about 9.1% | about 91% |
| 20 | about 4.8% | about 95% |
Frequently asked questions
Why do virtual nodes matter?
A single point per server leaves the ring unevenly divided, so one server can take far more than its share. Many points per server average out the gaps, and they also let a bigger server take more points and therefore more keys. 100 to 200 virtual nodes per server is a common choice.
How many keys move when a node is added?
On average 1 ÷ (N + 1) of them for N existing nodes, and every moved key goes to the new node. Removing a node moves only the keys that node held, about 1 ÷ N of the total, to its clockwise neighbours.
Is consistent hashing the same as rendezvous hashing?
No. Rendezvous (highest random weight) hashing scores every node for each key and picks the top score; it has the same minimal-movement property without a ring, at the cost of hashing against every node per lookup. Rings are faster to look up with many nodes; rendezvous is simpler with few.
Which systems use consistent hashing?
Memcached and Redis client libraries, Amazon DynamoDB and Cassandra for partitioning, Akamai and other CDNs for routing, and load balancers such as Envoy and NGINX for sticky sessions. Anywhere a key must map stably to a server while servers come and go.
Does the hash function matter?
It must be fast and spread values evenly; it does not need to be cryptographic. FNV-1a, MurmurHash and xxHash are typical. Using the same hash on every client is what matters, because two clients that disagree on the ring will route the same key to different servers.