Posts

Showing posts with the label Caching

Understanding the Hash Ring in Consistent Hashing

Image
 If you’ve ever looked into distributed systems or scalable caching, you’ve probably heard the term hash ring . It’s at the heart of consistent hashing — the algorithm that powers systems like DynamoDB, Cassandra, Riak, and distributed caches such as Memcached and Redis Cluster. In this post, we’ll break down what a hash ring is, how it works, and why it matters. What Is a Hash Ring? A hash ring is a conceptual circle that represents the entire range of hash values. Imagine the numbers from 0 to 2³² − 1 arranged in a circle. Nodes (servers) : Each server in your cluster is hashed to a point on the ring based on its identifier (e.g., IP address). Keys (data items) : Each key you want to store (e.g., cache key, user ID) is also hashed to a point on the ring. Assignment rule : A key is assigned to the first server found clockwise from its hash position. https://ably.com/blog/implementing-efficient-consistent-hashing Adding a Node When you add a new node: Hash the node’...