The Desi Architect
Notes / Docker Sandboxes / Consistent Hashing Ring with Virtual Nodes
Docker Sandboxes · Tier 2: Data & Scale · Lab 25

Consistent Hashing Ring with Virtual Nodes

Add a fifth cache server and watch what happens to your keys. With hash % N almost everything moves. With a consistent hash ring about a quarter moves. See it first as numbers, then on four real Redis servers as a hit rate.

Time30 minutes
StackPython 3Ports 16385-16388
MemoryAbout 40 MB
Before thisLab 02Docker Compose in Practice
Verified runWindows, Mac, LinuxBash and PowerShell
  1. 1PrepareWhat you will learn
  2. 2PredictGuess before you run
  3. 3RunStep by step
  4. 4ObserveWhat you should see
  5. 5Break itChange one thing
  6. 6Clean upLeave nothing running
On this page
  1. 00 / What You Will Learn
  2. 01 / Why It Matters
  3. 02 / What We Are Building
  4. 03 / Words You Need
  5. 04 / Predict First
  6. 05 / Step by Step
  7. 06 / What You Should See
  8. 07 / Look Inside
  9. 08 / Break It, Fix It
  10. 09 / In Real Projects
  11. 10 / Interview Corner
  12. 11 / Clean Up

00 /What You Will Learn

By the end you will be able to
  • Explain why hash(key) % N breaks when N changes.
  • Explain a hash ring and how a key finds its server.
  • Explain virtual nodes and why 1 point per server is uneven.
  • Show with real Redis servers that a ring keeps most of the cache hit rate when a server is added.
  • Say what changes when a server is removed.

Before you start

Finish Lab 02 (Docker Compose in Practice) and Lab 06 (Redis Basics) first. You should know SET and GET. Docker Desktop and Python 3 are needed. Nothing else is installed.