Moving from a Line to a Circle
The core insight of consistent hashing is to change the topology of the address space from a line to a circle (a ring). Instead of mapping keys to positions 0 through N-1, we map them to positions on a ring that spans the full output range of a hash function — typically 0 to 2³²−1 (about 4.3 billion positions) for a 32-bit hash.
Think of it like a clock face, but with 4 billion tick marks instead of 12.
Placing Servers on the Ring
We hash the servers themselves — using their IP address, hostname, or any stable identifier — and place them at the resulting positions on the ring.
hash("192.168.1.1") → position 10 (Server A)
hash("192.168.1.2") → position 50 (Server B)
hash("192.168.1.3") → position 90 (Server C)
Placing Keys on the Ring
We hash data keys using the same hash function, placing them on the same ring.
hash("user_123") → position 20
hash("session_9") → position 65
hash("order_77") → position 95
The Rule: Clockwise Lookup
To find which server owns a key, start at the key's position and walk clockwise until you reach the first server.
"user_123" at 20 → clockwise → Server B at 50 ✓
"session_9" at 65 → clockwise → Server C at 90 ✓
"order_77" at 95 → clockwise → wraps around → Server A at 10 ✓
Each server "owns" the arc of the ring that stretches counter-clockwise from it back to the previous server. Server B owns positions 11–50, Server C owns 51–90, Server A owns 91–10 (wrapping around).