{"id":23,"date":"2020-08-30T09:12:54","date_gmt":"2020-08-30T09:12:54","guid":{"rendered":"https:\/\/system.camp\/index.php\/2020\/08\/30\/consistent-hashing\/"},"modified":"2020-10-06T09:56:51","modified_gmt":"2020-10-06T09:56:51","slug":"consistent-hashing","status":"publish","type":"post","link":"https:\/\/system.camp\/tutorial\/consistent-hashing\/","title":{"rendered":"Consistent Hashing"},"content":{"rendered":"\n
Consistent Hashing is a distributed hashing technique that is loosely coupled with the number of servers or objects in a distributed hash table by positioning them in an abstract circle or hash ring<\/em>. This allows servers and objects to scale without affecting the overall system.<\/p>\n\n\n\n Assume that you have 10 servers and you need to distribute a thousand keys among these 10 servers. How would you do that? I know that the most impulsive decision is to assign the servers a unique number from 0 to 9 and then hash the keys using the modulo operation ( This obvious solution has a major drawback: it is not scalable in a horizontal fashion. This essentially means that whenever you add or a remove a server, you\u2019d need to calculate the hashes again for the keys to assign them to a server.<\/p>\n\n\n\n An explanation that uses an example does wonders, so let\u2019s use one right away. We assume that we have three servers for the sake of simplicity. The steps involved in consistent hashing are described below:<\/p>\n\n\n\nWhy would I need Consistent Hashing at all?<\/h3>\n\n\n\n
key % 10<\/code>) to assign them to a server.<\/p>\n\n\n\n
Let\u2019s dive into the explanation of Consistent Hashing<\/h3>\n\n\n\n
h(x)<\/code>.<\/li>
h(x)<\/code> onto an abstract circle.<\/li>
h(x)<\/code> and put onto the abstract circle.<\/li>
S2<\/code> and
S3<\/code> respectively.<\/li><\/ul>\n\n\n\n