<?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"><channel><title><![CDATA[🚆 Why IRCTC Tatkal Crashes at 10:00 AM? The Hidden “Thundering Herd Problem” Behind Flash Sales & Server Meltdowns]]></title><description><![CDATA[By the end of this article, you’ll:

✅ Understand why IRCTC Tatkal and flash sales crash at peak time

✅ Learn what the Thundering Herd Problem actually means (in simple terms)

✅ See real-world + technical examples (cache expiry, retry storms, sales spikes)

✅ Visualize how synchronized traffic overloads systems

✅ Discover practical solutions like exponential backoff, jitter, cache locking & rate limiting

✅ Build intuition useful for system design interviews and real-world backend development

If you’ve ever wondered “Why does this always crash exactly at launch time?” — this blog will give you the answer.]]></description><link>https://system-design-sourabh-bhardwaj.hashnode.dev</link><image><url>https://cdn.hashnode.com/uploads/logos/69a3392ba7428b958d4afe12/d411875f-03d8-439f-b444-78ef565adca6.jpg</url><title>🚆 Why IRCTC Tatkal Crashes at 10:00 AM? The Hidden “Thundering Herd Problem” Behind Flash Sales &amp; Server Meltdowns</title><link>https://system-design-sourabh-bhardwaj.hashnode.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Fri, 04 Sep 2026 12:13:09 GMT</lastBuildDate><atom:link href="https://system-design-sourabh-bhardwaj.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How Large Systems Prevent Cache Stampede (Netflix, IPL, E-commerce) ]]></title><description><![CDATA[Caching is one of the most powerful techniques for scaling backend systems.
A simple caching strategy often looks like this:
1. Request arrives
2. Check cache
3. If hit → return cached value
4. If mis]]></description><link>https://system-design-sourabh-bhardwaj.hashnode.dev/how-large-systems-prevent-cache-stampede-netflix-ipl-e-commerce</link><guid isPermaLink="true">https://system-design-sourabh-bhardwaj.hashnode.dev/how-large-systems-prevent-cache-stampede-netflix-ipl-e-commerce</guid><category><![CDATA[ttl-expiration]]></category><category><![CDATA[cache]]></category><category><![CDATA[ChaiCode]]></category><category><![CDATA[chai-code ]]></category><dc:creator><![CDATA[Sourabh Bhardwaj]]></dc:creator><pubDate>Sat, 07 Mar 2026 09:44:32 GMT</pubDate><content:encoded><![CDATA[<p>Caching is one of the most powerful techniques for scaling backend systems.</p>
<p>A simple caching strategy often looks like this:</p>
<pre><code class="language-plaintext">1. Request arrives
2. Check cache
3. If hit → return cached value
4. If miss → query database and store in cache with TTL
</code></pre>
<p>This works well — <strong>until it doesn't</strong>.</p>
<p>When many cache entries expire at the same time, thousands of requests suddenly hit the database simultaneously.</p>
<p>This phenomenon is called the <strong>Cache Stampede</strong> or <strong>Thundering Herd Problem</strong>.</p>
<p>You’ll see it in systems like:</p>
<ul>
<li><p>Netflix releasing a new show</p>
</li>
<li><p>E-commerce flash sales</p>
</li>
<li><p>IPL streaming traffic spikes</p>
</li>
<li><p>Viral social media posts</p>
</li>
</ul>
<p>In this article we’ll explore <strong>real strategies used in large-scale systems to prevent cache stampedes.</strong></p>
<hr />
<h2>Why Basic TTL Caching is Not Enough</h2>
<p>Most applications cache data with a <strong>fixed TTL (Time To Live)</strong>.</p>
<p>Example:</p>
<pre><code class="language-plaintext">User profile cached for 5 minutes
</code></pre>
<p>Timeline:</p>
<pre><code class="language-plaintext">t0: Cache created
t5: Cache expires
t5+: All requests fetch DB again
</code></pre>
<p>If <strong>thousands of users request the same data</strong>, they all hit the database simultaneously.</p>
<h3>Diagram: Basic TTL Expiry Problem</h3>
<img src="https://cdn.hashnode.com/uploads/covers/69a3392ba7428b958d4afe12/f7216b3a-cc3e-4011-963c-cfde1c1e3d44.png" alt="" style="display:block;margin:0 auto" />

