<?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[Mehhhhull]]></title><description><![CDATA[I'm Mehul, a CS student learning something new every day. I write about tech, projects, experiments, internships, and pretty much anything I explore. Not an expert, just learning, sharing, and improving every day.]]></description><link>https://mehhhhull.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Wed, 18 Nov 2026 13:16:46 GMT</lastBuildDate><atom:link href="https://mehhhhull.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Cache Me If You Can: The Secret Behind Fast Apps]]></title><description><![CDATA[Learn how caching works, including cache hits & misses, CDNs, CPU caches, Redis, caching strategies, and how caching improves application performance.]]></description><link>https://mehhhhull.hashnode.dev/cache-me-if-you-can-the-secret-behind-fast-apps</link><guid isPermaLink="true">https://mehhhhull.hashnode.dev/cache-me-if-you-can-the-secret-behind-fast-apps</guid><category><![CDATA[caching]]></category><category><![CDATA[Backend Development]]></category><category><![CDATA[System Design]]></category><category><![CDATA[Redis]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[caching strategies]]></category><dc:creator><![CDATA[Mehul Kumar Singh]]></dc:creator><pubDate>Wed, 18 Nov 2026 08:48:13 GMT</pubDate><content:encoded><![CDATA[<h1>Introduction to Caching</h1>
<p>A mechanism to store a subset of data in a faster, more accessible location to reduce the time and effort required for retrieval or operations.</p>
<p>Its core principle is that it minimizes latency and decreases server load by avoiding redundant, computationally expensive tasks.</p>
<img src="https://cdn.hashnode.com/uploads/covers/6af0daddfec6897e856e10fe/7d454cc5-86bc-4166-96ec-69081ffe224c.png" alt="Cache Hit Vs Cache Miss" style="display:block;margin:0 auto" />

<h2>Real-World Examples of Caching</h2>
<h3>Google Search</h3>
<p>Google caches search results for common queries to avoid repeatedly performing expensive operations. Suppose something is trending or there is big news happening, and it is searched many times. Cached results can help serve these searches faster without performing the same expensive operations repeatedly, otherwise there would be more load on the backend systems, and the system could become slower.</p>
<h3>Netflix (CDN)</h3>
<p>Uses Content Delivery Networks (CDNs) to store video content at edge locations. Edge locations are globally distributed data centers strategically positioned in major cities to deliver content with the lowest possible latency. This reduces buffering and server load.</p>
<h3>Twitter/X (Trends)</h3>
<p>Caches trending topics to prevent expensive real-time analysis of billions of tweets for every user request.</p>
<h2>Levels of Caching</h2>
<ol>
<li>Network-Level Caching</li>
<li>Hardware-Level Caching</li>
<li>Software-Based Caching</li>
</ol>
<p>Let's understand all types of caching in detail.</p>
<h2>1. Network-Level Caching</h2>
<p>There are two major ways of network-level caching:</p>
<h3>1. Content Delivery Network (CDN)</h3>
<p>The whole idea of a CDN is to cache content geographically closer to the end users. That's why they are called Edge Nodes, Edge Servers, or Edge Computers.</p>
<img src="https://cdn.hashnode.com/uploads/covers/6af0daddfec6897e856e10fe/511095e3-c17e-487c-84da-6a1831830d5a.png" alt="CDN" style="display:block;margin:0 auto" />

<ul>
<li><strong>Edge Nodes/Servers:</strong> Servers placed near the user to minimize latency.</li>
<li><strong>Point of Presence (PoP):</strong> A specific regional collection of edge servers.</li>
<li><strong>Workflow:</strong> The system uses DNS to route a user's request to a nearby PoP. If the content is missing (Cache Miss), it is fetched from the originating server and then cached.</li>
<li><strong>TTL (Time to Live):</strong> Defines how long content remains in the cache before it expires or is refreshed.</li>
</ul>
<h3>2. Domain Name System (DNS) Caching</h3>
<ul>
<li><strong>Recursive Resolver:</strong> A server that finds IP addresses. These maintain their own caches to avoid repeated lookups.</li>
<li><strong>Hierarchical Caching:</strong> DNS lookups check the local Operating System cache, then the browser cache, then the recursive resolver cache before querying root or authoritative name servers.</li>
</ul>
<h2>2. Hardware-Level Caching</h2>
<img src="https://cdn.hashnode.com/uploads/covers/6af0daddfec6897e856e10fe/62a11b5a-8712-42dd-a53f-4b5747d26e22.png" alt="Hardware Level Caching" style="display:block;margin:0 auto" />

<h3>CPU Caching</h3>
<p>Includes L1, L2, and L3 caches to speed up processing by storing frequently used data near the CPU.</p>
<h3>Primary Memory (RAM)</h3>
<ul>
<li><strong>Volatile Storage:</strong> Data is lost when power is cut.</li>
<li><strong>Speed:</strong> Significantly faster than secondary disk-based storage due to electrical signal access rather than mechanical movement.</li>
<li><strong>Trade-off:</strong> High speed but limited capacity and lack of persistence.</li>
</ul>
<h2>3. Software-Based Caching &amp; Strategies</h2>
<p>In the backend, these also take the help of hardware.</p>
<h3>In-Memory Databases (e.g., Redis, Memcached)</h3>
<ul>
<li><strong>Key-Value Stores:</strong> NoSQL data stores that store data in RAM for extreme performance.</li>
<li><strong>Persistence:</strong> While they are in-memory, some can be configured to periodically save data to disk.</li>
</ul>
<h3>Caching Strategies</h3>
<img src="https://cdn.hashnode.com/uploads/covers/6af0daddfec6897e856e10fe/28895fd8-3d06-4dce-93ad-ce3b508cd7f5.png" alt="Caching Strategies" style="display:block;margin:0 auto" />

<ul>
<li><strong>Lazy Caching (Cache-Aside):</strong> Data is only cached when it is requested for the first time.</li>
<li><strong>Write-Through:</strong> Data is updated in both the cache and the primary database during a write operation to ensure cache freshness.</li>
</ul>
<h3>Eviction Policies (When Memory Is Full)</h3>
<ul>
<li><strong>LRU (Least Recently Used):</strong> Removes the data that hasn't been accessed for the longest time.</li>
<li><strong>LFU (Least Frequently Used):</strong> Removes the data with the lowest access frequency.</li>
<li><strong>TTL-Based:</strong> Removes keys that have expired.</li>
</ul>
<h2>Practical Use Cases of Caching</h2>
<ul>
<li><strong>Database Query Caching:</strong> Stores results of complex, compute-intensive SQL joins to avoid hitting the database for frequent, read-heavy requests.</li>
<li><strong>Session Management:</strong> Stores authentication session tokens in Redis to verify users instantly without database lookups on every request.</li>
<li><strong>External API Caching:</strong> Stores responses from third-party APIs (e.g., weather data) to reduce billing costs and avoid hitting rate limits.</li>
<li><strong>Rate Limiting:</strong> Uses an in-memory counter in Redis to track request counts per IP address, preventing abuse and protecting backend resources.</li>
</ul>
<h2>Conclusion</h2>
<p>Caching is one of the fundamental techniques used to improve performance in modern computing systems. From CPU caches to CDNs and in-memory databases like Redis, the underlying idea remains the same: store frequently accessed data in a faster location to reduce latency and avoid redundant operations.</p>
<p>However, caching is not just about making systems faster. It also involves deciding what to cache, when to update it, how long to keep it, and when to remove it.</p>
<p>Understanding these fundamentals makes it easier to design faster and more efficient applications.</p>
]]></content:encoded></item></channel></rss>