<?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 Preety Kumari on Medium]]></title>
        <description><![CDATA[Stories by Preety Kumari on Medium]]></description>
        <link>https://medium.com/@preetykumari983?source=rss-194aa4c48d7d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*zFWzIhmst6704FSv.</url>
            <title>Stories by Preety Kumari on Medium</title>
            <link>https://medium.com/@preetykumari983?source=rss-194aa4c48d7d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 16:22:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@preetykumari983/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[What is Consistent Hashing?]]></title>
            <link>https://preetykumari983.medium.com/what-is-consistent-hashing-9891f4c0e094?source=rss-194aa4c48d7d------2</link>
            <guid isPermaLink="false">https://medium.com/p/9891f4c0e094</guid>
            <category><![CDATA[consistent-hashing]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[hash-table]]></category>
            <dc:creator><![CDATA[Preety Kumari]]></dc:creator>
            <pubDate>Sun, 24 Jan 2021 10:34:11 GMT</pubDate>
            <atom:updated>2021-01-24T10:34:11.430Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>What is Consistent Hashing?</strong></p><p><strong>Consistent hashing</strong> is a very useful strategy for <strong>Distributed caching system</strong> and <strong>Distributed Hash Table (DHT)</strong> such that when a hash table is resized, only K/n keys need to be remapped on average, where K is the number of keys, and n is the number of nodes.</p><p>Well how it happens? We will understand it slowly as we proceed…</p><p>A <strong>distributed hash table</strong> (<strong>DHT</strong>) is a class of a decentralised distributed system that provides a lookup service similar to a <a href="https://en.wikipedia.org/wiki/Hash_table">h</a>ash table: (<em>key</em>, <em>value</em>) pairs are stored in a DHT, and any participating node can efficiently retrieve the value associated with a given key. — Wikipedia</p><p>A <strong>distributed caching system </strong>is a distributed system where each node has a small piece of the cache. It knows where to look.</p><p><em>Consider </em><strong><em>building a distributed caching system</em></strong><em> where </em><strong><em>n</em></strong><em> is number of cache.</em></p><p><strong>Which problem consistent hashing solves?</strong></p><p>A simple hash function generally used is K%n. It has two major drawbacks.</p><ul><li>It is not horizontally scalable. Basically change in number of caching server would need changes in all keys mapping to cache servers.</li><li>It is not load balanced. The non uniformity of distributed data will lead to data saturation for one and empty for other.</li></ul><p><strong>How Consistent hashing works?</strong></p><p>Consistent hashing maps a key for cache servers to an integer in a range.</p><p>Imagine that the integers in the range are placed on a circle.</p><p>Steps:</p><ol><li>Given a list of cache servers( say A, B, C, D), hash them to integers in the range.</li><li>Map a key to a server,</li></ol><ul><li>Hash it to a single integer.</li><li>Move clockwise on the ring until finding the first cache it encounters.</li><li>That cache is the one that contains the key.</li></ul><p>Add a new server, say E: Keys at cache server D will split. Some of them will be shifted to E, while other keys will not be touched.</p><p>Remove a cache or if a cache failed, say A: all keys at A will fall into B, and other cache server keys will not be affected.</p><p>Randomly distributed real data making the keys on caches unbalanced: Add “virtual replicas” for caches. Instead of mapping each cache to a single point on the ring, map it to multiple points on the ring, i.e. replicas. This way, each cache is associated with multiple portions of the ring.</p><p>A good hash function which mixes well as the number of replicas increases, will keep keys more balanced.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9891f4c0e094" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>