<?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:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0"><channel><title><![CDATA[System Design Codex]]></title><description><![CDATA[The best place to learn practical System Design with concepts and case studies]]></description><link>https://newsletter.systemdesigncodex.com</link><image><url>https://substackcdn.com/image/fetch/$s_!wAIR!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1adf652d-a848-4f3c-9100-3f025578ae11_256x256.png</url><title>System Design Codex</title><link>https://newsletter.systemdesigncodex.com</link></image><generator>Substack</generator><lastBuildDate>Wed, 22 Apr 2026 05:01:02 GMT</lastBuildDate><atom:link href="https://newsletter.systemdesigncodex.com/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[Saurabh Dashora]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[systemcodex@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[systemcodex@substack.com]]></itunes:email><itunes:name><![CDATA[Saurabh Dashora]]></itunes:name></itunes:owner><itunes:author><![CDATA[Saurabh Dashora]]></itunes:author><googleplay:owner><![CDATA[systemcodex@substack.com]]></googleplay:owner><googleplay:email><![CDATA[systemcodex@substack.com]]></googleplay:email><googleplay:author><![CDATA[Saurabh Dashora]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[Top Resiliency Patterns for Developers]]></title><description><![CDATA[Quick Guide]]></description><link>https://newsletter.systemdesigncodex.com/p/top-resiliency-patterns-for-developers</link><guid isPermaLink="false">https://newsletter.systemdesigncodex.com/p/top-resiliency-patterns-for-developers</guid><dc:creator><![CDATA[Saurabh Dashora]]></dc:creator><pubDate>Tue, 21 Apr 2026 06:08:56 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!eBaM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b084659-16be-42d9-ba14-e9b0ef568813_2175x1361.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Distributed systems are great at providing scalability and high availability to meet user demands.</p><p>But with increased complexity comes greater risk.</p><p>If you are building distributed systems, you must invest in proactive strategies to ensure resiliency. These strategies can be divided into two categories:</p><ul><li><p>Downstream Patterns</p></li><li><p>Upstream Patterns</p></li></ul><p>Let&#8217;s look at both.</p><h1><strong>Downstream Resiliency Patterns</strong></h1><p>Downstream patterns are used by the service caller. They are implemented by a service when it communicates with another service, ensuring that a failure in the downstream system doesn&#8217;t cause a domino effect.</p><h2><strong>1 - Timeouts</strong></h2><p>A timeout is a mechanism that prevents a service from waiting indefinitely for a response from a downstream service. By setting a maximum wait time, you avoid tying up resources that could be used for other requests.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!eBaM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b084659-16be-42d9-ba14-e9b0ef568813_2175x1361.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!eBaM!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b084659-16be-42d9-ba14-e9b0ef568813_2175x1361.png 424w, https://substackcdn.com/image/fetch/$s_!eBaM!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b084659-16be-42d9-ba14-e9b0ef568813_2175x1361.png 848w, https://substackcdn.com/image/fetch/$s_!eBaM!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b084659-16be-42d9-ba14-e9b0ef568813_2175x1361.png 1272w, https://substackcdn.com/image/fetch/$s_!eBaM!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b084659-16be-42d9-ba14-e9b0ef568813_2175x1361.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!eBaM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b084659-16be-42d9-ba14-e9b0ef568813_2175x1361.png" width="1456" height="911" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5b084659-16be-42d9-ba14-e9b0ef568813_2175x1361.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:911,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:173044,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!eBaM!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b084659-16be-42d9-ba14-e9b0ef568813_2175x1361.png 424w, https://substackcdn.com/image/fetch/$s_!eBaM!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b084659-16be-42d9-ba14-e9b0ef568813_2175x1361.png 848w, https://substackcdn.com/image/fetch/$s_!eBaM!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b084659-16be-42d9-ba14-e9b0ef568813_2175x1361.png 1272w, https://substackcdn.com/image/fetch/$s_!eBaM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b084659-16be-42d9-ba14-e9b0ef568813_2175x1361.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/8hO96SC5UPofVRnz1mtY?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><h4><strong>Why It&#8217;s Important:</strong></h4><ul><li><p>Prevents resource exhaustion caused by requests stuck waiting indefinitely.</p></li><li><p>Improves overall system responsiveness by allowing failed requests to be handled quickly.</p></li></ul><h4><strong>Implementation Tips:</strong></h4><ul><li><p>Fine-tune timeouts based on the expected response times of downstream services. For example, a cache lookup might have a 50ms timeout, while a database query might have a 500ms timeout.</p></li><li><p>Combine timeouts with monitoring to identify latency patterns and adjust as needed.</p></li></ul><h2><strong>2 - Circuit Breaker</strong></h2><p>A circuit breaker monitors the success and failure rates of requests and temporarily disables calls to a service if failures exceed a predefined threshold. Like an electrical circuit breaker, it prevents further damage by &#8220;tripping&#8221; the connection.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!aimz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb06ab6c3-a6e1-471e-9cdd-aa3160e1e8f5_5094x4494.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!aimz!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb06ab6c3-a6e1-471e-9cdd-aa3160e1e8f5_5094x4494.png 424w, https://substackcdn.com/image/fetch/$s_!aimz!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb06ab6c3-a6e1-471e-9cdd-aa3160e1e8f5_5094x4494.png 848w, https://substackcdn.com/image/fetch/$s_!aimz!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb06ab6c3-a6e1-471e-9cdd-aa3160e1e8f5_5094x4494.png 1272w, https://substackcdn.com/image/fetch/$s_!aimz!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb06ab6c3-a6e1-471e-9cdd-aa3160e1e8f5_5094x4494.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!aimz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb06ab6c3-a6e1-471e-9cdd-aa3160e1e8f5_5094x4494.png" width="1456" height="1285" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b06ab6c3-a6e1-471e-9cdd-aa3160e1e8f5_5094x4494.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1285,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1471232,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!aimz!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb06ab6c3-a6e1-471e-9cdd-aa3160e1e8f5_5094x4494.png 424w, https://substackcdn.com/image/fetch/$s_!aimz!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb06ab6c3-a6e1-471e-9cdd-aa3160e1e8f5_5094x4494.png 848w, https://substackcdn.com/image/fetch/$s_!aimz!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb06ab6c3-a6e1-471e-9cdd-aa3160e1e8f5_5094x4494.png 1272w, https://substackcdn.com/image/fetch/$s_!aimz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb06ab6c3-a6e1-471e-9cdd-aa3160e1e8f5_5094x4494.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/8hO96SC5UPofVRnz1mtY?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><h4><strong>Why It&#8217;s Important:</strong></h4><ul><li><p>Protects your system from overwhelming downstream services during failures.</p></li><li><p>Allows time for the downstream service to recover.</p></li></ul><h4><strong>Implementation Tips:</strong></h4><ul><li><p>Implement with standard libraries like Resilience4j to handle circuit breakers.</p></li><li><p>Define three states for the circuit:</p><ol><li><p><strong>Closed</strong>: Requests flow as usual.</p></li><li><p><strong>Open</strong>: Requests are blocked after reaching a failure threshold.</p></li><li><p><strong>Half-Open</strong>: A limited number of test requests are sent to check if the downstream service has recovered.</p></li></ol></li><li><p>Tune thresholds carefully, such as the number of failures or the time window for evaluating failures.</p></li></ul><h2><strong>3 - Retries with Exponential Backoff</strong></h2><p>Retries are essential when transient failures occur.</p><p>Exponential backoff adds a delay between retries, doubling the wait time after each attempt. This gives the downstream service more time to recover and avoids overwhelming it.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!jQfE!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff343deb2-c014-4da0-b17e-7d6e2598498b_2175x1710.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!jQfE!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff343deb2-c014-4da0-b17e-7d6e2598498b_2175x1710.png 424w, https://substackcdn.com/image/fetch/$s_!jQfE!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff343deb2-c014-4da0-b17e-7d6e2598498b_2175x1710.png 848w, https://substackcdn.com/image/fetch/$s_!jQfE!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff343deb2-c014-4da0-b17e-7d6e2598498b_2175x1710.png 1272w, https://substackcdn.com/image/fetch/$s_!jQfE!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff343deb2-c014-4da0-b17e-7d6e2598498b_2175x1710.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!jQfE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff343deb2-c014-4da0-b17e-7d6e2598498b_2175x1710.png" width="1456" height="1145" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f343deb2-c014-4da0-b17e-7d6e2598498b_2175x1710.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1145,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:257995,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!jQfE!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff343deb2-c014-4da0-b17e-7d6e2598498b_2175x1710.png 424w, https://substackcdn.com/image/fetch/$s_!jQfE!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff343deb2-c014-4da0-b17e-7d6e2598498b_2175x1710.png 848w, https://substackcdn.com/image/fetch/$s_!jQfE!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff343deb2-c014-4da0-b17e-7d6e2598498b_2175x1710.png 1272w, https://substackcdn.com/image/fetch/$s_!jQfE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff343deb2-c014-4da0-b17e-7d6e2598498b_2175x1710.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/8hO96SC5UPofVRnz1mtY?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><h4><strong>Why It&#8217;s Important:</strong></h4><ul><li><p>Increases the likelihood of success when the failure is temporary.</p></li><li><p>Reduces the risk of overloading a struggling downstream service.</p></li></ul><h4><strong>Implementation Tips:</strong></h4><ul><li><p>Combine retries with a maximum retry limit to avoid infinite loops.</p></li><li><p>Use jitter (randomized delay) in conjunction with exponential backoff to prevent synchronized retries from multiple clients causing a &#8220;thundering herd&#8221; problem.</p></li><li><p>Example: First retry after 100ms, second after 200ms, third after 400ms, with a maximum of 5 retries.</p></li></ul><h1><strong>Upstream Resiliency Patterns</strong></h1><p>Upstream patterns are used by the service owner. They are implemented by service owners to safeguard the health of their service and ensure stability during high traffic or failures.</p><h2><strong>1 - Load Shedding</strong></h2><p>Load shedding involves rejecting a portion of incoming requests when a service is overloaded.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!4fLm!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9167830a-a921-4f98-925f-436733fae2c7_2175x1361.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!4fLm!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9167830a-a921-4f98-925f-436733fae2c7_2175x1361.png 424w, https://substackcdn.com/image/fetch/$s_!4fLm!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9167830a-a921-4f98-925f-436733fae2c7_2175x1361.png 848w, https://substackcdn.com/image/fetch/$s_!4fLm!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9167830a-a921-4f98-925f-436733fae2c7_2175x1361.png 1272w, https://substackcdn.com/image/fetch/$s_!4fLm!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9167830a-a921-4f98-925f-436733fae2c7_2175x1361.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!4fLm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9167830a-a921-4f98-925f-436733fae2c7_2175x1361.png" width="1456" height="911" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9167830a-a921-4f98-925f-436733fae2c7_2175x1361.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:911,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:184542,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!4fLm!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9167830a-a921-4f98-925f-436733fae2c7_2175x1361.png 424w, https://substackcdn.com/image/fetch/$s_!4fLm!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9167830a-a921-4f98-925f-436733fae2c7_2175x1361.png 848w, https://substackcdn.com/image/fetch/$s_!4fLm!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9167830a-a921-4f98-925f-436733fae2c7_2175x1361.png 1272w, https://substackcdn.com/image/fetch/$s_!4fLm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9167830a-a921-4f98-925f-436733fae2c7_2175x1361.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/8hO96SC5UPofVRnz1mtY?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><h4><strong>Why It&#8217;s Important:</strong></h4><ul><li><p>Prevents complete system failure during peak loads.</p></li><li><p>Ensures critical users or requests are prioritized.</p></li></ul><h4><strong>Implementation Tips:</strong></h4><ul><li><p>Use techniques like token-bucket or leaky-bucket algorithms to control the rate of incoming requests.</p></li><li><p>Implement priority queues to ensure critical requests (e.g., payment transactions) are handled first.</p></li><li><p>Gradually degrade non-critical features or services under heavy load (e.g., disabling analytics during peak demand).</p></li></ul><h2><strong>2 - Rate Limiting</strong></h2><p>Rate limiting sets the maximum number of requests that a client can make within a specific time window. This prevents individual clients or malicious actors from overwhelming your service.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!5MHc!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26ce5f0c-a68d-4b5d-a7e8-daab0f7d280a_2175x1361.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!5MHc!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26ce5f0c-a68d-4b5d-a7e8-daab0f7d280a_2175x1361.png 424w, https://substackcdn.com/image/fetch/$s_!5MHc!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26ce5f0c-a68d-4b5d-a7e8-daab0f7d280a_2175x1361.png 848w, https://substackcdn.com/image/fetch/$s_!5MHc!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26ce5f0c-a68d-4b5d-a7e8-daab0f7d280a_2175x1361.png 1272w, https://substackcdn.com/image/fetch/$s_!5MHc!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26ce5f0c-a68d-4b5d-a7e8-daab0f7d280a_2175x1361.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!5MHc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26ce5f0c-a68d-4b5d-a7e8-daab0f7d280a_2175x1361.png" width="1456" height="911" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/26ce5f0c-a68d-4b5d-a7e8-daab0f7d280a_2175x1361.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:911,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:146394,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!5MHc!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26ce5f0c-a68d-4b5d-a7e8-daab0f7d280a_2175x1361.png 424w, https://substackcdn.com/image/fetch/$s_!5MHc!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26ce5f0c-a68d-4b5d-a7e8-daab0f7d280a_2175x1361.png 848w, https://substackcdn.com/image/fetch/$s_!5MHc!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26ce5f0c-a68d-4b5d-a7e8-daab0f7d280a_2175x1361.png 1272w, https://substackcdn.com/image/fetch/$s_!5MHc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26ce5f0c-a68d-4b5d-a7e8-daab0f7d280a_2175x1361.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/8hO96SC5UPofVRnz1mtY?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><h4><strong>Why It&#8217;s Important:</strong></h4><ul><li><p>Protects the service from abuse, such as Distributed Denial of Service (DDoS) attacks.</p></li><li><p>Ensures fair resource usage across all clients.</p></li></ul><h4><strong>Implementation Tips:</strong></h4><ul><li><p>Implement rate-limiting algorithms like the fixed window, sliding window, or token bucket.</p></li><li><p>Use APIs or middleware solutions such as API Gateway, NGINX, or tools like Kong.</p></li><li><p>Provide informative error messages (e.g., HTTP 429 Too Many Requests) to guide clients on retry strategies.</p></li></ul><h2><strong>3 - Bulkheads</strong></h2><p>Bulkheading involves isolating different parts of the system to prevent failures in one component from cascading to others. This is analogous to compartments in a ship&#8212;if one is breached, the others remain unaffected.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!dI27!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb81b2df7-c7c2-4017-83e9-209a50b57311_2175x1361.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!dI27!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb81b2df7-c7c2-4017-83e9-209a50b57311_2175x1361.png 424w, https://substackcdn.com/image/fetch/$s_!dI27!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb81b2df7-c7c2-4017-83e9-209a50b57311_2175x1361.png 848w, https://substackcdn.com/image/fetch/$s_!dI27!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb81b2df7-c7c2-4017-83e9-209a50b57311_2175x1361.png 1272w, https://substackcdn.com/image/fetch/$s_!dI27!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb81b2df7-c7c2-4017-83e9-209a50b57311_2175x1361.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!dI27!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb81b2df7-c7c2-4017-83e9-209a50b57311_2175x1361.png" width="1456" height="911" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b81b2df7-c7c2-4017-83e9-209a50b57311_2175x1361.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:911,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:150007,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!dI27!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb81b2df7-c7c2-4017-83e9-209a50b57311_2175x1361.png 424w, https://substackcdn.com/image/fetch/$s_!dI27!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb81b2df7-c7c2-4017-83e9-209a50b57311_2175x1361.png 848w, https://substackcdn.com/image/fetch/$s_!dI27!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb81b2df7-c7c2-4017-83e9-209a50b57311_2175x1361.png 1272w, https://substackcdn.com/image/fetch/$s_!dI27!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb81b2df7-c7c2-4017-83e9-209a50b57311_2175x1361.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/8hO96SC5UPofVRnz1mtY?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><h4><strong>Why It&#8217;s Important:</strong></h4><ul><li><p>Limits the blast radius of failures.</p></li><li><p>Improves fault isolation and prevents a single failure from affecting the entire system.</p></li></ul><h4><strong>Implementation Tips:</strong></h4><ul><li><p>Separate resource pools for different components (e.g., thread pools or connection pools for different services).</p></li><li><p>Isolate critical resources to prevent non-critical services from consuming them (e.g., separate database connections for high-priority and low-priority queries).</p></li><li><p>Use container orchestration tools like Kubernetes to allocate dedicated resources to specific services.</p></li></ul><h2><strong>4 - Health Checks with Load Balancers</strong></h2><p>Health checks monitor the status of service instances and enable a load balancer to redirect traffic away from unhealthy instances. This ensures that users are always routed to functioning parts of the system.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!2XzB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F86789376-d0ab-49a5-915f-a2458009a1f3_2175x1361.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!2XzB!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F86789376-d0ab-49a5-915f-a2458009a1f3_2175x1361.png 424w, https://substackcdn.com/image/fetch/$s_!2XzB!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F86789376-d0ab-49a5-915f-a2458009a1f3_2175x1361.png 848w, https://substackcdn.com/image/fetch/$s_!2XzB!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F86789376-d0ab-49a5-915f-a2458009a1f3_2175x1361.png 1272w, https://substackcdn.com/image/fetch/$s_!2XzB!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F86789376-d0ab-49a5-915f-a2458009a1f3_2175x1361.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!2XzB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F86789376-d0ab-49a5-915f-a2458009a1f3_2175x1361.png" width="1456" height="911" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/86789376-d0ab-49a5-915f-a2458009a1f3_2175x1361.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:911,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:264574,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!2XzB!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F86789376-d0ab-49a5-915f-a2458009a1f3_2175x1361.png 424w, https://substackcdn.com/image/fetch/$s_!2XzB!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F86789376-d0ab-49a5-915f-a2458009a1f3_2175x1361.png 848w, https://substackcdn.com/image/fetch/$s_!2XzB!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F86789376-d0ab-49a5-915f-a2458009a1f3_2175x1361.png 1272w, https://substackcdn.com/image/fetch/$s_!2XzB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F86789376-d0ab-49a5-915f-a2458009a1f3_2175x1361.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/8hO96SC5UPofVRnz1mtY?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><h4><strong>Why It&#8217;s Important:</strong></h4><ul><li><p>Prevents traffic from being sent to failing or degraded instances.</p></li><li><p>Improves overall user experience by minimizing downtime.</p></li></ul><h4><strong>Implementation Tips:</strong></h4><ul><li><p>Use active health checks (periodic pings) or passive health checks (monitoring error rates).</p></li><li><p>Configure thresholds for health checks, such as the number of failed requests or response latency.</p></li><li><p>Implement rolling updates with health checks to ensure smooth deployment without downtime.</p></li></ul><p><strong>So - which resiliency patterns have you used in your project?</strong></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/top-resiliency-patterns-for-developers/comments&quot;,&quot;text&quot;:&quot;Leave a comment&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/top-resiliency-patterns-for-developers/comments"><span>Leave a comment</span></a></p><div><hr></div><p><strong>That&#8217;s it for today! &#9728;&#65039;</strong></p><p>Enjoyed this issue of the newsletter?</p><p>Share with your friends and colleagues.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/top-resiliency-patterns-for-developers?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/top-resiliency-patterns-for-developers?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p></p>]]></content:encoded></item><item><title><![CDATA[What is the BFF Pattern?]]></title><description><![CDATA[And when do you need it?]]></description><link>https://newsletter.systemdesigncodex.com/p/what-is-the-bff-pattern</link><guid isPermaLink="false">https://newsletter.systemdesigncodex.com/p/what-is-the-bff-pattern</guid><dc:creator><![CDATA[Saurabh Dashora]]></dc:creator><pubDate>Tue, 07 Apr 2026 08:41:56 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!rMIC!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fef7849f7-bede-4d65-9adf-c01713e6d324_2107x1315.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Sometimes in software development, all you need is a BFF.</p><p>In software development, the term BFF, which stands for Backends-for-Frontends, refers to a design pattern where dedicated API gateways are created for each device or interface type.</p><p>For example, you create a separate BFF for web browsers, mobile apps, or public/partner APIs.</p><p>Each BFF acts as a specialized layer between the client and the underlying services, tailoring the API to the specific needs of the client.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!rMIC!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fef7849f7-bede-4d65-9adf-c01713e6d324_2107x1315.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!rMIC!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fef7849f7-bede-4d65-9adf-c01713e6d324_2107x1315.png 424w, https://substackcdn.com/image/fetch/$s_!rMIC!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fef7849f7-bede-4d65-9adf-c01713e6d324_2107x1315.png 848w, https://substackcdn.com/image/fetch/$s_!rMIC!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fef7849f7-bede-4d65-9adf-c01713e6d324_2107x1315.png 1272w, https://substackcdn.com/image/fetch/$s_!rMIC!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fef7849f7-bede-4d65-9adf-c01713e6d324_2107x1315.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!rMIC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fef7849f7-bede-4d65-9adf-c01713e6d324_2107x1315.png" width="1456" height="909" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ef7849f7-bede-4d65-9adf-c01713e6d324_2107x1315.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:909,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:194724,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!rMIC!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fef7849f7-bede-4d65-9adf-c01713e6d324_2107x1315.png 424w, https://substackcdn.com/image/fetch/$s_!rMIC!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fef7849f7-bede-4d65-9adf-c01713e6d324_2107x1315.png 848w, https://substackcdn.com/image/fetch/$s_!rMIC!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fef7849f7-bede-4d65-9adf-c01713e6d324_2107x1315.png 1272w, https://substackcdn.com/image/fetch/$s_!rMIC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fef7849f7-bede-4d65-9adf-c01713e6d324_2107x1315.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/5SU8bM1gDCRzZFjh1tQi?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><h2><strong>Key Characteristics of BFFs</strong></h2><ol><li><p><strong>Dedicated API Gateway</strong>: Each BFF serves as a dedicated API gateway for a specific device or interface type. It encapsulates the logic and requirements specific to that client type.</p></li><li><p><strong>Customized Functionality</strong>: BFFs can handle various functionalities beyond simple API routing. They can perform tasks such as:</p><ol><li><p>rate limiting,</p></li><li><p>authentication,</p></li><li><p>header sanitization</p></li><li><p>cache control</p></li></ol></li><li><p><strong>Decoupling from Lower-Level Services</strong>: By implementing BFFs, the logic specific to different client types is abstracted away from the lower-level services. This allows the services to focus on their core functionality while the BFFs handle client-specific requirements.</p></li></ol><h2><strong>Advantages of the BFF Pattern</strong></h2><p>Implementing the BFF pattern offers several advantages:</p><ol><li><p><strong>Resiliency</strong>: By having separate BFFs for different client types, the impact of a faulty deployment or issue in one BFF is isolated to that specific client. Other clients remain unaffected, improving overall system resiliency.</p></li><li><p><strong>Autonomy</strong>: Each BFF can be optimized according to the specific needs of the client it serves. For example, mobile clients may prefer larger responses to minimize network calls, while web clients may prioritize smaller payloads. BFFs provide the flexibility to cater to these varying requirements.</p></li><li><p><strong>Development Speed</strong>: The resiliency and autonomy provided by BFFs boost developer confidence and enable faster development velocity. Teams can work independently on different BFFs without the fear of impacting other clients.</p></li></ol><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!bSJv!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8d62579-3c9c-4d63-aa64-d9062aa6bd16_2107x1315.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!bSJv!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8d62579-3c9c-4d63-aa64-d9062aa6bd16_2107x1315.png 424w, https://substackcdn.com/image/fetch/$s_!bSJv!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8d62579-3c9c-4d63-aa64-d9062aa6bd16_2107x1315.png 848w, https://substackcdn.com/image/fetch/$s_!bSJv!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8d62579-3c9c-4d63-aa64-d9062aa6bd16_2107x1315.png 1272w, https://substackcdn.com/image/fetch/$s_!bSJv!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8d62579-3c9c-4d63-aa64-d9062aa6bd16_2107x1315.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!bSJv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8d62579-3c9c-4d63-aa64-d9062aa6bd16_2107x1315.png" width="1456" height="909" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e8d62579-3c9c-4d63-aa64-d9062aa6bd16_2107x1315.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:909,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:193193,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!bSJv!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8d62579-3c9c-4d63-aa64-d9062aa6bd16_2107x1315.png 424w, https://substackcdn.com/image/fetch/$s_!bSJv!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8d62579-3c9c-4d63-aa64-d9062aa6bd16_2107x1315.png 848w, https://substackcdn.com/image/fetch/$s_!bSJv!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8d62579-3c9c-4d63-aa64-d9062aa6bd16_2107x1315.png 1272w, https://substackcdn.com/image/fetch/$s_!bSJv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8d62579-3c9c-4d63-aa64-d9062aa6bd16_2107x1315.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/5SU8bM1gDCRzZFjh1tQi?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><h2><strong>Disadvantages of the BFF Pattern</strong></h2><p>While the BFF pattern offers benefits, it also has some drawbacks to consider:</p><ol><li><p><strong>Code Duplication</strong>: When multiple BFFs share common functionalities, such as authorization or business logic, there is a risk of code duplication across the BFFs. This can lead to maintenance challenges and inconsistencies.</p></li><li><p><strong>Complexity</strong>: As the BFFs become responsible for more glue-logic and orchestration of services, they can become more complex over time. Managing this complexity requires careful design and maintenance.</p></li><li><p><strong>Proliferation of BFFs</strong>: Developers may be tempted to create a new BFF for every slightly different scenario, leading to an excessive number of BFFs. This can result in increased complexity and maintenance overhead.</p></li></ol><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!1A8T!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb44fe621-06c9-4848-9f5e-8eabed64ac74_2107x1315.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!1A8T!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb44fe621-06c9-4848-9f5e-8eabed64ac74_2107x1315.png 424w, https://substackcdn.com/image/fetch/$s_!1A8T!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb44fe621-06c9-4848-9f5e-8eabed64ac74_2107x1315.png 848w, https://substackcdn.com/image/fetch/$s_!1A8T!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb44fe621-06c9-4848-9f5e-8eabed64ac74_2107x1315.png 1272w, https://substackcdn.com/image/fetch/$s_!1A8T!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb44fe621-06c9-4848-9f5e-8eabed64ac74_2107x1315.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!1A8T!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb44fe621-06c9-4848-9f5e-8eabed64ac74_2107x1315.png" width="1456" height="909" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b44fe621-06c9-4848-9f5e-8eabed64ac74_2107x1315.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:909,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:182715,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!1A8T!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb44fe621-06c9-4848-9f5e-8eabed64ac74_2107x1315.png 424w, https://substackcdn.com/image/fetch/$s_!1A8T!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb44fe621-06c9-4848-9f5e-8eabed64ac74_2107x1315.png 848w, https://substackcdn.com/image/fetch/$s_!1A8T!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb44fe621-06c9-4848-9f5e-8eabed64ac74_2107x1315.png 1272w, https://substackcdn.com/image/fetch/$s_!1A8T!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb44fe621-06c9-4848-9f5e-8eabed64ac74_2107x1315.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/5SU8bM1gDCRzZFjh1tQi?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><h2><strong>Best Practices for Implementing BFFs</strong></h2><p>To effectively leverage the BFF pattern, consider the following best practices:</p><ol><li><p><strong>Clearly Define Client Requirements</strong>: Thoroughly understand the specific requirements of each client type and design the BFFs accordingly. Avoid creating unnecessary BFFs for minor variations.</p></li><li><p><strong>Minimize Code Duplication</strong>: Identify common functionalities across BFFs and consider extracting them into shared libraries or services to minimize code duplication.</p></li><li><p><strong>Maintain Clear Boundaries</strong>: Clearly define the responsibilities of each BFF and ensure they align with the overall system architecture. Avoid overloading BFFs with excessive functionality.</p></li><li><p><strong>Monitor and Optimize Performance</strong>: Regularly monitor the performance of BFFs and optimize them based on client requirements and usage patterns. Ensure efficient resource utilization and scalability.</p></li></ol><p><strong>So - have you used the BFF pattern?</strong></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/what-is-the-bff-pattern/comments&quot;,&quot;text&quot;:&quot;Leave a comment&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/what-is-the-bff-pattern/comments"><span>Leave a comment</span></a></p><div><hr></div><p><strong>That&#8217;s it for today! &#9728;&#65039;</strong></p><p>Enjoyed this issue of the newsletter?</p><p>Share with your friends and colleagues.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/what-is-the-bff-pattern?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/what-is-the-bff-pattern?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p><em><strong>See you later with another edition &#8212; Saurabh</strong></em></p>]]></content:encoded></item><item><title><![CDATA[How TCP Handshake Works]]></title><description><![CDATA[The 3 step process]]></description><link>https://newsletter.systemdesigncodex.com/p/how-tcp-handshake-works</link><guid isPermaLink="false">https://newsletter.systemdesigncodex.com/p/how-tcp-handshake-works</guid><dc:creator><![CDATA[Saurabh Dashora]]></dc:creator><pubDate>Tue, 31 Mar 2026 08:17:52 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!1nC8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d8fe891-e992-42b7-a735-6ee2aeb7902b_2107x1318.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>A handshake that made the Internet possible.</p><p>I&#8217;m talking about the TCP 3-way handshake.</p><p>Every time you open a website, TCP makes sure this handshake happens and you get a reliable connection.</p><p>How does TCP pull it off?</p><p>Let&#8217;s look at each step:</p><h2><strong>1 - SYN (Synchronize)</strong></h2><ul><li><p>Think of it as one party extending their hand for a handshake.</p></li><li><p>The process starts with the client sending a TCP segment to the server with the SYN flag set.</p></li><li><p>Also, the client selects an initial sequence number (ISN) and includes it in the SYN segment. Let&#8217;s say the ISN is 1000.</p></li><li><p>This tells the server that the client wants to establish a connection.</p></li></ul><h2><strong>2 - SYN-ACK (Synchronize Acknowledge)</strong></h2><ul><li><p>This is like the second party taking the hand.</p></li><li><p>The server receives the SYN segment and responds by sending a SYN-ACK segment to the client.</p></li><li><p>Before sending, the server sets the SYN flag and the ACK flag in the segment</p></li><li><p>The ACK flag is meant to acknowledge the receipt of the client&#8217;s SYN segment by incrementing the ISN by 1 (i.e. 1001)</p></li><li><p>The server also selects its own ISN (let&#8217;s say 5000) and includes it in the SYN-ACK segment.</p></li></ul><h2><strong>3 - ACK (Acknowledge)</strong></h2><ul><li><p>This is where the two parties shake hands.</p></li><li><p>The client receives the SYN-ACK segment.</p></li><li><p>The client acknowledges the server&#8217;s response by sending another TCP segment with the ACK flag set.</p></li><li><p>The sequence number in the segment is set to the server&#8217;s ISN incremented by 1 (basically, 5001)</p></li></ul><p>After this, the connection is established.</p><p>The diagram below shows all the three steps:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!1nC8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d8fe891-e992-42b7-a735-6ee2aeb7902b_2107x1318.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!1nC8!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d8fe891-e992-42b7-a735-6ee2aeb7902b_2107x1318.png 424w, https://substackcdn.com/image/fetch/$s_!1nC8!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d8fe891-e992-42b7-a735-6ee2aeb7902b_2107x1318.png 848w, https://substackcdn.com/image/fetch/$s_!1nC8!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d8fe891-e992-42b7-a735-6ee2aeb7902b_2107x1318.png 1272w, https://substackcdn.com/image/fetch/$s_!1nC8!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d8fe891-e992-42b7-a735-6ee2aeb7902b_2107x1318.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!1nC8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d8fe891-e992-42b7-a735-6ee2aeb7902b_2107x1318.png" width="1456" height="911" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6d8fe891-e992-42b7-a735-6ee2aeb7902b_2107x1318.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:911,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:327144,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!1nC8!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d8fe891-e992-42b7-a735-6ee2aeb7902b_2107x1318.png 424w, https://substackcdn.com/image/fetch/$s_!1nC8!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d8fe891-e992-42b7-a735-6ee2aeb7902b_2107x1318.png 848w, https://substackcdn.com/image/fetch/$s_!1nC8!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d8fe891-e992-42b7-a735-6ee2aeb7902b_2107x1318.png 1272w, https://substackcdn.com/image/fetch/$s_!1nC8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d8fe891-e992-42b7-a735-6ee2aeb7902b_2107x1318.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/bmszSLu1meFO84FykuYU?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><h2><strong>FAQs</strong></h2><p>A few additional FAQs about the entire TCP handshake business:</p><blockquote><p><strong>What&#8217;s the deal with SYN and ACK? What are these exactly?</strong></p></blockquote><p>In TCP, several control flags are used to manage different aspects of the communication process. These flags are bits in the TCP header.</p><p>Some common ones are SYN, ACK, FIN, RST, PSH, and so on.</p><blockquote><p><strong>Why sequence numbers (ISNs) are so important?</strong></p></blockquote><p>The numbers help the client and server keep track of the message order so that nothing gets missed.</p><p>Also, these numbers are randomized and help prevent malicious actors from hijacking the TCP session.</p><blockquote><p><strong>Is the Internet moving away from TCP?</strong></p></blockquote><p>HTTP/3 doesn&#8217;t use TCP but relies on QUIC (Quick UDP Internet Connections). So yes, we may see a gradual move away from TCP.</p><p>However, the majority of websites are still on HTTP/1.1 and HTTP/2. So nothing is going to happen tomorrow.</p><p><strong>So - what do you think about the TCP 3-way handshake?</strong></p><p><strong>Is it an overkill? Or a great mechanism for establishing connections?</strong></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/how-tcp-handshake-works/comments&quot;,&quot;text&quot;:&quot;Leave a comment&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/how-tcp-handshake-works/comments"><span>Leave a comment</span></a></p><div><hr></div><p><strong>That&#8217;s it for today! &#9728;&#65039;</strong></p><p>Enjoyed this issue of the newsletter?</p><p>Share with your friends and colleagues.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/how-tcp-handshake-works?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/how-tcp-handshake-works?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p><em><strong>See you later with another edition &#8212; Saurabh</strong></em></p>]]></content:encoded></item><item><title><![CDATA[Object Oriented Programming - The Key Terms]]></title><description><![CDATA[The essential concepts]]></description><link>https://newsletter.systemdesigncodex.com/p/object-oriented-programming-the-key</link><guid isPermaLink="false">https://newsletter.systemdesigncodex.com/p/object-oriented-programming-the-key</guid><dc:creator><![CDATA[Saurabh Dashora]]></dc:creator><pubDate>Tue, 24 Mar 2026 08:38:43 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!jVVE!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0c01cb23-17b3-49c5-9613-ddb139ee9e77_1929x1319.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Object-Oriented Programming (OOP) is one of the most widely used programming paradigms, shaping how modern applications are designed and built.</p><p>At its core, OOP is based on four fundamental principles: <strong>Abstraction, Encapsulation, Inheritance, </strong>and<strong> Polymorphism</strong>.</p><p>Let&#8217;s break down each concept with explanations, examples, and best practices.</p><h2><strong>1 - Abstraction</strong></h2><p>Abstraction is the process of hiding complex implementation details while exposing only the essential features of an object. It allows developers to work with high-level concepts without worrying about the underlying implementation.</p><h3><strong>How It Works</strong></h3><p>Imagine a <code>Car</code> class with a method called <code>stop()</code>. Users of this class don&#8217;t need to know how the car stops&#8212;they just need to call <code>stop()</code>, and the underlying implementation takes care of the details.</p><pre><code><code>abstract class Car {
    abstract void stop();  // Abstract method, no implementation
}