<p>Instead of <strong>one database request</strong>, you suddenly get <strong>thousands</strong>.</p>
<p>This is the <strong>Cache Stampede</strong>.  </p>
<h1>How Cache Expiry Causes Traffic Spikes</h1>
<p>Imagine a product page cached for <strong>1 hour</strong>.</p>
<p>If <strong>1 million users</strong> access that page during a sale:</p>
<p>All cache entries created at similar times will <strong>expire together</strong>.</p>
<h3>Diagram: Synchronized TTL Expiry</h3>
<img src="https://cdn.hashnode.com/uploads/covers/69a3392ba7428b958d4afe12/62b229b7-73d8-49ac-9b42-07d13718a847.png" alt="" style="display:block;margin:0 auto" />

<p>The result:</p>
<ul>
<li><p>Database overload</p>
</li>
<li><p>Increased latency</p>
</li>
<li><p>Potential outages</p>
</li>
</ul>
<p>Large systems solve this using <strong>advanced caching strategies</strong>.</p>
<hr />
<h1>TTL Jitter – Randomizing Expiry</h1>
<p>Instead of giving every cache entry the <strong>same TTL</strong>, we introduce <strong>random variation</strong>.</p>
<p>Example:</p>
<pre><code class="language-plaintext">Base TTL = 1 hour
Random jitter = ±10 minutes
</code></pre>
<p>Now cache entries expire at <strong>different times</strong>.</p>
<h3>Diagram: Jittered TTL</h3>
<img src="https://cdn.hashnode.com/uploads/covers/69a3392ba7428b958d4afe12/a542d887-4ee5-4527-89d6-91e08b34f02f.png" alt="" style="display:block;margin:0 auto" />

<p>Instead of one massive spike, database traffic becomes <strong>smooth and distributed</strong>.</p>
<p>Benefits:</p>
<ul>
<li><p>Reduces synchronized cache expiry</p>
</li>
<li><p>Simple to implement</p>
</li>
<li><p>Works well for most workloads</p>
</li>
</ul>
<p>But this alone may not fully solve the problem.</p>
<hr />
<h1>Probability-Based Early Expiration</h1>
<p>Another clever strategy is <strong>probabilistic early recomputation</strong>.</p>
<p>Instead of waiting for the cache to expire, some requests <strong>refresh it early</strong> based on probability.</p>
<p>Concept:</p>
<pre><code class="language-plaintext">Closer to expiry → higher probability of refresh
</code></pre>
<p>This spreads recomputation across time.</p>
<h3>Diagram: Probabilistic Expiration</h3>
<img src="https://cdn.hashnode.com/uploads/covers/69a3392ba7428b958d4afe12/613b89e9-e42d-44a1-a4da-06a80278f564.png" alt="" style="display:block;margin:0 auto" />

<p>Result:</p>
<ul>
<li><p>Cache refresh happens gradually</p>
</li>
<li><p>Avoids sudden spikes</p>
</li>
<li><p>Database load spreads over time</p>
</li>
</ul>
<p>Many <strong>large-scale distributed systems</strong> use this strategy.</p>
<hr />
<h1>Mutex / Cache Locking</h1>
<p>One of the most effective solutions is <strong>mutex locking</strong>.</p>
<p>The idea is simple:</p>
<blockquote>
<p>When cache expires, only <strong>one request recomputes the value</strong>.</p>
</blockquote>
<p>All other requests <strong>wait</strong> or <strong>serve stale data</strong>.</p>
<h3>Diagram: Mutex Lock Flow</h3>
<img src="https://cdn.hashnode.com/uploads/covers/69a3392ba7428b958d4afe12/78639a6c-0849-441b-a183-c2728708e47a.png" alt="" style="display:block;margin:0 auto" />

