AI System Design
← Learn
Level 2intermediate

Consistent Hashing

You have 4 servers and 10,000 keys. Now add server #5.

Depth:
1

Mission

You're distributing cache keys across servers. With plain modulo hashing, adding one server reshuffles almost everything. Find a better way.
2

Interactive Simulation

Before we explain anything — play. Push it until it breaks, then fix it.

BAC3 servers200 keys

Membership

3 servers

Tuning

More virtual nodes even out how many keys each server owns, reducing hot spots.

Load distribution

busiest = 2.25× avg
A
150
B
49
C
1
3

What just happened?

With modulo hashing, changing the server count changed key % N for nearly every key, so most keys moved. With consistent hashing on a ring, adding a server only reassigns the keys in its arc — a small fraction move.

4

The concept

Consistent hashing places both servers and keys on a circular hash ring. Each key belongs to the next server clockwise. When you add or remove a server, only the keys between it and its neighbor move — roughly 1/N of keys — instead of nearly all of them. Virtual nodes (multiple ring positions per server) even out the distribution and reduce hotspots.

5

Trade-offs

Nothing is free. Here's what this solution costs you.

Uneven load
Few nodes without vnodes → lopsided arcs and hotspots.
Metadata
Virtual nodes multiply ring entries and lookup structures.
Still moves some data
~1/N of keys still relocate on membership change.
6

In the real world

Conceptually similar to key distribution in Dynamo-style stores and distributed caches.

7

Mini quiz

Question 1 of 30 correct

Adding one server to N with consistent hashing moves roughly…

8

Interview me

The app becomes your interviewer. One question, in your own words.

9

Boss challenge

Rebalance with minimal movement

Scale your cache tier from 3 to 6 nodes.

Goal: Reach 6+ nodes, move under 25% of keys on the last change, and keep the busiest node within 30% of average.

Use the simulator above with no hints. These checks update live as you play.

10

Interview question

“Explain the ring, why only 1/N of keys move, what virtual nodes solve, and where you'd use consistent hashing in a real system.”

Next: Unique ID Generator