class Honda extends Car {
    @Override
    void stop() {
        System.out.println("Honda slowing down and stopping.");
    }
}

class Tesla extends Car {
    @Override
    void stop() {
        System.out.println("Tesla applies brakes and stops.");
    }
}</code></code></pre><p>Here, <code>Car</code> defines the <code>stop()</code> method but doesn&#8217;t provide an implementation. Honda and Tesla provide their specific implementations, hiding the details from the users of these classes.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!jVVE!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0c01cb23-17b3-49c5-9613-ddb139ee9e77_1929x1319.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!jVVE!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0c01cb23-17b3-49c5-9613-ddb139ee9e77_1929x1319.png 424w, https://substackcdn.com/image/fetch/$s_!jVVE!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0c01cb23-17b3-49c5-9613-ddb139ee9e77_1929x1319.png 848w, https://substackcdn.com/image/fetch/$s_!jVVE!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0c01cb23-17b3-49c5-9613-ddb139ee9e77_1929x1319.png 1272w, https://substackcdn.com/image/fetch/$s_!jVVE!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0c01cb23-17b3-49c5-9613-ddb139ee9e77_1929x1319.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!jVVE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0c01cb23-17b3-49c5-9613-ddb139ee9e77_1929x1319.png" width="1456" height="996" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0c01cb23-17b3-49c5-9613-ddb139ee9e77_1929x1319.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:996,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:150886,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesigncodex.com/i/157778380?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0c01cb23-17b3-49c5-9613-ddb139ee9e77_1929x1319.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!jVVE!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0c01cb23-17b3-49c5-9613-ddb139ee9e77_1929x1319.png 424w, https://substackcdn.com/image/fetch/$s_!jVVE!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0c01cb23-17b3-49c5-9613-ddb139ee9e77_1929x1319.png 848w, https://substackcdn.com/image/fetch/$s_!jVVE!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0c01cb23-17b3-49c5-9613-ddb139ee9e77_1929x1319.png 1272w, https://substackcdn.com/image/fetch/$s_!jVVE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0c01cb23-17b3-49c5-9613-ddb139ee9e77_1929x1319.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/5DyBUTNWjQGxhgKJppGF?origin=share">You can check the diagram on Eraser.io</a></figcaption></figure></div><h3><strong>Why Abstraction Matters</strong></h3><ul><li><p>Simplifies complex systems by exposing only necessary parts.</p></li><li><p>Improves code maintainability by separating the interface from implementation.</p></li><li><p>Enhances security by hiding implementation logic from unauthorized access.</p></li></ul><h2><strong>2 - Encapsulation</strong></h2><p>Encapsulation is the concept of bundling data (fields) and methods that operate on the data into a single unit (class) while restricting direct access to the data.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!-Jca!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd855d979-d021-4412-93a6-6fc5f60b830a_1929x1319.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!-Jca!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd855d979-d021-4412-93a6-6fc5f60b830a_1929x1319.png 424w, https://substackcdn.com/image/fetch/$s_!-Jca!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd855d979-d021-4412-93a6-6fc5f60b830a_1929x1319.png 848w, https://substackcdn.com/image/fetch/$s_!-Jca!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd855d979-d021-4412-93a6-6fc5f60b830a_1929x1319.png 1272w, https://substackcdn.com/image/fetch/$s_!-Jca!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd855d979-d021-4412-93a6-6fc5f60b830a_1929x1319.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!-Jca!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd855d979-d021-4412-93a6-6fc5f60b830a_1929x1319.png" width="1456" height="996" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d855d979-d021-4412-93a6-6fc5f60b830a_1929x1319.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:996,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:147791,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesigncodex.com/i/157778380?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd855d979-d021-4412-93a6-6fc5f60b830a_1929x1319.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!-Jca!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd855d979-d021-4412-93a6-6fc5f60b830a_1929x1319.png 424w, https://substackcdn.com/image/fetch/$s_!-Jca!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd855d979-d021-4412-93a6-6fc5f60b830a_1929x1319.png 848w, https://substackcdn.com/image/fetch/$s_!-Jca!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd855d979-d021-4412-93a6-6fc5f60b830a_1929x1319.png 1272w, https://substackcdn.com/image/fetch/$s_!-Jca!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd855d979-d021-4412-93a6-6fc5f60b830a_1929x1319.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/5DyBUTNWjQGxhgKJppGF?origin=share">You can check the diagram on Eraser.io</a></figcaption></figure></div><h3><strong>How It Works</strong></h3><p>Encapsulation is achieved using access modifiers (<code>private</code>, <code>protected</code>, <code>public</code>) to control access to variables and methods.</p><pre><code><code>class BankAccount {
    private double balance;  // Private variable, cannot be accessed directly

    public BankAccount(double initialBalance) {
        this.balance = initialBalance;
    }

    public void deposit(double amount) {
        if (amount &gt; 0) {
            balance += amount;
        }
    }

    public double getBalance() {
        return balance;  // Provides controlled access to balance
    }
}</code></code></pre><p>Here <code>balance</code> is private, so it cannot be accessed directly from outside. Also, <code>getBalance()</code> is public, allowing controlled access to the balance.</p><h3><strong>Why Encapsulation Matters</strong></h3><ul><li><p>Protects data integrity by preventing unauthorized modifications.</p></li><li><p>Reduces dependencies by keeping data and its operations in one place.</p></li><li><p>Enhances flexibility as changes to implementation don&#8217;t affect external code.</p></li></ul><h2><strong>3 - Inheritance</strong></h2><p>Inheritance allows a class (child) to inherit attributes and methods from another class (parent). This promotes code reuse and hierarchical relationships between classes.</p><h3><strong>How It Works</strong></h3><p>Consider a <code>Vehicle</code> class. Instead of rewriting common functionality for each type of vehicle, a <code>Car</code> and <code>Bike</code> can inherit from <code>Vehicle</code>.</p><pre><code><code>class Car {
    String brand = "Generic Brand";

    void honk() {
        System.out.println("Beep! Beep!");
    }
}

class Car extends Vehicle {
    int doors = 4;
}

public class Main {
    public static void main(String[] args) {
        Car myCar = new Car();
        System.out.println(myCar.brand);  // Inherited from Vehicle
        myCar.honk();  // Inherited method
        System.out.println("Number of doors: " + myCar.doors);
    }
}</code></code></pre><p>Here, <code>Car</code> <strong>inherits</strong> <code>brand</code> and <code>honk()</code> from <code>Vehicle</code>, <strong>reusing existing logic</strong>.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!OGeI!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab0b984e-56e8-4530-b062-9ab5e030fef4_1929x1319.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!OGeI!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab0b984e-56e8-4530-b062-9ab5e030fef4_1929x1319.png 424w, https://substackcdn.com/image/fetch/$s_!OGeI!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab0b984e-56e8-4530-b062-9ab5e030fef4_1929x1319.png 848w, https://substackcdn.com/image/fetch/$s_!OGeI!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab0b984e-56e8-4530-b062-9ab5e030fef4_1929x1319.png 1272w, https://substackcdn.com/image/fetch/$s_!OGeI!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab0b984e-56e8-4530-b062-9ab5e030fef4_1929x1319.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!OGeI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab0b984e-56e8-4530-b062-9ab5e030fef4_1929x1319.png" width="1456" height="996" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ab0b984e-56e8-4530-b062-9ab5e030fef4_1929x1319.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:996,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:144849,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesigncodex.com/i/157778380?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab0b984e-56e8-4530-b062-9ab5e030fef4_1929x1319.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!OGeI!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab0b984e-56e8-4530-b062-9ab5e030fef4_1929x1319.png 424w, https://substackcdn.com/image/fetch/$s_!OGeI!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab0b984e-56e8-4530-b062-9ab5e030fef4_1929x1319.png 848w, https://substackcdn.com/image/fetch/$s_!OGeI!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab0b984e-56e8-4530-b062-9ab5e030fef4_1929x1319.png 1272w, https://substackcdn.com/image/fetch/$s_!OGeI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab0b984e-56e8-4530-b062-9ab5e030fef4_1929x1319.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/5DyBUTNWjQGxhgKJppGF?origin=share">You can check the diagram on Eraser.io</a></figcaption></figure></div><h3><strong>Why Inheritance Matters</strong></h3><ul><li><p>Reduces code duplication, making maintenance easier.</p></li><li><p>Creates hierarchical relationships (e.g., <code>Animal &#8594; Mammal &#8594; Dog</code>).</p></li><li><p>Improves extensibility, allowing new behaviors to be added to child classes.</p></li></ul><h2><strong>4 - Polymorphism</strong></h2><p>Polymorphism allows a single method to behave differently based on the object it is called on. This means one function can be applied to multiple object types.</p><p>There are two types of polymorphism:</p><ol><li><p><strong>Compile-time</strong></p></li><li><p><strong>Run-time</strong></p></li></ol><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!IjUh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5baf36ec-ed40-4543-a479-4455a3cb52b1_1929x1319.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!IjUh!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5baf36ec-ed40-4543-a479-4455a3cb52b1_1929x1319.png 424w, https://substackcdn.com/image/fetch/$s_!IjUh!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5baf36ec-ed40-4543-a479-4455a3cb52b1_1929x1319.png 848w, https://substackcdn.com/image/fetch/$s_!IjUh!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5baf36ec-ed40-4543-a479-4455a3cb52b1_1929x1319.png 1272w, https://substackcdn.com/image/fetch/$s_!IjUh!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5baf36ec-ed40-4543-a479-4455a3cb52b1_1929x1319.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!IjUh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5baf36ec-ed40-4543-a479-4455a3cb52b1_1929x1319.png" width="1456" height="996" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5baf36ec-ed40-4543-a479-4455a3cb52b1_1929x1319.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:996,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:174964,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesigncodex.com/i/157778380?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5baf36ec-ed40-4543-a479-4455a3cb52b1_1929x1319.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!IjUh!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5baf36ec-ed40-4543-a479-4455a3cb52b1_1929x1319.png 424w, https://substackcdn.com/image/fetch/$s_!IjUh!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5baf36ec-ed40-4543-a479-4455a3cb52b1_1929x1319.png 848w, https://substackcdn.com/image/fetch/$s_!IjUh!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5baf36ec-ed40-4543-a479-4455a3cb52b1_1929x1319.png 1272w, https://substackcdn.com/image/fetch/$s_!IjUh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5baf36ec-ed40-4543-a479-4455a3cb52b1_1929x1319.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/5DyBUTNWjQGxhgKJppGF?origin=share">You can check the diagram on Eraser.io</a></figcaption></figure></div><h3><strong>How It Works</strong></h3><p>Here&#8217;s an example of polymorphism:</p><pre><code><code>class MathOperations {
    int add(int a, int b) {
        return a + b;
    }

    double add(double a, double b) {
        return a + b;
    }
}

