Hashing: Both the nodes and the data items are hashed onto a hash ring, a conceptual circle representing the hash space. The hashing function typically generates a fixed range of values (e.g., 0-255 for an 8-bit hash).
Placement on the Ring: Each node and data item is assigned a position on this hash ring based on its hash value.
Data Lookup: To find where a data item should be stored, you move clockwise around the ring starting from the hash value of that item until you find the first node. This node is where the data item is stored.
Scalability and Flexibility: When a new node is added, it gets placed into its position on the ring based on its hash value. It only takes over the responsibility for data items that are closest to it on the ring. Similarly, when a node is removed, only its immediate neighbors on the ring take over serving its data items. This limits the amount of data that needs to be moved around, which is a key advantage over traditional hashing, where adding or removing a node might reshuffle a large portion of the data.
Load Balancing: Consistent hashing tends to naturally balance the load because each node gets approximately the same range of hash values. Virtual nodes, or "vnodes," can also be used where each physical node is represented by multiple points on the hash ring. This technique can help balance the workload more evenly among nodes.