<p>This ensures:</p>
<ul>
<li><p>Only <strong>one database query</strong></p>
</li>
<li><p>Prevents duplicate recomputation</p>
</li>
<li><p>Protects the backend</p>
</li>
</ul>
<p>Mutex locks are commonly implemented using:</p>
<ul>
<li><p>Redis locks</p>
</li>
<li><p>Distributed locks</p>
</li>
<li><p>Request deduplication</p>
</li>
</ul>
<hr />
<h1>Stale-While-Revalidate (SWR)</h1>
<p>A very popular strategy used by <strong>CDNs and large web platforms</strong> is <strong>Stale-While-Revalidate</strong>.</p>
<p>Instead of blocking users when cache expires:</p>
<ol>
<li><p>Serve <strong>stale data immediately</strong></p>
</li>
<li><p>Refresh cache <strong>in the background</strong></p>
</li>
</ol>
<h3>Diagram: SWR Flow</h3>
<img src="https://cdn.hashnode.com/uploads/covers/69a3392ba7428b958d4afe12/189c86e9-350b-4990-b1a7-820c5ef3a599.png" alt="" style="display:block;margin:0 auto" />

<p>Benefits:</p>
<ul>
<li><p>Zero latency spikes</p>
</li>
<li><p>Users never wait</p>
</li>
<li><p>Cache refresh happens asynchronously</p>
</li>
</ul>
<p>This is heavily used in:</p>
<ul>
<li><p>CDNs</p>
</li>
<li><p>Web APIs</p>
</li>
<li><p>Edge caching systems</p>
</li>
</ul>
<hr />
<h1>Cache Warming / Pre-Warming</h1>
<p>Sometimes you <strong>know traffic spikes are coming</strong>.</p>
<p>Examples:</p>
<ul>
<li><p>Netflix new season release</p>
</li>
<li><p>E-commerce flash sale</p>
</li>
<li><p>IPL match start</p>
</li>
<li><p>Ticket booking launch</p>
</li>
</ul>
<p>Instead of waiting for requests to populate cache, you <strong>pre-fill it beforehand</strong>.</p>
<h3>Diagram: Cache Warming</h3>
<img src="https://cdn.hashnode.com/uploads/covers/69a3392ba7428b958d4afe12/2d3844e5-e0cb-4ecc-8769-c09b5d852f51.png" alt="" style="display:block;margin:0 auto" />

