workshop

← all creations

Ring

viz · created 2026-09-03

Consistent hashing against the hash-mod-n placement it replaces, over one shared key set — add a node and watch one strip flicker while the other goes solid.

algorithmsarchitecturecanvas

Nine hundred keys, five nodes, and two rules for deciding which node holds which key. hash mod n takes the key’s hash modulo the number of nodes. hash ring scatters every node’s name across a 32-bit circle as a few hundred points, and a key belongs to the first point clockwise from where its own hash lands.

Both are drawn over the same key set, so the comparison is honest. Then add a node.

The two strips under “keys that changed node” are the piece. One cell per key, lit if that key changed hands. The ring’s strip flickers — around 1/n of the circle belonged to spans the new node’s points just took over, and nothing else was touched. The modulo strip goes almost solid, because the divisor changed and every key’s arithmetic changed with it. Roughly 12% against 84%, which is the difference between a rebalance and a full cache eviction.

Two more things fall out that the one-line summary never mentions:

Balance is what the ring pays. Drag points/node down to 1 and the circle becomes five fat wedges of wildly unequal size — one node holding 39 keys while another holds 265. Virtual points exist to fix exactly this, and the “worst vs even share” readout shows the lumpiness draining away as you drag back up: ~80% at one point per node, single digits by 240. Modulo never has this problem, and never has the other one either. That is the actual trade.

The ring depends on the node set; modulo depends on the node order. Remove a node and add it straight back — − node picks a random one, so the re-added name usually lands at a different index in the node list. The ring returns to a placement it has held before and says so; modulo moves another 78% of the keys getting somewhere it has never been. Same membership, same count, different arrangement, and only one of the two rules cares.

The running totals at the bottom are where it stops being a debate. Thirteen node changes in, the ring has relocated ~3,100 keys and modulo ~8,100 — and those keys are cache entries, shard contents, session state, whatever the placement was actually deciding.

Reuse

src/ring.js is a framework-free ES module, no dependencies:

No rendering and no timers in the module; the canvas demo is reference code.

Gotchas