<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Md. Nawaz Rahaman on Medium]]></title>
        <description><![CDATA[Stories by Md. Nawaz Rahaman on Medium]]></description>
        <link>https://medium.com/@mail2nawaz2000?source=rss-c2aa8c5d48a8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*0lbR35P4mxZbdzTc</url>
            <title>Stories by Md. Nawaz Rahaman on Medium</title>
            <link>https://medium.com/@mail2nawaz2000?source=rss-c2aa8c5d48a8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 12:55:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mail2nawaz2000/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Consistent Hashing Explained in 2 Minutes]]></title>
            <link>https://medium.com/@mail2nawaz2000/consistent-hashing-explained-in-2-minutes-8680124de8ca?source=rss-c2aa8c5d48a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/8680124de8ca</guid>
            <category><![CDATA[load-balancing]]></category>
            <category><![CDATA[consistent-hashing]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <dc:creator><![CDATA[Md. Nawaz Rahaman]]></dc:creator>
            <pubDate>Sat, 23 Aug 2025 18:12:30 GMT</pubDate>
            <atom:updated>2025-08-24T06:26:30.735Z</atom:updated>
            <content:encoded><![CDATA[<p>In a distributed system, requests must be distributed accross different server instances…</p><p>As evenly as possible.</p><h4>The Simple Approach: Basic Hashing</h4><p>A common way to distribute requests is by using a simple hash function:</p><blockquote><strong>serverIndex = hash(requestId) % N,<br>where N -&gt; number of servers.</strong></blockquote><p>Here every request ID(often the request ip address) is hashed using a hashing algorithm and the result is mapped to a server by taking the modulo with the number of servers(N). This provides the server index the request should be mapped to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*26XoVXMrd8HaZ75LhSC4Tg.png" /></figure><h4>The Problem with Changing Servers</h4><p>This is good when the<strong> number of servers are fixed</strong> and <strong>no new servers</strong> are added or deleted. This design however is bad when the number of servers keep changing as the local data present in each server needs to be updated whenever a new server is added or removed. When <strong>N</strong> changes, the mapping shifts — meaning almost all requests might be sent to different servers. This forces a major reshuffling of data, which is inefficient and disruptive.</p><h4>The Goal: Minimize Remapping</h4><p>Ideally, when servers are added or removed, only a small fraction of requests (or keys) should be remapped. This is where <strong>Consistent Hashing</strong> comes in.</p><h4>How Consistent Hashing Works</h4><p>With basic hashing, whenever servers are added or removed, all the keys/request need to be remapped. But with consistent hashing, only a few keys are needed to be redistributed.</p><h4>The Hash Ring</h4><p>Imagine all possible hash values (generated by hashing all servers and keys with the same hash function) arranged in a circle (the hash ring). Servers are placed at points on this ring, determined by their hash values. Each key is mapped clockwise to the next available server.</p><ol><li>The below is a standard hash ring with keys and servers distributed evenly.</li><li>Each key is mapped clockwise to the next available server.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*_P4cfx3BQsUexRpzXTibPw.png" /><figcaption>Hash ring with servers and keys</figcaption></figure><h4>Case: Adding a new server</h4><p>When a new server(s4) is added. only the keys that fall between the previous server and s4 (in this case, k1 is mapped to s4) need to be remapped to s4. The rest remain unaffected as seen below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*qVjB0BVokkHZ75IckqhbxA.png" /><figcaption>Hash ring when new server is added</figcaption></figure><h4>Case: Removing a server</h4><p>When the server(s2) is added, only the keys that were mapped to s2 now move to the next server in the ring (e.g., s0). The majority of keys stay where they are.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*AsaG1OvxM5EQYSlrsBmH-A.png" /><figcaption>Hash ring when a server is removed</figcaption></figure><p>This dramatically reduces the problem of remapping majority of the keys.</p><h4>Real-World Challenge: Uneven Server Distribution</h4><p>But there is a<strong> potential problem</strong> with this approach. The above images shows the servers distributed evenly spaced across the hash ring. But in real life scenarios, the servers may be clustered together and we are very unlikely to have the servers distributed evenly. This problem is inherent in this approach as position of the servers in the hash ring is determined by the hash value and the issue becomes pronounced when new servers are added or removed. Below is an image demonstrating the problem.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*gJAyX5L62tlPNT-PiPlKSQ.png" /><figcaption>Hash ring when servers are placed closely</figcaption></figure><h4>The Solution: Virtual Nodes</h4><p><strong>Virtual nodes</strong> are used to solve the problem. Here, each physical server is represented by multiple virtual nodes on the hash ring, each at a different position. The below is an illustration of the same.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*NojXBuY48A4nRjuLRybsiw.png" /></figure><p>One technique that can be used for virtualization of the servers is by using multiple hash functions to hash the same key.</p><ul><li>Each server is hashed multiple times using different hash functions.</li><li>Each hash result places a virtual node for that server at a different point on the ring.</li><li>For example, server s0 might be placed at s0_0, s0_1, and s0_2.</li><li>This increases the likelihood that servers are evenly distributed, balancing the load more effectively.</li></ul><p>In the above example, if we hash the server s0 using three different hash functions (let’s say hash_1(), hash_2() and hash_3()), and modulo each individual results by the number of points in the hash ring, we get 3 coordinates where s0 is placed as s0_0, s0_1 and s0_2. Similarly for s1, we place s1 at s1_0, s1_1 and s1_2.</p><p>The more virtual nodes per server, the smoother and more balanced the distribution.</p><h3>Summary</h3><ul><li><strong>Basic hashing</strong> is simple but doesn’t handle server changes well.</li><li><strong>Consistent hashing</strong> minimizes remapping when servers are added or removed.</li><li><strong>Virtual nodes</strong> solve the problem of uneven server distribution, ensuring better load balancing.</li></ul><p>Consistent hashing is a foundational technique for scalable, resilient distributed systems — making it easier to manage dynamic server pools without major disruptions.</p><h3>Thanks for reading!</h3><p>If you’d like to discuss distributed systems, consistent hashing, or share your own experiences, feel free to connect with me on LinkedIn: [Md. Nawaz Rahaman](<a href="https://www.linkedin.com/in/md-nawaz-rahaman/">LinkedIn</a>).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8680124de8ca" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>