<p>This ensures:</p>
<ul>
<li><p>Cache is ready before traffic arrives</p>
</li>
<li><p>Databases avoid sudden spikes</p>
</li>
<li><p>Faster response times</p>
</li>
</ul>
<p>Many systems run <strong>scheduled cache warming jobs</strong> before big events.</p>
<hr />
<h1>Tradeoffs: Freshness vs Latency vs Consistency</h1>
<p>Every caching strategy involves tradeoffs.</p>
<table>
<thead>
<tr>
<th>Strategy</th>
<th>Freshness</th>
<th>Latency</th>
<th>Complexity</th>
</tr>
</thead>
<tbody><tr>
<td>TTL Only</td>
<td>Medium</td>
<td>Low</td>
<td>Simple</td>
</tr>
<tr>
<td>TTL + Jitter</td>
<td>Medium</td>
<td>Low</td>
<td>Simple</td>
</tr>
<tr>
<td>Mutex Locking</td>
<td>High</td>
<td>Medium</td>
<td>Moderate</td>
</tr>
<tr>
<td>Probabilistic Expiry</td>
<td>High</td>
<td>Low</td>
<td>Moderate</td>
</tr>
<tr>
<td>Stale-While-Revalidate</td>
<td>Medium</td>
<td>Very Low</td>
<td>Moderate</td>
</tr>
<tr>
<td>Cache Warming</td>
<td>High</td>
<td>Low</td>
<td>Operational</td>
</tr>
</tbody></table>
<p>No single solution fits every system.</p>
<hr />
<h1>When to Use Each Strategy</h1>
<p>A good rule of thumb:</p>
<h3>Use TTL + Jitter</h3>
<p>For most <strong>general caching workloads</strong>.</p>
<h3>Use Mutex Locking</h3>
<p>When:</p>
<ul>
<li><p>Cache recomputation is expensive</p>
</li>
<li><p>Database cannot handle spikes</p>
</li>
</ul>
<h3>Use SWR</h3>
<p>For:</p>
<ul>
<li><p>APIs</p>
</li>
<li><p>CDN caching</p>
</li>
<li><p>Read-heavy systems</p>
</li>
</ul>
<h3>Use Probabilistic Expiry</h3>
<p>For:</p>
<ul>
<li><p>Massive distributed systems</p>
</li>
<li><p>High traffic platforms</p>
</li>
</ul>
<h3>Use Cache Warming</h3>
<p>When you <strong>know traffic spikes in advance</strong>.</p>
<p>Example events:</p>
<ul>
<li><p>Product launches</p>
</li>
<li><p>Sports streaming</p>
</li>
<li><p>Flash sales</p>
</li>
</ul>
<hr />
<h1>Final Thoughts</h1>
<p>Caching is easy to implement but <strong>hard to scale safely</strong>.</p>
<p>At scale, naive caching strategies can cause <strong>more damage than good</strong>.</p>
<p>That’s why large systems combine multiple strategies:</p>
<pre><code class="language-plaintext">TTL + Jitter
+ Mutex Locking
+ SWR
+ Cache Warming
</code></pre>
<p>Together, they ensure:</p>
<ul>
<li><p>Smooth traffic patterns</p>
</li>
<li><p>Protected databases</p>
</li>
<li><p>Reliable high-scale systems</p>
</li>
</ul>
<p>Understanding these patterns is essential for <strong>designing resilient distributed systems</strong>.</p>
<hr />
<p>If you enjoyed this article, consider exploring more topics in <strong>distributed systems and backend scalability</strong>.</p>
]]></content:encoded></item><item><title><![CDATA[🚆 Why IRCTC Tatkal Crashes at 10:00 AM?]]></title><description><![CDATA[At exactly 10:00 AM, something magical happens in India.Lakhs of people:

Refresh the IRCTC page

Hold their breath

Spam the “Book Now” button


10:00:01 AM →Website slows down.Payments fail.Twitter ]]></description><link>https://system-design-sourabh-bhardwaj.hashnode.dev/why-irctc-tatkal-crashes-at-10-00-am</link><guid isPermaLink="true">https://system-design-sourabh-bhardwaj.hashnode.dev/why-irctc-tatkal-crashes-at-10-00-am</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><dc:creator><![CDATA[Sourabh Bhardwaj]]></dc:creator><pubDate>Sat, 28 Feb 2026 19:39:46 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/69a3392ba7428b958d4afe12/0cba8243-9201-43bd-9ff7-1cab32e46cc7.jpg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>At exactly <strong>10:00 AM</strong>, something magical happens in India.<br />Lakhs of people:</p>
<ul>
<li><p>Refresh the IRCTC page</p>
</li>
<li><p>Hold their breath</p>
</li>
<li><p>Spam the “Book Now” button</p>
</li>
</ul>
<p>10:00:01 AM →<br />Website slows down.<br />Payments fail.<br />Twitter explodes.</p>
<p>Why does this happen <strong>every single time</strong>?<br />It’s not bad luck.<br />It’s not always poor engineering.<br />It’s a classic distributed systems issue called the <strong>Thundering Herd Problem</strong>.</p>
<p>Let’s break it down.</p>
<h2>🧠 What is the Thundering Herd Problem?</h2>
<p>The <strong>Thundering Herd Problem</strong> occurs when:</p>
<blockquote>
<p>Many clients/processes wake up at the same time and try to access or regenerate the same resource simultaneously.</p>
</blockquote>
<p>This overwhelms the system.</p>
<p>Think of it like a buffalo herd suddenly charging in one direction.</p>
<h2>🔍 Why IRCTC Tatkal is a Perfect Example</h2>
<p>At 9:59:59 AM:</p>
<ul>
<li>Users are refreshing continuously.</li>
</ul>
<p>At 10:00:00 AM:</p>
<ul>
<li><p>Booking opens.</p>
</li>
<li><p>Lakhs of requests hit the same booking API.</p>
</li>
<li><p>All want limited seats.</p>
</li>
<li><p>Payment gateways get flooded.</p>
</li>
</ul>
<p>The system isn't slow because it's weak.</p>
<p>It’s slow because:<br /><strong>Everyone synchronized their action.</strong></p>
<p>And synchronized traffic is dangerous.</p>
<h2>💻 Where This Happens in Real Systems</h2>
<ol>
<li><h3>Cache Expiry Disaster</h3>
</li>
</ol>
<p>Imagine:</p>
<ul>
<li><p>50,000 users request <code>/popular-trains</code></p>
</li>
<li><p>Data is cached for 1 hour</p>
</li>
<li><p>Cache expires at 12:00 PM</p>
</li>
</ul>
<p>At 12:00:01:<br />All 50,000 requests try to fetch fresh data from the database.</p>
<p>Instead of:<br />✔ 1 database query</p>
<p>You get:<br />❌ 50,000 database queries</p>
<p>That’s a database meltdown.</p>
<pre><code class="language-plaintext">Before Expiry:
Users → Cache → Response

