<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: vamsi karuturi</title>
    <description>The latest articles on DEV Community by vamsi karuturi (@vamsi_karuturi).</description>
    <link>https://dev.to/vamsi_karuturi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4128515%2F69a27a50-2bab-4b6c-86f2-55e46c4a65a2.png</url>
      <title>DEV Community: vamsi karuturi</title>
      <link>https://dev.to/vamsi_karuturi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vamsi_karuturi"/>
    <language>en</language>
    <item>
      <title>Consistent Hashing — Why "hash % N" Fails at Scale</title>
      <dc:creator>vamsi karuturi</dc:creator>
      <pubDate>Wed, 16 Sep 2026 18:08:26 +0000</pubDate>
      <link>https://dev.to/vamsi_karuturi/consistent-hashing-why-hash-n-fails-at-scale-50l5</link>
      <guid>https://dev.to/vamsi_karuturi/consistent-hashing-why-hash-n-fails-at-scale-50l5</guid>
      <description>&lt;p&gt;Facebook had 1000+ Memcached servers.&lt;/p&gt;

&lt;p&gt;They added one more.&lt;/p&gt;

&lt;p&gt;Billions of cache entries got invalidated at once. Thundering herd. Database crushed. Partial outage.&lt;/p&gt;

&lt;p&gt;They switched to consistent hashing. Problem solved.&lt;/p&gt;

&lt;p&gt;Here's the thing: every time you say "let's distribute data across N servers" in a system design interview, the interviewer is waiting for you to explain &lt;strong&gt;how&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If your answer is &lt;code&gt;hash % N&lt;/code&gt;, you've already failed the question. This post is why, and what the actual fix looks like.&lt;/p&gt;

&lt;h2&gt;
  
  
  The naive approach
&lt;/h2&gt;

&lt;p&gt;Setup: 4 cache servers.&lt;/p&gt;

&lt;p&gt;Key &lt;code&gt;"user:123"&lt;/code&gt; → &lt;code&gt;hash("user:123") % 4 = 2&lt;/code&gt; → goes to Server 2.&lt;/p&gt;

&lt;p&gt;Simple. Works fine. Until you scale.&lt;/p&gt;

&lt;p&gt;Now add a 5th server:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;hash("user:123") % 5 = 3&lt;/code&gt; → goes to Server 3.&lt;/p&gt;

&lt;p&gt;Same key. Different server. The data didn't move, but your lookup logic now points at the wrong place — so effectively, it has to move.&lt;/p&gt;

&lt;h2&gt;
  
  
  The math that breaks production
&lt;/h2&gt;

&lt;p&gt;When you go from N to N+1 servers, roughly &lt;code&gt;N/(N+1)&lt;/code&gt; of all your keys remap to a different server.&lt;/p&gt;

&lt;p&gt;For N = 100, that's &lt;strong&gt;99% of your keys moving&lt;/strong&gt; for the crime of adding a single server.&lt;/p&gt;

&lt;p&gt;Every one of those keys is now a cache miss. All of them hit the origin server at once. That's the thundering herd — and it's exactly what took Facebook's Memcached layer down.&lt;/p&gt;

&lt;p&gt;Consistent hashing brings that number from ~100% down to roughly &lt;code&gt;1/N&lt;/code&gt;. Adding a server only displaces a small, predictable slice of your keyspace instead of nearly all of it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The actual idea
&lt;/h2&gt;

&lt;p&gt;Instead of &lt;code&gt;hash % N&lt;/code&gt;, you place both your servers &lt;strong&gt;and&lt;/strong&gt; your keys on a circular hash space — 0 to 2³² − 1. This is the "hash ring" you'll hear mentioned in basically every system design interview that touches sharding, load balancing, or distributed caching.&lt;/p&gt;

&lt;p&gt;Once servers and keys share that ring, adding or removing a node only affects the keys sitting in its immediate neighborhood — not the whole dataset.&lt;/p&gt;




&lt;p&gt;I go through the full ring mechanics, virtual nodes, and how this shows up in real interview questions (Redis Cluster, DynamoDB, CDN routing) in the complete writeup here 👉 &lt;a href="https://vamsilabs.netlify.app/consistenthashing/" rel="noopener noreferrer"&gt;Consistent Hashing — full breakdown&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you're prepping for system design interviews, this is one of those concepts that separates a pass from a "we'll get back to you."&lt;/p&gt;

&lt;p&gt;What's your go-to explanation for consistent hashing when it comes up in an interview? Curious how others build the intuition.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>automation</category>
      <category>opensource</category>
      <category>systemdesign</category>
    </item>
  </channel>
</rss>
