How Consistent Hashing Solves Cache Server Scaling Challenges
Consistent hashing organizes the hash space into a virtual ring, allowing cache servers and objects to be mapped with minimal disruption when servers are added or removed, thereby reducing cache misses and backend load compared to traditional modulo‑based hashing.
What problem does consistent hashing solve?
When using a simple hash function to map an object to one of n cache servers (e.g., hash(object) % n), the system works initially but fails when a server goes down or a new server is added. Changing the number of servers forces almost all objects to be remapped, causing massive cache invalidation and a surge of traffic to the backend.
Principle of consistent hashing
Consistent hashing arranges the entire hash value space (e.g., 0‑2^32‑1) into a virtual clockwise ring. Each cache server is placed on the ring by hashing its identifier (IP, hostname, etc.). An object is also hashed; starting from its position on the ring, the first server encountered clockwise is the one that stores the object.
Because servers occupy points on the ring, adding or removing a server only affects the objects that map to the segment between the departing/arriving server and its predecessor, leaving the rest of the objects untouched.
Example with three servers A, B, C:
Four objects are mapped as follows: object 1 → A, object 2 and 3 → B, object 4 → C.
When server A fails and is removed, only object 1 needs to be remapped to the next server (B). When a new server D is added, only the objects that fall into D’s segment (e.g., object 2) are remapped, leaving the others unchanged.
This demonstrates that consistent hashing greatly reduces the amount of data that must be moved when the cache cluster changes, making it far more efficient than ordinary modulo hashing.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java High-Performance Architecture
Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