After Expiry:
Users → Database → 💥 Overload
Users → Database → 💥 Overload
Users → Database → 💥 Overload
</code></pre>
<p>One expired key.<br />Thousands of simultaneous refreshes.</p>
<ol>
<li><h2>Retry Storm</h2>
</li>
</ol>
<p>A service becomes temporarily unavailable.</p>
<p>Clients retry immediately.</p>
<p>Instead of helping recovery,<br />they increase pressure.</p>
<p>It’s like:</p>
<blockquote>
<p>A person faints in a crowd and instead of giving space, everyone gathers around.</p>
</blockquote>
<ol>
<li><h3>Flash Sales (Big Billion Days, etc.)</h3>
</li>
</ol>
<p>At exactly 12:00:</p>
<ul>
<li><p>“Only 100 units available!”</p>
</li>
<li><p>3 lakh users click “Buy Now”</p>
</li>
<li><p>Inventory service gets slammed</p>
</li>
<li><p>Payment APIs spike</p>
</li>
<li><p>Many users see “Out of stock”</p>
</li>
</ul>
<p>Classic herd behavior.</p>
<h2>How does It Happen ? (Step by step breakdown)</h2>
<p>Let's visualize a typical cache stampede scenario (very common in e-commerce/booking systems).</p>
<ol>
<li><p><strong>Normal state</strong> — Many users request popular data (e.g., train availability). Cache serves most hits quickly.</p>
</li>
<li><p><strong>Cache expires</strong> — TTL ends for a hot key (e.g., Tatkal quota for a route).</p>
</li>
<li><p><strong>The herd charges</strong> — Thousands of incoming requests see a cache miss at once.</p>
</li>
<li><p><strong>Stampede to backend</strong> — All requests query the slow/expensive database simultaneously → DB gets overloaded, latency spikes.</p>
</li>
<li><p><strong>Cascading pain</strong> — Slower responses → more timeouts/retries → even bigger surge. Servers crash or queue up.</p>
</li>
</ol>
<p>Here's a simple diagram showing the flow:</p>
<img src="https://cdn.hashnode.com/uploads/covers/69a3392ba7428b958d4afe12/4bdd769b-3446-4e80-9fff-5864175a469e.png" alt="" style="display:block;margin:0 auto" />

<img src="https://cdn.hashnode.com/uploads/covers/69a3392ba7428b958d4afe12/62c0cbdf-c192-4401-8b60-64d3f42ae664.png" alt="" style="display:block;margin:0 auto" />

