Consistent Hashing
Consistent Hashing is a smart way to distribute data across multiple servers so that minimum disruption happens when a server is added or removed.
🎯 Simple Explanation:
Imagine you have 100 lockers and you’re storing books based on the book’s name.
If you suddenly remove a few lockers (servers), all books get shuffled — that’s bad.
Consistent hashing solves this by putting lockers in a circle (hash ring).
Now, when a book is added, it goes to the locker clockwise from its hash.
🌀 If a locker (server) is removed or added:
- Only a few books need to move
- Most of the books stay where they are
💡 Why it’s useful:
- Used in distributed systems like caching (e.g., Redis, Memcached), databases
- Keeps systems scalable and stable under dynamic changes
📦 Real-Life Analogy:
Think of people standing in a circle passing out cards. If one person leaves, only the person before them changes who they hand cards to — not everyone.