Distributed Systems• 20 Min
Consistent Hashing Basic
EASY
# Core Concepts of Consistent Hashing
Traditional hashing uses the modulo operator: `hash(key) % N`, where N is the number of server nodes.
This behaves poorly when servers are added or removed, since **almost all keys** re-map to new servers, causing a cache stampede.
Consistent hashing solves this problem by using a shared circular hash ring (e.g., from 0 to $2^{32}-1$).
---
## 1. Step-by-Step Distribution
1. **Hash the Servers**: Hash server IPs and map them to positions on the ring.
2. **Hash the Keys**: Hash client keys and map them on the same ring.
3. **Route Requests**: To locate a key's server, travel clockwise from the key's position until you hit the first server node.
---
## 2. Virtual Nodes (V-Nodes)
To prevent hot spots (uneven distribution), we hash each physical server multiple times using offsets (e.g., `Node1#1`, `Node1#2`).
This guarantees a highly uniform key distribution across all active physical servers.
Prerequisites
- Modular Math Basics
Evaluation Workbench
Use this sandbox to test percentage evaluations locally. This course configuration evaluates on active client profiles.
Active SDK evaluation matches client consistent rollout bucket key.