<h3>Why It's So Dangerous</h3>
<ul>
<li><p><strong>Performance cliff</strong> — System handles 10k req/s normally, but 10k simultaneous req/s kills it.</p>
</li>
<li><p><strong>Wasted resources</strong> — Redundant work (multiple processes recompute the same thing).</p>
</li>
<li><p><strong>Cascading failures</strong> — One slow service drags down the entire chain.</p>
</li>
<li><p><strong>Poor user experience</strong> — Errors, lost sales, frustrated users (hello, endless IRCTC memes).</p>
</li>
</ul>
<h2>💥 Impact on System Components</h2>
<h3>CPU</h3>
<p>Sudden thread wake-ups → high context switching → CPU spikes.</p>
<h3>Database</h3>
<p>Connection pools exhaust → queries queue → timeouts.</p>
<h3>Cache</h3>
<p>Cache stampede → mass regeneration → eviction pressure.</p>
<h3>Latency</h3>
<p>P99 latency increases drastically → user experience degrades.</p>
<h2>📊 Normal Traffic Spike vs Thundering Herd</h2>
<p>Not all traffic spikes are bad.</p>
<h3>🟢 Normal Spike</h3>
<ul>
<li><p>Gradual increase in users</p>
</li>
<li><p>System auto-scales</p>
</li>
<li><p>Load is distributed over time</p>
</li>
<li><p>Predictable</p>
</li>
</ul>
<h3>🔴 Thundering Herd</h3>
<ul>
<li><p>Sudden synchronized burst</p>
</li>
<li><p>All requests hit at the same second</p>
</li>
<li><p>Resource contention</p>
</li>
<li><p>High probability of failure</p>
</li>
</ul>
<h3>Visual Timeline</h3>
<pre><code class="language-plaintext">Normal Spike:
    /
   /
  /
 /

Thundering Herd:
    |
    |
    |
    |
</code></pre>
<p>The difference is <strong>synchronization</strong>, not just volume.</p>
<hr />
<h1>🛠️How Engineers Solve It</h1>
<p>This is where system design gets interesting.</p>
<ul>
<li><h2>✅ 1. Exponential Backoff with Jitter</h2>
<p>Instead of retrying instantly:</p>
<p>Retry after:</p>
<ul>
<li><p>1 second</p>
</li>
<li><p>2 seconds</p>
</li>
<li><p>4 seconds</p>
</li>
<li><p>Add randomness</p>
</li>
</ul>
<p>Randomness prevents synchronization.</p>
<p>Without randomness:<br />Everyone retries together again.</p>
<p>With randomness:<br />Requests spread out.</p>
<hr />
<h2>✅ 2. Single Flight / Cache Locking</h2>
<p>When cache expires:</p>
<ul>
<li><p>First request regenerates data</p>
</li>
<li><p>Others wait</p>
</li>
<li><p>Only one DB call happens</p>
</li>
</ul>
<p>Problem solved.</p>
<hr />
<h2>✅ 3. Staggered Cache Expiry</h2>
<p>Instead of:</p>
<pre><code class="language-plaintext">All keys expire at 12:00 PM
</code></pre>
<p>Use:</p>
<pre><code class="language-plaintext">Expiry = 1 hour ± random(0–5 minutes)
</code></pre>
<p>Now refreshes are distributed over time.</p>
<hr />
<h2>✅ 4. Rate Limiting</h2>
<p>Control how many requests per second are allowed.</p>
<p>This prevents stampedes.</p>
<hr />
<h1>🧩 Visualizing the Difference</h1>
<h2>Without Protection</h2>
<pre><code class="language-plaintext">10,000 Users
      ↓
Database
      ↓
Crash
</code></pre>
<h2>With Protection</h2>
<pre><code class="language-plaintext">10,000 Users
      ↓
Cache Layer
      ↓
Single DB Query
      ↓
Stable System
</code></pre>
<hr />
<h1>🎯 Simple Definition</h1>
<blockquote>
<p>The Thundering Herd Problem happens when many clients attempt to access or regenerate the same resource simultaneously, overwhelming the system.</p>
</blockquote>
<p>Or in very simple words:</p>
<blockquote>
<p>Everyone remembered they were hungry at the same second.</p>
</blockquote>
<hr />
<h1>🚀 Final Thoughts</h1>
<p>Distributed systems don’t just fail because of bugs.</p>
<p>They fail because:</p>
<ul>
<li><p>Humans synchronize.</p>
</li>
<li><p>Timers synchronize.</p>
</li>
<li><p>Retries synchronize.</p>
</li>
</ul>
<p>And when everything wakes up together…</p>
<p>You don’t get traffic.</p>
<p>You get a herd.</p>
</li>
</ul>
]]></content:encoded></item></channel></rss>