public class Main {
    public static void main(String[] args) {
        MathOperations math = new MathOperations();
        System.out.println(math.add(5, 10));  // Calls int version
        System.out.println(math.add(5.5, 2.2));  // Calls double version
    }
}</code></code></pre><p>Here, the <code>add()</code> method behaves differently based on the parameter type.</p><h3><strong>Why Polymorphism Matters</strong></h3><ul><li><p>Enhances flexibility by allowing objects of different types to be treated uniformly.</p></li><li><p>Encourages code extensibility without modifying existing code.</p></li><li><p>Supports the Open-Closed Principle (OCP)&#8212;extend behavior without modifying existing logic.</p></li></ul><p><strong>So - have you used object-oriented programming? And are there any other concepts you find important?</strong></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/object-oriented-programming-the-key/comments&quot;,&quot;text&quot;:&quot;Leave a comment&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/object-oriented-programming-the-key/comments"><span>Leave a comment</span></a></p><div><hr></div><p><strong>That&#8217;s it for today! &#9728;&#65039;</strong></p><p>Enjoyed this issue of the newsletter?</p><p>Share with your friends and colleagues.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/object-oriented-programming-the-key?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/object-oriented-programming-the-key?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p></p>]]></content:encoded></item><item><title><![CDATA[Inside Look at Reddit's Metadata Store]]></title><description><![CDATA[How it works]]></description><link>https://newsletter.systemdesigncodex.com/p/inside-look-at-reddits-metadata-store</link><guid isPermaLink="false">https://newsletter.systemdesigncodex.com/p/inside-look-at-reddits-metadata-store</guid><dc:creator><![CDATA[Saurabh Dashora]]></dc:creator><pubDate>Tue, 17 Mar 2026 08:41:58 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!x-_u!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3d2973c-35eb-4c16-855e-53ecb1d7ec11_2130x1264.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Reddit is like the front page of the Internet.</p><p>It hosts billions of posts. And a lot many of these posts contain media content such as images, videos, gifs, and so on.</p><p>While the media content is often stored in object storage, the metadata needs to be stored elsewhere. For example, if you&#8217;ve got a video, you might need to store information such as the thumbnail URL, playback URLs, bitrates, and various resolutions.</p><p>Reddit had a big problem with this metadata.</p><p>While their systems had the information, it was scattered across multiple systems. Media data used for traditional image and video posts was stored with post data, whereas media data related to chats and other types of posts was stored in a different database.</p><p>This made it difficult for them to analyze and categorize the metadata. Auditing changes became tough. Even checking information about a specific image or video required them to query the S3 bucket.</p><p>To solve these challenges, the Reddit Engineering team decided to build a media metadata store.</p><h1><strong>Requirements of the Metadata Store</strong></h1><p>There were several requirements for the new metadata store:</p><ul><li><p>Move all existing media metadata from different systems into a unified storage. In other words, migrate existing data to the new database.</p></li><li><p>Support data retrieval to the tune of over 100K read requests per second with very low latency (less than 50 ms).</p></li><li><p>Support media creation and updates.</p></li></ul><p>After evaluating multiple choices, the Reddit Engineering Team went for AWS Aurora Postgres.</p><p>The diagram below shows a high-level architecture of their media metadata storage system.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Y_8m!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F10aa87cf-553f-4348-81c0-d08996eb5db0_1764x1070.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Y_8m!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F10aa87cf-553f-4348-81c0-d08996eb5db0_1764x1070.png 424w, https://substackcdn.com/image/fetch/$s_!Y_8m!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F10aa87cf-553f-4348-81c0-d08996eb5db0_1764x1070.png 848w, https://substackcdn.com/image/fetch/$s_!Y_8m!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F10aa87cf-553f-4348-81c0-d08996eb5db0_1764x1070.png 1272w, https://substackcdn.com/image/fetch/$s_!Y_8m!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F10aa87cf-553f-4348-81c0-d08996eb5db0_1764x1070.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Y_8m!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F10aa87cf-553f-4348-81c0-d08996eb5db0_1764x1070.png" width="1456" height="883" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/10aa87cf-553f-4348-81c0-d08996eb5db0_1764x1070.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:883,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:164832,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!Y_8m!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F10aa87cf-553f-4348-81c0-d08996eb5db0_1764x1070.png 424w, https://substackcdn.com/image/fetch/$s_!Y_8m!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F10aa87cf-553f-4348-81c0-d08996eb5db0_1764x1070.png 848w, https://substackcdn.com/image/fetch/$s_!Y_8m!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F10aa87cf-553f-4348-81c0-d08996eb5db0_1764x1070.png 1272w, https://substackcdn.com/image/fetch/$s_!Y_8m!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F10aa87cf-553f-4348-81c0-d08996eb5db0_1764x1070.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/faUxGiTi8HuBqi4JqN9X?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><p>The API service interfaces with the database to handle both reads and writes. To manage the connection pooling, they use pgBouncer as the proxy for connecting to Postgres.</p><p>Just so you know, pgBouncer is a lightweight connection pooler for Postgres.</p><h1><strong>Data Migration Process</strong></h1><p>While setting up a new Postgres database is easy, the real challenge lies in migrating terabytes of data from one database to another while serving 100K requests per second.</p><p>It&#8217;s like changing a car&#8217;s tires while you are driving it.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!3Ffb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe52574c7-baa4-44d1-9dc7-8699923d95e5_600x398.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!3Ffb!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe52574c7-baa4-44d1-9dc7-8699923d95e5_600x398.jpeg 424w, https://substackcdn.com/image/fetch/$s_!3Ffb!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe52574c7-baa4-44d1-9dc7-8699923d95e5_600x398.jpeg 848w, https://substackcdn.com/image/fetch/$s_!3Ffb!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe52574c7-baa4-44d1-9dc7-8699923d95e5_600x398.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!3Ffb!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe52574c7-baa4-44d1-9dc7-8699923d95e5_600x398.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!3Ffb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe52574c7-baa4-44d1-9dc7-8699923d95e5_600x398.jpeg" width="600" height="398" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e52574c7-baa4-44d1-9dc7-8699923d95e5_600x398.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:398,&quot;width&quot;:600,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Changing A Tire While Still Driving - Life Palette&quot;,&quot;title&quot;:&quot;Changing A Tire While Still Driving - Life Palette&quot;,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Changing A Tire While Still Driving - Life Palette" title="Changing A Tire While Still Driving - Life Palette" srcset="https://substackcdn.com/image/fetch/$s_!3Ffb!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe52574c7-baa4-44d1-9dc7-8699923d95e5_600x398.jpeg 424w, https://substackcdn.com/image/fetch/$s_!3Ffb!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe52574c7-baa4-44d1-9dc7-8699923d95e5_600x398.jpeg 848w, https://substackcdn.com/image/fetch/$s_!3Ffb!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe52574c7-baa4-44d1-9dc7-8699923d95e5_600x398.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!3Ffb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe52574c7-baa4-44d1-9dc7-8699923d95e5_600x398.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The consequences of the new database having the wrong media metadata could spell disaster for the website.</p><p>The migration was handled as follows:</p><ul><li><p>Enable dual writes into both the new and old databases from the clients of media metadata. This ensures that any new metadata is stored in the new database.</p></li><li><p>Backfill data from older databases to the metadata store.</p></li><li><p>Next, enable dual reads on media metadata from our service clients.</p></li><li><p>Compare the output of the reads and fix any data gaps.</p></li><li><p>Ramp up read traffic to the new database.</p></li></ul><p>Here&#8217;s what the dual writes and backfill part looks like.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ykbW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0b98bf0f-68dd-4094-a3eb-d9a15b65c2d1_1469x909.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ykbW!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0b98bf0f-68dd-4094-a3eb-d9a15b65c2d1_1469x909.png 424w, https://substackcdn.com/image/fetch/$s_!ykbW!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0b98bf0f-68dd-4094-a3eb-d9a15b65c2d1_1469x909.png 848w, https://substackcdn.com/image/fetch/$s_!ykbW!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0b98bf0f-68dd-4094-a3eb-d9a15b65c2d1_1469x909.png 1272w, https://substackcdn.com/image/fetch/$s_!ykbW!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0b98bf0f-68dd-4094-a3eb-d9a15b65c2d1_1469x909.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ykbW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0b98bf0f-68dd-4094-a3eb-d9a15b65c2d1_1469x909.png" width="1456" height="901" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0b98bf0f-68dd-4094-a3eb-d9a15b65c2d1_1469x909.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:901,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:104046,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!ykbW!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0b98bf0f-68dd-4094-a3eb-d9a15b65c2d1_1469x909.png 424w, https://substackcdn.com/image/fetch/$s_!ykbW!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0b98bf0f-68dd-4094-a3eb-d9a15b65c2d1_1469x909.png 848w, https://substackcdn.com/image/fetch/$s_!ykbW!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0b98bf0f-68dd-4094-a3eb-d9a15b65c2d1_1469x909.png 1272w, https://substackcdn.com/image/fetch/$s_!ykbW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0b98bf0f-68dd-4094-a3eb-d9a15b65c2d1_1469x909.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/faUxGiTi8HuBqi4JqN9X?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><h1><strong>Dealing with Issues</strong></h1><p>While the overall approach is fine from a happy path perspective, that&#8217;s not always the case in real software development.</p><p>Some issues that could come up are as follows:</p><ul><li><p>Data transformation bugs in the service layer.</p></li><li><p>Writes to the new metadata store could fail and the writes to the source database succeed resulting in inconsistent data.</p></li><li><p>The backfill process during migration can overwrite newer data from the service write.</p></li></ul><p>To handle these scenarios, the Reddit team built a more robust solution as shown below:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!x-_u!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3d2973c-35eb-4c16-855e-53ecb1d7ec11_2130x1264.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!x-_u!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3d2973c-35eb-4c16-855e-53ecb1d7ec11_2130x1264.png 424w, https://substackcdn.com/image/fetch/$s_!x-_u!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3d2973c-35eb-4c16-855e-53ecb1d7ec11_2130x1264.png 848w, https://substackcdn.com/image/fetch/$s_!x-_u!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3d2973c-35eb-4c16-855e-53ecb1d7ec11_2130x1264.png 1272w, https://substackcdn.com/image/fetch/$s_!x-_u!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3d2973c-35eb-4c16-855e-53ecb1d7ec11_2130x1264.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!x-_u!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3d2973c-35eb-4c16-855e-53ecb1d7ec11_2130x1264.png" width="1456" height="864" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d3d2973c-35eb-4c16-855e-53ecb1d7ec11_2130x1264.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:864,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:236203,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!x-_u!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3d2973c-35eb-4c16-855e-53ecb1d7ec11_2130x1264.png 424w, https://substackcdn.com/image/fetch/$s_!x-_u!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3d2973c-35eb-4c16-855e-53ecb1d7ec11_2130x1264.png 848w, https://substackcdn.com/image/fetch/$s_!x-_u!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3d2973c-35eb-4c16-855e-53ecb1d7ec11_2130x1264.png 1272w, https://substackcdn.com/image/fetch/$s_!x-_u!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3d2973c-35eb-4c16-855e-53ecb1d7ec11_2130x1264.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/faUxGiTi8HuBqi4JqN9X?origin=share">You can play around with the diagram in Eraser.io</a></figcaption></figure></div><p>Here is what&#8217;s going on:</p><ul><li><p>The client dual writes to the new database and the old database.</p></li><li><p>A Kafka consumer listens to the stream of data change events from the source database. This is done using a Change Data Capture (CDC) process.</p></li><li><p>The consumer performs data validation with the media metadata store to check inconsistencies.</p></li><li><p>In case of any inconsistency, the consumer reports the differences to another database so that engineers can take a look and fix the issues.</p></li></ul><h1><strong>What about Scaling?</strong></h1><p>The new media metadata store was heavily optimized for reads, helping Reddit achieve a <em>p50 latency of 2.6 ms</em> and <em>p99 latency of 17 ms</em> at 100K requests per second.</p><p>However, the data volume is also quite high and according to their estimates, the media metadata can reach 50 TB by 2030.</p><p>To handle this scalability challenge, Reddit has implemented partitioning in Postgres using an extension known as <code>pg_partman</code>.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!-Xpr!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faec6e34a-9c09-45aa-a472-9ca78584d59f_1130x350.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!-Xpr!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faec6e34a-9c09-45aa-a472-9ca78584d59f_1130x350.png 424w, https://substackcdn.com/image/fetch/$s_!-Xpr!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faec6e34a-9c09-45aa-a472-9ca78584d59f_1130x350.png 848w, https://substackcdn.com/image/fetch/$s_!-Xpr!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faec6e34a-9c09-45aa-a472-9ca78584d59f_1130x350.png 1272w, https://substackcdn.com/image/fetch/$s_!-Xpr!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faec6e34a-9c09-45aa-a472-9ca78584d59f_1130x350.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!-Xpr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faec6e34a-9c09-45aa-a472-9ca78584d59f_1130x350.png" width="1130" height="350" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/aec6e34a-9c09-45aa-a472-9ca78584d59f_1130x350.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:350,&quot;width&quot;:1130,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:77166,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!-Xpr!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faec6e34a-9c09-45aa-a472-9ca78584d59f_1130x350.png 424w, https://substackcdn.com/image/fetch/$s_!-Xpr!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faec6e34a-9c09-45aa-a472-9ca78584d59f_1130x350.png 848w, https://substackcdn.com/image/fetch/$s_!-Xpr!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faec6e34a-9c09-45aa-a472-9ca78584d59f_1130x350.png 1272w, https://substackcdn.com/image/fetch/$s_!-Xpr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faec6e34a-9c09-45aa-a472-9ca78584d59f_1130x350.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://www.reddit.com/r/RedditEng/comments/1avlywv/the_reddit_media_metadata_store/">Source: Reddit Engineering Blog</a></figcaption></figure></div><p>The above SQL statement is scheduled using the <code>pg_cron</code> scheduler to create new partitions when the number of spare partitions goes below a certain number.</p><p>They used range-based partitioning instead of hash-based partitioning for the partition key <code>post_id</code>.</p><p>This is because range-based partitioning on a monotonically increasing field such as <code>post_id</code> automatically ensures the partitions are created based on distinct time periods.</p><p>Since most read requests at Reddit target recent posts, it allows the Postgres engine to cache the indexes of the most recent partitions in its buffer pool. In other words, less Disk I/O and better performance.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!NFeW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc57e7817-fc8a-40fc-a51f-8c62b24ab22a_1844x1139.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!NFeW!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc57e7817-fc8a-40fc-a51f-8c62b24ab22a_1844x1139.png 424w, https://substackcdn.com/image/fetch/$s_!NFeW!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc57e7817-fc8a-40fc-a51f-8c62b24ab22a_1844x1139.png 848w, https://substackcdn.com/image/fetch/$s_!NFeW!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc57e7817-fc8a-40fc-a51f-8c62b24ab22a_1844x1139.png 1272w, https://substackcdn.com/image/fetch/$s_!NFeW!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc57e7817-fc8a-40fc-a51f-8c62b24ab22a_1844x1139.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!NFeW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc57e7817-fc8a-40fc-a51f-8c62b24ab22a_1844x1139.png" width="1456" height="899" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c57e7817-fc8a-40fc-a51f-8c62b24ab22a_1844x1139.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:899,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:105330,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!NFeW!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc57e7817-fc8a-40fc-a51f-8c62b24ab22a_1844x1139.png 424w, https://substackcdn.com/image/fetch/$s_!NFeW!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc57e7817-fc8a-40fc-a51f-8c62b24ab22a_1844x1139.png 848w, https://substackcdn.com/image/fetch/$s_!NFeW!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc57e7817-fc8a-40fc-a51f-8c62b24ab22a_1844x1139.png 1272w, https://substackcdn.com/image/fetch/$s_!NFeW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc57e7817-fc8a-40fc-a51f-8c62b24ab22a_1844x1139.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/faUxGiTi8HuBqi4JqN9X?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><p>So - what do you think about Reddit&#8217;s solution to the metadata problem?</p><p>Would you have done something differently?</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/inside-look-at-reddits-metadata-store/comments&quot;,&quot;text&quot;:&quot;Leave a comment&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/inside-look-at-reddits-metadata-store/comments"><span>Leave a comment</span></a></p><p><strong>References:</strong></p><ul><li><p><a href="https://www.reddit.com/r/RedditEng/comments/1avlywv/the_reddit_media_metadata_store/">The Reddit Media Metadata Store</a></p></li><li><p><a href="https://github.com/pgbouncer/pgbouncer">pgBouncer</a></p></li></ul><div><hr></div><p><strong>That&#8217;s it for today! &#9728;&#65039;</strong></p><p>Enjoyed this issue of the newsletter?</p><p>Share with your friends and colleagues.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/inside-look-at-reddits-metadata-store?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/inside-look-at-reddits-metadata-store?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p><em><strong>See you later with another edition &#8212; Saurabh</strong></em></p>]]></content:encoded></item><item><title><![CDATA[How Agoda Load Balanced Kafka]]></title><description><![CDATA[Deep Dive]]></description><link>https://newsletter.systemdesigncodex.com/p/how-agoda-load-balanced-kafka</link><guid isPermaLink="false">https://newsletter.systemdesigncodex.com/p/how-agoda-load-balanced-kafka</guid><dc:creator><![CDATA[Saurabh Dashora]]></dc:creator><pubDate>Tue, 10 Mar 2026 08:01:37 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!2f1n!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11c648fe-6f0b-4d3a-a406-1112f1c51393_2101x1315.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Agoda uses Kafka to transfer hundreds of terabytes of data across various supply systems every day. It&#8217;s an indispensable part of their tech stack.</p><p>As you might know, Agoda&#8217;s goal is to aggregate and provide the best prices from various external suppliers (hotels, restaurants, cab providers, etc). To ensure that customers always get the most up-to-date and accurate pricing information, Agoda&#8217;s supply system needs to process a massive amount of price updates from the suppliers in real time.</p><blockquote><p>For example, a single supplier can provide 1.5 million price updates and offer details in just one minute. Any delays or failures in reflecting these updates can lead to incorrect pricing and booking failures.</p></blockquote><p>Here&#8217;s how the typical Kafka application setup within Agoda&#8217;s supply system looks like:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!0lYF!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9760a841-f86f-4f54-bd32-083d5d323f8d_2101x1321.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!0lYF!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9760a841-f86f-4f54-bd32-083d5d323f8d_2101x1321.png 424w, https://substackcdn.com/image/fetch/$s_!0lYF!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9760a841-f86f-4f54-bd32-083d5d323f8d_2101x1321.png 848w, https://substackcdn.com/image/fetch/$s_!0lYF!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9760a841-f86f-4f54-bd32-083d5d323f8d_2101x1321.png 1272w, https://substackcdn.com/image/fetch/$s_!0lYF!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9760a841-f86f-4f54-bd32-083d5d323f8d_2101x1321.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!0lYF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9760a841-f86f-4f54-bd32-083d5d323f8d_2101x1321.png" width="1456" height="915" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9760a841-f86f-4f54-bd32-083d5d323f8d_2101x1321.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:915,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:198926,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!0lYF!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9760a841-f86f-4f54-bd32-083d5d323f8d_2101x1321.png 424w, https://substackcdn.com/image/fetch/$s_!0lYF!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9760a841-f86f-4f54-bd32-083d5d323f8d_2101x1321.png 848w, https://substackcdn.com/image/fetch/$s_!0lYF!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9760a841-f86f-4f54-bd32-083d5d323f8d_2101x1321.png 1272w, https://substackcdn.com/image/fetch/$s_!0lYF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9760a841-f86f-4f54-bd32-083d5d323f8d_2101x1321.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/arpZp4bcm33HPVRCSrAq?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><p>The key components are as follows:</p><ul><li><p><strong>Distributor: </strong>The component consumes price updates from various 3rd party systems (suppliers) and distributes processing jobs to the downstream processor service across multiple data centers.</p></li><li><p><strong>Processor:</strong> The processor service is responsible for transforming, processing, and delivering the updates to the downstream services and databases.</p></li><li><p><strong>Kafka:</strong> It acts as the messaging backbone between the distributor and processor components.</p></li></ul><p>One of the key features of Kafka that makes it suitable for such large-scale data processing is the use of partitions.</p><blockquote><blockquote><p>Partitions help Kafka achieve parallelism by distributing the workload across multiple partitions and consumers. In other words, it can process messages faster and more efficiently.</p></blockquote></blockquote><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!vUOg!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d8a3bfa-d33d-4052-a38d-cc8d6e03ce87_2101x1315.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!vUOg!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d8a3bfa-d33d-4052-a38d-cc8d6e03ce87_2101x1315.png 424w, https://substackcdn.com/image/fetch/$s_!vUOg!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d8a3bfa-d33d-4052-a38d-cc8d6e03ce87_2101x1315.png 848w, https://substackcdn.com/image/fetch/$s_!vUOg!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d8a3bfa-d33d-4052-a38d-cc8d6e03ce87_2101x1315.png 1272w, https://substackcdn.com/image/fetch/$s_!vUOg!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d8a3bfa-d33d-4052-a38d-cc8d6e03ce87_2101x1315.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!vUOg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d8a3bfa-d33d-4052-a38d-cc8d6e03ce87_2101x1315.png" width="1456" height="911" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7d8a3bfa-d33d-4052-a38d-cc8d6e03ce87_2101x1315.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:911,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:197666,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!vUOg!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d8a3bfa-d33d-4052-a38d-cc8d6e03ce87_2101x1315.png 424w, https://substackcdn.com/image/fetch/$s_!vUOg!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d8a3bfa-d33d-4052-a38d-cc8d6e03ce87_2101x1315.png 848w, https://substackcdn.com/image/fetch/$s_!vUOg!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d8a3bfa-d33d-4052-a38d-cc8d6e03ce87_2101x1315.png 1272w, https://substackcdn.com/image/fetch/$s_!vUOg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d8a3bfa-d33d-4052-a38d-cc8d6e03ce87_2101x1315.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/arpZp4bcm33HPVRCSrAq?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><p>However, Agoda&#8217;s online travel booking platform had some challenges that were made more apparent by Kafka&#8217;s parallelism.</p><h1><strong>Partitioner and Assignor Strategy</strong></h1><p>The partitioner and assignor strategies in Kafka play a crucial role in determining how messages (price updates from suppliers) are distributed across partitions and consumers.</p><ul><li><p><strong>Partitioner:</strong> Determines how messages are distributed across partitions when they are produced. For example, round-robin strategy and sticky partitioning.</p></li><li><p><strong>Assignor: </strong>Determines how partitions are assigned to consumers within a consumer group. For example, range assigner and round robin assigner.</p></li></ul><p>See the diagram below for a round-robin partitioner and round-robin assignor strategy:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!SYYu!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf4b0543-ec96-462c-b9c0-800630ccf40c_2101x1321.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!SYYu!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf4b0543-ec96-462c-b9c0-800630ccf40c_2101x1321.png 424w, https://substackcdn.com/image/fetch/$s_!SYYu!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf4b0543-ec96-462c-b9c0-800630ccf40c_2101x1321.png 848w, https://substackcdn.com/image/fetch/$s_!SYYu!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf4b0543-ec96-462c-b9c0-800630ccf40c_2101x1321.png 1272w, https://substackcdn.com/image/fetch/$s_!SYYu!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf4b0543-ec96-462c-b9c0-800630ccf40c_2101x1321.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!SYYu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf4b0543-ec96-462c-b9c0-800630ccf40c_2101x1321.png" width="1456" height="915" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/df4b0543-ec96-462c-b9c0-800630ccf40c_2101x1321.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:915,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:288064,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!SYYu!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf4b0543-ec96-462c-b9c0-800630ccf40c_2101x1321.png 424w, https://substackcdn.com/image/fetch/$s_!SYYu!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf4b0543-ec96-462c-b9c0-800630ccf40c_2101x1321.png 848w, https://substackcdn.com/image/fetch/$s_!SYYu!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf4b0543-ec96-462c-b9c0-800630ccf40c_2101x1321.png 1272w, https://substackcdn.com/image/fetch/$s_!SYYu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf4b0543-ec96-462c-b9c0-800630ccf40c_2101x1321.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/arpZp4bcm33HPVRCSrAq?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><p>Traditionally, these strategies were designed to work under the assumptions of homogenous consumer processing capabilities and uniform message workloads.</p><p>However, in Agoda&#8217;s case, these assumptions didn&#8217;t hold true leading to load-balancing challenges related to Kafka.</p><h2><strong>Challenges</strong></h2><p>The two main challenges are as follows:</p><ul><li><p><strong>Heterogenous Hardware: </strong>Agoda uses a private cloud with Kubernetes which can lead to pods running on servers of different hardware generations. Benchmarks show significant performance differences between hardware generations.</p></li><li><p><strong>Uneven Workload: </strong>Messages may require different processing steps, leading to varying processing times. For example, processing certain types of messages may require calling 3rd party APIs and executing database queries, resulting in latency fluctuations.</p></li></ul><p>These challenges led to the over-provisioning problem.</p><h1><strong>The Over-provisioning Problem At Agoda</strong></h1><p>Agoda initially used the Kafka round-robin partitioner and assigner to distribute the same number of messages to each partition and pod.</p><p>However, this led to over-provisioning.</p><blockquote><p><strong>Over-provisioning involves allocating more resources than necessary to handle the expected peak workload efficiently.</strong></p></blockquote><p>In Agoda&#8217;s case, the reason was an inefficient distribution of the load across their Kafka consumers.</p><p>For example, consider an example where Agoda deploys Kafka consumers on heterogeneous hardware in their processor service. Suppose they have:</p><ul><li><p>2 faster workers with a processing rate of 20 messages/second each.</p></li><li><p>1 slower worker with a processing rate of 10 messages/second.</p></li></ul><p>In this setup, the total expected capacity would be 20 + 20 + 10 = 50 messages/second.</p><p>However, with a round-robin distribution, each worker would receive 1/3 of the overall messages regardless of processing speed. If the incoming traffic consistently hits 50 messages/second, here&#8217;s what would happen:</p><ul><li><p>The 2 faster workers can easily handle their share of ~ 16.7 messages per second each.</p></li><li><p>The slower worker cannot keep up with its allocated ~16.7 messages per second, causing the lag to build up over time.</p></li></ul><p>The diagram below shows this scenario:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!2f1n!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11c648fe-6f0b-4d3a-a406-1112f1c51393_2101x1315.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!2f1n!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11c648fe-6f0b-4d3a-a406-1112f1c51393_2101x1315.png 424w, https://substackcdn.com/image/fetch/$s_!2f1n!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11c648fe-6f0b-4d3a-a406-1112f1c51393_2101x1315.png 848w, https://substackcdn.com/image/fetch/$s_!2f1n!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11c648fe-6f0b-4d3a-a406-1112f1c51393_2101x1315.png 1272w, https://substackcdn.com/image/fetch/$s_!2f1n!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11c648fe-6f0b-4d3a-a406-1112f1c51393_2101x1315.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!2f1n!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11c648fe-6f0b-4d3a-a406-1112f1c51393_2101x1315.png" width="1456" height="911" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/11c648fe-6f0b-4d3a-a406-1112f1c51393_2101x1315.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:911,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:301464,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!2f1n!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11c648fe-6f0b-4d3a-a406-1112f1c51393_2101x1315.png 424w, https://substackcdn.com/image/fetch/$s_!2f1n!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11c648fe-6f0b-4d3a-a406-1112f1c51393_2101x1315.png 848w, https://substackcdn.com/image/fetch/$s_!2f1n!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11c648fe-6f0b-4d3a-a406-1112f1c51393_2101x1315.png 1272w, https://substackcdn.com/image/fetch/$s_!2f1n!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11c648fe-6f0b-4d3a-a406-1112f1c51393_2101x1315.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/arpZp4bcm33HPVRCSrAq?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><p>To avoid high latency, Agoda would have to add extra resources to this setup to maintain processing SLAs. In this example, to process 50 messages/second, they would need to scale out to 5 machines. In other words, they end up over-provisioning by 2 extra machines due to the suboptimal distribution logic that doesn&#8217;t account for heterogeneous hardware.</p><p>Also, the same scenario can occur when the workload for each message is not identical. Either way, it results in:</p><ul><li><p>Increased hardware costs</p></li><li><p>Wasted resources as some consumers sit idle while others are overburdened</p></li><li><p>More maintenance overhead</p></li></ul><h1><strong>The Solution Agoda Didn&#8217;t Adopt</strong></h1><p>The first obvious solution to overcome the over-provisioning challenge was static balancing. There were mainly two approaches in this regard:</p><ul><li><p>Deployment on identical pods</p></li><li><p>Weighted load balancing</p></li></ul><h2><strong>Deployment on Identical Pods</strong></h2><p>This solution involves controlling the types of hardware used in service deployments. However, it had some drawbacks:</p><ul><li><p>Maintaining a homogeneous hardware environment can be expensive, especially in a private cloud setup.</p></li><li><p>Upgrading all existing hardware simultaneously can be challenging.</p></li></ul><p>Due to these reasons, it was not adopted.</p><h2><strong>Weighted Load Balancing</strong></h2><p>In this approach, varying weights are assigned to different consumers based on processing capacity. Consumers with higher weights are routed more traffic.</p><p>This solution works well when:</p><ul><li><p>The capacity of consumers is predictable and remains static.</p></li><li><p>The workload of messages is uniform, making it easier to estimate machine capacity.</p></li></ul><p>However, there were some challenges in implementing this in a real production environment at Agoda:</p><ul><li><p>Messages often had non-uniform workloads, making capacity estimation difficult.</p></li><li><p>Dependencies like network and 3rd party connections were unstable, leading to fluctuating capacities.</p></li><li><p>Frequent addition of new features required extra maintenance to keep the weights updated.</p></li></ul><h1><strong>Agoda&#8217;s Dynamic Lag-Aware Solution</strong></h1><p>Instead of the static rebalancing approaches, Agoda adopted a dynamic, lag-aware approach to solve the Kafka load balancing challenges. They implemented two main strategies:</p><ul><li><p>Lag-aware Producer</p></li><li><p>Lag-aware Consumer</p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!k1dh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72d1d4bc-6464-4b7d-9068-cc4e05706896_2101x1321.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!k1dh!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72d1d4bc-6464-4b7d-9068-cc4e05706896_2101x1321.png 424w, https://substackcdn.com/image/fetch/$s_!k1dh!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72d1d4bc-6464-4b7d-9068-cc4e05706896_2101x1321.png 848w, https://substackcdn.com/image/fetch/$s_!k1dh!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72d1d4bc-6464-4b7d-9068-cc4e05706896_2101x1321.png 1272w, https://substackcdn.com/image/fetch/$s_!k1dh!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72d1d4bc-6464-4b7d-9068-cc4e05706896_2101x1321.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!k1dh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72d1d4bc-6464-4b7d-9068-cc4e05706896_2101x1321.png" width="1456" height="915" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/72d1d4bc-6464-4b7d-9068-cc4e05706896_2101x1321.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:915,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:245337,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!k1dh!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72d1d4bc-6464-4b7d-9068-cc4e05706896_2101x1321.png 424w, https://substackcdn.com/image/fetch/$s_!k1dh!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72d1d4bc-6464-4b7d-9068-cc4e05706896_2101x1321.png 848w, https://substackcdn.com/image/fetch/$s_!k1dh!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72d1d4bc-6464-4b7d-9068-cc4e05706896_2101x1321.png 1272w, https://substackcdn.com/image/fetch/$s_!k1dh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72d1d4bc-6464-4b7d-9068-cc4e05706896_2101x1321.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/arpZp4bcm33HPVRCSrAq?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><h2><strong>Lag-aware Producer</strong></h2><p>A lag-aware producer dynamically adjusts the partitioning of messages based on the current lag information of the target topic. Here&#8217;s how it works:</p><ul><li><p>The producer maintains an internal cache of partition lags to reduce the number of calls to Kafka brokers.</p></li><li><p>Using the lag data, the producer applies a custom algorithm to publish fewer messages to partitions with high lag and more messages to partitions with low lag.</p></li><li><p>When lags are balanced and stable, this approach guarantees an even distribution of messages.</p></li></ul><p>For example, let&#8217;s consider a scenario where Agoda&#8217;s supply system has an internal producer that publishes task messages to its processor. The system has 6 partitions with the following lags:</p><ul><li><p>Partition 1 &#8594; 100 messages</p></li><li><p>Partition 2 &#8594; 120 messages</p></li><li><p>Partition 3 &#8594; 90 messages</p></li><li><p>Partition 4 &#8594; 300 messages</p></li><li><p>Partition 5 &#8594; 110 messages</p></li><li><p>Partition 6 &#8594; 280 messages</p></li></ul><p>In this case, the lag-aware producer would publish fewer messages to partitions 4 and 6 due to their high lag while publishing more messages to the other partitions with lower lag.</p><p>The diagram below illustrates this.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!XpZy!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb84e7cf9-d986-41c1-9acf-52630a2b9900_2101x1321.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!XpZy!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb84e7cf9-d986-41c1-9acf-52630a2b9900_2101x1321.png 424w, https://substackcdn.com/image/fetch/$s_!XpZy!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb84e7cf9-d986-41c1-9acf-52630a2b9900_2101x1321.png 848w, https://substackcdn.com/image/fetch/$s_!XpZy!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb84e7cf9-d986-41c1-9acf-52630a2b9900_2101x1321.png 1272w, https://substackcdn.com/image/fetch/$s_!XpZy!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb84e7cf9-d986-41c1-9acf-52630a2b9900_2101x1321.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!XpZy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb84e7cf9-d986-41c1-9acf-52630a2b9900_2101x1321.png" width="1456" height="915" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b84e7cf9-d986-41c1-9acf-52630a2b9900_2101x1321.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:915,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:214063,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!XpZy!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb84e7cf9-d986-41c1-9acf-52630a2b9900_2101x1321.png 424w, https://substackcdn.com/image/fetch/$s_!XpZy!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb84e7cf9-d986-41c1-9acf-52630a2b9900_2101x1321.png 848w, https://substackcdn.com/image/fetch/$s_!XpZy!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb84e7cf9-d986-41c1-9acf-52630a2b9900_2101x1321.png 1272w, https://substackcdn.com/image/fetch/$s_!XpZy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb84e7cf9-d986-41c1-9acf-52630a2b9900_2101x1321.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/arpZp4bcm33HPVRCSrAq?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><h2><strong>Lag-aware Consumer</strong></h2><p>Lag-aware consumers are used when multiple consumer groups subscribe to the same topic. Here&#8217;s how they work:</p><ul><li><p>In a downstream service like the Processor, a consumer instance experiencing high lag can proactively unsubscribe from the topic to trigger a rebalance.</p></li><li><p>During the rebalance, a customized Assigner redistributes the partitions across all consumer instances based on their current lag and processing capacity.</p></li><li><p>Kafka 2.4&#8217;s incremental cooperative rebalance protocol minimizes the performance impact of rebalancing, allowing for more frequent adjustments.</p></li></ul><p>For example, consider a scenario where Agoda&#8217;s Processor service has 3 consumer instances consuming from 6 partitions:</p><ul><li><p>Worker 1 &#8594; Partitions 1 and 2</p></li><li><p>Worker 2 &#8594; Partitions 3 and 4</p></li><li><p>Worker 3 &#8594; Partitions 5 and 6</p></li></ul><p>If Worker 3 is running on slower hardware, it may experience higher lags in partitions 5 and 6. In this case, Worker 3 can proactively unsubscribe from the topic, triggering a rebalance. The custom Assigner then redistributes the partitions based on the current lag and processing capacity of each worker.</p><h1><strong>Algorithms for Lag-aware Producer</strong></h1><p>Coming back to the Lag-aware producer, Agoda used two main algorithms:</p><ul><li><p>Same-Queue Length Algorithm</p></li><li><p>Outlier Detection Algorithm</p></li></ul><h2><strong>1 - Same-Queue Length Algorithm</strong></h2><p>The Same-Queue Length Algorithm aims to achieve equal queue lengths across all partitions by adjusting the number of messages published to each partition based on the current lag.</p><p>For example, consider a scenario with 4 partitions having the following lags:</p><ul><li><p>Partition 1 &#8594; 100 messages</p></li><li><p>Partition 2 &#8594; 150 messages</p></li><li><p>Partition 3 &#8594; 120 messages</p></li><li><p>Partition 4 &#8594; 200 messages</p></li></ul><p>The target queue length would be 200 (the maximum lag). The algorithm would then publish messages as follows:</p><ul><li><p>Partition 1 &#8594; Publish 100 messages (200 - 100)</p></li><li><p>Partition 2 &#8594; Publish 50 messages (200-150)</p></li><li><p>Partition 3 &#8594; Publish 80 messages (200 - 120)</p></li><li><p>Partition 4 &#8594; Publish 0 messages (already at the target)</p></li></ul><p>See the diagram below:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!cKO_!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2019140-dbef-4646-aea5-59743c9d5c16_2101x1323.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!cKO_!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2019140-dbef-4646-aea5-59743c9d5c16_2101x1323.png 424w, https://substackcdn.com/image/fetch/$s_!cKO_!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2019140-dbef-4646-aea5-59743c9d5c16_2101x1323.png 848w, https://substackcdn.com/image/fetch/$s_!cKO_!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2019140-dbef-4646-aea5-59743c9d5c16_2101x1323.png 1272w, https://substackcdn.com/image/fetch/$s_!cKO_!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2019140-dbef-4646-aea5-59743c9d5c16_2101x1323.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!cKO_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2019140-dbef-4646-aea5-59743c9d5c16_2101x1323.png" width="1456" height="917" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e2019140-dbef-4646-aea5-59743c9d5c16_2101x1323.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:917,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:192569,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!cKO_!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2019140-dbef-4646-aea5-59743c9d5c16_2101x1323.png 424w, https://substackcdn.com/image/fetch/$s_!cKO_!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2019140-dbef-4646-aea5-59743c9d5c16_2101x1323.png 848w, https://substackcdn.com/image/fetch/$s_!cKO_!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2019140-dbef-4646-aea5-59743c9d5c16_2101x1323.png 1272w, https://substackcdn.com/image/fetch/$s_!cKO_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2019140-dbef-4646-aea5-59743c9d5c16_2101x1323.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/arpZp4bcm33HPVRCSrAq?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><h2><strong>2 - Outlier Detection Algorithm</strong></h2><p>The Outlier Detection Algorithm identifies partitions with abnormally high lag (outliers) and temporarily stops publishing messages to those partitions to allow them to catch up.</p><p>It uses statistical methods like Interquartile Range (IQR) or Standard Deviation (STD) to identify outlier partitions.</p><p>For example, consider a scenario with 6 partitions having the following lags:</p><ul><li><p>Partition 1 &#8594; 100 messages</p></li><li><p>Partition 2 &#8594; 120 messages</p></li><li><p>Partition 3 &#8594; 300 messages</p></li></ul><p>Using the IQR method, partition 3 is identified as an outlier (slow partition). The algorithm would then:</p><ul><li><p>Stop publishing messages to partition 3</p></li><li><p>Evenly distribute messages among partitions 1 and 2.</p></li><li><p>If partition 3 improves and is no longer an outlier, gradually resume publishing messages to them.</p></li></ul><p><strong>So - what do you think about Agoda&#8217;s load-balancing solution for Kafka? Would you have done something differently?</strong></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/how-agoda-load-balanced-kafka/comments&quot;,&quot;text&quot;:&quot;Leave a comment&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/how-agoda-load-balanced-kafka/comments"><span>Leave a comment</span></a></p><p><strong>Reference:</strong></p><p><a href="https://medium.com/agoda-engineering/how-we-solve-load-balancing-challenges-in-apache-kafka-8cd88fdad02b">How We Solve Load Balancing Challenges in Apache Kafka</a></p><div><hr></div><p><strong>That&#8217;s it for today! &#9728;&#65039;</strong></p><p>Enjoyed this issue of the newsletter?</p><p>Share with your friends and colleagues.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/how-agoda-load-balanced-kafka?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/how-agoda-load-balanced-kafka?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p><em><strong>See you later with another edition &#8212; Saurabh</strong></em></p>]]></content:encoded></item><item><title><![CDATA[What Happens to an SQL Query?]]></title><description><![CDATA[The Journey Through the DB]]></description><link>https://newsletter.systemdesigncodex.com/p/what-happens-to-an-sql-query</link><guid isPermaLink="false">https://newsletter.systemdesigncodex.com/p/what-happens-to-an-sql-query</guid><dc:creator><![CDATA[Saurabh Dashora]]></dc:creator><pubDate>Wed, 04 Mar 2026 03:14:28 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!NfGN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a4e60df-517b-43df-bdb1-8dc56f523d3e_1808x2477.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><strong>What happens when you make an SQL query to the database?</strong></p><p>Let&#8217;s say this is the query:</p><blockquote><p><strong>SELECT name, age FROM users WHERE city = &#8216;New York&#8217;;</strong></p></blockquote><p>Here&#8217;s a diagram that shows the process visually:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!NfGN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a4e60df-517b-43df-bdb1-8dc56f523d3e_1808x2477.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!NfGN!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a4e60df-517b-43df-bdb1-8dc56f523d3e_1808x2477.png 424w, https://substackcdn.com/image/fetch/$s_!NfGN!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a4e60df-517b-43df-bdb1-8dc56f523d3e_1808x2477.png 848w, https://substackcdn.com/image/fetch/$s_!NfGN!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a4e60df-517b-43df-bdb1-8dc56f523d3e_1808x2477.png 1272w, https://substackcdn.com/image/fetch/$s_!NfGN!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a4e60df-517b-43df-bdb1-8dc56f523d3e_1808x2477.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!NfGN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a4e60df-517b-43df-bdb1-8dc56f523d3e_1808x2477.png" width="1456" height="1995" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9a4e60df-517b-43df-bdb1-8dc56f523d3e_1808x2477.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1995,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:430781,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!NfGN!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a4e60df-517b-43df-bdb1-8dc56f523d3e_1808x2477.png 424w, https://substackcdn.com/image/fetch/$s_!NfGN!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a4e60df-517b-43df-bdb1-8dc56f523d3e_1808x2477.png 848w, https://substackcdn.com/image/fetch/$s_!NfGN!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a4e60df-517b-43df-bdb1-8dc56f523d3e_1808x2477.png 1272w, https://substackcdn.com/image/fetch/$s_!NfGN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a4e60df-517b-43df-bdb1-8dc56f523d3e_1808x2477.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/nJvB4h1oZDT325MthtMx?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><p>Let&#8217;s go through each step in more detail:</p><h2><strong>STEP 1</strong></h2><p>When you hit run, the query string first reaches the Transport Subsystem of the database.</p><p>As the name suggests, this subsystem manages the connection with the client.</p><p>It also performs initial authentication and authorization checks, and if satisfied, lets the query go to the next step.</p><h2><strong>STEP 2</strong></h2><p>The query now reaches the Query Processor, which has two main parts:</p><ul><li><p>Query Parser</p></li><li><p>Query Optimizer</p></li></ul><p>The Query Parser breaks down the SQL query into its parts (SELECT, FROM, WHERE, etc). It checks for any syntax errors and creates a parse tree.</p><p>Then, the Query Optimizer goes through the parse tree, checks for semantic errors (e.g. - if the &#8216;users&#8217; table exists or not), and determines the most efficient way to execute the query.</p><p>As output, the optimizer produces an execution plan.</p><h2><strong>STEP 3</strong></h2><p>Next, the execution plan makes its way to the Execution Engine.</p><p>The plan is made up of all the steps that are needed to execute the query.</p><p>The Execution Engine takes this plan and coordinates the execution of each step by calling the Storage Engine. It also collects the results from each step and returns a unified response to the upper layer.</p><h2><strong>STEP 4</strong></h2><p>The Execution Engine sends low-level read/write requests to the Storage Engine depending on the execution plan.</p><p>All of this is facilitated by the various employees of the Storage Engine.</p><p>For example,</p><ul><li><p>The transaction manager ensures that the query runs within a transaction for consistency.</p></li><li><p>The lock manager acquires necessary locks on the &#8220;users&#8221; table to prevent conflicts.</p></li><li><p>The buffer manager checks if the required data pages are already in memory. If not, it requests the data to be loaded from the disk into memory.</p></li><li><p>The recovery manager logs the operations for rollback or recovery.</p></li></ul><p>&#128073; <strong>So - what else would you add to this journey of an SQL query?</strong></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/what-happens-to-an-sql-query/comments&quot;,&quot;text&quot;:&quot;Leave a comment&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/what-happens-to-an-sql-query/comments"><span>Leave a comment</span></a></p><div><hr></div><p><strong>That&#8217;s it for today! &#9728;&#65039;</strong></p><p>Enjoyed this issue of the newsletter?</p><p>Share with your friends and colleagues.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/what-happens-to-an-sql-query?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/what-happens-to-an-sql-query?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p><em><strong>See you later with another edition &#8212; Saurabh</strong></em></p>]]></content:encoded></item><item><title><![CDATA[How to Prevent the DB from Becoming a Bottleneck]]></title><description><![CDATA[Tips and Strategies]]></description><link>https://newsletter.systemdesigncodex.com/p/how-to-prevent-the-db-from-becoming</link><guid isPermaLink="false">https://newsletter.systemdesigncodex.com/p/how-to-prevent-the-db-from-becoming</guid><dc:creator><![CDATA[Saurabh Dashora]]></dc:creator><pubDate>Tue, 24 Feb 2026 08:15:03 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!Cl1U!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35b35c57-6027-4ba4-b8bb-bc572dc6eebb_2101x1370.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>You&#8217;ve done everything right. Your code is clean, your functions are optimized, and you&#8217;ve used the latest frameworks. But your application is still slow.</p><p>Why?</p><p>Because your database is struggling to keep up.</p><p>This is a common problem in backend development&#8212;your code executes in milliseconds, but your database queries take seconds. If you don&#8217;t address this, you&#8217;ll end up with sluggish APIs, frustrated users, and a system that crumbles under load.</p><p>Let&#8217;s explore why databases slow down and how to fix them.</p><h2><strong>Why the Database Can Become a Bottleneck?</strong></h2><p>Databases are slower than code execution.</p><p>Your application code runs in memory, but your database reads and writes data from disks or over a network. Even with SSDs and optimized database engines, disk access and network calls are still much slower than in-memory operations.</p><p>But how do you know if your database is causing performance issues?</p><p>Look for these symptoms:</p><ul><li><p>Your API requests take a long time despite minimal application logic.</p></li><li><p>Your database CPU usage is always high.</p></li><li><p>Queries take longer as your data grows.</p></li><li><p>Your application struggles under high user traffic.</p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Cl1U!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35b35c57-6027-4ba4-b8bb-bc572dc6eebb_2101x1370.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Cl1U!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35b35c57-6027-4ba4-b8bb-bc572dc6eebb_2101x1370.png 424w, https://substackcdn.com/image/fetch/$s_!Cl1U!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35b35c57-6027-4ba4-b8bb-bc572dc6eebb_2101x1370.png 848w, https://substackcdn.com/image/fetch/$s_!Cl1U!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35b35c57-6027-4ba4-b8bb-bc572dc6eebb_2101x1370.png 1272w, https://substackcdn.com/image/fetch/$s_!Cl1U!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35b35c57-6027-4ba4-b8bb-bc572dc6eebb_2101x1370.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Cl1U!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35b35c57-6027-4ba4-b8bb-bc572dc6eebb_2101x1370.png" width="1456" height="949" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/35b35c57-6027-4ba4-b8bb-bc572dc6eebb_2101x1370.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:949,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:302049,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!Cl1U!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35b35c57-6027-4ba4-b8bb-bc572dc6eebb_2101x1370.png 424w, https://substackcdn.com/image/fetch/$s_!Cl1U!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35b35c57-6027-4ba4-b8bb-bc572dc6eebb_2101x1370.png 848w, https://substackcdn.com/image/fetch/$s_!Cl1U!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35b35c57-6027-4ba4-b8bb-bc572dc6eebb_2101x1370.png 1272w, https://substackcdn.com/image/fetch/$s_!Cl1U!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35b35c57-6027-4ba4-b8bb-bc572dc6eebb_2101x1370.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/LkLxPbebfWJhCH7GSS7y?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><h2><strong>Diagnosing the Problem</strong></h2><p>Before you start optimizing, you need to identify the actual bottlenecks. Here&#8217;s how:</p><h3><strong>Use Query Profiling</strong></h3><p>Every major database has a way to analyze slow queries:</p><ul><li><p><strong>MySQL &amp; PostgreSQL:</strong> Use <code>EXPLAIN ANALYZE</code> to check execution plans.</p></li><li><p><strong>MongoDB:</strong> Use <code>.explain()</code> to analyze queries.</p></li><li><p><strong>Slow Query Logs:</strong> Identify the queries that are taking the most time.</p></li></ul><p>For example:</p><pre><code><code>EXPLAIN ANALYZE SELECT * FROM orders WHERE status = 'pending';</code></code></pre><p>This will show how your database processes the query and where the delays are happening.</p><h3><strong>Look at Key Performance Metrics</strong></h3><p>Monitor the following database metrics:</p><ul><li><p><strong>Query execution time:</strong> Are some queries consistently slow?</p></li><li><p><strong>Read/write latency:</strong> Is your database struggling with high read or write operations?</p></li><li><p><strong>Locking issues:</strong> Are queries blocking each other?</p></li><li><p><strong>Connection pooling:</strong> Are too many connections being opened and closed?</p></li></ul><p>Once you&#8217;ve identified the slow queries, you can start optimizing them.</p><h3><strong>Database Locking &amp; Deadlocks</strong></h3><p>When multiple queries or transactions run concurrently, databases use locking mechanisms to ensure data consistency.</p><p>However, poor transaction management can lead to deadlocks, where two or more queries wait indefinitely for each other to release a lock, causing performance bottlenecks.</p><p>There are different types of locks:</p><ul><li><p><strong>Row-level locks</strong>: Lock individual rows, allowing higher concurrency. (Ideal for OLTP applications)</p></li><li><p><strong>Table-level locks</strong>: Lock the entire table, preventing modifications while a transaction is running. (Can cause slowdowns)</p></li><li><p><strong>Shared vs. Exclusive locks</strong>: Shared locks allow multiple reads, while exclusive locks block all access until completion.</p></li></ul><p>Some best practices to deal with deadlocks are as follows:</p><ul><li><p>Keep transactions short and efficient (commit early).</p></li><li><p>Access tables in a consistent order across transactions.</p></li><li><p>Use indexing to reduce unnecessary locks.</p></li><li><p>Monitor for deadlocks using <code>SHOW ENGINE INNODB STATUS;</code> (MySQL) or <code>pg_stat_activity</code> (PostgreSQL).</p></li></ul><h2><strong>Optimizing Your Queries</strong></h2><p>Optimizing queries is a quick win. Here are some common tips that can help:</p><h3><strong>1 - Add Indexes (The Right Way!)</strong></h3><p>Indexes speed up lookups by avoiding full table scans.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Vzaf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a440b08-7b6b-4914-a015-b5f7df7b40ef_1604x966.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Vzaf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a440b08-7b6b-4914-a015-b5f7df7b40ef_1604x966.png 424w, https://substackcdn.com/image/fetch/$s_!Vzaf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a440b08-7b6b-4914-a015-b5f7df7b40ef_1604x966.png 848w, https://substackcdn.com/image/fetch/$s_!Vzaf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a440b08-7b6b-4914-a015-b5f7df7b40ef_1604x966.png 1272w, https://substackcdn.com/image/fetch/$s_!Vzaf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a440b08-7b6b-4914-a015-b5f7df7b40ef_1604x966.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Vzaf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a440b08-7b6b-4914-a015-b5f7df7b40ef_1604x966.png" width="1456" height="877" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4a440b08-7b6b-4914-a015-b5f7df7b40ef_1604x966.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:877,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:186589,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!Vzaf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a440b08-7b6b-4914-a015-b5f7df7b40ef_1604x966.png 424w, https://substackcdn.com/image/fetch/$s_!Vzaf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a440b08-7b6b-4914-a015-b5f7df7b40ef_1604x966.png 848w, https://substackcdn.com/image/fetch/$s_!Vzaf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a440b08-7b6b-4914-a015-b5f7df7b40ef_1604x966.png 1272w, https://substackcdn.com/image/fetch/$s_!Vzaf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a440b08-7b6b-4914-a015-b5f7df7b40ef_1604x966.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/LkLxPbebfWJhCH7GSS7y?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><p>For example, the query below would be considered bad without indexes in the email field.</p><pre><code><code>SELECT * FROM users WHERE email = 'user@example.com';</code></code></pre><p>A simple fix would be to create the index on email.</p><pre><code><code>CREATE INDEX idx_email ON users(email);</code></code></pre><p>With an index, the database can locate the data instantly instead of scanning every row. However, too many indexes slow down writes, so there is a trade-off involved. Make sure to only index the columns you frequently search on.</p><h3><strong>2 - Avoid SELECT *** (Be Specific)</strong></h3><p>Fetching all columns when you only need a few wastes resources. For example, the below query should not be used:</p><pre><code><code>SELECT * FROM orders WHERE status = 'pending';</code></code></pre><p>A better option is the query below:</p><pre><code><code>SELECT id, customer_id, total_price FROM orders WHERE status = 'pending';</code></code></pre><p>This reduces the amount of data transferred and speeds up queries.</p><h3><strong>3 - Use Joins &amp; Reduce Nested Queries</strong></h3><p>Avoid nested queries. For example:</p><pre><code><code>SELECT * FROM orders WHERE customer_id IN (SELECT id FROM customers WHERE city = 'New York');</code></code></pre><p>Using joins like the example below can be a much better strategy.</p><pre><code><code>SELECT orders.order_id 
FROM orders 
JOIN customers ON orders.customer_id = customers.id 
WHERE customers.city = 'New York';</code></code></pre><p>Joins are optimized by the database, whereas nested queries can cause multiple redundant lookups.</p><h2><strong>Scaling Beyond Queries: Architectural Optimizations</strong></h2><p>Some optimizations are also required on the architectural level to improve database performance. Here are some examples:</p><h3><strong>Schema Design</strong></h3><p>Database schema design directly impacts query speed, scalability, and storage efficiency. Poor schema decisions lead to slow queries, high storage costs, and scaling bottlenecks.</p><p>Here&#8217;s how to optimize schema design for better performance:</p><h4><strong>1 - Normalization vs. Denormalization: Trade-offs</strong></h4><ul><li><p>Normalization (3NF and above) reduces data redundancy by breaking tables into smaller, related entities.</p><ul><li><p><strong>Pros:</strong> Saves space and avoids update anomalies.</p></li><li><p><strong>Cons:</strong> Can slow down read-heavy queries due to excessive JOINs.</p></li></ul></li><li><p>Denormalization merges frequently used data to reduce JOINs, making reads faster at the cost of extra storage and potential update issues.</p><ul><li><p><strong>Pros:</strong> Great for analytics &amp; high-read workloads.</p></li><li><p><strong>Cons:</strong> Can lead to data inconsistency if not managed properly.</p></li></ul></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Ln7_!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a999744-9bd3-4680-b13e-10c338901a91_2361x1550.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Ln7_!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a999744-9bd3-4680-b13e-10c338901a91_2361x1550.png 424w, https://substackcdn.com/image/fetch/$s_!Ln7_!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a999744-9bd3-4680-b13e-10c338901a91_2361x1550.png 848w, https://substackcdn.com/image/fetch/$s_!Ln7_!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a999744-9bd3-4680-b13e-10c338901a91_2361x1550.png 1272w, https://substackcdn.com/image/fetch/$s_!Ln7_!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a999744-9bd3-4680-b13e-10c338901a91_2361x1550.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Ln7_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a999744-9bd3-4680-b13e-10c338901a91_2361x1550.png" width="1456" height="956" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0a999744-9bd3-4680-b13e-10c338901a91_2361x1550.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:956,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:286754,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!Ln7_!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a999744-9bd3-4680-b13e-10c338901a91_2361x1550.png 424w, https://substackcdn.com/image/fetch/$s_!Ln7_!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a999744-9bd3-4680-b13e-10c338901a91_2361x1550.png 848w, https://substackcdn.com/image/fetch/$s_!Ln7_!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a999744-9bd3-4680-b13e-10c338901a91_2361x1550.png 1272w, https://substackcdn.com/image/fetch/$s_!Ln7_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a999744-9bd3-4680-b13e-10c338901a91_2361x1550.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/LkLxPbebfWJhCH7GSS7y?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><p><strong>Rule of Thumb:</strong> Normalize when you expect frequent writes, denormalize when reads dominate.</p><h4><strong>2 - Choosing the Right Data Types</strong></h4><ul><li><p>Use <code>BIGINT</code> instead of <code>UUID</code> for primary keys unless uniqueness across distributed systems is needed.</p></li><li><p>Use <code>BOOLEAN</code> for true/false values.</p></li><li><p>Use <code>TEXT</code>/<code>JSONB</code> sparingly. This is because indexable columns are faster for queries.</p></li></ul><h3><strong>Use Caching</strong></h3><p>Instead of hitting the database every time, store frequently accessed data in a cache (Redis, Memcached). This reduces database load significantly.</p><p>For example, cache the result of expensive queries.</p><pre><code><code>cache.set("user_123_orders", query_result, expire=300) # Expires in 5 minutes</code></code></pre><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!pj9Q!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc7ae6ef-7856-40bd-9cf1-5a74644787b4_2175x1361.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!pj9Q!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc7ae6ef-7856-40bd-9cf1-5a74644787b4_2175x1361.png 424w, https://substackcdn.com/image/fetch/$s_!pj9Q!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc7ae6ef-7856-40bd-9cf1-5a74644787b4_2175x1361.png 848w, https://substackcdn.com/image/fetch/$s_!pj9Q!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc7ae6ef-7856-40bd-9cf1-5a74644787b4_2175x1361.png 1272w, https://substackcdn.com/image/fetch/$s_!pj9Q!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc7ae6ef-7856-40bd-9cf1-5a74644787b4_2175x1361.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!pj9Q!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc7ae6ef-7856-40bd-9cf1-5a74644787b4_2175x1361.png" width="1456" height="911" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cc7ae6ef-7856-40bd-9cf1-5a74644787b4_2175x1361.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:911,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:230837,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!pj9Q!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc7ae6ef-7856-40bd-9cf1-5a74644787b4_2175x1361.png 424w, https://substackcdn.com/image/fetch/$s_!pj9Q!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc7ae6ef-7856-40bd-9cf1-5a74644787b4_2175x1361.png 848w, https://substackcdn.com/image/fetch/$s_!pj9Q!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc7ae6ef-7856-40bd-9cf1-5a74644787b4_2175x1361.png 1272w, https://substackcdn.com/image/fetch/$s_!pj9Q!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc7ae6ef-7856-40bd-9cf1-5a74644787b4_2175x1361.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/LkLxPbebfWJhCH7GSS7y?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><h3><strong>Optimize Database Connections</strong></h3><p>Opening and closing database connections is expensive. Use <strong>connection pooling</strong> to reuse existing connections instead of creating new ones for every request.</p><p>For example, use <code>pgbouncer</code> for PostgreSQL connection pooling.</p><h3><strong>Materialized Views for Precomputed Expensive Queries</strong></h3><p>A Materialized View is a precomputed query result stored as a physical table. Unlike a regular database view, which runs a query every time it&#8217;s accessed, a materialized view stores the result persistently, making expensive queries much faster.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!JFk9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc22852f7-38dd-476f-b0b8-c5edc8ab65e3_1929x1277.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!JFk9!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc22852f7-38dd-476f-b0b8-c5edc8ab65e3_1929x1277.png 424w, https://substackcdn.com/image/fetch/$s_!JFk9!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc22852f7-38dd-476f-b0b8-c5edc8ab65e3_1929x1277.png 848w, https://substackcdn.com/image/fetch/$s_!JFk9!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc22852f7-38dd-476f-b0b8-c5edc8ab65e3_1929x1277.png 1272w, https://substackcdn.com/image/fetch/$s_!JFk9!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc22852f7-38dd-476f-b0b8-c5edc8ab65e3_1929x1277.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!JFk9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc22852f7-38dd-476f-b0b8-c5edc8ab65e3_1929x1277.png" width="1456" height="964" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c22852f7-38dd-476f-b0b8-c5edc8ab65e3_1929x1277.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:964,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:168878,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!JFk9!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc22852f7-38dd-476f-b0b8-c5edc8ab65e3_1929x1277.png 424w, https://substackcdn.com/image/fetch/$s_!JFk9!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc22852f7-38dd-476f-b0b8-c5edc8ab65e3_1929x1277.png 848w, https://substackcdn.com/image/fetch/$s_!JFk9!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc22852f7-38dd-476f-b0b8-c5edc8ab65e3_1929x1277.png 1272w, https://substackcdn.com/image/fetch/$s_!JFk9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc22852f7-38dd-476f-b0b8-c5edc8ab65e3_1929x1277.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/LkLxPbebfWJhCH7GSS7y?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><p>For example, suppose we frequently calculate total sales per day from a huge <code>orders</code> table:</p><pre><code><code>SELECT order_date, SUM(total_price) AS daily_sales
FROM orders
GROUP BY order_date;</code></code></pre><p>If the <code>orders</code> table is massive, this query slows down dashboards and reports. To handle this, you can create a materialized view. This way queries can read directly from the view instead of querying the <code>orders</code> table.</p><p>However, materialized views don&#8217;t usually auto-update when data changes. There needs to be a mechanism to update them. Also, this approach is not suitable for real-time data needs.</p><h3><strong>Sharding &amp; Partitioning for Large Datasets</strong></h3><p>When your database gets huge, split data across multiple servers (sharding) or distribute tables across partitions.</p><p>For example:</p><ul><li><p>Shard users based on country (<code>users_us</code>, <code>users_eu</code>)</p></li><li><p>Partition orders by date (<code>orders_2023</code>, <code>orders_2024</code>)</p></li></ul><p>This reduces the load on a single table and speeds up lookups.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!waRm!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F592eba2e-20df-4cb4-ad8c-8299ea7ab9e0_2101x1370.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!waRm!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F592eba2e-20df-4cb4-ad8c-8299ea7ab9e0_2101x1370.png 424w, https://substackcdn.com/image/fetch/$s_!waRm!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F592eba2e-20df-4cb4-ad8c-8299ea7ab9e0_2101x1370.png 848w, https://substackcdn.com/image/fetch/$s_!waRm!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F592eba2e-20df-4cb4-ad8c-8299ea7ab9e0_2101x1370.png 1272w, https://substackcdn.com/image/fetch/$s_!waRm!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F592eba2e-20df-4cb4-ad8c-8299ea7ab9e0_2101x1370.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!waRm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F592eba2e-20df-4cb4-ad8c-8299ea7ab9e0_2101x1370.png" width="1456" height="949" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/592eba2e-20df-4cb4-ad8c-8299ea7ab9e0_2101x1370.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:949,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:200182,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!waRm!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F592eba2e-20df-4cb4-ad8c-8299ea7ab9e0_2101x1370.png 424w, https://substackcdn.com/image/fetch/$s_!waRm!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F592eba2e-20df-4cb4-ad8c-8299ea7ab9e0_2101x1370.png 848w, https://substackcdn.com/image/fetch/$s_!waRm!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F592eba2e-20df-4cb4-ad8c-8299ea7ab9e0_2101x1370.png 1272w, https://substackcdn.com/image/fetch/$s_!waRm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F592eba2e-20df-4cb4-ad8c-8299ea7ab9e0_2101x1370.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/LkLxPbebfWJhCH7GSS7y?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><h3><strong>Use Read Replicas for Scaling Reads</strong></h3><p>If you have millions of reads per second, create read replicas to distribute the load.</p><p>For example:</p><ul><li><p><strong>Primary DB:</strong> Handles writes and critical reads.</p></li><li><p><strong>Read Replicas:</strong> Handle read queries.</p></li></ul><p>Many large-scale systems use this approach for redundancy as well as improved durability.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!F5lJ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ade9f26-135b-4d13-83b1-b8ea7f3ad693_1929x1319.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!F5lJ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ade9f26-135b-4d13-83b1-b8ea7f3ad693_1929x1319.png 424w, https://substackcdn.com/image/fetch/$s_!F5lJ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ade9f26-135b-4d13-83b1-b8ea7f3ad693_1929x1319.png 848w, https://substackcdn.com/image/fetch/$s_!F5lJ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ade9f26-135b-4d13-83b1-b8ea7f3ad693_1929x1319.png 1272w, https://substackcdn.com/image/fetch/$s_!F5lJ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ade9f26-135b-4d13-83b1-b8ea7f3ad693_1929x1319.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!F5lJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ade9f26-135b-4d13-83b1-b8ea7f3ad693_1929x1319.png" width="1456" height="996" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8ade9f26-135b-4d13-83b1-b8ea7f3ad693_1929x1319.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:996,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:199699,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!F5lJ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ade9f26-135b-4d13-83b1-b8ea7f3ad693_1929x1319.png 424w, https://substackcdn.com/image/fetch/$s_!F5lJ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ade9f26-135b-4d13-83b1-b8ea7f3ad693_1929x1319.png 848w, https://substackcdn.com/image/fetch/$s_!F5lJ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ade9f26-135b-4d13-83b1-b8ea7f3ad693_1929x1319.png 1272w, https://substackcdn.com/image/fetch/$s_!F5lJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ade9f26-135b-4d13-83b1-b8ea7f3ad693_1929x1319.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/LkLxPbebfWJhCH7GSS7y?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><h2><strong>Conclusion: Diagnose Before You Optimize</strong></h2><p>Here are some tips to keep in mind:</p><ul><li><p><strong>Don&#8217;t blindly optimize</strong>&#8212;use logs and profiling to find real bottlenecks.</p></li><li><p><strong>Start with query optimization</strong>&#8212;indexes, joins, and batching solve 80% of problems.</p></li><li><p><strong>Use caching and read replicas</strong>&#8212;offload repetitive queries.</p></li><li><p><strong>Think about scaling architecture</strong>&#8212;sharding, partitioning, and hybrid databases.</p></li></ul><p>A slow database doesn&#8217;t have to hold you back. With the right optimizations, you can make your system blazing fast and scalable.</p><p>&#128073; <strong>So - which other tip will you add to optimize the database access?</strong></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/how-to-prevent-the-db-from-becoming/comments&quot;,&quot;text&quot;:&quot;Leave a comment&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/how-to-prevent-the-db-from-becoming/comments"><span>Leave a comment</span></a></p><div><hr></div><p><strong>That&#8217;s it for today! &#9728;&#65039;</strong></p><p>Enjoyed this issue of the newsletter?</p><p>Share with your friends and colleagues.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/how-to-prevent-the-db-from-becoming?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/how-to-prevent-the-db-from-becoming?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p><em><strong>See you later with another edition &#8212; Saurabh</strong></em></p>]]></content:encoded></item><item><title><![CDATA[Airbnb's Move from Monolith]]></title><description><![CDATA[The journey of migration]]></description><link>https://newsletter.systemdesigncodex.com/p/airbnbs-move-from-monolith</link><guid isPermaLink="false">https://newsletter.systemdesigncodex.com/p/airbnbs-move-from-monolith</guid><dc:creator><![CDATA[Saurabh Dashora]]></dc:creator><pubDate>Tue, 17 Feb 2026 07:56:10 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!ZNoT!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feed9c53e-abbe-4c88-82c7-da34cb05ece1_1698x1218.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Like most startups, Airbnb started with a monolithic application built using Ruby on Rails. Internally, it was called the <em>monorail</em> because everything went through this single application.</p><p>This monolith was responsible for both client and server-side functionality. The model, view, and controller layers were packed into a single repository.</p><p>A simple diagram for this architecture would appear as follows:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ZNoT!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feed9c53e-abbe-4c88-82c7-da34cb05ece1_1698x1218.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ZNoT!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feed9c53e-abbe-4c88-82c7-da34cb05ece1_1698x1218.png 424w, https://substackcdn.com/image/fetch/$s_!ZNoT!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feed9c53e-abbe-4c88-82c7-da34cb05ece1_1698x1218.png 848w, https://substackcdn.com/image/fetch/$s_!ZNoT!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feed9c53e-abbe-4c88-82c7-da34cb05ece1_1698x1218.png 1272w, https://substackcdn.com/image/fetch/$s_!ZNoT!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feed9c53e-abbe-4c88-82c7-da34cb05ece1_1698x1218.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ZNoT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feed9c53e-abbe-4c88-82c7-da34cb05ece1_1698x1218.png" width="1456" height="1044" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/eed9c53e-abbe-4c88-82c7-da34cb05ece1_1698x1218.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1044,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:164218,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!ZNoT!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feed9c53e-abbe-4c88-82c7-da34cb05ece1_1698x1218.png 424w, https://substackcdn.com/image/fetch/$s_!ZNoT!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feed9c53e-abbe-4c88-82c7-da34cb05ece1_1698x1218.png 848w, https://substackcdn.com/image/fetch/$s_!ZNoT!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feed9c53e-abbe-4c88-82c7-da34cb05ece1_1698x1218.png 1272w, https://substackcdn.com/image/fetch/$s_!ZNoT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feed9c53e-abbe-4c88-82c7-da34cb05ece1_1698x1218.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/qww9HW81DEoiIj7zS5W3?origin=share">You can check out the diagram on Eraser.io</a></figcaption></figure></div><p>There were several advantages to this monolithic approach:</p><ul><li><p>Easy to get started initially.</p></li><li><p>Good for agile development</p></li><li><p>Manageable complexity levels</p></li></ul><p>Those were simpler times and such times usually don&#8217;t last. Airbnb grew fast, and its engineering team doubled and tripled. Suddenly, you had more and more developers adding new code and features to the monorail.</p><p>Just like too many cooks spoil the dish, the code base started to get tightly coupled, and data ownership became muddled. Any developer could make changes to any part of the application, making it difficult to track and coordinate the changes.</p><p>Airbnb decided to migrate from the monorail to a Service-Oriented Architecture. You could also see it as a move towards loosely coupled microservices.</p><h1><strong>The Rules of the Game</strong></h1><p>Of course, Airbnb was wise and came up with some key design principles for building services. Some of the rules are mentioned below:</p><ul><li><p>A service should own both the reads and writes to its data. This is similar to the database-per-service pattern where a particular piece of data is owned by one and only one service.</p></li><li><p>A service should address a specific concern</p></li><li><p>Services should avoid duplicating functionality</p></li><li><p>Data changes should happen via standard events to encourage loose coupling.</p></li><li><p>Each service must have proper alerting and observability settings</p></li></ul><h1><strong>The SOA Design</strong></h1><p>After a few years of migration stuff, Airbnb ended up with the below architecture:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!jIt2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F432ddaae-77cd-45eb-b4d4-379093ced8e1_1698x1906.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!jIt2!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F432ddaae-77cd-45eb-b4d4-379093ced8e1_1698x1906.png 424w, https://substackcdn.com/image/fetch/$s_!jIt2!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F432ddaae-77cd-45eb-b4d4-379093ced8e1_1698x1906.png 848w, https://substackcdn.com/image/fetch/$s_!jIt2!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F432ddaae-77cd-45eb-b4d4-379093ced8e1_1698x1906.png 1272w, https://substackcdn.com/image/fetch/$s_!jIt2!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F432ddaae-77cd-45eb-b4d4-379093ced8e1_1698x1906.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!jIt2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F432ddaae-77cd-45eb-b4d4-379093ced8e1_1698x1906.png" width="1456" height="1634" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/432ddaae-77cd-45eb-b4d4-379093ced8e1_1698x1906.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1634,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:250672,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!jIt2!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F432ddaae-77cd-45eb-b4d4-379093ced8e1_1698x1906.png 424w, https://substackcdn.com/image/fetch/$s_!jIt2!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F432ddaae-77cd-45eb-b4d4-379093ced8e1_1698x1906.png 848w, https://substackcdn.com/image/fetch/$s_!jIt2!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F432ddaae-77cd-45eb-b4d4-379093ced8e1_1698x1906.png 1272w, https://substackcdn.com/image/fetch/$s_!jIt2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F432ddaae-77cd-45eb-b4d4-379093ced8e1_1698x1906.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/qww9HW81DEoiIj7zS5W3?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><p>Let&#8217;s unpack it a bit.</p><ul><li><p>The bottom layer is composed of <strong>data services</strong>. These services are the entry point for all interactions with the database and aren&#8217;t dependent on any other service.</p></li><li><p>The <strong>derived services</strong> read data from other services and apply basic business logic. They can also have specialized data storage to store any derived data.</p></li><li><p>The <strong>middle-tier services</strong> contain the key business logic that doesn&#8217;t fit at the data service level or the derived data service level.</p></li><li><p>At the very top are the <strong>presentation services</strong>. These services aggregate data from all other services and apply frontend-specific business logic before returning the data to the client.</p></li></ul><h1><strong>The Migration</strong></h1><p>The move from the <em>monorail</em> to shiny new services wasn&#8217;t an overnight process. Also, migrating reads and writes had their problems.</p><p>Let&#8217;s look at both scenarios and how Airbnb handled the migration.</p><h2><strong>Migrating the Reads</strong></h2><p>Airbnb used dual reads and response comparison for the old read path (through the <em>monorail) </em>and the new read path (the service).</p><p>See the diagram below:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!mVXY!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F950084c7-1210-44b6-a3d7-faa7d1eaadd9_1698x1218.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!mVXY!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F950084c7-1210-44b6-a3d7-faa7d1eaadd9_1698x1218.png 424w, https://substackcdn.com/image/fetch/$s_!mVXY!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F950084c7-1210-44b6-a3d7-faa7d1eaadd9_1698x1218.png 848w, https://substackcdn.com/image/fetch/$s_!mVXY!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F950084c7-1210-44b6-a3d7-faa7d1eaadd9_1698x1218.png 1272w, https://substackcdn.com/image/fetch/$s_!mVXY!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F950084c7-1210-44b6-a3d7-faa7d1eaadd9_1698x1218.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!mVXY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F950084c7-1210-44b6-a3d7-faa7d1eaadd9_1698x1218.png" width="1456" height="1044" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/950084c7-1210-44b6-a3d7-faa7d1eaadd9_1698x1218.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1044,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:146004,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!mVXY!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F950084c7-1210-44b6-a3d7-faa7d1eaadd9_1698x1218.png 424w, https://substackcdn.com/image/fetch/$s_!mVXY!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F950084c7-1210-44b6-a3d7-faa7d1eaadd9_1698x1218.png 848w, https://substackcdn.com/image/fetch/$s_!mVXY!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F950084c7-1210-44b6-a3d7-faa7d1eaadd9_1698x1218.png 1272w, https://substackcdn.com/image/fetch/$s_!mVXY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F950084c7-1210-44b6-a3d7-faa7d1eaadd9_1698x1218.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/qww9HW81DEoiIj7zS5W3?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><p>Every read request went through both paths. The responses were sent to a comparison framework. Once the engineers were sure that things were as expected, the traffic to the service path was ramped up.</p><h2><strong>Migrating the Writes</strong></h2><p>Writes were trickier because one cannot dual-write to the same database. Therefore, the engineers used a shadow database.</p><p>See the diagram below:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!McET!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77e4531a-141b-4948-9751-512fe10dd27b_1698x1218.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!McET!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77e4531a-141b-4948-9751-512fe10dd27b_1698x1218.png 424w, https://substackcdn.com/image/fetch/$s_!McET!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77e4531a-141b-4948-9751-512fe10dd27b_1698x1218.png 848w, https://substackcdn.com/image/fetch/$s_!McET!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77e4531a-141b-4948-9751-512fe10dd27b_1698x1218.png 1272w, https://substackcdn.com/image/fetch/$s_!McET!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77e4531a-141b-4948-9751-512fe10dd27b_1698x1218.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!McET!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77e4531a-141b-4948-9751-512fe10dd27b_1698x1218.png" width="1456" height="1044" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/77e4531a-141b-4948-9751-512fe10dd27b_1698x1218.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1044,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:173306,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!McET!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77e4531a-141b-4948-9751-512fe10dd27b_1698x1218.png 424w, https://substackcdn.com/image/fetch/$s_!McET!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77e4531a-141b-4948-9751-512fe10dd27b_1698x1218.png 848w, https://substackcdn.com/image/fetch/$s_!McET!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77e4531a-141b-4948-9751-512fe10dd27b_1698x1218.png 1272w, https://substackcdn.com/image/fetch/$s_!McET!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77e4531a-141b-4948-9751-512fe10dd27b_1698x1218.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/qww9HW81DEoiIj7zS5W3?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><p>The new service initially writes to the shadow database. After that, read requests are sent to the prod and shadow database, and the responses are sent to the comparison framework.</p><p>Only after the comparison came out clean, the writes were completely switched to the new service.</p><h1><strong>Lessons</strong></h1><p>Airbnb had several important lessons from this whole migration process. A few important ones for us are as follows</p><ul><li><p>Invest in common infrastructure pieces early on. Things like shadow databases, comparison frameworks, etc. can help during the migration.</p></li><li><p>Simplify the service dependencies</p></li><li><p>Moving to services is not just technical but also a cultural change for the organization.</p></li><li><p>The migration isn&#8217;t a fixed destination but a journey.</p></li></ul><p><strong>So - what do you think about Airbnb&#8217;s migration journey? Would you have done something differently?</strong></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/airbnbs-move-from-monolith/comments&quot;,&quot;text&quot;:&quot;Leave a comment&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/airbnbs-move-from-monolith/comments"><span>Leave a comment</span></a></p><p><strong>References:</strong></p><ul><li><p><a href="https://www.infoq.com/news/2019/02/airbnb-monolith-migration-soa/">Airbnb&#8217;s Migration from Monolith to Services</a></p></li><li><p><a href="https://www.infoq.com/presentations/airbnb-scalability/">Airbnb at Scale</a></p></li></ul><div><hr></div><p><strong>That&#8217;s it for today! &#9728;&#65039;</strong></p><p>Enjoyed this issue of the newsletter?</p><p>Share with your friends and colleagues.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/airbnbs-move-from-monolith?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/airbnbs-move-from-monolith?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p><em><strong>See you later with another edition &#8212; Saurabh</strong></em></p>]]></content:encoded></item><item><title><![CDATA[Eraser’s New AI-Driven Diagramming Workflow]]></title><description><![CDATA[Making Documentation Wonderful Again]]></description><link>https://newsletter.systemdesigncodex.com/p/erasers-new-ai-driven-diagramming</link><guid isPermaLink="false">https://newsletter.systemdesigncodex.com/p/erasers-new-ai-driven-diagramming</guid><dc:creator><![CDATA[Saurabh Dashora]]></dc:creator><pubDate>Tue, 10 Feb 2026 08:52:33 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!C4Tv!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F036ccd4f-a119-431c-90d1-d8fcc8daff44_3102x3249.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>If there is one universal truth in software engineering, it is that everyone loves <em>having</em> documentation, but absolutely nobody loves <em>writing</em> it. We&#8217;ve all been there: you&#8217;ve just finished architecting a complex system or debugging a nasty race condition, and now you have to open a blank canvas, drag 50 rectangles onto a screen, and manually draw arrows until your eyes glaze over.</p><p>Eraser, the developer-focused whiteboard tool, makes this extremely easy, and now it can do a lot more with new integrations. The premise of this new integration is amazing: instead of dragging and dropping UI elements, what if you could just tell your IDE to &#8220;draw the architecture diagram&#8221;? </p><p>Last week, I got to try the new <a href="https://docs.eraser.io/docs/using-ai-agent-integrations">AI integrations of Eraser</a> and here&#8217;s what I learned:</p><h3>The Setup</h3><p>The biggest friction point in documentation is context switching. You usually have to leave your code editor, open a browser, log in to a tool, and start from scratch. However, Eraser makes this easy. All you need is install the skill in your IDE of choice by running a simple CLI command.</p><p><code>npx skills-add eraser-labs/eraser-io</code></p><p>With this command, we are essentially priming the IDE to work with Eraser. This allows the user to stay within an AI-powered editor (like Cursor) and generate diagrams without leaving their code. </p><h3>How It Works</h3><p>When we ask the AI agent to create a diagram using the Eraser skills, here&#8217;s what happens behind the scenes:</p><ol><li><p>You describe the diagram you want in natural language</p></li><li><p>The AI agent processes your request:</p><ul><li><p><strong>Skills</strong>: The agent generates Eraser-specific syntax.</p></li><li><p><strong>MCP Server</strong>: Can use the syntax or generate with natural language </p></li></ul></li><li><p>Eraser returns a rendered diagram image link.</p></li></ol><p>The diagram below shows this flow:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!NlLb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ec2ec4e-243f-4f71-895b-5a7be7e998d4_2200x394.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!NlLb!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ec2ec4e-243f-4f71-895b-5a7be7e998d4_2200x394.png 424w, https://substackcdn.com/image/fetch/$s_!NlLb!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ec2ec4e-243f-4f71-895b-5a7be7e998d4_2200x394.png 848w, https://substackcdn.com/image/fetch/$s_!NlLb!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ec2ec4e-243f-4f71-895b-5a7be7e998d4_2200x394.png 1272w, https://substackcdn.com/image/fetch/$s_!NlLb!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ec2ec4e-243f-4f71-895b-5a7be7e998d4_2200x394.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!NlLb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ec2ec4e-243f-4f71-895b-5a7be7e998d4_2200x394.png" width="1456" height="261" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6ec2ec4e-243f-4f71-895b-5a7be7e998d4_2200x394.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:261,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!NlLb!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ec2ec4e-243f-4f71-895b-5a7be7e998d4_2200x394.png 424w, https://substackcdn.com/image/fetch/$s_!NlLb!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ec2ec4e-243f-4f71-895b-5a7be7e998d4_2200x394.png 848w, https://substackcdn.com/image/fetch/$s_!NlLb!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ec2ec4e-243f-4f71-895b-5a7be7e998d4_2200x394.png 1272w, https://substackcdn.com/image/fetch/$s_!NlLb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ec2ec4e-243f-4f71-895b-5a7be7e998d4_2200x394.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>The agent can now generate any diagram type supported by Eraser:</p><ul><li><p><strong>Architecture diagrams</strong> - Cloud infrastructure, system design</p></li><li><p><strong>Sequence diagrams</strong> - API flows, authentication sequences</p></li><li><p><strong>Flowcharts</strong> - Process flows, decision trees</p></li><li><p><strong>Entity relationship diagrams (ERD)</strong> - Database schemas</p></li><li><p><strong>BPMN diagrams</strong> - Business processes, swimlane diagrams</p></li></ul><h3>Trial 1: Generating OAuth Flow</h3><p>To truly test a diagramming tool, you need a subject that is notoriously annoying to visualize. And therefore, I tried to visualize the OAuth flow:</p><p>If you have ever had to explain the OAuth flow to a junior developer or a stakeholder, you know the struggle. You have the User, the Client App, the Authorization Server, and the Resource Server. Then you add in the PKCE (Proof Key for Code Exchange) flow, and suddenly everything can start looking like a mess.</p><p>So, I tried it with Eraser this time, using a simple prompt. Instead of drawing the &#8220;Client&#8221; box, you simply prompt the agent: <em>&#8220;Generate a sequence diagram for the Google OAuth2 flow using PKCE and OIDC discovery.&#8221;</em></p><p>Here&#8217;s what I got in just a few seconds:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!C4Tv!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F036ccd4f-a119-431c-90d1-d8fcc8daff44_3102x3249.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!C4Tv!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F036ccd4f-a119-431c-90d1-d8fcc8daff44_3102x3249.png 424w, https://substackcdn.com/image/fetch/$s_!C4Tv!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F036ccd4f-a119-431c-90d1-d8fcc8daff44_3102x3249.png 848w, https://substackcdn.com/image/fetch/$s_!C4Tv!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F036ccd4f-a119-431c-90d1-d8fcc8daff44_3102x3249.png 1272w, https://substackcdn.com/image/fetch/$s_!C4Tv!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F036ccd4f-a119-431c-90d1-d8fcc8daff44_3102x3249.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!C4Tv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F036ccd4f-a119-431c-90d1-d8fcc8daff44_3102x3249.png" width="1456" height="1525" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/036ccd4f-a119-431c-90d1-d8fcc8daff44_3102x3249.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1525,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:678001,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesigncodex.com/i/187258228?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F036ccd4f-a119-431c-90d1-d8fcc8daff44_3102x3249.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!C4Tv!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F036ccd4f-a119-431c-90d1-d8fcc8daff44_3102x3249.png 424w, https://substackcdn.com/image/fetch/$s_!C4Tv!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F036ccd4f-a119-431c-90d1-d8fcc8daff44_3102x3249.png 848w, https://substackcdn.com/image/fetch/$s_!C4Tv!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F036ccd4f-a119-431c-90d1-d8fcc8daff44_3102x3249.png 1272w, https://substackcdn.com/image/fetch/$s_!C4Tv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F036ccd4f-a119-431c-90d1-d8fcc8daff44_3102x3249.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Pretty amazing, if you ask me. And it also makes thing easy to build upon further if needed.</p><h3>Trial 2: Visualizing Infrastructure (The Terraform Scenario)</h3><p>Another trial I did was using the infrastructure diagrams that you can generate using Terraform files.</p><p>Imagine you join a new team and are handed a massive repository of Terraform files. You see a <code>main.tf</code>, <code>variables.tf</code>, and modules for VPCs, RDS instances, and EC2 auto-scaling groups. Reading the code tells you what is there, but it doesn&#8217;t tell you how it connects.</p><p>Using this AI integration, you could theoretically feed the agent your <code>main.tf</code> file and ask: <em>&#8220;Read this Terraform configuration and generate an architecture diagram showing the relationship between the public subnets, the load balancers, and the database.&#8221;</em></p><p>The AI parses the HCL (HashiCorp Configuration Language), identifies the resources, understands the <code>depends_on</code> or reference links, and outputs a visual map. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!TsUs!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F09678082-1208-42a0-a650-c3168829c7b6_1479x530.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!TsUs!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F09678082-1208-42a0-a650-c3168829c7b6_1479x530.png 424w, https://substackcdn.com/image/fetch/$s_!TsUs!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F09678082-1208-42a0-a650-c3168829c7b6_1479x530.png 848w, https://substackcdn.com/image/fetch/$s_!TsUs!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F09678082-1208-42a0-a650-c3168829c7b6_1479x530.png 1272w, https://substackcdn.com/image/fetch/$s_!TsUs!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F09678082-1208-42a0-a650-c3168829c7b6_1479x530.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!TsUs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F09678082-1208-42a0-a650-c3168829c7b6_1479x530.png" width="1456" height="522" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/09678082-1208-42a0-a650-c3168829c7b6_1479x530.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:522,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:72056,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesigncodex.com/i/187258228?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F09678082-1208-42a0-a650-c3168829c7b6_1479x530.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!TsUs!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F09678082-1208-42a0-a650-c3168829c7b6_1479x530.png 424w, https://substackcdn.com/image/fetch/$s_!TsUs!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F09678082-1208-42a0-a650-c3168829c7b6_1479x530.png 848w, https://substackcdn.com/image/fetch/$s_!TsUs!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F09678082-1208-42a0-a650-c3168829c7b6_1479x530.png 1272w, https://substackcdn.com/image/fetch/$s_!TsUs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F09678082-1208-42a0-a650-c3168829c7b6_1479x530.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>This &#8220;Reverse Engineering&#8221; capability of Eraser is perhaps the strongest selling point for me. It transforms &#8220;documentation&#8221; from a proactive chore (something you have to create) into a reactive asset (something you can generate instantly from existing code).</p><h3>What I Feel About The AI Integrations?</h3><p>After seeing the capabilities, here is what I think about this skill and where it fits in a developer&#8217;s toolkit.</p><p><strong>1. It Respects Flow State:</strong> The primary benefit isn&#8217;t just that the computer draws faster than you. It&#8217;s that you don&#8217;t have to stop coding to document. By keeping the generation inside the terminal/IDE, there is very little context switching. You stay in the terminal, you stay in the code, and the diagram happens in the background.</p><p><strong>2. The &#8220;80/20&#8221; Rule of Diagramming:</strong> Is the AI-generated diagram perfect? Probably not 100% of the time. It might mislabel a specific edge case or group things awkwardly. However, it gets you 80% to 90% of the way there in seconds. It is much easier, in my view, to move a few pre-generated boxes around than to create a system design from a blank white screen.</p><p><strong>3. Documentation as a Communication Tool:</strong>  Often, backend developers build complex architectures that the Ops team has to deploy. Miscommunication here is common. Being able to instantly generate a visual representation of your code or Docker files bridges that gap. </p><blockquote><p><em><strong>Also, special thanks to the Eraser team for sharing the details about the new AI integrations and collaborating on this post.</strong></em></p></blockquote><p>You can try out these integrations yourself. Here&#8217;s the link to the documentation that can guide you through the process:</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://docs.eraser.io/docs/using-ai-agent-integrations&quot;,&quot;text&quot;:&quot;Eraser AI Integration Documentation&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://docs.eraser.io/docs/using-ai-agent-integrations"><span>Eraser AI Integration Documentation</span></a></p><p><strong>So, what do you think about these features?</strong></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/erasers-new-ai-driven-diagramming/comments&quot;,&quot;text&quot;:&quot;Leave a comment&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/erasers-new-ai-driven-diagramming/comments"><span>Leave a comment</span></a></p><div><hr></div><p><strong>That&#8217;s it for today! &#9728;&#65039;</strong></p><p>Enjoyed this issue of the newsletter?</p><p>Share with your friends and colleagues.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/erasers-new-ai-driven-diagramming?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/erasers-new-ai-driven-diagramming?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p></p>]]></content:encoded></item><item><title><![CDATA[The Role of Caching at Netflix]]></title><description><![CDATA[How Netflix Holds Your Attention]]></description><link>https://newsletter.systemdesigncodex.com/p/the-role-of-caching-at-netflix</link><guid isPermaLink="false">https://newsletter.systemdesigncodex.com/p/the-role-of-caching-at-netflix</guid><dc:creator><![CDATA[Saurabh Dashora]]></dc:creator><pubDate>Tue, 03 Feb 2026 08:52:57 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!s9HK!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6caec37-cfde-4ff4-8f91-ff464d4fb50b_2175x1361.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Netflix has a simple yet ambitious goal: to keep users engaged and streaming for as long as possible.</p><p>However, in a world where user attention spans are fleeting&#8212;averaging just 90 seconds before a decision is made&#8212;Netflix&#8217;s ability to deliver content swiftly is critical.</p><p>One of the core technologies that helps Netflix achieve this is EVCache, a distributed in-memory key-value store.</p><p>Here are four major use cases for EVCache at Netflix and how they contribute to keeping you streaming for as long as possible.</p><h2><strong>1 - Look-aside Cache</strong></h2><p>The first and perhaps most common use case for EVCache is as a <strong>look-aside cache</strong>.</p><p>This caching pattern ensures that frequently accessed data is readily available, reducing the time required to fetch data from backend services and databases.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!s9HK!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6caec37-cfde-4ff4-8f91-ff464d4fb50b_2175x1361.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!s9HK!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6caec37-cfde-4ff4-8f91-ff464d4fb50b_2175x1361.png 424w, https://substackcdn.com/image/fetch/$s_!s9HK!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6caec37-cfde-4ff4-8f91-ff464d4fb50b_2175x1361.png 848w, https://substackcdn.com/image/fetch/$s_!s9HK!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6caec37-cfde-4ff4-8f91-ff464d4fb50b_2175x1361.png 1272w, https://substackcdn.com/image/fetch/$s_!s9HK!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6caec37-cfde-4ff4-8f91-ff464d4fb50b_2175x1361.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!s9HK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6caec37-cfde-4ff4-8f91-ff464d4fb50b_2175x1361.png" width="1456" height="911" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b6caec37-cfde-4ff4-8f91-ff464d4fb50b_2175x1361.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:911,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:226896,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!s9HK!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6caec37-cfde-4ff4-8f91-ff464d4fb50b_2175x1361.png 424w, https://substackcdn.com/image/fetch/$s_!s9HK!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6caec37-cfde-4ff4-8f91-ff464d4fb50b_2175x1361.png 848w, https://substackcdn.com/image/fetch/$s_!s9HK!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6caec37-cfde-4ff4-8f91-ff464d4fb50b_2175x1361.png 1272w, https://substackcdn.com/image/fetch/$s_!s9HK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6caec37-cfde-4ff4-8f91-ff464d4fb50b_2175x1361.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/SfhnsDNAzASwsXfaPGO7?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><h3><strong>How It Works:</strong></h3><ul><li><p>When an application requests data, it first queries the EVCache client to see if the data is already cached.</p></li><li><p>If the data is not in the cache (a cache miss), the application fetches it from the backend service, which may involve querying the Cassandra database.</p></li><li><p>Once the data is retrieved from the database, it is stored in EVCache for future requests.</p></li></ul><h3><strong>Why It Matters:</strong></h3><ul><li><p><strong>Reduced Latency</strong>: By serving data directly from the cache, Netflix can significantly reduce the time it takes to load recommendations, watch histories, or other user-specific data.</p></li><li><p><strong>Scalability</strong>: Backend services and databases are spared from handling repetitive queries, allowing them to focus on other tasks.</p></li><li><p><strong>Improved User Experience</strong>: Faster response times mean users can start streaming without delays, reducing the likelihood of them abandoning the platform.</p></li></ul><h3><strong>Example Use Case:</strong></h3><p>Imagine a user navigating to the Netflix home page. The application needs to fetch personalized recommendations and thumbnails. Instead of querying the backend service for every user, EVCache serves these requests almost instantly, ensuring a smooth and engaging experience.</p><h2><strong>2 -Transient Data Store</strong></h2><p>Netflix also uses EVCache as a <strong>transient data store</strong> to manage temporary data that changes frequently but doesn&#8217;t require permanent storage. A prime example is playback session information.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!I6mK!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F114f84c8-d375-4b93-9121-50217cacd884_2175x1361.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!I6mK!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F114f84c8-d375-4b93-9121-50217cacd884_2175x1361.png 424w, https://substackcdn.com/image/fetch/$s_!I6mK!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F114f84c8-d375-4b93-9121-50217cacd884_2175x1361.png 848w, https://substackcdn.com/image/fetch/$s_!I6mK!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F114f84c8-d375-4b93-9121-50217cacd884_2175x1361.png 1272w, https://substackcdn.com/image/fetch/$s_!I6mK!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F114f84c8-d375-4b93-9121-50217cacd884_2175x1361.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!I6mK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F114f84c8-d375-4b93-9121-50217cacd884_2175x1361.png" width="1456" height="911" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/114f84c8-d375-4b93-9121-50217cacd884_2175x1361.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:911,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:230585,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!I6mK!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F114f84c8-d375-4b93-9121-50217cacd884_2175x1361.png 424w, https://substackcdn.com/image/fetch/$s_!I6mK!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F114f84c8-d375-4b93-9121-50217cacd884_2175x1361.png 848w, https://substackcdn.com/image/fetch/$s_!I6mK!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F114f84c8-d375-4b93-9121-50217cacd884_2175x1361.png 1272w, https://substackcdn.com/image/fetch/$s_!I6mK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F114f84c8-d375-4b93-9121-50217cacd884_2175x1361.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/SfhnsDNAzASwsXfaPGO7?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><h3><strong>How It Works:</strong></h3><ul><li><p>A playback session begins when a user starts watching a show or movie. This session information, such as playback time and device details, is stored in EVCache.</p></li><li><p>Other services may update this session data (for example, when a user pauses or skips content).</p></li><li><p>At the end of the session, the data may be discarded or stored in a more permanent database for analytics.</p></li></ul><h3><strong>Why It Matters:</strong></h3><ul><li><p><strong>Low Latency Updates</strong>: Transient data like session information requires real-time updates and reads, which EVCache handles efficiently.</p></li><li><p><strong>Service Coordination</strong>: Since multiple services interact with playback data during a session, EVCache ensures that this data is accessible to all relevant services with minimal latency.</p></li><li><p><strong>Cost Efficiency</strong>: EVCache provides a cost-effective solution for handling temporary data that doesn&#8217;t need to be stored long-term.</p></li></ul><h3><strong>Example Use Case:</strong></h3><p>When a user pauses a movie on one device and resumes it on another, EVCache ensures that the playback position is instantly updated and available, enabling seamless transitions between devices.</p><h2><strong>3 - Primary Store</strong></h2><p>For some use cases, EVCache is not just a caching layer but acts as a <strong>primary data store</strong>. One prominent example is Netflix&#8217;s personalized home page, which is computed nightly for every user.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!7f6z!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa8a68ca8-04cd-4a64-b521-3cfc8945e717_2175x1361.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!7f6z!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa8a68ca8-04cd-4a64-b521-3cfc8945e717_2175x1361.png 424w, https://substackcdn.com/image/fetch/$s_!7f6z!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa8a68ca8-04cd-4a64-b521-3cfc8945e717_2175x1361.png 848w, https://substackcdn.com/image/fetch/$s_!7f6z!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa8a68ca8-04cd-4a64-b521-3cfc8945e717_2175x1361.png 1272w, https://substackcdn.com/image/fetch/$s_!7f6z!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa8a68ca8-04cd-4a64-b521-3cfc8945e717_2175x1361.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!7f6z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa8a68ca8-04cd-4a64-b521-3cfc8945e717_2175x1361.png" width="1456" height="911" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a8a68ca8-04cd-4a64-b521-3cfc8945e717_2175x1361.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:911,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:219017,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!7f6z!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa8a68ca8-04cd-4a64-b521-3cfc8945e717_2175x1361.png 424w, https://substackcdn.com/image/fetch/$s_!7f6z!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa8a68ca8-04cd-4a64-b521-3cfc8945e717_2175x1361.png 848w, https://substackcdn.com/image/fetch/$s_!7f6z!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa8a68ca8-04cd-4a64-b521-3cfc8945e717_2175x1361.png 1272w, https://substackcdn.com/image/fetch/$s_!7f6z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa8a68ca8-04cd-4a64-b521-3cfc8945e717_2175x1361.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/SfhnsDNAzASwsXfaPGO7?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><h3><strong>How It Works:</strong></h3><ul><li><p>Large-scale pre-compute systems analyze each user&#8217;s watch history, preferences, and recommendation algorithms.</p></li><li><p>The result is a tailored home page, including categories, thumbnails, and recommendations for each profile.</p></li><li><p>This data is written to the EVCache cluster, where it is stored and served to the user&#8217;s device during their next session.</p></li></ul><h3><strong>Why It Matters:</strong></h3><ul><li><p><strong>Pre-Computed Efficiency</strong>: By precomputing the home page, Netflix reduces the computational load during peak hours when users log in.</p></li><li><p><strong>Scalability</strong>: EVCache&#8217;s distributed nature allows Netflix to handle millions of unique home pages across its global user base.</p></li><li><p><strong>Instant Access</strong>: Storing the home page data in EVCache ensures low-latency retrieval, enabling Netflix to deliver a fully personalized experience as soon as the user opens the app.</p></li></ul><h3><strong>Example Use Case:</strong></h3><p>When a user logs into their profile, the pre-computed data stored in EVCache is instantly retrieved to populate their home page. This allows Netflix to deliver recommendations without waiting for backend computations.</p><h2><strong>4 - High Volume Data</strong></h2><p>Netflix also uses EVCache for data that experiences high-volume access and requires high availability. One notable example is UI strings and translations shown on the home page.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ZNmR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e247939-28b5-4744-a839-a383f15a0107_2175x1361.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ZNmR!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e247939-28b5-4744-a839-a383f15a0107_2175x1361.png 424w, https://substackcdn.com/image/fetch/$s_!ZNmR!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e247939-28b5-4744-a839-a383f15a0107_2175x1361.png 848w, https://substackcdn.com/image/fetch/$s_!ZNmR!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e247939-28b5-4744-a839-a383f15a0107_2175x1361.png 1272w, https://substackcdn.com/image/fetch/$s_!ZNmR!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e247939-28b5-4744-a839-a383f15a0107_2175x1361.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ZNmR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e247939-28b5-4744-a839-a383f15a0107_2175x1361.png" width="1456" height="911" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3e247939-28b5-4744-a839-a383f15a0107_2175x1361.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:911,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:263144,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!ZNmR!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e247939-28b5-4744-a839-a383f15a0107_2175x1361.png 424w, https://substackcdn.com/image/fetch/$s_!ZNmR!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e247939-28b5-4744-a839-a383f15a0107_2175x1361.png 848w, https://substackcdn.com/image/fetch/$s_!ZNmR!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e247939-28b5-4744-a839-a383f15a0107_2175x1361.png 1272w, https://substackcdn.com/image/fetch/$s_!ZNmR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e247939-28b5-4744-a839-a383f15a0107_2175x1361.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/SfhnsDNAzASwsXfaPGO7?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><h3><strong>How It Works:</strong></h3><ul><li><p>A separate process asynchronously computes and publishes UI strings, such as titles, descriptions, and menu text, to EVCache.</p></li><li><p>These strings are then read by the application whenever needed, ensuring low latency and high availability.</p></li></ul><h3><strong>Why It Matters:</strong></h3><ul><li><p><strong>Global Reach</strong>: With users around the world, Netflix needs to deliver localized content and UI strings in multiple languages.</p></li><li><p><strong>High Availability</strong>: EVCache ensures that even under heavy traffic, essential UI elements are quickly and reliably available.</p></li><li><p><strong>Improved User Experience</strong>: By caching these high-volume data elements, Netflix ensures consistent and fast loading times across all devices and regions.</p></li></ul><h3><strong>Example Use Case:</strong></h3><p>When a user opens Netflix, the localized UI elements, such as titles and navigation options, are fetched from EVCache. This ensures that the interface is fully loaded before the user starts interacting with the app.</p><p>&#128073; <strong>So - which other caching use case have you come across?</strong></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/the-role-of-caching-at-netflix/comments&quot;,&quot;text&quot;:&quot;Leave a comment&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/the-role-of-caching-at-netflix/comments"><span>Leave a comment</span></a></p><div><hr></div><p><strong>That&#8217;s it for today! &#9728;&#65039;</strong></p><p>Enjoyed this issue of the newsletter?</p><p>Share with your friends and colleagues.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/the-role-of-caching-at-netflix?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/the-role-of-caching-at-netflix?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p>]]></content:encoded></item><item><title><![CDATA[Synchronous Communication is NOT the Only Way]]></title><description><![CDATA[There are other ways your application components can talk to each other]]></description><link>https://newsletter.systemdesigncodex.com/p/synchronous-communication-is-not</link><guid isPermaLink="false">https://newsletter.systemdesigncodex.com/p/synchronous-communication-is-not</guid><dc:creator><![CDATA[Saurabh Dashora]]></dc:creator><pubDate>Wed, 28 Jan 2026 01:57:51 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!8Wlm!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64be4e8d-7405-406f-b921-d8e9abd51968_2175x1361.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Stop using synchronous communication for every interaction between services.</p><blockquote><p><strong>Synchronous communication is when one service waits for a response from another before proceeding.</strong></p></blockquote><p>While it sometimes works well, relying solely on synchronous communication for every interaction between microservices is counter-productive.</p><h1><strong>The Challenges of Sync Communication</strong></h1><p>There are multiple challenges with just relying on synchronous communication.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!FR4W!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bd5b94a-2b01-49ca-8328-05aefc5f9b52_2175x1361.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!FR4W!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bd5b94a-2b01-49ca-8328-05aefc5f9b52_2175x1361.png 424w, https://substackcdn.com/image/fetch/$s_!FR4W!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bd5b94a-2b01-49ca-8328-05aefc5f9b52_2175x1361.png 848w, https://substackcdn.com/image/fetch/$s_!FR4W!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bd5b94a-2b01-49ca-8328-05aefc5f9b52_2175x1361.png 1272w, https://substackcdn.com/image/fetch/$s_!FR4W!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bd5b94a-2b01-49ca-8328-05aefc5f9b52_2175x1361.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!FR4W!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bd5b94a-2b01-49ca-8328-05aefc5f9b52_2175x1361.png" width="1456" height="911" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7bd5b94a-2b01-49ca-8328-05aefc5f9b52_2175x1361.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:911,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:233055,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!FR4W!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bd5b94a-2b01-49ca-8328-05aefc5f9b52_2175x1361.png 424w, https://substackcdn.com/image/fetch/$s_!FR4W!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bd5b94a-2b01-49ca-8328-05aefc5f9b52_2175x1361.png 848w, https://substackcdn.com/image/fetch/$s_!FR4W!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bd5b94a-2b01-49ca-8328-05aefc5f9b52_2175x1361.png 1272w, https://substackcdn.com/image/fetch/$s_!FR4W!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bd5b94a-2b01-49ca-8328-05aefc5f9b52_2175x1361.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/At0mcFda1UZDwM2nTEr8?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><p>Let&#8217;s look at a few important ones:</p><h3><strong>1 - Increased Latency</strong></h3><p>In a synchronous model, a service sends a request to another service and waits for a response.</p><p>If multiple services are chained in this manner, you just end up with latency compounding.</p><p>For instance, if Service A calls Service B, which then calls Service C, the overall response time is the sum of the latencies of each call. In scenarios where services are geographically distributed or under heavy load, this latency is bound to become a bottleneck.</p><h3><strong>2 - Downtime and Cascading Failures</strong></h3><p>When one service depends on another synchronously, any downtime or failure in one service can ripple through the entire system.</p><p>If Service B is unavailable, Service A will fail to process its requests. This tight coupling makes the entire system more fragile and prone to cascading failures.</p><h3><strong>3 - Higher Costs</strong></h3><p>Synchronous communication requires services to handle requests in real time.</p><p>To meet peak demand, you often need to provision resources for the highest possible load, leading to underutilized resources during off-peak times.</p><h3><strong>4 - Tight Temporal Coupling</strong></h3><p>Synchronous communication creates a dependency on the availability and responsiveness of other services at the instance level.</p><p>Both service instances must be operational simultaneously for communication to succeed. This temporal coupling can complicate deployments, scaling, and debugging.</p><h1><strong>Alternatives to Synchronous Communication</strong></h1><p>The good news is that there are alternative approaches to synchronous communication.</p><p>Let&#8217;s look at some of these alternatives:</p><h2><strong>Asynchronous Request-Response</strong></h2><p>In asynchronous communication, the caller sends a request but doesn&#8217;t block while waiting for the response. For example, a &#8220;Payment&#8221; service can place a &#8220;Process Payment&#8221; request in a queue. The &#8220;Billing&#8221; service processes the request asynchronously and places a &#8220;Payment Processed&#8221; message in the response queue.</p><p>A common pattern for implementing this is using message queues, such as RabbitMQ, Kafka, or AWS SQS.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!xHkR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32ec471d-4c3a-4c34-bae2-2f1498c1c941_2175x1361.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!xHkR!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32ec471d-4c3a-4c34-bae2-2f1498c1c941_2175x1361.png 424w, https://substackcdn.com/image/fetch/$s_!xHkR!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32ec471d-4c3a-4c34-bae2-2f1498c1c941_2175x1361.png 848w, https://substackcdn.com/image/fetch/$s_!xHkR!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32ec471d-4c3a-4c34-bae2-2f1498c1c941_2175x1361.png 1272w, https://substackcdn.com/image/fetch/$s_!xHkR!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32ec471d-4c3a-4c34-bae2-2f1498c1c941_2175x1361.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!xHkR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32ec471d-4c3a-4c34-bae2-2f1498c1c941_2175x1361.png" width="1456" height="911" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/32ec471d-4c3a-4c34-bae2-2f1498c1c941_2175x1361.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:911,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:159267,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!xHkR!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32ec471d-4c3a-4c34-bae2-2f1498c1c941_2175x1361.png 424w, https://substackcdn.com/image/fetch/$s_!xHkR!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32ec471d-4c3a-4c34-bae2-2f1498c1c941_2175x1361.png 848w, https://substackcdn.com/image/fetch/$s_!xHkR!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32ec471d-4c3a-4c34-bae2-2f1498c1c941_2175x1361.png 1272w, https://substackcdn.com/image/fetch/$s_!xHkR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32ec471d-4c3a-4c34-bae2-2f1498c1c941_2175x1361.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/At0mcFda1UZDwM2nTEr8?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><h3><strong>How It Works:</strong></h3><ul><li><p>The sender places a request on a message queue.</p></li><li><p>The receiver processes the request asynchronously and places the response back in the queue.</p></li><li><p>The sender retrieves the response at its convenience.</p></li></ul><h3><strong>Benefits:</strong></h3><ul><li><p>Non-blocking communication improves responsiveness.</p></li><li><p>Services are loosely coupled, as they don&#8217;t need to be online at the same time.</p></li><li><p>Message queues can act as a buffer, helping handle spikes in traffic.</p></li></ul><h2><strong>Event-Driven Architecture</strong></h2><p>In an event-driven architecture, services communicate by publishing and subscribing to events. Instead of direct service-to-service calls, services emit events that other services consume.</p><p>For example, when an &#8220;OrderPlaced&#8221; event is emitted by the &#8220;Order&#8221; service, the &#8220;Inventory&#8221; service updates stock levels, and the &#8220;Notification&#8221; service sends a confirmation email&#8212;all without direct communication between them.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!8Wlm!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64be4e8d-7405-406f-b921-d8e9abd51968_2175x1361.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!8Wlm!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64be4e8d-7405-406f-b921-d8e9abd51968_2175x1361.png 424w, https://substackcdn.com/image/fetch/$s_!8Wlm!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64be4e8d-7405-406f-b921-d8e9abd51968_2175x1361.png 848w, https://substackcdn.com/image/fetch/$s_!8Wlm!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64be4e8d-7405-406f-b921-d8e9abd51968_2175x1361.png 1272w, https://substackcdn.com/image/fetch/$s_!8Wlm!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64be4e8d-7405-406f-b921-d8e9abd51968_2175x1361.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!8Wlm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64be4e8d-7405-406f-b921-d8e9abd51968_2175x1361.png" width="1456" height="911" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/64be4e8d-7405-406f-b921-d8e9abd51968_2175x1361.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:911,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:150864,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!8Wlm!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64be4e8d-7405-406f-b921-d8e9abd51968_2175x1361.png 424w, https://substackcdn.com/image/fetch/$s_!8Wlm!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64be4e8d-7405-406f-b921-d8e9abd51968_2175x1361.png 848w, https://substackcdn.com/image/fetch/$s_!8Wlm!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64be4e8d-7405-406f-b921-d8e9abd51968_2175x1361.png 1272w, https://substackcdn.com/image/fetch/$s_!8Wlm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64be4e8d-7405-406f-b921-d8e9abd51968_2175x1361.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/At0mcFda1UZDwM2nTEr8?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><h3><strong>How It Works:</strong></h3><ul><li><p>Services publish events, such as &#8220;OrderPlaced&#8221; or &#8220;PaymentProcessed,&#8221; to an event broker (e.g., Kafka, AWS SNS, or Redis Streams).</p></li><li><p>Interested services subscribe to these events and take appropriate actions.</p></li></ul><h3><strong>Benefits:</strong></h3><ul><li><p>Decouples services, allowing them to operate independently.</p></li><li><p>Enables scalability and resilience, as services don&#8217;t directly depend on each other&#8217;s availability.</p></li><li><p>Simplifies adding new functionality, as new services can subscribe to existing events without modifying the publisher.</p></li></ul><h2><strong>Well-Defined Service Boundaries</strong></h2><p>When services have well-defined responsibilities and minimal overlap, the need for inter-service communication is naturally reduced.</p><p>For example, instead of having a &#8220;User&#8221; service that handles user data and authentication, split these responsibilities into a &#8220;User Profile&#8221; service and an &#8220;Authentication&#8221; service. This minimizes unnecessary interactions and makes each service easier to scale and maintain.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!IH8F!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3fdc24a-7850-43bb-9677-338d6d2bb1ae_2175x1361.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!IH8F!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3fdc24a-7850-43bb-9677-338d6d2bb1ae_2175x1361.png 424w, https://substackcdn.com/image/fetch/$s_!IH8F!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3fdc24a-7850-43bb-9677-338d6d2bb1ae_2175x1361.png 848w, https://substackcdn.com/image/fetch/$s_!IH8F!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3fdc24a-7850-43bb-9677-338d6d2bb1ae_2175x1361.png 1272w, https://substackcdn.com/image/fetch/$s_!IH8F!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3fdc24a-7850-43bb-9677-338d6d2bb1ae_2175x1361.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!IH8F!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3fdc24a-7850-43bb-9677-338d6d2bb1ae_2175x1361.png" width="1456" height="911" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b3fdc24a-7850-43bb-9677-338d6d2bb1ae_2175x1361.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:911,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:173991,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!IH8F!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3fdc24a-7850-43bb-9677-338d6d2bb1ae_2175x1361.png 424w, https://substackcdn.com/image/fetch/$s_!IH8F!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3fdc24a-7850-43bb-9677-338d6d2bb1ae_2175x1361.png 848w, https://substackcdn.com/image/fetch/$s_!IH8F!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3fdc24a-7850-43bb-9677-338d6d2bb1ae_2175x1361.png 1272w, https://substackcdn.com/image/fetch/$s_!IH8F!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3fdc24a-7850-43bb-9677-338d6d2bb1ae_2175x1361.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/At0mcFda1UZDwM2nTEr8?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><h3><strong>How This Helps:</strong></h3><ul><li><p>By encapsulating functionality within a service boundary, you avoid frequent cross-service calls.</p></li><li><p>Services can operate more independently, improving their reliability and scalability.</p></li></ul><h2><strong>Bulk Data Transfers</strong></h2><p>For scenarios involving large amounts of data, consider using bulk data transfers instead of multiple synchronous requests. For example, a &#8220;Reporting&#8221; service can retrieve transaction logs from the &#8220;Payments&#8221; service in bulk, rather than querying for each transaction individually.</p><h3><strong>How It Works:</strong></h3><ul><li><p>Services periodically exchange data using batch jobs, file transfers, or database replication.</p></li><li><p>These operations are performed asynchronously during off-peak hours.</p></li></ul><h3><strong>Benefits:</strong></h3><ul><li><p>Reduces the load on services during real-time operations.</p></li><li><p>Improves overall system efficiency.</p></li></ul><h2><strong>Caching Local Copy</strong></h2><p>Sometimes, frequent inter-service communication can be replaced by caching or maintaining a local copy of data. For example, a &#8220;Product&#8221; service can cache product details locally instead of querying the &#8220;Catalog&#8221; service for every request.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!kCO9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2a6d212-6b0d-4dd4-9609-74d13d4d2f59_2175x1361.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!kCO9!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2a6d212-6b0d-4dd4-9609-74d13d4d2f59_2175x1361.png 424w, https://substackcdn.com/image/fetch/$s_!kCO9!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2a6d212-6b0d-4dd4-9609-74d13d4d2f59_2175x1361.png 848w, https://substackcdn.com/image/fetch/$s_!kCO9!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2a6d212-6b0d-4dd4-9609-74d13d4d2f59_2175x1361.png 1272w, https://substackcdn.com/image/fetch/$s_!kCO9!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2a6d212-6b0d-4dd4-9609-74d13d4d2f59_2175x1361.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!kCO9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2a6d212-6b0d-4dd4-9609-74d13d4d2f59_2175x1361.png" width="1456" height="911" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b2a6d212-6b0d-4dd4-9609-74d13d4d2f59_2175x1361.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:911,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:175155,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!kCO9!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2a6d212-6b0d-4dd4-9609-74d13d4d2f59_2175x1361.png 424w, https://substackcdn.com/image/fetch/$s_!kCO9!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2a6d212-6b0d-4dd4-9609-74d13d4d2f59_2175x1361.png 848w, https://substackcdn.com/image/fetch/$s_!kCO9!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2a6d212-6b0d-4dd4-9609-74d13d4d2f59_2175x1361.png 1272w, https://substackcdn.com/image/fetch/$s_!kCO9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2a6d212-6b0d-4dd4-9609-74d13d4d2f59_2175x1361.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/At0mcFda1UZDwM2nTEr8?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><h3><strong>How It Works:</strong></h3><ul><li><p>Use caching solutions like Redis or Memcached to store frequently accessed data.</p></li><li><p>Replicate state across services to avoid constant data retrieval.</p></li></ul><h3><strong>Benefits:</strong></h3><ul><li><p>Reduces latency by serving data locally.</p></li><li><p>Minimizes the risk of service unavailability affecting performance.</p></li></ul><h1><strong>Best Practices for Adopting Alternatives</strong></h1><ul><li><p><strong>Understand the Use Case</strong>: Not every scenario requires asynchronous communication. Analyze the trade-offs and choose the approach that fits your requirements.</p></li><li><p><strong>Monitor and Debug</strong>: Use distributed tracing tools like Jaeger or Zipkin to monitor asynchronous flows and troubleshoot issues.</p></li><li><p><strong>Graceful Degradation</strong>: Implement fallbacks and retries to handle communication failures gracefully.</p></li><li><p><strong>Prioritize Idempotency</strong>: Ensure that operations are idempotent to handle duplicate messages in asynchronous systems.</p></li></ul><p><strong>&#128073; So - will you add any other alternative approach to synchronous communication?</strong></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/synchronous-communication-is-not/comments&quot;,&quot;text&quot;:&quot;Leave a comment&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/synchronous-communication-is-not/comments"><span>Leave a comment</span></a></p><div><hr></div><p><strong>That&#8217;s it for today! &#9728;&#65039;</strong></p><p>Enjoyed this issue of the newsletter?</p><p>Share with your friends and colleagues.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/synchronous-communication-is-not?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/synchronous-communication-is-not?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p><em><strong>See you later with another edition &#8212; Saurabh</strong></em></p>]]></content:encoded></item><item><title><![CDATA[Top Strategies to Reduce Latency]]></title><description><![CDATA[Latency is the new downtime]]></description><link>https://newsletter.systemdesigncodex.com/p/top-strategies-to-reduce-latency</link><guid isPermaLink="false">https://newsletter.systemdesigncodex.com/p/top-strategies-to-reduce-latency</guid><dc:creator><![CDATA[Saurabh Dashora]]></dc:creator><pubDate>Tue, 20 Jan 2026 13:27:51 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!tU3c!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F734da7be-949f-4a8e-b88f-69e07482e6b6_4943x2814.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Latency is the new downtime in distributed systems.</p><p>High latency can render an application effectively unusable, frustrating end-users and negatively impacting business outcomes just as much as a complete outage.</p><p>The frustration of a slow website is more catastrophic to modern-day users.</p><div class="pullquote"><p><em><strong>At the bare minimum, unavailable websites don&#8217;t waste a user&#8217;s time directly.</strong></em></p></div><p>Considering this, it is wise for developers to invest in learning about low-latency strategies.</p><p>Here are the top strategies to reduce latency that you must be aware of (in no particular order):</p><h2><strong>1 - Caching</strong></h2><p>Caching is a fundamental technique used in distributed systems to improve performance and reduce the load on backend services.</p><p>The primary goal of caching is to minimize costly database lookups and avoid performing high-latency computations repeatedly.</p><p>By storing frequently accessed data in a cache, applications can retrieve the data much faster compared to fetching it from the source, such as a database or a remote service.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!uguW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33e9bd61-bd97-4ea1-a393-eb0f6a0e6b19_2032x1379.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!uguW!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33e9bd61-bd97-4ea1-a393-eb0f6a0e6b19_2032x1379.png 424w, https://substackcdn.com/image/fetch/$s_!uguW!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33e9bd61-bd97-4ea1-a393-eb0f6a0e6b19_2032x1379.png 848w, https://substackcdn.com/image/fetch/$s_!uguW!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33e9bd61-bd97-4ea1-a393-eb0f6a0e6b19_2032x1379.png 1272w, https://substackcdn.com/image/fetch/$s_!uguW!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33e9bd61-bd97-4ea1-a393-eb0f6a0e6b19_2032x1379.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!uguW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33e9bd61-bd97-4ea1-a393-eb0f6a0e6b19_2032x1379.png" width="1456" height="988" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/33e9bd61-bd97-4ea1-a393-eb0f6a0e6b19_2032x1379.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:988,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:204225,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!uguW!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33e9bd61-bd97-4ea1-a393-eb0f6a0e6b19_2032x1379.png 424w, https://substackcdn.com/image/fetch/$s_!uguW!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33e9bd61-bd97-4ea1-a393-eb0f6a0e6b19_2032x1379.png 848w, https://substackcdn.com/image/fetch/$s_!uguW!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33e9bd61-bd97-4ea1-a393-eb0f6a0e6b19_2032x1379.png 1272w, https://substackcdn.com/image/fetch/$s_!uguW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33e9bd61-bd97-4ea1-a393-eb0f6a0e6b19_2032x1379.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/t4VLfBoncm3jqGpbmyDr?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><p>Caches are typically implemented using high-speed memory or fast storage systems that provide low-latency access to the cached data.</p><h2><strong>2 - Content Delivery Networks (CDN)</strong></h2><p>While caching is a powerful technique for improving performance and reducing the load on backend services, it can be taken to the next level by leveraging Content Delivery Networks (CDNs).</p><p>A CDN is a geographically distributed network of servers that work together to deliver content to end users with high availability and performance.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!3zc7!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76e96fe3-111e-4157-9b7e-28614c285f3d_3864x4233.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!3zc7!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76e96fe3-111e-4157-9b7e-28614c285f3d_3864x4233.png 424w, https://substackcdn.com/image/fetch/$s_!3zc7!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76e96fe3-111e-4157-9b7e-28614c285f3d_3864x4233.png 848w, https://substackcdn.com/image/fetch/$s_!3zc7!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76e96fe3-111e-4157-9b7e-28614c285f3d_3864x4233.png 1272w, https://substackcdn.com/image/fetch/$s_!3zc7!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76e96fe3-111e-4157-9b7e-28614c285f3d_3864x4233.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!3zc7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76e96fe3-111e-4157-9b7e-28614c285f3d_3864x4233.png" width="1456" height="1595" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/76e96fe3-111e-4157-9b7e-28614c285f3d_3864x4233.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1595,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1061392,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!3zc7!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76e96fe3-111e-4157-9b7e-28614c285f3d_3864x4233.png 424w, https://substackcdn.com/image/fetch/$s_!3zc7!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76e96fe3-111e-4157-9b7e-28614c285f3d_3864x4233.png 848w, https://substackcdn.com/image/fetch/$s_!3zc7!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76e96fe3-111e-4157-9b7e-28614c285f3d_3864x4233.png 1272w, https://substackcdn.com/image/fetch/$s_!3zc7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76e96fe3-111e-4157-9b7e-28614c285f3d_3864x4233.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/t4VLfBoncm3jqGpbmyDr?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><p>CDNs reduce latency by caching content closer to the end users.</p><ul><li><p>When a user requests content from a website or application that utilizes a CDN, the request is redirected to the nearest CDN server instead of the origin server.</p></li><li><p>If the requested content is already cached on the CDN server, it is served directly from the cache, eliminating the need to retrieve it from the origin server. This reduces the distance the data has to travel and minimizes the response time.</p></li></ul><h2><strong>3 - Load Balancing</strong></h2><p>Load Balancing is a super important technique to distribute workload between multiple machines.</p><p>By employing load balancers to distribute incoming traffic across multiple servers, we ensure that no single server becomes overwhelmed. In other words, the system performs according to the user&#8217;s expectations.</p><p>When a client sends a request to a distributed system, the load balancer acts as the initial point of contact. It receives the incoming request and intelligently routes it to one of the available servers based on predefined algorithms or policies.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!85kO!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f74767f-8ec9-4449-881e-440eeae3cf76_2133x1280.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!85kO!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f74767f-8ec9-4449-881e-440eeae3cf76_2133x1280.png 424w, https://substackcdn.com/image/fetch/$s_!85kO!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f74767f-8ec9-4449-881e-440eeae3cf76_2133x1280.png 848w, https://substackcdn.com/image/fetch/$s_!85kO!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f74767f-8ec9-4449-881e-440eeae3cf76_2133x1280.png 1272w, https://substackcdn.com/image/fetch/$s_!85kO!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f74767f-8ec9-4449-881e-440eeae3cf76_2133x1280.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!85kO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f74767f-8ec9-4449-881e-440eeae3cf76_2133x1280.png" width="1456" height="874" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3f74767f-8ec9-4449-881e-440eeae3cf76_2133x1280.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:874,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:165935,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!85kO!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f74767f-8ec9-4449-881e-440eeae3cf76_2133x1280.png 424w, https://substackcdn.com/image/fetch/$s_!85kO!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f74767f-8ec9-4449-881e-440eeae3cf76_2133x1280.png 848w, https://substackcdn.com/image/fetch/$s_!85kO!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f74767f-8ec9-4449-881e-440eeae3cf76_2133x1280.png 1272w, https://substackcdn.com/image/fetch/$s_!85kO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f74767f-8ec9-4449-881e-440eeae3cf76_2133x1280.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/t4VLfBoncm3jqGpbmyDr?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><p>Common load-balancing algorithms include:</p><ul><li><p>Round Robin</p></li><li><p>Least Connections</p></li><li><p>IP Hash</p></li></ul><h2><strong>4 - Async Processing</strong></h2><p>When dealing with long-running tasks in a distributed system, it&#8217;s important to consider the user experience and the overall system responsiveness.</p><p>Implementing asynchronous processing is a powerful technique that allows the system to respond quickly to the user while performing further processing in the background.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Jufk!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2900375-1422-4684-958a-524fc49c4959_3259x1957.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Jufk!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2900375-1422-4684-958a-524fc49c4959_3259x1957.png 424w, https://substackcdn.com/image/fetch/$s_!Jufk!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2900375-1422-4684-958a-524fc49c4959_3259x1957.png 848w, https://substackcdn.com/image/fetch/$s_!Jufk!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2900375-1422-4684-958a-524fc49c4959_3259x1957.png 1272w, https://substackcdn.com/image/fetch/$s_!Jufk!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2900375-1422-4684-958a-524fc49c4959_3259x1957.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Jufk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2900375-1422-4684-958a-524fc49c4959_3259x1957.png" width="1456" height="874" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b2900375-1422-4684-958a-524fc49c4959_3259x1957.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:874,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:274299,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!Jufk!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2900375-1422-4684-958a-524fc49c4959_3259x1957.png 424w, https://substackcdn.com/image/fetch/$s_!Jufk!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2900375-1422-4684-958a-524fc49c4959_3259x1957.png 848w, https://substackcdn.com/image/fetch/$s_!Jufk!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2900375-1422-4684-958a-524fc49c4959_3259x1957.png 1272w, https://substackcdn.com/image/fetch/$s_!Jufk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2900375-1422-4684-958a-524fc49c4959_3259x1957.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/t4VLfBoncm3jqGpbmyDr?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><p>Here&#8217;s how it works:</p><ul><li><p>In an asynchronous processing model, when a user initiates a long-running task, such as generating a complex report or processing a large dataset, the system immediately acknowledges the request and returns a response to the user.</p></li><li><p>The response indicates that the request has been received and is being processed.</p></li><li><p>Behind the scenes, the system enqueues the task into a message queue or a task queue.</p></li><li><p>A separate background worker process or a pool of worker processes continuously monitors this queue, picking up tasks as they become available.</p></li><li><p>The worker process executes the long-running task asynchronously, without blocking the main application thread or impacting the system&#8217;s responsiveness.</p></li></ul><h2><strong>5 - Database Indexing</strong></h2><p>Databases can be a huge source of latency if not designed optimally.</p><p>To ensure optimal database performance and faster query processing, it is crucial to implement the right indexes and identify and refactor slow database queries.</p><p>Indexes play a vital role in improving the efficiency of database queries.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!BAeG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3eeb5f72-a0e2-498d-b62f-12066079fc5b_1604x966.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!BAeG!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3eeb5f72-a0e2-498d-b62f-12066079fc5b_1604x966.png 424w, https://substackcdn.com/image/fetch/$s_!BAeG!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3eeb5f72-a0e2-498d-b62f-12066079fc5b_1604x966.png 848w, https://substackcdn.com/image/fetch/$s_!BAeG!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3eeb5f72-a0e2-498d-b62f-12066079fc5b_1604x966.png 1272w, https://substackcdn.com/image/fetch/$s_!BAeG!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3eeb5f72-a0e2-498d-b62f-12066079fc5b_1604x966.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!BAeG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3eeb5f72-a0e2-498d-b62f-12066079fc5b_1604x966.png" width="1456" height="877" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3eeb5f72-a0e2-498d-b62f-12066079fc5b_1604x966.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:877,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:159166,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!BAeG!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3eeb5f72-a0e2-498d-b62f-12066079fc5b_1604x966.png 424w, https://substackcdn.com/image/fetch/$s_!BAeG!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3eeb5f72-a0e2-498d-b62f-12066079fc5b_1604x966.png 848w, https://substackcdn.com/image/fetch/$s_!BAeG!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3eeb5f72-a0e2-498d-b62f-12066079fc5b_1604x966.png 1272w, https://substackcdn.com/image/fetch/$s_!BAeG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3eeb5f72-a0e2-498d-b62f-12066079fc5b_1604x966.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/DrwhlCozKb9lf29Me4w7?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><p>By creating appropriate indexes on frequently accessed columns or combinations of columns, the database can quickly locate and retrieve the required data without scanning the entire table. This reduces the time and resources needed to process queries, especially for large datasets.</p><h2><strong>6 - Data Compression</strong></h2><p>When transmitting data over a network, especially in distributed systems, it&#8217;s important to consider the size of the data being sent.</p><p>Larger data payloads can consume more network bandwidth, increase latency, and impact overall system performance.</p><p>To mitigate these issues, a common technique is to compress the data before sending it over the network.</p><p>Data compression involves reducing the size of the data by applying compression algorithms that remove redundancy and represent the data more efficiently. There are several benefits to compressing the data:</p><ul><li><p>Reduced bandwidth usage</p></li><li><p>Improved latency</p></li><li><p>Efficient resource utilization</p></li><li><p>Cost savings</p></li></ul><h2><strong>7 - Precaching</strong></h2><p>Pre-caching is a technique used to proactively cache data in anticipation of future requests.</p><p>The idea is to cache in advance data that has a high probability of being accessed so that you can serve it faster when requested by a user.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!tU3c!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F734da7be-949f-4a8e-b88f-69e07482e6b6_4943x2814.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!tU3c!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F734da7be-949f-4a8e-b88f-69e07482e6b6_4943x2814.png 424w, https://substackcdn.com/image/fetch/$s_!tU3c!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F734da7be-949f-4a8e-b88f-69e07482e6b6_4943x2814.png 848w, https://substackcdn.com/image/fetch/$s_!tU3c!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F734da7be-949f-4a8e-b88f-69e07482e6b6_4943x2814.png 1272w, https://substackcdn.com/image/fetch/$s_!tU3c!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F734da7be-949f-4a8e-b88f-69e07482e6b6_4943x2814.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!tU3c!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F734da7be-949f-4a8e-b88f-69e07482e6b6_4943x2814.png" width="1456" height="829" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/734da7be-949f-4a8e-b88f-69e07482e6b6_4943x2814.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:829,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:648222,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!tU3c!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F734da7be-949f-4a8e-b88f-69e07482e6b6_4943x2814.png 424w, https://substackcdn.com/image/fetch/$s_!tU3c!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F734da7be-949f-4a8e-b88f-69e07482e6b6_4943x2814.png 848w, https://substackcdn.com/image/fetch/$s_!tU3c!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F734da7be-949f-4a8e-b88f-69e07482e6b6_4943x2814.png 1272w, https://substackcdn.com/image/fetch/$s_!tU3c!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F734da7be-949f-4a8e-b88f-69e07482e6b6_4943x2814.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/t4VLfBoncm3jqGpbmyDr?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><h2><strong>8 - Use Keep-Alive Connections</strong></h2><p>The TCP handshake is a critical process that establishes a reliable connection between two endpoints before data transmission can begin.</p><p>However, this process can be costly in terms of network latency and resource consumption, as it involves multiple round trips between the client and the server.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!3OJt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a6d576b-f973-4826-92ec-e322bb3c434b_4288x2615.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!3OJt!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a6d576b-f973-4826-92ec-e322bb3c434b_4288x2615.png 424w, https://substackcdn.com/image/fetch/$s_!3OJt!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a6d576b-f973-4826-92ec-e322bb3c434b_4288x2615.png 848w, https://substackcdn.com/image/fetch/$s_!3OJt!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a6d576b-f973-4826-92ec-e322bb3c434b_4288x2615.png 1272w, https://substackcdn.com/image/fetch/$s_!3OJt!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a6d576b-f973-4826-92ec-e322bb3c434b_4288x2615.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!3OJt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a6d576b-f973-4826-92ec-e322bb3c434b_4288x2615.png" width="1456" height="888" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5a6d576b-f973-4826-92ec-e322bb3c434b_4288x2615.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:888,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:390809,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!3OJt!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a6d576b-f973-4826-92ec-e322bb3c434b_4288x2615.png 424w, https://substackcdn.com/image/fetch/$s_!3OJt!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a6d576b-f973-4826-92ec-e322bb3c434b_4288x2615.png 848w, https://substackcdn.com/image/fetch/$s_!3OJt!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a6d576b-f973-4826-92ec-e322bb3c434b_4288x2615.png 1272w, https://substackcdn.com/image/fetch/$s_!3OJt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5a6d576b-f973-4826-92ec-e322bb3c434b_4288x2615.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/t4VLfBoncm3jqGpbmyDr?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><p>To optimize the overhead associated with establishing new TCP connections, it is recommended to reuse existing connections whenever possible.</p><p>Connection reuse, also known as connection pooling, is a technique that allows multiple requests to be sent over the same TCP connection, reducing the need to establish new connections for each request.</p><p>&#128073; <strong>So - which other low-latency techniques have you used?</strong></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/top-strategies-to-reduce-latency/comments&quot;,&quot;text&quot;:&quot;Leave a comment&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/top-strategies-to-reduce-latency/comments"><span>Leave a comment</span></a></p><div><hr></div><p><strong>That&#8217;s it for today! &#9728;&#65039;</strong></p><p>Enjoyed this issue of the newsletter?</p><p>Share with your friends and colleagues.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/top-strategies-to-reduce-latency?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/top-strategies-to-reduce-latency?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p><em><strong>See you later with another edition &#8212; Saurabh</strong></em></p>]]></content:encoded></item><item><title><![CDATA[Sticky Sessions or Not?]]></title><description><![CDATA[How to decide?]]></description><link>https://newsletter.systemdesigncodex.com/p/sticky-sessions-or-not</link><guid isPermaLink="false">https://newsletter.systemdesigncodex.com/p/sticky-sessions-or-not</guid><dc:creator><![CDATA[Saurabh Dashora]]></dc:creator><pubDate>Tue, 13 Jan 2026 08:43:21 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!4U4U!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fb5105d-039e-40e1-ad76-ab0302bde9dc_4076x2345.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Before trying to answer this question, let&#8217;s understand the role of sticky sessions.</p><p>Sticky sessions make sure that all of a user&#8217;s requests are consistently directed to the same server instance for the duration of their session.</p><p>Here&#8217;s what it looks like:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!4U4U!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fb5105d-039e-40e1-ad76-ab0302bde9dc_4076x2345.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!4U4U!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fb5105d-039e-40e1-ad76-ab0302bde9dc_4076x2345.png 424w, https://substackcdn.com/image/fetch/$s_!4U4U!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fb5105d-039e-40e1-ad76-ab0302bde9dc_4076x2345.png 848w, https://substackcdn.com/image/fetch/$s_!4U4U!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fb5105d-039e-40e1-ad76-ab0302bde9dc_4076x2345.png 1272w, https://substackcdn.com/image/fetch/$s_!4U4U!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fb5105d-039e-40e1-ad76-ab0302bde9dc_4076x2345.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!4U4U!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fb5105d-039e-40e1-ad76-ab0302bde9dc_4076x2345.png" width="1456" height="838" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0fb5105d-039e-40e1-ad76-ab0302bde9dc_4076x2345.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:838,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:647317,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!4U4U!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fb5105d-039e-40e1-ad76-ab0302bde9dc_4076x2345.png 424w, https://substackcdn.com/image/fetch/$s_!4U4U!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fb5105d-039e-40e1-ad76-ab0302bde9dc_4076x2345.png 848w, https://substackcdn.com/image/fetch/$s_!4U4U!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fb5105d-039e-40e1-ad76-ab0302bde9dc_4076x2345.png 1272w, https://substackcdn.com/image/fetch/$s_!4U4U!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fb5105d-039e-40e1-ad76-ab0302bde9dc_4076x2345.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/O4g2Zp1BTHHY7nmUXoE5?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><p>But why is this important?</p><p>It&#8217;s important when the server instance physically stores some user-specific information without which the user&#8217;s experience gets impacted.</p><p>Here are a few examples:</p><ul><li><p><strong>Session Objects: </strong>When a user establishes a connection with the server, the server may create a session object specific to that client-server pair. This object is stored in the server&#8217;s memory and contains information about the session.</p></li><li><p><strong>Shopping Cart Details: </strong>In an e-commerce application, a user&#8217;s shopping cart details may be stored on a specific server instance.</p></li><li><p><strong>File Processing: </strong>Consider a scenario where a user initiates a file processing task on a server. The server instance handling the task may need to maintain the state of the processing and provide updates to the user.</p></li></ul><p>In all of these examples, only with sticky sessions, subsequent requests from the same user are directed to the same server instance so that the server can access and maintain the session object.</p><p>There are a few advantages to this approach:</p><ul><li><p>The user-specific data stored on a server remains consistent throughout the user&#8217;s session.</p></li><li><p>You get better performance by directing a user&#8217;s requests to the same server instance.</p></li><li><p>There&#8217;s also a cost advantage with sticky sessions where you don&#8217;t have to invest in external storage for session information.</p></li></ul><h2><strong>Downsides of Sticky Sessions</strong></h2><p>Despite their advantages, however, sticky sessions have a couple of downsides:</p><ul><li><p><strong>Sticky sessions will stick.</strong> Hence the name. They defeat the purpose of a load balancer because multiple users might get stuck to one instance while other instances sit idle and don&#8217;t receive any requests. Ultimately, this will create scalability challenges.</p></li><li><p><strong>The session is gone if the server goes down</strong>. Since the session is usually stored in memory, it&#8217;s tied to the life of the server instance. Of course, the user is redirected to another instance but the session information is gone. In practical terms, this might mean that the user needs to log in once more or stuff their shopping cart from scratch again. Not a great user experience, in my view.</p></li></ul><h2><strong>Where Are Sticky Sessions Useful?</strong></h2><p>Sticky sessions can be useful in a couple of scenarios:</p><ul><li><p>WebSockets rely on persistent sticky connections.</p></li><li><p>A basic implementation of the file-processing example where a user needs to check the status of a file being processed. Even there, for more advanced scenarios, you might want to store the status information for file processing in a separate store.</p></li></ul><h2><strong>Alternative to Sticky Sessions</strong></h2><p><strong>In my view, instead of relying on sticky sessions, it&#8217;s often better to store session information in a distributed session store.</strong></p><p>A distributed session store is a separate, centralized storage system that holds session data. Popular options for distributed session stores include Redis and DynamoDB.</p><p>The diagram below shows this setup:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!fmRS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5d526de4-4efd-46f3-8acf-abbd6fa8abe5_4236x2405.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!fmRS!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5d526de4-4efd-46f3-8acf-abbd6fa8abe5_4236x2405.png 424w, https://substackcdn.com/image/fetch/$s_!fmRS!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5d526de4-4efd-46f3-8acf-abbd6fa8abe5_4236x2405.png 848w, https://substackcdn.com/image/fetch/$s_!fmRS!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5d526de4-4efd-46f3-8acf-abbd6fa8abe5_4236x2405.png 1272w, https://substackcdn.com/image/fetch/$s_!fmRS!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5d526de4-4efd-46f3-8acf-abbd6fa8abe5_4236x2405.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!fmRS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5d526de4-4efd-46f3-8acf-abbd6fa8abe5_4236x2405.png" width="1456" height="827" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5d526de4-4efd-46f3-8acf-abbd6fa8abe5_4236x2405.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:827,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:714046,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!fmRS!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5d526de4-4efd-46f3-8acf-abbd6fa8abe5_4236x2405.png 424w, https://substackcdn.com/image/fetch/$s_!fmRS!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5d526de4-4efd-46f3-8acf-abbd6fa8abe5_4236x2405.png 848w, https://substackcdn.com/image/fetch/$s_!fmRS!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5d526de4-4efd-46f3-8acf-abbd6fa8abe5_4236x2405.png 1272w, https://substackcdn.com/image/fetch/$s_!fmRS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5d526de4-4efd-46f3-8acf-abbd6fa8abe5_4236x2405.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/O4g2Zp1BTHHY7nmUXoE5?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><p>Here&#8217;s how it works:</p><ul><li><p>When a user&#8217;s request arrives at the load balancer, it can distribute the traffic evenly across the available server instances. No need for sticky sessions.</p></li><li><p>The server instance that receives the request retrieves the relevant session information from the distributed session store.</p></li><li><p>After processing the request, the server instance updates the session information in the distributed store. This ensures that the latest session data is persisted.</p></li><li><p>Subsequent requests from the same user can be routed to any available server instance, as the latest session information can be retrieved from the distributed store.</p></li></ul><h2><strong>Advantages of A Distributed Session Store</strong></h2><p>The key advantages of using a distributed session store are as follows:</p><ul><li><p><strong>Fault Tolerance: </strong>If a particular server instance goes down, the session information is not lost.</p></li><li><p><strong>Scalability: </strong>As the system scales and more server instances are added, the load balancer can distribute traffic evenly without being constrained by sticky sessions. This is good for resource utilization and performance. Also, it helps make your application layer stateless.</p></li><li><p><strong>Flexibility: </strong>With session information in a distributed store, you have more flexibility in terms of server maintenance and updates. Server instances can be taken offline for maintenance without disrupting the user experience.</p></li></ul><p><strong>So - what do you think about the use of sticky sessions? Do you still prefer using them?</strong></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/sticky-sessions-or-not/comments&quot;,&quot;text&quot;:&quot;Leave a comment&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/sticky-sessions-or-not/comments"><span>Leave a comment</span></a></p><div><hr></div><p><strong>That&#8217;s it for today! &#9728;&#65039;</strong></p><p>Enjoyed this issue of the newsletter?</p><p>Share with your friends and colleagues.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/sticky-sessions-or-not?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/sticky-sessions-or-not?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p><em><strong>See you later with another edition &#8212; Saurabh</strong></em></p>]]></content:encoded></item><item><title><![CDATA[Consistent Hashing in a Nutshell]]></title><description><![CDATA[How it works?]]></description><link>https://newsletter.systemdesigncodex.com/p/consistent-hashing-in-a-nutshell</link><guid isPermaLink="false">https://newsletter.systemdesigncodex.com/p/consistent-hashing-in-a-nutshell</guid><dc:creator><![CDATA[Saurabh Dashora]]></dc:creator><pubDate>Tue, 06 Jan 2026 08:40:29 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!Bffx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9b509e0-5491-488e-8902-0265fba57b52_2876x1595.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>The concept of Consistent Hashing often comes up in interviews. However, I&#8217;ve seen people struggle while trying to explain it.</p><p>In today&#8217;s post, we&#8217;ll look at the process of consistent hashing in a step-by-step manner so that it becomes easier to understand and explain.</p><blockquote><p><em><strong>Consistent Hashing is a technique used for distributing keys uniformly across a cluster of nodes.</strong></em></p></blockquote><p>The primary focus behind consistent hashing is to minimize the number of keys that need to be moved around when we add or remove a node from the cluster.</p><p>The below steps demonstrate how consistent hashing works:</p><h2><strong>STEP 1</strong></h2><p>The keys are hashed using a hash function.</p><p>The output range of these key values is treated as a fixed circular space or ring. For example, in the diagram below, K1, K2, K3, and K15 are the positions of the keys on the hash ring.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!z3OU!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fa3cdb1-33be-4bf2-a700-d5157e82ced4_2876x1595.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!z3OU!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fa3cdb1-33be-4bf2-a700-d5157e82ced4_2876x1595.png 424w, https://substackcdn.com/image/fetch/$s_!z3OU!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fa3cdb1-33be-4bf2-a700-d5157e82ced4_2876x1595.png 848w, https://substackcdn.com/image/fetch/$s_!z3OU!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fa3cdb1-33be-4bf2-a700-d5157e82ced4_2876x1595.png 1272w, https://substackcdn.com/image/fetch/$s_!z3OU!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fa3cdb1-33be-4bf2-a700-d5157e82ced4_2876x1595.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!z3OU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fa3cdb1-33be-4bf2-a700-d5157e82ced4_2876x1595.png" width="1456" height="807" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6fa3cdb1-33be-4bf2-a700-d5157e82ced4_2876x1595.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:807,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:278644,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!z3OU!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fa3cdb1-33be-4bf2-a700-d5157e82ced4_2876x1595.png 424w, https://substackcdn.com/image/fetch/$s_!z3OU!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fa3cdb1-33be-4bf2-a700-d5157e82ced4_2876x1595.png 848w, https://substackcdn.com/image/fetch/$s_!z3OU!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fa3cdb1-33be-4bf2-a700-d5157e82ced4_2876x1595.png 1272w, https://substackcdn.com/image/fetch/$s_!z3OU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fa3cdb1-33be-4bf2-a700-d5157e82ced4_2876x1595.png 1456w" sizes="100vw" loading="lazy" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/asPRtUIyi2L0QdNAIEeq?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><h2><strong>STEP 2</strong></h2><p>Next, the servers or nodes are also hashed using the IP address or the domain name as input.</p><p>We use the same hashing function to determine their respective positions on the ring.</p><p>See the below diagram:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!4Hbv!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa143d5bd-f758-410f-9b4b-7d8bda651fe7_2876x1595.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!4Hbv!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa143d5bd-f758-410f-9b4b-7d8bda651fe7_2876x1595.png 424w, https://substackcdn.com/image/fetch/$s_!4Hbv!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa143d5bd-f758-410f-9b4b-7d8bda651fe7_2876x1595.png 848w, https://substackcdn.com/image/fetch/$s_!4Hbv!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa143d5bd-f758-410f-9b4b-7d8bda651fe7_2876x1595.png 1272w, https://substackcdn.com/image/fetch/$s_!4Hbv!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa143d5bd-f758-410f-9b4b-7d8bda651fe7_2876x1595.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!4Hbv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa143d5bd-f758-410f-9b4b-7d8bda651fe7_2876x1595.png" width="1456" height="807" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a143d5bd-f758-410f-9b4b-7d8bda651fe7_2876x1595.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:807,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:254309,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!4Hbv!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa143d5bd-f758-410f-9b4b-7d8bda651fe7_2876x1595.png 424w, https://substackcdn.com/image/fetch/$s_!4Hbv!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa143d5bd-f758-410f-9b4b-7d8bda651fe7_2876x1595.png 848w, https://substackcdn.com/image/fetch/$s_!4Hbv!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa143d5bd-f758-410f-9b4b-7d8bda651fe7_2876x1595.png 1272w, https://substackcdn.com/image/fetch/$s_!4Hbv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa143d5bd-f758-410f-9b4b-7d8bda651fe7_2876x1595.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/asPRtUIyi2L0QdNAIEeq?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><h2><strong>STEP 3</strong></h2><p>Lastly, for every key, we traverse the ring in a clockwise direction starting from the position of the key.</p><p>Once a node is found, we store the key on that node.</p><p>See the below diagram:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Bffx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9b509e0-5491-488e-8902-0265fba57b52_2876x1595.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Bffx!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9b509e0-5491-488e-8902-0265fba57b52_2876x1595.png 424w, https://substackcdn.com/image/fetch/$s_!Bffx!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9b509e0-5491-488e-8902-0265fba57b52_2876x1595.png 848w, https://substackcdn.com/image/fetch/$s_!Bffx!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9b509e0-5491-488e-8902-0265fba57b52_2876x1595.png 1272w, https://substackcdn.com/image/fetch/$s_!Bffx!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9b509e0-5491-488e-8902-0265fba57b52_2876x1595.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Bffx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9b509e0-5491-488e-8902-0265fba57b52_2876x1595.png" width="1456" height="807" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f9b509e0-5491-488e-8902-0265fba57b52_2876x1595.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:807,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:242079,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!Bffx!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9b509e0-5491-488e-8902-0265fba57b52_2876x1595.png 424w, https://substackcdn.com/image/fetch/$s_!Bffx!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9b509e0-5491-488e-8902-0265fba57b52_2876x1595.png 848w, https://substackcdn.com/image/fetch/$s_!Bffx!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9b509e0-5491-488e-8902-0265fba57b52_2876x1595.png 1272w, https://substackcdn.com/image/fetch/$s_!Bffx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9b509e0-5491-488e-8902-0265fba57b52_2876x1595.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/asPRtUIyi2L0QdNAIEeq?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><h2><strong>Virtual Nodes in Consistent Hashing</strong></h2><p>Virtual nodes (often abbreviated as &#8220;v-nodes&#8221;) are a technique used in consistent hashing to address load balancing and uneven data distribution.</p><p>Instead of mapping a single physical node to one position on the hash ring, each physical node is mapped to multiple positions, creating <em>&#8220;virtual nodes&#8221;</em>. These positions are determined by applying a hash function multiple times with different input variations (e.g., appending a unique identifier like NodeID-1, NodeID-2, etc.).</p><p>For example, each physical node has 3 virtual nodes. After hashing, the virtual nodes might be distributed on the ring as follows:</p><ul><li><p><strong>Node A:</strong> Virtual nodes A1, A2, A3</p></li><li><p><strong>Node B:</strong> Virtual nodes B1, B2, B3</p></li><li><p><strong>Node C:</strong> Virtual nodes C1, C2, C3</p></li></ul><p>Keys (data) are hashed onto the ring and assigned to the first virtual node encountered while moving clockwise.</p><ul><li><p>Key K1 might fall near B2, so it is assigned to Node B.</p></li><li><p>Key K2 might fall near A3, so it is assigned to Node A.</p></li></ul><p>Since there are more positions (virtual nodes) on the ring, the data distribution is more evenly spread across physical nodes. Even if one key hashes poorly to a specific ring area, the effect is diluted across the multiple virtual nodes for each physical node.</p><p>On the downside, virtual nodes increase the size of the metadata the system needs to track, as multiple entries represent each physical node.</p><h2><strong>Advantages of Consistent Hashing</strong></h2><p>There are multiple advantages of consistent hashing:</p><ul><li><p><strong>Scalability</strong>: Adding or removing nodes in the system only affects a small portion of the data, rather than requiring all data to be reassigned. This makes it ideal for distributed systems with dynamic membership.</p></li><li><p><strong>Load Balancing</strong>: By using techniques like virtual nodes (assigning multiple positions for each physical node), consistent hashing ensures a more balanced data distribution across servers.</p></li><li><p><strong>Fault Tolerance</strong>: When a node fails, only its keys need to be redistributed to other nodes. The rest of the system continues to function smoothly.</p></li></ul><h2><strong>Disadvantages of Consistent Hashing</strong></h2><p>Consistent hashing also has some disadvantages that should be kept in mind:</p><ul><li><p><strong>Imbalance Without Virtual Nodes</strong>: Without virtual nodes, the natural distribution of keys can be skewed, leading to uneven loads across nodes.</p></li><li><p><strong>Dependency on Hash Function</strong>: The quality of the hash function directly affects the balance of the distribution. A poorly chosen hash function can lead to clustering or inefficiencies.</p></li></ul><h2><strong>Use Cases</strong></h2><p>Consistent hashing is widely used in various solutions. Here are a few important examples:</p><ul><li><p><strong>Distributed Databases</strong>: Ensures even data distribution and minimal disruption when nodes are added or removed (e.g., Amazon DynamoDB).</p></li><li><p><strong>Caching Systems</strong>: Balances requests across cache servers and minimizes cache misses after server changes (e.g., Memcached).</p></li><li><p><strong>Content Delivery Networks (CDNs)</strong>: Balances file storage and retrieval across geographically distributed servers.</p></li></ul><p>&#128073; <strong>So - have you used Consistent Hashing?</strong></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/consistent-hashing-in-a-nutshell/comments&quot;,&quot;text&quot;:&quot;Leave a comment&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/consistent-hashing-in-a-nutshell/comments"><span>Leave a comment</span></a></p><div><hr></div><p><strong>That&#8217;s it for today! &#9728;&#65039;</strong></p><p>Enjoyed this issue of the newsletter?</p><p>Share with your friends and colleagues.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/consistent-hashing-in-a-nutshell?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/consistent-hashing-in-a-nutshell?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p><em><strong>See you later with another edition &#8212; Saurabh</strong></em></p>]]></content:encoded></item><item><title><![CDATA[Polling or Webhooks]]></title><description><![CDATA[When to use what?]]></description><link>https://newsletter.systemdesigncodex.com/p/polling-or-webhooks</link><guid isPermaLink="false">https://newsletter.systemdesigncodex.com/p/polling-or-webhooks</guid><dc:creator><![CDATA[Saurabh Dashora]]></dc:creator><pubDate>Tue, 30 Dec 2025 11:44:43 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!8S-B!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3fb0bc9-e5d8-4305-9a1b-b75989173946_2101x1315.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>What is Polling? And what is a Webhook?</p><p>And how should you make the right choice in your project?</p><p>Let&#8217;s clarify it in today&#8217;s post.</p><h2><strong>Polling: A Resource-Intensive Approach</strong></h2><p>When ordering food at a restaurant, it would be impractical and embarrassing to constantly ask the waiter if your order is ready.</p><p>This scenario illustrates the inefficiency of polling, a method where a client repeatedly requests data from a server at predefined intervals.</p><p>Polling involves one service making repeated requests to another service to check for new data.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!8S-B!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3fb0bc9-e5d8-4305-9a1b-b75989173946_2101x1315.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!8S-B!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3fb0bc9-e5d8-4305-9a1b-b75989173946_2101x1315.png 424w, https://substackcdn.com/image/fetch/$s_!8S-B!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3fb0bc9-e5d8-4305-9a1b-b75989173946_2101x1315.png 848w, https://substackcdn.com/image/fetch/$s_!8S-B!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3fb0bc9-e5d8-4305-9a1b-b75989173946_2101x1315.png 1272w, https://substackcdn.com/image/fetch/$s_!8S-B!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3fb0bc9-e5d8-4305-9a1b-b75989173946_2101x1315.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!8S-B!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3fb0bc9-e5d8-4305-9a1b-b75989173946_2101x1315.png" width="1456" height="911" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c3fb0bc9-e5d8-4305-9a1b-b75989173946_2101x1315.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:911,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:166847,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!8S-B!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3fb0bc9-e5d8-4305-9a1b-b75989173946_2101x1315.png 424w, https://substackcdn.com/image/fetch/$s_!8S-B!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3fb0bc9-e5d8-4305-9a1b-b75989173946_2101x1315.png 848w, https://substackcdn.com/image/fetch/$s_!8S-B!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3fb0bc9-e5d8-4305-9a1b-b75989173946_2101x1315.png 1272w, https://substackcdn.com/image/fetch/$s_!8S-B!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3fb0bc9-e5d8-4305-9a1b-b75989173946_2101x1315.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/cw0sa4jBfuFBAdIf2ZLj?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><p>Here are the key characteristics of polling:</p><ul><li><p><strong>Repeated Requests</strong>: In polling, the client sends requests to the server at regular intervals, asking if there is any new data available. This approach is akin to constantly asking, &#8220;Do you have something new for me?&#8221; even when there might be no updates.</p></li><li><p><strong>Resource-Intensive</strong>: Polling is resource-intensive and inefficient. It consumes network bandwidth and server resources, even when there are no updates available.</p></li><li><p><strong>Missed Real-Time Updates</strong>: Polling can lead to missed real-time updates. Since the client checks for updates at predefined intervals, it may not receive notifications immediately when data becomes available.</p></li></ul><h2><strong>Webhooks: A Notification-Based Approach</strong></h2><p>Webhooks offer a more efficient and real-time alternative to polling. Here&#8217;s how webhooks work:</p><ol><li><p><strong>Callback URL</strong>: With webhooks, you set up a callback URL that one system uses to notify another system when new data is available. This approach is like having a built-in notification system where the server says, &#8220;I&#8217;ll let you know when something happens.&#8221;</p></li><li><p><strong>Push-Based Data Delivery</strong>: Webhooks push data to the recipient service as soon as it becomes available, ensuring real-time updates. This makes webhooks ideal for scenarios where timely notifications are crucial.</p></li><li><p><strong>Efficiency and Real-Time Updates</strong>: Webhooks are more efficient than polling because they eliminate the need for repeated requests. They provide real-time updates, making them perfect for applications like payment notifications, CI/CD platforms, and other services that require immediate updates.</p></li></ol><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!bMkx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7546cad1-e2f7-48a0-8f75-1ec1fa524fdf_2101x1315.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!bMkx!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7546cad1-e2f7-48a0-8f75-1ec1fa524fdf_2101x1315.png 424w, https://substackcdn.com/image/fetch/$s_!bMkx!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7546cad1-e2f7-48a0-8f75-1ec1fa524fdf_2101x1315.png 848w, https://substackcdn.com/image/fetch/$s_!bMkx!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7546cad1-e2f7-48a0-8f75-1ec1fa524fdf_2101x1315.png 1272w, https://substackcdn.com/image/fetch/$s_!bMkx!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7546cad1-e2f7-48a0-8f75-1ec1fa524fdf_2101x1315.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!bMkx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7546cad1-e2f7-48a0-8f75-1ec1fa524fdf_2101x1315.png" width="1456" height="911" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7546cad1-e2f7-48a0-8f75-1ec1fa524fdf_2101x1315.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:911,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:160788,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!bMkx!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7546cad1-e2f7-48a0-8f75-1ec1fa524fdf_2101x1315.png 424w, https://substackcdn.com/image/fetch/$s_!bMkx!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7546cad1-e2f7-48a0-8f75-1ec1fa524fdf_2101x1315.png 848w, https://substackcdn.com/image/fetch/$s_!bMkx!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7546cad1-e2f7-48a0-8f75-1ec1fa524fdf_2101x1315.png 1272w, https://substackcdn.com/image/fetch/$s_!bMkx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7546cad1-e2f7-48a0-8f75-1ec1fa524fdf_2101x1315.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/cw0sa4jBfuFBAdIf2ZLj?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><h2><strong>When to Use Polling and Webhooks</strong></h2><p>Each approach has its use cases:</p><ol><li><p><strong>Polling</strong>:</p><ul><li><p><strong>Frequent Data Updates</strong>: Polling is better when you don&#8217;t need real-time data updates and the data is frequently updated. Sending webhooks for every event can be resource-intensive. For example, a social media app that wants to report on its user base might be overwhelmed with webhooks if many users sign up in quick succession.</p></li><li><p><strong>Flexibility</strong>: You can customize the sync frequency based on how often you need updated data.</p></li></ul></li><li><p><strong>Webhooks</strong>:</p><ul><li><p><strong>Real-Time Updates</strong>: Webhooks are perfect for scenarios where real-time updates matter. Examples include payment notifications, chat applications, and any service that requires immediate notifications.</p></li><li><p><strong>Efficient Resource Utilization</strong>: Webhooks are more efficient in terms of resource utilization compared to polling. They ensure that data is delivered in real time without the need for repeated requests.</p></li></ul></li></ol><p><strong>So - have you used Polling or Webhooks in your application?</strong></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/polling-or-webhooks/comments&quot;,&quot;text&quot;:&quot;Leave a comment&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/polling-or-webhooks/comments"><span>Leave a comment</span></a></p><div><hr></div><h1><strong>Shoutout</strong></h1><p>Here are some interesting articles I&#8217;ve read recently:</p><ul><li><p><a href="https://strategizeyourcareer.com/p/how-i-keep-advancing-my-career-without-neglecting-my-life?utm_source=activity_item">Read this if you want a successful year at work in 2026</a> by <span class="mention-wrap" data-attrs="{&quot;name&quot;:&quot;Fran Soto&quot;,&quot;id&quot;:170998285,&quot;type&quot;:&quot;user&quot;,&quot;url&quot;:null,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/10f90fdb-11ac-48b4-8f51-6a59e07763d2_1149x1149.png&quot;,&quot;uuid&quot;:&quot;4dc6d02c-d691-4b83-a837-103d5aedeaaf&quot;}" data-component-name="MentionToDOM"></span> </p></li><li><p><a href="https://open.substack.com/pub/akoskm/p/how-to-ship-fast-without-creating?utm_campaign=post-expanded-share&amp;utm_medium=web">How to Ship Fast Without Creating a Mess</a> by <span class="mention-wrap" data-attrs="{&quot;name&quot;:&quot;Akos Komuves&quot;,&quot;id&quot;:50223467,&quot;type&quot;:&quot;user&quot;,&quot;url&quot;:null,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f76bbbff-e0c9-4b43-81a4-38d2bf31c5cb_1000x1000.jpeg&quot;,&quot;uuid&quot;:&quot;98968497-c315-47f6-b367-a7822811b729&quot;}" data-component-name="MentionToDOM"></span> </p></li><li><p><a href="https://thetshaped.dev/p/the-systematic-ai-code-review-workflow-plan-generate-validate">The Systematic AI Code Review Workflow: Plan, Generate, Validate</a> by <span class="mention-wrap" data-attrs="{&quot;name&quot;:&quot;Petar Ivanov&quot;,&quot;id&quot;:10269058,&quot;type&quot;:&quot;user&quot;,&quot;url&quot;:null,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b236a7ab-735e-49d2-bbe8-98b1f901b169_500x500.jpeg&quot;,&quot;uuid&quot;:&quot;d1790e23-a5ac-4117-a333-4a79603c65af&quot;}" data-component-name="MentionToDOM"></span> </p></li></ul><div><hr></div><p><strong>That&#8217;s it for today! &#9728;&#65039;</strong></p><p>Enjoyed this issue of the newsletter?</p><p>Share with your friends and colleagues.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/polling-or-webhooks?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/polling-or-webhooks?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p><em><strong>See you later with another edition &#8212; Saurabh</strong></em></p>]]></content:encoded></item><item><title><![CDATA[Multiple Places Where Caching Exists]]></title><description><![CDATA[Caching is everywhere]]></description><link>https://newsletter.systemdesigncodex.com/p/multiple-places-where-caching-exists</link><guid isPermaLink="false">https://newsletter.systemdesigncodex.com/p/multiple-places-where-caching-exists</guid><dc:creator><![CDATA[Saurabh Dashora]]></dc:creator><pubDate>Tue, 23 Dec 2025 09:17:41 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!gvWL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F937fb03b-15f4-4a8a-933c-f0ff1472489a_1552x1850.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Caching is everywhere.</p><p>It&#8217;s one of the few techniques in software development that can be applied at every layer of your application.</p><p>Things start right from the front-end layer and end at the database layer. The only thing that changes is the overall usage pattern of the cache.</p><p>The diagram below shows the utilization of cache across a typical application stack.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!gvWL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F937fb03b-15f4-4a8a-933c-f0ff1472489a_1552x1850.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!gvWL!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F937fb03b-15f4-4a8a-933c-f0ff1472489a_1552x1850.png 424w, https://substackcdn.com/image/fetch/$s_!gvWL!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F937fb03b-15f4-4a8a-933c-f0ff1472489a_1552x1850.png 848w, https://substackcdn.com/image/fetch/$s_!gvWL!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F937fb03b-15f4-4a8a-933c-f0ff1472489a_1552x1850.png 1272w, https://substackcdn.com/image/fetch/$s_!gvWL!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F937fb03b-15f4-4a8a-933c-f0ff1472489a_1552x1850.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!gvWL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F937fb03b-15f4-4a8a-933c-f0ff1472489a_1552x1850.png" width="1456" height="1736" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/937fb03b-15f4-4a8a-933c-f0ff1472489a_1552x1850.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1736,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:293358,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!gvWL!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F937fb03b-15f4-4a8a-933c-f0ff1472489a_1552x1850.png 424w, https://substackcdn.com/image/fetch/$s_!gvWL!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F937fb03b-15f4-4a8a-933c-f0ff1472489a_1552x1850.png 848w, https://substackcdn.com/image/fetch/$s_!gvWL!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F937fb03b-15f4-4a8a-933c-f0ff1472489a_1552x1850.png 1272w, https://substackcdn.com/image/fetch/$s_!gvWL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F937fb03b-15f4-4a8a-933c-f0ff1472489a_1552x1850.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/sYuQXLwa7lkbCJpinIxf?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><p>Let&#8217;s look at each stage in a little more detail.</p><h2><strong>1 - Front End App</strong></h2><p>Browsers cache stuff all the time - HTTP responses, asset files, HTML pages, and so on.</p><p>Developers can set the caching directives in response headers to control the caching behavior for specific assets.</p><h2><strong>2 - Content Delivery Networks</strong></h2><p>CDNs can cache static content like images, stylesheets, and JS files.</p><p>Their advantage is caching stuff closer to the users, reducing latency in the process.</p><h2><strong>3 - Load Balancers</strong></h2><p>Some load balancers can also cache frequently accessed data.</p><p>Responses can be served without calling the backend server. This improves the response times and also reduces the load on the server or database.</p><h2><strong>4 - Service Instance Cache</strong></h2><p>Service instances can employ their caching solutions to boost performance.</p><p>This can be in the form of in-memory caches that are checked before fetching from the database or even the distributed cache.</p><h2><strong>5 - Distributed Cache</strong></h2><p>A more robust caching solution can use distributed caches like Redis.</p><p>They help with faster reads and writes than going to a traditional relational database. Also, you can scale the cache across multiple nodes for greater resilience.</p><h2><strong>6 - Full-text Search Tools</strong></h2><p>Searching through tons of text information is a time-consuming task.</p><p>Tools like ElasticSearch help index the data for faster text search, effectively acting as a cache.</p><h2><strong>7 - Databases</strong></h2><p>You might think that databases always fetch from the disk.</p><p>But databases also use special caching mechanisms. For example, a Bufferpool is like a cache within the database that holds data pages to support faster reads.</p><p>Also, Materialized Views store results of pre-computed results of expensive queries for faster access</p><p>Lastly, many new-age databases have their built-in cache solutions.</p><p><strong>So - for how many layers have you used caching?</strong></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/multiple-places-where-caching-exists/comments&quot;,&quot;text&quot;:&quot;Leave a comment&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/multiple-places-where-caching-exists/comments"><span>Leave a comment</span></a></p><div><hr></div><p><strong>That&#8217;s it for today! &#9728;&#65039;</strong></p><p>Enjoyed this issue of the newsletter?</p><p>Share with your friends and colleagues.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/multiple-places-where-caching-exists?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/multiple-places-where-caching-exists?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p><em><strong>See you later with another edition &#8212; Saurabh</strong></em></p>]]></content:encoded></item><item><title><![CDATA[Database Scaling and Performance Tips]]></title><description><![CDATA[Strategies you must know]]></description><link>https://newsletter.systemdesigncodex.com/p/database-scaling-and-performance</link><guid isPermaLink="false">https://newsletter.systemdesigncodex.com/p/database-scaling-and-performance</guid><dc:creator><![CDATA[Saurabh Dashora]]></dc:creator><pubDate>Tue, 16 Dec 2025 08:47:15 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!2yKp!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e375e70-283d-433f-870f-4261675180b5_1929x1215.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Data storage is probably the most important capability for an application.</p><p>While computing has many applications even when storage is not involved, it&#8217;s hard to imagine the utility of software systems for a majority of normal users in the absence of storage systems like databases.</p><p>Naturally, this means that the <strong>performance</strong> and <strong>scalability</strong> of databases play a big role in shaping an application&#8217;s user experience.</p><p>There are so many factors that can impact the performance of a database. Some important ones are as follows:</p><ul><li><p><strong>Item Size: </strong>The average payload size of an item stored in the database determines whether the workload is CPU-bound or storage-bound.</p></li><li><p><strong>Item Type:</strong> The type of item directly impacts the kind of compression that is possible. For example, if you&#8217;re storing text, you can take advantage of a high compression ratio. Not so much when you store images, videos, or encrypted data.</p></li><li><p><strong>Total Dataset Size:</strong> This one directly impacts the infrastructure options and whether you&#8217;d need to go for replication and sharding.</p></li><li><p><strong>Throughput and Latency Requirements: </strong>Just saying &#8220;high throughput&#8221; is not enough. It&#8217;s critical to know the target throughput for choosing the optimal database type and infrastructure.</p></li></ul><p>Having said that, databases also evolve along with your application. From time to time, you may need to come up with new strategies to extract the best performance and scalability out of your database.</p><p>Let&#8217;s look at a few tried and tested strategies that can boost the performance of the database as well as help you scale it better.</p><h2><strong>1 - Indexing</strong></h2><p>In databases, an index acts as a &#8220;table of contents&#8221; for your data.</p><p>It allows the database to quickly locate and retrieve specific information without scanning through every single record. Without an index, the database would have to scan the entire table to find matching records.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!b9bR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F200ed6f4-c5e2-45cb-9eac-8ec96dde382f_1604x966.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!b9bR!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F200ed6f4-c5e2-45cb-9eac-8ec96dde382f_1604x966.png 424w, https://substackcdn.com/image/fetch/$s_!b9bR!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F200ed6f4-c5e2-45cb-9eac-8ec96dde382f_1604x966.png 848w, https://substackcdn.com/image/fetch/$s_!b9bR!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F200ed6f4-c5e2-45cb-9eac-8ec96dde382f_1604x966.png 1272w, https://substackcdn.com/image/fetch/$s_!b9bR!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F200ed6f4-c5e2-45cb-9eac-8ec96dde382f_1604x966.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!b9bR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F200ed6f4-c5e2-45cb-9eac-8ec96dde382f_1604x966.png" width="1456" height="877" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/200ed6f4-c5e2-45cb-9eac-8ec96dde382f_1604x966.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:877,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:159694,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!b9bR!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F200ed6f4-c5e2-45cb-9eac-8ec96dde382f_1604x966.png 424w, https://substackcdn.com/image/fetch/$s_!b9bR!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F200ed6f4-c5e2-45cb-9eac-8ec96dde382f_1604x966.png 848w, https://substackcdn.com/image/fetch/$s_!b9bR!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F200ed6f4-c5e2-45cb-9eac-8ec96dde382f_1604x966.png 1272w, https://substackcdn.com/image/fetch/$s_!b9bR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F200ed6f4-c5e2-45cb-9eac-8ec96dde382f_1604x966.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/2Q0XVsHuYTnCNTrNl9Gf?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><p>For example, if you have a &#8220;Customers&#8221; table with columns like &#8220;ID&#8221;, &#8220;Name&#8221;, &#8220;Email&#8221;, and &#8220;City&#8221;. In case you often search for customers by email, creating an index on the &#8220;Email&#8221; column can make a huge difference.</p><p>Key benefits of indexing are:</p><ul><li><p>Faster queries</p></li><li><p>Reduced resource usage</p></li><li><p>Increased concurrency</p></li></ul><p>The trade-offs are as follows:</p><ul><li><p>Extra disk space for each indexed column</p></li><li><p>More work during write operations to update the index.</p></li></ul><h2><strong>2 - Materialized Views</strong></h2><p>A materialized view is like a snapshot of a query result, stored separately from the original data.</p><p>It&#8217;s derived from one or more tables or views and is maintained independently. Think of it as a pre-calculated summary that you can quickly access whenever you need it.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!GXIS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a04d7c6-f7a8-444d-b495-992f90f89aa1_1929x1277.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!GXIS!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a04d7c6-f7a8-444d-b495-992f90f89aa1_1929x1277.png 424w, https://substackcdn.com/image/fetch/$s_!GXIS!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a04d7c6-f7a8-444d-b495-992f90f89aa1_1929x1277.png 848w, https://substackcdn.com/image/fetch/$s_!GXIS!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a04d7c6-f7a8-444d-b495-992f90f89aa1_1929x1277.png 1272w, https://substackcdn.com/image/fetch/$s_!GXIS!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a04d7c6-f7a8-444d-b495-992f90f89aa1_1929x1277.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!GXIS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a04d7c6-f7a8-444d-b495-992f90f89aa1_1929x1277.png" width="1456" height="964" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1a04d7c6-f7a8-444d-b495-992f90f89aa1_1929x1277.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:964,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:147263,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!GXIS!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a04d7c6-f7a8-444d-b495-992f90f89aa1_1929x1277.png 424w, https://substackcdn.com/image/fetch/$s_!GXIS!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a04d7c6-f7a8-444d-b495-992f90f89aa1_1929x1277.png 848w, https://substackcdn.com/image/fetch/$s_!GXIS!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a04d7c6-f7a8-444d-b495-992f90f89aa1_1929x1277.png 1272w, https://substackcdn.com/image/fetch/$s_!GXIS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a04d7c6-f7a8-444d-b495-992f90f89aa1_1929x1277.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/2Q0XVsHuYTnCNTrNl9Gf?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><p>This materialized view can be refreshed periodically to keep the data up to date.</p><p>Key benefits of materialized views are:</p><ul><li><p>No need to run complex and time-consuming queries in the user request flow.</p></li><li><p>Reduced load</p></li></ul><p>The trade-offs are as follows:</p><ul><li><p>Extra storage</p></li><li><p>Higher refresh time and inconsistent data in the view</p></li></ul><h2><strong>3 - Denormalization</strong></h2><p>Denormalization involves duplicating data across multiple tables to optimize query performance. The goal is to reduce the number of joins and computations required to retrieve data, making queries faster and more scalable.</p><p>In other words, the rules of normalization are relaxed a bit in favor of performance.</p><p>Imagine an e-commerce store with a &#8220;Customers&#8221; table and an &#8220;Orders&#8221; table. In a normalized design, the &#8220;Orders&#8221; table would only store a reference to the &#8220;Customers&#8221; table.</p><p>To get the customer details with the order information, you&#8217;d need to join the two tables. However, as the number of orders grows, the join operation can become a performance bottleneck.</p><p>That&#8217;s where denormalization comes in handy.</p><p>By storing a field like the &#8220;CustomerName&#8221; directly in the &#8220;Orders&#8221; table, you can retrieve the details along with order information in a single query. Note that this is just an example scenario and doing so may depend on the overall system context and the data modeling rules in place.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!2yKp!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e375e70-283d-433f-870f-4261675180b5_1929x1215.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!2yKp!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e375e70-283d-433f-870f-4261675180b5_1929x1215.png 424w, https://substackcdn.com/image/fetch/$s_!2yKp!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e375e70-283d-433f-870f-4261675180b5_1929x1215.png 848w, https://substackcdn.com/image/fetch/$s_!2yKp!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e375e70-283d-433f-870f-4261675180b5_1929x1215.png 1272w, https://substackcdn.com/image/fetch/$s_!2yKp!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e375e70-283d-433f-870f-4261675180b5_1929x1215.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!2yKp!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e375e70-283d-433f-870f-4261675180b5_1929x1215.png" width="1456" height="917" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4e375e70-283d-433f-870f-4261675180b5_1929x1215.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:917,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:160683,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!2yKp!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e375e70-283d-433f-870f-4261675180b5_1929x1215.png 424w, https://substackcdn.com/image/fetch/$s_!2yKp!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e375e70-283d-433f-870f-4261675180b5_1929x1215.png 848w, https://substackcdn.com/image/fetch/$s_!2yKp!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e375e70-283d-433f-870f-4261675180b5_1929x1215.png 1272w, https://substackcdn.com/image/fetch/$s_!2yKp!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e375e70-283d-433f-870f-4261675180b5_1929x1215.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/2Q0XVsHuYTnCNTrNl9Gf?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><p>Benefits of Denormalization:</p><ul><li><p>Faster queries</p></li><li><p>Reduced overhead</p></li><li><p>Improved read performance</p></li></ul><p>The trade-offs are as follows:</p><ul><li><p>Data redundancy.</p></li><li><p>Complex updates since redundant data may need to be kept in sync across multiple tables.</p></li><li><p>Potential inconsistency.</p></li></ul><h2><strong>4 - Vertical Scaling</strong></h2><p>Vertical scaling, also known as &#8220;scaling up,&#8221; is a technique that focuses on increasing the hardware resources of a single server.</p><p>It&#8217;s all about making your database server bigger, stronger, and faster.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!mouf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F663686d5-ddbe-481d-953f-2c86e99dccde_1604x966.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!mouf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F663686d5-ddbe-481d-953f-2c86e99dccde_1604x966.png 424w, https://substackcdn.com/image/fetch/$s_!mouf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F663686d5-ddbe-481d-953f-2c86e99dccde_1604x966.png 848w, https://substackcdn.com/image/fetch/$s_!mouf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F663686d5-ddbe-481d-953f-2c86e99dccde_1604x966.png 1272w, https://substackcdn.com/image/fetch/$s_!mouf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F663686d5-ddbe-481d-953f-2c86e99dccde_1604x966.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!mouf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F663686d5-ddbe-481d-953f-2c86e99dccde_1604x966.png" width="1456" height="877" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/663686d5-ddbe-481d-953f-2c86e99dccde_1604x966.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:877,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:119123,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!mouf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F663686d5-ddbe-481d-953f-2c86e99dccde_1604x966.png 424w, https://substackcdn.com/image/fetch/$s_!mouf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F663686d5-ddbe-481d-953f-2c86e99dccde_1604x966.png 848w, https://substackcdn.com/image/fetch/$s_!mouf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F663686d5-ddbe-481d-953f-2c86e99dccde_1604x966.png 1272w, https://substackcdn.com/image/fetch/$s_!mouf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F663686d5-ddbe-481d-953f-2c86e99dccde_1604x966.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/2Q0XVsHuYTnCNTrNl9Gf?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><p>A few easy ways to do so are:</p><ul><li><p>Upgrading to a faster CPU</p></li><li><p>Adding more memory to your server</p></li><li><p>Switching to high-performance storage devices like SSDs.</p></li></ul><p>There are several benefits of Vertical Scaling:</p><ul><li><p>Better performance</p></li><li><p>Simplified management</p></li><li><p>Reduced latency</p></li></ul><p>However, there are some limitations as well:</p><ul><li><p>There&#8217;s a limit to how much you can vertically scale a server before hitting some cost constraints.</p></li><li><p>A single server failure can bring down your database.</p></li><li><p>Upgrading hardware can be expensive.</p></li></ul><h2><strong>5 - Caching</strong></h2><p>Caching is a technique that involves storing frequently accessed data in a high-speed storage layer, separate from the primary database.</p><p>When an application receives a request for data, it first checks the cache. If the data is found (a cache hit), it&#8217;s quickly retrieved without bothering the database. If the data is not found (a cache miss), the application fetches it from the database and stores a copy in the cache for future requests.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ilu2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0175e3c7-8032-4ead-8beb-dcb8873cb27b_2032x1379.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ilu2!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0175e3c7-8032-4ead-8beb-dcb8873cb27b_2032x1379.png 424w, https://substackcdn.com/image/fetch/$s_!ilu2!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0175e3c7-8032-4ead-8beb-dcb8873cb27b_2032x1379.png 848w, https://substackcdn.com/image/fetch/$s_!ilu2!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0175e3c7-8032-4ead-8beb-dcb8873cb27b_2032x1379.png 1272w, https://substackcdn.com/image/fetch/$s_!ilu2!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0175e3c7-8032-4ead-8beb-dcb8873cb27b_2032x1379.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ilu2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0175e3c7-8032-4ead-8beb-dcb8873cb27b_2032x1379.png" width="1456" height="988" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0175e3c7-8032-4ead-8beb-dcb8873cb27b_2032x1379.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:988,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:204144,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!ilu2!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0175e3c7-8032-4ead-8beb-dcb8873cb27b_2032x1379.png 424w, https://substackcdn.com/image/fetch/$s_!ilu2!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0175e3c7-8032-4ead-8beb-dcb8873cb27b_2032x1379.png 848w, https://substackcdn.com/image/fetch/$s_!ilu2!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0175e3c7-8032-4ead-8beb-dcb8873cb27b_2032x1379.png 1272w, https://substackcdn.com/image/fetch/$s_!ilu2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0175e3c7-8032-4ead-8beb-dcb8873cb27b_2032x1379.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/2Q0XVsHuYTnCNTrNl9Gf?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><p>The benefits of Caching are as follows:</p><ul><li><p>Reduced database load</p></li><li><p>Improved read performance</p></li></ul><p>There are some trade-offs as well:</p><ul><li><p>Additional complexity</p></li><li><p>Extra cost</p></li><li><p>Chances of stale data</p></li></ul><h2><strong>6 - Replication</strong></h2><p>Replication is a technique used in database systems to create and maintain multiple copies of data across different servers or nodes.</p><p>In a typical leader-follower replication model, one node is designated as the leader, while the others are followers.</p><p>The leader handles all the write operations ensuring consistency and integrity. The changes are automatically shared with the follower nodes whenever a write operation is performed on the leader node. The leader can also handle critical read operations where high consistency is required.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!AuLb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc47860f-6e4c-47b0-a6ae-c5fa424b2993_1929x1319.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!AuLb!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc47860f-6e4c-47b0-a6ae-c5fa424b2993_1929x1319.png 424w, https://substackcdn.com/image/fetch/$s_!AuLb!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc47860f-6e4c-47b0-a6ae-c5fa424b2993_1929x1319.png 848w, https://substackcdn.com/image/fetch/$s_!AuLb!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc47860f-6e4c-47b0-a6ae-c5fa424b2993_1929x1319.png 1272w, https://substackcdn.com/image/fetch/$s_!AuLb!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc47860f-6e4c-47b0-a6ae-c5fa424b2993_1929x1319.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!AuLb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc47860f-6e4c-47b0-a6ae-c5fa424b2993_1929x1319.png" width="1456" height="996" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fc47860f-6e4c-47b0-a6ae-c5fa424b2993_1929x1319.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:996,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:171951,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!AuLb!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc47860f-6e4c-47b0-a6ae-c5fa424b2993_1929x1319.png 424w, https://substackcdn.com/image/fetch/$s_!AuLb!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc47860f-6e4c-47b0-a6ae-c5fa424b2993_1929x1319.png 848w, https://substackcdn.com/image/fetch/$s_!AuLb!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc47860f-6e4c-47b0-a6ae-c5fa424b2993_1929x1319.png 1272w, https://substackcdn.com/image/fetch/$s_!AuLb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc47860f-6e4c-47b0-a6ae-c5fa424b2993_1929x1319.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/2Q0XVsHuYTnCNTrNl9Gf?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><p>The follower nodes, in turn, handle read operations and help distribute the workload to improve performance.</p><p>The benefits of Replication are as follows:</p><ul><li><p>Improved Read Performance</p></li><li><p>High Availability</p></li><li><p>Durability</p></li></ul><p>There are also some trade-offs:</p><ul><li><p>Introduces some delay in data synchronization known as replication lag</p></li><li><p>Increased complexity</p></li></ul><h2><strong>7 - Sharding</strong></h2><p>Database sharding is a technique that partitions a single large database into smaller, more manageable units called shards.</p><p>In a sharded database architecture, data is distributed across multiple shards based on a specific sharding key. The choice of the sharding key determines how the data is allocated to different shards.</p><p>Common sharding strategies include:</p><ul><li><p><strong>Range-based Sharding:</strong> Data is partitioned based on a range of values of the sharding key.</p></li><li><p><strong>Hash-based Sharding:</strong> A hash function is applied to the sharding key to determine the target shard.</p></li><li><p><strong>Directory-based Sharding:</strong> A separate lookup table is maintained to map the sharding key to the corresponding shard.</p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!lNW-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F21126878-2928-410d-a240-2ce98a346452_2032x1319.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!lNW-!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F21126878-2928-410d-a240-2ce98a346452_2032x1319.png 424w, https://substackcdn.com/image/fetch/$s_!lNW-!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F21126878-2928-410d-a240-2ce98a346452_2032x1319.png 848w, https://substackcdn.com/image/fetch/$s_!lNW-!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F21126878-2928-410d-a240-2ce98a346452_2032x1319.png 1272w, https://substackcdn.com/image/fetch/$s_!lNW-!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F21126878-2928-410d-a240-2ce98a346452_2032x1319.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!lNW-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F21126878-2928-410d-a240-2ce98a346452_2032x1319.png" width="1456" height="945" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/21126878-2928-410d-a240-2ce98a346452_2032x1319.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:945,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:212943,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!lNW-!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F21126878-2928-410d-a240-2ce98a346452_2032x1319.png 424w, https://substackcdn.com/image/fetch/$s_!lNW-!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F21126878-2928-410d-a240-2ce98a346452_2032x1319.png 848w, https://substackcdn.com/image/fetch/$s_!lNW-!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F21126878-2928-410d-a240-2ce98a346452_2032x1319.png 1272w, https://substackcdn.com/image/fetch/$s_!lNW-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F21126878-2928-410d-a240-2ce98a346452_2032x1319.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/2Q0XVsHuYTnCNTrNl9Gf?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><p>The benefits of Sharding are as follows:</p><ul><li><p>Sharding allows for horizontal scaling of the database.</p></li><li><p>Queries and write operations are processed in parallel.</p></li><li><p>Reduced hardware costs when compared to vertical scaling.</p></li></ul><p>However, there are also trade-offs:</p><ul><li><p>Sharding introduces additional complexity.</p></li><li><p>Rebalancing data across shards can be a complex and time-consuming process.</p></li><li><p>Joining data across shards can be challenging.</p></li></ul><p><strong>So - how do you improve the performance and scalability of the database?</strong></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/database-scaling-and-performance/comments&quot;,&quot;text&quot;:&quot;Leave a comment&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/database-scaling-and-performance/comments"><span>Leave a comment</span></a></p><div><hr></div><p><strong>That&#8217;s it for today! &#9728;&#65039;</strong></p><p>Enjoyed this issue of the newsletter?</p><p>Share with your friends and colleagues.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/database-scaling-and-performance?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/database-scaling-and-performance?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p><em><strong>See you later with another edition &#8212; Saurabh</strong></em></p>]]></content:encoded></item><item><title><![CDATA[LSM Trees Explained]]></title><description><![CDATA[Making database writes fast]]></description><link>https://newsletter.systemdesigncodex.com/p/lsm-trees-explained</link><guid isPermaLink="false">https://newsletter.systemdesigncodex.com/p/lsm-trees-explained</guid><dc:creator><![CDATA[Saurabh Dashora]]></dc:creator><pubDate>Tue, 09 Dec 2025 09:04:35 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!6vYd!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80379b47-b560-4fc3-9c43-a7fb9f7ca8f8_3318x2284.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><strong>How do you guarantee fast writes to the database?</strong></p><p>Choose a database with a storage engine that follows the LSM Tree approach to store and retrieve data.</p><p>An LSM Tree, which stands for Log-Structured Merge-Tree, is a data structure designed to store and retrieve key-value pairs efficiently. It is specifically optimized for high write throughput.</p><p>Storage engines based on this data structure are called LSM storage engines. For example, LevelDB and RocksDB are a couple of key-value storage engine libraries that use LSM trees. Similar storage engines are also used in databases like Cassandra and HBase.</p><h1><strong>4 Steps to LSM Storage Engine</strong></h1><p>Here&#8217;s how a typical LSM Storage Engine works:</p><ul><li><p><strong>STEP 1: </strong>When a write request for a key-value pair arrives, it is added to an in-memory structure known as memtable.</p></li><li><p><strong>STEP 2: </strong>When the memtable gets bigger than some threshold, it is flushed to disk as an immutable file called an SSTable (Sorted String Table). This is handled asynchronously so that the new requests are not blocked.</p></li><li><p><strong>STEP 3: </strong>To serve a read request, first try to find the key in the memtable, then in the most recent SSTable, then in the next older SSTable, and so on.</p></li><li><p><strong>STEP 4:</strong> To keep the number of SSTable files in check, run a periodic merging and compaction process in the background to combine them and discard overwritten or deleted values.</p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!6vYd!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80379b47-b560-4fc3-9c43-a7fb9f7ca8f8_3318x2284.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!6vYd!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80379b47-b560-4fc3-9c43-a7fb9f7ca8f8_3318x2284.png 424w, https://substackcdn.com/image/fetch/$s_!6vYd!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80379b47-b560-4fc3-9c43-a7fb9f7ca8f8_3318x2284.png 848w, https://substackcdn.com/image/fetch/$s_!6vYd!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80379b47-b560-4fc3-9c43-a7fb9f7ca8f8_3318x2284.png 1272w, https://substackcdn.com/image/fetch/$s_!6vYd!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80379b47-b560-4fc3-9c43-a7fb9f7ca8f8_3318x2284.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!6vYd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80379b47-b560-4fc3-9c43-a7fb9f7ca8f8_3318x2284.png" width="1456" height="1002" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/80379b47-b560-4fc3-9c43-a7fb9f7ca8f8_3318x2284.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1002,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:574239,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!6vYd!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80379b47-b560-4fc3-9c43-a7fb9f7ca8f8_3318x2284.png 424w, https://substackcdn.com/image/fetch/$s_!6vYd!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80379b47-b560-4fc3-9c43-a7fb9f7ca8f8_3318x2284.png 848w, https://substackcdn.com/image/fetch/$s_!6vYd!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80379b47-b560-4fc3-9c43-a7fb9f7ca8f8_3318x2284.png 1272w, https://substackcdn.com/image/fetch/$s_!6vYd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80379b47-b560-4fc3-9c43-a7fb9f7ca8f8_3318x2284.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/riJ4hupsTB6qlILaha5G?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><h1><strong>Components of an LSM Tree</strong></h1><p>What is an LSM Tree made up of?</p><p>It has a few key components:</p><ul><li><p>Memtable</p></li><li><p>SSTable</p></li><li><p>Compaction Process</p></li></ul><p>The diagram below shows the overall design of LSM Trees</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!9xcn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1896712e-2c47-4302-a70f-d457280bd689_3334x2284.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!9xcn!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1896712e-2c47-4302-a70f-d457280bd689_3334x2284.png 424w, https://substackcdn.com/image/fetch/$s_!9xcn!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1896712e-2c47-4302-a70f-d457280bd689_3334x2284.png 848w, https://substackcdn.com/image/fetch/$s_!9xcn!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1896712e-2c47-4302-a70f-d457280bd689_3334x2284.png 1272w, https://substackcdn.com/image/fetch/$s_!9xcn!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1896712e-2c47-4302-a70f-d457280bd689_3334x2284.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!9xcn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1896712e-2c47-4302-a70f-d457280bd689_3334x2284.png" width="1456" height="997" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1896712e-2c47-4302-a70f-d457280bd689_3334x2284.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:997,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:473781,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!9xcn!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1896712e-2c47-4302-a70f-d457280bd689_3334x2284.png 424w, https://substackcdn.com/image/fetch/$s_!9xcn!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1896712e-2c47-4302-a70f-d457280bd689_3334x2284.png 848w, https://substackcdn.com/image/fetch/$s_!9xcn!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1896712e-2c47-4302-a70f-d457280bd689_3334x2284.png 1272w, https://substackcdn.com/image/fetch/$s_!9xcn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1896712e-2c47-4302-a70f-d457280bd689_3334x2284.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/riJ4hupsTB6qlILaha5G?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><h2><strong>1 - Memtable</strong></h2><p>Imagine having a notebook where you write down new information as it comes in. In an LSM Tree, this notebook is called a memtable.</p><p>It&#8217;s a place in memory where all the new data is initially stored. You can use well-known tree data structures (such as red-black trees or AVL trees) to insert keys in any order and read them back in a sorted order.</p><p>For example: let&#8217;s say you are running a bookstore and want to keep track of your inventory. Whenever you receive a new shipment of books, you write down the book name and quantities in your memtable.</p><p>Here&#8217;s how the memtable looks like:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!NtMO!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F485ddc38-38d8-4257-b3ff-94543b7ff0eb_1427x715.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!NtMO!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F485ddc38-38d8-4257-b3ff-94543b7ff0eb_1427x715.png 424w, https://substackcdn.com/image/fetch/$s_!NtMO!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F485ddc38-38d8-4257-b3ff-94543b7ff0eb_1427x715.png 848w, https://substackcdn.com/image/fetch/$s_!NtMO!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F485ddc38-38d8-4257-b3ff-94543b7ff0eb_1427x715.png 1272w, https://substackcdn.com/image/fetch/$s_!NtMO!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F485ddc38-38d8-4257-b3ff-94543b7ff0eb_1427x715.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!NtMO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F485ddc38-38d8-4257-b3ff-94543b7ff0eb_1427x715.png" width="1427" height="715" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/485ddc38-38d8-4257-b3ff-94543b7ff0eb_1427x715.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:715,&quot;width&quot;:1427,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:76851,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!NtMO!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F485ddc38-38d8-4257-b3ff-94543b7ff0eb_1427x715.png 424w, https://substackcdn.com/image/fetch/$s_!NtMO!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F485ddc38-38d8-4257-b3ff-94543b7ff0eb_1427x715.png 848w, https://substackcdn.com/image/fetch/$s_!NtMO!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F485ddc38-38d8-4257-b3ff-94543b7ff0eb_1427x715.png 1272w, https://substackcdn.com/image/fetch/$s_!NtMO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F485ddc38-38d8-4257-b3ff-94543b7ff0eb_1427x715.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/riJ4hupsTB6qlILaha5G?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><h2><strong>2 - SSTable</strong></h2><p>SSTables are files on disk that store the data from the memtable in a sorted order.</p><p>When the memtable reaches a certain size threshold, its contents are flushed to disk as an SSTable file.</p><p>For example: taking our bookstore example, here&#8217;s how the data might look in the SSTable</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!yStN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ad93fcf-0863-4497-a4e2-4aa525f3e2c0_1427x715.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!yStN!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ad93fcf-0863-4497-a4e2-4aa525f3e2c0_1427x715.png 424w, https://substackcdn.com/image/fetch/$s_!yStN!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ad93fcf-0863-4497-a4e2-4aa525f3e2c0_1427x715.png 848w, https://substackcdn.com/image/fetch/$s_!yStN!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ad93fcf-0863-4497-a4e2-4aa525f3e2c0_1427x715.png 1272w, https://substackcdn.com/image/fetch/$s_!yStN!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ad93fcf-0863-4497-a4e2-4aa525f3e2c0_1427x715.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!yStN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ad93fcf-0863-4497-a4e2-4aa525f3e2c0_1427x715.png" width="1427" height="715" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3ad93fcf-0863-4497-a4e2-4aa525f3e2c0_1427x715.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:715,&quot;width&quot;:1427,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:77028,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!yStN!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ad93fcf-0863-4497-a4e2-4aa525f3e2c0_1427x715.png 424w, https://substackcdn.com/image/fetch/$s_!yStN!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ad93fcf-0863-4497-a4e2-4aa525f3e2c0_1427x715.png 848w, https://substackcdn.com/image/fetch/$s_!yStN!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ad93fcf-0863-4497-a4e2-4aa525f3e2c0_1427x715.png 1272w, https://substackcdn.com/image/fetch/$s_!yStN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ad93fcf-0863-4497-a4e2-4aa525f3e2c0_1427x715.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/riJ4hupsTB6qlILaha5G?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><p>As more updates come in, new memtables are created and flushed to disk as additional SSTables.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!wQmv!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfbba2e5-4f39-4d57-a133-68e450981a3a_1427x623.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!wQmv!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfbba2e5-4f39-4d57-a133-68e450981a3a_1427x623.png 424w, https://substackcdn.com/image/fetch/$s_!wQmv!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfbba2e5-4f39-4d57-a133-68e450981a3a_1427x623.png 848w, https://substackcdn.com/image/fetch/$s_!wQmv!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfbba2e5-4f39-4d57-a133-68e450981a3a_1427x623.png 1272w, https://substackcdn.com/image/fetch/$s_!wQmv!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfbba2e5-4f39-4d57-a133-68e450981a3a_1427x623.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!wQmv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfbba2e5-4f39-4d57-a133-68e450981a3a_1427x623.png" width="1427" height="623" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cfbba2e5-4f39-4d57-a133-68e450981a3a_1427x623.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:623,&quot;width&quot;:1427,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:62303,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!wQmv!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfbba2e5-4f39-4d57-a133-68e450981a3a_1427x623.png 424w, https://substackcdn.com/image/fetch/$s_!wQmv!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfbba2e5-4f39-4d57-a133-68e450981a3a_1427x623.png 848w, https://substackcdn.com/image/fetch/$s_!wQmv!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfbba2e5-4f39-4d57-a133-68e450981a3a_1427x623.png 1272w, https://substackcdn.com/image/fetch/$s_!wQmv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfbba2e5-4f39-4d57-a133-68e450981a3a_1427x623.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/riJ4hupsTB6qlILaha5G?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!sSJ2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc143430b-438b-4226-9b48-159d76b41265_1427x623.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!sSJ2!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc143430b-438b-4226-9b48-159d76b41265_1427x623.png 424w, https://substackcdn.com/image/fetch/$s_!sSJ2!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc143430b-438b-4226-9b48-159d76b41265_1427x623.png 848w, https://substackcdn.com/image/fetch/$s_!sSJ2!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc143430b-438b-4226-9b48-159d76b41265_1427x623.png 1272w, https://substackcdn.com/image/fetch/$s_!sSJ2!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc143430b-438b-4226-9b48-159d76b41265_1427x623.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!sSJ2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc143430b-438b-4226-9b48-159d76b41265_1427x623.png" width="1427" height="623" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c143430b-438b-4226-9b48-159d76b41265_1427x623.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:623,&quot;width&quot;:1427,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:63398,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!sSJ2!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc143430b-438b-4226-9b48-159d76b41265_1427x623.png 424w, https://substackcdn.com/image/fetch/$s_!sSJ2!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc143430b-438b-4226-9b48-159d76b41265_1427x623.png 848w, https://substackcdn.com/image/fetch/$s_!sSJ2!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc143430b-438b-4226-9b48-159d76b41265_1427x623.png 1272w, https://substackcdn.com/image/fetch/$s_!sSJ2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc143430b-438b-4226-9b48-159d76b41265_1427x623.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/riJ4hupsTB6qlILaha5G?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><h2><strong>3 - Compaction Process</strong></h2><p>Over time, you might end up with many SSTable files, making it harder to find specific information.</p><p>As the number of SSTables grows, the LSM Tree performs compaction to merge the smaller SSTables into larger ones. During compaction, the data is merged based on the key, and the latest values for each key are retained.</p><p>In our bookstore example, the data after compaction looks like this:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!cCVA!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e716189-fb09-4175-bcf7-df7231a45714_2306x1584.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!cCVA!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e716189-fb09-4175-bcf7-df7231a45714_2306x1584.png 424w, https://substackcdn.com/image/fetch/$s_!cCVA!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e716189-fb09-4175-bcf7-df7231a45714_2306x1584.png 848w, https://substackcdn.com/image/fetch/$s_!cCVA!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e716189-fb09-4175-bcf7-df7231a45714_2306x1584.png 1272w, https://substackcdn.com/image/fetch/$s_!cCVA!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e716189-fb09-4175-bcf7-df7231a45714_2306x1584.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!cCVA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e716189-fb09-4175-bcf7-df7231a45714_2306x1584.png" width="1456" height="1000" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7e716189-fb09-4175-bcf7-df7231a45714_2306x1584.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1000,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:222907,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!cCVA!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e716189-fb09-4175-bcf7-df7231a45714_2306x1584.png 424w, https://substackcdn.com/image/fetch/$s_!cCVA!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e716189-fb09-4175-bcf7-df7231a45714_2306x1584.png 848w, https://substackcdn.com/image/fetch/$s_!cCVA!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e716189-fb09-4175-bcf7-df7231a45714_2306x1584.png 1272w, https://substackcdn.com/image/fetch/$s_!cCVA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e716189-fb09-4175-bcf7-df7231a45714_2306x1584.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/riJ4hupsTB6qlILaha5G?origin=share">You can play around with the diagram on Eraser.io</a></figcaption></figure></div><p>In this compacted SSTable, the latest values for each book are stored. For example, &#8220;Book A&#8221; has a quantity of 8, which is the most recent value from SSTable 2.</p><h1><strong>How LSM Trees Differ from B-trees?</strong></h1><p>Let&#8217;s look at the key differences between LSM Trees and B-Trees in some important aspects.</p><h2><strong>1 - Write Optimization</strong></h2><ul><li><p><strong>LSM Trees: </strong>Optimized for high write throughput. As we discussed, writes are initially stored in a memtable and later flushed to disk, allowing for fast and efficient write operations.</p></li><li><p><strong>B-Trees: </strong>Writes require traversing the tree and potentially causing cascading splits or merges, which can be slower compared to LSM Trees.</p></li></ul><h2><strong>2 - Read Performance</strong></h2><ul><li><p><strong>LSM Trees:</strong> Reads may require accessing multiple levels of SSTables, resulting in higher latency compared to B-Trees. Techniques like Bloom Filters can help but we will discuss them later.</p></li><li><p><strong>B-Trees: </strong>Reads are faster as data is stored in a sorted manner, and the tree structure allows for efficient lookups.</p></li></ul><h2><strong>3 - Space Amplification</strong></h2><ul><li><p><strong>LSM Trees: </strong>Due to the multi-level structure and the need for compaction, LSM Trees may have higher space amplifications compared to B-Trees.</p></li><li><p><strong>B-Trees: They have lower space amplification as data is stored more compactly.</strong></p></li></ul><h2><strong>4 - Compaction Overhead</strong></h2><ul><li><p><strong>LSM Trees:</strong> Compaction is a background process that merges SSTables, which can consume I/O and CPU resources.</p></li><li><p><strong>B-Trees: </strong>There is no separate compaction process, but they may require rebalancing and merging operations.</p></li></ul><p><strong>&#128073; So - have you used databases that support LSM Trees?</strong></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/lsm-trees-explained/comments&quot;,&quot;text&quot;:&quot;Leave a comment&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/lsm-trees-explained/comments"><span>Leave a comment</span></a></p><div><hr></div><p><strong>That&#8217;s it for today! &#9728;&#65039;</strong></p><p>Enjoyed this issue of the newsletter?</p><p>Share with your friends and colleagues.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/lsm-trees-explained?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/lsm-trees-explained?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p></p><p><em><strong>See you later with another value-packed edition &#8212; Saurabh</strong></em></p>]]></content:encoded></item><item><title><![CDATA[Top Microservices Patterns]]></title><description><![CDATA[The ones that are most common]]></description><link>https://newsletter.systemdesigncodex.com/p/top-microservices-patterns</link><guid isPermaLink="false">https://newsletter.systemdesigncodex.com/p/top-microservices-patterns</guid><dc:creator><![CDATA[Saurabh Dashora]]></dc:creator><pubDate>Tue, 02 Dec 2025 08:41:51 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!afLc!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfb78731-5ff3-47ae-b560-c19532bedd93_4580x2615.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Building microservices isn&#8217;t easy.</p><p>Even in the best of times, you might end up in a mess.</p><p>But if you&#8217;ve to build microservices for some reason, it&#8217;s better to know some patterns that can make your life easy.</p><p>Here are <strong>4 must-know patterns</strong> for building microservices:</p><h2><strong>Database Per Service</strong></h2><p>As the name suggests, this pattern proposes that each microservice manages its own data.</p><p>This implies that no other microservice can directly access or manipulate the data managed by another microservice.</p><p>Any exchange or manipulation of data can be done only by using a set of well-defined APIs.</p><p>The figure below shows an example of a database-per-service pattern.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ZfIA!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3755de0d-b906-489c-ac21-16ae1f25a002_4580x2615.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ZfIA!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3755de0d-b906-489c-ac21-16ae1f25a002_4580x2615.png 424w, https://substackcdn.com/image/fetch/$s_!ZfIA!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3755de0d-b906-489c-ac21-16ae1f25a002_4580x2615.png 848w, https://substackcdn.com/image/fetch/$s_!ZfIA!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3755de0d-b906-489c-ac21-16ae1f25a002_4580x2615.png 1272w, https://substackcdn.com/image/fetch/$s_!ZfIA!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3755de0d-b906-489c-ac21-16ae1f25a002_4580x2615.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ZfIA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3755de0d-b906-489c-ac21-16ae1f25a002_4580x2615.png" width="1456" height="831" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3755de0d-b906-489c-ac21-16ae1f25a002_4580x2615.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:831,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:562073,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesigncodex.com/i/180480739?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3755de0d-b906-489c-ac21-16ae1f25a002_4580x2615.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ZfIA!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3755de0d-b906-489c-ac21-16ae1f25a002_4580x2615.png 424w, https://substackcdn.com/image/fetch/$s_!ZfIA!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3755de0d-b906-489c-ac21-16ae1f25a002_4580x2615.png 848w, https://substackcdn.com/image/fetch/$s_!ZfIA!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3755de0d-b906-489c-ac21-16ae1f25a002_4580x2615.png 1272w, https://substackcdn.com/image/fetch/$s_!ZfIA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3755de0d-b906-489c-ac21-16ae1f25a002_4580x2615.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/tJsRGxsibLOWUZfsT2z4?origin=share">You can play with the diagram on Eraser.io</a></figcaption></figure></div><p>At face value, this pattern seems quite simple. You can implement it relatively easily when you are starting a brand-new application.</p><p>However, when you are trying to migrate an existing monolithic application to a microservices architecture, the demarcation between services is not so clear.</p><p>Most of the functionality is written in a way where different parts of the system access data from other parts informally.</p><p>Two main areas that you must focus on when using a database-per-service pattern are:</p><ul><li><p>Defining bounded contexts for each service.</p></li><li><p>Managing business transactions spanning multiple microservices.</p></li></ul><h2><strong>Shared Database</strong></h2><p>The next important pattern is the shared database pattern.</p><p>Depending on how you are looking at things, this might also sound like an anti-pattern.</p><p>That&#8217;s because this pattern adopts a much more lenient approach by using a shared database accessible to multiple microservices.</p><p>Here&#8217;s what it looks like in practice:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Xfiw!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbcd839e3-2fd0-489e-803e-ca1b76573782_4580x2615.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Xfiw!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbcd839e3-2fd0-489e-803e-ca1b76573782_4580x2615.png 424w, https://substackcdn.com/image/fetch/$s_!Xfiw!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbcd839e3-2fd0-489e-803e-ca1b76573782_4580x2615.png 848w, https://substackcdn.com/image/fetch/$s_!Xfiw!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbcd839e3-2fd0-489e-803e-ca1b76573782_4580x2615.png 1272w, https://substackcdn.com/image/fetch/$s_!Xfiw!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbcd839e3-2fd0-489e-803e-ca1b76573782_4580x2615.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Xfiw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbcd839e3-2fd0-489e-803e-ca1b76573782_4580x2615.png" width="1456" height="831" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bcd839e3-2fd0-489e-803e-ca1b76573782_4580x2615.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:831,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:553756,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesigncodex.com/i/180480739?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbcd839e3-2fd0-489e-803e-ca1b76573782_4580x2615.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Xfiw!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbcd839e3-2fd0-489e-803e-ca1b76573782_4580x2615.png 424w, https://substackcdn.com/image/fetch/$s_!Xfiw!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbcd839e3-2fd0-489e-803e-ca1b76573782_4580x2615.png 848w, https://substackcdn.com/image/fetch/$s_!Xfiw!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbcd839e3-2fd0-489e-803e-ca1b76573782_4580x2615.png 1272w, https://substackcdn.com/image/fetch/$s_!Xfiw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbcd839e3-2fd0-489e-803e-ca1b76573782_4580x2615.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/tJsRGxsibLOWUZfsT2z4?origin=share">You can play with the diagram on Eraser.io</a></figcaption></figure></div><p>For existing applications transitioning to a microservices architecture, this is a much safer pattern as we can slowly evolve the application layer without changing the database design.</p><p>However, this approach takes away some key benefits of microservices.</p><ul><li><p>Developers across teams need to coordinate schema changes to tables</p></li><li><p>Runtime conflicts may arise when multiple services are trying to access the same database resources.</p></li></ul><p><strong>Thanks for reading System Design Codex! Subscribe for free to receive new posts and support my work.</strong></p><h2><strong>API Composition</strong></h2><p>The API Composition pattern attempts to solve the problem of implementing complex queries in a microservices architecture.</p><p>An API composer invokes other services in the required order. After fetching the results, it performs an in-memory join of the data before returning it to the caller.</p><p>However, this is an inefficient approach due to in-memory joins on potentially large datasets.</p><p>Check the illustration below:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!n70E!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F40cb1380-ba25-4a10-bbfe-e6650d304c40_4580x2615.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!n70E!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F40cb1380-ba25-4a10-bbfe-e6650d304c40_4580x2615.png 424w, https://substackcdn.com/image/fetch/$s_!n70E!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F40cb1380-ba25-4a10-bbfe-e6650d304c40_4580x2615.png 848w, https://substackcdn.com/image/fetch/$s_!n70E!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F40cb1380-ba25-4a10-bbfe-e6650d304c40_4580x2615.png 1272w, https://substackcdn.com/image/fetch/$s_!n70E!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F40cb1380-ba25-4a10-bbfe-e6650d304c40_4580x2615.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!n70E!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F40cb1380-ba25-4a10-bbfe-e6650d304c40_4580x2615.png" width="1456" height="831" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/40cb1380-ba25-4a10-bbfe-e6650d304c40_4580x2615.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:831,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:510865,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesigncodex.com/i/180480739?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F40cb1380-ba25-4a10-bbfe-e6650d304c40_4580x2615.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!n70E!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F40cb1380-ba25-4a10-bbfe-e6650d304c40_4580x2615.png 424w, https://substackcdn.com/image/fetch/$s_!n70E!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F40cb1380-ba25-4a10-bbfe-e6650d304c40_4580x2615.png 848w, https://substackcdn.com/image/fetch/$s_!n70E!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F40cb1380-ba25-4a10-bbfe-e6650d304c40_4580x2615.png 1272w, https://substackcdn.com/image/fetch/$s_!n70E!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F40cb1380-ba25-4a10-bbfe-e6650d304c40_4580x2615.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/tJsRGxsibLOWUZfsT2z4?origin=share">You can play with the diagram on Eraser.io</a></figcaption></figure></div><h2><strong>CQRS and Event Sourcing</strong></h2><p>CQRS stands for Command Query Responsibility Segregation.</p><p>In the CQRS pattern, an application listens to domain events from other microservices and updates a separate database for supporting queries and views.</p><p>You can then serve complex aggregation queries from this separate database while optimizing the performance and scaling it out as needed.</p><p>Event Sourcing takes it a bit further by storing the state of the entity or the aggregate as a sequence of events.</p><p>Whenever there is an update or an insert on an object, a new event is created and stored in the event store.</p><p>You can use CQRS and Event Sourcing together to solve a lot of challenges around event handling and maintaining separate query data. This way, you can scale the read and writes separately based on specific requirements.</p><p>On the downside, this is an unfamiliar style of building applications for many developers and there are also multiple moving parts to manage.</p><p>Check out the illustration below that shows CQRS and Event Sourcing together.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!afLc!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfb78731-5ff3-47ae-b560-c19532bedd93_4580x2615.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!afLc!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfb78731-5ff3-47ae-b560-c19532bedd93_4580x2615.png 424w, https://substackcdn.com/image/fetch/$s_!afLc!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfb78731-5ff3-47ae-b560-c19532bedd93_4580x2615.png 848w, https://substackcdn.com/image/fetch/$s_!afLc!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfb78731-5ff3-47ae-b560-c19532bedd93_4580x2615.png 1272w, https://substackcdn.com/image/fetch/$s_!afLc!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfb78731-5ff3-47ae-b560-c19532bedd93_4580x2615.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!afLc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfb78731-5ff3-47ae-b560-c19532bedd93_4580x2615.png" width="1456" height="831" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cfb78731-5ff3-47ae-b560-c19532bedd93_4580x2615.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:831,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:657021,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesigncodex.com/i/180480739?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfb78731-5ff3-47ae-b560-c19532bedd93_4580x2615.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!afLc!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfb78731-5ff3-47ae-b560-c19532bedd93_4580x2615.png 424w, https://substackcdn.com/image/fetch/$s_!afLc!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfb78731-5ff3-47ae-b560-c19532bedd93_4580x2615.png 848w, https://substackcdn.com/image/fetch/$s_!afLc!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfb78731-5ff3-47ae-b560-c19532bedd93_4580x2615.png 1272w, https://substackcdn.com/image/fetch/$s_!afLc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfb78731-5ff3-47ae-b560-c19532bedd93_4580x2615.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://app.eraser.io/workspace/tJsRGxsibLOWUZfsT2z4?origin=share">You can play with the diagram on Eraser.io</a></figcaption></figure></div><p>So - have you used any of these patterns?</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/top-microservices-patterns/comments&quot;,&quot;text&quot;:&quot;Leave a comment&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/top-microservices-patterns/comments"><span>Leave a comment</span></a></p><div><hr></div><h1>Shoutout</h1><p>Here are some interesting articles I read this week:</p><ul><li><p><a href="https://thetshaped.dev/p/two-tier-to-three-tier-architecture-migration-case-stuty-modular-monolith-graphql-api-software-architecture?r=1m1f9z&amp;utm_campaign=post&amp;utm_medium=web&amp;showWelcomeOnShare=false">2-Tier to 3-Tier Architecture: Migration Journey With Modular Monolith and GraphQL</a> by <span class="mention-wrap" data-attrs="{&quot;name&quot;:&quot;Petar Ivanov&quot;,&quot;id&quot;:10269058,&quot;type&quot;:&quot;user&quot;,&quot;url&quot;:null,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b236a7ab-735e-49d2-bbe8-98b1f901b169_500x500.jpeg&quot;,&quot;uuid&quot;:&quot;01392dad-7c4e-442d-a753-441715267f0d&quot;}" data-component-name="MentionToDOM"></span> </p></li><li><p><a href="https://newsletter.eng-leadership.com/p/essential-skills-for-engineers-to?utm_campaign=post&amp;utm_medium=web">Essential Skills for Engineers to Thrive in the AI Era</a> by <span class="mention-wrap" data-attrs="{&quot;name&quot;:&quot;Gregor Ojstersek&quot;,&quot;id&quot;:106098672,&quot;type&quot;:&quot;user&quot;,&quot;url&quot;:null,&quot;photo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b7fdc30-d8c4-45f2-b0df-0b60baf9d4f4_1000x1000.jpeg&quot;,&quot;uuid&quot;:&quot;b6963149-26bf-4a40-865c-5869c74d3f8b&quot;}" data-component-name="MentionToDOM"></span> </p></li></ul><div><hr></div><p><strong>That&#8217;s it for today! &#9728;&#65039;</strong></p><p>Enjoyed this issue of the newsletter?</p><p>Share with your friends and colleagues.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesigncodex.com/p/top-microservices-patterns?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesigncodex.com/p/top-microservices-patterns?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p></p>]]></content:encoded></item></channel></rss>