<?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 Himanshu Bhatia on Medium]]></title>
        <description><![CDATA[Stories by Himanshu Bhatia on Medium]]></description>
        <link>https://medium.com/@himanshuu.bhatia21?source=rss-71d91c5c2166------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*-ilcHLlRQ9SUHYdO</url>
            <title>Stories by Himanshu Bhatia on Medium</title>
            <link>https://medium.com/@himanshuu.bhatia21?source=rss-71d91c5c2166------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 00:27:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@himanshuu.bhatia21/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[Mastering Caching in System Design: Techniques, Patterns, and Best Practices]]></title>
            <link>https://medium.com/@himanshuu.bhatia21/mastering-caching-in-system-design-techniques-patterns-and-best-practices-cc4dcda77533?source=rss-71d91c5c2166------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc4dcda77533</guid>
            <category><![CDATA[caching]]></category>
            <category><![CDATA[caching-strategies]]></category>
            <category><![CDATA[system-design-interview]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[cache]]></category>
            <dc:creator><![CDATA[Himanshu Bhatia]]></dc:creator>
            <pubDate>Thu, 16 Jan 2025 14:04:36 GMT</pubDate>
            <atom:updated>2025-01-16T14:04:36.316Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is a Cache?</h3><p>In simple terms, a cache is a temporary storage that provides quick access to frequently used data. It’s usually stored into the memory for low latency.</p><p><strong>Imagine a Scenario: Caching in E-commerce platform</strong></p><p><strong>Problem: </strong>An e-commerce platform experiences high traffic during sales events, with thousands of users browsing products simultaneously. Each product page includes details such as name, price, description, images, stock availability, and reviews. Fetching this data directly from the database for every user request causes significant latency and puts a heavy load on the database.</p><p><strong>How Caching solves this problem?</strong></p><p><strong>1. Caching Product Details</strong>:<br>Product details (name, price, description, and images) change infrequently, so they can be cached in a distributed in-memory store like <strong>Redis</strong> or <strong>Memcached</strong>. When a user requests a product page:</p><ul><li>First, the system checks if the product details are in the cache.</li><li>If available (cache hit), the data is served from the cache, reducing latency.</li><li>If not (cache miss), the data is fetched from the database, stored in the cache, and served to the user.</li></ul><p><strong>2. Caching Stock Availability</strong>:<br>Stock availability updates frequently but can still benefit from caching with a short expiration time (e.g., 5–10 seconds). This balances freshness and performance.</p><p><strong>3. Caching User-Specific Recommendations</strong>:<br>Recommendations personalized for users based on browsing history are computationally expensive to generate. By caching the recommendations and updating them periodically, the system reduces the load on recommendation engines.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OTwyJiYYUezjIcOTdEbNCw.png" /><figcaption>Caching</figcaption></figure><h3>Caches in Different Layers</h3><ol><li><strong>Processor Caches (Hardware Level): </strong>Processor caches are small, fast memory located close to the CPU core. They store frequently used instruction or data to reduce the latency. Common levels include:</li></ol><ul><li><strong>L1 Cache: </strong>It is closest to the CPU core, smallest size and fastest access. Split into instruction cache (stores instruction) and data cache (stores data). Typical size: <strong>32–128 KB</strong></li><li><strong>L2 Cache: </strong>Larger than L1, shared by one or more cores. Slightly slower but still it is faster than the main memory. Typical size: <strong>256 KB - 4MB.</strong></li><li><strong>L3 Cache: </strong>It is shared across all CPU cores. Typical size: <strong>4 - 32 MB.</strong></li></ul><p><strong>2. Main Memory (RAM) and Paging Caches:</strong></p><ul><li><strong>RAM Cache: </strong>It stores frequently used memory pages.</li><li><strong>Translation Lookaside Buffer (TLB): </strong>Part of the CPU, speeds up virtual-to-physical memory address translation.</li></ul><p><strong>3. Storage Level Caches:</strong></p><ul><li><strong>Disk Cache: </strong>Stores recently accessed data from a hard drive or SSD in faster memory. Found in operating systems (e.g., page cache) or within disk controllers.</li><li><strong>SSD Cache: </strong>Uses NAND flash memory as cache for slower storage (e.g., HDD)</li></ul><p><strong>4. Operating System Caches:</strong></p><ul><li><strong>Page Cache: </strong>It is managed by the OS, stores file data read from storage in memory. It speeds up the file access.</li><li><strong>Buffer Cache: I</strong>t stores data temporarily during I/O operations to improve performance.</li></ul><p><strong>5. Application-Level Caches:</strong></p><ul><li><strong>Web Browser Cache: </strong>Stores website data (HTML, Images, CSS) locally to speed up the page loading.</li><li><strong>Database Cache: </strong>Applications like MYSQL or Redis caches frequently used queries or data in memory.</li></ul><p><strong>6. Network Level Caches:</strong></p><ul><li><strong>CDN Cache: </strong>Content Delivery Network (CDNs) cache web content closer to the user to reduce latency.</li><li><strong>DNS Cache: </strong>Resolves domain names to IP address locally to reduce query times.</li></ul><h3><strong>Cache Eviction Policies</strong></h3><ol><li><strong>First in First out (FIFO): </strong>Removes the oldest item in the cache, regardless of how frequently or recently it was used.</li></ol><ul><li><strong>Use Case: </strong>Simple to implement and works well when access pattern are uniform.</li></ul><p>2. <strong>Last in First out (LIFO): </strong>Removes the most recently added item from the cache.</p><ul><li><strong>Use Case: </strong>LIFO is not widely applicable for general-purpose caching because it contradicts typical cache access pattern, where recent or frequently used cache item are expected to stay in cache.</li></ul><p><strong>3. Least Frequently Used (LFU): </strong>Removes the item accessed the least number of times.</p><ul><li><strong>Use Case: </strong>Effective when the access frequency of items determine their value.</li></ul><p>4. <strong>Least Recently Used (LRU): </strong>Removes the item that has been accessed least recently.</p><ul><li><strong>Use Case: </strong>Suitable for scenario where recently accessed data is likely to be accessed again.</li></ul><h3><strong>Caching Patterns</strong></h3><ol><li><strong>Cache Aside:</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VFx0IB58bza7JVPQHs_gHA.png" /><figcaption>Cache Aside</figcaption></figure><p><strong>Workflow:</strong></p><ul><li>Read data from cache.</li><li>Read data from the database on a <strong>cache miss.</strong></li><li>Write data to Cache</li><li>Return the Data.</li></ul><p>It’s also called <strong>Lazy loading, </strong>because only the query data get’s cached. Also, the cache doesn’t interact with the DB but the application does.</p><p><strong>Advantages:</strong></p><ul><li>Easy Implementation</li><li>Finer control over cache population.</li></ul><p><strong>Disadvantages:</strong></p><ul><li>Degraded Latency</li><li>Potential Data inconsistency.</li></ul><p><strong>2. Write Through:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/939/1*4xFWnHd-2aB-dGsvMzyUpw.png" /><figcaption>Write Through</figcaption></figure><p><strong>Workflow:</strong></p><ul><li>Write Data to cache.</li><li>And the<strong> cache writes </strong>data synchronously to the database.</li></ul><p><strong>Advantages:</strong></p><ul><li>Data consistency</li><li>Low read latency.</li></ul><p><strong>Disadvantages:</strong></p><ul><li>High write latency.</li><li>Most data in the cache is never read.</li></ul><p><strong>3. Read Through:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/939/1*ZiihlsEDkrcqINPfe835Aw.png" /><figcaption>Read Through</figcaption></figure><p><strong>Workflow:</strong></p><ul><li>Read data from cache</li><li>Read data from the Database on a <strong>cache miss.</strong></li><li>Write data to cache.</li><li>Return the data.</li></ul><p>The app doesn’t interact with the database, but the cache does. This is what makes it different from the <strong>aside pattern.</strong></p><p><strong>Advantages:</strong></p><ul><li>Low read frequency for frequently accessed data.</li><li>Improved read scalability.</li></ul><p><strong>Disadvantages:</strong></p><ul><li>Potential data inconsistency.</li><li>High latency on a <strong>cache miss.</strong></li></ul><h4><strong>Local Caching System</strong></h4><p>Local caching refers to storing data on a single machine or within a single application. It’s commonly used in scenarios where data retrieval is limited or where the volume of data is relatively small.</p><h4>Distributed Caching System</h4><p>Distributed caching involves storing data across multiple machines or nodes, often in a network. This type of caching is essential for applications that need to scale across multiple systems.\</p><h4>Local Vs. Distributed Caching System</h4><p>Consider an e-commerce website that receives <strong>thousands of request per second.</strong> If the website relies solely on local caching, it might store product details on the server where the website is hosted. However, as traffic increases or if the website is accessed from different regions, this approach can lead to bottleneck.</p><p>On the other hand, with <strong>distributed caching, </strong>products can be stored on across multiple cache servers located in different regions. When a user accesses a website, the system retrieves product details from the nearest cache servers, ensuring faster response time and a better user experience.</p><h3><strong>Conclusion</strong></h3><p>Caching is a critical component in system design, enabling improved performance, reduced latency, and efficient resource utilization. By leveraging different caching layers, patterns, and eviction policies, systems can handle high traffic and scale effectively. The choice between local and distributed caching depends on the application’s requirements, such as data consistency, access patterns, and geographic distribution. Properly implemented caching strategies ensure a seamless and responsive user experience, making them indispensable for modern, high-performance applications.</p><p>Feel free to share your thoughts and suggestions. I’d be happy to connect and talk with you! My social media handles are:</p><p><a href="https://www.linkedin.com/in/himanshu-bhatia-03494a1b6/"><strong>Linkedin </strong></a>| <a href="https://github.com/himanshubhatia2910"><strong>Github</strong></a></p><p>or just drop me an email at: himanshu.mbhatia@gmail.com</p><p>Thank you for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc4dcda77533" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Deep Dive into Content Delivery Networks (CDN)]]></title>
            <link>https://medium.com/@himanshuu.bhatia21/a-deep-dive-into-content-delivery-networks-cdn-ca0184306861?source=rss-71d91c5c2166------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca0184306861</guid>
            <category><![CDATA[system-design-interview]]></category>
            <category><![CDATA[caching]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[content-delivery-network]]></category>
            <dc:creator><![CDATA[Himanshu Bhatia]]></dc:creator>
            <pubDate>Mon, 01 Jan 2024 10:34:34 GMT</pubDate>
            <atom:updated>2025-01-12T14:17:38.261Z</atom:updated>
            <content:encoded><![CDATA[<p>The landscape of web development and infrastructure is evolving quickly, and the need for speed has become a non-negotiable factor. It is expected by users to get instant access to the information and a seamless experience with faster load times. Now, this is made possible with the help of Content Delivery Networks (CDNs).</p><p><strong>Imagine a scenario: </strong>You click on a link and you’re eagerly waiting for the content of page to load, but you’re met with the frustration of slow-loading page. We’ve all been there, feeling the impatience with every passing second. In these moments, the CDNs play a significant role in delivering the content to end user quickly and efficiently.</p><p>In this blog series, I’m going to explain the fundamentals of system design and the basic building block of it, and our first stop is Content Delivery Networks (CDNs). Let’s get started!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Jk7FxKo-A7jGPT1dIUElA.png" /><figcaption>Content Delivery Network (CDN)</figcaption></figure><h3>What is CDN?</h3><p>In simple terms, a CDN is a distributed network infrastructure that help to deliver the content to the end user efficiently and quickly. The content can be anything like web pages, images, videos, etc.</p><p>With the help of CDN, the content is distributed across multiple servers strategically that are located in different geographical location, often referred to as Points of Presence (POPs). Instead of serving content from a single central server, this distributed approach is used.</p><p>The CDN automatically determines the nearest edge server based on factors such as network proximity and server availability.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HLFzVg5SOHyXL40RF9rypA.png" /><figcaption>CDN Efficiency Illustration</figcaption></figure><p>The above image represents how a CDN can improve the speed of retrieving an image from a web server. A copy of image can be stored on the CDN and when a user requests the image, the image can be accessed from the nearest CDN that will improve the overall speed and performance.</p><h3>How CDN Improves Load Time?</h3><p>The load time is improved due to the following factors:-</p><ol><li><strong>Reduced Network Distance: </strong>The content is brought closer to the user with the help of CDN by placing edge servers in geographically strategic locations worldwide.</li><li><strong>Load Balancing: </strong>If one server is facing high traffic or it is currently unavailable, the CDN can route request to other nearby server.</li><li><strong>Caching: </strong>When a user requests a specific content, if the content is present in the cache, the CDN serves it directly from the cache. This eliminates the need to fetch it from the origin server.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5VrGRozNHtNxrO4TSk0tPQ.png" /><figcaption>CDN Workflow</figcaption></figure><ol><li>Imagine Client A is trying to access an image, let’s call it “image.jpeg,” using a URL provided by a CDN (Content Delivery Network) provider.</li><li>Now, if the CDN server doesn’t already have “image.jpeg” in its cache, it fetches the file from the origin. This origin could be a web server or an online storage service like a Firebase bucket.</li><li>The origin sends response containing “image.jpeg” back to the CDN server, and here’s where it gets interesting. Along with the image, the origin may include an optional HTTP header called Time-to-Live (TTL). This TTL essentially tells the CDN server how long it’s allowed to cache the image.</li><li>With the image now safely cached, the CDN server fulfills the request from Client A by delivering the image.</li><li>Now, let’s say Client B enters the scene and sends a request for the same image.</li><li>If the TTL hasn’t expired, the CDN server retrieves the image directly from its cache and delivers it to Client B.</li></ol><p>This process not only optimizes the delivery of content but also ensures that frequently accessed resources are readily available, offering a seamless experience to both Client A and Client B.</p><h3>Benefits of CDN</h3><ol><li><strong>Improved Performance: </strong>CDNs significantly boost website speed and loading times by caching and delivering content from servers strategically positioned closer to end-users.</li><li><strong>Scalability:</strong> CDNs enable scalability, allowing websites to handle increased traffic effortlessly by distributing content across a network of servers.</li><li><strong>Global Reach:</strong> With servers strategically located worldwide, CDNs ensure a global reach, reducing latency and providing a consistent user experience regardless of geographical location.</li><li><strong>Reliability:</strong> CDNs enhance reliability through redundancy, with content stored on multiple servers. Even if one server fails, others can pick up the load, ensuring uninterrupted service.</li><li><strong>Security: </strong>CDNs offers features like DDoS mitigation, SSL encryption, and web application firewall (WAF) protection, safeguarding against various online threats and attacks.</li></ol><h3>Conclusion</h3><p>System design is crucial as it lays the foundation for efficient, scalable, and resilient digital architectures, ensuring optimal performance and user experience. In this blog series, we will delve into all the fundamental and core concepts of System Design. This installment focused on the essentials of Content Delivery Networks (CDNs). In the next blog, we’ll explore caches and dive deep into caching.</p><p>Feel free to share your thoughts and suggestions. I’d be happy to connect and talk with you! My social media handles are:</p><p><a href="https://www.linkedin.com/in/himanshu-bhatia-03494a1b6/"><strong>Linkedin </strong></a>| <a href="https://github.com/himanshubhatia2910"><strong>Github</strong></a></p><p>or just drop me an email at: <strong>himanshuu.bhatia21@vit.edu</strong></p><p>Thank you for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca0184306861" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>