Intermediate · INTERACTIVE LESSON
Consistent hashing
Follow clockwise key ownership and compare remapping with modulo hashing as nodes join or leave.
The interactive player is loading. If it does not appear, you can still read the explanation below.
THE IDEA BEHIND THE STEPS
How it works
A consistent-hash ring places both keys and virtual-node tokens in an ordered hash space. A key belongs to the first token at or clockwise after its hash. Beyond the last token, wrap to the first. Multiple tokens belong to one physical node; they are not replicated copies of data. With no nodes, keys are unassigned.
This bounded teaching model hashes ASCII text by starting h=0 and applying h=(31h+character code) mod 100. Keys are hashed directly; virtual tokens use node:replica, with replicas numbered 1–4. Tokens sort by position, ASCII physical-node name, then replica number. On a collision, the first token in that order wins the interval; later colliding tokens may own no keys. The Token collisions preset uses Aa and BB, which collide for corresponding replicas. The Wraparound preset places key c at 99 beyond A:1 at 12.
Each membership change is atomic. Walk through its before and after placement and then inspect each key. Adding an existing node, removing an absent node, or adding beyond five active nodes leaves membership unchanged with an explanation. Keys remain fixed throughout a run. Apply scenario creates a new run; results shown while editing belong to the last applied scenario.
The modulo comparison hashes exactly the same keys with exactly the same hash function and uses hash(key) % N into ASCII-sorted physical nodes. Ring and modulo counters count physical-owner differences for the latest membership change, not cumulative traffic or bytes. Initial placement counts zero. Transitions between unassigned and assigned count as owner changes but are not actual data transfers. Per-node key counts expose skew; they are not request rates or server capacity.
Adding a node changes ring ownership only for keys taken by the added node. Removing a node changes only keys it owned. Modulo membership changes can affect many keys. A small sample need not favor the ring. More virtual nodes can improve distribution with suitable hashes and enough keys, but neither virtual nodes nor this intentionally small polynomial hash guarantees balance. Compare one and four tokens on the same key set.
This is placement, not replication, availability or durability. No storage copying, migration protocol, concurrent membership views, failure detection, network timing or production throughput is modeled. A real implementation must decide how to migrate data and maintain consistent membership views. This simulator rebuilds and sorts tokens and copies snapshots for replay; playback speed is not algorithm runtime.