Consistent Hashing Playground

Spread keys over a few servers four ways, then add a server or take one away and count what moves. The playground compares modulo hashing, a hash ring with virtual nodes, rendezvous hashing and jump consistent hash, side by side, in your browser.

On a wide screen you can open it full screen.

How to Use It

  1. Set the scene. Pick the number of servers, called nodes here, the number of keys, and how many virtual nodes each server gets on the ring.
  2. Pick a change. Add a node, or remove one.
  3. Read the results. The ring shows each node’s points and a sample of keys, with the keys that moved drawn larger. The table shows, for each method, how many keys moved, how many moved between two nodes that both stayed, and how far the busiest node sits above an even share.
  4. Play with the virtual nodes. Drop them to one per node and watch the ring’s load fall apart, then raise them again.

Why Consistent Hashing Exists

The obvious way to pick a server for a key is modulo: hash the key, divide by the number of servers, keep the remainder. It works until the number of servers changes. Add a sixth server to five and the divisor changes, so about 83% of keys get a new home, most of them moving between servers that never changed. For a cache that’s a flood of misses. For a store it’s data copied across the network for nothing.

Consistent hashing moves only what has to move. Add a sixth server and about a sixth of the keys move, all of them to the new one. The hash ring does it by placing servers and keys on a circle. Rendezvous hashing scores every server for every key and takes the best. Jump hash, a short loop published by Google engineers in 2014, needs no memory at all but can only add or drop its last server. Redis and Valkey clusters get the same effect another way, with 16,384 fixed slots they move between servers by hand.

How It Was Tested

The playground’s MurmurHash3 gave the same hashes as the Python mmh3 package for 10,000 strings, and its jump hash the same buckets as the code printed in the jump hash paper for 20,000 keys. With 100,000 keys, the ring, rendezvous and jump hash never moved a key between two nodes that stayed, while modulo moved 67% to 91% of keys. On 10 nodes, the busiest node on the ring held 2.84 times an even share with one virtual node each, and 1.08 times with 160.

The Code

The playground’s logic is one JavaScript file with no dependencies, open source under the Apache License 2.0. It runs as this page, as a command line in Node.js, and inside your own code:

node ring/cli.js --nodes 5 --add

The full manual and the tests are in the ring folder on GitHub. The other tools work the same way.