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.