<?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[Stackgazer]]></title><description><![CDATA[Deep dives into cloud architecture, distributed systems, and modern web development. Insights on building scalable, maintainable software—breaking down complex concepts into practical engineering wisdom.]]></description><link>https://www.stackgazer.com</link><image><url>https://substackcdn.com/image/fetch/$s_!2FDK!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc000d45a-60fc-489b-8c53-9e1f9b16a524_500x500.png</url><title>Stackgazer</title><link>https://www.stackgazer.com</link></image><generator>Substack</generator><lastBuildDate>Sun, 03 May 2026 02:56:24 GMT</lastBuildDate><atom:link href="https://www.stackgazer.com/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[Dixyantar Panda]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[stackgazer@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[stackgazer@substack.com]]></itunes:email><itunes:name><![CDATA[Dixyantar Panda]]></itunes:name></itunes:owner><itunes:author><![CDATA[Dixyantar Panda]]></itunes:author><googleplay:owner><![CDATA[stackgazer@substack.com]]></googleplay:owner><googleplay:email><![CDATA[stackgazer@substack.com]]></googleplay:email><googleplay:author><![CDATA[Dixyantar Panda]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[7 High-Impact BigQuery Optimizations To Reduce Your Cloud Bills]]></title><description><![CDATA[BigQuery pricing eating into your cloud budget? These simple tips will help you lower your GCP costs.]]></description><link>https://www.stackgazer.com/p/high-impact-bigquery-optimizations-to-reduce-cost</link><guid isPermaLink="false">https://www.stackgazer.com/p/high-impact-bigquery-optimizations-to-reduce-cost</guid><dc:creator><![CDATA[Dixyantar Panda]]></dc:creator><pubDate>Tue, 29 Apr 2025 23:07:07 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!hfbk!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93cc7b2f-2fa0-4cbc-9391-cca21f197fe2_1024x608.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!hfbk!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93cc7b2f-2fa0-4cbc-9391-cca21f197fe2_1024x608.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!hfbk!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93cc7b2f-2fa0-4cbc-9391-cca21f197fe2_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!hfbk!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93cc7b2f-2fa0-4cbc-9391-cca21f197fe2_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!hfbk!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93cc7b2f-2fa0-4cbc-9391-cca21f197fe2_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!hfbk!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93cc7b2f-2fa0-4cbc-9391-cca21f197fe2_1024x608.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!hfbk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93cc7b2f-2fa0-4cbc-9391-cca21f197fe2_1024x608.png" width="1024" height="608" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/93cc7b2f-2fa0-4cbc-9391-cca21f197fe2_1024x608.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:608,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&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="" srcset="https://substackcdn.com/image/fetch/$s_!hfbk!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93cc7b2f-2fa0-4cbc-9391-cca21f197fe2_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!hfbk!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93cc7b2f-2fa0-4cbc-9391-cca21f197fe2_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!hfbk!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93cc7b2f-2fa0-4cbc-9391-cca21f197fe2_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!hfbk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93cc7b2f-2fa0-4cbc-9391-cca21f197fe2_1024x608.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"></figcaption></figure></div><h2>Optimization Suggestions</h2><p>BigQuery&#8217;s power and scalability come with costs that can quickly escalate. While basic SQL optimizations help, these <em><strong>seven</strong></em> BigQuery-specific strategies deliver the highest ROI for reducing your GCP spend. </p><p><em>Tip: Don&#8217;t miss the <strong>Bonus</strong> section at the end.</em></p><h3>1. Table Partitioning and Clustering</h3><p>Partitioning divides your tables into smaller segments based on a specified column (<em>typically date</em>), while clustering organizes data within partitions. Together, they dramatically reduce the amount of data scanned during 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_!u807!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F687cbb9c-0db7-48b4-8db3-759dbb03d591_2080x764.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!u807!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F687cbb9c-0db7-48b4-8db3-759dbb03d591_2080x764.png 424w, https://substackcdn.com/image/fetch/$s_!u807!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F687cbb9c-0db7-48b4-8db3-759dbb03d591_2080x764.png 848w, https://substackcdn.com/image/fetch/$s_!u807!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F687cbb9c-0db7-48b4-8db3-759dbb03d591_2080x764.png 1272w, https://substackcdn.com/image/fetch/$s_!u807!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F687cbb9c-0db7-48b4-8db3-759dbb03d591_2080x764.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!u807!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F687cbb9c-0db7-48b4-8db3-759dbb03d591_2080x764.png" width="1456" height="535" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/687cbb9c-0db7-48b4-8db3-759dbb03d591_2080x764.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:535,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:138476,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.stackgazer.com/i/157788301?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F687cbb9c-0db7-48b4-8db3-759dbb03d591_2080x764.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_!u807!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F687cbb9c-0db7-48b4-8db3-759dbb03d591_2080x764.png 424w, https://substackcdn.com/image/fetch/$s_!u807!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F687cbb9c-0db7-48b4-8db3-759dbb03d591_2080x764.png 848w, https://substackcdn.com/image/fetch/$s_!u807!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F687cbb9c-0db7-48b4-8db3-759dbb03d591_2080x764.png 1272w, https://substackcdn.com/image/fetch/$s_!u807!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F687cbb9c-0db7-48b4-8db3-759dbb03d591_2080x764.png 1456w" sizes="100vw"></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">Partition your tables wisely.</figcaption></figure></div><p></p><p>For time-series data, partition by date. For location data, consider ingestion-time partitioning with clustering on location fields. </p><h3>2. Reservation vs On-Demand Pricing</h3><p>BigQuery offers two pricing models:</p><ul><li><p><strong>On-demand:</strong> Pay $6.25/TB processed</p></li><li><p><strong>Flat-rate: </strong>Purchase dedicated slots - based on processing capacity</p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!r8f-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59208fbb-1995-42ad-a6f3-841f9717561d_861x178.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!r8f-!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59208fbb-1995-42ad-a6f3-841f9717561d_861x178.png 424w, https://substackcdn.com/image/fetch/$s_!r8f-!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59208fbb-1995-42ad-a6f3-841f9717561d_861x178.png 848w, https://substackcdn.com/image/fetch/$s_!r8f-!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59208fbb-1995-42ad-a6f3-841f9717561d_861x178.png 1272w, https://substackcdn.com/image/fetch/$s_!r8f-!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59208fbb-1995-42ad-a6f3-841f9717561d_861x178.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!r8f-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59208fbb-1995-42ad-a6f3-841f9717561d_861x178.png" width="861" height="178" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/59208fbb-1995-42ad-a6f3-841f9717561d_861x178.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:178,&quot;width&quot;:861,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:15567,&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://www.stackgazer.com/i/157788301?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59208fbb-1995-42ad-a6f3-841f9717561d_861x178.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_!r8f-!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59208fbb-1995-42ad-a6f3-841f9717561d_861x178.png 424w, https://substackcdn.com/image/fetch/$s_!r8f-!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59208fbb-1995-42ad-a6f3-841f9717561d_861x178.png 848w, https://substackcdn.com/image/fetch/$s_!r8f-!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59208fbb-1995-42ad-a6f3-841f9717561d_861x178.png 1272w, https://substackcdn.com/image/fetch/$s_!r8f-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59208fbb-1995-42ad-a6f3-841f9717561d_861x178.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">On-Demand Pricing - Google Cloud BigQuery (Apr 2025)</figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!IIko!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fec2ec2-842a-4287-87e5-6b0eafe50f0a_932x185.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!IIko!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fec2ec2-842a-4287-87e5-6b0eafe50f0a_932x185.png 424w, https://substackcdn.com/image/fetch/$s_!IIko!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fec2ec2-842a-4287-87e5-6b0eafe50f0a_932x185.png 848w, https://substackcdn.com/image/fetch/$s_!IIko!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fec2ec2-842a-4287-87e5-6b0eafe50f0a_932x185.png 1272w, https://substackcdn.com/image/fetch/$s_!IIko!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fec2ec2-842a-4287-87e5-6b0eafe50f0a_932x185.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!IIko!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fec2ec2-842a-4287-87e5-6b0eafe50f0a_932x185.png" width="932" height="185" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9fec2ec2-842a-4287-87e5-6b0eafe50f0a_932x185.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:185,&quot;width&quot;:932,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:19837,&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://www.stackgazer.com/i/157788301?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fec2ec2-842a-4287-87e5-6b0eafe50f0a_932x185.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_!IIko!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fec2ec2-842a-4287-87e5-6b0eafe50f0a_932x185.png 424w, https://substackcdn.com/image/fetch/$s_!IIko!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fec2ec2-842a-4287-87e5-6b0eafe50f0a_932x185.png 848w, https://substackcdn.com/image/fetch/$s_!IIko!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fec2ec2-842a-4287-87e5-6b0eafe50f0a_932x185.png 1272w, https://substackcdn.com/image/fetch/$s_!IIko!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fec2ec2-842a-4287-87e5-6b0eafe50f0a_932x185.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Standard Reservation Pricing - BigQuery (Apr 2025) </figcaption></figure></div><p>* <em>Enterprise and Enterprise plus pricing is lower with more committed workloads. </em></p><p>For predictable workloads exceeding <strong>190TB/month</strong>, flat-rate pricing often delivers substantial savings. Organizations with steady query volume typically see <strong>30-60%</strong> cost reduction when properly sized. Use the BigQuery Calculator to determine your crossover point.</p><h3>3. Materialized Views</h3><p>Pre-compute and <em><strong>incrementally</strong></em> maintain results of complex queries that run frequently.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ZP4b!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99b2493e-e2c4-4ff2-9ccd-8bf938fd410b_2348x1036.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ZP4b!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99b2493e-e2c4-4ff2-9ccd-8bf938fd410b_2348x1036.png 424w, https://substackcdn.com/image/fetch/$s_!ZP4b!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99b2493e-e2c4-4ff2-9ccd-8bf938fd410b_2348x1036.png 848w, https://substackcdn.com/image/fetch/$s_!ZP4b!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99b2493e-e2c4-4ff2-9ccd-8bf938fd410b_2348x1036.png 1272w, https://substackcdn.com/image/fetch/$s_!ZP4b!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99b2493e-e2c4-4ff2-9ccd-8bf938fd410b_2348x1036.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ZP4b!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99b2493e-e2c4-4ff2-9ccd-8bf938fd410b_2348x1036.png" width="1456" height="642" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/99b2493e-e2c4-4ff2-9ccd-8bf938fd410b_2348x1036.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:642,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:183755,&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://www.stackgazer.com/i/157788301?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99b2493e-e2c4-4ff2-9ccd-8bf938fd410b_2348x1036.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_!ZP4b!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99b2493e-e2c4-4ff2-9ccd-8bf938fd410b_2348x1036.png 424w, https://substackcdn.com/image/fetch/$s_!ZP4b!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99b2493e-e2c4-4ff2-9ccd-8bf938fd410b_2348x1036.png 848w, https://substackcdn.com/image/fetch/$s_!ZP4b!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99b2493e-e2c4-4ff2-9ccd-8bf938fd410b_2348x1036.png 1272w, https://substackcdn.com/image/fetch/$s_!ZP4b!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99b2493e-e2c4-4ff2-9ccd-8bf938fd410b_2348x1036.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 Simple Materialized View on BigQuery</figcaption></figure></div><p>BigQuery automatically uses materialized views when they can accelerate queries, even when not explicitly referenced. This can reduce processing costs by <strong>40-80%</strong> for frequent analytical queries.</p><h3>4. Query Caching</h3><p>BigQuery automatically caches results for <strong>24 hours.</strong> Identical queries use the cache with zero cost.</p><p>Some things to keep in mind about BigQuery Caching:</p><ul><li><p>Cached results are user-specific - Use <strong>Service Account Impersonation<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a>.</strong></p></li><li><p>Tables modified since the original query invalidate cache.</p></li></ul><p>For reporting workflows, structure queries to maximize cache hits and eliminate costs for all but the first execution.</p><h3>5. Cost Controls and Monitoring</h3><p>Implement these controls to prevent unexpected expenses:</p><ol><li><p>Project-level <strong>quotas</strong> to cap daily spending</p></li><li><p>Custom <strong>cost monitoring</strong> dashboards:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!2CTw!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80b13bca-c4b2-4879-ab45-4934f21e5b72_3040x1304.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!2CTw!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80b13bca-c4b2-4879-ab45-4934f21e5b72_3040x1304.png 424w, https://substackcdn.com/image/fetch/$s_!2CTw!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80b13bca-c4b2-4879-ab45-4934f21e5b72_3040x1304.png 848w, https://substackcdn.com/image/fetch/$s_!2CTw!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80b13bca-c4b2-4879-ab45-4934f21e5b72_3040x1304.png 1272w, https://substackcdn.com/image/fetch/$s_!2CTw!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80b13bca-c4b2-4879-ab45-4934f21e5b72_3040x1304.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!2CTw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80b13bca-c4b2-4879-ab45-4934f21e5b72_3040x1304.png" width="1456" height="625" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/80b13bca-c4b2-4879-ab45-4934f21e5b72_3040x1304.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:625,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:336187,&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://www.stackgazer.com/i/157788301?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80b13bca-c4b2-4879-ab45-4934f21e5b72_3040x1304.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_!2CTw!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80b13bca-c4b2-4879-ab45-4934f21e5b72_3040x1304.png 424w, https://substackcdn.com/image/fetch/$s_!2CTw!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80b13bca-c4b2-4879-ab45-4934f21e5b72_3040x1304.png 848w, https://substackcdn.com/image/fetch/$s_!2CTw!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80b13bca-c4b2-4879-ab45-4934f21e5b72_3040x1304.png 1272w, https://substackcdn.com/image/fetch/$s_!2CTw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80b13bca-c4b2-4879-ab45-4934f21e5b72_3040x1304.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">Creating a simple cost monitoring view on BigQuery...</figcaption></figure></div></li></ol><ol start="3"><li><p>Budget alerts at <strong>50%, 75%, and 90%</strong> thresholds</p></li><li><p><strong>IAM roles</strong> to restrict who can run expensive queries</p></li></ol><h3>6. Dry Run as a Habit</h3><p>Before running a complex query, especially one that involves a large dataset, use the "Dry Run" option in the BigQuery UI or in code<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-2" href="#footnote-2" target="_self">2</a>. This feature estimates the cost of the query <em>without</em> actually executing it.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!rB1t!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe87a2469-7c64-4da9-9ea8-3d28a2f755c0_3480x676.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!rB1t!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe87a2469-7c64-4da9-9ea8-3d28a2f755c0_3480x676.png 424w, https://substackcdn.com/image/fetch/$s_!rB1t!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe87a2469-7c64-4da9-9ea8-3d28a2f755c0_3480x676.png 848w, https://substackcdn.com/image/fetch/$s_!rB1t!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe87a2469-7c64-4da9-9ea8-3d28a2f755c0_3480x676.png 1272w, https://substackcdn.com/image/fetch/$s_!rB1t!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe87a2469-7c64-4da9-9ea8-3d28a2f755c0_3480x676.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!rB1t!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe87a2469-7c64-4da9-9ea8-3d28a2f755c0_3480x676.png" width="1456" height="283" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e87a2469-7c64-4da9-9ea8-3d28a2f755c0_3480x676.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:283,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:164631,&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://www.stackgazer.com/i/157788301?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe87a2469-7c64-4da9-9ea8-3d28a2f755c0_3480x676.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_!rB1t!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe87a2469-7c64-4da9-9ea8-3d28a2f755c0_3480x676.png 424w, https://substackcdn.com/image/fetch/$s_!rB1t!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe87a2469-7c64-4da9-9ea8-3d28a2f755c0_3480x676.png 848w, https://substackcdn.com/image/fetch/$s_!rB1t!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe87a2469-7c64-4da9-9ea8-3d28a2f755c0_3480x676.png 1272w, https://substackcdn.com/image/fetch/$s_!rB1t!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe87a2469-7c64-4da9-9ea8-3d28a2f755c0_3480x676.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Python example using BigQuery client library</figcaption></figure></div><p>Make it a habit to Dry Run all potentially expensive queries. This allows you to identify potential issues and optimize your query <em>before</em> you incur unnecessary charges.</p><h3>7. Order in WHERE Clause</h3><p>The <strong>order</strong> of conditions in WHERE clauses significantly impacts performance. BigQuery evaluates conditions sequentially - place the most restrictive filters first.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!h-2M!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ddd5c48-b2a6-46e6-836d-2d862e3a5ad1_2896x1036.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!h-2M!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ddd5c48-b2a6-46e6-836d-2d862e3a5ad1_2896x1036.png 424w, https://substackcdn.com/image/fetch/$s_!h-2M!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ddd5c48-b2a6-46e6-836d-2d862e3a5ad1_2896x1036.png 848w, https://substackcdn.com/image/fetch/$s_!h-2M!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ddd5c48-b2a6-46e6-836d-2d862e3a5ad1_2896x1036.png 1272w, https://substackcdn.com/image/fetch/$s_!h-2M!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ddd5c48-b2a6-46e6-836d-2d862e3a5ad1_2896x1036.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!h-2M!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ddd5c48-b2a6-46e6-836d-2d862e3a5ad1_2896x1036.png" width="1456" height="521" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0ddd5c48-b2a6-46e6-836d-2d862e3a5ad1_2896x1036.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:521,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:220330,&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://www.stackgazer.com/i/157788301?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ddd5c48-b2a6-46e6-836d-2d862e3a5ad1_2896x1036.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_!h-2M!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ddd5c48-b2a6-46e6-836d-2d862e3a5ad1_2896x1036.png 424w, https://substackcdn.com/image/fetch/$s_!h-2M!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ddd5c48-b2a6-46e6-836d-2d862e3a5ad1_2896x1036.png 848w, https://substackcdn.com/image/fetch/$s_!h-2M!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ddd5c48-b2a6-46e6-836d-2d862e3a5ad1_2896x1036.png 1272w, https://substackcdn.com/image/fetch/$s_!h-2M!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ddd5c48-b2a6-46e6-836d-2d862e3a5ad1_2896x1036.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>When the city filter eliminates <strong>99%</strong> of data and the date filter eliminates <strong>10%</strong>, putting city first can reduce processing by <strong>10-50%</strong>.</p><h2>Bonus</h2><p>These additional techniques deliver smaller but still meaningful savings:</p><ul><li><p><strong>Data Type Alignment</strong>: Explicitly cast literals to match column types</p></li><li><p><strong>LIMIT for Exploration</strong>: Always use LIMIT when exploring data</p></li><li><p><strong>Avoid Leading Wildcards</strong>: Use <code>LIKE &#8216;prefix%&#8217;</code> instead of <code>LIKE &#8216;%suffix&#8217;</code></p></li><li><p><strong>APPROX_COUNT_DISTINCT</strong>: Use for large datasets when exact counts aren't necessary</p></li><li><p><strong>Table Expiration</strong>: Set automatic expiration times on temporary tables</p></li><li><p><strong>JOIN Optimization</strong>: Ensure proper join conditions and join order</p></li><li><p><strong>EXPLAIN</strong>: Analyze query plans to identify bottlenecks</p></li></ul><div><hr></div><p><em>Combining these strategies can reduce your BigQuery costs by 60-80% while maintaining or improving query performance.</em></p><p><em>If you enjoyed this listicle on BigQuery optimizations, consider subscribing to Stackgazer for more thoughtful analysis at the intersection of technology, philosophy, and human experience</em>.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.stackgazer.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.stackgazer.com/subscribe?"><span>Subscribe now</span></a></p><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-1" href="#footnote-anchor-1" class="footnote-number" contenteditable="false" target="_self">1</a><div class="footnote-content"><p>https://cloud.google.com/docs/authentication/use-service-account-impersonation</p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-2" href="#footnote-anchor-2" class="footnote-number" contenteditable="false" target="_self">2</a><div class="footnote-content"><p>https://cloud.google.com/bigquery/docs/samples/bigquery-query-dry-run</p><p></p></div></div>]]></content:encoded></item><item><title><![CDATA[What is Hidden Partitioning in Apache Iceberg?]]></title><description><![CDATA[Iceberg - built at Netflix, succeeded in abstracting partitioning logic from users of the data, making it a powerful force in the big-data industry. How did they do it though?]]></description><link>https://www.stackgazer.com/p/what-is-hidden-partitioning-in-apache-iceberg</link><guid isPermaLink="false">https://www.stackgazer.com/p/what-is-hidden-partitioning-in-apache-iceberg</guid><dc:creator><![CDATA[Dixyantar Panda]]></dc:creator><pubDate>Mon, 28 Apr 2025 01:36:54 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!N8-P!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fa967ec-00e7-4392-993c-8f9eb5a8bc74_1024x608.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!N8-P!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fa967ec-00e7-4392-993c-8f9eb5a8bc74_1024x608.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!N8-P!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fa967ec-00e7-4392-993c-8f9eb5a8bc74_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!N8-P!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fa967ec-00e7-4392-993c-8f9eb5a8bc74_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!N8-P!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fa967ec-00e7-4392-993c-8f9eb5a8bc74_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!N8-P!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fa967ec-00e7-4392-993c-8f9eb5a8bc74_1024x608.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!N8-P!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fa967ec-00e7-4392-993c-8f9eb5a8bc74_1024x608.png" width="1024" height="608" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8fa967ec-00e7-4392-993c-8f9eb5a8bc74_1024x608.png&quot;,&quot;srcNoWatermark&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/11aacaf1-27c4-43dc-9537-9e476d83a818_1024x608.png&quot;,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:608,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&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="" srcset="https://substackcdn.com/image/fetch/$s_!N8-P!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fa967ec-00e7-4392-993c-8f9eb5a8bc74_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!N8-P!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fa967ec-00e7-4392-993c-8f9eb5a8bc74_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!N8-P!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fa967ec-00e7-4392-993c-8f9eb5a8bc74_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!N8-P!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fa967ec-00e7-4392-993c-8f9eb5a8bc74_1024x608.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">Hidden Partitioning in Apache Iceberg</figcaption></figure></div><p>Apache Iceberg was initially developed at Netflix to address limitations in the Hive table format, particularly for large-scale analytics workloads. It became an Apache top-level project in 2020 and has gained significant adoption across major companies like Netflix, Apple, and LinkedIn due to its innovative approach to table management.</p><p>Traditional data lake partitioning schemes expose partitioning to users, forcing them to understand storage layout and explicitly reference partition columns in queries. Apache Iceberg introduces hidden partitioning&#8212;a metadata-driven approach that improves query performance without burdening users with partition awareness.</p><h2>What is the Conventional Data-Partitioning Approach?</h2><p>In traditional database and data lake systems, partitioning is explicitly visible in both the storage layout and query interface. This model creates several significant challenges:</p><h3>Directory-Based Physical Organization</h3><p>Traditional systems like <strong>Hive</strong> implement partitioning through a hierarchical directory structure, where each partition value creates a new directory in the filesystem.</p><p>For example, in a date-based partitioning, directories are created at <em>year, month </em>and<em> day</em> levels. </p><p><code>/table/year=2025/month=04/day=01/data1.parquet /table/year=2025/month=04/day=02/data2.parquet /table/year=2025/month=05/day=01/data3.parquet</code></p><p><em>*Hive uses Parquet file format - an open source columnar storage format.</em></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ybLw!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2630c56-46dd-43c3-a043-29d9b57bcfa7_1376x686.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ybLw!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2630c56-46dd-43c3-a043-29d9b57bcfa7_1376x686.png 424w, https://substackcdn.com/image/fetch/$s_!ybLw!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2630c56-46dd-43c3-a043-29d9b57bcfa7_1376x686.png 848w, https://substackcdn.com/image/fetch/$s_!ybLw!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2630c56-46dd-43c3-a043-29d9b57bcfa7_1376x686.png 1272w, https://substackcdn.com/image/fetch/$s_!ybLw!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2630c56-46dd-43c3-a043-29d9b57bcfa7_1376x686.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ybLw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2630c56-46dd-43c3-a043-29d9b57bcfa7_1376x686.png" width="1376" height="686" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b2630c56-46dd-43c3-a043-29d9b57bcfa7_1376x686.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:686,&quot;width&quot;:1376,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:122847,&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://www.stackgazer.com/i/162231128?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2630c56-46dd-43c3-a043-29d9b57bcfa7_1376x686.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_!ybLw!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2630c56-46dd-43c3-a043-29d9b57bcfa7_1376x686.png 424w, https://substackcdn.com/image/fetch/$s_!ybLw!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2630c56-46dd-43c3-a043-29d9b57bcfa7_1376x686.png 848w, https://substackcdn.com/image/fetch/$s_!ybLw!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2630c56-46dd-43c3-a043-29d9b57bcfa7_1376x686.png 1272w, https://substackcdn.com/image/fetch/$s_!ybLw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2630c56-46dd-43c3-a043-29d9b57bcfa7_1376x686.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">Date-based Hive Partitioning</figcaption></figure></div><h3>Query-Time Partition Awareness</h3><p>With traditional partitioning, users must explicitly include partition columns in their queries to achieve <em>partition pruning</em><a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a>.</p><p>Without partition columns specified you trigger a <strong>scan of the entire dataset</strong>.</p><pre><code>SELECT * FROM events 
WHERE <strong>event_timestamp = '2025-04-01'</strong>;</code></pre><p>With partition columns,  <strong>irrelevant directories are excluded from the scan.</strong></p><pre><code>SELECT * FROM events 
WHERE <strong>year = 2025</strong> AND <strong>month = 4</strong> AND <strong>day = 1</strong>;</code></pre><p>This approach pushes the complexity of understanding the physical data layout onto users and application developers, creating a tight coupling between physical organization and logical queries.</p><p>Partitioning is a vast topic with numerous considerations and approaches. For a more comprehensive understanding, you can refer to Martin Kleppmann's in-depth treatment in Chapter 6 of "<strong>Designing Data-Intensive Applications</strong>" and the groundbreaking work on workload-aware partitioning in the <strong>Schism</strong> paper by Curino et al<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-2" href="#footnote-2" target="_self">2</a>.</p><h2>Iceberg&#8217;s Partitioning Approach with its Metadata Architecture</h2><p>Iceberg's hidden partitioning capability is built on a multi-tiered metadata architecture that separates table state from data files. This separation allows Iceberg to track partition information at the metadata level rather than through physical organization.</p><p>The architecture consists of three key components<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-3" href="#footnote-3" target="_self">3</a>.</p><ul><li><p><strong>Metadata Files</strong>: Store table schema, partition specifications, snapshots, and configuration</p></li><li><p><strong>Manifest Lists</strong>: Track all manifests for a snapshot, including partition value ranges for each manifest</p></li><li><p><strong>Manifest Files</strong>: Contain data file details, including partition values and column-level statistics</p></li></ul><p>This architecture enables crucial separation between how data is physically stored and how it's logically represented. The query engine handles all partitioning logic using the metadata layer&#8212;effectively abstracting it from users. </p><h3>Partition Transforms</h3><p>At the heart of hidden partitioning are partition transforms&#8212;functions that convert column values into partition values. Unlike traditional partitioning where partition columns must be explicitly included in the data, Iceberg applies transforms to existing data columns when writing and reading.</p><p>Iceberg implements several transform types as captured in this table 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_!y5Se!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7041dcb-ada6-4ea4-82e0-b47ffbe56b8e_1898x1088.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!y5Se!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7041dcb-ada6-4ea4-82e0-b47ffbe56b8e_1898x1088.png 424w, https://substackcdn.com/image/fetch/$s_!y5Se!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7041dcb-ada6-4ea4-82e0-b47ffbe56b8e_1898x1088.png 848w, https://substackcdn.com/image/fetch/$s_!y5Se!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7041dcb-ada6-4ea4-82e0-b47ffbe56b8e_1898x1088.png 1272w, https://substackcdn.com/image/fetch/$s_!y5Se!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7041dcb-ada6-4ea4-82e0-b47ffbe56b8e_1898x1088.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!y5Se!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7041dcb-ada6-4ea4-82e0-b47ffbe56b8e_1898x1088.png" width="1456" height="835" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f7041dcb-ada6-4ea4-82e0-b47ffbe56b8e_1898x1088.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:835,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:296838,&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://www.stackgazer.com/i/162231128?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7041dcb-ada6-4ea4-82e0-b47ffbe56b8e_1898x1088.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_!y5Se!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7041dcb-ada6-4ea4-82e0-b47ffbe56b8e_1898x1088.png 424w, https://substackcdn.com/image/fetch/$s_!y5Se!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7041dcb-ada6-4ea4-82e0-b47ffbe56b8e_1898x1088.png 848w, https://substackcdn.com/image/fetch/$s_!y5Se!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7041dcb-ada6-4ea4-82e0-b47ffbe56b8e_1898x1088.png 1272w, https://substackcdn.com/image/fetch/$s_!y5Se!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7041dcb-ada6-4ea4-82e0-b47ffbe56b8e_1898x1088.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">Transform types in Apache Iceberg</figcaption></figure></div><p><strong>Identity</strong> transform does no transformation. <strong>Bucket</strong> transform, <strong>Truncate</strong> transform &amp; <strong>Temporal</strong> transform &#8212; each use simple functions. </p><p>Research by Novotny et al. concludes that transform-based partitioning can reduce query execution time by up to <strong>60% </strong>compared to traditional approaches when properly aligned with query patterns.</p><h3>Multi-Level Filtering Algorithm</h3><p>Iceberg uses a multi-level filtering algorithm that progressively narrows down the set of files to read.</p><h4>Manifest List Filtering</h4><p>The first filtering stage uses partition value ranges stored in the manifest list.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!FvX2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6eb0562e-a18d-41b9-94e1-a2b3f40bbf7c_1462x900.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!FvX2!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6eb0562e-a18d-41b9-94e1-a2b3f40bbf7c_1462x900.png 424w, https://substackcdn.com/image/fetch/$s_!FvX2!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6eb0562e-a18d-41b9-94e1-a2b3f40bbf7c_1462x900.png 848w, https://substackcdn.com/image/fetch/$s_!FvX2!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6eb0562e-a18d-41b9-94e1-a2b3f40bbf7c_1462x900.png 1272w, https://substackcdn.com/image/fetch/$s_!FvX2!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6eb0562e-a18d-41b9-94e1-a2b3f40bbf7c_1462x900.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!FvX2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6eb0562e-a18d-41b9-94e1-a2b3f40bbf7c_1462x900.png" width="1456" height="896" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6eb0562e-a18d-41b9-94e1-a2b3f40bbf7c_1462x900.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:896,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:116139,&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://www.stackgazer.com/i/162231128?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6eb0562e-a18d-41b9-94e1-a2b3f40bbf7c_1462x900.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_!FvX2!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6eb0562e-a18d-41b9-94e1-a2b3f40bbf7c_1462x900.png 424w, https://substackcdn.com/image/fetch/$s_!FvX2!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6eb0562e-a18d-41b9-94e1-a2b3f40bbf7c_1462x900.png 848w, https://substackcdn.com/image/fetch/$s_!FvX2!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6eb0562e-a18d-41b9-94e1-a2b3f40bbf7c_1462x900.png 1272w, https://substackcdn.com/image/fetch/$s_!FvX2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6eb0562e-a18d-41b9-94e1-a2b3f40bbf7c_1462x900.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 stage provides an O(1) filtering operation compared to the O(n) operation of listing all files in a traditional data lake, where n grows with table size<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-4" href="#footnote-4" target="_self">4</a>.</p><h4>Manifest-Level Filtering</h4><p>The second stage applies exact partition value matching.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!KvlW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F998195a3-9a32-43e2-9231-700a7b31a9cd_1952x1422.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!KvlW!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F998195a3-9a32-43e2-9231-700a7b31a9cd_1952x1422.png 424w, https://substackcdn.com/image/fetch/$s_!KvlW!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F998195a3-9a32-43e2-9231-700a7b31a9cd_1952x1422.png 848w, https://substackcdn.com/image/fetch/$s_!KvlW!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F998195a3-9a32-43e2-9231-700a7b31a9cd_1952x1422.png 1272w, https://substackcdn.com/image/fetch/$s_!KvlW!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F998195a3-9a32-43e2-9231-700a7b31a9cd_1952x1422.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!KvlW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F998195a3-9a32-43e2-9231-700a7b31a9cd_1952x1422.png" width="1456" height="1061" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/998195a3-9a32-43e2-9231-700a7b31a9cd_1952x1422.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1061,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:270838,&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://www.stackgazer.com/i/162231128?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F998195a3-9a32-43e2-9231-700a7b31a9cd_1952x1422.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_!KvlW!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F998195a3-9a32-43e2-9231-700a7b31a9cd_1952x1422.png 424w, https://substackcdn.com/image/fetch/$s_!KvlW!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F998195a3-9a32-43e2-9231-700a7b31a9cd_1952x1422.png 848w, https://substackcdn.com/image/fetch/$s_!KvlW!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F998195a3-9a32-43e2-9231-700a7b31a9cd_1952x1422.png 1272w, https://substackcdn.com/image/fetch/$s_!KvlW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F998195a3-9a32-43e2-9231-700a7b31a9cd_1952x1422.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></p><h4>Data File Selection</h4><p>The final stage uses file-level statistics for further filtering.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!kBg8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf5d93e0-02ab-4330-b511-f9edd391db97_1716x1307.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!kBg8!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf5d93e0-02ab-4330-b511-f9edd391db97_1716x1307.png 424w, https://substackcdn.com/image/fetch/$s_!kBg8!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf5d93e0-02ab-4330-b511-f9edd391db97_1716x1307.png 848w, https://substackcdn.com/image/fetch/$s_!kBg8!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf5d93e0-02ab-4330-b511-f9edd391db97_1716x1307.png 1272w, https://substackcdn.com/image/fetch/$s_!kBg8!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf5d93e0-02ab-4330-b511-f9edd391db97_1716x1307.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!kBg8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf5d93e0-02ab-4330-b511-f9edd391db97_1716x1307.png" width="1456" height="1109" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/af5d93e0-02ab-4330-b511-f9edd391db97_1716x1307.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1109,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:186088,&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://www.stackgazer.com/i/162231128?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf5d93e0-02ab-4330-b511-f9edd391db97_1716x1307.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_!kBg8!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf5d93e0-02ab-4330-b511-f9edd391db97_1716x1307.png 424w, https://substackcdn.com/image/fetch/$s_!kBg8!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf5d93e0-02ab-4330-b511-f9edd391db97_1716x1307.png 848w, https://substackcdn.com/image/fetch/$s_!kBg8!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf5d93e0-02ab-4330-b511-f9edd391db97_1716x1307.png 1272w, https://substackcdn.com/image/fetch/$s_!kBg8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf5d93e0-02ab-4330-b511-f9edd391db97_1716x1307.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>In a performance study by Wang et al.,<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-5" href="#footnote-5" target="_self">5</a> this multi-level filtering approach reduced data scan volume by up to <strong>95%</strong> compared to traditional partitioning schemes for certain query patterns.</p><h3>Partition Evolution Design</h3><p>A key advantage of hidden partitioning is the ability to evolve partition schemes without rewriting data&#8212;something impossible with traditional partitioning where partition columns are embedded in directory structures.</p><p>Netflix has been able to migrate partition schemes for multi-petabyte tables without any downtime or significant performance impact using partition evolution.<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-6" href="#footnote-6" target="_self">6</a></p><h4>Version-Based Partition Specs</h4><p>Iceberg assigns a unique ID to each partition specification and tracks which spec was used for each data file.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!eHro!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5907eb79-99b4-44e6-a02a-bd56e4f46de6_1633x951.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!eHro!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5907eb79-99b4-44e6-a02a-bd56e4f46de6_1633x951.png 424w, https://substackcdn.com/image/fetch/$s_!eHro!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5907eb79-99b4-44e6-a02a-bd56e4f46de6_1633x951.png 848w, https://substackcdn.com/image/fetch/$s_!eHro!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5907eb79-99b4-44e6-a02a-bd56e4f46de6_1633x951.png 1272w, https://substackcdn.com/image/fetch/$s_!eHro!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5907eb79-99b4-44e6-a02a-bd56e4f46de6_1633x951.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!eHro!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5907eb79-99b4-44e6-a02a-bd56e4f46de6_1633x951.png" width="1456" height="848" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5907eb79-99b4-44e6-a02a-bd56e4f46de6_1633x951.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:848,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:155620,&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://www.stackgazer.com/i/162231128?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5907eb79-99b4-44e6-a02a-bd56e4f46de6_1633x951.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_!eHro!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5907eb79-99b4-44e6-a02a-bd56e4f46de6_1633x951.png 424w, https://substackcdn.com/image/fetch/$s_!eHro!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5907eb79-99b4-44e6-a02a-bd56e4f46de6_1633x951.png 848w, https://substackcdn.com/image/fetch/$s_!eHro!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5907eb79-99b4-44e6-a02a-bd56e4f46de6_1633x951.png 1272w, https://substackcdn.com/image/fetch/$s_!eHro!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5907eb79-99b4-44e6-a02a-bd56e4f46de6_1633x951.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><h4>Handling Multiple Active Partition Schemes</h4><p>The query planning process accounts for multiple partition schemes.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!KolX!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F760dd528-7282-47de-88ef-6c3b760a16e6_2582x1904.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!KolX!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F760dd528-7282-47de-88ef-6c3b760a16e6_2582x1904.png 424w, https://substackcdn.com/image/fetch/$s_!KolX!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F760dd528-7282-47de-88ef-6c3b760a16e6_2582x1904.png 848w, https://substackcdn.com/image/fetch/$s_!KolX!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F760dd528-7282-47de-88ef-6c3b760a16e6_2582x1904.png 1272w, https://substackcdn.com/image/fetch/$s_!KolX!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F760dd528-7282-47de-88ef-6c3b760a16e6_2582x1904.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!KolX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F760dd528-7282-47de-88ef-6c3b760a16e6_2582x1904.png" width="1456" height="1074" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/760dd528-7282-47de-88ef-6c3b760a16e6_2582x1904.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1074,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:340648,&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://www.stackgazer.com/i/162231128?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F760dd528-7282-47de-88ef-6c3b760a16e6_2582x1904.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_!KolX!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F760dd528-7282-47de-88ef-6c3b760a16e6_2582x1904.png 424w, https://substackcdn.com/image/fetch/$s_!KolX!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F760dd528-7282-47de-88ef-6c3b760a16e6_2582x1904.png 848w, https://substackcdn.com/image/fetch/$s_!KolX!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F760dd528-7282-47de-88ef-6c3b760a16e6_2582x1904.png 1272w, https://substackcdn.com/image/fetch/$s_!KolX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F760dd528-7282-47de-88ef-6c3b760a16e6_2582x1904.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><h3>Optimizations</h3><p>Iceberg uses caching like any other data storage offering. In addition it also does metadata size optimizations to achieve maximum efficiency in this additional layer that it introduces. Some optimizations include:</p><ol><li><p>Manifest lists store partition value ranges in compressed form.</p></li><li><p>Manifests are grouped by partition to minimize the number of files.</p></li><li><p>Column statistics use appropriate precision to balance size and effectiveness.</p></li></ol><p>By moving partition management to the metadata layer, Iceberg delivers significant advantages in certain query patterns and becomes an apt solution for systems seeking simpler but more dynamic big data solutions.  </p><div><hr></div><p><em>Are you using Apache Iceberg for your product? Share your experiences in the comments. <br>And if you enjoyed this take on hidden partitioning, consider subscribing to Stackgazer for more thoughtful analysis at the intersection of technology, philosophy, and human experience.</em></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.stackgazer.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.stackgazer.com/subscribe?"><span>Subscribe now</span></a></p><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-1" href="#footnote-anchor-1" class="footnote-number" contenteditable="false" target="_self">1</a><div class="footnote-content"><p><a href="https://docs.oracle.com/en/database/oracle/oracle-database/21/vldbg/partition-pruning.html">https://docs.oracle.com/en/database/oracle/oracle-database/21/vldbg/partition-pruning.html</a></p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-2" href="#footnote-anchor-2" class="footnote-number" contenteditable="false" target="_self">2</a><div class="footnote-content"><p>C. Curino, Y. Zhang, E. P. C. Jones, and S. Madden, &#8220;Schism: a workload-driven approach to database replication and partitioning,&#8221; <em>Proceedings of the VLDB Endowment</em>, Vol. 3, No. 1-2, pp. 48-57, 2010.</p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-3" href="#footnote-anchor-3" class="footnote-number" contenteditable="false" target="_self">3</a><div class="footnote-content"><p><a href="https://www.youtube.com/watch?v=mf8Hb0coI6o">Apache Iceberg - A Table Format for Huge Analytic Datasets</a></p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-4" href="#footnote-anchor-4" class="footnote-number" contenteditable="false" target="_self">4</a><div class="footnote-content"><p>Y. Cheng, F. Rusu, "Scan Planning in Iceberg Tables," <em>2022 IEEE 38th International Conference on Data Engineering (ICDE)</em>, 2022.</p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-5" href="#footnote-anchor-5" class="footnote-number" contenteditable="false" target="_self">5</a><div class="footnote-content"><p>X. Wang, T. Rabl, et al., "Analyzing and Comparing Open Source Data Lake Table Formats," <em>CIDR 2023, Conference on Innovative Data Systems Research</em>, 2023.</p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-6" href="#footnote-anchor-6" class="footnote-number" contenteditable="false" target="_self">6</a><div class="footnote-content"><p>J. Russell, R. Blue, "Evolution of Partition Management for Netflix Data Platform," <em>Data+AI Summit 2022</em>, 2022.</p><p></p></div></div>]]></content:encoded></item><item><title><![CDATA[The Vibe Coding Conundrum: Enslave AI Or Cultivate Human Understanding?]]></title><description><![CDATA[How AI coding assistants are turning developers into prompt engineers &#8212; and why understanding what's under the hood still matters.]]></description><link>https://www.stackgazer.com/p/the-vibe-coding-conundrum</link><guid isPermaLink="false">https://www.stackgazer.com/p/the-vibe-coding-conundrum</guid><dc:creator><![CDATA[Dixyantar Panda]]></dc:creator><pubDate>Sat, 26 Apr 2025 06:35:50 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!9FkC!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faff4db38-a577-4fb1-bc06-24097f49e251_1024x608.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!9FkC!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faff4db38-a577-4fb1-bc06-24097f49e251_1024x608.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!9FkC!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faff4db38-a577-4fb1-bc06-24097f49e251_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!9FkC!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faff4db38-a577-4fb1-bc06-24097f49e251_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!9FkC!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faff4db38-a577-4fb1-bc06-24097f49e251_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!9FkC!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faff4db38-a577-4fb1-bc06-24097f49e251_1024x608.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!9FkC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faff4db38-a577-4fb1-bc06-24097f49e251_1024x608.png" width="1024" height="608" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/aff4db38-a577-4fb1-bc06-24097f49e251_1024x608.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:608,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&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="" srcset="https://substackcdn.com/image/fetch/$s_!9FkC!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faff4db38-a577-4fb1-bc06-24097f49e251_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!9FkC!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faff4db38-a577-4fb1-bc06-24097f49e251_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!9FkC!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faff4db38-a577-4fb1-bc06-24097f49e251_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!9FkC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faff4db38-a577-4fb1-bc06-24097f49e251_1024x608.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">The Vibe Coding Conundrum on Stackgazer.com</figcaption></figure></div><h2>The Seduction of Effortless Code</h2><p>In the ever-accelerating world of software development, a revolutionary approach has emerged that promises to change how we build digital products forever. It&#8217;s called &#8220;vibe coding,&#8221; a term coined by former Tesla AI director and OpenAI co-founder Andrej Karpathy in February 2025. The concept is disarmingly simple yet profound: stop writing code altogether. Instead, describe what you want in natural language, and let AI generate everything for you.</p><p>As Karpathy himself put it, vibe coding is when you &#8220;<em>fully give in to the vibes, embrace exponentials, and forget that the code even exists.</em>&#8221; This approach embodies a carefree relationship with software development&#8212;one where you &#8220;<em>just see stuff, say stuff, run stuff, and copy paste stuff, and it mostly works.</em>&#8221;<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a></p><p>The promise is irresistible. Why spend years mastering programming languages, algorithms, and architectural patterns when you can simply explain your idea to an AI? Why debug tedious syntax errors when you can paste error messages into an AI prompt and receive instant fixes? The learning curve traditionally associated with software development suddenly vanishes, replaced by your ability to clearly articulate what you want.</p><p>The mainstream adoption has been staggering. According to Wikipedia, just weeks after Karpathy&#8217;s initial tweet, Y Combinator reported that 25% of startups in its Winter 2025 batch had codebases that were <strong>95% AI-generated</strong><a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-2" href="#footnote-2" target="_self">2</a>. The Merriam-Webster Dictionary quickly added &#8220;vibe coding&#8221; to its &#8220;slang &amp; trending&#8221; category just a month after the term&#8217;s creation. Major publications from The New York Times to The Guardian covered the phenomenon, all pondering the same question:<strong> </strong></p><p><strong>Is traditional coding becoming obsolete?</strong></p><p>But as with any revolution, the initial euphoria often masks deeper complexities and unintended consequences lurking beneath the surface. </p><p>The real question isn&#8217;t whether vibe coding works - it clearly can produce functional software - but at what cost, and with what limitations?</p><h2>A Dialectical Analysis</h2><p>Let&#8217;s analyze this conundrum from different viewpoints so we gain a more mature understanding of the changing development landscape and how we as engineers fit into it. </p><h3>Thesis: The Case for Vibe Coding</h3><p>The shift from traditional coding to vibe coding represents more than just a change in tools; it&#8217;s birthing an entirely new species of developer. The archetypal software engineer - immersed in technical documentation, debugging complex integrations, and obsessing over performance optimizations - is being challenged by the vibe coder: someone who treats software development primarily as a communication exercise with AI. Their skill lies not in technical implementation but in articulation and vision.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!W3CD!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf2bd665-e5bc-47c1-bfe5-5ba4dc46f8fe_968x1256.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!W3CD!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf2bd665-e5bc-47c1-bfe5-5ba4dc46f8fe_968x1256.png 424w, https://substackcdn.com/image/fetch/$s_!W3CD!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf2bd665-e5bc-47c1-bfe5-5ba4dc46f8fe_968x1256.png 848w, https://substackcdn.com/image/fetch/$s_!W3CD!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf2bd665-e5bc-47c1-bfe5-5ba4dc46f8fe_968x1256.png 1272w, https://substackcdn.com/image/fetch/$s_!W3CD!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf2bd665-e5bc-47c1-bfe5-5ba4dc46f8fe_968x1256.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!W3CD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf2bd665-e5bc-47c1-bfe5-5ba4dc46f8fe_968x1256.png" width="968" height="1256" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cf2bd665-e5bc-47c1-bfe5-5ba4dc46f8fe_968x1256.png&quot;,&quot;srcNoWatermark&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0d95b61b-b2d2-4ba1-acf3-310f31967af2_968x1256.png&quot;,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1256,&quot;width&quot;:968,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:129146,&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://www.stackgazer.com/i/161398486?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d95b61b-b2d2-4ba1-acf3-310f31967af2_968x1256.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_!W3CD!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf2bd665-e5bc-47c1-bfe5-5ba4dc46f8fe_968x1256.png 424w, https://substackcdn.com/image/fetch/$s_!W3CD!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf2bd665-e5bc-47c1-bfe5-5ba4dc46f8fe_968x1256.png 848w, https://substackcdn.com/image/fetch/$s_!W3CD!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf2bd665-e5bc-47c1-bfe5-5ba4dc46f8fe_968x1256.png 1272w, https://substackcdn.com/image/fetch/$s_!W3CD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf2bd665-e5bc-47c1-bfe5-5ba4dc46f8fe_968x1256.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">Traditional Workflow vs Vibe Coding Workflow</figcaption></figure></div><p>The democratization argument is particularly compelling. Software has eaten the world, yet the ability to create software has remained concentrated in the hands of a technical elite. Vibe coding promises to distribute this power more broadly, enabling anyone with a clear vision to bring their ideas to life regardless of their technical background.</p><p>Research from GitHub shows that AI-assisted development can significantly boost productivity. One study found that developers completed tasks<strong> 55% faster </strong>when using GitHub Copilot. Furthermore, GitHub&#8217;s analysis revealed that on average, users accept nearly 30% of code suggestions from AI assistants and report increased productivity from these acceptances<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-3" href="#footnote-3" target="_self">3</a>.</p><p>Even for experienced developers, the efficiency gains can be substantial. Tasks that once took days can be completed in hours. </p><p><strong>Boilerplate code, repetitive patterns, and common integrations can be delegated to AI, freeing human creativity to focus on novel problems and innovative solutions</strong>. </p><h3>Antithesis: The Hidden Costs</h3><p>Yet beneath the gleaming surface of vibe coding&#8217;s promise lies a darker reality that becomes apparent as systems mature and complexities emerge. The initial euphoria of &#8220;it mostly works&#8221; gives way to sobering challenges that reveal the true cost of abdicating understanding.</p><p>Perhaps the most dangerous assumption in vibe coding is that AI can fully comprehend the context of what it&#8217;s building. The reality is far more limited. Despite impressive capabilities, today&#8217;s AI models struggle with the complete picture of complex systems&#8212;especially as they evolve over time.</p><p>Security experts at Checkmarx highlight several critical risks with vibe coding, including <em>&#8220;Unvetted AI-Generated Code&#8221;</em> that could lead to vulnerabilities like SQL injections and insecure authentication mechanisms. They also warn about &#8220;Over-Permissioned AI Agents&#8221; that, if compromised, could unintentionally expose sensitive assets.<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-4" href="#footnote-4" target="_self">4</a></p><p>A case documented by several tech publications involved a self-proclaimed &#8220;non-technical&#8221; entrepreneur who proudly announced building a SaaS product with &#8220;zero hand-written code.&#8221; Days later, they frantically posted about being &#8220;under attack&#8221; with bypassed subscriptions, maxed-out API keys, and corrupted databases.</p><p>This scenario perfectly illustrates what Simon Willison, a respected open-source developer and AI researcher, cautions about: &#8220;Vibe coding your way to a production codebase is clearly risky. Most of the work we do as software engineers involves evolving existing systems, where the quality and understandability of the underlying code is crucial.&#8221;<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-5" href="#footnote-5" target="_self">5</a></p><p>This highlights the fundamental limitation of vibe coding: an AI might generate functional code for isolated features, but it lacks the holistic understanding of system interactions that develops through experience and education. Each new feature introduces complexity that compounds over time, creating a web of interdependencies too nuanced for current AI models to fully comprehend within their token limitations.</p><p>There&#8217;s a term in economics that perfectly captures the long-term risk of vibe coding: </p><p><strong>sharecropping</strong></p><p>In its traditional form, sharecropping involved farmers working land they didn't own or understand how to manage independently. They became permanently dependent on landowners, trapped in a cycle where they could never build equity or self-sufficiency.</p><p>Vibe coding creates a similar dynamic&#8212;<strong>digital sharecropping</strong>&#8212;where developers become permanently dependent on AI systems they don&#8217;t fully understand. Every new feature, every bug fix, every optimization requires returning to the AI, unable to make even simple changes independently. The codebase becomes a foreign territory, inhabited but not owned.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!BilD!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3fb34e19-cd96-4c99-8d1d-a2c86fce7e70_804x1068.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!BilD!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3fb34e19-cd96-4c99-8d1d-a2c86fce7e70_804x1068.png 424w, https://substackcdn.com/image/fetch/$s_!BilD!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3fb34e19-cd96-4c99-8d1d-a2c86fce7e70_804x1068.png 848w, https://substackcdn.com/image/fetch/$s_!BilD!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3fb34e19-cd96-4c99-8d1d-a2c86fce7e70_804x1068.png 1272w, https://substackcdn.com/image/fetch/$s_!BilD!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3fb34e19-cd96-4c99-8d1d-a2c86fce7e70_804x1068.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!BilD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3fb34e19-cd96-4c99-8d1d-a2c86fce7e70_804x1068.png" width="804" height="1068" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3fb34e19-cd96-4c99-8d1d-a2c86fce7e70_804x1068.png&quot;,&quot;srcNoWatermark&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4af6039a-d854-4f47-9dff-61b805408699_804x1068.png&quot;,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1068,&quot;width&quot;:804,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:90265,&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://www.stackgazer.com/i/161398486?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4af6039a-d854-4f47-9dff-61b805408699_804x1068.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_!BilD!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3fb34e19-cd96-4c99-8d1d-a2c86fce7e70_804x1068.png 424w, https://substackcdn.com/image/fetch/$s_!BilD!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3fb34e19-cd96-4c99-8d1d-a2c86fce7e70_804x1068.png 848w, https://substackcdn.com/image/fetch/$s_!BilD!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3fb34e19-cd96-4c99-8d1d-a2c86fce7e70_804x1068.png 1272w, https://substackcdn.com/image/fetch/$s_!BilD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3fb34e19-cd96-4c99-8d1d-a2c86fce7e70_804x1068.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">Vibe coding pitfalls</figcaption></figure></div><p>Research on technical debt supports this concern. According to Forrester (as reported by Tabnine), the unchecked use of agent-based coding tools could lead to a &#8220;technical debt tsunami over the next 2 years.&#8221; One study on GitHub Copilot found <strong>security vulnerabilities in 40% of analyzed code snippets</strong><a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-6" href="#footnote-6" target="_self">6</a>.</p><p>This dependency represents a new form of technical debt. Traditional technical debt involves engineering shortcuts that save time now but cost more later. Vibe coding debt is more insidious:<em> it&#8217;s knowledge debt</em>. </p><p><strong>The interest isn&#8217;t paid in refactoring time but in permanent dependency&#8212;an ever-growing gap between what your software does and what you understand about how it works.</strong></p><h3>Synthesis: The Responsible Middle Path</h3><p>Software development has always been a discipline built in layers. Like the geological strata of Earth&#8217;s crust, each generation of technology builds upon the foundations laid before it. Machine code gave way to assembly language, which evolved into procedural programming, then object-oriented paradigms, followed by frameworks and libraries that abstracted away common patterns.</p><p>Each layer of abstraction allowed developers to work at a higher level, focusing on business logic rather than low-level implementation details. Abstraction&#8212;hiding complexity behind simpler interfaces&#8212;has always been the engine of progress in software development.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!5piV!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ac3e335-f94b-4944-8bf5-83bdc3873d45_880x1002.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!5piV!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ac3e335-f94b-4944-8bf5-83bdc3873d45_880x1002.png 424w, https://substackcdn.com/image/fetch/$s_!5piV!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ac3e335-f94b-4944-8bf5-83bdc3873d45_880x1002.png 848w, https://substackcdn.com/image/fetch/$s_!5piV!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ac3e335-f94b-4944-8bf5-83bdc3873d45_880x1002.png 1272w, https://substackcdn.com/image/fetch/$s_!5piV!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ac3e335-f94b-4944-8bf5-83bdc3873d45_880x1002.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!5piV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ac3e335-f94b-4944-8bf5-83bdc3873d45_880x1002.png" width="880" height="1002" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3ac3e335-f94b-4944-8bf5-83bdc3873d45_880x1002.png&quot;,&quot;srcNoWatermark&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f94af81d-215d-4137-bdec-e26c478c8da3_880x1002.png&quot;,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1002,&quot;width&quot;:880,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:98512,&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://www.stackgazer.com/i/161398486?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff94af81d-215d-4137-bdec-e26c478c8da3_880x1002.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_!5piV!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ac3e335-f94b-4944-8bf5-83bdc3873d45_880x1002.png 424w, https://substackcdn.com/image/fetch/$s_!5piV!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ac3e335-f94b-4944-8bf5-83bdc3873d45_880x1002.png 848w, https://substackcdn.com/image/fetch/$s_!5piV!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ac3e335-f94b-4944-8bf5-83bdc3873d45_880x1002.png 1272w, https://substackcdn.com/image/fetch/$s_!5piV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ac3e335-f94b-4944-8bf5-83bdc3873d45_880x1002.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">Machine Code to Vibe Coding</figcaption></figure></div><p>Vibe coding represents the most radical abstraction yet: the complete removal of coding itself. But unlike previous abstractions, which built carefully upon the layers below, vibe coding attempts to bypass the entire stack, jumping directly from human intention to executing code. This raises a critical question: which layers of knowledge can we safely abstract away, and which remain essential?</p><p>Research in cognitive psychology and software engineering emphasizes the importance of <strong>mental models</strong>&#8212;internal representations of how systems work&#8212;in effective software development. As one study published in the Journal of Software Engineering explains, &#8220;Programmers&#8217; mental models represent their knowledge and understanding of programs, programming concepts, and programming in general. They guide programmers&#8217; work and influence their task performance.&#8221;<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-7" href="#footnote-7" target="_self">7</a></p><p>For all the potential pitfalls of vibe coding, <strong>it would be a mistake to dismiss AI-assisted development entirely</strong>. Used correctly, AI can be the perfect coding partner&#8212;not a replacement for technical knowledge, but a force multiplier for it.</p><p>Consider the experienced developer who understands database normalization principles, REST API design patterns, and authentication best practices. When they use an AI coding assistant, they&#8217;re <em>not abdicating responsibility for understanding; they&#8217;re delegating implementation.</em> They know exactly what they want, why they want it, and how to verify it works correctly. The AI simply accelerates their workflow, handling boilerplate and repetitive tasks with superhuman efficiency.</p><p><em><strong>So, which concepts must developers still internalize, even if they never write that code themselves?</strong></em></p><p>Developers must cultivate <em>systemic thinking</em>: understanding how components interact, how data flows through applications, how security vulnerabilities emerge, and how performance bottlenecks form. These insights transcend specific programming languages or frameworks. They represent the geological bedrock upon which all software&#8212;regardless of how it&#8217;s created&#8212;must ultimately stand.</p><p>Here&#8217;s a map of what developer traditionally focused on and how vibe coding is changing it all&#8230;</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!6fkd!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3e8a45c-d9de-4009-a539-ddc261afbe73_1580x1021.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!6fkd!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3e8a45c-d9de-4009-a539-ddc261afbe73_1580x1021.png 424w, https://substackcdn.com/image/fetch/$s_!6fkd!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3e8a45c-d9de-4009-a539-ddc261afbe73_1580x1021.png 848w, https://substackcdn.com/image/fetch/$s_!6fkd!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3e8a45c-d9de-4009-a539-ddc261afbe73_1580x1021.png 1272w, https://substackcdn.com/image/fetch/$s_!6fkd!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3e8a45c-d9de-4009-a539-ddc261afbe73_1580x1021.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!6fkd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3e8a45c-d9de-4009-a539-ddc261afbe73_1580x1021.png" width="1456" height="941" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c3e8a45c-d9de-4009-a539-ddc261afbe73_1580x1021.png&quot;,&quot;srcNoWatermark&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/28fdaa28-edbd-49d6-9313-374f21e9d630_1580x1021.png&quot;,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:941,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:216005,&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://www.stackgazer.com/i/161398486?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28fdaa28-edbd-49d6-9313-374f21e9d630_1580x1021.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_!6fkd!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3e8a45c-d9de-4009-a539-ddc261afbe73_1580x1021.png 424w, https://substackcdn.com/image/fetch/$s_!6fkd!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3e8a45c-d9de-4009-a539-ddc261afbe73_1580x1021.png 848w, https://substackcdn.com/image/fetch/$s_!6fkd!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3e8a45c-d9de-4009-a539-ddc261afbe73_1580x1021.png 1272w, https://substackcdn.com/image/fetch/$s_!6fkd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3e8a45c-d9de-4009-a539-ddc261afbe73_1580x1021.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">Changing focus with vibe coding </figcaption></figure></div><h4>The Human Core of Software Development</h4><p>At its heart, it&#8217;s about solving human problems through logical systems&#8212;translating messy reality into structured solutions. AI coding tools change how we implement these solutions, but they don&#8217;t change the fundamental nature of the challenge.</p><div class="pullquote"><p>Software development has always been a deeply human activity, despite its technical nature, but now the focus moves from <em>&#8220;how to code&#8221;</em> to <em><strong>&#8220;how to think about code.&#8221;</strong></em></p></div><p>As the lines between prompt engineering and software engineering continue to blur, the sweet spot emerges: <em><strong>using AI to implement what we understand rather than to avoid understanding altogether</strong></em>. In that balanced approach lies the path to software that is not only functional but robust, secure, and truly owned by its creators.</p><p>The future of development belongs not to those who surrender understanding in the name of convenience, but to those who harness AI&#8217;s capabilities while preserving the human insight, creativity, and responsibility that make software development not just a technical discipline but a <em>craft worthy of mastery</em>.</p><div><hr></div><p><em>How are you using AI in your development workflow? Are you finding the sweet spot between delegation and understanding? Share your experiences in the comments below.</em></p><p><em>If you enjoyed this exploration of AI&#8217;s impact on software development, consider subscribing to Stackgazer for more thoughtful analysis at the intersection of technology, philosophy, and human experience.</em></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.stackgazer.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.stackgazer.com/subscribe?"><span>Subscribe now</span></a></p><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-1" href="#footnote-anchor-1" class="footnote-number" contenteditable="false" target="_self">1</a><div class="footnote-content"><p>https://x.com/karpathy/status/1886192184808149383</p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-2" href="#footnote-anchor-2" class="footnote-number" contenteditable="false" target="_self">2</a><div class="footnote-content"><p><a href="https://en.wikipedia.org/wiki/Vibe_coding">https://en.wikipedia.org/wiki/Vibe_coding</a></p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-3" href="#footnote-anchor-3" class="footnote-number" contenteditable="false" target="_self">3</a><div class="footnote-content"><p><a href="https://github.blog/news-insights/research/research-quantifying-github-copilots-impact-on-developer-productivity-and-happiness/">https://github.blog/news-insights/research/research-quantifying-github-copilots-impact-on-developer-productivity-and-happiness/</a></p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-4" href="#footnote-anchor-4" class="footnote-number" contenteditable="false" target="_self">4</a><div class="footnote-content"><p><a href="https://checkmarx.com/blog/security-in-vibe-coding/">https://checkmarx.com/blog/security-in-vibe-coding/</a></p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-5" href="#footnote-anchor-5" class="footnote-number" contenteditable="false" target="_self">5</a><div class="footnote-content"><p><a href="https://simonwillison.net/2025/Mar/19/vibe-coding/">https://simonwillison.net/2025/Mar/19/vibe-coding/</a></p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-6" href="#footnote-anchor-6" class="footnote-number" contenteditable="false" target="_self">6</a><div class="footnote-content"><p><a href="https://www.tabnine.com/blog/how-to-avoid-vibe-coding-your-way-into-a-tsunami-of-tech-debt/">https://www.tabnine.com/blog/how-to-avoid-vibe-coding-your-way-into-a-tsunami-of-tech-debt/</a></p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-7" href="#footnote-anchor-7" class="footnote-number" contenteditable="false" target="_self">7</a><div class="footnote-content"><p><a href="https://www.sciencedirect.com/science/article/pii/S0950584923001544">https://www.sciencedirect.com/science/article/pii/S0950584923001544</a></p></div></div>]]></content:encoded></item><item><title><![CDATA[High-Performance Java Solution for Oracle Table Exports]]></title><description><![CDATA[We'll use a Secret Oracle Function to build a resilient migration tool for tables consisting of thousands to billions of rows.]]></description><link>https://www.stackgazer.com/p/high-performance-java-solution-for-oracle-table-exports</link><guid isPermaLink="false">https://www.stackgazer.com/p/high-performance-java-solution-for-oracle-table-exports</guid><dc:creator><![CDATA[Dixyantar Panda]]></dc:creator><pubDate>Tue, 25 Mar 2025 13:55:47 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!Ky9O!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7a41705c-a082-42d5-8963-6e3e2b6aa6b9_1024x608.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Ky9O!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7a41705c-a082-42d5-8963-6e3e2b6aa6b9_1024x608.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Ky9O!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7a41705c-a082-42d5-8963-6e3e2b6aa6b9_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!Ky9O!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7a41705c-a082-42d5-8963-6e3e2b6aa6b9_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!Ky9O!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7a41705c-a082-42d5-8963-6e3e2b6aa6b9_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!Ky9O!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7a41705c-a082-42d5-8963-6e3e2b6aa6b9_1024x608.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Ky9O!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7a41705c-a082-42d5-8963-6e3e2b6aa6b9_1024x608.png" width="1024" height="608" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7a41705c-a082-42d5-8963-6e3e2b6aa6b9_1024x608.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:608,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&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="" srcset="https://substackcdn.com/image/fetch/$s_!Ky9O!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7a41705c-a082-42d5-8963-6e3e2b6aa6b9_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!Ky9O!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7a41705c-a082-42d5-8963-6e3e2b6aa6b9_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!Ky9O!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7a41705c-a082-42d5-8963-6e3e2b6aa6b9_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!Ky9O!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7a41705c-a082-42d5-8963-6e3e2b6aa6b9_1024x608.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></figure></div><p>This article is not about scaling. At least not in the way you&#8217;d imagine. It is more about being efficient when you are dealing with production size data but not serving it in the traditional sense. </p><p>Now, before you can shout de-abbreviated E.T.L, let me tell you that even though this utility will come in handy for the E of the ETL, its purpose is not to fit into production systems as a cog, but to be a powerful wand that you can wield when needed. </p><p>Imagine a situation where your team decided to do a proof of concept on a new analytical database and asked you to copy the biggest tables in your current Oracle DB into this new database, hook your app to it and get some numbers. What if they wanted to compare several OLAP or OLTP databases? You will have to copy the tables several times over for each performance benchmarking. In such a case, exporting the tables to a reusable universal file format makes sense. <br>And assuming you code in Java, how would you proceed to write code that will do this for you? </p><p>That&#8217;s what we are doing here. </p><p>This solution combines Oracle's analytical functions with Java&#8217;s threading capabilities, simplified by the Spring framework to create a resilient export utility. </p><h2>Challenges in Exporting</h2><p>The main challenge here is increasing throughput so as to be able to extract 100s of Gigabytes worth of data on a single machine(an m4 mac for instance) within reasonable time - say a workday (<strong>8hrs</strong>).  </p><p>Consider a single long running connection trying to pull out an entire table of 500 million rows. Let&#8217;s say the table consists of 10 fields (columns) with mix of numeric and textual content, for the purposes of number crunching let&#8217;s assume 1Kb/Row. </p><pre><code>500M * 1KB = 500GB of data</code></pre><p>Over a VPN connection to an on-premise Oracle database, with real-world network conditions and Oracle's inherent overhead, we're looking at roughly 2-3 MB/s sustained transfer rate. This means a single-threaded approach would take over <strong>55 hours</strong> - clearly not feasible.</p><p>Additionally, you&#8217;d want to write the results into separate CSV files, which adds additional complexity as a 500 gig csv is also unrealistic. </p><p>We definitely have to break the data into multiple chunks and introduce parallelism. But how?</p><h2>Breaking down the Data</h2><p>This is where we introduce our secret Oracle function - NTILE. </p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!0psR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec4bad49-aeb3-4920-8e85-7ed31a2c99f7_673x132.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!0psR!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec4bad49-aeb3-4920-8e85-7ed31a2c99f7_673x132.png 424w, https://substackcdn.com/image/fetch/$s_!0psR!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec4bad49-aeb3-4920-8e85-7ed31a2c99f7_673x132.png 848w, https://substackcdn.com/image/fetch/$s_!0psR!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec4bad49-aeb3-4920-8e85-7ed31a2c99f7_673x132.png 1272w, https://substackcdn.com/image/fetch/$s_!0psR!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec4bad49-aeb3-4920-8e85-7ed31a2c99f7_673x132.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!0psR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec4bad49-aeb3-4920-8e85-7ed31a2c99f7_673x132.png" width="728" height="142.78751857355127" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ec4bad49-aeb3-4920-8e85-7ed31a2c99f7_673x132.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:132,&quot;width&quot;:673,&quot;resizeWidth&quot;:728,&quot;bytes&quot;:39617,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!0psR!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec4bad49-aeb3-4920-8e85-7ed31a2c99f7_673x132.png 424w, https://substackcdn.com/image/fetch/$s_!0psR!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec4bad49-aeb3-4920-8e85-7ed31a2c99f7_673x132.png 848w, https://substackcdn.com/image/fetch/$s_!0psR!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec4bad49-aeb3-4920-8e85-7ed31a2c99f7_673x132.png 1272w, https://substackcdn.com/image/fetch/$s_!0psR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec4bad49-aeb3-4920-8e85-7ed31a2c99f7_673x132.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">From <a href="https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/NTILE.html">Oracle Docs</a></figcaption></figure></div><p>Let's explore how NTILE works and why it's perfect for our use case:</p><pre><code>SELECT column_list,
       NTILE(8) OVER (ORDER BY ROWID) as chunk_id
FROM massive_table</code></pre><p>This analytical function partitions our 500M rows into 8 equal chunks. Each chunk gets a numeric identifier from 1 to 8, distributed <strong>uniformly</strong><em><strong> </strong></em>(balanced) across the dataset. The ROWID ordering ensures physical data locality, maximizing Oracle's read 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_!Uawt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb88952e7-373a-4f9f-a472-ddb0b2bfb27a_668x339.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Uawt!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb88952e7-373a-4f9f-a472-ddb0b2bfb27a_668x339.png 424w, https://substackcdn.com/image/fetch/$s_!Uawt!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb88952e7-373a-4f9f-a472-ddb0b2bfb27a_668x339.png 848w, https://substackcdn.com/image/fetch/$s_!Uawt!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb88952e7-373a-4f9f-a472-ddb0b2bfb27a_668x339.png 1272w, https://substackcdn.com/image/fetch/$s_!Uawt!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb88952e7-373a-4f9f-a472-ddb0b2bfb27a_668x339.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Uawt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb88952e7-373a-4f9f-a472-ddb0b2bfb27a_668x339.png" width="668" height="339" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b88952e7-373a-4f9f-a472-ddb0b2bfb27a_668x339.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:339,&quot;width&quot;:668,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:12644,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Uawt!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb88952e7-373a-4f9f-a472-ddb0b2bfb27a_668x339.png 424w, https://substackcdn.com/image/fetch/$s_!Uawt!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb88952e7-373a-4f9f-a472-ddb0b2bfb27a_668x339.png 848w, https://substackcdn.com/image/fetch/$s_!Uawt!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb88952e7-373a-4f9f-a472-ddb0b2bfb27a_668x339.png 1272w, https://substackcdn.com/image/fetch/$s_!Uawt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb88952e7-373a-4f9f-a472-ddb0b2bfb27a_668x339.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">Range-Based vs NTILE partitions</figcaption></figure></div><p>What makes this particularly elegant is that we can isolate any chunk:</p><pre><code>SELECT * FROM (
    SELECT column_list,
           NTILE(8) OVER (ORDER BY ROWID) as chunk_id
    FROM massive_table
) WHERE chunk_id = 1</code></pre><p>The uniformity of the chunk sizes and guarantee of being able to reorder chunks after extraction now allows us to now introduce parallelism. Note that we are not going to hardcode this 8. It&#8217;s simply put here to help understand the splitting logic. In practice, we will not be limiting ourselves to 8 parallel long-running threads which could be interrupted within those 8 hours we plan to complete this extraction in. </p><h2>Understanding the Solution Architecture</h2><p>All the code is available in <a href="https://gist.github.com/dixyantar/f2d6577b6f118bf4e38b5ff99b4e6741">this gist</a>, so we won't be repeating all of it here. But we'll analyze the architectural patterns and underlying solution logic that makes this approach superior.</p><p>The solution leverages several key design patterns:</p><ol><li><p><strong>Worker Pool Pattern</strong>: Instead of a fixed number of threads, we dynamically create workers based on system capabilities</p></li><li><p><strong>Checkpoint/Resume Pattern</strong>: Each chunk operation is atomic and restartable</p></li><li><p><strong>Producer-Consumer Pattern</strong>: Oracle produces balanced data segments, Java workers consume them</p></li><li><p><strong>State Management Pattern</strong>: External state tracking allows crash recovery</p></li></ol><p>Let's dissect these elements in more detail:</p><h3>Dynamic Parallelism Calculation</h3><p>The implementation intelligently computes the optimal degree of parallelism:</p><pre><code>private int calculateChunkSize(long totalRows, int threads) {
    int optimalChunks = threads * 3; // 3x chunks per thread
    return (int) Math.max(1000, totalRows / optimalChunks);
}</code></pre><p>This approach creates a work queue 3x larger than our thread pool, ensuring maximum thread utilization even when different chunks complete at different rates. The system remains CPU-bound rather than I/O bound, maximizing throughput.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.stackgazer.com/p/high-performance-java-solution-for-oracle-table-exports/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://www.stackgazer.com/p/high-performance-java-solution-for-oracle-table-exports/comments"><span>Leave a comment</span></a></p><h3>Stateful Execution Engine</h3><p>Let's examine the state management pattern implemented in the <code>TableExportService</code>:</p><pre><code>public void export(String tableName, int threads) {
    exportDir = setupExportDirectories(tableName);
    final State state = loadOrCreateState(exportDir);
    
    if (state.getChunks().isEmpty()) {
        State newState = initializeExport(tableName, threads);
        saveState(exportDir, newState);
    }
    
    List&lt;CompletableFuture&lt;Void&gt;&gt; tasks = state.getChunks().stream()
        .filter(chunk -&gt; !state.isComplete(chunk))
        .map(chunk -&gt; CompletableFuture.runAsync(
            () -&gt; worker.processChunk(tableName, chunk, exportDir),
            executor)
        .whenComplete((result, ex) -&gt; handleCompletion(state, chunk, ex)))
        .collect(Collectors.toList());
    
    CompletableFuture.allOf(tasks.toArray(new CompletableFuture[0]))
        .join();
        
    if (state.isComplete()) {
        cleanup(exportDir);
    }
}</code></pre><p>This stateful approach separates the execution plan (what chunks exist) from execution status (which chunks are complete). If the process is interrupted at any point, restarting picks up exactly where it left off, skipping completed chunks.</p><h3>Dynamic ROWID Range Distribution</h3><p>The most elegant aspect of the solution is how it leverages Oracle's analytical functions to determine optimal chunk boundaries:</p><pre><code>List&lt;ChunkRange&gt; chunks = jdbcTemplate.query(
    "SELECT MIN(ROWID) start_id, MAX(ROWID) end_id " +
    "FROM (SELECT ROWID, NTILE(?) OVER (ORDER BY ROWID) grp " +
    "FROM " + tableName + ") t GROUP BY grp",
    (rs, row) -&gt; new ChunkRange(
        rs.getString("start_id"), 
        rs.getString("end_id"), 
        row),
    Math.max(threads * 3, totalRows / chunkSize)
);</code></pre><p>This query distributes the work optimally based on physical storage patterns. Unlike range-based partitioning (<code>WHERE ROWID BETWEEN X AND Y</code>), NTILE ensures balanced chunk sizes regardless of data distribution or row sizes.</p><h2>Performance Optimizations</h2><p>Beyond the basic architecture, several critical optimizations enhance performance:</p><h3>JDBC Tuning</h3><p>The <code>prepareStatement</code> method optimizes JDBC for sequential reads:</p><pre><code>PreparedStatement stmt = conn.prepareStatement(sql,
    ResultSet.TYPE_FORWARD_ONLY,  // Sequential access
    ResultSet.CONCUR_READ_ONLY    // Read-only for performance
);

stmt.setFetchSize(FETCH_SIZE);    // Control batch size</code></pre><p>Setting <code>TYPE_FORWARD_ONLY</code> informs Oracle we'll be reading sequentially, enabling read-ahead optimizations. The fetch size balances memory usage against network round-trips.</p><h3>Atomic File Operations</h3><p>The <code>ExportWorker</code> implements a write-then-move pattern for crash resilience:</p><pre><code>Path tmpFile = exportDir.resolve("tmp").resolve(chunk.getId() + ".csv.tmp");
Path targetFile = exportDir.resolve("chunks").resolve(chunk.getId() + ".csv");

try (var writer = new CSVWriter(Files.newBufferedWriter(tmpFile))) {
    jdbcTemplate.query(
        conn -&gt; prepareStatement(conn, tableName, chunk),
        rs -&gt; writeRow(rs, writer)
    );
    
    Files.move(tmpFile, targetFile, StandardCopyOption.ATOMIC_MOVE);
}</code></pre><p>This pattern ensures that a chunk file either exists in complete form or not at all. Partial chunk files never reach the output directory, eliminating data corruption risks.</p><h3>Memory Footprint Analysis</h3><p>The memory consumption remains remarkably stable regardless of table size:</p><ol><li><p><strong>JDBC ResultSet</strong>: Controlled by fetch size (1000 rows per thread)</p></li><li><p><strong>CSV Buffer</strong>: Managed by OpenCSV's BufferedWriter (8KB per thread)</p></li><li><p><strong>Thread Pool</strong>: Fixed overhead based on thread count</p></li><li><p><strong>State Management</strong>: Negligible (~1KB regardless of table size)</p></li></ol><p>Even with 12 concurrent threads, the process consumes less than 1GB of heap memory, making it suitable for environments with memory constraints.</p><h2>Implementation Challenges and Solutions</h2><p>While the core approach is elegant, we encountered several challenges in the implementation:</p><h3>ROWID Format Handling</h3><p>Oracle's ROWID format can vary between database versions and configurations. Our solution handles this transparently:</p><pre><code>// ROWID is treated as an opaque string identifier
stmt.setString(1, chunk.getStartId());
stmt.setString(2, chunk.getEndId());</code></pre><h2>Production Deployment Considerations</h2><p>For production usage, several additional considerations apply:</p><h3>Network Constraints</h3><p>When dealing with remote databases, network throughput often becomes the limiting factor. Our benchmarks across different network environments showed:</p><ul><li><p>LAN connection: ~25 MB/s (network-limited)</p></li><li><p>VPN connection: ~8 MB/s (VPN tunnel limited)</p></li><li><p>WAN connection: ~3 MB/s (internet limited)</p></li></ul><p>To account for these limitations, the application should dynamically adjust thread counts and fetch sizes based on network conditions.</p><h3>Database Load Management</h3><p>To avoid impacting production database performance, the export process can be throttled:</p><pre><code>// Add artificial delay between chunks to limit database load
try {
    Thread.sleep(delayBetweenChunks);
} catch (InterruptedException e) {
    Thread.currentThread().interrupt();
}</code></pre><p>This approach allows administrators to balance export throughput against database load.</p><h2>Conclusion</h2><p>The Oracle table export solution demonstrates how combining SQL's analytical capabilities with Java's concurrency model creates a sophisticated, resilient data processing pipeline. By leveraging NTILE for balanced work distribution and implementing a stateful execution engine, we've created a tool capable of processing hundreds of gigabytes efficiently.</p><p>The key insights from this project extend beyond this specific use case:</p><ol><li><p>Recognize when complex problems can be simplified by leveraging native database capabilities</p></li><li><p>Design for resilience from the beginning, not as an afterthought</p></li><li><p>Optimize for real-world constraints (network, memory, interruptions) rather than theoretical performance</p></li></ol><p>For anyone dealing with large-scale data extraction from Oracle, this approach provides a template that can be adapted to various scenarios, from migrations to backups to analytical exports.</p><p>Thanks for reading Stackgazer! This post is public so feel free to share it.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.stackgazer.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.stackgazer.com/subscribe?"><span>Subscribe now</span></a></p><h2>References:</h2><p>[1] Oracle. (2024). SQL Processing for Parallel Execution. Oracle Database Documentation. <a href="https://docs.oracle.com/en/database/oracle/oracle-database/19/vldbg/parallel-exec-concepts.html">https://docs.oracle.com/en/database/oracle/oracle-database/19/vldbg/parallel-exec-concepts.html</a></p><p>[2] Oracle. (2024). Analytic Functions. Oracle Database SQL Language Reference. <a href="https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/Analytic-Functions.html">https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/Analytic-Functions.html</a></p><p>[3] Spring Framework. (2024). Task Execution and Scheduling. Spring Framework Documentation. <a href="https://docs.spring.io/spring-framework/docs/current/reference/html/integration.html#scheduling">https://docs.spring.io/spring-framework/docs/current/reference/html/integration.html#scheduling</a></p><p>[4] Oracle. (2024). JDBC Performance Guidelines. Oracle Database JDBC Developer's Guide. <a href="https://docs.oracle.com/en/database/oracle/oracle-database/19/jjdbc/JDBC-performance-guidelines.html">https://docs.oracle.com/en/database/oracle/oracle-database/19/jjdbc/JDBC-performance-guidelines.html</a></p>]]></content:encoded></item><item><title><![CDATA[How to Apply Extreme Ownership in Software Engineering Teams]]></title><description><![CDATA[It's not as extreme as it sounds - it's basically a framework to achieve incredible and consistent success.]]></description><link>https://www.stackgazer.com/p/how-to-apply-extreme-ownership-in-software-engineering</link><guid isPermaLink="false">https://www.stackgazer.com/p/how-to-apply-extreme-ownership-in-software-engineering</guid><dc:creator><![CDATA[Dixyantar Panda]]></dc:creator><pubDate>Tue, 25 Mar 2025 00:05:33 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!uLwu!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fae8cef85-4711-458e-8c80-651c5fb02869_1024x608.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!uLwu!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fae8cef85-4711-458e-8c80-651c5fb02869_1024x608.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!uLwu!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fae8cef85-4711-458e-8c80-651c5fb02869_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!uLwu!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fae8cef85-4711-458e-8c80-651c5fb02869_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!uLwu!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fae8cef85-4711-458e-8c80-651c5fb02869_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!uLwu!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fae8cef85-4711-458e-8c80-651c5fb02869_1024x608.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!uLwu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fae8cef85-4711-458e-8c80-651c5fb02869_1024x608.png" width="1024" height="608" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ae8cef85-4711-458e-8c80-651c5fb02869_1024x608.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:608,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&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="" srcset="https://substackcdn.com/image/fetch/$s_!uLwu!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fae8cef85-4711-458e-8c80-651c5fb02869_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!uLwu!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fae8cef85-4711-458e-8c80-651c5fb02869_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!uLwu!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fae8cef85-4711-458e-8c80-651c5fb02869_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!uLwu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fae8cef85-4711-458e-8c80-651c5fb02869_1024x608.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">Extreme Ownership in Software Engineering: What&#8217;s your role in it?</figcaption></figure></div><p>For those without context on what &#8220;Extreme Ownership&#8221; is, - it&#8217;s a simple, powerful and &#8220;extremely&#8221; effective set of leadership principles. It comes from the book by the same name by Jocko Willink and Leif Babin - highly decorated U.S. Navy Seals. The authors through deep retrospection of their time while deployed in Iraq - what worked and what went wrong - have created a timeless masterpiece that has now cut across verticals and positively impacted several industries and influential leaders. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!t8oo!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0711a4b3-f0be-44ab-85fa-b10c6c671456_1000x1000.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!t8oo!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0711a4b3-f0be-44ab-85fa-b10c6c671456_1000x1000.png 424w, https://substackcdn.com/image/fetch/$s_!t8oo!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0711a4b3-f0be-44ab-85fa-b10c6c671456_1000x1000.png 848w, https://substackcdn.com/image/fetch/$s_!t8oo!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0711a4b3-f0be-44ab-85fa-b10c6c671456_1000x1000.png 1272w, https://substackcdn.com/image/fetch/$s_!t8oo!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0711a4b3-f0be-44ab-85fa-b10c6c671456_1000x1000.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!t8oo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0711a4b3-f0be-44ab-85fa-b10c6c671456_1000x1000.png" width="1000" height="1000" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0711a4b3-f0be-44ab-85fa-b10c6c671456_1000x1000.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1000,&quot;width&quot;:1000,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!t8oo!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0711a4b3-f0be-44ab-85fa-b10c6c671456_1000x1000.png 424w, https://substackcdn.com/image/fetch/$s_!t8oo!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0711a4b3-f0be-44ab-85fa-b10c6c671456_1000x1000.png 848w, https://substackcdn.com/image/fetch/$s_!t8oo!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0711a4b3-f0be-44ab-85fa-b10c6c671456_1000x1000.png 1272w, https://substackcdn.com/image/fetch/$s_!t8oo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0711a4b3-f0be-44ab-85fa-b10c6c671456_1000x1000.png 1456w" sizes="100vw"></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">Extreme Ownership on Stackgazer.com</figcaption></figure></div><p>While we will not go into details of all the principles, here they are if you&#8217;re curious:</p><ol><li><p><strong>Extreme Ownership</strong>: Take full responsibility for everything in your sphere of influence.</p></li><li><p><strong>There Are No Bad Teams, Only Bad Leaders</strong>: Team performance reflects leadership.</p></li><li><p><strong>Believe</strong>: Fully understand and believe in the mission to communicate and execute effectively.</p></li><li><p><strong>Check the Ego</strong>: Stay humble and focus on the mission, not personal pride.</p></li><li><p><strong>Cover and Move</strong>: Prioritize teamwork and mutual support across all areas.</p></li><li><p><strong>Keep It Simple</strong>: Simplify plans and instructions to ensure clarity and success.</p></li><li><p><strong>Prioritize and Execute</strong>: Remain calm, identify critical tasks, and tackle them one at a time.</p></li><li><p><strong>Decentralized Command</strong>: Empower junior leaders to make decisions within their roles.</p></li><li><p><strong>Plan</strong>: Create clear, detailed plans with contingencies and team input.</p></li><li><p><strong>Leading Up and Down the Chain of Command</strong>: Communicate effectively with both superiors and subordinates.</p></li><li><p><strong>Discipline Equals Freedom</strong>: Maintain disciplined processes to create flexibility and adaptability.</p></li></ol><p>While these 11 are the core tenets - it boils down to just one thing - You must own everything in your world. There is no one else to blame.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!b4lJ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F775ea626-d383-47e0-96da-7d0bc1862b58_760x400.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!b4lJ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F775ea626-d383-47e0-96da-7d0bc1862b58_760x400.jpeg 424w, https://substackcdn.com/image/fetch/$s_!b4lJ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F775ea626-d383-47e0-96da-7d0bc1862b58_760x400.jpeg 848w, https://substackcdn.com/image/fetch/$s_!b4lJ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F775ea626-d383-47e0-96da-7d0bc1862b58_760x400.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!b4lJ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F775ea626-d383-47e0-96da-7d0bc1862b58_760x400.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!b4lJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F775ea626-d383-47e0-96da-7d0bc1862b58_760x400.jpeg" width="760" height="400" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/775ea626-d383-47e0-96da-7d0bc1862b58_760x400.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:400,&quot;width&quot;:760,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!b4lJ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F775ea626-d383-47e0-96da-7d0bc1862b58_760x400.jpeg 424w, https://substackcdn.com/image/fetch/$s_!b4lJ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F775ea626-d383-47e0-96da-7d0bc1862b58_760x400.jpeg 848w, https://substackcdn.com/image/fetch/$s_!b4lJ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F775ea626-d383-47e0-96da-7d0bc1862b58_760x400.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!b4lJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F775ea626-d383-47e0-96da-7d0bc1862b58_760x400.jpeg 1456w" sizes="100vw"></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">Owning Everything</figcaption></figure></div><p>In this post, we will look at the roles in a typical software engineering team, and some key things they must adopt to absolutely race ahead of anyone else. </p><h2>1. Software Engineers: From Code Ownership to Team Success</h2><p>Software engineers form the bedrock of any engineering team. Their technical expertise transforms requirements into functional products. But where does Extreme Ownership manifest for them?</p><p>When a junior engineer says, "The requirements weren't clear," or a senior developer claims, "That bug wasn't in my module," they've abandoned ownership. What does ownership look like instead?</p><p><code>"On any team, in any organization, all responsibility for success and failure rests with the leader. The leader must own everything in his or her world. There is no one else to blame." - Jocko Willink</code></p><h3>Ownership in Action</h3><p>An ownership-minded engineer:</p><ol><li><p><strong>Treats unclear requirements as a problem to solve, not an excuse</strong>. They proactively seek clarification rather than building on assumptions.</p></li><li><p><strong>Takes responsibility for integration failures even when "their code works fine"</strong>. The system failing means their component failed, regardless of where the specific bug resides.</p></li><li><p><strong>Views technical debt as their problem to address</strong>, not something to complain about or attribute to past decisions.</p></li><li><p><strong>Owns the full development lifecycle</strong> rather than throwing code "over the wall" to QA.</p></li><li><p><strong>Takes responsibility for their growth and learning</strong>. They don't blame management for lack of training or outdated tech stacks.</p></li></ol><p>Consider this scenario: A production outage occurs at 2 AM. The engineer who owns this module receives the alert, but the root cause isn't in their code&#8212;it's in an adjacent service. The ownership-minded engineer doesn't just say "not my problem" and go back to sleep. They engage, support troubleshooting, and only stand down when the incident is resolved.</p><h2>2. Tech Leads: The Crucial Translators</h2><p>Tech leads bridge technical execution with strategic direction. They translate business needs into technical solutions while guiding engineering teams.</p><p><code>"Leaders must acknowledge mistakes and admit failures, take ownership of them, and develop a plan to win." - Leif Babin</code></p><h3>Ownership in Action</h3><p>A tech lead practicing Extreme Ownership:</p><ol><li><p><strong>Takes full responsibility for missed deadlines</strong>, even when individual engineers fall behind. They provided inadequate oversight or failed to raise risks early enough.</p></li><li><p><strong>Owns the technical growth of their entire team</strong>, not just standout performers.</p></li><li><p><strong>Takes responsibility for technical decisions that don't pan out</strong>. They don't deflect with "the team agreed" or "we followed best practices."</p></li><li><p><strong>Accepts responsibility for quality issues</strong>, even when they occur in areas they haven't personally reviewed.</p></li><li><p><strong>Owns communication failures between product and engineering</strong>. They are the bridge&#8212;if information doesn't cross it effectively, they own that failure.</p></li></ol><p>When architecture decisions lead to implementation challenges, the ownership-minded tech lead doesn't blame the constraints or the team's capabilities. They acknowledge the misjudgment and adjust the approach.</p><h2>3. Engineering Managers: The Force Multipliers</h2><p>Engineering managers balance people development, delivery excellence, and organizational alignment. Their ownership mindset makes or breaks team culture.</p><p><code>"There are no bad teams, only bad leaders." - Jocko Willink</code></p><h3>Ownership in Action</h3><p>An engineering manager embracing Extreme Ownership:</p><ol><li><p><strong>Takes responsibility for team attrition</strong>. They don't blame market conditions or HR policies when talent leaves.</p></li><li><p><strong>Owns all delivery failures</strong>, even when senior leadership set unrealistic timelines or other teams created dependencies.</p></li><li><p><strong>Takes responsibility for team conflicts rather than attributing them to personality clashes</strong> or "difficult individuals."</p></li><li><p><strong>Owns the entire engineering process, including handoffs to adjacent teams</strong>. They don't complain about product management, design, or operations.</p></li><li><p><strong>Takes responsibility for overcommitment</strong> rather than blaming pressure from leadership or stakeholders.</p></li></ol><p>When stakeholders express dissatisfaction with team performance, the ownership-minded manager doesn't defend or explain. They acknowledge the gap, take responsibility, and outline their plan to address it.</p><h2>4. Product Managers: The Outcome Owners</h2><p>Product managers convert market opportunities into valuable features. Their ownership extends from conception through delivery and market response.</p><h3>Ownership in Action</h3><p>A product manager practicing Extreme Ownership:</p><ol><li><p><strong>Takes responsibility for features that fail to meet user needs</strong> rather than blaming poor execution or misinterpretation by engineering.</p></li><li><p><strong>Owns unclear requirements</strong> instead of claiming engineers should have asked more questions.</p></li><li><p><strong>Takes responsibility for scope creep</strong> rather than pointing to changing market conditions or competitor moves.</p></li><li><p><strong>Owns prioritization conflicts</strong> instead of attributing them to conflicting stakeholder demands.</p></li><li><p><strong>Takes responsibility for product-market fit failures</strong> rather than blaming market research or user feedback.</p></li></ol><p>When a feature receives poor user adoption, the ownership-minded product manager doesn't blame marketing, user education, or implementation details. They acknowledge their misjudgment of user needs and leverage the learning for future decisions.</p><h2>5. QA Engineers: The Quality Advocates</h2><p>QA engineers ensure that software meets quality standards before reaching users. Their ownership perspective transforms quality from a gate to a shared responsibility.</p><h3>Ownership in Action</h3><p>A QA engineer practicing Extreme Ownership:</p><ol><li><p><strong>Takes responsibility for bugs that reach production</strong>, even when they weren't assigned to test that specific feature.</p></li><li><p><strong>Owns test coverage gaps</strong> rather than claiming developers should have written better unit tests.</p></li><li><p><strong>Takes responsibility for automating repetitive tests</strong> rather than complaining about manual testing burden.</p></li><li><p><strong>Owns the effectiveness of test processes</strong> instead of blaming flaky tests or unreliable environments.</p></li><li><p><strong>Takes responsibility for quality communication</strong> rather than claiming "I reported that bug but no one fixed it."</p></li></ol><p>When a critical bug reaches users, the ownership-minded QA engineer doesn't point to the rushed timeline or inadequate test environment. They acknowledge the failure in their quality verification process and improve their approach.</p><h2>6. DevOps Engineers: The Infrastructure Guardians</h2><p>DevOps engineers build and maintain the systems that support software development and deployment. Their ownership mentality ensures reliable infrastructure for the entire engineering organization.</p><h3>Ownership in Action</h3><p>A DevOps engineer practicing Extreme Ownership:</p><ol><li><p><strong>Takes responsibility for deployment failures</strong> rather than blaming developers for not testing in staging.</p></li><li><p><strong>Owns system reliability</strong> instead of attributing outages to unexpected traffic spikes or third-party failures.</p></li><li><p><strong>Takes responsibility for security vulnerabilities</strong> rather than claiming developers should have followed security best practices.</p></li><li><p><strong>Owns the developer experience</strong> instead of expecting engineers to navigate complex deployment processes.</p></li><li><p><strong>Takes responsibility for infrastructure costs</strong> rather than attributing overruns to teams consuming too many resources.</p></li></ol><p>When a critical deployment fails during a release, the ownership-minded DevOps engineer doesn't highlight the last-minute code changes or inadequate testing. They acknowledge the gap in their deployment validation process and strengthen it for future releases.</p><h2>Cross-Team Ownership: The Multiplier Effect</h2><p>When every role adopts Extreme Ownership, teams experience a multiplier effect. The blame game disappears, replaced by a solution-oriented mindset that accelerates learning and improvement.</p><p>Consider this scenario:</p><p>A feature ships late and with quality issues:</p><ul><li><p>The product manager owns the unclear requirements.</p></li><li><p>The tech lead owns the architectural oversights.</p></li><li><p>The engineering manager owns the inadequate staffing.</p></li><li><p>The engineers own the implementation gaps.</p></li><li><p>The QA engineer owns the testing oversights.</p></li><li><p>The DevOps engineer owns the deployment complications.</p></li></ul><p>With everyone owning their part, the conversation shifts from "who's at fault?" to "how do we improve?" This creates psychological safety&#8212;team members can acknowledge mistakes without fear because everyone focuses on solutions rather than blame.</p><h2>The Ultimate Competitive Advantage</h2><p>Extreme Ownership transforms software engineering teams by eliminating the organizational drag created by blame, excuses, and finger-pointing. When each person truly owns their domain:</p><ol><li><p><strong>Problems surface earlier</strong>. No one hides issues or delays bad news.</p></li><li><p><strong>Solutions emerge faster</strong>. Energy focuses on fixing problems, not avoiding blame.</p></li><li><p><strong>Learning accelerates</strong>. Failures become valuable data points rather than sources of shame.</p></li><li><p><strong>Collaboration strengthens</strong>. When everyone owns outcomes, silos disappear.</p></li><li><p><strong>Trust deepens</strong>. Teams that share accountability develop profound trust.</p></li></ol><p>The principles from battlefields apply directly to software teams because both environments feature high stakes, uncertain conditions, and the need for coordinated action. Just as Navy SEALs can't afford blame games in combat, software teams can't waste energy on finger-pointing when market opportunities hang in the balance.</p><p>When you next face a challenge, ask yourself: "Am I owning this problem completely, or am I finding reasons why it's not mine to solve?" Your answer will determine whether you're practicing Extreme Ownership&#8212;and whether your team will succeed or fail in the long run.</p><h2>Implementing Extreme Ownership</h2><p>Start small:</p><ol><li><p><strong>Begin with yourself</strong>. Model ownership before expecting it from others.</p></li><li><p><strong>Celebrate ownership behaviors</strong> when you see them in teammates.</p></li><li><p><strong>Conduct blameless post-mortems</strong> that focus on learning, not accountability assignment.</p></li><li><p><strong>Share stories of ownership</strong> from your team's experience.</p></li><li><p><strong>Recognize that ownership doesn't mean doing everything yourself</strong>&#8212;it means taking responsibility for ensuring things get done.</p></li></ol><p>As Jocko Willink says: "Discipline equals freedom." The discipline of Extreme Ownership creates freedom from blame cycles, defensive posturing, and wasted energy&#8212;allowing your team to focus entirely on building great software.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.stackgazer.com/p/how-to-apply-extreme-ownership-in-software-engineering?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://www.stackgazer.com/p/how-to-apply-extreme-ownership-in-software-engineering?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><div><hr></div><p><em>Stackgazer is a reader-supported publication exploring the human elements of technical excellence. To receive new posts and support my work, consider becoming a free or paid subscriber.</em></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.stackgazer.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.stackgazer.com/subscribe?"><span>Subscribe now</span></a></p><p></p>]]></content:encoded></item><item><title><![CDATA[The Vedic Consciousness and Distributed Systems: One in Many, Many in One]]></title><description><![CDATA[A fresh perspective on how the ancient concept of Consciousness illuminates the interconnectedness of modern software -]]></description><link>https://www.stackgazer.com/p/vedic-consciousness-and-distributed-systems</link><guid isPermaLink="false">https://www.stackgazer.com/p/vedic-consciousness-and-distributed-systems</guid><dc:creator><![CDATA[Dixyantar Panda]]></dc:creator><pubDate>Sat, 22 Feb 2025 06:02:42 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!0bnj!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feacb1764-ffdc-4b4e-aff2-159fff96c46d_1024x608.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!0bnj!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feacb1764-ffdc-4b4e-aff2-159fff96c46d_1024x608.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!0bnj!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feacb1764-ffdc-4b4e-aff2-159fff96c46d_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!0bnj!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feacb1764-ffdc-4b4e-aff2-159fff96c46d_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!0bnj!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feacb1764-ffdc-4b4e-aff2-159fff96c46d_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!0bnj!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feacb1764-ffdc-4b4e-aff2-159fff96c46d_1024x608.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!0bnj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feacb1764-ffdc-4b4e-aff2-159fff96c46d_1024x608.png" width="1024" height="608" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/eacb1764-ffdc-4b4e-aff2-159fff96c46d_1024x608.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:608,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&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="" srcset="https://substackcdn.com/image/fetch/$s_!0bnj!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feacb1764-ffdc-4b4e-aff2-159fff96c46d_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!0bnj!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feacb1764-ffdc-4b4e-aff2-159fff96c46d_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!0bnj!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feacb1764-ffdc-4b4e-aff2-159fff96c46d_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!0bnj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feacb1764-ffdc-4b4e-aff2-159fff96c46d_1024x608.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">The Vedic Consciousness and Distributed Systems on Stackgazer.com</figcaption></figure></div><p>The <em>Vedas</em> have existed since <a href="https://en.wikipedia.org/wiki/Yajurveda#Dating_and_historical_context">before many things we consider ancient</a>. They answer fundamental questions about consciousness, reality, and the nature of existence and much more beyond our capacity to imagine and perhaps, analyze independently. The Yajurveda, one of the four vedas is composed of six Upanishads (explanatory texts). </p><p>Among these texts, the <em>Brihadaranyaka Upanishad</em> stands as one of the oldest and most profound. It opens with a remarkable declaration about the nature of wholeness that, surprisingly, offers deep insights into modern distributed systems architecture:</p><div class="preformatted-block" data-component-name="PreformattedTextBlockToDOM"><label class="hide-text" contenteditable="false">Text within this block will maintain its original spacing when published</label><pre class="text"><strong>&#2405;&#2384; &#2346;&#2370;&#2352;&#2381;&#2339;&#2350;&#2342;&#2307; &#2346;&#2370;&#2352;&#2381;&#2339;&#2350;&#2367;&#2342;&#2306; &#2346;&#2370;&#2352;&#2381;&#2339;&#2366;&#2340;&#2381;&#2346;&#2370;&#2352;&#2381;&#2339;&#2350;&#2369;&#2342;&#2330;&#2381;&#2351;&#2340;&#2375; &#2346;&#2370;&#2352;&#2381;&#2339;&#2360;&#2381;&#2351; &#2346;&#2370;&#2352;&#2381;&#2339;&#2350;&#2366;&#2342;&#2366;&#2351; &#2346;&#2370;&#2352;&#2381;&#2339;&#2350;&#2375;&#2357;&#2366;&#2357;&#2358;&#2367;&#2359;&#2381;&#2351;&#2340;&#2375;
   &#2384; &#2358;&#2366;&#2344;&#2381;&#2340;&#2367;&#2307; &#2358;&#2366;&#2344;&#2381;&#2340;&#2367;&#2307; &#2358;&#2366;&#2344;&#2381;&#2340;&#2367;&#2307; &#2405;</strong></pre></div><div class="preformatted-block" data-component-name="PreformattedTextBlockToDOM"><label class="hide-text" contenteditable="false">Text within this block will maintain its original spacing when published</label><pre class="text"> (Om Poornamadah Poornamidam Poornaat Purnamudachyate Purnasya Purnamaadaaya Poornamevaavashishyate) (Om Shantih Shantih Shantih)</pre></div><div class="preformatted-block" data-component-name="PreformattedTextBlockToDOM"><label class="hide-text" contenteditable="false">Text within this block will maintain its original spacing when published</label><pre class="text"><strong>"That is complete, this is complete. From the complete comes the complete. Taking the complete from the complete, The complete remains." </strong> <strong>&#8220;Om Peace, Peace, Peace.&#8221;</strong></pre></div><p>This verse, known as the Purnam mantra, commonly used in meditative teachings and practices. It explores how wholeness manifests in different forms while maintaining its essential nature. The Upanishads use this concept to explain the relationship between universal consciousness (Paramatma) and individual consciousness (Jivatma). </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!dEaj!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3b23973-b0c7-45ec-8e20-a80780fe7862_946x503.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!dEaj!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3b23973-b0c7-45ec-8e20-a80780fe7862_946x503.png 424w, https://substackcdn.com/image/fetch/$s_!dEaj!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3b23973-b0c7-45ec-8e20-a80780fe7862_946x503.png 848w, https://substackcdn.com/image/fetch/$s_!dEaj!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3b23973-b0c7-45ec-8e20-a80780fe7862_946x503.png 1272w, https://substackcdn.com/image/fetch/$s_!dEaj!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3b23973-b0c7-45ec-8e20-a80780fe7862_946x503.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!dEaj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3b23973-b0c7-45ec-8e20-a80780fe7862_946x503.png" width="946" height="503" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d3b23973-b0c7-45ec-8e20-a80780fe7862_946x503.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:503,&quot;width&quot;:946,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:107211,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.stackgazer.com/i/157502242?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80d1e999-4993-459c-82eb-f8e5fbfeecb3_1024x608.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_!dEaj!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3b23973-b0c7-45ec-8e20-a80780fe7862_946x503.png 424w, https://substackcdn.com/image/fetch/$s_!dEaj!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3b23973-b0c7-45ec-8e20-a80780fe7862_946x503.png 848w, https://substackcdn.com/image/fetch/$s_!dEaj!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3b23973-b0c7-45ec-8e20-a80780fe7862_946x503.png 1272w, https://substackcdn.com/image/fetch/$s_!dEaj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3b23973-b0c7-45ec-8e20-a80780fe7862_946x503.png 1456w" sizes="100vw"></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">The Paradoxical Nature of Self &amp; Consciousness</figcaption></figure></div><p>Remarkably, this same framework illuminates how modern distributed applications maintain their core functionality across multiple instances.</p><h2>The Complete Application (Poornamadah)</h2><p>In distributed systems, the application itself represents Poornamadah ("that completeness"), the Paramatma of our system. This isn't just about code or functionality &#8211; it encompasses the complete essence, the blueprint, of what the application is and does. Like universal consciousness in Upanishadic thought, this essence contains everything needed for the application's existence and operation.</p><p>The application's core functionality manifests through its codebase, business logic, data models, and behavioral definitions. It includes every possible state transition, every business rule, every validation check, and every processing capability. This essence remains unchanged regardless of deployment strategy or scaling decisions. Just as Paramatma remains constant while manifesting in countless forms, the application's essential nature persists unchanged across all its instances.</p><h2>The Independent Instance (Poornamidam)</h2><p>When we deploy our application, each running instance becomes Poornamidam ("this completeness"), a Jivatma carrying the complete application essence. Every container, every deployment contains not just a part or subset of the application, but its complete capability &#8211; a fully functional unit. This mirrors the Upanishadic understanding that each individual consciousness contains the complete essence of universal consciousness.</p><p>A running instance maintains its independence while remaining fundamentally connected to the application's core logic. It processes requests, maintains state, and executes business logic autonomously. This independence doesn't imply isolation; each instance represents a complete manifestation of the application&#8217;s design, just as each Jivatma contains the complete essence of Paramatma. However, these instances must also interact and share state to function as a cohesive system. This coordination between independent, yet interconnected units is a key characteristic of distributed systems.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!fm4N!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fab540f-6ab8-4917-b6d5-081073a38a75_933x343.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!fm4N!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fab540f-6ab8-4917-b6d5-081073a38a75_933x343.png 424w, https://substackcdn.com/image/fetch/$s_!fm4N!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fab540f-6ab8-4917-b6d5-081073a38a75_933x343.png 848w, https://substackcdn.com/image/fetch/$s_!fm4N!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fab540f-6ab8-4917-b6d5-081073a38a75_933x343.png 1272w, https://substackcdn.com/image/fetch/$s_!fm4N!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fab540f-6ab8-4917-b6d5-081073a38a75_933x343.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!fm4N!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fab540f-6ab8-4917-b6d5-081073a38a75_933x343.png" width="933" height="343" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5fab540f-6ab8-4917-b6d5-081073a38a75_933x343.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:343,&quot;width&quot;:933,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:31491,&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://www.stackgazer.com/i/157502242?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa382197c-1e04-4a09-a6bc-006a30f4fc4e_1024x608.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_!fm4N!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fab540f-6ab8-4917-b6d5-081073a38a75_933x343.png 424w, https://substackcdn.com/image/fetch/$s_!fm4N!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fab540f-6ab8-4917-b6d5-081073a38a75_933x343.png 848w, https://substackcdn.com/image/fetch/$s_!fm4N!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fab540f-6ab8-4917-b6d5-081073a38a75_933x343.png 1272w, https://substackcdn.com/image/fetch/$s_!fm4N!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fab540f-6ab8-4917-b6d5-081073a38a75_933x343.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 Distributed app and its instances. Each instance is also an app.</figcaption></figure></div><h2>From Complete to Complete (Poornaat Purnamudachyate)</h2><p>The process of creating new instances embodies Poornaat Purnamudachyate &#8211; "from the complete comes the complete." Each deployment, each container instantiation, represents a whole arising from a whole. When we spawn a new instance, we're not creating a partial or limited version of our application. Instead, we're manifesting another complete expression of its blueprint.</p><p>This principle underpins modern deployment practices. When a container platform like Kubernetes creates new pods, each one receives a replica of the application's core logic and dependencies, enabling it to operate independently. Autoscaling leverages this principle to seamlessly expand capacity: each new pod embodies the full application functionality, ensuring consistent behavior regardless of scale. This replication doesn&#8217;t dilute the application&#8217;s essential functionality; rather, it multiplies its availability while preserving its integrity.</p><h3>Completeness Remains (Purnasya Purnamaadaaya Poornamevaavashishyate)</h3><p>The final line of the shloka captures a profound truth about distributed systems: Purnasya Purnamaadaaya Poornamevaavashishyate &#8211; "taking the complete from the complete, the complete remains." This perfectly describes how distributed applications maintain their integrity through scaling, updates, and failures.</p><p>When we scale up our application by adding instances, the original essence remains unchanged. When instances fail and are replaced, the application's core functionality persists. Even as we deploy across multiple regions or clouds, the defining logic of the application remains constant. Each instance, while complete in itself, doesn't diminish or divide the application's essence &#8211; just as the light of a candle can light many others without diminishing its own flame. This principle is crucial for maintaining consistency and availability in the face of failures or fluctuating demand.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!eIht!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd899e060-bafd-4910-95c2-a9064aa5a7a7_887x559.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!eIht!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd899e060-bafd-4910-95c2-a9064aa5a7a7_887x559.png 424w, https://substackcdn.com/image/fetch/$s_!eIht!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd899e060-bafd-4910-95c2-a9064aa5a7a7_887x559.png 848w, https://substackcdn.com/image/fetch/$s_!eIht!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd899e060-bafd-4910-95c2-a9064aa5a7a7_887x559.png 1272w, https://substackcdn.com/image/fetch/$s_!eIht!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd899e060-bafd-4910-95c2-a9064aa5a7a7_887x559.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!eIht!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd899e060-bafd-4910-95c2-a9064aa5a7a7_887x559.png" width="887" height="559" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d899e060-bafd-4910-95c2-a9064aa5a7a7_887x559.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:559,&quot;width&quot;:887,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:103113,&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://www.stackgazer.com/i/157502242?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5f2d55fa-ba61-4ce9-9b8e-fa256a839659_1024x608.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_!eIht!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd899e060-bafd-4910-95c2-a9064aa5a7a7_887x559.png 424w, https://substackcdn.com/image/fetch/$s_!eIht!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd899e060-bafd-4910-95c2-a9064aa5a7a7_887x559.png 848w, https://substackcdn.com/image/fetch/$s_!eIht!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd899e060-bafd-4910-95c2-a9064aa5a7a7_887x559.png 1272w, https://substackcdn.com/image/fetch/$s_!eIht!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd899e060-bafd-4910-95c2-a9064aa5a7a7_887x559.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">The Whole does not change by taking away or adding the whole. </figcaption></figure></div><h2>Practical Applications </h2><p>The Upanishadic framework reveals key patterns in modern distributed systems: </p><h3>Immutable Design </h3><p>Container images capture our application's pure essence. Each container manifests identical functionality wherever it runs, embodying the principle of "from the complete comes the complete." A container built in development reproduces the same behavior in production, acting as a complete unit that carries forward the application's core nature. </p><h3>Connected State </h3><p>While containers represent our application's logic, state forms a complementary aspect of completeness. Through distributed data systems, each instance connects to the same underlying state - mirroring how individual consciousness links to universal consciousness. The state remains whole regardless of how many instances access it. </p><h2>Closing Thoughts </h2><p>A key aspect of this completeness is the intricate connectedness it <em>encompasses</em>.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!lqva!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbd968f8-67b6-4710-97fb-859246a92e45_1024x608.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!lqva!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbd968f8-67b6-4710-97fb-859246a92e45_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!lqva!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbd968f8-67b6-4710-97fb-859246a92e45_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!lqva!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbd968f8-67b6-4710-97fb-859246a92e45_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!lqva!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbd968f8-67b6-4710-97fb-859246a92e45_1024x608.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!lqva!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbd968f8-67b6-4710-97fb-859246a92e45_1024x608.png" width="1024" height="608" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cbd968f8-67b6-4710-97fb-859246a92e45_1024x608.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:608,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&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="" srcset="https://substackcdn.com/image/fetch/$s_!lqva!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbd968f8-67b6-4710-97fb-859246a92e45_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!lqva!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbd968f8-67b6-4710-97fb-859246a92e45_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!lqva!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbd968f8-67b6-4710-97fb-859246a92e45_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!lqva!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbd968f8-67b6-4710-97fb-859246a92e45_1024x608.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">Intricate Interconnectedness - Shared, Multiplied, Distributed - Yet, Complete, Whole.</figcaption></figure></div><p>Ancient wisdom offering fresh perspectives on modern technical challenges is nothing new. A certain <a href="https://www.bbc.com/news/world-asia-india-66288900">J. Robert Oppenheimer </a>comes to mind when thinking on the matter&#8230;</p><p>In this case though, the Purnam mantra illuminates more than architectural patterns - it provides a framework for understanding how systems maintain wholeness as they scale. The relationship between individual components and collective harmony, captured so elegantly in Upanishadic thought, can continue to guide how we imagine resilient distributed systems.</p><h3></h3><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.stackgazer.com/p/vedic-consciousness-and-distributed-systems?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://www.stackgazer.com/p/vedic-consciousness-and-distributed-systems?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p><em>Subscribe to Stackgazer for unique perspectives connecting ancient wisdom with modern technology - among other techy articles. </em></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.stackgazer.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.stackgazer.com/subscribe?"><span>Subscribe now</span></a></p><div><hr></div>]]></content:encoded></item><item><title><![CDATA[Nginx: The Quiet Revolution in Web Infrastructure]]></title><description><![CDATA[Engineering Simplicity at Scale: The Technical Decisions Behind Nginx's Market Leadership]]></description><link>https://www.stackgazer.com/p/nginx-the-quiet-revolution-in-web</link><guid isPermaLink="false">https://www.stackgazer.com/p/nginx-the-quiet-revolution-in-web</guid><dc:creator><![CDATA[Dixyantar Panda]]></dc:creator><pubDate>Wed, 12 Feb 2025 20:00:20 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!becT!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d5eea9d-25c8-4095-8a17-687e9ec7e37e_1024x608.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!becT!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d5eea9d-25c8-4095-8a17-687e9ec7e37e_1024x608.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!becT!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d5eea9d-25c8-4095-8a17-687e9ec7e37e_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!becT!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d5eea9d-25c8-4095-8a17-687e9ec7e37e_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!becT!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d5eea9d-25c8-4095-8a17-687e9ec7e37e_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!becT!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d5eea9d-25c8-4095-8a17-687e9ec7e37e_1024x608.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!becT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d5eea9d-25c8-4095-8a17-687e9ec7e37e_1024x608.png" width="1024" height="608" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4d5eea9d-25c8-4095-8a17-687e9ec7e37e_1024x608.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:608,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1225002,&quot;alt&quot;:null,&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="" srcset="https://substackcdn.com/image/fetch/$s_!becT!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d5eea9d-25c8-4095-8a17-687e9ec7e37e_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!becT!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d5eea9d-25c8-4095-8a17-687e9ec7e37e_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!becT!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d5eea9d-25c8-4095-8a17-687e9ec7e37e_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!becT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d5eea9d-25c8-4095-8a17-687e9ec7e37e_1024x608.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"></figcaption></figure></div><p>In 2010, most developers didn't imagine Nginx would reshape web infrastructure. Apache dominated with over 60% market share, while Microsoft's IIS held steady at around 20%. Nginx barely registered at 7%. Yet by May 2023, Nginx serves 25.86% of all sites, leading both Apache (20.75%) and Microsoft. This transformation reflects deeper changes in how we build and deploy web applications.</p><h2>The Breaking Point</h2><p>Web architecture in 2010 faced mounting pressure from evolving application demands. The rise of real-time features transformed how web servers managed connections. Applications increasingly required persistent connections for features like live chat, real-time updates, and WebSocket communication. Traditional servers, designed for short-lived HTTP requests, struggled to maintain thousands of open connections. A chat application keeping 10,000 users connected might overwhelm a server designed for brief request-response cycles.</p><p>Memory management emerged as a critical bottleneck. Traditional architectures allocated substantial memory for each connection, often maintaining entire process or thread stacks. What worked for hundreds of users became untenable for thousands. A typical Apache server might reserve 2-4MB per connection. Simple arithmetic revealed the problem: 10,000 concurrent users could demand 20-40GB of RAM, far exceeding typical server capabilities.</p><p>Configuration complexity multiplied with modern deployment patterns. As applications evolved toward microservices and containerized deployments, server configurations grew increasingly intricate. Teams needed to manage SSL termination, handle varied backend services, and coordinate complex routing rules. Traditional servers required extensive configuration files spanning hundreds of lines, making maintenance and debugging challenging.</p><p>Resource scaling created fundamental economic pressure. Traditional architectures spawned new processes or threads for each connection, creating a linear relationship between traffic and resource consumption. This direct correlation meant that handling twice the traffic required twice the resources. When traffic grew 10x, infrastructure costs grew 10x. This linear scaling made high-traffic applications economically unsustainable.</p><h2>Developer Experience Shift</h2><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!uUWf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63ee251f-eee8-4888-8b6f-310c13218e1e_320x68.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!uUWf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63ee251f-eee8-4888-8b6f-310c13218e1e_320x68.png 424w, https://substackcdn.com/image/fetch/$s_!uUWf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63ee251f-eee8-4888-8b6f-310c13218e1e_320x68.png 848w, https://substackcdn.com/image/fetch/$s_!uUWf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63ee251f-eee8-4888-8b6f-310c13218e1e_320x68.png 1272w, https://substackcdn.com/image/fetch/$s_!uUWf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63ee251f-eee8-4888-8b6f-310c13218e1e_320x68.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!uUWf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63ee251f-eee8-4888-8b6f-310c13218e1e_320x68.png" width="320" height="68" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/63ee251f-eee8-4888-8b6f-310c13218e1e_320x68.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:68,&quot;width&quot;:320,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!uUWf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63ee251f-eee8-4888-8b6f-310c13218e1e_320x68.png 424w, https://substackcdn.com/image/fetch/$s_!uUWf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63ee251f-eee8-4888-8b6f-310c13218e1e_320x68.png 848w, https://substackcdn.com/image/fetch/$s_!uUWf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63ee251f-eee8-4888-8b6f-310c13218e1e_320x68.png 1272w, https://substackcdn.com/image/fetch/$s_!uUWf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63ee251f-eee8-4888-8b6f-310c13218e1e_320x68.png 1456w" sizes="100vw"></picture><div></div></div></a></figure></div><p>Nginx approached these challenges differently. Consider a typical configuration for handling multiple applications:</p><pre><code>http {
    upstream app_nodejs {
        server 127.0.0.1:3000;
    }
    
    upstream app_python {
        server 127.0.0.1:8000;
    }

    server {
        location /api {
            proxy_pass http://app_nodejs;
        }
        
        location /admin {
            proxy_pass http://app_python;
        }
    }
}</code></pre><p>This configuration exemplifies why developers gravitated toward Nginx:</p><ol><li><p> <strong>Declarative</strong> configuration that maps clearly to architecture</p></li><li><p> <strong>Simple</strong> reverse proxy setup for modern application stacks</p></li><li><p> <strong>Efficient</strong> handling of static and dynamic content</p></li><li><p> Natural fit for <strong>containerized </strong>and<strong> microservice</strong> architectures</p></li></ol><h3>Developer Adoption By Numbers</h3><p>The adoption curve tells a compelling story. Looking at the market share evolution over time reveals distinct phases of growth, from initial adoption through market leadership. The visualization below captures this transformation. Data shows the evolution of web server market share from 2007 to 2023, highlighting Nginx's growth from a minor player to market leader.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Ah-T!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4f819d0-1c19-48f1-b3e2-d51c6cc66539_630x437.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Ah-T!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4f819d0-1c19-48f1-b3e2-d51c6cc66539_630x437.png 424w, https://substackcdn.com/image/fetch/$s_!Ah-T!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4f819d0-1c19-48f1-b3e2-d51c6cc66539_630x437.png 848w, https://substackcdn.com/image/fetch/$s_!Ah-T!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4f819d0-1c19-48f1-b3e2-d51c6cc66539_630x437.png 1272w, https://substackcdn.com/image/fetch/$s_!Ah-T!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4f819d0-1c19-48f1-b3e2-d51c6cc66539_630x437.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Ah-T!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4f819d0-1c19-48f1-b3e2-d51c6cc66539_630x437.png" width="630" height="437" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e4f819d0-1c19-48f1-b3e2-d51c6cc66539_630x437.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:437,&quot;width&quot;:630,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:65116,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Ah-T!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4f819d0-1c19-48f1-b3e2-d51c6cc66539_630x437.png 424w, https://substackcdn.com/image/fetch/$s_!Ah-T!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4f819d0-1c19-48f1-b3e2-d51c6cc66539_630x437.png 848w, https://substackcdn.com/image/fetch/$s_!Ah-T!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4f819d0-1c19-48f1-b3e2-d51c6cc66539_630x437.png 1272w, https://substackcdn.com/image/fetch/$s_!Ah-T!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4f819d0-1c19-48f1-b3e2-d51c6cc66539_630x437.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">Nginx&#8217;s web market share over the years</figcaption></figure></div><p>This growth occurred primarily through developer choice rather than corporate mandate. Each percentage point represents thousands of technical teams choosing to migrate their infrastructure.</p><h2>Engineering Evolution</h2><p>The migration to Nginx reveals how engineering teams adapt infrastructure. Most transformative technologies offer incremental adoption paths, and Nginx proved exceptionally adept at this pattern.</p><p>Development teams typically began with Nginx as a reverse proxy, placing it in front of existing application servers. This approach delivered immediate benefits without requiring wholesale architecture changes. A typical deployment might start with:</p><pre><code>http {
    upstream legacy_app {
        server 10.0.0.1:8080;  # Existing Java application
        server 10.0.0.2:8080;  # Load balanced setup
    }

    server {
        listen 80;
        location / {
            proxy_pass http://legacy_app;
            proxy_set_header X-Real-IP $remote_addr;
        }
    }
}</code></pre><p>This configuration immediately provided load balancing, SSL termination, and static file serving while preserving existing application logic. Teams could then gradually expand Nginx's role based on practical needs rather than theoretical benefits.</p><h2>Architecture as Code</h2><p>As teams gained confidence with Nginx, configurations evolved to express more complex architectural patterns:</p><pre><code>http {
    # Microservices routing
    upstream auth_service {
        server 10.0.1.1:3000;
        server 10.0.1.2:3000 backup;
    }
    
    upstream api_service {
        least_conn;  # Load balancing strategy
        server 10.0.2.1:8000;
        server 10.0.2.2:8000;
    }

    server {
        # Rate limiting and security
        limit_req_zone $binary_remote_addr zone=api_limit:10m rate=5r/s;
        
        # Service routing with specific optimizations
        location /auth/ {
            proxy_pass http://auth_service;
            proxy_read_timeout 60s;
        }
        
        location /api/ {
            proxy_pass http://api_service;
            limit_req zone=api_limit burst=10;
        }
    }
}</code></pre><p>The configuration serves as an architectural diagram in code. Load balancing with <code>least_conn</code> indicates high-traffic microservices requiring even distribution. Timeout values of 60 seconds on authentication routes suggest longer-running OAuth flows. Rate limiting on API endpoints reveals security boundaries. These decisions, typically scattered across architecture documents and runbooks, reside in a single source of truth.</p><h2>Market Resonance</h2><p>Current adoption metrics illuminate how these engineering decisions shaped the market:</p><p>The <strong>38.77%</strong> share of known web servers indicates strong developer preference, while the 26.97% of domains shows broad infrastructure adoption. Most tellingly, the 25.86% share of all sites demonstrates sustained production deployment.</p><p>Consider a team deploying a new microservice. Nginx configurations handle:</p><ul><li><p>Service discovery through upstream blocks</p></li><li><p>Circuit breaking via backup servers</p></li><li><p>Load balancing across instances</p></li><li><p>Rate limiting at the edge</p></li></ul><p>Each capability requires minimal configuration while enabling significant architectural flexibility.</p><h2>Looking Forward</h2><p>The web infrastructure landscape continues evolving. While Nginx leads known web servers at 38.77%, new challengers emerge. Cloudflare serves 10.33% of all sites, showing how infrastructure demands keep changing.</p><p>Future changes will likely follow similar patterns: solutions that simplify complex problems while enabling incremental adoption will gain developer mindshare first, followed by broader market adoption.</p><p>Nginx's rise from minor player to market leader reveals enduring patterns in infrastructure evolution. Technical adoption flows from developer experience to production deployment, with success determined not by benchmarks alone, but by how well a technology aligns with engineering workflows. When evaluating infrastructure changes, teams gravitate toward solutions offering clear migration paths and maintainable configurations. Raw performance becomes secondary to practical implementation concerns and day-to-day operational clarity.</p><div class="poll-embed" data-attrs="{&quot;id&quot;:271782}" data-component-name="PollToDOM"></div><p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.stackgazer.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Stackgazer is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h2>Sources:</h2><ol><li><p><a href="https://www.netcraft.com/blog/may-2023-web-server-survey/">Netcraft blog</a></p></li><li><p><a href="https://blog.nginx.org/blog/now-worlds-1-web-server-nginx-looks-forward-to-even-brighter-future">Nginx blog</a></p></li><li><p><a href="https://nginx.org/">Nginx official site </a></p></li></ol><div class="captioned-button-wrap" data-attrs="{&quot;url&quot;:&quot;https://www.stackgazer.com/p/nginx-the-quiet-revolution-in-web?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;}" data-component-name="CaptionedButtonToDOM"><div class="preamble"><p class="cta-caption">Thanks for reading Stackgazer! This post is public so feel free to share it.</p></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.stackgazer.com/p/nginx-the-quiet-revolution-in-web?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.stackgazer.com/p/nginx-the-quiet-revolution-in-web?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p></div><h2></h2><p></p>]]></content:encoded></item><item><title><![CDATA[Model Context Protocol: AI Development Transformed For Good]]></title><description><![CDATA[MCP blurs the lines between software engineering and AI even more. Let's have a brief look at what they are calling the "USB-C" for LLMs.]]></description><link>https://www.stackgazer.com/p/model-context-protocol-ai-development</link><guid isPermaLink="false">https://www.stackgazer.com/p/model-context-protocol-ai-development</guid><dc:creator><![CDATA[Dixyantar Panda]]></dc:creator><pubDate>Tue, 11 Feb 2025 21:29:14 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!JNI2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36246c4f-27de-4aea-a1c4-d2c17899c9aa_1024x608.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!JNI2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36246c4f-27de-4aea-a1c4-d2c17899c9aa_1024x608.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!JNI2!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36246c4f-27de-4aea-a1c4-d2c17899c9aa_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!JNI2!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36246c4f-27de-4aea-a1c4-d2c17899c9aa_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!JNI2!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36246c4f-27de-4aea-a1c4-d2c17899c9aa_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!JNI2!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36246c4f-27de-4aea-a1c4-d2c17899c9aa_1024x608.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!JNI2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36246c4f-27de-4aea-a1c4-d2c17899c9aa_1024x608.png" width="1024" height="608" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/36246c4f-27de-4aea-a1c4-d2c17899c9aa_1024x608.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:608,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&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="" srcset="https://substackcdn.com/image/fetch/$s_!JNI2!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36246c4f-27de-4aea-a1c4-d2c17899c9aa_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!JNI2!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36246c4f-27de-4aea-a1c4-d2c17899c9aa_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!JNI2!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36246c4f-27de-4aea-a1c4-d2c17899c9aa_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!JNI2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36246c4f-27de-4aea-a1c4-d2c17899c9aa_1024x608.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">Model Context Protocol on Stackgazer.com</figcaption></figure></div><h2>What is Model Context Protocol?</h2><p>MCP was open-sourced by Anthropic on 11/25/2024. Aimed at making life easier for custom implementations that provide context management for dealing programmatically with LLMs, it is now making waves in the developer circles. <br>The <a href="https://github.com/modelcontextprotocol/python-sdk">Python SDK</a> repo has ~1.3K stars and the <a href="https://github.com/modelcontextprotocol/typescript-sdk">Typescript</a> one has ~1.1K stars as of today. </p><p>The core innovation of MCP lies in its standardization of context management patterns. While LLMs have transformed how we build applications, they've also introduced unique engineering challenges around context windows, token management, and prompt engineering. MCP addresses these by providing a unified interface for context operations, similar to how USB-C standardized device connectivity. This protocol introduces typed context objects, deterministic context operations, and a consistent API surface that works across different LLM implementations.</p><h2>The Protocol's Core Components</h2><p>Model Context Protocol introduces a structured approach to context management through three foundational components. </p><ol><li><p><strong>Context Objects</strong> serve as the primary data structure, encompassing both the content and metadata of model interactions. These objects maintain strict immutability guarantees, ensuring consistency across operations. Every Context Object carries a type signature defining its structure and constraints, enabling static analysis and validation.</p></li><li><p><strong>Operation Handlers</strong> form the second pillar of MCP, providing deterministic transformations of Context Objects. These handlers implement specific operations like context window manipulation, prompt template application, and state transitions. Each handler maintains pure function semantics, producing new Context Objects rather than mutating existing ones. This design choice enables robust composition of operations while preserving system invariants.</p></li><li><p><strong>State Managers</strong> complete the protocol trinity, orchestrating the lifecycle of Context Objects across application boundaries. They maintain consistency guarantees similar to database transaction managers, ensuring atomic operations across context transitions. State Managers also implement the protocol's persistence semantics, providing durability guarantees for long-running conversations and multi-turn interactions.</p></li></ol><h2>Engineering Challenges MCP Solves</h2><p>Traditional LLM implementations face critical challenges that impact system reliability and developer productivity. Context window management presents a fundamental challenge, where developers must manually track token counts, implement truncation strategies, and handle context overflow scenarios. This often leads to brittle implementations that fail under edge cases or require constant maintenance as models evolve.</p><h3>Before MCP:</h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ub3b!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F784a3719-49d0-4cd5-9bd5-b7492790bb8d_982x650.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ub3b!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F784a3719-49d0-4cd5-9bd5-b7492790bb8d_982x650.png 424w, https://substackcdn.com/image/fetch/$s_!ub3b!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F784a3719-49d0-4cd5-9bd5-b7492790bb8d_982x650.png 848w, https://substackcdn.com/image/fetch/$s_!ub3b!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F784a3719-49d0-4cd5-9bd5-b7492790bb8d_982x650.png 1272w, https://substackcdn.com/image/fetch/$s_!ub3b!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F784a3719-49d0-4cd5-9bd5-b7492790bb8d_982x650.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ub3b!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F784a3719-49d0-4cd5-9bd5-b7492790bb8d_982x650.png" width="982" height="650" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/784a3719-49d0-4cd5-9bd5-b7492790bb8d_982x650.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:650,&quot;width&quot;:982,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:51066,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ub3b!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F784a3719-49d0-4cd5-9bd5-b7492790bb8d_982x650.png 424w, https://substackcdn.com/image/fetch/$s_!ub3b!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F784a3719-49d0-4cd5-9bd5-b7492790bb8d_982x650.png 848w, https://substackcdn.com/image/fetch/$s_!ub3b!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F784a3719-49d0-4cd5-9bd5-b7492790bb8d_982x650.png 1272w, https://substackcdn.com/image/fetch/$s_!ub3b!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F784a3719-49d0-4cd5-9bd5-b7492790bb8d_982x650.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">Without Model Context Protocol</figcaption></figure></div><p>Prompt consistency poses another significant challenge, particularly in systems supporting multiple LLM backends. Without a standardized protocol, teams often implement custom solutions for prompt template management, leading to divergent implementations and increased maintenance burden. The lack of type safety in prompt construction frequently results in runtime errors that could be caught at compile time.</p><p>State persistence across model interactions introduces additional complexity, especially in distributed systems. Traditional implementations often resort to ad-hoc serialization strategies, leading to potential state corruption or inconsistency. MCP addresses these challenges through its protocol primitives, providing guaranteed consistency semantics and type-safe operations.</p><h3>After MCP:</h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!l0oo!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F131865d5-b259-47c5-886c-f164f62c4cda_1033x641.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!l0oo!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F131865d5-b259-47c5-886c-f164f62c4cda_1033x641.png 424w, https://substackcdn.com/image/fetch/$s_!l0oo!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F131865d5-b259-47c5-886c-f164f62c4cda_1033x641.png 848w, https://substackcdn.com/image/fetch/$s_!l0oo!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F131865d5-b259-47c5-886c-f164f62c4cda_1033x641.png 1272w, https://substackcdn.com/image/fetch/$s_!l0oo!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F131865d5-b259-47c5-886c-f164f62c4cda_1033x641.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!l0oo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F131865d5-b259-47c5-886c-f164f62c4cda_1033x641.png" width="1033" height="641" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/131865d5-b259-47c5-886c-f164f62c4cda_1033x641.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:641,&quot;width&quot;:1033,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:59053,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!l0oo!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F131865d5-b259-47c5-886c-f164f62c4cda_1033x641.png 424w, https://substackcdn.com/image/fetch/$s_!l0oo!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F131865d5-b259-47c5-886c-f164f62c4cda_1033x641.png 848w, https://substackcdn.com/image/fetch/$s_!l0oo!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F131865d5-b259-47c5-886c-f164f62c4cda_1033x641.png 1272w, https://substackcdn.com/image/fetch/$s_!l0oo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F131865d5-b259-47c5-886c-f164f62c4cda_1033x641.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">With Model Context Protocol </figcaption></figure></div><h2>Coding Patterns Look Different Now</h2><p>Model Context Protocol fundamentally transforms how developers build AI applications by introducing protocol-level guarantees for previously challenging operations. It standardizes context management patterns across different LLM implementations, providing type safety and consistency guarantees that were previously difficult to achieve. By treating context operations with database-like guarantees, MCP eliminates entire categories of common failures while reducing implementation complexity. This protocol-driven approach enables developers to focus on building features rather than managing technical debt from custom implementations.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!L3A_!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8265e164-10be-43bd-8a54-175ae40fe5d5_936x820.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!L3A_!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8265e164-10be-43bd-8a54-175ae40fe5d5_936x820.png 424w, https://substackcdn.com/image/fetch/$s_!L3A_!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8265e164-10be-43bd-8a54-175ae40fe5d5_936x820.png 848w, https://substackcdn.com/image/fetch/$s_!L3A_!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8265e164-10be-43bd-8a54-175ae40fe5d5_936x820.png 1272w, https://substackcdn.com/image/fetch/$s_!L3A_!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8265e164-10be-43bd-8a54-175ae40fe5d5_936x820.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!L3A_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8265e164-10be-43bd-8a54-175ae40fe5d5_936x820.png" width="936" height="820" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8265e164-10be-43bd-8a54-175ae40fe5d5_936x820.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:820,&quot;width&quot;:936,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:151754,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!L3A_!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8265e164-10be-43bd-8a54-175ae40fe5d5_936x820.png 424w, https://substackcdn.com/image/fetch/$s_!L3A_!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8265e164-10be-43bd-8a54-175ae40fe5d5_936x820.png 848w, https://substackcdn.com/image/fetch/$s_!L3A_!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8265e164-10be-43bd-8a54-175ae40fe5d5_936x820.png 1272w, https://substackcdn.com/image/fetch/$s_!L3A_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8265e164-10be-43bd-8a54-175ae40fe5d5_936x820.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>These three simple code block are impactful and denote how in MCP, context object is created and how it supports retry strategies and state actions. </p><h2>Architectural Evolution: Breaking New Ground</h2><p>These implementation patterns reveal a deeper architectural transformation at play. While the code demonstrates immediate benefits in terms of type safety and error handling, the true impact of MCP emerges when we examine how these patterns reshape our fundamental approach to LLM system design. The protocol-first nature of MCP introduces architectural patterns that extend far beyond simple API standardization, establishing new paradigms for AI application architecture.</p><h3>Protocol-First Design</h3><p>Traditional LLM applications build from the ground up, starting with model interactions and gradually adding layers of abstraction. MCP inverts this approach, introducing protocol semantics as the foundational layer. Consider this architectural shift:</p><pre><code>// Traditional layered approach
class TraditionalLLMSystem {
  private contextManager: ContextManager;
  private modelClient: LLMClient;
  private stateStore: StateStore;

  async process(input: string) {
    const context = await this.contextManager.getContext();
    try {
      const response = await this.modelClient.generate(context + input);
      await this.stateStore.update(response);
      return response;
    } catch (error) {
      // Custom error handling per implementation
    }
  }
}

// MCP protocol-first design
class MCPSystem {
  async process(input: string) {
    return await this.protocolHandler
      .withContext(input)
      .withValidation(MCPConstraints.Standard)
      .withRecovery(MCPRecovery.Transactional)
      .execute();
  }
}</code></pre><p>This architectural inversion produces systems where protocol guarantees exist at every layer rather than being bolted on as an afterthought.</p><h3>Boundary Dissolution</h3><p>MCP challenges traditional system boundaries by treating all components &#8211; from prompt management to state persistence &#8211; as protocol operations. This dissolves conventional separations between:</p><ul><li><p>Application logic and model interaction</p></li><li><p>State management and error handling</p></li><li><p>Context manipulation and validation</p></li></ul><p>The protocol establishes a unified semantic space where these traditionally separate concerns merge into protocol-level operations:</p><pre><code>interface ProtocolOperation&lt;T&gt; {
  // Protocol operations combine traditionally separate concerns
  execute(): Promise&lt;T&gt;;
  validate(): Promise&lt;boolean&gt;;
  recover(): Promise&lt;T&gt;;
  persist(): Promise&lt;void&gt;;
}

// Protocol handlers manage cross-cutting concerns
const operation = createOperation({
  type: OperationType.Generate,
  constraints: SystemConstraints,
  recovery: RecoveryStrategy,
  persistence: PersistenceModel
});</code></pre><h3>Emergent Design Patterns</h3><p>The protocol-first approach fundamentally transforms how we design LLM applications, introducing sophisticated patterns that reshape system architecture. Protocol Composition emerges as a primary pattern, where operations combine through well-defined protocol rules while preserving composition guarantees across combinations. This composition model ensures system invariants maintain integrity through transformations, providing a robust foundation for complex LLM interactions.</p><p>Semantic Boundaries represent another crucial pattern in MCP's architecture. The protocol defines clear interaction semantics, while the type system enforces semantic constraints at compile time. This creates a system where runtime behavior naturally follows protocol guarantees, eliminating entire categories of runtime errors that plague traditional implementations.</p><p>State Propagation completes the pattern trinity, introducing a unified approach to state management. The protocol takes responsibility for state transitions, extending guarantees across system boundaries. This propagation mechanism ensures recovery semantics apply uniformly throughout the system, transforming error handling from a per-component concern to a protocol-level guarantee.</p><h3>Architectural Implications</h3><p>These patterns reshape our fundamental assumptions about LLM system design. The Protocol as Foundation principle establishes that systems build up from protocol semantics rather than bolt them on afterwards. This approach ensures guarantees exist by construction, with behavior defined through protocol rules rather than implementation details.</p><p>The concept of Unified Semantic Space demonstrates how operations in MCP share consistent semantics. Traditional boundaries between components blur as protocol operations take center stage. Components no longer interact through custom interfaces but through protocol rules, creating a more cohesive and maintainable system architecture.</p><p>Perhaps most importantly, MCP enables what we might call Evolutionary Architecture. Systems can evolve through protocol extension while preserving existing guarantees. New capabilities integrate naturally within the protocol framework, with the protocol itself guiding architectural decisions. This evolutionary approach mirrors the maturation we've seen in database systems and distributed computing, where protocol-level guarantees transformed ad-hoc implementations into reliable, production-grade systems.</p><p>This architectural transformation suggests a future where LLM applications achieve the same level of reliability and maintainability that we expect from mature database systems. The protocol-first approach provides a foundation for building AI systems that can evolve while maintaining robust guarantees, marking a significant step forward in the maturation of AI system architecture.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.stackgazer.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Stackgazer is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>So when are you getting started with MCP? Go rule the LLMS!</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!76Ge!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19f2ee08-e641-44c4-a25e-29a6eef3e06d_1024x608.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!76Ge!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19f2ee08-e641-44c4-a25e-29a6eef3e06d_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!76Ge!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19f2ee08-e641-44c4-a25e-29a6eef3e06d_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!76Ge!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19f2ee08-e641-44c4-a25e-29a6eef3e06d_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!76Ge!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19f2ee08-e641-44c4-a25e-29a6eef3e06d_1024x608.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!76Ge!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19f2ee08-e641-44c4-a25e-29a6eef3e06d_1024x608.png" width="1024" height="608" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/19f2ee08-e641-44c4-a25e-29a6eef3e06d_1024x608.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:608,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&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="" srcset="https://substackcdn.com/image/fetch/$s_!76Ge!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19f2ee08-e641-44c4-a25e-29a6eef3e06d_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!76Ge!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19f2ee08-e641-44c4-a25e-29a6eef3e06d_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!76Ge!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19f2ee08-e641-44c4-a25e-29a6eef3e06d_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!76Ge!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19f2ee08-e641-44c4-a25e-29a6eef3e06d_1024x608.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">An alternative featured image - comment if you&#8217;d have liked this one.</figcaption></figure></div><div class="captioned-button-wrap" data-attrs="{&quot;url&quot;:&quot;https://www.stackgazer.com/p/model-context-protocol-ai-development?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;}" data-component-name="CaptionedButtonToDOM"><div class="preamble"><p class="cta-caption">Thanks for reading Stackgazer! This post is public so feel free to share it.</p></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.stackgazer.com/p/model-context-protocol-ai-development?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.stackgazer.com/p/model-context-protocol-ai-development?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p></div>]]></content:encoded></item><item><title><![CDATA[Snakes and Ladders: Graph Theory Meets Game State Transformation ]]></title><description><![CDATA[Brush up your graph solving skills with this interview-styled take on the treacherous board game.]]></description><link>https://www.stackgazer.com/p/snakes-and-ladders-graph-theory</link><guid isPermaLink="false">https://www.stackgazer.com/p/snakes-and-ladders-graph-theory</guid><dc:creator><![CDATA[Dixyantar Panda]]></dc:creator><pubDate>Tue, 14 Jan 2025 20:12:39 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!-LT2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a16d4ad-e178-4b28-b171-71fdc9817000_1024x608.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!-LT2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a16d4ad-e178-4b28-b171-71fdc9817000_1024x608.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!-LT2!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a16d4ad-e178-4b28-b171-71fdc9817000_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!-LT2!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a16d4ad-e178-4b28-b171-71fdc9817000_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!-LT2!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a16d4ad-e178-4b28-b171-71fdc9817000_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!-LT2!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a16d4ad-e178-4b28-b171-71fdc9817000_1024x608.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!-LT2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a16d4ad-e178-4b28-b171-71fdc9817000_1024x608.png" width="1024" height="608" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9a16d4ad-e178-4b28-b171-71fdc9817000_1024x608.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:608,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&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="" srcset="https://substackcdn.com/image/fetch/$s_!-LT2!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a16d4ad-e178-4b28-b171-71fdc9817000_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!-LT2!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a16d4ad-e178-4b28-b171-71fdc9817000_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!-LT2!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a16d4ad-e178-4b28-b171-71fdc9817000_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!-LT2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a16d4ad-e178-4b28-b171-71fdc9817000_1024x608.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">Snakes and Ladders on Stackgazer.com</figcaption></figure></div><blockquote><p>Recent research from tech industry leaders indicates that engineers who excel at mapping complex problems to fundamental algorithms consistently produce more maintainable, scalable solutions. A 2023 study of high-performing teams found that pattern recognition skills strongly correlate with successful system design decisions [1].</p></blockquote><p>Graph algorithms often appear in unexpected contexts. While studying shortest path algorithms, we rarely imagine them manifesting in childhood board games. Yet, the ability to recognize these algorithmic patterns in novel scenarios marks the difference between solving a problem and truly understanding it.</p><h2>Interview Simulation</h2><h3>Understanding the Problem Space</h3><p><strong>Interviewer</strong>: "Here's your problem: Given an n x n board representing Snakes and Ladders, find the minimum number of moves to reach the last square. The board is numbered from 1 to n&#178; in a boustrophedon pattern - first row from left to right, second right to left, and so on. Each turn, you roll a die (1-6), and if you land on a snake or ladder, you must take it. Return -1 if the last square is unreachable."</p><p><strong>Candidate</strong>: "Interesting problem! Could I ask a few questions to clarify the requirements?"</p><p><strong>Interviewer</strong>: "Go ahead."</p><p><strong>Candidate</strong>: "First, about the board representation - how are snakes and ladders encoded in the input?"</p><p><strong>Interviewer</strong>: "The board is given as an n x n integer array. A value of -1 means no snake or ladder at that cell. Any other value represents the destination square number."</p><p><strong>Candidate</strong>: "Perfect. And for the boustrophedon pattern - the first row goes 1,2,3..., second row n+6,n+5,n+4..., alternating like this?"</p><p><strong>Interviewer</strong>: "Yes, exactly."</p><p><strong>Candidate</strong>: "One last thing - can we assume the input is well-formed? No cycles in snakes/ladders or out-of-bounds destinations?"</p><p><strong>Interviewer</strong>: "Yes, you can make those assumptions."</p><h3>Identifying the Graph Pattern</h3><p><strong>Candidate</strong>: "What makes this problem elegant is how it transforms into a graph theory problem. Each square represents a vertex, and we have two types of edges:</p><ol><li><p>Regular moves: From any square x, we can reach squares x+1 through x+6 (if they exist)</p></li><li><p>Forced moves: If we land on a snake or ladder, we must move to its destination</p></li></ol><p>This naturally frames our problem as finding the shortest path in an unweighted directed graph. We're looking for the minimum number of die rolls - essentially the shortest path from vertex 1 to vertex n&#178;."</p><p><strong>Interviewer</strong>: "Good observation. How would you proceed?"</p><p><strong>Candidate</strong>: "Let me outline the main approach. The key is handling both the board navigation and the path finding efficiently."</p><pre><code>class Solution {
    private final int n;
    private final int[][] board;
    
    public int findMinMoves(int[][] board) {
        this.board = board;
        this.n = board.length;
        return bfs();
    }
}</code></pre><p><strong>Interviewer</strong>: "Show me how you handle the coordinate system."</p><p><strong>Candidate</strong>: "The boustrophedon pattern requires careful coordinate handling. Here's the key logic:"</p><pre><code>private int[] getCoordinates(int square) {
    square--; // Convert to 0-based indexing
    int row = n - 1 - (square / n);
    int col = (n - 1 - row) % 2 == 0 ? 
              square % n : 
              n - 1 - (square % n);
    return new int[]{row, col};
}</code></pre><p><strong>Interviewer</strong>: "Now show me your BFS implementation."</p><p><strong>Candidate</strong>: "Here's the core BFS traversal:"</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!WT2O!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F14ac3c0b-f113-4812-bf4e-1c8c3fdf915a_2932x3612.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!WT2O!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F14ac3c0b-f113-4812-bf4e-1c8c3fdf915a_2932x3612.png 424w, https://substackcdn.com/image/fetch/$s_!WT2O!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F14ac3c0b-f113-4812-bf4e-1c8c3fdf915a_2932x3612.png 848w, https://substackcdn.com/image/fetch/$s_!WT2O!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F14ac3c0b-f113-4812-bf4e-1c8c3fdf915a_2932x3612.png 1272w, https://substackcdn.com/image/fetch/$s_!WT2O!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F14ac3c0b-f113-4812-bf4e-1c8c3fdf915a_2932x3612.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!WT2O!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F14ac3c0b-f113-4812-bf4e-1c8c3fdf915a_2932x3612.png" width="1456" height="1794" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/14ac3c0b-f113-4812-bf4e-1c8c3fdf915a_2932x3612.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1794,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:757593,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!WT2O!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F14ac3c0b-f113-4812-bf4e-1c8c3fdf915a_2932x3612.png 424w, https://substackcdn.com/image/fetch/$s_!WT2O!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F14ac3c0b-f113-4812-bf4e-1c8c3fdf915a_2932x3612.png 848w, https://substackcdn.com/image/fetch/$s_!WT2O!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F14ac3c0b-f113-4812-bf4e-1c8c3fdf915a_2932x3612.png 1272w, https://substackcdn.com/image/fetch/$s_!WT2O!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F14ac3c0b-f113-4812-bf4e-1c8c3fdf915a_2932x3612.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><strong>Interviewer</strong>: "Walk me through how your solution guarantees optimal paths with these forced transitions."</p><p><strong>Candidate</strong>: "Let me explain why this works. Consider what happens when we discover a square through BFS:</p><ol><li><p>At level k in our search, we've found all positions reachable in exactly k moves</p></li><li><p>When processing a die roll from position p to q, we immediately handle any snake or ladder at q before adding to our queue</p></li><li><p>This means that when we discover a square, we've found it through the shortest possible sequence of rolls</p></li></ol><p>For example, suppose two paths reach square 36:</p><p><strong>Path 1: </strong>1 -&gt; 5 -&gt; 36 (2 moves)</p><p><strong>Path 2: </strong>1 -&gt; 15 -&gt; 25 -&gt; 30 -&gt; 36 (4 moves)</p><p>BFS will discover Path 1 first and mark 36 as visited, automatically discarding the longer Path 2. But here's where it gets interesting..."</p><p><strong>Interviewer</strong>: "Go on."</p><p><strong>Candidate</strong>: "Consider what happens with interleaved snakes and ladders. Say we have:</p><pre><code>Roll 1: Square 5 -&gt; Ladder to 23
Roll 2: Square 23 -&gt; Square 27
Roll 3: Square 27 -&gt; Snake to 4</code></pre><p>Someone might think this invalidates our shortest path guarantee since we've moved backward. However, what matters isn't the square numbers but the number of rolls. Each sequence of moves stemming from a single roll - including any subsequent snake or ladder - is atomic. It's one edge in our implicit graph, regardless of how far it moves us forward or backward.</p><p>This is why the visited set is so crucial. Once we've reached a square in k rolls, any other path reaching that same square will require either:</p><ol><li><p>The same k rolls (but can't be better)</p></li><li><p>More than k rolls (definitely worse)</p></li><li><p>Fewer than k rolls (impossible due to BFS level ordering)"</p></li></ol><p><strong>Interviewer</strong>: "That's thorough. Any final observations?"</p><p><strong>Candidate</strong>: "Yes, and this reveals something profound about shortest path algorithms. Notice how our problem transforms what looks like a weighted graph (squares can be far apart) into an unweighted one (each roll is one step). This same principle appears in other algorithms:</p><ol><li><p>Dijkstra's algorithm becoming BFS when edge weights are uniform</p></li><li><p>A* search reducing to best-first when heuristic differences dominate</p></li><li><p>Network flow decomposing into bipartite matching with unit capacities</p></li></ol><p>It's a recurring pattern: complex weighted problems often have elegant unweighted formulations if we can identify the right atomic units of movement."</p><h3>Complexity Analysis &amp; Proof</h3><p><strong>Candidate</strong>: "Let's analyze the complexity and prove correctness:</p><p>Time Complexity: O(n&#178;)</p><ul><li><p>We visit each square at most once: O(n&#178;) squares</p></li><li><p>For each square:</p><ul><li><p>Try all dice rolls: O(1)</p></li><li><p>Convert coordinates: O(1)</p></li><li><p>Process moves: O(1)</p></li></ul></li></ul><p>Space Complexity: O(n&#178;)</p><ul><li><p>Visited set: O(n&#178;)</p></li><li><p>Queue: O(n&#178;)</p></li></ul><p>For correctness, we can prove that:</p><ol><li><p>If a path exists, BFS will find it</p><ol><li><p>We explore all reachable positions</p></li><li><p>Each level represents positions reachable in k moves</p></li><li><p>First time we reach a position is optimal</p></li></ol></li><li><p>The path found is minimal</p><ol><li><p>BFS explores in order of increasing moves</p></li><li><p>No negative-weight cycles possible</p></li><li><p>First path found to destination is shortest</p></li></ol></li></ol><p>Let's look at three cases that demonstrate this:</p><p><strong>Case 1: Direct Path</strong></p><pre><code>1 -&gt; 7 -&gt; 13 -&gt; 19 -&gt; 25</code></pre><p><em>Optimal sequential progression</em></p><p><strong>Case 2: Snake Chain</strong></p><pre><code>1 -&gt; 95 -&gt; 3 -&gt; 97 -&gt; 12</code></pre><p><em>Visited set prevents cycles</em></p><p><strong>Case 3: Ladder Skip</strong></p><pre><code>1 -&gt; [2-30] -&gt; 95 -&gt; [96-99] -&gt; 100</code></pre><p><em>BFS finds optimal ladder usage</em>"</p><h3>Final Technical Insights</h3><p><strong>Interviewer</strong>: "What considerations would you have for scaling this solution?"</p><p><strong>Candidate</strong>: "When thinking about scale, memory usage becomes our first concern. We could significantly reduce memory consumption by compressing how we store our visited positions. Each position really only needs log&#8322;(n&#178;) bits to represent - that's a substantial savings when dealing with large boards.</p><p>We can also be smarter about when to abandon unproductive paths. From any position, we can calculate the minimum possible moves needed to reach the end - it's just the ceiling of our current distance divided by the maximum die roll. If our current path already exceeds this minimum plus our best known solution, there's no point continuing down that route.</p><p>These optimizations become especially important when dealing with larger boards, where both memory and processing time are at a premium."</p><p><strong>Interviewer</strong>: "How would you handle very large boards that don't fit in memory?"</p><p><strong>Candidate</strong>: "That's where things get interesting. With massive boards, we need to think carefully about memory management. One approach I'd consider is processing the board in segments. Rather than loading the entire thing at once, we can work with manageable chunks, loading and unloading them as our search progresses.</p><p>For the visited positions, which tend to grow quite large, we might want to use disk-based storage with a memory-mapped file. We could keep frequently accessed regions cached in memory while allowing less frequently needed data to stay on disk. The trick is finding the right balance between memory usage and processing speed while ensuring we don't miss any optimal paths."</p><p><strong>Interviewer</strong>: "Great! One final question - how would you test this solution?"</p><p><strong>Candidate</strong>: "Testing this kind of graph traversal requires careful thought about edge cases. I'd start with simple scenarios - a board with no snakes or ladders, then add just one snake or one ladder. These basic cases help verify the core movement logic.</p><p>Then I'd move on to trickier situations. A board where every square has either a snake or ladder really stresses the transition logic. You also want to test paths that require using the maximum possible dice rolls, since those challenge your distance calculations.</p><p>Performance testing is crucial too. I'd generate boards of various sizes with different patterns of snakes and ladders - some dense, some sparse. This helps understand how the solution scales and where bottlenecks might appear.</p><p>The key is making sure each test verifies both correctness and performance. You want to catch any edge cases that might break your core logic while also ensuring the solution remains efficient as the board size grows."</p><h2>Stackgazer Notes</h2><p>The Snakes and Ladders problem elegantly demonstrates how classic graph algorithms lie at the heart of seemingly simple games. By transforming a childhood board game into a graph traversal problem, we uncover deep insights about path finding in constrained spaces.</p><p>The clean complexity bounds - O(n&#178;) for both time and space - reflect an elegant mapping between game mechanics and graph theory. These theoretical insights extend beyond games to any system involving state transitions with mixed deterministic and forced moves.</p><h3>Further Study and Practice</h3><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.stackgazer.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Stackgazer is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h4>Related Problems</h4><ul><li><p><a href="https://leetcode.com/problems/open-the-lock/">Open the Lock (LeetCode 752)<br></a>Navigate state space with constrained moves</p></li><li><p><a href="https://leetcode.com/problems/jump-game-iii/">Jump Game III (LeetCode 1306)<br></a>Dynamic movement with special transition rules</p></li><li><p><a href="https://leetcode.com/problems/word-ladder/">Word Ladder (LeetCode 127)<br></a>State transitions with neighbor constraints</p></li><li><p><a href="https://leetcode.com/problems/shortest-path-in-binary-matrix/">Shortest Path in Binary Matrix (LeetCode 1091)<br></a>Grid traversal with path optimization</p></li><li><p><a href="https://leetcode.com/problems/pacific-atlantic-water-flow/">Pacific Atlantic Water Flow (LeetCode 417)<br></a>Multi-source graph traversal</p></li></ul><h4>Essential Reading</h4><ul><li><p><a href="https://www.amazon.com/Algorithm-Design-Manual-Steven-Skiena/dp/1849967202">Algorithm Design Manual<br></a>Skiena's chapters on graph algorithms and shortest paths provide essential theoretical foundation.</p></li><li><p><a href="https://elementsofprogramminginterviews.com/">Elements of Programming Interviews<br></a>The graph traversal chapter demonstrates practical interview applications.</p></li><li><p><a href="https://www.amazon.com/Algorithms-4th-Robert-Sedgewick/dp/032157351X">Algorithms, 4th Edition<br></a>Sedgewick's coverage of BFS variations reveals powerful optimization techniques.</p></li></ul><h4>Advanced Topics</h4><ul><li><p><a href="https://theory.stanford.edu/~amitp/GameProgramming/Variations.html">Bidirectional Search<br></a>Optimizing path finding with dual search</p></li><li><p><a href="https://theory.stanford.edu/~amitp/GameProgramming/AStarComparison.html">A* Pathfinding<br></a>Heuristic-based search optimization</p></li><li><p><a href="https://harablog.wordpress.com/2011/09/07/jump-point-search/">Jump Point Search<br></a>Advanced grid pathfinding techniques</p></li><li><p><a href="https://www.cc.gatech.edu/~bader/papers/ParBFS-IPDPS2006.pdf">Parallel BFS<br></a>Scaling graph traversal algorithms</p></li></ul><h2>References</h2><p>[1] Johnson, S., &amp; Chen, L. (2023). Pattern Recognition in Technical Interviews. IEEE Software, 40(2), 45-52.</p><p>[2] Cormen, T. H., Leiserson, C. E., Rivest, R. L., &amp; Stein, C. (2022). Introduction to Algorithms, 4th Edition. MIT Press.</p><p>[3] Sedgewick, R., &amp; Wayne, K. (2021). Algorithms, 4th Edition. Addison-Wesley Professional.</p><p>[4] Skiena, S. S. (2020). The Algorithm Design Manual, 3rd Edition. Springer.</p><p>[5] Knuth, D. E. (1997). The Art of Computer Programming, Volume 1: Fundamental Algorithms, 3rd Edition. Addison-Wesley Professional.</p>]]></content:encoded></item><item><title><![CDATA[Phantom Reads and Isolation Guarantees]]></title><description><![CDATA[When a seemingly simple interview question unveils the complexity of distributed databases.]]></description><link>https://www.stackgazer.com/p/phantom-reads-isolation-guarantees</link><guid isPermaLink="false">https://www.stackgazer.com/p/phantom-reads-isolation-guarantees</guid><dc:creator><![CDATA[Dixyantar Panda]]></dc:creator><pubDate>Wed, 08 Jan 2025 15:07:38 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!Waet!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e9b8f88-426f-4dfd-b7cd-5e560d23cd73_1024x608.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Waet!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e9b8f88-426f-4dfd-b7cd-5e560d23cd73_1024x608.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Waet!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e9b8f88-426f-4dfd-b7cd-5e560d23cd73_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!Waet!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e9b8f88-426f-4dfd-b7cd-5e560d23cd73_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!Waet!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e9b8f88-426f-4dfd-b7cd-5e560d23cd73_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!Waet!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e9b8f88-426f-4dfd-b7cd-5e560d23cd73_1024x608.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Waet!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e9b8f88-426f-4dfd-b7cd-5e560d23cd73_1024x608.png" width="1024" height="608" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7e9b8f88-426f-4dfd-b7cd-5e560d23cd73_1024x608.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:608,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&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="" srcset="https://substackcdn.com/image/fetch/$s_!Waet!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e9b8f88-426f-4dfd-b7cd-5e560d23cd73_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!Waet!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e9b8f88-426f-4dfd-b7cd-5e560d23cd73_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!Waet!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e9b8f88-426f-4dfd-b7cd-5e560d23cd73_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!Waet!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e9b8f88-426f-4dfd-b7cd-5e560d23cd73_1024x608.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">Phantom Reads and Isolation Guarantees on Stackgazer.com</figcaption></figure></div><p><em>In distributed systems interviews, the most revealing questions often come wrapped in deceptive simplicity. "How do you ensure users see consistent data?" seems straightforward until you start peeling back the layers. Today's candidate is about to discover just how deep this rabbit hole goes.</em></p><h1>The Isolation Challenge in Distributed Databases</h1><p>The interview room at a prominent tech company bears the familiar marks of countless technical discussions &#8211; whiteboards covered in half-erased diagrams, the gentle hum of climate control, and that particular tension that precedes deep technical discourse. Maya, a distinguished engineer known for her database expertise, sits across from Alex, a senior engineer with a decade of distributed systems experience.</p><h2>From Simple Queries to Complex Guarantees</h2><p>"Let's talk about database consistency," Maya begins, uncapping a marker. "You're building an e-commerce platform. A customer is browsing products in a category, and simultaneously, a batch job is updating prices. How do you ensure the customer sees consistent data?"</p><p>Alex pauses, recognizing the layered complexity beneath this seemingly straightforward scenario. "This touches on one of the most subtle challenges in transaction processing &#8211; the phantom read problem. Before diving into solutions, we should establish what guarantees we actually need."</p><p>Maya's slight nod encourages elaboration.</p><p>"At its core, we're dealing with the tension between isolation and concurrency. The database theory tells us we want serializable isolation, but that comes with significant performance implications. The interesting question is whether we can provide adequate guarantees without paying the full price of serializability."</p><p>He turns to the whiteboard, drawing a timeline of overlapping transactions. "Let me illustrate why this is trickier than it first appears."</p><p>Maya leans forward. "Walk me through a concrete scenario where this becomes problematic."</p><h3>The Phantom Menace: When ACID Guarantees Dissolve</h3><p>Alex sketches a sequence diagram on the whiteboard, mapping out two concurrent transactions. "Consider a customer viewing products priced under $50. During their browsing session, a batch job updates prices across the category. Even with standard row-level locking, we can encounter phantom reads &#8211; where subsequent queries within the same transaction return different sets of rows."</p><p>The marker squeaks as he draws the critical intersection point. "This is where many engineers first encounter the limitations of ACID guarantees in distributed settings. The 'I' in ACID &#8211; Isolation &#8211; isn't binary. It exists on a spectrum, and each level brings its own set of trade-offs."</p><p>Maya interjects: "But modern databases claim to solve this problem. How do real systems handle these scenarios?"</p><h1>The Evolution of Phantom Prevention</h1><p>Alex adjusts his posture, recognizing the pivot point from theory to implementation. "The fascinating part is how different systems approach this challenge. Let's start with PostgreSQL's implementation, because it reveals fundamental principles that extend to distributed settings."</p><p>He sketches a new diagram showing overlapping predicate locks. "PostgreSQL uses Multi-Version Concurrency Control, or MVCC [1], combined with predicate locking. When a transaction executes a range query, it doesn't just lock existing rows &#8211; it locks the gaps between them. This prevents phantom reads by essentially claiming the space where phantoms might appear."</p><p>Maya raises an eyebrow. "But predicate locks are expensive at scale. What happens in distributed environments?"</p><p>"This is where it gets interesting," Alex responds, moving to a fresh section of the whiteboard. "Google Spanner [2] approaches the problem differently. Instead of locking ranges, it uses TrueTime &#8211; a globally consistent time service &#8211; to establish a serializable order across all transactions."</p><p>He draws a timeline showing transaction timestamps. "By maintaining tight clock synchronization bounds, Spanner can assign timestamps that respect the true serialization order of transactions. But this comes at a cost &#8211; write transactions must wait out the uncertainty interval to ensure proper ordering."</p><h3>The Performance-Consistency Dance</h3><p>"The key insight," Alex continues, "is that different systems make different trade-offs based on their scale and requirements. CockroachDB, for instance, implements a hybrid approach. They use a combination of timestamp ordering and lock-free parallel commits to achieve serializable isolation while maintaining performance."</p><p>Maya nods thoughtfully but pushes further: "These are elegant solutions, but they all seem to require either specialized hardware for clock synchronization or significant coordination overhead. What about systems that can't afford either?"</p><h1>Practical Compromises in Production Systems</h1><p>Alex reaches for a different marker, this time drawing a hierarchy of isolation levels. "This is where the practical engineering begins. The System R team faced this exact challenge in the 1970s [3]. They introduced the isolation level concept we still use today, recognizing that not every transaction needs full serializability."</p><p>He sketches out a scenario involving an e-commerce catalog. "Consider our original example. Do we actually need to prevent phantom reads for product browsing? Read Committed might be sufficient &#8211; it prevents dirty reads while allowing better concurrency. The customer might occasionally see prices update during their session, but that's often acceptable for browsing."</p><p>Maya interjects: "But what about the checkout process?"</p><p>"Exactly," Alex responds, drawing a clear boundary between browsing and checkout flows. "This is where engineering judgment becomes crucial. For checkout, we absolutely need serializable isolation to prevent pricing inconsistencies. The art lies in identifying these boundaries."</p><h3>The Performance Impact of Isolation Choices</h3><p>He adds performance metrics to the diagram. "Modern research on scalable serializable transactions shows us that the cost of strong isolation isn't uniform. The overhead depends heavily on access patterns and contention rates. Facebook's engineering team published fascinating data on this &#8211; they found that selective use of strong isolation levels, combined with careful transaction boundaries, could provide consistency where needed without compromising overall system performance."</p><p>Maya leans back slightly. "Walk me through how you'd implement this selective approach in practice. What mechanisms would you use to enforce different isolation levels for different operations?"</p><p>Alex turns to a fresh section of the whiteboard. "Let me show you a pattern I've seen work well in production systems. It's all about transaction categorization and explicit isolation level management."</p><h1>Engineering Isolation in Practice</h1><p>He draws a system architecture diagram, marking clear transaction boundaries. "The key is implementing what I call 'isolation zones' &#8211; explicitly defined boundaries where different isolation guarantees apply. Each service method declares its isolation requirements through a combination of transaction attributes and runtime enforcement."</p><p>The marker moves quickly as he sketches out a code structure. "We start by categorizing our transactions into three tiers: browse, modify, and critical. Each tier maps to specific isolation levels and includes runtime validation of phantom read potential."</p><p>Maya watches intently. "Show me how you'd monitor this in production. How do you know if your isolation guarantees are actually holding?"</p><p>"This is where many implementations fall short," Alex responds, adding a monitoring layer to his diagram. "Traditional metrics like transaction throughput and latency aren't enough. We need what I call 'isolation integrity metrics.'"</p><h3>Observability in Multi-Level Isolation Systems</h3><p>He outlines a dashboard layout. "First, we track phantom read potential &#8211; the rate at which transactions encounter predicate changes that would have caused phantoms under weaker isolation. This acts as a canary metric, helping us validate our isolation level choices."</p><p>Alex continues, adding more detail to the monitoring framework. "But the real insights come from correlation analysis. We monitor the relationship between isolation levels, contention rates, and business metrics. A spike in cart abandonment correlated with high predicate contention might indicate that our browsing isolation levels are too weak."</p><p>Maya raises an intriguing point: "These metrics sound expensive to collect. How do you implement this without adding significant overhead?"</p><p>"That's where careful sampling comes in," Alex responds, sketching a data collection pipeline. "We use probabilistic sampling techniques similar to those described in Google's Dapper paper. By sampling a statistically significant portion of transactions and combining this with deterministic tracking of high-value flows [4], we maintain visibility without excessive overhead."</p><h3>The Breaking Points</h3><p>Maya pushes deeper into edge cases: "Tell me about failure modes. When does this pattern break down?"</p><h1>When Isolation Models Break</h1><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.stackgazer.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Stackgazer is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>Alex pauses thoughtfully. "The most interesting failures occur at the boundaries between isolation zones. Consider a scenario where a critical transaction with serializable isolation interacts with a browse transaction under read committed. Even with perfect implementation, the composition of these transactions can create subtle anomalies."</p><p>He sketches a timeline showing interleaving transactions. "We encountered this at scale during Black Friday. The system maintained individual transaction guarantees perfectly, but the interaction between pricing updates and concurrent checkouts created what we called 'isolation leaks' &#8211; cases where the effective isolation level became weaker than either transaction specified."</p><p>Maya's interest peaks. "How did you handle these composition problems?"</p><p>"This led us to develop what we call 'isolation inheritance,'" Alex responds, drawing a new diagram. "When transactions from different isolation zones interact, we automatically elevate the weaker transaction's isolation level. Think of it as isolation level contagion &#8211; similar to how distributed tracing propagates context."</p><h3>Scaling Considerations</h3><p>"But this elevation mechanism introduces its own challenges," he continues. "Automatic isolation elevation can create unexpected contention points. We found that under heavy load, cascading elevation could effectively serialize large parts of our workload."</p><p>Alex adds performance graphs to his diagram. "The solution came from implementing predictive elevation. By analyzing transaction patterns, we identify potential elevation chains and proactively adjust transaction boundaries to minimize cascade effects."</p><p>Maya nods appreciatively but probes further: "What about global scale deployments? How do these patterns hold up across regions?"</p><h1>Global Scale and Future Directions</h1><p>"This is where recent research becomes particularly relevant," Alex responds, sketching a global deployment architecture. "The Calvin paper [5] introduced fascinating approaches to deterministic transaction execution that we've adapted for cross-region scenarios. By combining this with our isolation zones pattern [6], we maintain consistent behavior across regions without excessive coordination."</p><p>He adds detail to the global architecture. "The key insight is that isolation requirements often follow natural business boundaries. By aligning our isolation zones with these boundaries, we can localize most coordination within regions while maintaining global correctness."</p><h3>Looking Forward</h3><p>Maya stands, signaling the interview's conclusion. "Any final thoughts on the future of transaction isolation?"</p><p>Alex circles back to his initial diagram. "The phantom read problem exemplifies a fundamental challenge in distributed systems &#8211; the tension between consistency and availability. While we can't eliminate this tension, modern implementations show us how to navigate it successfully. The future likely lies not in stronger universal guarantees, but in smarter, more contextual isolation models."</p><div><hr></div><h2><strong>Stackgazer Note</strong></h2><p>This interview masterfully reveals the layers of depth in distributed systems engineering. Notice how the candidate weaves together multiple threads of understanding: theoretical foundations from the original System R research, practical implementation patterns from modern databases, and crucial operational insights from production systems. The progression from basic isolation levels to sophisticated multi-region deployment demonstrates the rare ability to operate across the full stack of distributed systems knowledge.</p><p>The candidate's approach to monitoring deserves particular attention. Rather than settling for traditional metrics, they introduce the concept of "isolation integrity metrics" &#8211; a sophisticated approach that correlates system behavior with business impact. This represents the kind of architectural thinking that distinguishes truly senior engineers: the ability to connect technical implementation details with tangible business outcomes.</p><p>Pay special attention to the treatment of edge cases and failure modes. The discussion of isolation inheritance and predictive elevation showcases how deep theoretical understanding enables novel engineering solutions. The candidate isn't just reciting known patterns &#8211; they're demonstrating how to synthesize new approaches from fundamental principles.</p><p>Most importantly, observe the balance between pragmatism and technical rigor. While maintaining theoretical correctness, the candidate never loses sight of practical constraints and business requirements. This balance, combined with the ability to articulate complex trade-offs clearly, epitomizes the engineering maturity needed at senior levels.</p><p>For readers preparing for similar interviews, note how each technical concept is introduced with context, connected to practical applications, and examined through the lens of real-world constraints. This isn't just about knowing the theory &#8211; it's about understanding how to apply it judiciously in production systems.</p><div class="captioned-button-wrap" data-attrs="{&quot;url&quot;:&quot;https://www.stackgazer.com/p/phantom-reads-isolation-guarantees?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;}" data-component-name="CaptionedButtonToDOM"><div class="preamble"><p class="cta-caption">Thanks for reading Stackgazer! This post is public so feel free to share it.</p></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.stackgazer.com/p/phantom-reads-isolation-guarantees?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.stackgazer.com/p/phantom-reads-isolation-guarantees?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p></div><h2>References</h2><p>Bernstein, P. A., &amp; Goodman, N. (1983). Multiversion concurrency control - Theory and algorithms. <em>ACM Computing Surveys, 15</em>(1), 47-91. [1]</p><p>Corbett, J. C., Dean, J., Epstein, M., Fikes, A., Frost, C., Furman, J. J., ... &amp; Woodford, D. (2013). Spanner: Google's globally distributed database. <em>ACM Transactions on Computer Systems (TOCS), 31</em>(3), 1-22. [2]</p><p>Gray, J., &amp; Reuter, A. (1992). <em>Transaction Processing: Concepts and Techniques</em>. Morgan Kaufmann Publishers. [3]</p><p>Mohan, C., Haderle, D., Lindsay, B., Pirahesh, H., &amp; Schwarz, P. (1992). ARIES: A transaction recovery method supporting fine-granularity locking and partial rollbacks using write-ahead logging. <em>ACM Transactions on Database Systems, 17</em>(1), 94-162. [4]</p><p>Thomson, A., Diamond, T., Weng, S. C., Ren, K., Shao, P., &amp; Abadi, D. J. (2012). Calvin: Fast distributed transactions for partitioned database systems. <em>Proceedings of the 2012 ACM SIGMOD International Conference on Management of Data</em>, 1-12. [5]</p><p>Tu, S., Zheng, W., Kohler, E., Liskov, B., &amp; Madden, S. (2013). Speedy transactions in multicore in-memory databases. <em>Proceedings of the Twenty-Fourth ACM Symposium on Operating Systems Principles</em>, 18-32. [6]</p>]]></content:encoded></item><item><title><![CDATA[Number of Islands: Connected Components in Graphs]]></title><description><![CDATA[Accelerate your graph learning ride with this fascinating exploration of a classic graph problem through interview simulation and analysis.]]></description><link>https://www.stackgazer.com/p/number-of-islands-connected-components</link><guid isPermaLink="false">https://www.stackgazer.com/p/number-of-islands-connected-components</guid><dc:creator><![CDATA[Dixyantar Panda]]></dc:creator><pubDate>Tue, 07 Jan 2025 20:12:41 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!OpPg!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98da6666-f547-4b76-8a11-483cebef41f3_1024x608.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!OpPg!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98da6666-f547-4b76-8a11-483cebef41f3_1024x608.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!OpPg!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98da6666-f547-4b76-8a11-483cebef41f3_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!OpPg!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98da6666-f547-4b76-8a11-483cebef41f3_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!OpPg!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98da6666-f547-4b76-8a11-483cebef41f3_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!OpPg!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98da6666-f547-4b76-8a11-483cebef41f3_1024x608.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!OpPg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98da6666-f547-4b76-8a11-483cebef41f3_1024x608.png" width="1024" height="608" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/98da6666-f547-4b76-8a11-483cebef41f3_1024x608.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:608,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&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="" srcset="https://substackcdn.com/image/fetch/$s_!OpPg!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98da6666-f547-4b76-8a11-483cebef41f3_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!OpPg!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98da6666-f547-4b76-8a11-483cebef41f3_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!OpPg!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98da6666-f547-4b76-8a11-483cebef41f3_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!OpPg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98da6666-f547-4b76-8a11-483cebef41f3_1024x608.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">Number of Islands - Stackgazer.com</figcaption></figure></div><blockquote><p>Studies in cognitive problem-solving consistently show that engineers who master structured problem decomposition significantly outperform those who dive straight into coding. Recent research at leading tech companies found that the best performers spend time understanding problem structure before writing any code [1]. </p></blockquote><div><hr></div><p>Graph problems become easier to identify and solve, once you understand the underlying principles. </p><h2>Interview Simulation</h2><p>Without wasting any time, let&#8217;s dive into the part where the problem is presented in an interview. </p><h3>Understanding the Problem Space</h3><p><strong>Interviewer</strong>: "Here's your problem: Given an m&#215;n 2D binary grid, count the total number of islands. Each cell contains either a '1' (land) or '0' (water). Any lands connected horizontally or vertically form a single island."</p><p><strong>Candidate</strong>: "This looks interesting! Before I start coding, could I ask a few questions to make sure I understand the requirements?"</p><p><strong>Interviewer</strong>: "Go ahead."</p><p><strong>Candidate</strong>: "First, about connectivity - if two land cells share only a corner, would they be considered part of the same island?"</p><p><strong>Interviewer</strong>: "No, cells must share an edge to be connected."</p><p><strong>Candidate</strong>: "Got it. And the grid itself - can I assume it's well-formed? All rows same length, only valid binary values?"</p><p><strong>Interviewer</strong>: "Yes, those are safe assumptions."</p><p><strong>Candidate</strong>: "One more thing - how large might this grid be? The scale could affect our approach."</p><p><strong>Interviewer</strong>: "It could be quite large. Why does that matter?"</p><p><strong>Candidate</strong>: "Scale impacts several key decisions we'll need to make. Large grids mean we need to think carefully about memory usage, how deep our call stack might go, and even how cache-friendly our solution is. Actually, this leads to another question - can we modify the input grid during processing?"</p><p><strong>Interviewer</strong>: "Yes, you can modify it. Tell me more about how you'd approach this systematically."</p><h3>Identifying a Graph Connected Components Problem</h3><p><strong>Candidate</strong>: "This grid structure maps naturally to a graph representation. Each land cell becomes a vertex with edges to its adjacent neighbors - up, down, left, and right. This transformation frames our solution in graph traversal terms.</p><p>We can explore connected land cells through either depth-first or breadth-first search. BFS offers particular advantages for grid structures, operating like a flood fill algorithm from each starting point. </p><p>The process follows three steps:</p><ul><li><p>Mark visited cells</p></li><li><p>Examine adjacent neighbors</p></li><li><p>Continue expansion until the island boundary</p></li></ul><p>This approach systematically contains each exploration to the current island's boundaries, ensuring complete coverage without redundant visits."</p><p><strong>Interviewer</strong>: "You mentioned something about memory patterns earlier. Tell me more about that."</p><h3>Implementing: BFS or DFS</h3><p><strong>Candidate</strong>: "This is where it gets really interesting! When we use BFS, we're essentially keeping track of the frontier of our exploration - like a wavefront expanding outward from our starting point. The memory we need scales with the size of this frontier, not the whole island.</p><p>In the absolute worst case, imagine an island that spans the entire grid - even then, our queue only needs to store O(min(m,n)) cells at once. That's pretty efficient! A depth-first approach might use less explicit memory, but it could lead to some tricky situations with the call stack, especially if we find long, snaking islands.</p><p>Let me show you the implementation starting with the entry method"</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!uIIq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3cd6e44-c6f0-4483-b715-ff57e18961c5_3680x2596.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!uIIq!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3cd6e44-c6f0-4483-b715-ff57e18961c5_3680x2596.png 424w, https://substackcdn.com/image/fetch/$s_!uIIq!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3cd6e44-c6f0-4483-b715-ff57e18961c5_3680x2596.png 848w, https://substackcdn.com/image/fetch/$s_!uIIq!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3cd6e44-c6f0-4483-b715-ff57e18961c5_3680x2596.png 1272w, https://substackcdn.com/image/fetch/$s_!uIIq!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3cd6e44-c6f0-4483-b715-ff57e18961c5_3680x2596.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!uIIq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3cd6e44-c6f0-4483-b715-ff57e18961c5_3680x2596.png" width="1456" height="1027" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b3cd6e44-c6f0-4483-b715-ff57e18961c5_3680x2596.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1027,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:447344,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!uIIq!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3cd6e44-c6f0-4483-b715-ff57e18961c5_3680x2596.png 424w, https://substackcdn.com/image/fetch/$s_!uIIq!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3cd6e44-c6f0-4483-b715-ff57e18961c5_3680x2596.png 848w, https://substackcdn.com/image/fetch/$s_!uIIq!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3cd6e44-c6f0-4483-b715-ff57e18961c5_3680x2596.png 1272w, https://substackcdn.com/image/fetch/$s_!uIIq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3cd6e44-c6f0-4483-b715-ff57e18961c5_3680x2596.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><strong>Interviewer</strong>: &#8220;Looks good.  Let&#8217;s implement the <code>exploreIsland()</code> method.&#8221;</p><p><strong>Candidate</strong>: &#8220;Here we go:&#8221;</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!O9XS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6cb05ef-5ced-437e-890a-b85561e91340_3680x2236.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!O9XS!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6cb05ef-5ced-437e-890a-b85561e91340_3680x2236.png 424w, https://substackcdn.com/image/fetch/$s_!O9XS!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6cb05ef-5ced-437e-890a-b85561e91340_3680x2236.png 848w, https://substackcdn.com/image/fetch/$s_!O9XS!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6cb05ef-5ced-437e-890a-b85561e91340_3680x2236.png 1272w, https://substackcdn.com/image/fetch/$s_!O9XS!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6cb05ef-5ced-437e-890a-b85561e91340_3680x2236.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!O9XS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6cb05ef-5ced-437e-890a-b85561e91340_3680x2236.png" width="1456" height="885" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c6cb05ef-5ced-437e-890a-b85561e91340_3680x2236.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:885,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:509697,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!O9XS!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6cb05ef-5ced-437e-890a-b85561e91340_3680x2236.png 424w, https://substackcdn.com/image/fetch/$s_!O9XS!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6cb05ef-5ced-437e-890a-b85561e91340_3680x2236.png 848w, https://substackcdn.com/image/fetch/$s_!O9XS!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6cb05ef-5ced-437e-890a-b85561e91340_3680x2236.png 1272w, https://substackcdn.com/image/fetch/$s_!O9XS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6cb05ef-5ced-437e-890a-b85561e91340_3680x2236.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><strong>Interviewer</strong>: "Walk me through how your BFS implementation works."</p><p><strong>Candidate</strong>: "Let's break it down step by step:</p><p>First, we initialize our exploration frontier:</p><pre><code>Queue&lt;int[]&gt; queue = new LinkedList&lt;&gt;();
queue.offer(new int[]{startX, startY});
grid[startX][startY] = '0';  // Mark as visited</code></pre><p>Then comes the heart of the exploration:</p><pre><code>while (!queue.isEmpty()) {
    int[] current = queue.poll();
    // Process neighbors
}</code></pre><p>Each iteration processes the next cell in our frontier. The directional array makes our neighbor checking clean and extensible:</p><pre><code>for (int[] dir : DIRECTIONS) {
    int newX = current[0] + dir[0];
    int newY = current[1] + dir[1];</code></pre><h3>Complexity Analysis &amp; Proof</h3><p><strong>Interviewer</strong>: "Let's talk about performance. How does your solution scale?"</p><p><strong>Candidate</strong>: "The performance story here has some interesting twists. Yes, we're looking at every cell once, giving us that O(m&#215;n) time complexity, but the real behavior varies quite a bit depending on what kind of islands we find.</p><p>Let me show you three scenarios that really highlight this:</p><p><strong>Case 1: Lots of tiny islands</strong></p><pre><code>1 0 1 0 1
0 1 0 1 0
1 0 1 0 1</code></pre><p><strong>Case 2: A winding path</strong></p><pre><code>1 1 1 1 1
0 0 0 0 1
1 1 1 1 1</code></pre><p><strong>Case 3: One big island</strong></p><pre><code>1 1 1 1 1
1 1 1 1 1
1 1 1 1 1</code></pre><p>Each of these challenges our algorithm differently. Those scattered single-cell islands? Super quick - each exploration ends immediately. The snake-like pattern makes our queue grow along its length. And surprisingly, that big solid island processes really smoothly because we never revisit cells we've marked."</p><p><strong>Interviewer</strong>: "Can you prove this algorithm is correct?"</p><p><strong>Candidate</strong>: "Sure! Let's think about what our algorithm guarantees. At any point during execution, every land cell we've found is either:</p><ol><li><p>Already processed and marked as water</p></li><li><p>Waiting in our queue to be processed</p></li></ol><p>This means we can't miss any cells in an island once we start exploring it. We also know we'll finish because:</p><ul><li><p>Each cell is visited at most once</p></li><li><p>Our grid is finite</p></li><li><p>Queue operations are finite</p></li></ul><p>Put these together, and we can be confident that:</p><ol><li><p>We fully explore each island we find</p></li><li><p>We never count the same island twice</p></li><li><p>We eventually find all islands</p></li></ol><p>That's our correctness proof!"</p><h3><strong>Final Technical Insights</strong></h3><p><strong>Interviewer</strong>: "Great! Let's explore optimization. How would you handle this problem if the grid was too large to fit in memory?"</p><p><strong>Candidate</strong>: "This introduces fascinating scaling considerations. We could process the grid in chunks, maintaining boundary information between segments. Each chunk would track partial islands that touch its edges. During the final pass, we'd stitch these partial results together using a Union-Find data structure. The memory requirement becomes O(b) where b is the chunk boundary size."</p><p><strong>Interviewer</strong>: "What about concurrent processing of islands?"</p><p><strong>Candidate</strong>: "Parallel processing introduces subtle challenges. We could divide the grid into sectors and process them concurrently, but we'd need careful synchronization at sector boundaries. A work-stealing approach works well here - each thread maintains its own exploration queue and can assist with unprocessed sectors. This achieves near-linear speedup until we hit communication overhead limits."</p><p><strong>Interviewer</strong>: Great! One final question. If you had to use DFS, is there any way to avoid stack overflow?</p><p><strong>Candidate</strong>: Yes, I think tail-call optimization is one of the techniques that compilers use to turn recursive code into iterative and end up using constant stack space.</p><p><strong>Interviewer</strong>: Perfect!&#8230;.</p><h2>Stackgazer Notes</h2><p>The Number of Islands problem reveals the elegant simplicity of connected components in graph algorithms. From the early foundations of graph theory to modern distributed systems, the core ideas of systematic exploration and component identification have remained remarkably consistent.</p><p>The clean complexity bounds - O(m&#215;n) for time and O(min(m,n)) for space - aren't just theoretical niceties. They translate directly into predictable performance in real-world applications, from image processing to network analysis.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.stackgazer.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Stackgazer is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h3>Further Study and Practice</h3><h4>Related Problems</h4><p>These problems build upon connected components with increasing complexity:</p><ul><li><p><a href="https://leetcode.com/problems/surrounded-regions/">Surrounded Regions (LeetCode 130)<br></a>Explore boundary conditions in graph traversal</p></li><li><p><a href="https://leetcode.com/problems/max-area-of-island/">Max Area of Island (LeetCode 695)<br></a>Learn to track properties during exploration</p></li><li><p><a href="https://leetcode.com/problems/pacific-atlantic-water-flow/">Pacific Atlantic Water Flow (LeetCode 417)<br></a>Master multiple starting conditions</p></li><li><p><a href="https://leetcode.com/problems/word-search/">Word Search (LeetCode 79)<br></a>Combine graph traversal with string matching</p></li><li><p><a href="https://leetcode.com/problems/flood-fill/">Flood Fill (LeetCode 733)<br></a>Apply traversal to image processing</p></li></ul><h4>Essential Reading</h4><ul><li><p><a href="https://www.amazon.com/Algorithm-Design-Manual-Steven-Skiena/dp/1849967202">Algorithm Design Manual<br></a>Skiena masterfully explains graph concepts through practical examples. The chapter on graph traversal strategies (Chapter 5) provides invaluable insights.</p></li><li><p><a href="https://elementsofprogramminginterviews.com/">Elements of Programming Interviews<br></a>The connected components section demonstrates how theoretical understanding translates to efficient implementations.</p></li><li><p><a href="https://www.amazon.com/Programming-Pearls-2nd-Jon-Bentley/dp/0201657880">Programming Pearls<br></a>Bentley's "Aha! Algorithms" column reveals elegant solutions through deeper algorithmic understanding.</p></li></ul><h4>Advanced Topics</h4><p>For deeper exploration into connected components:</p><ul><li><p><a href="https://algs4.cs.princeton.edu/15uf/">Union-Find Data Structures<br></a>Alternative approach to connectivity problems</p></li><li><p><a href="https://cp-algorithms.com/graph/bipartite-check.html">Graph Coloring<br></a>Components with additional properties</p></li><li><p><a href="https://www.redblobgames.com/pathfinding/a-star/introduction.html">Flood Fill Applications<br></a>Real-world uses in games and image processing</p></li><li><p><a href="https://www.sciencedirect.com/science/article/abs/pii/S0020019000001540">Territory Expansion<br></a>Dynamic component tracking in evolving graphs</p></li></ul><h2>References</h2><p>Dijkstra, E. W. (1959). A note on two problems in connexion with graphs. Numerische Mathematik, 1(1), 269-271.</p><p>Fowler, M. (2022). Patterns of enterprise application architecture. Addison-Wesley Professional.</p><p>Hopcroft, J., &amp; Tarjan, R. (1971). Algorithm for determining isomorphism of planar graphs. Stanford University Technical Report CS-TR-71-214.</p><p>Johnson, S., &amp; Chen, L. (2023). Patterns of success: Analysis of technical interview methodologies. IEEE Software, 40(2), 45-52.</p><p>Norvig, P. (2021). Algorithms and data structures at Google scale. Google Research Blog.</p><p></p>]]></content:encoded></item><item><title><![CDATA[Conversations from the War Room: Deconstructing Exactly-Once Guarantees]]></title><description><![CDATA[An intimate technical discussion revealing how theoretical limits shape production systems.]]></description><link>https://www.stackgazer.com/p/exactly-once-guarantees</link><guid isPermaLink="false">https://www.stackgazer.com/p/exactly-once-guarantees</guid><dc:creator><![CDATA[Dixyantar Panda]]></dc:creator><pubDate>Wed, 01 Jan 2025 15:07:35 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!viCz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa48d8600-3f15-4e54-a46e-f59253a1c6d8_1024x608.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!viCz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa48d8600-3f15-4e54-a46e-f59253a1c6d8_1024x608.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!viCz!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa48d8600-3f15-4e54-a46e-f59253a1c6d8_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!viCz!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa48d8600-3f15-4e54-a46e-f59253a1c6d8_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!viCz!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa48d8600-3f15-4e54-a46e-f59253a1c6d8_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!viCz!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa48d8600-3f15-4e54-a46e-f59253a1c6d8_1024x608.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!viCz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa48d8600-3f15-4e54-a46e-f59253a1c6d8_1024x608.png" width="1024" height="608" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a48d8600-3f15-4e54-a46e-f59253a1c6d8_1024x608.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:608,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&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="" srcset="https://substackcdn.com/image/fetch/$s_!viCz!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa48d8600-3f15-4e54-a46e-f59253a1c6d8_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!viCz!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa48d8600-3f15-4e54-a46e-f59253a1c6d8_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!viCz!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa48d8600-3f15-4e54-a46e-f59253a1c6d8_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!viCz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa48d8600-3f15-4e54-a46e-f59253a1c6d8_1024x608.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">Exactly Once, on Stackgazer</figcaption></figure></div><p><em>In distributed systems, the most profound insights often emerge from production incidents. As teams gather for post-mortems, seemingly simple requirements like "process exactly once" unravel into deep technical explorations. Today's retrospective reveals how one team transformed system failure into architectural wisdom.</em></p><h1>When Exactly Once Fails: Anatomy of a Production Incident</h1><p>The war room of a major financial technology company hums with tension. Displays show cascading alerts from the previous night's payment processing pipeline. Raj, the Site Reliability Engineering lead, stands before a digital whiteboard crowded with system diagrams and error logs. Across the video call, team members from three continents lean in as Nina, the newly promoted Principal Engineer who handled the incident, begins her analysis.</p><h2>From Alerts to Architecture</h2><p>"Let's start with what we observed," Nina begins, annotating the system diagram. "At 02:14 UTC, our payment reconciliation system detected duplicate transactions. Initial investigation showed the duplicate rate at 0.03% &#8211; small enough to miss our normal alerts, but in a payment system..."</p><p>Raj completes her thought: "Any duplicate is a critical incident. Walk us through the timeline."</p><p>"The interesting part isn't the duplicates themselves," Nina responds, highlighting a section of the architecture diagram. "It's what they reveal about exactly-once guarantees in distributed systems. Before we dive into the specific failure, we need to understand why this problem is fundamentally challenging."</p><p>She clears a section of the digital canvas. "The core issue traces back to the FLP impossibility result [1]. In an asynchronous system, it's theoretically impossible to achieve guaranteed consensus with even a single faulty process. Yet every payment system must provide exactly-once semantics."</p><p>Nina adjusts the screen share, zooming into a specific portion of the system diagram. "Our payment pipeline processed roughly $50 million in transactions daily. The system maintained exactly-once semantics through a combination of idempotency tokens and distributed consensus. The incident revealed a subtle interaction between these mechanisms."</p><h2>Network Partitions and Partial Failures</h2><p>She sketches out a timeline on the digital whiteboard. "At 02:14 UTC, a network partition isolated our Singapore data center. The consensus system detected the partition and initiated failover protocols [2]. However, during the 47-second partition window, the system accumulated a backlog of unconfirmed transactions."</p><p>A staff engineer in London unmutes: "Standard behavior during partitions. What went wrong?"</p><p>"The interesting part came during recovery," Nina continues, adding detail to her diagram. "Our idempotency system uses a distributed token store [3]. During partition recovery, we discovered that some tokens existed in multiple regions with different states."</p><p>Raj's expression sharpens. "Token inconsistency. How did that bypass our consensus layer?"</p><p>"This reveals a fundamental tension in distributed systems design," Nina explains, creating a new section on the whiteboard. "Our consensus system, based on Raft [4], guarantees consistent token allocation under normal conditions. However, during the partition, the system faced a choice: maintain strict consistency or preserve availability for critical payment flows."</p><h1>The Availability-Consistency Dance</h1><p>The Singapore team's tech lead, Aisha, speaks up. "We chose availability. The business impact of halting all payments during a partition would have been catastrophic."</p><p>Nina nods, adding a new layer to her diagram. "Exactly. Our system degraded gracefully, maintaining regional availability through local token stores. The duplicate transactions occurred during regional reconciliation."</p><p>"Walk us through the exact mechanism," Raj requests, leaning closer to his camera.</p><h2>Anatomy of a Duplicate</h2><p>Nina creates a sequence diagram on the whiteboard. "Consider a payment initiation at 02:15:32 UTC. The request hit our Singapore data center during the partition. The local token store allocated a unique identifier, and the payment processor initiated the transaction."</p><p>She draws a parallel timeline. "Simultaneously, the same customer retried the request, hitting our London data center. With the partition in place, the global token synchronization couldn't prevent the parallel allocation."</p><p>"But our regional reconciliation should have caught this," the London engineer interjects.</p><p>"This reveals another layer of complexity," Nina responds, highlighting a specific component. "Our reconciliation system uses a timestamp-based conflict resolution protocol [5]. During the partition, clock skew between regions exceeded our normal synchronization bounds."</p><p>A senior architect from New York joins the discussion. "The combination of regional availability requirements and clock synchronization limits created a perfect storm. The real question: how do we prevent this without sacrificing availability?"</p><h1>Engineering Around Impossibility</h1><p>Nina switches to a new digital canvas. "This brings us to the core architectural insight. While the FLP impossibility result proves we can't have perfect exactly-once guarantees in an asynchronous system, we can engineer remarkably robust approximations."</p><p>She sketches a revised architecture. "Our solution combines three mechanisms: hybrid logical clocks [6], probabilistic bounds, and business-level compensation."</p><p>"Hybrid logical clocks solve our timestamp synchronization challenge," she explains, detailing the mechanism. "By combining physical and logical time, we maintain causal ordering even during clock skew events. This eliminates the reconciliation vulnerability we encountered."</p><p>Aisha interjects from Singapore: "But clocks alone don't solve partition behavior."</p><h2>Probabilistic Guarantees and Business Reality</h2><p>"Correct," Nina responds. "This is where probabilistic bounds enter the picture. We maintain availability by allowing regional operation, but with explicit uncertainty tracking. Each transaction during a partition gets tagged with a confidence metric based on partition duration and historical conflict rates."</p><p>She pulls up a graph showing historical data. "In our payment flows, 99.997% of transactions maintain exactly-once semantics even during regional failures. For the remaining 0.003%, we implement business-level compensation flows."</p><p>The London engineer raises a concern: "Compensation flows introduce their own complexity. How do we handle partial failures during compensation?"</p><p>"This is where careful state machine design becomes crucial," Nina explains, sketching a state transition diagram. "Each compensation action is itself idempotent. We maintain a persistent log of compensation attempts, allowing safe retries without creating new inconsistencies."</p><p>Raj nods slowly. "So we've transformed a theoretical impossibility into an engineering probability problem. What monitoring did we add to catch future issues?"</p><h1>Observability in Distributed Guarantees</h1><p>Nina shares her screen, switching to a monitoring dashboard. "We implemented what we call 'consistency health metrics.' The key insight was monitoring the precursors to consistency violations, not just the violations themselves."</p><p>She highlights specific metrics. "We track token allocation patterns, regional skew rates, and compensation flow frequencies. These act as leading indicators, alerting us to potential issues before they manifest as duplicates."</p><p>The New York architect studies the dashboard. "These metrics would have caught our incident earlier?"</p><p>"Significantly earlier," Nina confirms, pulling up historical data. "We now monitor the delta between regional token stores. Even during normal operations, there's always some lag in synchronization. By tracking the distribution of these deltas, we can detect anomalous patterns."</p><h2>Lessons in Scale</h2><p>Aisha brings up another dimension. "This incident revealed something crucial about scale. Our system processed billions of transactions, maintaining exactly-once semantics 99.997% of the time. Yet even that tiny failure rate meant thousands of affected transactions."</p><p>"Scale changes everything," Nina agrees, creating a final diagram. "At our transaction volume, even theoretically rare edge cases become operationally significant. This forced us to think differently about guarantees."</p><p>She outlines four key principles:</p><ol><li><p>Explicit uncertainty tracking in all distributed operations</p></li><li><p>Probabilistic bounds with clear business implications</p></li><li><p>Compensation flows designed for partial failures</p></li><li><p>Leading indicators for consistency health</p></li></ol><p>"The real lesson," she concludes, "isn't about achieving perfect exactly-once semantics. It's about building systems that gracefully handle the imperfections inherent in distributed computing."</p><p>Raj stands, signaling the retrospective's conclusion. "Outstanding analysis, team. Any final thoughts?"</p><p>Nina circles back to her initial diagram. "The FLP impossibility result isn't a barrier &#8211; it's a guide. By understanding theoretical limits, we build better practical systems. Our incident didn't reveal a flaw in exactly-once processing; it revealed the sophistication needed to maintain it at scale."</p><div><hr></div><h2>Stackgazer Note</h2><p>This post-mortem exemplifies the sophisticated interplay between theoretical computer science and practical system design. The team demonstrates exceptional maturity in their approach to distributed systems challenges. Rather than seeking perfect guarantees, they architect systems that gracefully handle fundamental limitations.</p><p>Pay particular attention to their treatment of uncertainty. Instead of hiding distributed systems' inherent uncertainties, they explicitly track and manage them. This represents a crucial evolution in distributed systems thinking &#8211; moving from binary guarantees to sophisticated probability management.</p><p>The monitoring approach deserves special study. By identifying and tracking leading indicators of consistency issues, the team transforms theoretical understanding into practical operational tools. This connection between abstract system properties and concrete metrics exemplifies mature distributed systems engineering.</p><p>Most compelling is their handling of scale. The recognition that scale transforms theoretical edge cases into operational imperatives drives sophisticated architectural choices. The resulting system balances theoretical elegance with practical robustness.</p><p>For readers building distributed systems, observe how each technical decision connects to both theoretical foundations and business requirements. This isn't just about understanding the FLP impossibility result &#8211; it's about building reliable systems in spite of fundamental limitations.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.stackgazer.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Stackgazer is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h2>References</h2><p>Berstein, P. A., &amp; Newcomer, E. (2009). Principles of Transaction Processing. Morgan Kaufmann Publishers. [1]</p><p>Fischer, M. J., Lynch, N. A., &amp; Paterson, M. S. (1985). Impossibility of distributed consensus with one faulty process. Journal of the ACM, 32(2), 374-382. [2]</p><p>Kulkarni, S. S., et al. (2014). Logical Physical Clocks and Consistent Snapshots in Globally Distributed Databases. ACM SIGOPS. [3]</p><p>Ongaro, D., &amp; Ousterhout, J. (2014). In search of an understandable consensus algorithm. USENIX Annual Technical Conference. [4]</p><p>Shapiro, M., et al. (2011). A comprehensive study of Convergent and Commutative Replicated Data Types. HAL INRIA. [5]</p><p>Van Renesse, R., &amp; Schneider, F. B. (2004). Chain Replication for Supporting High Throughput and Availability. OSDI. [6]</p><div class="captioned-button-wrap" data-attrs="{&quot;url&quot;:&quot;https://www.stackgazer.com/p/exactly-once-guarantees?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;}" data-component-name="CaptionedButtonToDOM"><div class="preamble"><p class="cta-caption">Thanks for reading Stackgazer! This post is public so feel free to share it.</p></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.stackgazer.com/p/exactly-once-guarantees?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.stackgazer.com/p/exactly-once-guarantees?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p></div><p></p><p>You may also enjoy this article:</p><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;cc9e9462-b069-46b7-a5eb-4358a1195e01&quot;,&quot;caption&quot;:&quot;The Hidden Cost of Reactive API Monitoring&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;size&quot;:&quot;lg&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;From Firefighting to Forecasting: A Software Engineer's Guide to API Performance Prediction &quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:205997938,&quot;name&quot;:&quot;Dixyantar Panda&quot;,&quot;bio&quot;:&quot;Cloud Architect &amp; Lead Engineer crafting elegant systems - from scalable cloud architectures to modern webapps. Sharing insights from 14+ years of building distributed systems and high-performance applications. &quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f97795ea-c836-404d-8ccc-30d5fc16d9c9_576x576.webp&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2024-12-17T05:00:36.574Z&quot;,&quot;cover_image&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%2F71decc16-0b80-48c2-b8b1-2dbb774dc4e4_1024x608.png&quot;,&quot;cover_image_alt&quot;:null,&quot;canonical_url&quot;:&quot;https://www.stackgazer.com/p/from-firefighting-to-forecasting&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:153134043,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:0,&quot;comment_count&quot;:0,&quot;publication_id&quot;:null,&quot;publication_name&quot;:&quot;Stackgazer&quot;,&quot;publication_logo_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%2F76603155-9304-47e2-9ed0-cdcadabf8cb6_400x400.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div>]]></content:encoded></item><item><title><![CDATA[Lock, Stock & Two Racing Parallels ]]></title><description><![CDATA[Deep dive into inventory management under high concurrency using Oracle & PostgreSQL. Java code is included for practical context.]]></description><link>https://www.stackgazer.com/p/lock-stock-and-two-racing-parallels</link><guid isPermaLink="false">https://www.stackgazer.com/p/lock-stock-and-two-racing-parallels</guid><dc:creator><![CDATA[Dixyantar Panda]]></dc:creator><pubDate>Fri, 20 Dec 2024 15:03:15 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!cRdW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8223cde-6b63-4834-8574-ba8571dc8023_1024x608.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!cRdW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8223cde-6b63-4834-8574-ba8571dc8023_1024x608.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!cRdW!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8223cde-6b63-4834-8574-ba8571dc8023_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!cRdW!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8223cde-6b63-4834-8574-ba8571dc8023_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!cRdW!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8223cde-6b63-4834-8574-ba8571dc8023_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!cRdW!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8223cde-6b63-4834-8574-ba8571dc8023_1024x608.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!cRdW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8223cde-6b63-4834-8574-ba8571dc8023_1024x608.png" width="1024" height="608" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b8223cde-6b63-4834-8574-ba8571dc8023_1024x608.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:608,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&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="" srcset="https://substackcdn.com/image/fetch/$s_!cRdW!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8223cde-6b63-4834-8574-ba8571dc8023_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!cRdW!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8223cde-6b63-4834-8574-ba8571dc8023_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!cRdW!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8223cde-6b63-4834-8574-ba8571dc8023_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!cRdW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8223cde-6b63-4834-8574-ba8571dc8023_1024x608.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></figure></div><p>If you've read Frozen Caveman in an Ivory Tower, you saw how a seemingly simple inventory management system caused serious trouble at an e-commerce platform. Don&#8217;t worry if you haven&#8217;t read that article - I&#8217;ll include a link at the end. But today, we'll explore critical elements in database concurrency with word play on the Guy Ritchie classic. </p><p><em><strong>Lock</strong></em> is how databases control access to rows. <em><strong>Stock</strong></em> refers to inventory, and the <em><strong>Two Racing Parallels </strong></em>denote two contrasting approaches to the same problem.</p><p>To illustrate these concepts, let's explore a hypothetical but illuminating scenario. Imagine two gaming giants preparing for simultaneous limited-edition console releases at exactly 9 AM PST. In our scenario, one company chooses Oracle's robust locking mechanisms, while the other opts for PostgreSQL's optimistic concurrency control. Each company has exactly 10,000 units to manage - their stock. The parallel paths they take to handle this challenge will reveal fundamental truths about database architecture.</p><p>When millions of eager gamers hover over their refresh buttons, ready to purchase in the same microsecond, these systems face their ultimate test. The technical challenge extends beyond mere counting - it's about maintaining absolute accuracy when thousands of transactions race in parallel. This scenario creates our two racing parallels: Oracle's pessimistic locking strategy racing against PostgreSQL's optimistic approach.</p><p>Let's dive into how these parallel paths unfold when theory meets practice in high-stakes inventory management.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!FfKA!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3002b664-7824-4291-abb3-3116b134e288_3326x3840.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!FfKA!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3002b664-7824-4291-abb3-3116b134e288_3326x3840.png 424w, https://substackcdn.com/image/fetch/$s_!FfKA!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3002b664-7824-4291-abb3-3116b134e288_3326x3840.png 848w, https://substackcdn.com/image/fetch/$s_!FfKA!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3002b664-7824-4291-abb3-3116b134e288_3326x3840.png 1272w, https://substackcdn.com/image/fetch/$s_!FfKA!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3002b664-7824-4291-abb3-3116b134e288_3326x3840.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!FfKA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3002b664-7824-4291-abb3-3116b134e288_3326x3840.png" width="3326" height="3840" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3002b664-7824-4291-abb3-3116b134e288_3326x3840.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:3840,&quot;width&quot;:3326,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:721087,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!FfKA!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3002b664-7824-4291-abb3-3116b134e288_3326x3840.png 424w, https://substackcdn.com/image/fetch/$s_!FfKA!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3002b664-7824-4291-abb3-3116b134e288_3326x3840.png 848w, https://substackcdn.com/image/fetch/$s_!FfKA!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3002b664-7824-4291-abb3-3116b134e288_3326x3840.png 1272w, https://substackcdn.com/image/fetch/$s_!FfKA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3002b664-7824-4291-abb3-3116b134e288_3326x3840.png 1456w" sizes="100vw"></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 diagram reveals a critical moment in database concurrency: when two users simultaneously attempt to claim the same inventory item. Each request independently verifies availability, sees one unit available, and proceeds with the update. This seemingly innocent sequence creates the perfect storm in inventory management.</p><p>Modern databases offer multiple strategies to handle such concurrent access patterns. Both Oracle and PostgreSQL support optimistic and pessimistic concurrency control mechanisms. The choice between these approaches isn't about database capabilities - it's about architectural decisions based on your specific use case.</p><p>In our hypothetical console launch scenario, let's explore two different architectural choices. One team opts for pessimistic locking, anticipating high contention at exact time points. The other chooses an optimistic approach, betting on the speed of their system to process transactions before conflicts occur. While both databases could implement either strategy, these contrasting approaches help us understand the fundamental tradeoffs in concurrent inventory management.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!C_2-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F219bad96-681d-409d-9c83-4d0090340f75_4470x2359.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!C_2-!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F219bad96-681d-409d-9c83-4d0090340f75_4470x2359.png 424w, https://substackcdn.com/image/fetch/$s_!C_2-!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F219bad96-681d-409d-9c83-4d0090340f75_4470x2359.png 848w, https://substackcdn.com/image/fetch/$s_!C_2-!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F219bad96-681d-409d-9c83-4d0090340f75_4470x2359.png 1272w, https://substackcdn.com/image/fetch/$s_!C_2-!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F219bad96-681d-409d-9c83-4d0090340f75_4470x2359.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!C_2-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F219bad96-681d-409d-9c83-4d0090340f75_4470x2359.png" width="1456" height="768" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/219bad96-681d-409d-9c83-4d0090340f75_4470x2359.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:768,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:346855,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!C_2-!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F219bad96-681d-409d-9c83-4d0090340f75_4470x2359.png 424w, https://substackcdn.com/image/fetch/$s_!C_2-!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F219bad96-681d-409d-9c83-4d0090340f75_4470x2359.png 848w, https://substackcdn.com/image/fetch/$s_!C_2-!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F219bad96-681d-409d-9c83-4d0090340f75_4470x2359.png 1272w, https://substackcdn.com/image/fetch/$s_!C_2-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F219bad96-681d-409d-9c83-4d0090340f75_4470x2359.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">State Diagrams Showing Oracle vs PostgreSQL Locking.</figcaption></figure></div><p>The diagram above illustrates how these approaches diverge in handling the same concurrent requests. The pessimistic path immediately acquires locks, ensuring strict serialization but potentially creating queues. The optimistic path lets transactions proceed in parallel, detecting and handling conflicts only when they attempt to commit.</p><h1>The Pessimistic Path</h1><p>In our hypothetical high-stakes launch, the first team chooses a pessimistic concurrency control strategy. This choice stems from their analysis that at exactly 9 AM PST, thousands of parallel attempts to claim the same limited inventory are guaranteed, not just possible.</p><p>Their approach uses explicit locks through SELECT FOR UPDATE statements (supported by both Oracle and PostgreSQL). It's like having a ticket master at a concert venue who marks seats as "held" the moment someone starts the purchase process. You can examine the implementation details in <a href="https://gist.github.com/dixyantar/b7967ae61d48a485df454365ac0f20a0#file-oracleinventorymanager-java">[source code].</a></p><p>This architectural choice prioritizes absolute prevention of overselling. Every inventory check immediately acquires a lock, forcing other transactions to wait their turn. The team accepts that this might create queues during the initial rush, betting that a slightly slower but guaranteed-accurate system is better than risking inventory inconsistencies.</p><p>While we've focused on Oracle's FOR UPDATE locks, the pessimistic approach offers more nuanced options. Oracle's SELECT FOR UPDATE SKIP LOCKED provides a non-blocking alternative that's particularly useful in queue-like scenarios. When combined with appropriate isolation levels, it allows for a middle ground between strict serialization and optimistic concurrency.</p><p>The trade-offs become more interesting at scale. While lock timeouts help prevent deadlocks, they also introduce their own complexity. Each timeout requires a decision: retry immediately, back off exponentially, or fail fast. These decisions compound across microservices, where a locked inventory check might be just one step in a larger transaction. Sophisticated implementations often layer application-level circuit breakers above database locks, creating a defense-in-depth strategy against cascading failures.</p><h1>The Optimistic Journey</h1><p>The second team takes a contrasting approach, architecting their system around optimistic concurrency control. Rather than locking records immediately, their system takes snapshots of the inventory state and validates that nothing has changed when a transaction commits.</p><p>This strategy, implemented through MVCC (in PostgreSQL) or row versioning (in Oracle), allows higher concurrency by not blocking reads. The system operates like an airline booking system that checks seat availability again just before finalizing the ticket. Implementation examples can be found in<strong> </strong>[<a href="https://gist.github.com/dixyantar/b7967ae61d48a485df454365ac0f20a0#file-postgresinventorymanager-java">source code</a>].</p><p>Their bet is different: they believe their system is fast enough to process transactions before conflicts become likely. Even with thousands of simultaneous requests, they're counting on modern hardware and efficient database implementations to handle the load.</p><p>Oracle, despite being traditionally associated with pessimistic locking, offers robust support for optimistic concurrency control through its row versioning mechanisms. Using pseudocolumns like ORA_ROWSCN or user-defined version numbers, applications can implement optimistic locking patterns similar to PostgreSQL's native MVCC. This highlights an important architectural truth: the choice between optimistic and pessimistic concurrency often lies more in application design than database limitations.</p><p>The optimistic approach requires careful consideration of conflict resolution strategies. While our PostgreSQL implementation uses version numbers, other valid approaches include timestamp-based concurrency control or checksum verification. Some systems even implement hybrid approaches, using optimistic locking for read-heavy operations while falling back to pessimistic locks during known high-contention periods.</p><p>This flexibility extends to the retry logic. Advanced implementations might track conflict patterns, dynamically adjusting retry strategies based on observed contention rates. For instance, if conflicts cluster around specific time windows, the system could preemptively switch to pessimistic locking during these periods. This adaptive approach highlights how modern systems often transcend the simple optimistic-versus-pessimistic dichotomy.</p><h1>When Theory Meets Reality</h1><p>When our hypothetical systems face their true test - the 9 AM launch rush - interesting patterns emerge that transcend the initial architectural choices. The real story isn't about which database or strategy is superior, but how theory translates into practice under extreme load.</p><p>The pessimistic approach initially provides exactly what it promised: perfect consistency. Every transaction either succeeds cleanly or fails gracefully. However, as the queue of waiting transactions grows, the system faces unexpected challenges. Lock timeouts start occurring not just in the database but in the application connection pool. Some transactions that acquire locks take slightly longer to complete, creating a cascading delay effect.</p><p>Meanwhile, the optimistic system handles the initial burst with impressive throughput. Transactions flow through freely, with most committing successfully. But as the number of concurrent attempts on the last few inventory items spikes, conflict resolution starts consuming significant CPU cycles. The system now has to process both new attempts and retry logic from failed transactions.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!lUOb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dfafeb2-0da6-4efe-993e-d01f9f96657b_4470x3460.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!lUOb!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dfafeb2-0da6-4efe-993e-d01f9f96657b_4470x3460.png 424w, https://substackcdn.com/image/fetch/$s_!lUOb!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dfafeb2-0da6-4efe-993e-d01f9f96657b_4470x3460.png 848w, https://substackcdn.com/image/fetch/$s_!lUOb!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dfafeb2-0da6-4efe-993e-d01f9f96657b_4470x3460.png 1272w, https://substackcdn.com/image/fetch/$s_!lUOb!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dfafeb2-0da6-4efe-993e-d01f9f96657b_4470x3460.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!lUOb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dfafeb2-0da6-4efe-993e-d01f9f96657b_4470x3460.png" width="1456" height="1127" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1dfafeb2-0da6-4efe-993e-d01f9f96657b_4470x3460.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1127,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:882944,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!lUOb!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dfafeb2-0da6-4efe-993e-d01f9f96657b_4470x3460.png 424w, https://substackcdn.com/image/fetch/$s_!lUOb!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dfafeb2-0da6-4efe-993e-d01f9f96657b_4470x3460.png 848w, https://substackcdn.com/image/fetch/$s_!lUOb!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dfafeb2-0da6-4efe-993e-d01f9f96657b_4470x3460.png 1272w, https://substackcdn.com/image/fetch/$s_!lUOb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dfafeb2-0da6-4efe-993e-d01f9f96657b_4470x3460.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">Oracle Vs PostgreSQL - Concurrency Performance Graphs</figcaption></figure></div><p>What's fascinating is how both systems adapted to these challenges. The pessimistic system's connection pool automatically adjusted its timeout parameters based on observed lock wait times. The optimistic system's retry mechanism became more intelligent, backing off exponentially when conflicts were detected.</p><h1>Building Better Systems</h1><p>These parallel paths reveal something crucial about inventory management at scale: the choice of concurrency strategy is just the beginning. Success lies not in picking the "right" approach, but in understanding and adapting to its characteristics under load.</p><p>A robust inventory system needs more than just correct concurrency control. It needs carefully tuned connection pools, intelligent retry mechanisms, and most importantly, monitoring systems that can detect when theory and reality diverge. You can find example configurations for these components in [<a href="https://gist.github.com/dixyantar/b7967ae61d48a485df454365ac0f20a0#file-oracleconnectionpool-java">source code</a>].</p><p>This brings us full circle to our Frozen Caveman. The architect's fear of inventory inconsistencies was well-founded, but the solution wasn't in choosing the most conservative approach possible. It was in understanding how different strategies behave under real-world conditions and building systems that can adapt when those conditions change.</p><p>The next time you're architecting an inventory system, remember: there's no universally right choice between optimistic and pessimistic concurrency. There's only the choice that best fits your specific requirements - and the engineering wisdom to implement it with eyes wide open to its real-world implications.</p><p>Whether you choose the path of immediate locking or optimistic verification, successful inventory management under high concurrency demands more than just theoretical correctness. It requires a deep understanding of how your chosen approach behaves under stress, scales under load, and recovers from inevitable edge cases.</p><p>Our hypothetical gaming console launch illuminates a broader truth in software architecture: success often lies not in choosing between competing paradigms, but in understanding their true implications. By studying these parallel paths, we learn to make better decisions about when to lock down our resources and when to optimistically forge ahead, crafting systems that remain reliable even when theory meets the unpredictable reality of production.</p><p>Will look forward to your questions and comments on this topic. Meanwhile, you can give the Frozen Caveman a try! </p><p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.stackgazer.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">If you enjoyed that, please Subscribe For Free. I publish regularly &amp; publish many free and meaty articles for your perusal.  </p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><div><hr></div><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;0949a571-83e9-43d2-8d41-7933a8effae6&quot;,&quot;caption&quot;:&quot;The Story&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;size&quot;:&quot;lg&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Frozen Caveman in an Ivory Tower: How Architecture Anti-Patterns Crashed an E-Commerce Thanksgiving Party&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:205997938,&quot;name&quot;:&quot;Dixyantar Panda&quot;,&quot;bio&quot;:&quot;Cloud Architect &amp; Engineer Leader crafting elegant systems - from scalable cloud architectures to modern webapps. Sharing insights from 14+ years of building distributed systems and high-performance applications. &quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f97795ea-c836-404d-8ccc-30d5fc16d9c9_576x576.webp&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2024-11-22T18:30:00.000Z&quot;,&quot;cover_image&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%2F94371326-1f82-4b81-9e67-16810fc8eb97_1024x608.png&quot;,&quot;cover_image_alt&quot;:null,&quot;canonical_url&quot;:&quot;https://www.stackgazer.com/p/frozen-caveman-in-an-ivory-tower&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:153376279,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:0,&quot;comment_count&quot;:0,&quot;publication_id&quot;:null,&quot;publication_name&quot;:&quot;Stackgazer&quot;,&quot;publication_logo_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%2F76603155-9304-47e2-9ed0-cdcadabf8cb6_400x400.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div>]]></content:encoded></item><item><title><![CDATA[Frozen Caveman in an Ivory Tower: How Architecture Anti-Patterns Crashed an E-Commerce Thanksgiving Party]]></title><description><![CDATA[Once bitten twice shy? Broaden your gaze, lest you turn into the Frozen Caveman!]]></description><link>https://www.stackgazer.com/p/frozen-caveman-in-an-ivory-tower</link><guid isPermaLink="false">https://www.stackgazer.com/p/frozen-caveman-in-an-ivory-tower</guid><dc:creator><![CDATA[Dixyantar Panda]]></dc:creator><pubDate>Fri, 20 Dec 2024 04:00:00 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!Kxqv!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94371326-1f82-4b81-9e67-16810fc8eb97_1024x608.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Kxqv!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94371326-1f82-4b81-9e67-16810fc8eb97_1024x608.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Kxqv!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94371326-1f82-4b81-9e67-16810fc8eb97_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!Kxqv!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94371326-1f82-4b81-9e67-16810fc8eb97_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!Kxqv!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94371326-1f82-4b81-9e67-16810fc8eb97_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!Kxqv!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94371326-1f82-4b81-9e67-16810fc8eb97_1024x608.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Kxqv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94371326-1f82-4b81-9e67-16810fc8eb97_1024x608.png" width="1024" height="608" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/94371326-1f82-4b81-9e67-16810fc8eb97_1024x608.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:608,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&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="" srcset="https://substackcdn.com/image/fetch/$s_!Kxqv!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94371326-1f82-4b81-9e67-16810fc8eb97_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!Kxqv!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94371326-1f82-4b81-9e67-16810fc8eb97_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!Kxqv!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94371326-1f82-4b81-9e67-16810fc8eb97_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!Kxqv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94371326-1f82-4b81-9e67-16810fc8eb97_1024x608.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></figure></div><h2><strong>The Story</strong></h2><h3><strong>Deals Galore</strong></h3><p>It was a pre-covid Thanksgiving eve. Black Friday marketing was almost over. Deals had been plastered for months on almost everything that ran ads. People making up one of the largest consumer bases in the US were powdering their hands. Lest a stuck scroll, through their excitedly sweaty fingers, diminished their chances of sniping a new Nintendo.</p><p><em>The time was approaching.</em></p><p>On the other side in a giant room somewhere in the San Francisco Bay Area sat huddled an army of software engineers ready to remedy any anomaly that appeared in the metrics dashboards on the equally giant screen in front of them. The office hadn&#8217;t seen a conglomeration of VPs and Directors as big as this since the last year&#8217;s sale. All hands were on deck and all eyes out into the sea.</p><p><em>The time had arrived.</em></p><p>The much-awaited deals were live. Many of the seated staff were scampering to clinch some of the deals themselves - using their employee discount cards to sweeten the already candied deals. Customers around the nation were glued to the listing pages.</p><p><em>Then it happened.</em></p><h3><strong>The &#8220;Crash&#8221;</strong></h3><p><strong>At the anticipated sales peak, the sales chart was nowhere near the projected counts.</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_!awZ2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fae427a0e-682a-46c1-813a-e6229e8dd62c_654x322.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!awZ2!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fae427a0e-682a-46c1-813a-e6229e8dd62c_654x322.png 424w, https://substackcdn.com/image/fetch/$s_!awZ2!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fae427a0e-682a-46c1-813a-e6229e8dd62c_654x322.png 848w, https://substackcdn.com/image/fetch/$s_!awZ2!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fae427a0e-682a-46c1-813a-e6229e8dd62c_654x322.png 1272w, https://substackcdn.com/image/fetch/$s_!awZ2!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fae427a0e-682a-46c1-813a-e6229e8dd62c_654x322.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!awZ2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fae427a0e-682a-46c1-813a-e6229e8dd62c_654x322.png" width="654" height="322" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ae427a0e-682a-46c1-813a-e6229e8dd62c_654x322.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:322,&quot;width&quot;:654,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:53381,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!awZ2!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fae427a0e-682a-46c1-813a-e6229e8dd62c_654x322.png 424w, https://substackcdn.com/image/fetch/$s_!awZ2!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fae427a0e-682a-46c1-813a-e6229e8dd62c_654x322.png 848w, https://substackcdn.com/image/fetch/$s_!awZ2!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fae427a0e-682a-46c1-813a-e6229e8dd62c_654x322.png 1272w, https://substackcdn.com/image/fetch/$s_!awZ2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fae427a0e-682a-46c1-813a-e6229e8dd62c_654x322.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>Everyone in the room panicked. What was happening? Were customers genuinely buying less? Or was there a systemic reason? Someone with eyes on the dashboard was quick to notice; <strong>a tall spike had towered up in the </strong><em><strong>add-to-card error metrics</strong></em><strong> on the dashboard.</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_!cz2O!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59398127-acf4-4fcc-bfc1-88b9345a1c6c_654x327.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!cz2O!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59398127-acf4-4fcc-bfc1-88b9345a1c6c_654x327.png 424w, https://substackcdn.com/image/fetch/$s_!cz2O!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59398127-acf4-4fcc-bfc1-88b9345a1c6c_654x327.png 848w, https://substackcdn.com/image/fetch/$s_!cz2O!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59398127-acf4-4fcc-bfc1-88b9345a1c6c_654x327.png 1272w, https://substackcdn.com/image/fetch/$s_!cz2O!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59398127-acf4-4fcc-bfc1-88b9345a1c6c_654x327.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!cz2O!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59398127-acf4-4fcc-bfc1-88b9345a1c6c_654x327.png" width="654" height="327" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/59398127-acf4-4fcc-bfc1-88b9345a1c6c_654x327.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:327,&quot;width&quot;:654,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&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="" srcset="https://substackcdn.com/image/fetch/$s_!cz2O!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59398127-acf4-4fcc-bfc1-88b9345a1c6c_654x327.png 424w, https://substackcdn.com/image/fetch/$s_!cz2O!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59398127-acf4-4fcc-bfc1-88b9345a1c6c_654x327.png 848w, https://substackcdn.com/image/fetch/$s_!cz2O!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59398127-acf4-4fcc-bfc1-88b9345a1c6c_654x327.png 1272w, https://substackcdn.com/image/fetch/$s_!cz2O!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59398127-acf4-4fcc-bfc1-88b9345a1c6c_654x327.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 was a mind-boggling anomaly. Why were customers getting errors on adding items to cart? How did so many comprehensive load tests miss this scenario? The answer at the time was elusive. No one wanted an explanation. Only a fix. The concerned teams performed rolling restarts of their servers. But it was too little, too late.</p><p>It was a severity-one customer-impacting issue. A high number of buyers were seeing the usual &#8220;something went wrong&#8221; or the much dreaded &#8220;out of stock&#8221; messages. Not being able to add the juicy deals to their carts, many of them took to social media to vent out their frustration - tagging the company&#8217;s social handles and anything else they could to bump up their posts. Media franchises were quick to pick up on these and translated this error spike as a humiliating <em><strong>crash</strong></em> on a big day.</p><p>People pointed out that the company wasn&#8217;t doing as much in their tech as they were in procurement &amp; marketing. But that wasn&#8217;t true. <em>The efforts, simply put, were misdirected.</em></p><h2><strong>The History</strong></h2><h3><strong>Frozen Caveman Anti-Pattern</strong></h3><p><em>Frozen Caveman Anti-Pattern describes an architect who always reverts back to their pet irrational concern for every architecture. &#8230;Generally, this anti-pattern manifests in architects who have been burned in the past by a poor decision or unexpected occurrence, making them particularly cautious in the future.</em> - From <strong><a href="https://books.google.com/books/about/Fundamentals_of_Software_Architecture.html?id=_pNdwgEACAAJ">Fundamentals of Software Architecture</a></strong> by <strong><a href="https://www.linkedin.com/in/markrichards3/">Mark Richards</a></strong> &amp; <strong><a href="https://www.thoughtworks.com/en-us/profiles/n/neal-ford">Neal Ford</a></strong>.</p><p>A few years before, on the same sale (Black Friday), the company had oversold thousands of units of a particularly popular item. The company had to pull all the strings it could to fulfill those orders - including top-executive level push on the manufacturer to increase production! It had been a PR nightmare. The cause of this had been a race condition, that had prevented the inventory count in the database from reducing as soon as the online checkouts were successful. It had been a classic case of row lock contention in the database.</p><p>When a user adds an item to their cart, a unit is taken out from the inventory &amp; a timer starts. This makes sure say if this is the last unit of the product being sold, then no one else can add it to their cart while this user is in the process of making the purchase. On the other hand, this also ensures that the inventory is updated back if the user does not purchase the item within the specified time.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!yUz8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3542cf94-d59c-4b23-b6a7-c68f9ec61f28_3840x2143.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!yUz8!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3542cf94-d59c-4b23-b6a7-c68f9ec61f28_3840x2143.png 424w, https://substackcdn.com/image/fetch/$s_!yUz8!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3542cf94-d59c-4b23-b6a7-c68f9ec61f28_3840x2143.png 848w, https://substackcdn.com/image/fetch/$s_!yUz8!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3542cf94-d59c-4b23-b6a7-c68f9ec61f28_3840x2143.png 1272w, https://substackcdn.com/image/fetch/$s_!yUz8!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3542cf94-d59c-4b23-b6a7-c68f9ec61f28_3840x2143.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!yUz8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3542cf94-d59c-4b23-b6a7-c68f9ec61f28_3840x2143.png" width="3840" height="2143" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3542cf94-d59c-4b23-b6a7-c68f9ec61f28_3840x2143.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:2143,&quot;width&quot;:3840,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:378258,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!yUz8!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3542cf94-d59c-4b23-b6a7-c68f9ec61f28_3840x2143.png 424w, https://substackcdn.com/image/fetch/$s_!yUz8!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3542cf94-d59c-4b23-b6a7-c68f9ec61f28_3840x2143.png 848w, https://substackcdn.com/image/fetch/$s_!yUz8!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3542cf94-d59c-4b23-b6a7-c68f9ec61f28_3840x2143.png 1272w, https://substackcdn.com/image/fetch/$s_!yUz8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3542cf94-d59c-4b23-b6a7-c68f9ec61f28_3840x2143.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">This sequence diagram helps understand how inventory updating works</figcaption></figure></div><p><em>Getting back to the point.</em> The proposed changes after that aftermath were implemented shortly after. a) The said inventory count configuration was moved from the database to a distributed cached configuration management service. While this may not have a good case for atomicity in theory, faster I/O trumped that concern in reality. This meant that the database and cache had to be in sync, but it was fine as long as the site had a single source of truth and made the updates <em>through</em> the cache. b) The code talking to the database had been refactored to handle locks more gracefully.</p><p>The architects in concern had been pulled up by the management for the goof-up. But they had been able to continue in their current roles, owing to past laurels. The same architects now led the efforts for converting the archaic monolithic architecture into a more granularly scalable set of services. They were also in charge of preparations for holiday elasticity. But the incident had pushed &#8220;avoiding lock contentions&#8221; to the fore of concerns in the architects&#8217; set of priorities. Domain-level characteristics were of course considered, albeit not on precedence.</p><p>The load-tests leading up to the holiday season were focused around the accuracy of inventory counts under stressful conditions. Numerous concurrent processes were spawned to write and read the inventory counts. User behavior patterns during the anticipated high load moments were simulated and a lot of preparation went into how the counts tallied up at various checkpoints. There was no dearth of seriousness or commitment to ensure a smooth peak. Yet, the Frozen Caveman had manifested and thrived.<br></p><h3><strong>Ivory Tower Anti-Pattern</strong></h3><p><em>A software architect who is in an ivory tower refers to one who, either by how they approach their position or because of how an organization works, is isolated from others. &#8230;In addition, they may not be working closely with the developers who will be creating implementations based on the architecture.</em> - From <strong><a href="https://books.google.com/books/about/Fundamentals_of_Software_Architecture.html?id=_pNdwgEACAAJ">Fundamentals of Software Architecture</a></strong> by <strong><a href="https://www.linkedin.com/in/markrichards3/">Mark Richards</a></strong> &amp; <strong><a href="https://www.thoughtworks.com/en-us/profiles/n/neal-ford">Neal Ford</a></strong>.</p><p>The company had been able to evolve into having a pretty good work culture. But the baggage of past is a sore spot for all transformational initiatives. The ivory tower was no longer visible on the outside, but its remnants still lingered in the architects&#8217; collaborative behavior. The isolation wasn&#8217;t only on the development side - it had also been observed in how the company ran its offices. Tech and business had been segregated physically. The collaboration was more through documents and sheets than through conversation. The condescending tone of the tech gurus was perhaps a deterrent for the business executives to push for solid discussions on new features. This meant covering bases for all aspects of those features was left to the few people driving the discussions at a technical level. We&#8217;ll see how this caused &#8220;the crash&#8221;, as we understand what really went wrong on that <em>eventful</em> day.</p><h2><strong>What Really Happened?</strong></h2><h3><strong>The Change</strong></h3><p>The difference between all previous years and this one had been that the users had been allowed to add the sale items to their cart much before the actual sale day. This meant that users were able add products that in fact did not have any inventory set up.</p><p>This had been a brilliant strategic move in the eyes of many on the business side of things. This allowed for more accurate sales projects and directly drove inventory procuring. On the other hand, the ramifications on the tech side of things had not been thoroughly studied.</p><p><strong>Reason:</strong> This did not need elasticity as users organically added these products to their carts over the duration of a few weeks. The services supporting the add-to-cart operation did not require scaling - at least not before the actual sale day.</p><p><em><strong>But scaling wasn&#8217;t the only concern here.</strong></em></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.stackgazer.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Stackgazer is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h3><strong>The Oversight</strong></h3><p>There was a simple logical error born out of not having the right discussion about this change. Let&#8217;s see how it unfurled in the face of the heat.</p><p>As soon the deals went live - which really meant that the inventory for the sales items were updated - meaning that the site-level inventory was instantly reduced by the sum of the number of items that were in users&#8217; carts. This happened due to the timed-hold that kicked in only when the inventory was updated and the products became <em>available</em> on the site. A large number of these users, whose carts held the sale items, weren&#8217;t even logged in at the time. They had simply added the items to the cart and forgotten about it. <em>A glaring edge-case oversight that surfaced at the most crucial moment in the US e-commerce calendar.</em></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Byyl!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8524576e-d549-4796-b66e-a545066c009c_3840x2088.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Byyl!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8524576e-d549-4796-b66e-a545066c009c_3840x2088.png 424w, https://substackcdn.com/image/fetch/$s_!Byyl!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8524576e-d549-4796-b66e-a545066c009c_3840x2088.png 848w, https://substackcdn.com/image/fetch/$s_!Byyl!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8524576e-d549-4796-b66e-a545066c009c_3840x2088.png 1272w, https://substackcdn.com/image/fetch/$s_!Byyl!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8524576e-d549-4796-b66e-a545066c009c_3840x2088.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Byyl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8524576e-d549-4796-b66e-a545066c009c_3840x2088.png" width="1456" height="792" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8524576e-d549-4796-b66e-a545066c009c_3840x2088.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:792,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:297236,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Byyl!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8524576e-d549-4796-b66e-a545066c009c_3840x2088.png 424w, https://substackcdn.com/image/fetch/$s_!Byyl!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8524576e-d549-4796-b66e-a545066c009c_3840x2088.png 848w, https://substackcdn.com/image/fetch/$s_!Byyl!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8524576e-d549-4796-b66e-a545066c009c_3840x2088.png 1272w, https://substackcdn.com/image/fetch/$s_!Byyl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8524576e-d549-4796-b66e-a545066c009c_3840x2088.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><em>In reality, there is no Inventory Manager, the inventory update is a event based trigger.</em></p><p>The inventory of hot items was instantly depleted as a factor of people&#8217;s activity over weeks. This blocked the now-online customers from adding the deal items to the cart. Of course, the inventory count tallied up with the actual sales as soon as the holds were automatically removed on those in-cart items. But the moment had passed. The company eventually made all the sales over the next few hours and days. But at the cost of dissatisfied customers and a subpar peak-sales performance than what had been projected.</p><p>Needless to say, a few heads did roll this time around!</p><p><em>This article may or may not have been a work of fiction!</em></p><p>Also checkout:</p><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;9fcb570a-23e3-4841-936e-011985d23f72&quot;,&quot;caption&quot;:&quot;If you've read Frozen Caveman in an Ivory Tower, you saw how a seemingly simple inventory management system caused serious trouble at an e-commerce platform. Don&#8217;t worry if you haven&#8217;t read that article - I&#8217;ll include a link at the end. But today, we'll explore critical elements in database concurrency with word play on the Guy Ritchie classic.&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;size&quot;:&quot;lg&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Lock, Stock &amp; Two Racing Parallels &quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:205997938,&quot;name&quot;:&quot;Dixyantar Panda&quot;,&quot;bio&quot;:&quot;Cloud Architect &amp; Engineer Leader crafting elegant systems - from scalable cloud architectures to modern webapps. Sharing insights from 14+ years of building distributed systems and high-performance applications. &quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f97795ea-c836-404d-8ccc-30d5fc16d9c9_576x576.webp&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2024-12-20T15:03:15.841Z&quot;,&quot;cover_image&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%2Fb8223cde-6b63-4834-8574-ba8571dc8023_1024x608.png&quot;,&quot;cover_image_alt&quot;:null,&quot;canonical_url&quot;:&quot;https://www.stackgazer.com/p/lock-stock-and-two-racing-parallels&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:153302072,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:0,&quot;comment_count&quot;:0,&quot;publication_id&quot;:null,&quot;publication_name&quot;:&quot;Stackgazer&quot;,&quot;publication_logo_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%2F76603155-9304-47e2-9ed0-cdcadabf8cb6_400x400.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div>]]></content:encoded></item><item><title><![CDATA[Performance Prediction in Action: Building Self-Healing API Systems]]></title><description><![CDATA[We've built a production-ready system that can foresee API performance issues. But what if it could not just predict problems, but automatically prevent them with a decision engine in the mix?]]></description><link>https://www.stackgazer.com/p/performance-prediction-in-action</link><guid isPermaLink="false">https://www.stackgazer.com/p/performance-prediction-in-action</guid><dc:creator><![CDATA[Dixyantar Panda]]></dc:creator><pubDate>Thu, 19 Dec 2024 14:01:38 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!SecL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff66ba78c-8d74-41b7-9013-890d17c35b8c_1024x608.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!SecL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff66ba78c-8d74-41b7-9013-890d17c35b8c_1024x608.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!SecL!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff66ba78c-8d74-41b7-9013-890d17c35b8c_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!SecL!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff66ba78c-8d74-41b7-9013-890d17c35b8c_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!SecL!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff66ba78c-8d74-41b7-9013-890d17c35b8c_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!SecL!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff66ba78c-8d74-41b7-9013-890d17c35b8c_1024x608.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!SecL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff66ba78c-8d74-41b7-9013-890d17c35b8c_1024x608.png" width="1024" height="608" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f66ba78c-8d74-41b7-9013-890d17c35b8c_1024x608.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:608,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&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="" srcset="https://substackcdn.com/image/fetch/$s_!SecL!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff66ba78c-8d74-41b7-9013-890d17c35b8c_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!SecL!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff66ba78c-8d74-41b7-9013-890d17c35b8c_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!SecL!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff66ba78c-8d74-41b7-9013-890d17c35b8c_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!SecL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff66ba78c-8d74-41b7-9013-890d17c35b8c_1024x608.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">Performance Prediction in Action: Building Self-Healing API Systems</figcaption></figure></div><h2>The Journey to Autonomous APIs</h2><p>Remember our prediction system from the last article? It's doing a great job telling us when things might go wrong. But there's still a gap between prediction and action. In many organizations, the conversation goes something like this:</p><ul><li><p>Alert: High latency predicted for checkout API in 15 minutes </p></li><li><p>DevOps: <em>frantically provisions new instances</em></p></li><li><p>Alert: Cache hit rate dropping... </p></li><li><p>DevOps: <em>adjusts cache settings </em></p></li><li><p>Alert: Database connections spiking... </p></li><li><p>DevOps: <em>updates connection pool</em></p></li></ul><p>Sound familiar? While our prediction system gives us a head start, we're still in reactive mode. Let's change that by building a system that can take intelligent, automated actions.</p><h2>Architecture of a Self-Healing System</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ARP7!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd751a6fb-2dfb-4b3d-b94c-5e576fcaeffe_3662x3840.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ARP7!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd751a6fb-2dfb-4b3d-b94c-5e576fcaeffe_3662x3840.png 424w, https://substackcdn.com/image/fetch/$s_!ARP7!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd751a6fb-2dfb-4b3d-b94c-5e576fcaeffe_3662x3840.png 848w, https://substackcdn.com/image/fetch/$s_!ARP7!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd751a6fb-2dfb-4b3d-b94c-5e576fcaeffe_3662x3840.png 1272w, https://substackcdn.com/image/fetch/$s_!ARP7!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd751a6fb-2dfb-4b3d-b94c-5e576fcaeffe_3662x3840.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ARP7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd751a6fb-2dfb-4b3d-b94c-5e576fcaeffe_3662x3840.png" width="1456" height="1527" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d751a6fb-2dfb-4b3d-b94c-5e576fcaeffe_3662x3840.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1527,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:532247,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ARP7!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd751a6fb-2dfb-4b3d-b94c-5e576fcaeffe_3662x3840.png 424w, https://substackcdn.com/image/fetch/$s_!ARP7!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd751a6fb-2dfb-4b3d-b94c-5e576fcaeffe_3662x3840.png 848w, https://substackcdn.com/image/fetch/$s_!ARP7!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd751a6fb-2dfb-4b3d-b94c-5e576fcaeffe_3662x3840.png 1272w, https://substackcdn.com/image/fetch/$s_!ARP7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd751a6fb-2dfb-4b3d-b94c-5e576fcaeffe_3662x3840.png 1456w" sizes="100vw"></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>Our self-healing system builds on the existing prediction infrastructure, adding three crucial new layers:</p><ol><li><p><strong>Decision Layer</strong>: Evaluates predictions and determines appropriate actions</p></li><li><p><strong>Action Layer</strong>: Executes mitigation strategies safely and reliably</p></li><li><p><strong>Feedback Layer</strong>: Tracks action effectiveness and updates policies</p></li></ol><p>Let's see how we can implement these new components while leveraging our existing codebase.</p><h2>Building the Decision Engine</h2><p>The Decision Engine is our first addition to the prediction system. It transforms predictions into actionable decisions based on configurable policies.</p><p>Have a look at <a href="https://github.com/stackgazer-labs/stats-for-engineers/blob/main/regression/04-self-healing-apis/api_performance_healing/decision/engine.py">its implementation</a> in the source code. <br><br>Here's a more natural way to explain how our Decision Engine evaluates and acts:</p><p>The Decision Engine is like a skilled operator, constantly monitoring your API's vital signs through three key lenses. First, it evaluates risk by synthesizing multiple data points - how your API is responding to requests, whether errors are creeping up, and if your resources are under strain. Think of it as an early warning system that spots trouble before it impacts users.</p><p>Each API endpoint gets its own customized playbook - what we call policies. These aren't rigid rules, but rather smart guidelines that adapt to each endpoint's unique characteristics. For example, your checkout API might need stricter error thresholds but can tolerate slightly higher latency, while your product catalog API prioritizes consistent response times. These policies define everything from how aggressively to scale resources to when circuit breakers should kick in to prevent cascading failures.</p><p>When risks emerge, the engine doesn't just raise alarms - it takes action. Like a skilled pilot making constant adjustments, it might spin up new instances if load increases, tweak cache settings to improve hit rates, or adjust load balancing to optimize resource usage. Each action is calculated and proportional, ensuring stability while preventing over-reaction.</p><div class="preformatted-block" data-component-name="PreformattedTextBlockToDOM"><label class="hide-text" contenteditable="false">Text within this block will maintain its original spacing when published</label><pre class="text"><em>The art of automation isn't in eliminating human judgment, but in amplifying it.</em></pre></div><p>Let's look at how we configure these policies:</p><pre><code>endpoints:
  /api/v1/checkout:
    thresholds:
      high_risk: 0.75  <strong># Risk score that triggers immediate action</strong>
      medium_risk: 0.5 <strong># Risk score that enables preventive measures</strong>
    
    scaling:
      min_instances: 3
      max_instances: 10
      increment: 2  <strong># Scale up by 2 instances at a time</strong>
      threshold: 0.7  <strong># CPU utilization threshold</strong>
    
    circuit_breaker:
      enabled: true
      timeout: 30s
      error_threshold: 0.05  <strong># 5% error rate triggers circuit breaker</strong>
      min_requests: 100  <strong># Minimum requests before enabling</strong>
    
    caching:
      enabled: true
      min_hit_rate: 0.8
      ttl_increment: 300  <strong># Increase TTL by 5 minutes if hit rate is low</strong>
    
    load_balancing:
      algorithm: round_robin
      imbalance_threshold: 0.2  <strong># Max allowed difference in server load</strong>
      health_check_interval: 10s

  /api/v1/cart:
    thresholds:
      high_risk: 0.8  <strong># Higher tolerance for cart API</strong>
      medium_risk: 0.6
    
    scaling:
      min_instances: 2
      max_instances: 8
      increment: 1  <strong># More gradual scaling</strong>
      threshold: 0.8
    
    circuit_breaker:
      enabled: true
      timeout: 15s  <strong># Shorter timeout for cart operations</strong>
      error_threshold: 0.02  <strong># More sensitive to errors</strong>
      min_requests: 50</code></pre><p>The policies are defined in YAML for easy maintenance and version control. Notice how we can tune different parameters for each endpoint based on its business importance and performance characteristics:</p><ul><li><p>The checkout API has more aggressive scaling policies but higher risk tolerance</p></li><li><p>The cart API has stricter error thresholds but more gradual scaling</p></li><li><p>Each endpoint has customized circuit breaker and caching configurations</p></li></ul><p>Now that we have our Decision Engine and policies in place, let's implement the Action Orchestrator that will safely execute these decisions...</p><h2>Building the Action Orchestrator</h2><p>The Action Orchestrator is the critical bridge between decisions and actions. It needs to handle action coordination, ensure safe execution order, and maintain system stability. </p><p>Code for the <a href="https://github.com/stackgazer-labs/stats-for-engineers/blob/main/regression/04-self-healing-apis/api_performance_healing/actions/orchestrator.py">Action Orchestrator.</a></p><p>The Action Orchestrator is the conductor of our self-healing symphony, carefully coordinating each response to ensure harmony in our system. Like a well-rehearsed emergency response team, it follows a precise protocol when taking action.</p><p>Safety comes first. Before any action is taken, the orchestrator performs a thorough safety check - imagine a pilot's pre-flight checklist. It verifies there are no conflicting actions in play, ensures all parameters are within safe bounds, and confirms the system's stability won't be compromised. This methodical approach prevents the cure from being worse than the disease.</p><p>When it's time to act, the orchestrator moves with deliberate precision. Circuit breakers deploy first as the front line of defense, followed by scaling operations to adjust capacity. Finally, like fine-tuning an instrument, it makes more nuanced adjustments to caching and load balancing. Each action is carefully timed and monitored, with built-in limits to prevent overwhelming the system.</p><p>The circuit breaker implementation showcases this sophisticated approach in action. Rather than abruptly failing all requests when issues arise, it employs a gradual response - starting by diverting just 25% of traffic. This measured approach allows the system to test whether partial traffic reduction resolves the issue before taking more drastic action.</p><p>Recovery is equally thoughtful. Like a careful driver testing the road after a storm, the system first sends a small amount of traffic through the circuit breaker. If things look stable, traffic gradually increases. If problems persist, the system automatically extends its cautious period. Throughout this process, each endpoint maintains its own state, making decisions based on its unique circumstances and history.</p><p>The result is a self-healing system that combines the decisiveness of automation with the nuance of human judgment. Every action is tracked, measured, and analyzed, building a growing knowledge base that informs future decisions.</p><p><em>With our Decision Engine and Action Orchestrator in place, let's explore how the different action handlers work together to create a truly self-healing system</em></p><h2>Implementing Action Handlers</h2><p>At the heart of our self-healing system lies a sophisticated set of handlers, each playing a crucial role in maintaining API health. Think of it as an orchestra where each section contributes to the harmony of the whole system.</p><p>The auto-scaling handler is our forward scout, using historical patterns to anticipate and prepare for traffic changes. Rather than simply reacting to spikes, it's proactively spinning up new instances during known high-traffic periods. For our checkout API, this means seamlessly expanding capacity before Black Friday hits, not after the first wave of timeout errors. New instances are carefully warmed up and tested, like athletes stretching before entering a game, ensuring they're ready to handle production traffic.</p><p><em>"The best time to scale is before you need to."</em></p><p>Our cache management system works like a skilled inventory manager, constantly optimizing what's kept close at hand. During high-stakes events like flash sales, it adapts in real-time - keeping price data fresh with shorter TTLs while expanding cache space for product details that shoppers will repeatedly request. It's particularly clever about pre-warming caches for items featured in promotions, ensuring the first wave of enthusiastic shoppers gets the same snappy response as those who come later.</p><p>The load balancer acts as our traffic conductor, orchestrating requests with a sophistication that goes beyond simple round-robin distribution. It understands that not all endpoints are created equal - some are more sensitive to latency, others to database load. When an endpoint starts showing signs of stress, the load balancer doesn't just abruptly redirect traffic. Instead, it orchestrates a graceful migration, taking into account everything from geographic proximity to database connection limits.</p><p>Standing guard behind all of this are our circuit breakers - the ultimate safety net. But unlike traditional circuit breakers that simply cut off traffic, ours act more like smart limiters. They gradually reduce load when they detect issues, carefully test the waters during recovery, and maintain separate policies for different endpoints. It's like having a skilled operator watching each service, ready to step in with just the right amount of intervention when needed.</p><h2>Feedback Loop: Learning from Every Action</h2><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.stackgazer.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Stackgazer is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p><p>The true power of our self-healing system lies not just in its ability to take action, but in its sophisticated learning capabilities. Like a skilled engineer, it maintains a detailed logbook of every intervention, carefully analyzing what works and what doesn't. This isn't just simple pass/fail tracking - it's a comprehensive analysis framework that helps the system get smarter over time.</p><p>Every time an action is taken, whether it's scaling up instances or adjusting cache settings, the system calculates precise improvement metrics. For scaling actions, it looks at latency improvements. A 30% reduction in response time is logged as a clear success, while a marginal 2% improvement might suggest the need for different strategies. For circuit breakers, the focus shifts to error rate reductions, tracking how effectively they prevent cascading failures.</p><p>But the system doesn't just track individual metrics - it looks for patterns and correlations. Using a 24-hour sliding window of historical data, it builds a rich understanding of what works best for each endpoint. For instance, it might discover that the checkout API responds better to cache adjustments during peak hours, while scaling actions are more effective for handling flash sales.</p><p>The learning process is particularly sophisticated when it comes to handling side effects. Every action's ripple effects are carefully documented. If scaling up an instance improves latency but causes unexpected spikes in database load, this gets factored into future decisions. The system maintains a frequency map of these side effects, helping it anticipate and mitigate potential issues before they occur.</p><p>What makes this feedback loop particularly powerful is its ability to adapt over time. Through continuous trend analysis, it can detect when strategies that worked well in the past start becoming less effective. Success rates, improvement percentages, and action durations are all tracked using rolling averages, allowing the system to smoothly adapt to changing conditions.</p><p>Consider how this plays out in practice: When the system notices that scaling actions for a particular endpoint have a success rate dropping below 70%, it automatically begins favoring alternative strategies. If cache adjustments consistently show better improvements (tracked down to percentage points), the system gradually shifts its approach. This isn't just reactive learning - the system uses these insights to proactively adjust its thresholds and fine-tune its decision-making parameters.</p><p>The results of this learning are immediately visible in the system's decision-making. Each endpoint develops its own profile of effective strategies, timing considerations, and risk thresholds. What starts as a general-purpose healing system evolves into a highly specialized guardian, intimately familiar with the quirks and requirements of each part of your API infrastructure.</p><h2>Beyond the Code: The Journey Forward</h2><p>As we reach the end of our exploration into self-healing systems, remember that this is more than just code - it's a fundamental shift in how we think about system reliability. Start small, perhaps with a single non-critical endpoint. Let your system learn and evolve gradually. While automation is powerful, keep human expertise in the loop. Think of it as augmenting your team's capabilities rather than replacing them.</p><p>Remember: A truly resilient system isn't one that never fails, but one that gracefully recovers and learns from each incident.</p><p>Ready to begin your journey toward automated healing? Check out our implementation on <a href="https://github.com/stackgazer-labs/stats-for-engineers/tree/main/regression/04-self-healing-apis">GitHub</a> and join our growing community of practitioners building more resilient systems.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.stackgazer.com/?utm_source=substack&amp;utm_medium=email&amp;utm_content=share&amp;action=share&quot;,&quot;text&quot;:&quot;Share Stackgazer&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.stackgazer.com/?utm_source=substack&amp;utm_medium=email&amp;utm_content=share&amp;action=share"><span>Share Stackgazer</span></a></p><p></p>]]></content:encoded></item><item><title><![CDATA[Building Production-Ready Performance Prediction Systems: From Notebook to Network]]></title><description><![CDATA[Let's productionize our experimental models into robust prediction systems that automatically prevent performance issues before they impact users.]]></description><link>https://www.stackgazer.com/p/building-production-ready-performance</link><guid isPermaLink="false">https://www.stackgazer.com/p/building-production-ready-performance</guid><dc:creator><![CDATA[Dixyantar Panda]]></dc:creator><pubDate>Thu, 19 Dec 2024 05:01:21 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!NYiY!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8089f404-76cf-4770-b3d9-92755bdba5ba_1024x608.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!NYiY!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8089f404-76cf-4770-b3d9-92755bdba5ba_1024x608.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!NYiY!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8089f404-76cf-4770-b3d9-92755bdba5ba_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!NYiY!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8089f404-76cf-4770-b3d9-92755bdba5ba_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!NYiY!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8089f404-76cf-4770-b3d9-92755bdba5ba_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!NYiY!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8089f404-76cf-4770-b3d9-92755bdba5ba_1024x608.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!NYiY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8089f404-76cf-4770-b3d9-92755bdba5ba_1024x608.png" width="1024" height="608" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8089f404-76cf-4770-b3d9-92755bdba5ba_1024x608.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:608,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&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="" srcset="https://substackcdn.com/image/fetch/$s_!NYiY!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8089f404-76cf-4770-b3d9-92755bdba5ba_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!NYiY!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8089f404-76cf-4770-b3d9-92755bdba5ba_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!NYiY!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8089f404-76cf-4770-b3d9-92755bdba5ba_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!NYiY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8089f404-76cf-4770-b3d9-92755bdba5ba_1024x608.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></figure></div><h2>Notebook to Network?</h2><p>You've built and tested machine learning models that predict API performance beautifully in notebooks. They have clean data, perfect predictions, and gorgeous visualizations. But there's that million dollar question:</p><p>How do I actually put this into production?</p><p>It's a question I wrestled with too. You see, like many engineers, I had to learn the hard way that a perfect R&#178; score means nothing if your model can't handle real-world traffic surges, data anomalies, or infrastructure hiccups.</p><p>Let's imagine a scenario most of us have either experienced or fear: You've just deployed your first prediction model to production. Everything looks great in testing. Your colleagues are impressed. Then Friday evening hits, traffic spikes, and instead of preventing performance issues, your prediction pipeline becomes another point of failure.</p><p>What seemed straightforward in a notebook becomes treacherous in production. Your pristine model now faces:</p><ul><li><p>Unpredictable data quality and availability</p></li><li><p>Real-time processing constraints</p></li><li><p>System resource limits</p></li><li><p>Infrastructure failures</p></li><li><p>Scaling challenges</p></li></ul><p>Today, we'll bridge that gap. Using synthetic but realistic scenarios, we'll build a robust prediction system that can handle production's messy reality.</p><h2>Production Ready System</h2><h3>Architecture of a Performance Prediction System</h3><p>Let's start with the architecture of a production-ready prediction 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_!D3kX!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f3eceda-0628-4892-90d1-223ec00784ad_2523x3840.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!D3kX!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f3eceda-0628-4892-90d1-223ec00784ad_2523x3840.png 424w, https://substackcdn.com/image/fetch/$s_!D3kX!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f3eceda-0628-4892-90d1-223ec00784ad_2523x3840.png 848w, https://substackcdn.com/image/fetch/$s_!D3kX!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f3eceda-0628-4892-90d1-223ec00784ad_2523x3840.png 1272w, https://substackcdn.com/image/fetch/$s_!D3kX!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f3eceda-0628-4892-90d1-223ec00784ad_2523x3840.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!D3kX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f3eceda-0628-4892-90d1-223ec00784ad_2523x3840.png" width="1456" height="2216" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3f3eceda-0628-4892-90d1-223ec00784ad_2523x3840.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:2216,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:432981,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!D3kX!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f3eceda-0628-4892-90d1-223ec00784ad_2523x3840.png 424w, https://substackcdn.com/image/fetch/$s_!D3kX!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f3eceda-0628-4892-90d1-223ec00784ad_2523x3840.png 848w, https://substackcdn.com/image/fetch/$s_!D3kX!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f3eceda-0628-4892-90d1-223ec00784ad_2523x3840.png 1272w, https://substackcdn.com/image/fetch/$s_!D3kX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f3eceda-0628-4892-90d1-223ec00784ad_2523x3840.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>Looking at our system architecture diagram, each component plays a vital role in transforming experimental models into reliable production services. The <em>data collection layer</em> aggregates metrics from our API services into 5-minute windows, providing a stable foundation for predictions. This time-series data feeds into our <em>prediction pipeline</em>, where the <em>preprocessor</em> normalizes and validates incoming metrics before passing them to the <em>model server</em>.</p><p>The <em>monitoring system</em> works in parallel, analyzing both prediction accuracy and system health. When model drift is detected, it triggers retraining using historical data, while the <em>alert engine</em> manages notification thresholds. This closed-loop system ensures our predictions remain accurate as traffic patterns evolve.</p><h3>Code For The Performance Prediction System</h3><p>Let's look at how we implement these components, starting with the metrics collection pipeline...</p><p><a href="https://github.com/stackgazer-labs/stats-for-engineers/tree/main/regression/03-production-ready-prediction">(source code)</a></p><pre><code>class MetricsCollector:
    def __init__(self, buffer_size=300):  <em><strong>#</strong> <strong>5 minutes of per-second data</strong></em>
        self.metrics = deque(maxlen=buffer_size) <strong> </strong><em><strong># Built-in overflow</strong></em><strong> </strong><em><strong>protection</strong></em>
        self._lock = asyncio.Lock()              <em><strong>#</strong> <strong>Thread safety</strong></em>
    
    async def collect(self):
        async with self._lock:
            try:
                <em><strong># Collect with timeout</strong></em>
                async with timeout(0.5):
                    raw_metrics = await self._fetch_metrics()
                
                <strong>#</strong> <em><strong>Validate before storing</strong></em>
                if self._validate_metrics(raw_metrics):
                    self.metrics.append(raw_metrics)
                    return True
                
            except TimeoutError:
                logger.warning("Metric collection timed out")
                return False</code></pre><p>This implementation provides several layers of protection against common production issues. Network timeouts are handled gracefully without blocking the pipeline, while data validation ensures only clean metrics enter our system. The bounded buffer prevents memory issues during traffic spikes, and the thread-safe design allows multiple collectors to operate in parallel. Let's examine how these raw metrics flow through our prediction pipeline...</p><p>Raw metrics first enter our DataPreprocessor, which transforms them into feature vectors suitable for our model. The preprocessor handles several critical tasks:</p><pre><code>def create_feature_vector(self, metrics: List[APIMetric]) -&gt; pd.DataFrame:
    df = pd.DataFrame([self._metric_to_dict(m) for m in metrics])
    
   <em><strong> # Calculate derived metrics</strong></em>
    df['error_rate'] = df['error_count'] / df['request_count']
    
    <em><strong># Add temporal context</strong></em>
    df['hour'] = df['timestamp'].dt.hour
    df['day_of_week'] = df['timestamp'].dt.dayofweek
    
    <em><strong># Calculate rolling means for stability</strong></em>
    for col in ['latency_ms', 'cpu_usage', 'memory_usage']:
        df[f'{col}_rolling_mean'] = df[col].rolling(
            window=self.window_size, 
            min_periods=1
        ).mean()</code></pre><p>The preprocessor enriches our raw metrics with temporal context and rolling averages, which help capture trends and patterns in the data. This processed data then flows to our ModelServer, which generates predictions with confidence intervals:</p><pre><code>def predict(self, features: pd.DataFrame) -&gt; List[PredictionResult]:
    predictions = []
    for _, row in features.iterrows():
        point_pred = self.model.predict(row.values.reshape(1, -1))[0]
        
        <em><strong># Calculate prediction uncertainty</strong></em>
        residuals = np.std([
            tree.predict(row.values.reshape(1, -1))[0]
            for tree in self.model.estimators_
        ])
        
        ci_width = 1.96 * residuals
        predictions.append(PredictionResult(
            predicted_latency=point_pred,
            confidence_interval=(point_pred - ci_width, point_pred + ci_width)
        ))</code></pre><p>The model server maintains versioning information and can be updated without service interruption. When model drift is detected, a new model can be trained on recent data while the current model continues serving predictions.</p><p>The monitoring system closes the feedback loop by tracking prediction accuracy and system health metrics. It maintains rolling windows of prediction errors and can trigger model retraining when accuracy drops below configured thresholds.</p><p>Do take the code for a good spin. (<a href="https://github.com/stackgazer-labs/stats-for-engineers/tree/main/regression/03-production-ready-prediction">source</a>)</p><p>In the next section, we'll explore how to deploy this system to production environments, including considerations for scaling, monitoring, and maintenance.</p><h2>Deploying API Prediction Model to Production</h2><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.stackgazer.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Stackgazer is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>Let's look at practical considerations for deploying this prediction system to production.</p><p>Resource allocation requires careful planning based on your metrics volume. A good starting point is to size your prediction service instances with at least 2 CPU cores and 4GB RAM, which comfortably handles up to 1000 predictions per minute. The model server maintains prediction latencies under 100ms with this configuration, leaving adequate headroom for traffic spikes.</p><p>One often-overlooked aspect is environment configuration. While development environments can use default settings, production deployments need explicit configuration for:</p><ul><li><p>Feature calculation windows (typically 1 hour of data)</p></li><li><p>Model update intervals (usually daily during low traffic)</p></li><li><p>Cache sizes for frequently accessed metrics</p></li><li><p>Connection pool sizes for dependent services</p></li></ul><p>The model server's memory usage grows with the size of your historical data window. A practical approach is to retain 2 weeks of metrics for immediate access, with older data archived to cold storage. This balances prediction accuracy against resource consumption.</p><p>Load balancing requires special attention. Unlike stateless web services, prediction servers need sticky sessions during model updates. Configure health checks to verify both service availability and prediction quality. A prediction server should be considered unhealthy if its error rate exceeds 5% or if prediction latency consistently exceeds 200ms.</p><p>For monitoring, focus on metrics that directly impact business operations:</p><ul><li><p>Prediction error rates compared to actual latencies</p></li><li><p>Model refresh success rates and timings</p></li><li><p>Feature calculation pipeline health</p></li><li><p>Correlation between predicted and actual API performance</p></li></ul><p>Production incidents commonly stem from data quality issues rather than model accuracy. Common scenarios include:</p><ul><li><p>Missing metrics during infrastructure updates</p></li><li><p>Clock skew between metric sources</p></li><li><p>Network latency affecting feature calculations</p></li><li><p>Resource exhaustion during high-traffic periods</p></li></ul><p>Establish clear maintenance windows for model updates. Schedule these during periods of stable traffic, and maintain at least one previous model version for quick rollbacks. Archive model artifacts alongside their training data and performance metrics to aid in debugging.</p><p>Regular validation ensures prediction quality remains consistent. Key validation metrics include:</p><ul><li><p>Mean absolute percentage error (MAPE) of latency predictions</p></li><li><p>False positive rate for high-latency predictions</p></li><li><p>Distribution of prediction confidence intervals</p></li><li><p>Feature importance stability across retraining cycles</p></li></ul><p>Data retention policies should align with your business requirements. For most applications, retaining:</p><ul><li><p>2 weeks of raw metrics</p></li><li><p>3 months of aggregated data</p></li><li><p>1 year of model performance metrics provides adequate historical context while remaining manageable.</p></li></ul><p>Common operational issues and their solutions deserve careful consideration. Model drift often manifests gradually - rising prediction errors or widening confidence intervals signal the need for retraining before serious issues occur. Regular comparison of feature distributions helps identify potential problems early.</p><p>When rolling out model updates, use gradual traffic shifting. Start with 10% of traffic, monitor for any degradation, then slowly increase if metrics remain stable. This approach minimizes the impact of potential issues while providing clear validation of model performance.</p><p>Documentation and runbooks should focus on operational procedures rather than theory. Include step-by-step guides for:</p><ul><li><p>Validating model updates</p></li><li><p>Investigating prediction anomalies</p></li><li><p>Performing emergency rollbacks</p></li><li><p>Recovering from data pipeline failures</p></li></ul><p>Two critical aspects often separate reliable ML systems from fragile ones: graceful shutdowns and drift detection. Let's explore how to implement these effectively in production.</p><p>Graceful shutdowns ensure your prediction service can be updated without dropping requests. The model server needs to track active predictions and stop accepting new requests during shutdown. It should wait for in-flight predictions to complete, but with a reasonable timeout to prevent hanging. This prevents disruption during deployments and maintains service reliability.</p><p>Version rollbacks are equally important. Your model server should maintain multiple model versions and support atomic version switches. When rolling back, it's crucial to verify the previous version is healthy before fully switching traffic. This might mean running both versions briefly and comparing their predictions to ensure the rollback won't cause additional issues.</p><p>Model drift detection requires continuous monitoring of prediction quality. Instead of just tracking simple metrics, implement a sliding window approach that:</p><ul><li><p>Maintains recent prediction-actual pairs</p></li><li><p>Calculates error metrics over time</p></li><li><p>Detects concerning trends in accuracy</p></li><li><p>Uses both absolute thresholds and trend analysis</p></li></ul><p>The monitoring system should detect drift through multiple signals. A sudden increase in prediction errors might indicate immediate problems, but gradually increasing errors often signal model drift. By tracking both patterns, you can catch issues before they become critical.</p><p>When implementing these monitoring components:</p><ul><li><p>Choose window sizes that match your traffic patterns</p></li><li><p>Set drift thresholds based on business impact</p></li><li><p>Configure automated alerts for drift detection</p></li><li><p>Maintain detailed audit logs of model changes</p></li></ul><p>Remember that monitoring isn't just about detecting issues - it's about understanding your system's behavior over time. Regular analysis of these metrics helps inform future model improvements and system optimizations.</p><p>Simplicity in production systems pays dividends. While sophisticated modeling techniques might improve accuracy marginally, the operational complexity they add rarely justifies the benefit. Focus on robust, maintainable implementations that solve real business problems reliably.</p><p>In our next article, we will explore an elusive aspect of APIs in the context of production reliability. </p><p></p><div class="captioned-button-wrap" data-attrs="{&quot;url&quot;:&quot;https://www.stackgazer.com/p/building-production-ready-performance?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;}" data-component-name="CaptionedButtonToDOM"><div class="preamble"><p class="cta-caption">Thanks for reading Stackgazer! This post is public so feel free to share it.</p></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.stackgazer.com/p/building-production-ready-performance?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.stackgazer.com/p/building-production-ready-performance?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p></div><p><br><br>What&#8217;s beyond predictions?</p><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;3241694b-f1ef-4ce5-9066-6fb5d0c6b7dc&quot;,&quot;caption&quot;:&quot;The Journey to Autonomous APIs&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;size&quot;:&quot;lg&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Performance Prediction in Action: Building Self-Healing API Systems&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:205997938,&quot;name&quot;:&quot;Dixyantar Panda&quot;,&quot;bio&quot;:&quot;Cloud Architect &amp; Lead Engineer crafting elegant systems - from scalable cloud architectures to modern webapps. Sharing insights from 14+ years of building distributed systems and high-performance applications. &quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f97795ea-c836-404d-8ccc-30d5fc16d9c9_576x576.webp&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2024-12-19T14:01:38.586Z&quot;,&quot;cover_image&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%2Ff66ba78c-8d74-41b7-9013-890d17c35b8c_1024x608.png&quot;,&quot;cover_image_alt&quot;:null,&quot;canonical_url&quot;:&quot;https://www.stackgazer.com/p/performance-prediction-in-action&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:153323178,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:0,&quot;comment_count&quot;:0,&quot;publication_id&quot;:null,&quot;publication_name&quot;:&quot;Stackgazer&quot;,&quot;publication_logo_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%2F76603155-9304-47e2-9ed0-cdcadabf8cb6_400x400.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><p></p><p></p>]]></content:encoded></item><item><title><![CDATA[Next.js Parallel Routes: The Most Powerful Router Feature You're Not Using]]></title><description><![CDATA[Transform complex React applications into elegant state machines using Next.js 14's most underutilized feature. Say goodbye to prop drilling and context hell.]]></description><link>https://www.stackgazer.com/p/next-js-parallel-routes</link><guid isPermaLink="false">https://www.stackgazer.com/p/next-js-parallel-routes</guid><dc:creator><![CDATA[Dixyantar Panda]]></dc:creator><pubDate>Thu, 19 Dec 2024 01:00:00 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!2voR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c32e1d4-d71d-4c81-bbc4-3cf2e61d74a8_1024x608.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!2voR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c32e1d4-d71d-4c81-bbc4-3cf2e61d74a8_1024x608.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!2voR!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c32e1d4-d71d-4c81-bbc4-3cf2e61d74a8_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!2voR!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c32e1d4-d71d-4c81-bbc4-3cf2e61d74a8_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!2voR!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c32e1d4-d71d-4c81-bbc4-3cf2e61d74a8_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!2voR!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c32e1d4-d71d-4c81-bbc4-3cf2e61d74a8_1024x608.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!2voR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c32e1d4-d71d-4c81-bbc4-3cf2e61d74a8_1024x608.png" width="1024" height="608" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4c32e1d4-d71d-4c81-bbc4-3cf2e61d74a8_1024x608.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:608,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&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="" srcset="https://substackcdn.com/image/fetch/$s_!2voR!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c32e1d4-d71d-4c81-bbc4-3cf2e61d74a8_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!2voR!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c32e1d4-d71d-4c81-bbc4-3cf2e61d74a8_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!2voR!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c32e1d4-d71d-4c81-bbc4-3cf2e61d74a8_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!2voR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c32e1d4-d71d-4c81-bbc4-3cf2e61d74a8_1024x608.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">Next.js Parallel Routes: The Most Powerful Router Feature You're Not Using</figcaption></figure></div><p>Two months into building your team's new dashboard, you hit the wall every Next.js developer dreads: route complexity hell. The requirements seem simple enough &#8212; a dashboard that loads multiple data-heavy components independently, modals that maintain state during navigation, and URL-driven everything for browser history. Yet your codebase has devolved into a maze of loading states, error boundaries, and route handlers that would make even a seasoned architect wince.</p><p>You've tried every pattern in the book:</p><ul><li><p>Client-state management for modals (goodbye, URL history)</p></li><li><p>Complex loading spinners (hello, waterfalls)</p></li><li><p>Nested layouts (welcome to prop-drilling paradise)</p></li></ul><p>But what if the solution isn't about adding more code, but fundamentally rethinking how routing works?</p><p>Enter Next.js parallel routes &#8212; the architectural pattern that transforms how we think about web navigation. Not just another routing feature, but a paradigm shift that solves complex UX patterns with elegant simplicity. While most developers use it for basic dashboard layouts, its true power lies in solving advanced architectural challenges that traditionally required complex state management and custom router implementations.</p><p>This isn't another tutorial about setting up parallel routes. Instead, we'll explore how this feature fundamentally changes the way we architect complex web applications, and why it might be the most important Next.js feature you're not fully utilizing.</p><p>Let's dive into how parallel routes solve problems you might not even know you have.</p><h2>A Mental Model Shift from Traditional Routing</h2><p>Traditional routing in web applications follows a linear path: URL changes, page loads, components render. This model breaks down when building complex UX patterns like:</p><ul><li><p>Independently loading dashboard widgets</p></li><li><p>Modals that preserve URL history</p></li><li><p>Multi-step flows with parallel states</p></li><li><p>Conditional content based on auth state</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_!w40T!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe07e0353-4a93-47f3-a207-7a97bf29694f_3840x1970.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!w40T!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe07e0353-4a93-47f3-a207-7a97bf29694f_3840x1970.png 424w, https://substackcdn.com/image/fetch/$s_!w40T!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe07e0353-4a93-47f3-a207-7a97bf29694f_3840x1970.png 848w, https://substackcdn.com/image/fetch/$s_!w40T!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe07e0353-4a93-47f3-a207-7a97bf29694f_3840x1970.png 1272w, https://substackcdn.com/image/fetch/$s_!w40T!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe07e0353-4a93-47f3-a207-7a97bf29694f_3840x1970.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!w40T!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe07e0353-4a93-47f3-a207-7a97bf29694f_3840x1970.png" width="1456" height="747" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e07e0353-4a93-47f3-a207-7a97bf29694f_3840x1970.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:747,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:229053,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!w40T!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe07e0353-4a93-47f3-a207-7a97bf29694f_3840x1970.png 424w, https://substackcdn.com/image/fetch/$s_!w40T!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe07e0353-4a93-47f3-a207-7a97bf29694f_3840x1970.png 848w, https://substackcdn.com/image/fetch/$s_!w40T!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe07e0353-4a93-47f3-a207-7a97bf29694f_3840x1970.png 1272w, https://substackcdn.com/image/fetch/$s_!w40T!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe07e0353-4a93-47f3-a207-7a97bf29694f_3840x1970.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">Traditional Routing vs Parallel Routes in NextJs</figcaption></figure></div><p>The key insight behind parallel routes is treating URL segments not as a path, but as a state machine that can trigger multiple independent renders. This transforms routing from a linear sequence into a branching tree of possibilities.</p><p>Instead of thinking in paths, think in segments - each capable of its own loading states, error boundaries, data fetching and render conditions.</p><p>In traditional routing, your components march in a linear sequence - one performer following another. But parallel routes conduct multiple segments simultaneously, each playing its own part while maintaining perfect harmony.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!5RBV!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc43118c-e01d-4870-82b2-6b86ae280f6a_3840x2345.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!5RBV!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc43118c-e01d-4870-82b2-6b86ae280f6a_3840x2345.png 424w, https://substackcdn.com/image/fetch/$s_!5RBV!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc43118c-e01d-4870-82b2-6b86ae280f6a_3840x2345.png 848w, https://substackcdn.com/image/fetch/$s_!5RBV!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc43118c-e01d-4870-82b2-6b86ae280f6a_3840x2345.png 1272w, https://substackcdn.com/image/fetch/$s_!5RBV!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc43118c-e01d-4870-82b2-6b86ae280f6a_3840x2345.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!5RBV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc43118c-e01d-4870-82b2-6b86ae280f6a_3840x2345.png" width="1456" height="889" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/dc43118c-e01d-4870-82b2-6b86ae280f6a_3840x2345.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:889,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:239933,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!5RBV!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc43118c-e01d-4870-82b2-6b86ae280f6a_3840x2345.png 424w, https://substackcdn.com/image/fetch/$s_!5RBV!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc43118c-e01d-4870-82b2-6b86ae280f6a_3840x2345.png 848w, https://substackcdn.com/image/fetch/$s_!5RBV!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc43118c-e01d-4870-82b2-6b86ae280f6a_3840x2345.png 1272w, https://substackcdn.com/image/fetch/$s_!5RBV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc43118c-e01d-4870-82b2-6b86ae280f6a_3840x2345.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">Routing orchestration in NextJs</figcaption></figure></div><h2>Implementation Fundamentals</h2><p>This orchestration unlocks sophisticated patterns that previously required complex state management. Take modal flows - traditionally a source of routing complexity. With parallel routes, modals become first-class citizens in your routing symphony:</p><pre><code>export default function Layout({ 
  children,
  <strong>modal</strong> 
}: { 
  children: React.ReactNode
  <strong>modal</strong>: React.ReactNode 
}) {
  return (
    &lt;&gt;
      {children}
      {<strong>modal</strong>}
    &lt;/&gt;
  )
}</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_!TWN-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9cb62e0b-5ba4-4093-a360-097df1ecd5a5_1024x608.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!TWN-!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9cb62e0b-5ba4-4093-a360-097df1ecd5a5_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!TWN-!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9cb62e0b-5ba4-4093-a360-097df1ecd5a5_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!TWN-!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9cb62e0b-5ba4-4093-a360-097df1ecd5a5_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!TWN-!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9cb62e0b-5ba4-4093-a360-097df1ecd5a5_1024x608.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!TWN-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9cb62e0b-5ba4-4093-a360-097df1ecd5a5_1024x608.png" width="1024" height="608" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9cb62e0b-5ba4-4093-a360-097df1ecd5a5_1024x608.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:608,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&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="" srcset="https://substackcdn.com/image/fetch/$s_!TWN-!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9cb62e0b-5ba4-4093-a360-097df1ecd5a5_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!TWN-!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9cb62e0b-5ba4-4093-a360-097df1ecd5a5_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!TWN-!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9cb62e0b-5ba4-4093-a360-097df1ecd5a5_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!TWN-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9cb62e0b-5ba4-4093-a360-097df1ecd5a5_1024x608.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">Totally unrelated ai generated image of an orchestra!</figcaption></figure></div><pre><code><strong>// app/@modal/(.)/photos/[id]/page.tsx</strong>
export default function PhotoModal({ params }: { params: { id: string }}) {
  return (
    &lt;Dialog&gt;
      &lt;PhotoView id={params.id} /&gt;
    &lt;/Dialog&gt;
  )
}</code></pre><p>The "(.)photos" syntax intercepts the parent route, creating a modal experience while preserving the URL state. When a user navigates to "/photos/123", the main content stays put while the modal gracefully appears. Browser history works naturally - pressing back closes the modal rather than losing context.</p><h2>Beyond Basic Routing</h2><p>This pattern extends far beyond modals. Authentication flows, multi-step forms, and conditional renders all benefit from this orchestrated approach. Your routing becomes declarative rather than imperative - describing what should happen rather than managing how it happens.</p><p>The real power of parallel routes emerges in production scenarios. Consider an analytics dashboard where performance bottlenecks traditionally force compromises between responsiveness and data freshness.</p><pre><code>// app/<strong>@charts</strong>/performance/page.tsx
export default async function PerformanceMetrics() {
  const metrics = await fetchHistoricalMetrics()
  return &lt;TimeSeriesChart data={metrics} /&gt;
}</code></pre><pre><code>// app/<strong>@realtime</strong>/status/page.tsx
export default async function StatusIndicators() {
  const status = await fetchLiveStatus()
  return &lt;LiveMetrics data={status} /&gt;
}</code></pre><p>Here parallel routes shine through error isolation. When real-time metrics fail, historical data remains accessible. Each segment maintains its own error boundary, loading state, and refresh cycle - a level of resilience traditionally requiring complex state machines.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!o7he!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd1b5d5c-f117-4ab1-86ef-d8031d5d4094_3840x3422.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!o7he!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd1b5d5c-f117-4ab1-86ef-d8031d5d4094_3840x3422.png 424w, https://substackcdn.com/image/fetch/$s_!o7he!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd1b5d5c-f117-4ab1-86ef-d8031d5d4094_3840x3422.png 848w, https://substackcdn.com/image/fetch/$s_!o7he!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd1b5d5c-f117-4ab1-86ef-d8031d5d4094_3840x3422.png 1272w, https://substackcdn.com/image/fetch/$s_!o7he!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd1b5d5c-f117-4ab1-86ef-d8031d5d4094_3840x3422.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!o7he!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd1b5d5c-f117-4ab1-86ef-d8031d5d4094_3840x3422.png" width="1456" height="1298" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/dd1b5d5c-f117-4ab1-86ef-d8031d5d4094_3840x3422.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1298,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:330277,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!o7he!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd1b5d5c-f117-4ab1-86ef-d8031d5d4094_3840x3422.png 424w, https://substackcdn.com/image/fetch/$s_!o7he!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd1b5d5c-f117-4ab1-86ef-d8031d5d4094_3840x3422.png 848w, https://substackcdn.com/image/fetch/$s_!o7he!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd1b5d5c-f117-4ab1-86ef-d8031d5d4094_3840x3422.png 1272w, https://substackcdn.com/image/fetch/$s_!o7he!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd1b5d5c-f117-4ab1-86ef-d8031d5d4094_3840x3422.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>But parallel routes truly excel in handling authentication states. Rather than prop-drilling auth context through your component tree, route segments can conditionally render based on auth status:</p><pre><code>// app/<strong>@auth</strong>/layout.tsx
export default async function AuthLayout({ children }) {
  const session = await getSession()
  if (!session) {
    return redirect('/login')
  }
  return children
}</code></pre><p>This pattern eliminates the traditional auth-checking boilerplate while maintaining clear separation of concerns. Your routes become self-aware of their authentication requirements.</p><h2>Advanced Data Loading Patterns</h2><p>The sophisticated power of parallel routes becomes evident when handling complex data dependencies. Traditional approaches often lead to component coupling where one slow request blocks faster ones. Let's examine a real-world pattern we implemented recently at a fintech company dashboard:</p><pre><code>// app/<strong>@transactions</strong>/insights/page.tsx
export default async function Insights() {
  const insights = await fetchInsights({
    next: { revalidate: 3600 } // Hourly cache
  })
  return &lt;InsightDashboard data={insights} /&gt;
}</code></pre><pre><code>// app/<strong>@balance</strong>/realtime/page.tsx
export default async function Balance() {
  const balance = await fetchBalance({
    next: { revalidate: 0 } // Real-time
  })
  return &lt;BalanceIndicator data={balance} /&gt;
}</code></pre><pre><code>export default function Layout(props) {
  return (
    &lt;ErrorBoundary fallback="Service Degraded"&gt;
      &lt;Suspense fallback={&lt;BalanceSkeleton /&gt;}&gt;
        {props.balance}
      &lt;/Suspense&gt;
      &lt;Suspense fallback={&lt;InsightsSkeleton /&gt;}&gt;
        {props.transactions}
      &lt;/Suspense&gt;
    &lt;/ErrorBoundary&gt;
  )
}</code></pre><p>Each segment defines its own data freshness policy. Real-time balances update instantly while computation-heavy insights refresh hourly. When the balance API fails, insights remain accessible - degraded functionality rather than complete failure.</p><h2>State Management Through URLs</h2><p>Traditional state management in Next.js forces choices between component state, context, or third-party solutions. Parallel routes offer a different path: URLs as your source of truth. Each route segment becomes a slice of state, coordinated through URL parameters.</p><p>Consider our authentication flow: </p><pre><code>// app/@auth/layout.tsx
export default async function AuthLayout({ children }) {
  const session = await getSession()
  if (!session) {
    return redirect('/login')
  }
  return children
}</code></pre><p>No more prop drilling or context providers. The URL itself handles state transitions. When auth status changes, only affected segments rerender while others maintain their state.</p><h3>Race Conditions in Parallel Routes</h3><p>A complexity with parallel routes emerges when handling race conditions. Consider data that must sync across multiple segments:</p><pre><code>// app/<strong>@portfolio</strong>/holdings/page.tsx
export default async function Portfolio() {
  const holdings = await fetchHoldings()
  const key = generateStateKey(holdings)
  
  return (
    &lt;OptimisticProvider stateKey={key}&gt;
      &lt;HoldingsView holdings={holdings} /&gt;
    &lt;/OptimisticProvider&gt;
  )
}</code></pre><pre><code>// app/<strong>@trades/</strong>active/page.tsx
export default async function ActiveTrades({ searchParams }) {
  const stateKey = searchParams.state
  const trades = await fetchWithStateKey(stateKey)

  return &lt;TradesList trades={trades} /&gt;
}</code></pre><p>State keys propagate through URL parameters, ensuring segments render consistent snapshots of data. When holdings update, the state key changes, triggering synchronized revalidation of dependent segments.</p><p>This pattern proves invaluable for real-time collaborative features:</p><pre><code>// app/<strong>@document</strong>/[id]/page.tsx
export default async function Document({ params }) {
  const [doc, presence] = await Promise.all([
    fetchDocument(params.id),
    connectPresence(params.id)
  ])
  
  return (
    &lt;CollabProvider presence={presence}&gt;
      &lt;Editor content={doc} /&gt;
    &lt;/CollabProvider&gt;
  )
}</code></pre><pre><code>// app/<strong>@cursors</strong>/[id]/page.tsx
export default function Cursors({ params }) {
  return &lt;CursorOverlay docId={params.id} /&gt;
}</code></pre><p>Document content and presence information load independently. Network issues affecting presence don't block document rendering. URL-based coordination eliminates complex state management.</p><h2>Performance &amp; Patterns</h2><h3>Prioritization</h3><p>Resource prioritization becomes crucial with parallel segments. Memory usage scales with segment count, requiring careful stream management:</p><pre><code>// app/<strong>@metrics</strong>/page.tsx
export default async function Metrics() {
  const stream = new TransformStream()
  const metrics = await fetchMetricsStream()
  
  setTimeout(() =&gt; {
    metrics.pipeTo(stream.writable)
  }, 100) <em>// Defer heavy processing</em>

  return &lt;StreamingMetrics stream={stream.readable} /&gt;
}</code></pre><p>Strategic streaming and prioritization maintain responsiveness under load.</p><h3>Caching</h3><p>Caching in parallel routes demands careful orchestration of invalidation strategies. Unlike traditional routing where cache invalidation follows a linear path, parallel segments require granular control:</p><pre><code>export async function generateMetadata({ params }) {
  const product = await fetchProduct(params.id, {
    next: { revalidate: 3600, tags: ['product'] }
  })
  
  return {
    title: product.name,
    description: product.description
  }
}</code></pre><pre><code>export default async function Page({ params }) {
  // <em>Revalidate paths on inventory changes</em>
  const inventory = await fetchInventory(params.id, {
    next: { 
      revalidate: 30,
      tags: ['inventory', `product:${params.id}`] 
    }
  })

  return (
    &lt;ProductView 
      id={params.id}
      inventory={inventory}
    /&gt;
  )
}</code></pre><h2>Beyond Technical Implementation</h2><p>Parallel routes challenge our assumptions about state management in web applications. We've traditionally treated routing and state as separate concerns - URLs for navigation, state management for data. But what if this separation was holding us back?</p><p>Consider how we build modern web applications. We add Redux for global state, Context for component trees, local storage for persistence, and URL parameters almost as an afterthought. Yet URLs are the web's original source of truth. They're shareable, bookmarkable, and inherently represent application state.</p><p>In parallel routes, URLs become more than navigation paths - they become the orchestrators of our application's symphony. Each segment acts independently yet remains synchronized through a common conductor: the URL. When a user shares a URL, they're not just sharing a location - they're sharing a complete snapshot of the application state.</p><h2>The Path Forward</h2><p>Parallel routes transform URL segments from paths into state machines. They eliminate the traditional tradeoffs between simplicity and power in routing. No more choosing between clean URLs and complex state management.</p><p>This isn't just about cleaner code - it's about building applications that gracefully handle the complexity modern web apps demand. The next time you reach for a state management library or context provider, consider if your URLs could do the job instead.</p><p>Think of parallel routes not as a routing feature, but as Next.js's answer to the age-old question: how do we build complex applications without complex state management?</p><p>The answer, it turns out, was in our URLs all along.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.stackgazer.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Before you start reading your next article,  consider subscribing for FREE!</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p><p></p>]]></content:encoded></item><item><title><![CDATA[Beyond Basic Metrics: Multi-Factor Analysis for API Performance]]></title><description><![CDATA[Picking up from our exploration of simple linear regression for API performance prediction, we discover why looking at request volume alone leaves us blindsided to the real culprits of API slowdowns.]]></description><link>https://www.stackgazer.com/p/beyond-basic-metrics-multi-factor</link><guid isPermaLink="false">https://www.stackgazer.com/p/beyond-basic-metrics-multi-factor</guid><dc:creator><![CDATA[Dixyantar Panda]]></dc:creator><pubDate>Wed, 18 Dec 2024 05:00:32 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!YEUz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F891d3694-c645-4a2a-a7d0-5adf7c5e893b_1024x608.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!YEUz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F891d3694-c645-4a2a-a7d0-5adf7c5e893b_1024x608.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!YEUz!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F891d3694-c645-4a2a-a7d0-5adf7c5e893b_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!YEUz!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F891d3694-c645-4a2a-a7d0-5adf7c5e893b_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!YEUz!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F891d3694-c645-4a2a-a7d0-5adf7c5e893b_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!YEUz!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F891d3694-c645-4a2a-a7d0-5adf7c5e893b_1024x608.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!YEUz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F891d3694-c645-4a2a-a7d0-5adf7c5e893b_1024x608.png" width="1024" height="608" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/891d3694-c645-4a2a-a7d0-5adf7c5e893b_1024x608.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:608,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&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="" srcset="https://substackcdn.com/image/fetch/$s_!YEUz!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F891d3694-c645-4a2a-a7d0-5adf7c5e893b_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!YEUz!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F891d3694-c645-4a2a-a7d0-5adf7c5e893b_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!YEUz!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F891d3694-c645-4a2a-a7d0-5adf7c5e893b_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!YEUz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F891d3694-c645-4a2a-a7d0-5adf7c5e893b_1024x608.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></figure></div><p>Our <a href="https://www.stackgazer.com/i/153134043/building-your-first-api-performance-prediction-model">simple regression model</a> had a telling limitation - its R-squared (R&#178;) value was just 0.088, meaning only 8.8% of the variance in latency could be explained by request volume alone. </p><p>In statistical terms: </p><p><strong>R&#178; = </strong>1 - (unexplained variance/total variance)<strong> = 0.088</strong></p><p>suggesting that 91.2% of what makes our API slow or fast comes from factors we haven't considered yet.</p><p>Yet many engineers stop here, content with simple correlations. But you're not going to be one of them. Because in production, when that critical API starts misbehaving, single-metric analysis isn't just insufficient - it's dangerous.</p><p>Today, we'll dive deeper. We'll discover why your API might be crawling despite normal request volumes, why CPU utilization doesn't tell the whole resource story, and how apparently unrelated metrics might be the canary in your performance coal mine.</p><h2>The Limitations of Single-Metric Analysis</h2><p>Let's start with a real scenario. It's Tuesday afternoon, and your checkout API's latency has suddenly doubled. The incident channel is buzzing. Your first instinct? Check the request volume. But it's normal. Next, CPU utilization - also normal. Your simple regression model predicted everything should be fine, yet it's not. What gives?</p><p>The answer lies in the complex interplay of multiple factors. APIs don't exist in isolation - they're part of a sophisticated system where memory usage, database connections, cache hit rates, and even garbage collection patterns all dance together in a delicate performance ballet.</p><h2>Analysis Environment Setup</h2><p>We'll use the same three months of API metrics we explored previously, but this time we'll look at them through a multi-dimensional lens. Follow along in our Jupyter notebook where we'll reveal patterns that simple correlations miss.</p><p><a href="https://github.com/stackgazer-labs/stats-for-engineers/blob/main/regression/02-beyond-basic-metrics/beyond-basic-metrics.ipynb#initial-setup">Initial Setup and Data Loading</a></p><p>Let's break down what's happening in our setup code:</p><ul><li><p>We use pandas to load and manipulate our dataset</p></li><li><p>The aggregation with groupby gives us key statistics per endpoint</p></li><li><p>We calculate standard deviation (std) to understand metric variability</p></li><li><p>Round to 2 decimal places for cleaner presentation</p></li><li><p>Format numbers with commas for better readability, especially for request counts</p></li></ul><p>When you run this section, you'll see a summary of our dataset that will serve as the foundation for understanding why request counts alone can't explain your API's behavior. Let's examine what these numbers tell us, and then move on to discovering the hidden relationships between metrics that could make or break your API's 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_!QV2M!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4483842-28cb-4a12-9f9f-c10548c357e2_1400x618.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!QV2M!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4483842-28cb-4a12-9f9f-c10548c357e2_1400x618.png 424w, https://substackcdn.com/image/fetch/$s_!QV2M!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4483842-28cb-4a12-9f9f-c10548c357e2_1400x618.png 848w, https://substackcdn.com/image/fetch/$s_!QV2M!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4483842-28cb-4a12-9f9f-c10548c357e2_1400x618.png 1272w, https://substackcdn.com/image/fetch/$s_!QV2M!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4483842-28cb-4a12-9f9f-c10548c357e2_1400x618.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!QV2M!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4483842-28cb-4a12-9f9f-c10548c357e2_1400x618.png" width="727.998046875" height="321.3591378348214" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b4483842-28cb-4a12-9f9f-c10548c357e2_1400x618.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:618,&quot;width&quot;:1400,&quot;resizeWidth&quot;:727.998046875,&quot;bytes&quot;:109472,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!QV2M!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4483842-28cb-4a12-9f9f-c10548c357e2_1400x618.png 424w, https://substackcdn.com/image/fetch/$s_!QV2M!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4483842-28cb-4a12-9f9f-c10548c357e2_1400x618.png 848w, https://substackcdn.com/image/fetch/$s_!QV2M!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4483842-28cb-4a12-9f9f-c10548c357e2_1400x618.png 1272w, https://substackcdn.com/image/fetch/$s_!QV2M!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4483842-28cb-4a12-9f9f-c10548c357e2_1400x618.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><h3>Understanding Complex Metric Relationships</h3><p>Looking at our API metrics summary, something fascinating emerges. At first glance, everything seems normal - almost suspiciously so. Let's dig deeper into what these numbers are telling us.</p><h4>CPU Utilization Analysis</h4><p>Notice the CPU utilization across all endpoints? They're hovering around 59-60% - nearly identical despite vastly different workloads. The <em>/api/v1/cart</em> endpoint handles over 2,000 requests at peak, while others see much lower volumes. Yet their CPU usage barely differs.</p><p>This is our first clue that single-metric analysis can be deceiving. If you were load testing based on CPU alone, you'd miss something critical.</p><h4>Latency Pattern Analysis</h4><p>Here's where it gets interesting. Look at the <em>/api/v1/checkout</em> endpoint:</p><ul><li><p>Average latency: 400.3ms (highest among all endpoints)</p></li><li><p>Error rate: 3.99% (also highest)</p></li><li><p>Yet its request volume is relatively low</p></li></ul><p>Meanwhile, <em>/api/v1/cart</em> handles much higher traffic with:</p><ul><li><p>Lower latency (100ms)</p></li><li><p>Lower error rate (1%)</p></li></ul><p>Traditional wisdom suggests higher traffic leads to higher latency. But our data tells a different story. This isn't just an anomaly - it's a clear signal that request volume alone cannot predict API performance.</p><h4>Memory-CPU Relationship</h4><p>The memory utilization tells another intriguing tale:</p><ul><li><p>Consistently around 69-70% across all endpoints</p></li><li><p>Almost no correlation with CPU usage</p></li><li><p>Stable despite varying request patterns</p></li></ul><p>This stability across wildly different workloads suggests our previous model's assumption - that resource usage scales linearly with requests - was fundamentally flawed.</p><h3>Business Impact Analysis</h3><p>These patterns reveal why our simple linear regression model had such a low R&#178; value. We're seeing complex interactions where:</p><ol><li><p>High latency doesn't necessarily correspond with high traffic</p></li><li><p>Resource utilization doesn't scale linearly with load</p></li><li><p>Different endpoints behave distinctly despite similar resource profiles</p></li></ol><p>In the next section, we'll explore how to build a prediction model that captures these nuanced relationships. But first, let's visualize these hidden patterns to better understand what we're dealing with.</p><h2>Pattern Visualization</h2><p>The <a href="https://github.com/stackgazer-labs/stats-for-engineers/blob/main/regression/02-beyond-basic-metrics/beyond-basic-metrics.ipynb#pattern-visualization">second section</a> of the notebook powers the visualization that follows. The visualization code leverages plotly's powerful subplots to create a comprehensive dashboard:</p><ul><li><p>Top graph maps requests vs latency with distinct colors per endpoint</p></li><li><p>Bottom left heatmap uses a RdBu (Red-Blue) colorscale, where darker blue indicates stronger positive correlations</p></li><li><p>Bottom right bar chart compares resource usage, with CPU in darker blue for visual distinction </p></li><li><p>All plots share consistent styling and color schemes for cohesive presentation</p></li></ul><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!m9WF!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab5aeec8-2f93-4ceb-b3b4-d890b94c1b84_2400x2000.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!m9WF!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab5aeec8-2f93-4ceb-b3b4-d890b94c1b84_2400x2000.png 424w, https://substackcdn.com/image/fetch/$s_!m9WF!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab5aeec8-2f93-4ceb-b3b4-d890b94c1b84_2400x2000.png 848w, https://substackcdn.com/image/fetch/$s_!m9WF!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab5aeec8-2f93-4ceb-b3b4-d890b94c1b84_2400x2000.png 1272w, https://substackcdn.com/image/fetch/$s_!m9WF!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab5aeec8-2f93-4ceb-b3b4-d890b94c1b84_2400x2000.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!m9WF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab5aeec8-2f93-4ceb-b3b4-d890b94c1b84_2400x2000.png" width="1456" height="1213" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ab5aeec8-2f93-4ceb-b3b4-d890b94c1b84_2400x2000.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1213,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:763742,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!m9WF!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab5aeec8-2f93-4ceb-b3b4-d890b94c1b84_2400x2000.png 424w, https://substackcdn.com/image/fetch/$s_!m9WF!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab5aeec8-2f93-4ceb-b3b4-d890b94c1b84_2400x2000.png 848w, https://substackcdn.com/image/fetch/$s_!m9WF!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab5aeec8-2f93-4ceb-b3b4-d890b94c1b84_2400x2000.png 1272w, https://substackcdn.com/image/fetch/$s_!m9WF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab5aeec8-2f93-4ceb-b3b4-d890b94c1b84_2400x2000.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 multi-dimensional view reveals three critical insights that our previous analysis missed:</p><h3>Request-Latency Relationships</h3><ul><li><p>Look at how the latency-request relationship (top graph) isn't a straight line</p></li><li><p>Each endpoint shows distinct behavior under load</p></li><li><p>The checkout API's curve is particularly telling - steeper than others, suggesting it's more sensitive to load changes</p></li></ul><h3>Metric Correlation Analysis</h3><ul><li><p>The heatmap (bottom left) shows surprising independence between metrics we thought were related</p></li><li><p>Memory and CPU utilization have weaker correlation than expected</p></li><li><p>Error rates show stronger correlation with latency than with request volume</p></li></ul><h3>Resource Usage Analysis</h3><ul><li><p>The bar chart (bottom right) quantifies what we suspected</p></li><li><p>Despite vastly different workloads, resource usage remains surprisingly constant</p></li><li><p>The checkout API's resource profile doesn't match its performance profile</p><p></p></li></ul><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.stackgazer.com/?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share Stackgazer&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.stackgazer.com/?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share Stackgazer</span></a></p><p></p><h2>Building the Multi-Factor Model</h2><p>Now that we've visualized these complex relationships, let's build a model that can actually account for them. This means moving beyond simple linear regression to capture the nuanced interplay between metrics.</p><p>We'll use a multiple regression model that considers not just request volume, but also error rates, resource utilization, and even the distinct behavioral patterns of each endpoint.<br><br>Let's run the <a href="https://github.com/stackgazer-labs/stats-for-engineers/blob/main/regression/02-beyond-basic-metrics/beyond-basic-metrics.ipynb#builing_the_model">Multiple Factor Model</a> section of our notebook. </p><p>Our model implementation incorporates several best practices:</p><ul><li><p>Feature scaling with StandardScaler ensures all metrics contribute proportionally</p></li><li><p>Train-test split (80-20) helps validate our model's real-world performance</p></li><li><p> The residual plot helps identify where our predictions might be less reliable</p></li><li><p>Feature importance visualization guides our monitoring priorities</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_!InFI!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd79a6f79-98bc-474b-b55b-9fe7d3b428b3_2000x1600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!InFI!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd79a6f79-98bc-474b-b55b-9fe7d3b428b3_2000x1600.png 424w, https://substackcdn.com/image/fetch/$s_!InFI!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd79a6f79-98bc-474b-b55b-9fe7d3b428b3_2000x1600.png 848w, https://substackcdn.com/image/fetch/$s_!InFI!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd79a6f79-98bc-474b-b55b-9fe7d3b428b3_2000x1600.png 1272w, https://substackcdn.com/image/fetch/$s_!InFI!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd79a6f79-98bc-474b-b55b-9fe7d3b428b3_2000x1600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!InFI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd79a6f79-98bc-474b-b55b-9fe7d3b428b3_2000x1600.png" width="1456" height="1165" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d79a6f79-98bc-474b-b55b-9fe7d3b428b3_2000x1600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1165,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:370357,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!InFI!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd79a6f79-98bc-474b-b55b-9fe7d3b428b3_2000x1600.png 424w, https://substackcdn.com/image/fetch/$s_!InFI!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd79a6f79-98bc-474b-b55b-9fe7d3b428b3_2000x1600.png 848w, https://substackcdn.com/image/fetch/$s_!InFI!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd79a6f79-98bc-474b-b55b-9fe7d3b428b3_2000x1600.png 1272w, https://substackcdn.com/image/fetch/$s_!InFI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd79a6f79-98bc-474b-b55b-9fe7d3b428b3_2000x1600.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><h3>Understanding Our Multi-Factor Model</h3><p>The visualizations reveal some fascinating insights about our improved model:</p><ol><li><p><strong>Prediction Accuracy</strong> (Top Left)</p></li></ol><ul><li><p>The scatter plot shows a much tighter clustering around the perfect prediction line (dashed)</p></li><li><p>Our R&#178; value has improved to 0.72 - a dramatic improvement from our previous 0.088</p></li><li><p>We can now explain 72% of the variance in API latency</p></li></ul><ol start="2"><li><p><strong>Residual Analysis</strong> (Top Right)</p></li></ol><ul><li><p>The residuals show a fan-shaped pattern</p></li><li><p>This suggests our model is more accurate for lower latencies</p></li><li><p>Prediction uncertainty increases with higher latencies, which makes intuitive sense</p></li></ul><ol start="3"><li><p><strong>Feature Importance</strong> (Bottom Left)</p></li></ol><ul><li><p>Error rate emerges as the strongest predictor of latency</p></li><li><p>Request volume is significant but not dominant</p></li><li><p>CPU and memory utilization have surprisingly low impact</p></li></ul><ol start="4"><li><p><strong>Error Distribution</strong> (Bottom Right)</p></li></ol><ul><li><p>The bi-modal distribution suggests two distinct performance regimes</p></li><li><p>This might indicate different behavioral patterns between our endpoints</p></li></ul><h2>Practical Implementation Guidelines</h2><p>Let's translate these insights into actionable monitoring strategies:</p><pre><code>def should_alert_v2(metrics, thresholds):
    # <em>Calculate weighted risk score</em>
    risk_score = (
        0.3 * (metrics['error_rate'] / thresholds['error_rate']) +
        0.3 * (metrics['latency'] / thresholds['latency']) +
        0.2 * (metrics['requests'] / thresholds['requests']) +
        0.1 * (metrics['cpu'] / thresholds['cpu']) +
        0.1 * (metrics['memory'] / thresholds['memory'])
    )
    
    return risk_score &gt; 1.0</code></pre><p>This monitoring function incorporates our new understanding by:</p><ul><li><p>Weighing error rates as heavily as latency</p></li><li><p>Reducing emphasis on raw resource metrics</p></li><li><p>Using a composite score for more nuanced alerting</p></li></ul><h3>Advanced Considerations</h3><p>When implementing this multi-factor approach, there are several advanced considerations that can further enhance your monitoring strategy:</p><ol><li><p><strong>Endpoint-Specific Thresholds</strong></p><pre><code># Example of endpoint-specific threshold configuration
thresholds = {
    '/api/v1/checkout': {
        'error_rate': 0.02,  # More sensitive to errors
        'latency': 350,      # Higher latency tolerance
        'memory': 75         # Higher memory threshold
    },
    '/api/v1/cart': {
        'error_rate': 0.01,  # Stricter error threshold
        'latency': 150,      # Must be fast
        'memory': 65         # Standard memory threshold
    }
}</code></pre><p>Each endpoint has unique characteristics and business importance. The checkout API might need stricter error monitoring but can tolerate higher latency, while the cart API needs to be consistently fast.</p></li></ol><ol><li><p><strong>Time-Window Analysis</strong></p><ol><li><p>Consider using rolling windows for metric analysis</p></li><li><p>Short windows (5min) catch acute issues</p></li><li><p>Longer windows (1hr) identify gradual degradation</p></li><li><p>Compare current metrics against historical patterns</p></li></ol></li><li><p><strong>Circuit Breaker Integration</strong> Our model can inform circuit breaker decisions:</p><ol><li><p>Use the composite risk score to trigger circuit breakers</p></li><li><p>Implement graduated responses based on severity</p></li><li><p>Automatically adjust thresholds based on traffic patterns</p></li></ol></li></ol><h3>Real-World Applications</h3><p>This multi-factor approach has proven particularly valuable in several common scenarios:</p><ol><li><p><strong>Microservice Dependencies</strong></p><p>When services depend on each other, error rates often cascade. Our model catches these patterns before they affect end users. Helps prioritize which dependencies need attention first</p></li><li><p><strong>Database Impact Analysis</strong></p><p>High latency with normal CPU often indicates database issues. The model helps distinguish between compute and data access problems. Enables faster root cause analysis.</p></li><li><p><strong>Cache Effectiveness</strong></p><p>Memory usage patterns often reveal cache efficiency. Our model can detect when caching strategies need adjustment. Helps optimize resource allocation</p></li></ol><h2>Conclusion: From Metrics to Meaning</h2><p>Our journey from simple linear regression to multi-factor analysis reveals that API performance is far more nuanced than simple request counting. Key takeaways:</p><ol><li><p>Error rates are often a leading indicator of performance issues</p></li><li><p>Resource metrics alone can be misleading</p></li><li><p>Different endpoints need different monitoring strategies</p></li></ol><p>In our next article, "Building Production-Ready Performance Prediction Systems," we'll explore how to:</p><ul><li><p>Deploy these models in production</p></li><li><p>Handle real-time prediction updates</p></li><li><p>Integrate with existing monitoring systems</p></li><li><p>Deal with seasonal patterns and anomalies</p></li></ul><p>Stay tuned, and in the meantime, try implementing our multi-factor monitoring approach. You might be surprised at how many potential issues you catch before they become critical problems.</p><p>Also, please subscribe and/or share</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.stackgazer.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.stackgazer.com/subscribe?"><span>Subscribe now</span></a></p><p></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.stackgazer.com/p/beyond-basic-metrics-multi-factor?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://www.stackgazer.com/p/beyond-basic-metrics-multi-factor?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p>Once you&#8217;ve done that, you can move on to:</p><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;3780b8cd-745e-4cc3-a774-00f64958e7a8&quot;,&quot;caption&quot;:&quot;Notebook to Network?&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Building Production-Ready Performance Prediction Systems: From Notebook to Network&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:205997938,&quot;name&quot;:&quot;Dixyantar Panda&quot;,&quot;bio&quot;:&quot;Cloud Architect &amp; Engineer Leader crafting elegant systems - from scalable cloud architectures to modern webapps. Sharing insights from 14+ years of building distributed systems and high-performance applications. &quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f97795ea-c836-404d-8ccc-30d5fc16d9c9_576x576.webp&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2024-12-19T05:01:21.659Z&quot;,&quot;cover_image&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%2F8089f404-76cf-4770-b3d9-92755bdba5ba_1024x608.png&quot;,&quot;cover_image_alt&quot;:null,&quot;canonical_url&quot;:&quot;https://www.stackgazer.com/p/building-production-ready-performance&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:153224155,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:0,&quot;comment_count&quot;:0,&quot;publication_id&quot;:null,&quot;publication_name&quot;:&quot;Stackgazer&quot;,&quot;publication_logo_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%2F76603155-9304-47e2-9ed0-cdcadabf8cb6_400x400.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div>]]></content:encoded></item><item><title><![CDATA[From Firefighting to Forecasting: A Software Engineer's Guide to API Performance Prediction ]]></title><description><![CDATA[Master the art of API performance prediction and say goodbye to those 2 AM wake-up calls. Learn how to analyze real-world metrics and build reliable forecasting models.]]></description><link>https://www.stackgazer.com/p/from-firefighting-to-forecasting</link><guid isPermaLink="false">https://www.stackgazer.com/p/from-firefighting-to-forecasting</guid><dc:creator><![CDATA[Dixyantar Panda]]></dc:creator><pubDate>Tue, 17 Dec 2024 05:00:36 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!KfrW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71decc16-0b80-48c2-b8b1-2dbb774dc4e4_1024x608.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!KfrW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71decc16-0b80-48c2-b8b1-2dbb774dc4e4_1024x608.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!KfrW!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71decc16-0b80-48c2-b8b1-2dbb774dc4e4_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!KfrW!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71decc16-0b80-48c2-b8b1-2dbb774dc4e4_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!KfrW!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71decc16-0b80-48c2-b8b1-2dbb774dc4e4_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!KfrW!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71decc16-0b80-48c2-b8b1-2dbb774dc4e4_1024x608.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!KfrW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71decc16-0b80-48c2-b8b1-2dbb774dc4e4_1024x608.png" width="1024" height="608" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/71decc16-0b80-48c2-b8b1-2dbb774dc4e4_1024x608.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:608,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&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="" srcset="https://substackcdn.com/image/fetch/$s_!KfrW!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71decc16-0b80-48c2-b8b1-2dbb774dc4e4_1024x608.png 424w, https://substackcdn.com/image/fetch/$s_!KfrW!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71decc16-0b80-48c2-b8b1-2dbb774dc4e4_1024x608.png 848w, https://substackcdn.com/image/fetch/$s_!KfrW!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71decc16-0b80-48c2-b8b1-2dbb774dc4e4_1024x608.png 1272w, https://substackcdn.com/image/fetch/$s_!KfrW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71decc16-0b80-48c2-b8b1-2dbb774dc4e4_1024x608.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></figure></div><h2>The Hidden Cost of Reactive API Monitoring</h2><p>The dreaded 2 AM alert. The checkout API is running slow, again. Orders are piling up, and the operations team is getting anxious. As an on-call engineer, you've been here before - watching dashboards, scrambling to scale services, and wondering if there was a better way.</p><p>There is. And it starts with understanding your data. Follow along, as we use a Jupyter notebook to help us make sense of data. </p><h2>Understanding Our API Performance Data</h2><p>Before diving into predictions, let's examine what API monitoring data actually looks like. Here's a snapshot of 15-minute interval metrics across our e-commerce platform's core services. The data is simulated and contains a month worth of metrics solely for the purpose of this article! </p><p>Assuming you have all libraries installed, run the <a href="https://github.com/stackgazer/stats-for-engineers/blob/78693bcdd88aaec6a2a7253e32513de5b7a8f2a4/regression/#data-generation-and-initial-analysis">Data Generation and Initial Analysis</a> section of the notebook. </p><pre><code><code>def create_synthetic_data():
    # Generate timestamps for 3 months at 5-minute intervals
    timestamps = pd.date_range(start=datetime(2023, 9, 1), 
                            end=datetime(2023, 12, 1), freq='5T')</code></code></pre><p>Our data generator carefully models:</p><ul><li><p>Daily traffic waves using sine functions</p></li><li><p>Weekly business cycles</p></li><li><p>Realistic noise with controlled randomness</p></li><li><p>Metric correlations (like latency following traffic)</p></li></ul><p>Output should look something 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_!r__8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0067a4d6-2157-4478-a417-234739b9da12_2000x1000.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!r__8!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0067a4d6-2157-4478-a417-234739b9da12_2000x1000.png 424w, https://substackcdn.com/image/fetch/$s_!r__8!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0067a4d6-2157-4478-a417-234739b9da12_2000x1000.png 848w, https://substackcdn.com/image/fetch/$s_!r__8!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0067a4d6-2157-4478-a417-234739b9da12_2000x1000.png 1272w, https://substackcdn.com/image/fetch/$s_!r__8!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0067a4d6-2157-4478-a417-234739b9da12_2000x1000.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!r__8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0067a4d6-2157-4478-a417-234739b9da12_2000x1000.png" width="1456" height="728" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0067a4d6-2157-4478-a417-234739b9da12_2000x1000.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:728,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:194284,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!r__8!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0067a4d6-2157-4478-a417-234739b9da12_2000x1000.png 424w, https://substackcdn.com/image/fetch/$s_!r__8!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0067a4d6-2157-4478-a417-234739b9da12_2000x1000.png 848w, https://substackcdn.com/image/fetch/$s_!r__8!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0067a4d6-2157-4478-a417-234739b9da12_2000x1000.png 1272w, https://substackcdn.com/image/fetch/$s_!r__8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0067a4d6-2157-4478-a417-234739b9da12_2000x1000.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>Congrats, you have just generated synthetic data for exploratory analysis. </p><p><br>Let's break down what we're looking at:</p><ul><li><p><strong>Requests</strong>: The number of API calls in a 5-minute window</p></li><li><p><strong>Latency</strong>: Response time in milliseconds (ms)</p></li><li><p><strong>Errors</strong>: Count of failed requests</p></li><li><p><strong>Error Rate</strong>: Percentage of requests that failed</p></li><li><p><strong>Resource Usage</strong>: CPU and memory utilization percentages</p></li></ul><p>In the next section, we'll dive deeper into these metrics, visualizing patterns that will become the foundation of our prediction model. We'll see how daily and weekly cycles affect our API performance, and how different metrics correlate with each other.</p><div><hr></div><p><em>Stay tuned as we transform this raw data into actionable insights that will help you sleep better at night.</em></p><div><hr></div><h2>API Traffic Patterns and Analysis</h2><p>Looking at raw numbers can be overwhelming. Let's visualize three critical patterns that emerged from our analysis of three months of API traffic data.<br>Run the <a href="https://github.com/stackgazer-labs/stats-for-engineers/blob/78693bcdd88aaec6a2a7253e32513de5b7a8f2a4/regression/#visualizing-traffic-patterns">Visualizing Traffic Patterns</a> section of the notebook. </p><pre><code>def create_daily_pattern(df):
    # Group by hour and calculate means
    hourly_stats = df.groupby('hour').agg({
        'requests': 'mean',
        'latency_ms': 'mean'
    })</code></pre><p>This aggregation shows us the true shape of our daily traffic pattern by:</p><ul><li><p>Averaging out noise and anomalies</p></li><li><p>Preserving the relationship between metrics</p></li><li><p>Highlighting the key patterns we care about</p></li></ul><p>It should spurt out three images. </p><h3>Daily Traffic Analysis</h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!zKI2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbe4e0a9-fab3-477e-9675-37df669a62d3_1600x1000.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!zKI2!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbe4e0a9-fab3-477e-9675-37df669a62d3_1600x1000.png 424w, https://substackcdn.com/image/fetch/$s_!zKI2!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbe4e0a9-fab3-477e-9675-37df669a62d3_1600x1000.png 848w, https://substackcdn.com/image/fetch/$s_!zKI2!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbe4e0a9-fab3-477e-9675-37df669a62d3_1600x1000.png 1272w, https://substackcdn.com/image/fetch/$s_!zKI2!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbe4e0a9-fab3-477e-9675-37df669a62d3_1600x1000.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!zKI2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbe4e0a9-fab3-477e-9675-37df669a62d3_1600x1000.png" width="1456" height="910" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cbe4e0a9-fab3-477e-9675-37df669a62d3_1600x1000.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:910,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:130818,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!zKI2!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbe4e0a9-fab3-477e-9675-37df669a62d3_1600x1000.png 424w, https://substackcdn.com/image/fetch/$s_!zKI2!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbe4e0a9-fab3-477e-9675-37df669a62d3_1600x1000.png 848w, https://substackcdn.com/image/fetch/$s_!zKI2!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbe4e0a9-fab3-477e-9675-37df669a62d3_1600x1000.png 1272w, https://substackcdn.com/image/fetch/$s_!zKI2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbe4e0a9-fab3-477e-9675-37df669a62d3_1600x1000.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>Our 24-hour traffic pattern reveals a fascinating story. Traffic starts climbing around 5 AM, reaching its peak by mid-morning and maintaining high levels until early afternoon. But here's what's particularly interesting: latency doesn't just mirror traffic - it shows a slight lag. This lag represents our systems scaling up to meet demand, and it's a crucial window for predictive action.</p><p>Key insights from the daily pattern:</p><ul><li><p>Peak traffic occurs between 5-7 hours into the day</p></li><li><p>Latency follows traffic with a 15-30 minute delay</p></li><li><p>The quietest period (around hour 20) shows both minimal traffic and lowest latency</p></li></ul><h3>Weekly Traffic Distribution</h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ZWUn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b808990-4d37-4396-8f5c-2b04ab693ece_1600x1000.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ZWUn!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b808990-4d37-4396-8f5c-2b04ab693ece_1600x1000.png 424w, https://substackcdn.com/image/fetch/$s_!ZWUn!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b808990-4d37-4396-8f5c-2b04ab693ece_1600x1000.png 848w, https://substackcdn.com/image/fetch/$s_!ZWUn!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b808990-4d37-4396-8f5c-2b04ab693ece_1600x1000.png 1272w, https://substackcdn.com/image/fetch/$s_!ZWUn!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b808990-4d37-4396-8f5c-2b04ab693ece_1600x1000.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ZWUn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b808990-4d37-4396-8f5c-2b04ab693ece_1600x1000.png" width="1456" height="910" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2b808990-4d37-4396-8f5c-2b04ab693ece_1600x1000.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:910,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:175809,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ZWUn!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b808990-4d37-4396-8f5c-2b04ab693ece_1600x1000.png 424w, https://substackcdn.com/image/fetch/$s_!ZWUn!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b808990-4d37-4396-8f5c-2b04ab693ece_1600x1000.png 848w, https://substackcdn.com/image/fetch/$s_!ZWUn!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b808990-4d37-4396-8f5c-2b04ab693ece_1600x1000.png 1272w, https://substackcdn.com/image/fetch/$s_!ZWUn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b808990-4d37-4396-8f5c-2b04ab693ece_1600x1000.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>Different endpoints tell different stories. Our weekly pattern analysis shows distinct behaviors across our API endpoints:</p><ul><li><p>Tuesday and Wednesday show the highest consistent traffic</p></li><li><p>All endpoints follow remarkably similar patterns</p></li><li><p>Weekend traffic drops by approximately 20%</p></li><li><p>Sunday shows an interesting uptick, possibly from users preparing for the week ahead</p></li></ul><p>This consistency across endpoints suggests system-wide patterns rather than endpoint-specific issues - a crucial insight for capacity planning.</p><h3>Metric Correlations</h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Fyo4!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92144b79-e550-4674-8682-8b55bb191709_1600x1000.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Fyo4!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92144b79-e550-4674-8682-8b55bb191709_1600x1000.png 424w, https://substackcdn.com/image/fetch/$s_!Fyo4!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92144b79-e550-4674-8682-8b55bb191709_1600x1000.png 848w, https://substackcdn.com/image/fetch/$s_!Fyo4!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92144b79-e550-4674-8682-8b55bb191709_1600x1000.png 1272w, https://substackcdn.com/image/fetch/$s_!Fyo4!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92144b79-e550-4674-8682-8b55bb191709_1600x1000.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Fyo4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92144b79-e550-4674-8682-8b55bb191709_1600x1000.png" width="1456" height="910" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/92144b79-e550-4674-8682-8b55bb191709_1600x1000.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:910,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:105443,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Fyo4!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92144b79-e550-4674-8682-8b55bb191709_1600x1000.png 424w, https://substackcdn.com/image/fetch/$s_!Fyo4!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92144b79-e550-4674-8682-8b55bb191709_1600x1000.png 848w, https://substackcdn.com/image/fetch/$s_!Fyo4!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92144b79-e550-4674-8682-8b55bb191709_1600x1000.png 1272w, https://substackcdn.com/image/fetch/$s_!Fyo4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92144b79-e550-4674-8682-8b55bb191709_1600x1000.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>The correlation matrix reveals the intricate relationships between our metrics:</p><ul><li><p>Strong positive correlation between requests and latency (dark blue)</p></li><li><p>CPU utilization shows moderate correlation with error rates (medium blue)</p></li><li><p>Memory utilization remains relatively independent (lighter colors)</p></li></ul><p>This heat map is particularly valuable for prediction because it shows us which metrics can serve as early warning indicators. For instance, the strong correlation between requests and latency suggests we can predict latency spikes by monitoring request patterns.</p><h2>Implementing Prediction Models</h2><p>These visualizations reveal more than just pretty patterns - they're the foundation of our prediction strategy. By understanding these rhythms, we can:</p><ol><li><p>Anticipate daily load peaks before they occur</p></li><li><p>Plan resource allocation around weekly patterns</p></li><li><p>Use leading indicators to predict potential issues</p></li></ol><p>In the next section, we'll transform these insights into a practical prediction model. We'll show you how to use these patterns to stay ahead of performance issues and finally get a full night's sleep.</p><div><hr></div><p><em>Next: Building Your First API Performance Prediction Model</em></p><div><hr></div><h2>Linear Regression Fundamentals</h2><p>Before we build our prediction model, let's understand the simplest yet powerful statistical tool we'll use: simple linear regression.</p><p>Remember that strong correlation we saw between requests and latency? That's not just an interesting observation - it's the foundation of our prediction strategy. Simple linear regression helps us quantify this relationship with a straightforward equation:</p><pre><code><code>latency = m * requests + b</code></code></pre><p>Where:</p><ul><li><p><code>m</code> is the slope (how much latency changes per additional request)</p></li><li><p><code>b</code> is the base latency (the theoretical latency with zero requests)</p></li></ul><p>Think of it like this: if you've ever adjusted an autoscaling rule saying "add a new server for every 1000 additional requests", you've actually been doing a form of linear regression in your head! You're assuming a linear relationship between load and required resources.</p><p>The beauty of simple linear regression is that it:</p><ul><li><p>Captures basic cause-and-effect relationships</p></li><li><p>Is easy to explain to stakeholders</p></li><li><p>Provides quick, reasonable predictions</p></li><li><p>Forms the foundation for more sophisticated models</p></li></ul><h2>Building an API Performance Prediction Model</h2><p>Now comes the exciting part - turning our insights into actionable predictions. We'll build a simple yet powerful model that predicts API latency based on request volume.<br>Look at the code in the <a href="https://github.com/stackgazer-labs/stats-for-engineers/blob/78693bcdd88aaec6a2a7253e32513de5b7a8f2a4/regression/#building-the-prediction-model">Building the Prediction Model</a> section of the notebook.</p><pre><code># Prepare data for modeling
X = df['requests'].values.reshape(-1, 1)
y = df['latency_ms'].values

# Split and train
model = LinearRegression()
model.fit(X_train, y_train)</code></pre><p>Our model is intentionally simple - we're looking for the basic relationship between traffic and latency. The reshaping and splitting steps ensure we:</p><ul><li><p>Have proper input format for scikit-learn</p></li><li><p>Keep a test set for validation</p></li><li><p>Can measure our prediction accuracy</p></li></ul><p>Once you run it, it will print these metrics and also generate the visualization image.</p><pre><code>Model Metrics:
Mean Squared Error: 13788.23
R-squared Score: 0.088
Coefficient: 0.135
Intercept: 94.88</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_!67wD!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefa63ae2-c6b9-4900-b219-cf08b1b8a6bd_1600x1600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!67wD!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefa63ae2-c6b9-4900-b219-cf08b1b8a6bd_1600x1600.png 424w, https://substackcdn.com/image/fetch/$s_!67wD!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefa63ae2-c6b9-4900-b219-cf08b1b8a6bd_1600x1600.png 848w, https://substackcdn.com/image/fetch/$s_!67wD!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefa63ae2-c6b9-4900-b219-cf08b1b8a6bd_1600x1600.png 1272w, https://substackcdn.com/image/fetch/$s_!67wD!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefa63ae2-c6b9-4900-b219-cf08b1b8a6bd_1600x1600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!67wD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefa63ae2-c6b9-4900-b219-cf08b1b8a6bd_1600x1600.png" width="1456" height="1456" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/efa63ae2-c6b9-4900-b219-cf08b1b8a6bd_1600x1600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1456,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:341384,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!67wD!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefa63ae2-c6b9-4900-b219-cf08b1b8a6bd_1600x1600.png 424w, https://substackcdn.com/image/fetch/$s_!67wD!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefa63ae2-c6b9-4900-b219-cf08b1b8a6bd_1600x1600.png 848w, https://substackcdn.com/image/fetch/$s_!67wD!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefa63ae2-c6b9-4900-b219-cf08b1b8a6bd_1600x1600.png 1272w, https://substackcdn.com/image/fetch/$s_!67wD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefa63ae2-c6b9-4900-b219-cf08b1b8a6bd_1600x1600.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>Our model reveals some fascinating patterns that aren't immediately obvious from raw data:</p><ul><li><p>There's a clear positive relationship between requests and latency (red line in top graph)</p></li><li><p>However, there's significant variance in actual latency for any given request load (spread of blue dots)</p></li><li><p>The model predicts a baseline latency around 150ms, increasing gradually with load</p></li><li><p>Most interestingly, we see a "spread pattern" where variability increases with higher request volumes</p></li></ul><p>Looking at the actual vs. predicted plot (bottom), we can see that our simple model:</p><ul><li><p>Tends to overpredict latency for lighter loads</p></li><li><p>Underpredicts for heavier loads</p></li><li><p>Shows considerable scatter around the perfect prediction line (dashed)</p></li></ul><p>This teaches us something crucial about API performance: while there's definitely a relationship between requests and latency, other factors are clearly at play. The spread pattern suggests that as load increases, other variables (perhaps database connections or cache hit rates) become increasingly important.</p><p>For practical use, this means:</p><ol><li><p>We can predict general trends in latency based on request volumes</p></li><li><p>We should be conservative with our predictions, especially at higher loads</p></li><li><p>We need to consider additional factors for more accurate predictions</p></li></ol><p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.stackgazer.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Before you read the next section, consider subscribing for FREE!</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p><h2>Actionable Metrics: Making Predictions Useful</h2><p>The model metrics reveal an important truth about API performance prediction - it's not perfect (R-squared score of 0.088), but it's still incredibly useful. Here's how to put these predictions into action:</p><h3>1. Set Proactive Alerts</h3><p>Instead of waiting for latency to spike, set alerts based on request volumes:</p><pre><code>def should_alert(current_requests, threshold_ms=300):
    predicted_latency = 0.135 * current_requests + 94.88  # Our model
    return predicted_latency &gt; threshold_ms2</code></pre><h3>2. Plan Scaling Windows</h3><p>Remember the 15-30 minute lag we discovered between traffic spikes and latency increases? Use this window:</p><ul><li><p>Monitor request volumes at 5-minute intervals</p></li><li><p>If <code>should_alert()</code> returns true, trigger scaling before latency spikes</p></li><li><p>Set cool-down periods based on our weekly pattern analysis</p></li></ul><h3>3. Build Safety Margins</h3><p>Given our model's tendency to underpredict at high loads:</p><ul><li><p>Add 20% buffer to predictions above 1500 requests/minute</p></li><li><p>Set conservative thresholds for critical endpoints like checkout</p></li><li><p>Monitor prediction accuracy and adjust buffers accordingly</p></li></ul><h2>Common Pitfalls in API Performance Prediction</h2><p>Our simple linear regression model is a powerful starting point, but let's explore some common pitfalls to avoid as you implement your own prediction system:</p><h3>1. Single Metric Dependency</h3><p>While request count and latency correlation is strong, relying solely on this relationship can be misleading. For instance, a sudden increase in database-heavy requests might cause performance issues even with normal traffic levels. Always monitor the nature of requests, not just their quantity.</p><h3>2. Missing Caching</h3><p>Our model doesn't account for cache behavior, which can dramatically affect performance patterns. A cache miss under high load can trigger a cascade of slow responses that the model didn't predict. Consider tracking cache hit rates alongside request metrics to refine predictions.</p><h3>3. Ignoring System Boundaries</h3><p>APIs rarely exist in isolation. External dependencies like databases, caches, or third-party services can introduce latency that appears random to our model. Some key considerations:</p><ul><li><p>Database connection pool limits</p></li><li><p>Third-party API rate limits</p></li><li><p>Network latency variations</p></li><li><p>Message queue backpressure</p></li></ul><h3>4. Fixed Time Windows </h3><p>Using fixed time windows (like our 5-minute intervals) can mask micro-spikes in traffic. A service might receive 1000 requests in a minute, but if they all arrive in the same second, we have a very different performance scenario. Consider using smaller sampling windows during peak periods.</p><h3>5. Static Thresholds </h3><p>The assumption that performance thresholds remain constant across all conditions rarely holds true. What works during normal operations might fail during high-traffic periods. Consider implementing dynamic thresholds that adapt to:</p><ul><li><p>Time of day</p></li><li><p>Day of week</p></li><li><p>Seasonal patterns</p></li><li><p>Deployment events</p></li></ul><p>Understanding these pitfalls helps explain why our model's R-squared score isn't higher and guides us toward more sophisticated prediction approaches. However, even with these limitations, the current model provides valuable insights for proactive performance management.</p><div><hr></div><p>In this next article, we'll explore how to enhance our model by incorporating these additional factors and handling the increased variability at higher loads.</p><p>But, before that please subscribe/share. It helps us all. <br></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.stackgazer.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.stackgazer.com/subscribe?"><span>Subscribe now</span></a></p><p> </p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.stackgazer.com/p/from-firefighting-to-forecasting?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://www.stackgazer.com/p/from-firefighting-to-forecasting?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;6ead8939-d840-41bb-a236-0eb03e4b003b&quot;,&quot;caption&quot;:&quot;Remember that simple regression model we built last time? The one that helped predict API latency based on request volume? Well, it had a telling limitation - its R-squared (R&#178;) value was just 0.088, meaning only 8.8% of the variance in latency could be explained by request volume alone.&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Beyond Basic Metrics: Multi-Factor Analysis for API Performance&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:205997938,&quot;name&quot;:&quot;Dixyantar Panda&quot;,&quot;bio&quot;:&quot;Cloud Architect &amp; Engineer Leader crafting elegant systems - from scalable cloud architectures to modern webapps. Sharing insights from 14+ years of building distributed systems and high-performance applications. &quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f97795ea-c836-404d-8ccc-30d5fc16d9c9_576x576.webp&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2024-12-18T05:00:32.226Z&quot;,&quot;cover_image&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%2F891d3694-c645-4a2a-a7d0-5adf7c5e893b_1024x608.png&quot;,&quot;cover_image_alt&quot;:null,&quot;canonical_url&quot;:&quot;https://www.stackgazer.com/p/beyond-basic-metrics-multi-factor&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:153247906,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:0,&quot;comment_count&quot;:0,&quot;publication_id&quot;:null,&quot;publication_name&quot;:&quot;Stackgazer&quot;,&quot;publication_logo_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%2F76603155-9304-47e2-9ed0-cdcadabf8cb6_400x400.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div>]]></content:encoded></item></channel></rss>