<?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[The System Design Newsletter]]></title><description><![CDATA[Download my system design playbook on newsletter signup for FREE]]></description><link>https://newsletter.systemdesign.one</link><image><url>https://substackcdn.com/image/fetch/$s_!W5r-!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa1c8067a-95bb-416b-9114-e0b9fb8821d4_256x256.png</url><title>The System Design Newsletter</title><link>https://newsletter.systemdesign.one</link></image><generator>Substack</generator><lastBuildDate>Mon, 13 Apr 2026 08:34:23 GMT</lastBuildDate><atom:link href="https://newsletter.systemdesign.one/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[Neo Kim]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[systemdesignone@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[systemdesignone@substack.com]]></itunes:email><itunes:name><![CDATA[Neo Kim]]></itunes:name></itunes:owner><itunes:author><![CDATA[Neo Kim]]></itunes:author><googleplay:owner><![CDATA[systemdesignone@substack.com]]></googleplay:owner><googleplay:email><![CDATA[systemdesignone@substack.com]]></googleplay:email><googleplay:author><![CDATA[Neo Kim]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[11 AI Concepts Explained, Simply]]></title><description><![CDATA[#138: Break into AI Engineering]]></description><link>https://newsletter.systemdesign.one/p/ai-concepts</link><guid isPermaLink="false">https://newsletter.systemdesign.one/p/ai-concepts</guid><dc:creator><![CDATA[Neo Kim]]></dc:creator><pubDate>Thu, 09 Apr 2026 09:54:36 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/f266f60d-51aa-416b-b477-90b1dc4c2299_1280x720.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/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">Get my system design playbook for FREE on newsletter signup:</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><ul><li><p><em><a href="https://newsletter.systemdesign.one/p/ai-concepts/?action=share">Share this post</a> &amp; I'll send you some rewards for the referrals.</em></p></li></ul><div><hr></div><p>I&#8217;ve built agents at Google to support their machine learning operations.</p><p>Then one thing became super clear to me: <em>AI engineering is good software engineering with an understanding of a few key AI principles.</em></p><p>Just a year ago, hardly any software engineers were building with AI.</p><p>Now, engineers are expected to understand AI engineering and integrate AI into their products. This newsletter is a primer to bridge the gap from software to AI engineering.</p><p>Onward.</p><div><hr></div><h2><a href="https://cline.gg/neo">The tax you pay to run multiple agents (Partner)</a></h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://cline.gg/neo" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!MX0h!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e0ba733-c96e-461d-92e4-e2bd8c2cb2a5_1600x900.png 424w, https://substackcdn.com/image/fetch/$s_!MX0h!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e0ba733-c96e-461d-92e4-e2bd8c2cb2a5_1600x900.png 848w, https://substackcdn.com/image/fetch/$s_!MX0h!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e0ba733-c96e-461d-92e4-e2bd8c2cb2a5_1600x900.png 1272w, https://substackcdn.com/image/fetch/$s_!MX0h!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e0ba733-c96e-461d-92e4-e2bd8c2cb2a5_1600x900.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!MX0h!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e0ba733-c96e-461d-92e4-e2bd8c2cb2a5_1600x900.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4e0ba733-c96e-461d-92e4-e2bd8c2cb2a5_1600x900.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:&quot;https://cline.gg/neo&quot;,&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_!MX0h!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e0ba733-c96e-461d-92e4-e2bd8c2cb2a5_1600x900.png 424w, https://substackcdn.com/image/fetch/$s_!MX0h!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e0ba733-c96e-461d-92e4-e2bd8c2cb2a5_1600x900.png 848w, https://substackcdn.com/image/fetch/$s_!MX0h!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e0ba733-c96e-461d-92e4-e2bd8c2cb2a5_1600x900.png 1272w, https://substackcdn.com/image/fetch/$s_!MX0h!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e0ba733-c96e-461d-92e4-e2bd8c2cb2a5_1600x900.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>If you&#8217;ve spent any time with coding agents, you know the feeling.</p><p>You start the morning with a clean plan. Spin up a few agents. One is refactoring the auth module. Another is writing tests. A third is scaffolding a new API endpoint. You&#8217;re flying.</p><p>Then, around 10:30 AM, you look up and realize you have 20 terminal windows open. One agent is blocked waiting for a decision you forgot to make. Another finished 40 minutes ago, and you never noticed. A third went sideways three commits back. You&#8217;re no longer flying. You&#8217;re drowning.</p><p>You&#8217;ve shifted from human as driver to human as director.</p><p>When running coding agents in parallel, the bottleneck isn&#8217;t just context. It&#8217;s your own attention trying to manage 10 agents across 10 terminals. You&#8217;re losing your mind to terminal chaos.</p><p>Meet <strong><a href="https://cline.gg/neo">Cline Kanban</a></strong>, a CLI-agnostic visual orchestration layer that makes multi-agent workflows usable across providers. Multiple agents, one UI. It&#8217;s the air traffic controller for the agents you&#8217;re already running, regardless of where they live.</p><ul><li><p><strong>Interoperable: </strong>Claude Code and Codex compatible, with more coming soon.</p></li><li><p><strong>Full Visibility:</strong> Confidently run multiple agents and work through your backlog faster.</p></li><li><p><strong>Smart Triage:</strong> See which agents are blocked or in review and jump in to unblock them.</p></li><li><p><strong>Chain Tasks:</strong> Set dependencies so Agent B won&#8217;t start until Agent A is complete.</p></li><li><p><strong>Familiar UI:</strong> Everything in a single Kanban view.</p></li></ul><p>Stop tracking agents and start directing them. Get a meaningful edge with the beta release.</p><p><strong>Install Cline Kanban Today: </strong><code>npm i -g cline</code></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://cline.gg/neo&quot;,&quot;text&quot;:&quot;Get Started Today&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://cline.gg/neo"><span>Get Started Today</span></a></p><p>(Thanks to <a href="https://cline.gg/neo">Cline</a> for partnering on this post.)</p><div><hr></div><p>I want to introduce <strong><a href="http://aiforswes.com/subscribe">Logan Thorneloe</a></strong> as the guest author.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="http://aiforswes.com/subscribe" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Zf30!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ee68530-d50b-4df7-9548-6d342b4361b2_1310x816.png 424w, https://substackcdn.com/image/fetch/$s_!Zf30!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ee68530-d50b-4df7-9548-6d342b4361b2_1310x816.png 848w, https://substackcdn.com/image/fetch/$s_!Zf30!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ee68530-d50b-4df7-9548-6d342b4361b2_1310x816.png 1272w, https://substackcdn.com/image/fetch/$s_!Zf30!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ee68530-d50b-4df7-9548-6d342b4361b2_1310x816.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Zf30!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ee68530-d50b-4df7-9548-6d342b4361b2_1310x816.png" width="1310" height="816" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6ee68530-d50b-4df7-9548-6d342b4361b2_1310x816.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:816,&quot;width&quot;:1310,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:&quot;http://aiforswes.com/subscribe&quot;,&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_!Zf30!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ee68530-d50b-4df7-9548-6d342b4361b2_1310x816.png 424w, https://substackcdn.com/image/fetch/$s_!Zf30!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ee68530-d50b-4df7-9548-6d342b4361b2_1310x816.png 848w, https://substackcdn.com/image/fetch/$s_!Zf30!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ee68530-d50b-4df7-9548-6d342b4361b2_1310x816.png 1272w, https://substackcdn.com/image/fetch/$s_!Zf30!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ee68530-d50b-4df7-9548-6d342b4361b2_1310x816.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>He&#8217;s a software engineer at Google, building at the intersection of machine learning infrastructure, AI agents, and developer tooling.</p><p>He uses his background in machine learning research to teach software engineers the AI topics they should know via his newsletter, <strong><a href="http://aiforswes.com/subscribe">AI for Software Engineers</a></strong>.</p><p>You can also get an exclusive&nbsp;<strong><a href="https://www.aiforswes.com/67113502">25% off a paid AI for Software Engineers subscription</a></strong>&nbsp;as a reader of the System Design Newsletter.</p><div><hr></div><h2><strong>1 Software 1.0, 2.0, and 3.0</strong></h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!3Ir2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffeebfe95-2383-47ab-9b48-714973d2e17a_1200x630.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!3Ir2!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffeebfe95-2383-47ab-9b48-714973d2e17a_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!3Ir2!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffeebfe95-2383-47ab-9b48-714973d2e17a_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!3Ir2!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffeebfe95-2383-47ab-9b48-714973d2e17a_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!3Ir2!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffeebfe95-2383-47ab-9b48-714973d2e17a_1200x630.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!3Ir2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffeebfe95-2383-47ab-9b48-714973d2e17a_1200x630.png" width="1200" height="630" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/feebfe95-2383-47ab-9b48-714973d2e17a_1200x630.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:630,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:277568,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/192186526?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffeebfe95-2383-47ab-9b48-714973d2e17a_1200x630.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_!3Ir2!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffeebfe95-2383-47ab-9b48-714973d2e17a_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!3Ir2!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffeebfe95-2383-47ab-9b48-714973d2e17a_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!3Ir2!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffeebfe95-2383-47ab-9b48-714973d2e17a_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!3Ir2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffeebfe95-2383-47ab-9b48-714973d2e17a_1200x630.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><blockquote><p>&#8220;The hottest new programming language is English.&#8221; - <a href="https://x.com/karpathy/status/1617979122625712128">Andrej Karpathy</a></p></blockquote><p>There have been two recent AI-related shifts that have fundamentally changed software development and required software engineers to learn new concepts.</p><p>Both changes have been caused by the development of <em>machine learning models</em>: programs trained on data to recognize patterns and make predictions rather than follow explicit rules.</p><p>Andrej Karpathy details these changes by describing three different eras of software engineering:</p><ul><li><p><a href="https://karpathy.medium.com/software-2-0-a64152b37c35">Software 1.0</a>: hand-written logic via writing code. This was the paradigm from the inception of programming all the way to the advent of machine learning.</p></li><li><p><a href="https://karpathy.medium.com/software-2-0-a64152b37c35">Software 2.0</a>: shift from explicitly writing logic via code to curating datasets and teaching algorithms to understand them. This shifts logic from a set of instructions to logic learned from data. A good example of this is Tesla&#8217;s Autopilot system, shifting from hand-written C++ code to neural networks<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a> for vision.</p></li><li><p><a href="https://www.youtube.com/watch?v=LCEmiRjPEtQ">Software 3.0</a>: shift toward natural language<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-2" href="#footnote-2" target="_self">2</a> being our new programming interface. This enables engineers to write code by speaking English (<a href="https://x.com/karpathy/status/1886192184808149383">vibe coding</a>). It also enables engineers to build agents<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-3" href="#footnote-3" target="_self">3</a>, or software that can think and act autonomously.</p></li></ul><p>Software engineers <a href="https://www.aiforswes.com/p/why-software-engineers-need-to-understand-ml">need to understand</a> these key AI principles to be productive in the software 3.0 paradigm&#8230;</p><h2><strong>2 Large Language Models (LLMs)</strong></h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!VnN-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4095f8c9-e27f-4be6-bec4-ceb6e8f2a8fc_1200x630.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!VnN-!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4095f8c9-e27f-4be6-bec4-ceb6e8f2a8fc_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!VnN-!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4095f8c9-e27f-4be6-bec4-ceb6e8f2a8fc_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!VnN-!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4095f8c9-e27f-4be6-bec4-ceb6e8f2a8fc_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!VnN-!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4095f8c9-e27f-4be6-bec4-ceb6e8f2a8fc_1200x630.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!VnN-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4095f8c9-e27f-4be6-bec4-ceb6e8f2a8fc_1200x630.png" width="1200" height="630" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4095f8c9-e27f-4be6-bec4-ceb6e8f2a8fc_1200x630.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:630,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:402460,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/192186526?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4095f8c9-e27f-4be6-bec4-ceb6e8f2a8fc_1200x630.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_!VnN-!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4095f8c9-e27f-4be6-bec4-ceb6e8f2a8fc_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!VnN-!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4095f8c9-e27f-4be6-bec4-ceb6e8f2a8fc_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!VnN-!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4095f8c9-e27f-4be6-bec4-ceb6e8f2a8fc_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!VnN-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4095f8c9-e27f-4be6-bec4-ceb6e8f2a8fc_1200x630.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>LLMs are natural language AI models trained to predict the continuation of text given a natural language input.</p><p>As with any AI model, understanding how it works best comes from examining its training data. LLMs are trained on a massive dataset of text from the internet. They&#8217;re trained to learn the <em><strong>relationship between words</strong></em> <em><strong>to best predict an output</strong></em> when given a specific string of inputs.</p><p>This relationship enables LLMs to use the knowledge stored in the semantics of language to understand relationships between concepts.</p><p>LLMs are also tuned to be <em><strong>non-deterministic</strong></em>; i.e., to provide different answers when an input is sent to the LLM more than once. This ensures <a href="https://www.aiforswes.com/p/temperature-in-llms?utm_source=publication-search">an LLM&#8217;s output isn&#8217;t locked to a given input</a>.</p><p>These two concepts make LLMs intelligent.</p><p>To relate LLMs to general software engineering, we can think of an LLM as a &#8220;non-deterministic database&#8221;.</p><p>This makes it easier to understand the impact of the knowledge encoded in its weights via semantic understanding. I like to compare it to a SQL database and a query: <em>LLM is the database, and the prompt given to the LLM is the query that extracts the information in the format the user wants.</em></p><p>In AI engineering, it&#8217;s apt to think of an LLM as the central processing unit (CPU) of your application. By giving an LLM input information, it can make decisions on its own. Thus, the LLM becomes the CPU for your software, deciding what to do with the information provided.</p><p>This is also an apt comparison because choosing an LLM is like picking a CPU.</p><p>Each LLM has its own tradeoffs for latency, cost, functionality, and more. Choosing the right model (or models!) is important to meet the requirements of production software systems.</p><h2><strong>3 Context</strong></h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!-Elf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F195e9f44-5a2b-46e9-be38-fb9370a85ca1_1200x630.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!-Elf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F195e9f44-5a2b-46e9-be38-fb9370a85ca1_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!-Elf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F195e9f44-5a2b-46e9-be38-fb9370a85ca1_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!-Elf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F195e9f44-5a2b-46e9-be38-fb9370a85ca1_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!-Elf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F195e9f44-5a2b-46e9-be38-fb9370a85ca1_1200x630.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!-Elf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F195e9f44-5a2b-46e9-be38-fb9370a85ca1_1200x630.png" width="1200" height="630" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/195e9f44-5a2b-46e9-be38-fb9370a85ca1_1200x630.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:630,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:291234,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/192186526?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F195e9f44-5a2b-46e9-be38-fb9370a85ca1_1200x630.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_!-Elf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F195e9f44-5a2b-46e9-be38-fb9370a85ca1_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!-Elf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F195e9f44-5a2b-46e9-be38-fb9370a85ca1_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!-Elf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F195e9f44-5a2b-46e9-be38-fb9370a85ca1_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!-Elf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F195e9f44-5a2b-46e9-be38-fb9370a85ca1_1200x630.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><strong>Context</strong></em> is the information LLMs store in their memory and functions as the working memory for a task. For an LLM to perform a task or make a decision, it must have the relevant information in its context window<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-4" href="#footnote-4" target="_self">4</a>.</p><p>Context works by converting all input into <em><strong>tokens</strong></em>, which are small chunks of text (roughly 3-4 characters each) and feeding them into a model sequentially. The model uses an <em><strong>attention mechanism</strong></em> (a process that calculates how each token relates to every other token in the sequence) to determine which tokens are relevant to each other.</p><p>This is how LLMs &#8216;understand&#8217; the relationships within the input mentioned above.</p><p>The tokens currently part of a conversation with an LLM are considered part of that LLM&#8217;s &#8220;context window&#8221;. Each time you interact with an LLM, the model processes the entire context window from scratch. It doesn&#8217;t remember the previous turn unless you feed the entire conversation history back in.</p><p>Similar to RAM, an LLM&#8217;s context window is finite&#8230;</p><p>There is a hard limit to the number of tokens that can be stored in context at a time. Even before hitting that limit, LLMs tend to bias their knowledge toward the start and end of their context window. This means an LLM&#8217;s understanding of the information it is given can degrade before it reaches the hard limit.</p><p>The size of an LLM&#8217;s context window varies between models.</p><p>We&#8217;re at a point where frontier models can process 1 million or more tokens, whereas many open models are closer to 256,000 tokens. This isn&#8217;t enough for many applications, so it&#8217;s important to design AI systems with context limitations in mind.</p><p>Also, like RAM, an LLM&#8217;s context doesn&#8217;t persist between sessions.</p><p>LLMs will only remember the context provided during a session. This means AI systems with long-term memory require a more persistent memory storage and retrieval system.</p><p>Context is managed by only keeping the tokens a model needs for a task.</p><p>To effectively manage context, consider:</p><ul><li><p><strong>Using subagents for specific tasks</strong>. A separate agent means a separate context window. That agent can process and summarize the context, then return it to our primary agent.</p></li><li><p><strong>Summarizing all information currently within an LLM&#8217;s context window</strong>, clearing the context window, and adding the summary back in. This stores the same information in a shorter context.</p></li><li><p><strong>Using external systems to store information</strong>. Information is only needed in context when it&#8217;s being used. It should be stored in a separate, accessible datastore otherwise.</p></li></ul><p>Every AI application built with LLMs needs to properly manage context.</p><h2><strong>4 Embeddings and Vector Databases</strong></h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!2EKH!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b96b4e5-74fd-4de4-bbfb-4e26e996b3e2_1200x630.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!2EKH!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b96b4e5-74fd-4de4-bbfb-4e26e996b3e2_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!2EKH!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b96b4e5-74fd-4de4-bbfb-4e26e996b3e2_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!2EKH!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b96b4e5-74fd-4de4-bbfb-4e26e996b3e2_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!2EKH!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b96b4e5-74fd-4de4-bbfb-4e26e996b3e2_1200x630.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!2EKH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b96b4e5-74fd-4de4-bbfb-4e26e996b3e2_1200x630.png" width="1200" height="630" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7b96b4e5-74fd-4de4-bbfb-4e26e996b3e2_1200x630.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:630,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:201783,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/192186526?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b96b4e5-74fd-4de4-bbfb-4e26e996b3e2_1200x630.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_!2EKH!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b96b4e5-74fd-4de4-bbfb-4e26e996b3e2_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!2EKH!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b96b4e5-74fd-4de4-bbfb-4e26e996b3e2_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!2EKH!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b96b4e5-74fd-4de4-bbfb-4e26e996b3e2_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!2EKH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b96b4e5-74fd-4de4-bbfb-4e26e996b3e2_1200x630.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>You can&#8217;t fit everything into a model&#8217;s context window, so you need a way to find relevant information efficiently.</p><p>An <strong>embedding</strong> represents the meaning of data as a list of numbers, called a <strong>vector</strong>. An embedding can be created from text, audio, video, or any other data format to convey the meaning of that data. Items with similar embedding vectors are considered similar.</p><p>Consider a coordinate system in which each axis corresponds to a learned semantic dimension.</p><p><em>&#8220;Deploy a microservice&#8221;</em> and <em>&#8220;ship a container to production&#8221;</em> would be plotted close together. <em>&#8220;Deploy a microservice&#8221;</em> and <em>&#8220;quarterly revenue forecast&#8221;</em> would be far apart. Embeddings can do this across thousands of dimensions. Distance in this high-dimensional space equals similarity in meaning.</p><p>Vector databases<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-5" href="#footnote-5" target="_self">5</a> are built explicitly to store and query embeddings.</p><p>They use algorithms optimized for quickly finding the most similar vectors in the database. Those vectors are then added to a model&#8217;s context. This is comparable to retrieving data from a cache.</p><p>The process follows these steps:</p><ol><li><p><strong>Index</strong>: Convert documents into embeddings, store in a vector database</p></li><li><p><strong>Retrieve</strong>: Embed the query and find the most similar documents</p></li><li><p><strong>Augment</strong>: Pass those documents into the LLM&#8217;s context window with the user&#8217;s question</p></li><li><p><strong>Generate</strong>: LLM answers using retrieved information</p></li></ol><p>Almost every production AI engineering system will need a working memory solution.</p><p>Context will need to be augmented with a persistent data store. Embeddings and vector databases.</p><h2><strong>5 Time to First Token</strong></h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!g-Ix!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff332d3e0-2df1-49e0-99a5-7486eb6ac39a_1200x630.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!g-Ix!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff332d3e0-2df1-49e0-99a5-7486eb6ac39a_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!g-Ix!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff332d3e0-2df1-49e0-99a5-7486eb6ac39a_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!g-Ix!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff332d3e0-2df1-49e0-99a5-7486eb6ac39a_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!g-Ix!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff332d3e0-2df1-49e0-99a5-7486eb6ac39a_1200x630.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!g-Ix!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff332d3e0-2df1-49e0-99a5-7486eb6ac39a_1200x630.png" width="1200" height="630" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f332d3e0-2df1-49e0-99a5-7486eb6ac39a_1200x630.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:630,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:377887,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/192186526?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff332d3e0-2df1-49e0-99a5-7486eb6ac39a_1200x630.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_!g-Ix!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff332d3e0-2df1-49e0-99a5-7486eb6ac39a_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!g-Ix!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff332d3e0-2df1-49e0-99a5-7486eb6ac39a_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!g-Ix!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff332d3e0-2df1-49e0-99a5-7486eb6ac39a_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!g-Ix!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff332d3e0-2df1-49e0-99a5-7486eb6ac39a_1200x630.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>There are many factors to consider when choosing a specific LLM for your production AI system. One of these requirements is latency: <em>your system must function fast enough to be useful.</em></p><p>AI systems must consider the key latency metrics of traditional software systems and the LLM latency metrics, such as:</p><ul><li><p><strong>Time to First Token (TTFT)</strong>: How long until the model starts responding. This determines perceived responsiveness. Smaller models respond in under a second, but larger models can take several seconds to generate anything.</p></li><li><p><strong>Tokens Per Second (Throughput)</strong>: How fast the model generates after starting. This varies significantly across model sizes and compute units, and also affects how quickly the model's response is output to the user.</p></li></ul><p>AI applications require concurrency to stream the output of an LLM call and reduce perceived latency.</p><p><a href="https://www.aiforswes.com/p/mle-metrics?utm_source=publication-search">Latency is an incredibly important metric</a> to understand the real-world functionality of an AI system.</p><p>This is like streaming services, which play the start of a video while loading the rest in the background. This enables the viewer to watch the video before the entire video loads.</p><h2><strong>6 Evals</strong></h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!FYJN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F813834d8-5814-46f2-a8f0-215141afbd65_1200x630.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!FYJN!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F813834d8-5814-46f2-a8f0-215141afbd65_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!FYJN!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F813834d8-5814-46f2-a8f0-215141afbd65_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!FYJN!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F813834d8-5814-46f2-a8f0-215141afbd65_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!FYJN!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F813834d8-5814-46f2-a8f0-215141afbd65_1200x630.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!FYJN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F813834d8-5814-46f2-a8f0-215141afbd65_1200x630.png" width="1200" height="630" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/813834d8-5814-46f2-a8f0-215141afbd65_1200x630.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:630,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:184818,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/192186526?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F813834d8-5814-46f2-a8f0-215141afbd65_1200x630.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_!FYJN!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F813834d8-5814-46f2-a8f0-215141afbd65_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!FYJN!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F813834d8-5814-46f2-a8f0-215141afbd65_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!FYJN!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F813834d8-5814-46f2-a8f0-215141afbd65_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!FYJN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F813834d8-5814-46f2-a8f0-215141afbd65_1200x630.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><blockquote><p>&#8220;Evals are a new toolset for any and all AI engineers, and software engineers should also know about them. Move from guesswork to a systematic engineering process for improving AI quality.&#8221; - <a href="https://newsletter.pragmaticengineer.com/p/evals">Pragmatic Engineer, December 2025</a></p></blockquote><p>In traditional software, tests are written to ensure code function reliability.</p><p>In AI, traditional tests are <em>insufficient</em> for many parts of the system because of their non-deterministic nature. Instead, we write evaluations (evals for short).</p><p>Since assert statements won&#8217;t suffice for non-deterministic applications, evals are written using LLM-as-a-judge<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-6" href="#footnote-6" target="_self">6</a>.</p><p>Essentially, a dataset of inputs and their successful outputs is curated.</p><p>This dataset will be used to tell the judge what we&#8217;re looking for in our model's output. The LLM-as-a-judge will score how closely the tested model&#8217;s outputs resemble the successful output based on given criteria such as relevance, hallucinations, and accuracy.</p><p>For example, an eval can be used to assess whether an LLM effectively pulls the important information from a document when summarizing. A set of documents and summarization pairs is gathered as a solution set. The documents are run through the LLM we&#8217;re testing, and our LLM-as-a-judge compares the solution for that document to our LLM&#8217;s output.</p><p>Evals are vital because even the smallest changes in a non-deterministic system can change the user's output. The most common of these changes is model tweaks. Even a small tweak in model performance can drastically change the output of a system.</p><p>Evals are written to catch these changes.</p><h2><strong>7 Agent Loops</strong></h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!1TB1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6483a3aa-045c-4ea8-80d8-63753e903ecd_1200x630.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!1TB1!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6483a3aa-045c-4ea8-80d8-63753e903ecd_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!1TB1!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6483a3aa-045c-4ea8-80d8-63753e903ecd_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!1TB1!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6483a3aa-045c-4ea8-80d8-63753e903ecd_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!1TB1!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6483a3aa-045c-4ea8-80d8-63753e903ecd_1200x630.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!1TB1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6483a3aa-045c-4ea8-80d8-63753e903ecd_1200x630.png" width="1200" height="630" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6483a3aa-045c-4ea8-80d8-63753e903ecd_1200x630.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:630,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:357847,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/192186526?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6483a3aa-045c-4ea8-80d8-63753e903ecd_1200x630.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_!1TB1!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6483a3aa-045c-4ea8-80d8-63753e903ecd_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!1TB1!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6483a3aa-045c-4ea8-80d8-63753e903ecd_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!1TB1!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6483a3aa-045c-4ea8-80d8-63753e903ecd_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!1TB1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6483a3aa-045c-4ea8-80d8-63753e903ecd_1200x630.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>Agent loops<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-7" href="#footnote-7" target="_self">7</a> represent the shift from Software 2.0 to Software 3.0.</p><p>Software 1.0 to 2.0 was the change from logical control flow to probabilistic output. In the shift to Software 3.0, we see probabilistic output used as reasoning loops in an agentic system<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-8" href="#footnote-8" target="_self">8</a>.</p><p>Agent loops enable an LLM to continuously receive and act on information. An agent loop looks something like:</p><ol><li><p><strong>Thought</strong>: Model reasons about the current state and what it needs to do next</p></li><li><p><strong>Action</strong>: The model decides to call a tool</p></li><li><p><strong>Observation</strong>: Application executes the tool and returns the result</p></li><li><p><strong>Repeat</strong>: Model then reasons about the observation, takes another action, or provides a final answer</p></li></ol><p>This is the <a href="https://arxiv.org/abs/2210.03629">ReAct pattern</a> (Reason + Act), and it has become the default agent loop architecture.</p><p>ReAct merges Chain of Thought reasoning, where the model works through a problem step by step, with tool execution into a single loop. This means a model can not only reason to act, but also take its previous actions and their outputs into account, continuously acting until a task is complete.</p><p>For example, consider an AI travel agent tasked with booking a trip within a budget.</p><p>It first searches for flights and finds the cheapest option. It then reasons about how much budget remains and searches for hotels accordingly. The initial results are all outside the city center, so it adjusts its search criteria and finds a better option. It calculates the total, confirms it fits the budget, and presents the full itinerary.</p><p>An agent loop relies on the LLM to determine the next step continuously until it completes a task. This looping process enables an LLM to use its knowledge and context to do meaningful work.</p><p>This enables complex workflows that aren&#8217;t possible with written code alone.</p><h2><strong>8 Tool Calling</strong></h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!SU62!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17803a9f-946d-4559-ac7a-e91ed81babf3_1200x630.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!SU62!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17803a9f-946d-4559-ac7a-e91ed81babf3_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!SU62!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17803a9f-946d-4559-ac7a-e91ed81babf3_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!SU62!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17803a9f-946d-4559-ac7a-e91ed81babf3_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!SU62!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17803a9f-946d-4559-ac7a-e91ed81babf3_1200x630.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!SU62!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17803a9f-946d-4559-ac7a-e91ed81babf3_1200x630.png" width="1200" height="630" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/17803a9f-946d-4559-ac7a-e91ed81babf3_1200x630.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:630,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:185870,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/192186526?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17803a9f-946d-4559-ac7a-e91ed81babf3_1200x630.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_!SU62!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17803a9f-946d-4559-ac7a-e91ed81babf3_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!SU62!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17803a9f-946d-4559-ac7a-e91ed81babf3_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!SU62!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17803a9f-946d-4559-ac7a-e91ed81babf3_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!SU62!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17803a9f-946d-4559-ac7a-e91ed81babf3_1200x630.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>Meaningful work is further enabled by tool calling<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-9" href="#footnote-9" target="_self">9</a> capabilities.</p><p>This gives the LLM the ability to <em>do something</em> as part of its action. While LLMs can always output natural language, tool calling enables that output to call functions that perform work.</p><p>LLMs cannot execute code, access the internet, or perform other work natively. Instead, tool calling must be enabled:</p>
      <p>
          <a href="https://newsletter.systemdesign.one/p/ai-concepts">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Everything You Need to Know to Design GenAI Systems From Scratch]]></title><description><![CDATA[#137: Part 1 - Generative AI Masterclass]]></description><link>https://newsletter.systemdesign.one/p/generative-ai-system-design</link><guid isPermaLink="false">https://newsletter.systemdesign.one/p/generative-ai-system-design</guid><dc:creator><![CDATA[Louis-François Bouchard]]></dc:creator><pubDate>Tue, 07 Apr 2026 12:33:42 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/863a9f29-e5d1-4565-8f9e-6b3a355991ef_1280x720.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://newsletter.systemdesign.one/subscribe?yearly=true" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!RKN7!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3689f342-2008-4ce6-b968-16461682508b_1280x300.png 424w, https://substackcdn.com/image/fetch/$s_!RKN7!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3689f342-2008-4ce6-b968-16461682508b_1280x300.png 848w, https://substackcdn.com/image/fetch/$s_!RKN7!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3689f342-2008-4ce6-b968-16461682508b_1280x300.png 1272w, https://substackcdn.com/image/fetch/$s_!RKN7!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3689f342-2008-4ce6-b968-16461682508b_1280x300.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!RKN7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3689f342-2008-4ce6-b968-16461682508b_1280x300.png" width="1280" height="300" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3689f342-2008-4ce6-b968-16461682508b_1280x300.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:300,&quot;width&quot;:1280,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:24224,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:&quot;https://newsletter.systemdesign.one/subscribe?yearly=true&quot;,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/192435842?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3689f342-2008-4ce6-b968-16461682508b_1280x300.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_!RKN7!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3689f342-2008-4ce6-b968-16461682508b_1280x300.png 424w, https://substackcdn.com/image/fetch/$s_!RKN7!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3689f342-2008-4ce6-b968-16461682508b_1280x300.png 848w, https://substackcdn.com/image/fetch/$s_!RKN7!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3689f342-2008-4ce6-b968-16461682508b_1280x300.png 1272w, https://substackcdn.com/image/fetch/$s_!RKN7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3689f342-2008-4ce6-b968-16461682508b_1280x300.png 1456w" sizes="100vw" fetchpriority="high"></picture><div></div></div></a></figure></div><ul><li><p><em><a href="https://newsletter.systemdesign.one/p/generative-ai-system-design/?action=share">Share this post</a> &amp; I'll send you some rewards for the referrals.</em></p></li></ul><p>I have a big big announcement for those of you who want to become good at AI engineering.</p><p>INTRODUCING:<strong> GENERATIVE AI MASTERCLASS</strong></p><p>This is a <em><strong>monthly newsletter series</strong></em> that&#8217;ll teach you Generative AI system design.</p><p>By the end of this newsletter series, you&#8217;ll walk away with:</p><ul><li><p><strong>Simple breakdown of real-world architectures</strong></p></li><li><p>Frameworks you can plug into your work or business</p></li><li><p><strong>Proven systems behind ChatGPT, Perplexity, and Copilot</strong></p></li></ul><p><em>And here&#8217;s the best part:</em></p><p>You&#8217;ll go from knowing how to &#8220;use AI&#8221; to understanding how to design, build, and ship AI.</p><p>No AI/ML background needed. Each newsletter explains concepts in plain English, with visuals and real product examples.</p><p>If you want the maximum AI career leverage, join below:</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/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://newsletter.systemdesign.one/subscribe?"><span>Subscribe now</span></a></p><div><hr></div><h3><a href="https://agentfield.ai/blog/posts/beyond-vibe-coding/?utm_source=sys_design&amp;utm_medium=newsletter&amp;utm_campaign=sys_design-060407&amp;utm_id=sys_design-060407-blog-bvc-cta&amp;utm_content=blog-bvc-cta">New Open Source: Build and Scale Agents and Harnesses Like APIs (Partner)</a></h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://agentfield.ai/blog/posts/beyond-vibe-coding/?utm_source=sys_design&amp;utm_medium=newsletter&amp;utm_campaign=sys_design-060407&amp;utm_id=sys_design-060407-blog-bvc-cta&amp;utm_content=blog-bvc-cta" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!_ibW!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47cf900f-e29b-4ef8-965f-17c733bcd2d3_1920x1920.webp 424w, https://substackcdn.com/image/fetch/$s_!_ibW!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47cf900f-e29b-4ef8-965f-17c733bcd2d3_1920x1920.webp 848w, https://substackcdn.com/image/fetch/$s_!_ibW!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47cf900f-e29b-4ef8-965f-17c733bcd2d3_1920x1920.webp 1272w, https://substackcdn.com/image/fetch/$s_!_ibW!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47cf900f-e29b-4ef8-965f-17c733bcd2d3_1920x1920.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!_ibW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47cf900f-e29b-4ef8-965f-17c733bcd2d3_1920x1920.webp" width="1456" height="1456" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/47cf900f-e29b-4ef8-965f-17c733bcd2d3_1920x1920.webp&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;:186332,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/webp&quot;,&quot;href&quot;:&quot;https://agentfield.ai/blog/posts/beyond-vibe-coding/?utm_source=sys_design&amp;utm_medium=newsletter&amp;utm_campaign=sys_design-060407&amp;utm_id=sys_design-060407-blog-bvc-cta&amp;utm_content=blog-bvc-cta&quot;,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/179236490?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47cf900f-e29b-4ef8-965f-17c733bcd2d3_1920x1920.webp&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!_ibW!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47cf900f-e29b-4ef8-965f-17c733bcd2d3_1920x1920.webp 424w, https://substackcdn.com/image/fetch/$s_!_ibW!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47cf900f-e29b-4ef8-965f-17c733bcd2d3_1920x1920.webp 848w, https://substackcdn.com/image/fetch/$s_!_ibW!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47cf900f-e29b-4ef8-965f-17c733bcd2d3_1920x1920.webp 1272w, https://substackcdn.com/image/fetch/$s_!_ibW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47cf900f-e29b-4ef8-965f-17c733bcd2d3_1920x1920.webp 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><code>One.harness()</code> call and orchestrate hundreds of Claude Code, Codex, and Gemini instances into a coordinated team. They discover each other at runtime, split work, cross-reference results, and converge autonomously. Go deeper on harness engineering &#8594; <a href="https://agentfield.ai/blog/posts/beyond-vibe-coding/?utm_source=sys_design&amp;utm_medium=newsletter&amp;utm_campaign=sys_design-060407&amp;utm_id=sys_design-060407-blog-bvc-cta&amp;utm_content=blog-bvc-cta">blog</a>.</p><p>No DAGs. No glue code. Agents work like APIs, Python, TypeScript &amp; Go.</p><p>We built production systems you can clone and run today:</p><p>&#8594; <a href="https://agentfield.ai/github/swe-af/?utm_source=github-readme&amp;utm_campaign=github-readme&amp;utm_id=github-readme-swe-af-repo">Autonomous Engineering Team</a>: 175 agents ship code end-to-end</p><p>&#8594; <a href="https://agentfield.ai/github/cloudsecurity/?utm_source=github-readme&amp;utm_campaign=github-readme&amp;utm_id=github-readme-cloudsec-repo">Deep Security Auditor</a>: 250 agents scan every CVE</p><p>&#8594; <a href="https://agentfield.ai/github/sec-af/?utm_source=github-readme&amp;utm_campaign=github-readme&amp;utm_id=github-readme-sec-af-repo">Adversarial Code Reviewer</a>: 50+ agents debate your PRs</p><p>Each runs on any model. Apache 2.0.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://agentfield.ai/github/?utm_source=sys_design&amp;utm_medium=newsletter&amp;utm_campaign=sys_design-060407&amp;utm_id=sys_design-060407-github-cta&amp;utm_content=github-cta&quot;,&quot;text&quot;:&quot;Clone a Recipe&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://agentfield.ai/github/?utm_source=sys_design&amp;utm_medium=newsletter&amp;utm_campaign=sys_design-060407&amp;utm_id=sys_design-060407-github-cta&amp;utm_content=github-cta"><span>Clone a Recipe</span></a></p><div><hr></div><p>We&#8217;ve all used ChatGPT.</p><p>From our user perspective, it looks simple: <em>type a question, get a response</em>. But there&#8217;s a lot more behind it than a large language model (LLM) with a chat interface.</p><p>Building a product like ChatGPT means choosing the right model from a growing landscape of options, preparing the data that trains it, running a multi-stage training pipeline, evaluating whether the outputs are actually good, adding safety controls to prevent harm, and wrapping it all in serving infrastructure that can handle millions of requests. The same is true for Perplexity, GitHub Copilot, and Midjourney.</p><p>The model is one piece of a much larger system.</p><p>Understanding these components is what separates someone who can use GenAI from someone who can design and build it. That&#8217;s what this newsletter series is for.</p><p>This first newsletter covers the foundation.</p><p>We walk through the model landscape, the data layer, the training pipeline, evaluation, safety, and the engineering that turns a model into a product.</p><p>Let&#8217;s start with a glossary of key terms that come up throughout this newsletter and the rest of the series. If you&#8217;re already comfortable with terms like tokens, embeddings, and context windows, skip ahead to <em>Part 1: The AI Model Landscape.</em></p><div><hr></div><p>I want to introduce <a href="https://louisbouchard.substack.com/">Louis-Fran&#231;ois Bouchard</a> as the author of this newsletter.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://louisbouchard.substack.com/" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!8ezx!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2bbacb1f-03da-4781-9a5e-b720e4af2e34_1100x220.png 424w, https://substackcdn.com/image/fetch/$s_!8ezx!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2bbacb1f-03da-4781-9a5e-b720e4af2e34_1100x220.png 848w, https://substackcdn.com/image/fetch/$s_!8ezx!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2bbacb1f-03da-4781-9a5e-b720e4af2e34_1100x220.png 1272w, https://substackcdn.com/image/fetch/$s_!8ezx!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2bbacb1f-03da-4781-9a5e-b720e4af2e34_1100x220.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!8ezx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2bbacb1f-03da-4781-9a5e-b720e4af2e34_1100x220.png" width="1100" height="220" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2bbacb1f-03da-4781-9a5e-b720e4af2e34_1100x220.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:220,&quot;width&quot;:1100,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:&quot;https://louisbouchard.substack.com/&quot;,&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_!8ezx!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2bbacb1f-03da-4781-9a5e-b720e4af2e34_1100x220.png 424w, https://substackcdn.com/image/fetch/$s_!8ezx!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2bbacb1f-03da-4781-9a5e-b720e4af2e34_1100x220.png 848w, https://substackcdn.com/image/fetch/$s_!8ezx!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2bbacb1f-03da-4781-9a5e-b720e4af2e34_1100x220.png 1272w, https://substackcdn.com/image/fetch/$s_!8ezx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2bbacb1f-03da-4781-9a5e-b720e4af2e34_1100x220.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>He&#8217;s a best-selling author (<a href="https://amzn.to/4bqYU9b">Building LLMs for Production</a>), the co-founder of <a href="https://academy.towardsai.net/?ref=1f9b29">Towards AI</a>, and the creator of the YouTube Channel, <a href="https://www.youtube.com/@whatsai?sub_confirmation=1">What&#8217;s AI</a>, where he helps people understand AI and learn how to apply it in the real world. Through his development works with clients and his content, teaching, and AI training programs on the <a href="https://academy.towardsai.net/?ref=1f9b29">Towards AI Academy</a>, Louis focuses on making AI practical for builders, engineers, and curious learners alike.</p><p>At Towards AI, he and his team train AI engineers through courses built for every stage, from beginner to advanced. That educational mission and the real-world experience building for his clients are exactly why I wanted him in this newsletter series.</p><div><hr></div><h2><strong>Key Terms</strong></h2><p>You don&#8217;t need to learn these upfront.</p><p>Skim to get familiar, then refer back whenever you hit an unfamiliar term:</p><p><strong>Token</strong>: LLMs work with numbers, not words. Before processing any text, the model breaks it into small chunks, called tokens. A token can be a whole word (&#8220;the&#8221;), part of a word (&#8220;un&#8221;, &#8220;believ&#8221;, &#8220;able&#8221;), or punctuation. One token is roughly &#8776; 4 English characters, though this varies by language and model. API pricing, context limits, and cost are all measured in tokens.</p><p><strong>Embedding</strong>: A token ID alone (like 1023 for &#8220;What&#8221;) tells the model nothing about meaning. An embedding replaces that ID with a list of numbers (a vector) that captures what the word means and how it relates to other words. These vectors are what the model actually works with internally, processing and transforming them at every step to build up an understanding of the full input. Words with similar meaning end up with similar vectors: &#8220;king&#8221; and &#8220;queen&#8221; are close together, &#8220;king&#8221; and &#8220;banana&#8221; are far apart. This same property also powers search in GenAI products: when a user asks <em>&#8220;How do I reset my password?&#8221;</em>, the system can find documents on password resets, account recovery, and login issues, even if those documents never use that exact phrase.</p><p><strong>Parameter</strong>: These are internal variables inside a model, billions of them. At the start of training, they&#8217;re random. Each time the model makes an incorrect prediction, settings are nudged slightly. After trillions of such adjustments, they encode language patterns. GPT-3 had 175B parameters. Llama 4 comes in Scout (17B active) and Maverick (17B active). More parameters mean more capability, but also more memory: a large model can need 140GB or more just to load.</p><p><strong>Context Window</strong>: The maximum amount of text (in tokens) a model can see in one request. GPT-5 supports up to 400K tokens (272K input). Claude and Gemini support up to 1M tokens. Everything the model needs, system instructions, conversation history, retrieved documents, and the user&#8217;s question must fit within this window. Deciding what goes in and what gets cut is called <em>context engineering</em>.</p><p><strong>Inference</strong>: Every time someone sends a message to ChatGPT, the model runs to produce a response. That&#8217;s one inference call. At scale, this can mean millions of calls per day, and the cost adds up. Two key metrics define inference performance: <em>Time to First Token (<strong>TTFT</strong>)</em>, the time the user waits before the first word appears, and <em>Tokens per Second (<strong>TPS</strong>)</em>, the rate at which the rest of the response streams in after that.</p><p><strong>LLM (Large Language Model)</strong>: A neural network (a program that learns patterns from data) trained on one objective: to predict the next token. GPT, Claude, Llama, and Gemini are all LLMs. The objective is simple, but at a massive scale (trillions of tokens of training data), it produces the ability to follow instructions, write code, reason through problems, and hold conversations.</p><p><strong>Foundation Model</strong>: A large, general-purpose model trained on massive data that serves as the starting point for products. Both LLMs (GPT-5, Claude) and diffusion models (Stable Diffusion, Midjourney) are foundation models. These aren&#8217;t built from scratch for each product. You take one and adapt it through prompting, fine-tuning, or both.</p><p><strong>RAG (Retrieval-Augmented Generation)</strong>: A design approach where the system retrieves relevant documents at query time and includes them in the prompt, so the answer is grounded in real sources rather than what the model memorized during training. Products like Perplexity use this approach: search the web, feed the results to the model, and generate an answer with citations. It&#8217;s widely used in products that need up-to-date or domain-specific knowledge.</p><p><strong>Fine-tuning</strong>: Taking a foundation model and training it further on a smaller, task-specific dataset to specialize its behavior. For example, a model fine-tuned on customer support conversations learns the right tone, format, and escalation patterns for that domain. Fine-tuning changes <em>how</em> the model responds (style, format, tone), not <em>what</em> it knows. If the model needs to answer questions using knowledge not in its training data, retrieval-augmented generation (RAG) is the standard approach.</p><p><strong>Prompt</strong>: The full text input sent to a model for each request is a prompt. It typically includes a <em>system prompt</em> (developer-defined instructions that define the model&#8217;s role), the <em>conversation history</em> (previous messages), and the <em>user message</em> (the current question). In RAG systems, retrieved documents are also included. <em>Prompt engineering</em> is the practice of refining how this input is structured to get better results.</p><p><strong>Hallucination</strong>: When a model generates confident but factually wrong output, like citing a paper that doesn&#8217;t exist or inventing a URL. This isn&#8217;t a bug. These models are optimized to produce text that sounds plausible rather than factually correct, so hallucinations are a built-in trade-off, not a malfunction. The main ways to reduce hallucinations are <em>RAG</em> (retrieving real sources to ground the answer) and <em>evaluation</em> (testing the model&#8217;s outputs for accuracy).</p><p><strong>Transformer</strong>: The neural network architecture behind nearly all modern foundation models, introduced in 2017 (&#8220;Attention Is All You Need&#8221;). Its key innovation is the <em>attention mechanism</em>: instead of processing tokens sequentially, the model considers all tokens simultaneously and learns which are relevant to one another. In &#8220;The cat sat on the mat because it was tired,&#8221; attention connects &#8220;it&#8221; back to &#8220;cat&#8221; rather than &#8220;mat.&#8221; Some models extend this architecture with a <em>Mixture of Experts (<strong>MoE</strong>)</em>, where only a subset of the model&#8217;s parameters is used for each input rather than all of them, making the model faster and cheaper to run while maintaining high overall capability.</p><p><strong>GPU/TPU</strong>: The specialized hardware on which GenAI runs. <strong>GPUs</strong> (NVIDIA H100, A100, B200) handle the massive number of calculations required by models. A request that takes milliseconds on a GPU could take orders of magnitude longer on a regular CPU. Training a large model needs thousands of GPUs running for months. <strong>TPUs</strong> are Google&#8217;s custom chips for ML, used primarily within Google Cloud.</p><p><strong>Latency</strong>: How long the user waits for a response. Different products have different targets depending on what the user is doing. Autocomplete has to keep up with typing, so it typically needs a response in under 300ms. Chat users expect a short pause before the reply starts streaming. Image and video generation is much slower; users wait 10 to 60 seconds. These targets influence which model to use, whether to add caching, and how much the system can do before it starts to feel slow.</p><p>The first decision in designing any GenAI system is choosing the right model&#8230;</p><p>That starts with understanding what kinds of models exist and what each one is good at.</p><div><hr></div><h2><strong>Part 1: The AI Model Landscape</strong></h2><p>Not all generative models work the same way.</p><p>They differ in how they generate output, what kinds of output they produce, and how they&#8217;re built. This section breaks down the two core architectures, types of outputs they support, the internal structure of models, and how to choose between them.</p><h3><strong>Two Families of Generative Models</strong></h3><p>All generative AI models are built on one of two architectures:</p><p><strong>1 Autoregressive models</strong> generate text one token at a time.</p><p>Given the input &#8220;The capital of France is&#8221;, the model predicts the most likely next token: &#8220;Paris&#8221; in this case. It appends &#8220;Paris&#8221; to the sequence, and now uses &#8220;The capital of France is Paris&#8221; to predict the next token, i.e., &#8220;.&#8221; Then it uses the full sequence to predict the token, and so on. Each output feeds back as input. This is how GPT, Claude, Gemini, and Llama models work.</p><p>When you see a chatbot &#8220;typing&#8221; its response word by word, that&#8217;s not a UI animation; the model is actually producing tokens one after another.</p><p>Because generation is sequential, latency scales with output length: <em>a 500-token response takes roughly 500 generation steps</em>. Cost scales, too: <em>a 1,000-token response costs roughly 10x as much as a 100-token response</em>.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!LNuG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ea33f71-994a-449b-becd-7e5f6f110635_1600x180.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!LNuG!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ea33f71-994a-449b-becd-7e5f6f110635_1600x180.png 424w, https://substackcdn.com/image/fetch/$s_!LNuG!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ea33f71-994a-449b-becd-7e5f6f110635_1600x180.png 848w, https://substackcdn.com/image/fetch/$s_!LNuG!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ea33f71-994a-449b-becd-7e5f6f110635_1600x180.png 1272w, https://substackcdn.com/image/fetch/$s_!LNuG!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ea33f71-994a-449b-becd-7e5f6f110635_1600x180.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!LNuG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ea33f71-994a-449b-becd-7e5f6f110635_1600x180.png" width="1456" height="164" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4ea33f71-994a-449b-becd-7e5f6f110635_1600x180.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:164,&quot;width&quot;:1456,&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_!LNuG!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ea33f71-994a-449b-becd-7e5f6f110635_1600x180.png 424w, https://substackcdn.com/image/fetch/$s_!LNuG!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ea33f71-994a-449b-becd-7e5f6f110635_1600x180.png 848w, https://substackcdn.com/image/fetch/$s_!LNuG!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ea33f71-994a-449b-becd-7e5f6f110635_1600x180.png 1272w, https://substackcdn.com/image/fetch/$s_!LNuG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ea33f71-994a-449b-becd-7e5f6f110635_1600x180.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p style="text-align: center;"><em>Autoregressive generation: each token is produced one at a time, left to right.</em></p><p><strong>2 Diffusion models</strong> work completely differently.</p><p>Instead of producing one piece at a time, they start with pure random noise and gradually remove it over many steps until a coherent image (or video) emerges.</p><p>During training, the model sees millions of images with noise added at various levels and learns to predict what the clean version looks like. At generation time, it reverses the process step by step, typically 20 to 50 steps, removing a little noise each time until a clear image forms.</p><p>This is how Midjourney, Stable Diffusion, DALL-E, and Sora work.</p><p>The serving model is very different from text: image generation can take roughly 10 to 60 seconds, and video can take minutes, so products typically run generation as batch jobs with a queue rather than streaming.</p><p>A single image generation also costs roughly 10-100x as much compute as a typical ChatGPT response.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!NtsK!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F093fded3-ee7e-4917-871d-8803c37ae54c_1600x383.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!NtsK!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F093fded3-ee7e-4917-871d-8803c37ae54c_1600x383.png 424w, https://substackcdn.com/image/fetch/$s_!NtsK!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F093fded3-ee7e-4917-871d-8803c37ae54c_1600x383.png 848w, https://substackcdn.com/image/fetch/$s_!NtsK!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F093fded3-ee7e-4917-871d-8803c37ae54c_1600x383.png 1272w, https://substackcdn.com/image/fetch/$s_!NtsK!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F093fded3-ee7e-4917-871d-8803c37ae54c_1600x383.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!NtsK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F093fded3-ee7e-4917-871d-8803c37ae54c_1600x383.png" width="1456" height="349" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/093fded3-ee7e-4917-871d-8803c37ae54c_1600x383.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:349,&quot;width&quot;:1456,&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_!NtsK!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F093fded3-ee7e-4917-871d-8803c37ae54c_1600x383.png 424w, https://substackcdn.com/image/fetch/$s_!NtsK!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F093fded3-ee7e-4917-871d-8803c37ae54c_1600x383.png 848w, https://substackcdn.com/image/fetch/$s_!NtsK!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F093fded3-ee7e-4917-871d-8803c37ae54c_1600x383.png 1272w, https://substackcdn.com/image/fetch/$s_!NtsK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F093fded3-ee7e-4917-871d-8803c37ae54c_1600x383.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption"><em>Diffusion models iteratively denoise random noise into a coherent image.</em></figcaption></figure></div><h3><strong>Models Outputs</strong></h3><p>These two architectures cover a range of output types:</p><p><strong>1 Text generation</strong> (autoregressive): chat responses, code, summaries, translations, structured data extraction. This powers ChatGPT, Claude, GitHub Copilot, Perplexity.</p><p><strong>2 Text-to-image</strong> (diffusion): generate images from text prompts. Midjourney, DALL-E 3, Stable Diffusion.</p><p><strong>3 Text-to-video</strong> (diffusion): generate video clips from text or image prompts. Sora, Runway Gen-3, Kling.</p><p><strong>4 Text-to-audio</strong> (autoregressive + diffusion): generate speech, music, and sound effects. ElevenLabs, Suno, Bark.</p><p><strong>5 Vision-language models</strong> (autoregressive) process images alongside text. Upload a photo and ask the model to describe it, extract data from a receipt, or analyze a chart. GPT-5, Claude, and Gemini all support this.</p><h3><strong>Multimodality</strong></h3><p>Each of the output types above used to require its own dedicated model.</p><p>That&#8217;s changing; models like GPT-5 and Gemini now handle text, images, audio, and video within a single architecture. The question is how. How does a text prompt like <em>&#8220;a photo of a cat&#8221;</em> actually guide an image model to generate the right image?</p><p>Through <strong>cross-modal embeddings</strong>.</p><p>An embedding converts content into a list of numbers that captures its meaning. Cross-modal embeddings do this across different content types, text and images, placing them on the same map.</p><p><em>CLIP</em>, developed by OpenAI, is the most well-known example. It places both <em>&#8220;a photo of a cat&#8221;</em> (text) and an actual cat photo (image) side by side on this shared map. That shared representation enables a text description to guide image generation.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ZFpI!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa119134b-5712-46cb-992c-53942e0eab5f_1560x1074.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ZFpI!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa119134b-5712-46cb-992c-53942e0eab5f_1560x1074.png 424w, https://substackcdn.com/image/fetch/$s_!ZFpI!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa119134b-5712-46cb-992c-53942e0eab5f_1560x1074.png 848w, https://substackcdn.com/image/fetch/$s_!ZFpI!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa119134b-5712-46cb-992c-53942e0eab5f_1560x1074.png 1272w, https://substackcdn.com/image/fetch/$s_!ZFpI!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa119134b-5712-46cb-992c-53942e0eab5f_1560x1074.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ZFpI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa119134b-5712-46cb-992c-53942e0eab5f_1560x1074.png" width="1456" height="1002" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a119134b-5712-46cb-992c-53942e0eab5f_1560x1074.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1002,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;: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_!ZFpI!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa119134b-5712-46cb-992c-53942e0eab5f_1560x1074.png 424w, https://substackcdn.com/image/fetch/$s_!ZFpI!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa119134b-5712-46cb-992c-53942e0eab5f_1560x1074.png 848w, https://substackcdn.com/image/fetch/$s_!ZFpI!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa119134b-5712-46cb-992c-53942e0eab5f_1560x1074.png 1272w, https://substackcdn.com/image/fetch/$s_!ZFpI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa119134b-5712-46cb-992c-53942e0eab5f_1560x1074.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"><em>Text and images mapped to the same vector space. Similar content lands nearby.</em></figcaption></figure></div><h3><strong>Model Architecture Variants</strong></h3><p>Not all foundation models are built the same way&#8230;</p><p>Most are based on the Transformer (covered in the glossary above), but they use it differently. The two main jobs of a language model are understanding input and generating output.</p><p>Different architectures handle these jobs in different ways:</p><p><strong>1 Decoder-only</strong> models focus entirely on generation: they take an input and produce text left-to-right, one token at a time. GPT, Claude, Llama, and Gemini are all decoder-only. This is the dominant architecture for text generation today.</p><p><strong>2 Encoder-only</strong> models (like BERT, an early Transformer&#8209;based language model) focus entirely on understanding: they read input and produce a numerical representation of its meaning, but don&#8217;t generate new text. Used for classification, sentiment analysis, and search ranking. For example, when a support system reads <em>&#8220;I&#8217;m furious about my broken order&#8221;</em> and classifies it as &#8220;negative sentiment, high urgency&#8221;, that&#8217;s an encoder-only model at work. In GenAI products, they play supporting roles, such as classifying user intent or detecting toxicity.</p><p><strong>3 Encoder-decoder</strong> models (like Google&#8217;s T5 and Meta&#8217;s BART) do both: one part reads and understands the input, the other generates the output. Suited for translation, summarization, and rewriting.</p><p><strong>4 Mixture of Experts (MoE)</strong> is a different kind of optimization.</p><p>Instead of a single large model where every parameter is used for every input, MoE splits the model into multiple specialized groups, called &#8220;experts.&#8221; For each input, a router determines which experts are relevant and activates only those. A question about Python code might activate code-specialized experts, while a question about French history might activate different experts. Models like Mistral&#8217;s Mixtral 8x7B use this approach, with 46.7 billion total parameters but only around 12.9 billion active per token. You get more capability per unit of compute, but you need more GPU memory to store all the experts.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!2Gh9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f7ce967-d17b-4670-80d8-7b92b5014fbe_1600x308.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!2Gh9!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f7ce967-d17b-4670-80d8-7b92b5014fbe_1600x308.png 424w, https://substackcdn.com/image/fetch/$s_!2Gh9!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f7ce967-d17b-4670-80d8-7b92b5014fbe_1600x308.png 848w, https://substackcdn.com/image/fetch/$s_!2Gh9!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f7ce967-d17b-4670-80d8-7b92b5014fbe_1600x308.png 1272w, https://substackcdn.com/image/fetch/$s_!2Gh9!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f7ce967-d17b-4670-80d8-7b92b5014fbe_1600x308.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!2Gh9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f7ce967-d17b-4670-80d8-7b92b5014fbe_1600x308.png" width="1456" height="280" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6f7ce967-d17b-4670-80d8-7b92b5014fbe_1600x308.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:280,&quot;width&quot;:1456,&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_!2Gh9!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f7ce967-d17b-4670-80d8-7b92b5014fbe_1600x308.png 424w, https://substackcdn.com/image/fetch/$s_!2Gh9!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f7ce967-d17b-4670-80d8-7b92b5014fbe_1600x308.png 848w, https://substackcdn.com/image/fetch/$s_!2Gh9!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f7ce967-d17b-4670-80d8-7b92b5014fbe_1600x308.png 1272w, https://substackcdn.com/image/fetch/$s_!2Gh9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f7ce967-d17b-4670-80d8-7b92b5014fbe_1600x308.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption"><em>Most modern GenAI products use decoder-only or MoE architectures.</em></figcaption></figure></div><h3><strong>The Model Landscape: Proprietary, Open-Weight, and Open-Source</strong></h3><p>When choosing a model, there are three categories with different trade-offs:</p><p><strong>1 Proprietary models</strong> (GPT, Claude, Gemini) are accessed via API. They offer the highest capability and are the easiest to start with, but give users the least control. You can&#8217;t see the model&#8217;s internal parameters, modify its architecture, or run it on your own servers.</p><p><strong>2 Open-weight models</strong> (Llama, Mistral, Gemma) release their trained parameters publicly. You can download them, run them on your own GPUs, and fine-tune them. Training data and methods are typically not shared. This gives you full control over the model, but it also means you have to manage the infrastructure yourself.</p><p><strong>3 Open-source models</strong> go further by sharing not just weights but training code, data, and the full methodology behind how the model was built.</p><p>The gap between proprietary and open-source is narrowing&#8230;</p><p>By early 2025, models like Llama 4 Maverick and DeepSeek-V3 were competitive with proprietary models on many tasks. Most production systems use a mix: a proprietary model for complex tasks and an open-weight model for high-volume, simple ones.</p><h3><strong>Model Selection</strong></h3><p>Each model family offers a range of sizes (e.g., GPT-5 vs. GPT-5 mini, Claude Opus vs. Haiku, Llama 4 Maverick vs Scout).</p><p>Smaller models are faster and cheaper, but less capable. Beyond size, some models offer specialized variants. OpenAI&#8217;s GPT-5, for example, includes configurable reasoning effort, and Claude offers an extended thinking mode. These reasoning capabilities require more compute during inference to work through problems step by step, breaking complex questions into smaller parts before answering. This improves accuracy on tasks such as math, logic, and multi-step analysis, but it costs more per request and takes longer to respond.</p><p>This trade-off is another reason model routing matters: route simple questions to a faster model, and complex reasoning tasks to a model with these capabilities.</p><p>Public benchmarks help narrow down which specific model is best suited to a task. MMLU tests general knowledge across 57 subjects; HumanEval and MBPP focus on code generation; Chatbot Arena by LMSYS aggregates human preference scores from real conversations; and benchmarks like GPQA and ARC-AGI evaluate reasoning and problem-solving abilities.</p><p>But benchmarks have a well-known problem: contamination.</p><p>Models can be trained on benchmark test data, inflating scores. It&#8217;s like a student who memorized the answers to last year&#8217;s exam; they score high, but can&#8217;t solve newer problems. A model that tops MMLU may underperform on a specific task. Benchmarks are useful for narrowing the field, but final selection requires evaluating on your own data.</p><p>That covers the model landscape, what models exist, how they differ, and how to pick between them. All of these models, though, start with random parameters. What turns them into something useful is data.</p><div><hr></div><p><em><strong>Reminder: this is a teaser of the subscriber-only newsletter series, exclusive to my golden members.</strong></em></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://newsletter.systemdesign.one/subscribe?yearly=true" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!3mfm!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0002d397-a8f7-4519-a51c-f020e29ce8b3_1280x300.png 424w, https://substackcdn.com/image/fetch/$s_!3mfm!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0002d397-a8f7-4519-a51c-f020e29ce8b3_1280x300.png 848w, https://substackcdn.com/image/fetch/$s_!3mfm!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0002d397-a8f7-4519-a51c-f020e29ce8b3_1280x300.png 1272w, https://substackcdn.com/image/fetch/$s_!3mfm!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0002d397-a8f7-4519-a51c-f020e29ce8b3_1280x300.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!3mfm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0002d397-a8f7-4519-a51c-f020e29ce8b3_1280x300.png" width="1280" height="300" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0002d397-a8f7-4519-a51c-f020e29ce8b3_1280x300.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:300,&quot;width&quot;:1280,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:24224,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:&quot;https://newsletter.systemdesign.one/subscribe?yearly=true&quot;,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/192435842?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0002d397-a8f7-4519-a51c-f020e29ce8b3_1280x300.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_!3mfm!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0002d397-a8f7-4519-a51c-f020e29ce8b3_1280x300.png 424w, https://substackcdn.com/image/fetch/$s_!3mfm!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0002d397-a8f7-4519-a51c-f020e29ce8b3_1280x300.png 848w, https://substackcdn.com/image/fetch/$s_!3mfm!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0002d397-a8f7-4519-a51c-f020e29ce8b3_1280x300.png 1272w, https://substackcdn.com/image/fetch/$s_!3mfm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0002d397-a8f7-4519-a51c-f020e29ce8b3_1280x300.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>When you upgrade, you&#8217;ll get:</p><ul><li><p><strong>Simple breakdown of real-world architectures</strong></p></li><li><p>Frameworks you can plug into your work or business</p></li><li><p><strong>Proven systems behind ChatGPT, Perplexity, and Copilot</strong></p></li></ul><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/subscribe?yearly=true&quot;,&quot;text&quot;:&quot;Unlock Full Access&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesign.one/subscribe?yearly=true"><span>Unlock Full Access</span></a></p><div><hr></div><h2><strong>Part 2: The Data Layer</strong></h2><p>A model&#8217;s capability comes entirely from the data it was trained on.</p><p>The quality of that data, how it&#8217;s collected, cleaned, and organized directly determines how well the model performs.</p><h3><strong>Training Data</strong></h3><p>Foundation models learn from massive datasets: trillions of tokens scraped from books, websites, code repositories, scientific papers, and forum posts. For diffusion models, training data consists of millions of images, each paired with a text description of its contents.</p><p>Raw data is never used directly.</p><p>It passes through a&nbsp;<strong>data pipeline</strong>&nbsp;that cleans, filters, deduplicates, and transforms the data before training begins. For example, the same news article might appear on hundreds of websites. Without deduplication, the model sees the same phrases hundreds of times and overlearns them.</p><p>The pipeline handles problems like near-duplicate web pages that inflate certain patterns, toxic or biased content the model would absorb, personally identifiable information (<strong>PII</strong>) that shouldn&#8217;t be memorized, and low-quality text that adds noise without a useful signal.</p><p>The quality of this pipeline directly determines the model's quality.</p><p><strong>Synthetic data generation</strong> is increasingly used to fill data gaps. An existing model generates additional training examples for areas where real data is scarce, such as specialized medical terminology, underrepresented languages, or edge-case code patterns. The quality of synthetic data depends on the model that generates it and how it&#8217;s validated.</p><p><strong>Bias detection</strong> starts here. If the training data overrepresents certain perspectives, demographics, or viewpoints, the model will reflect those imbalances. Data teams audit for representation gaps and offensive content before training begins, but detection is imperfect. Some biases only surface after the model is trained and tested.</p><p><strong>NSFW and harmful content</strong> requires explicit handling during this stage. Some pipelines filter it entirely. Others retain it in a controlled form so the model can later learn to recognize and refuse it. The approach depends on the product&#8217;s intended use.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!pfnJ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1e31eb63-a6f0-4f1c-b036-26eea788218d_1999x545.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!pfnJ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1e31eb63-a6f0-4f1c-b036-26eea788218d_1999x545.png 424w, https://substackcdn.com/image/fetch/$s_!pfnJ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1e31eb63-a6f0-4f1c-b036-26eea788218d_1999x545.png 848w, https://substackcdn.com/image/fetch/$s_!pfnJ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1e31eb63-a6f0-4f1c-b036-26eea788218d_1999x545.png 1272w, https://substackcdn.com/image/fetch/$s_!pfnJ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1e31eb63-a6f0-4f1c-b036-26eea788218d_1999x545.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!pfnJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1e31eb63-a6f0-4f1c-b036-26eea788218d_1999x545.png" width="1456" height="397" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1e31eb63-a6f0-4f1c-b036-26eea788218d_1999x545.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:397,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:186851,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/192435842?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1e31eb63-a6f0-4f1c-b036-26eea788218d_1999x545.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_!pfnJ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1e31eb63-a6f0-4f1c-b036-26eea788218d_1999x545.png 424w, https://substackcdn.com/image/fetch/$s_!pfnJ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1e31eb63-a6f0-4f1c-b036-26eea788218d_1999x545.png 848w, https://substackcdn.com/image/fetch/$s_!pfnJ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1e31eb63-a6f0-4f1c-b036-26eea788218d_1999x545.png 1272w, https://substackcdn.com/image/fetch/$s_!pfnJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1e31eb63-a6f0-4f1c-b036-26eea788218d_1999x545.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"><em>Data pipeline: raw data is cleaned through multiple stages before training.</em></figcaption></figure></div><h3><strong>Data Storage and Retrieval</strong></h3><p>Training and inference have very different data needs.</p><p>During training, the dataset can be terabytes or more in size, containing text, images, and code. Teams typically store this in distributed file systems like <strong>HDFS</strong> (Hadoop Distributed File System), which splits large files across a cluster of machines so they can be read in parallel, or cloud object storage like <strong>S3</strong> (Amazon&#8217;s Simple Storage Service), which stores files as objects in the cloud and is widely used because it&#8217;s cheap, scales without limits, and requires no infrastructure to manage. Training pipelines stream data from these systems to GPU clusters in batches, feeding the model continuously throughout training.</p><p>At inference time, the training data is no longer needed.</p><p>What matters is the model itself. The model&#8217;s parameters need to be loaded into GPU memory before it can serve any requests, and for large models, that means hundreds of gigabytes. Once loaded, the model takes in a prompt and generates tokens one at a time, streaming them back to the user.</p><p>The challenge is keeping sufficient GPU capacity available to handle many users simultaneously without long wait times.</p><p>Some GenAI systems also retrieve data at runtime, pulling in documents, search results, or database records when a user asks a question. This is how products like Perplexity stay current beyond the model&#8217;s training data.</p><p>In Part 6, we cover how this retrieval works, embeddings, vector databases, and structured data handling when we design the full product architecture.</p><p>But having clean, well-organized data is only the starting point.</p><p>The next question is what happens to that data, and how a pile of text becomes a model that can actually follow instructions&#8230;</p><p>Let&#8217;s keep going!</p>
      <p>
          <a href="https://newsletter.systemdesign.one/p/generative-ai-system-design">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Amazon S3 - A Deep Dive]]></title><description><![CDATA[#136: How S3 Actually Works]]></description><link>https://newsletter.systemdesign.one/p/aws-s3-system-design</link><guid isPermaLink="false">https://newsletter.systemdesign.one/p/aws-s3-system-design</guid><dc:creator><![CDATA[Hayk]]></dc:creator><pubDate>Wed, 01 Apr 2026 12:04:35 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/b7180882-5e86-477b-b950-8a08d76a8ddc_1280x720.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/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">Get my system design playbook for FREE on newsletter signup:</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><ul><li><p><em><a href="https://newsletter.systemdesign.one/p/aws-s3-system-design/?action=share">Share this post</a> &amp; I'll send you some rewards for the referrals.</em></p></li><li><p><em>Block diagrams created using <a href="https://app.eraser.io/auth/sign-up?ref=neo">Eraser</a>.</em></p></li></ul><div><hr></div><p>Object storage isn&#8217;t just <em>&#8220;upload a file, get a URL back.&#8221;</em></p><p>That&#8217;s true for a small side project. It stops being true when you&#8217;re storing 100 trillion objects like AWS S3 does today.</p><p>Amazon Simple Storage Service (<strong>S3</strong>) launched in 2006.</p><p>In 2013, Amazon reported storing 2 trillion objects. By 2021, that number crossed 100 trillion. The system handling all of that doesn&#8217;t look anything like a file server or a relational database. It&#8217;s a fundamentally different class of infrastructure, built around a different set of tradeoffs.</p><p>This problem shows up in senior- and staff-level interviews at companies building storage-heavy products&#8230;</p><p>It tests the exact skills that separate mid-level engineers from seniors: <em>understanding why different storage types exist, designing for durability at a scale where hardware failures occur daily, and making smart trade-offs between consistency, cost, and performance.</em></p><p>We&#8217;re going to build this from scratch:</p><p>We&#8217;ll start with what object storage actually is and how it differs from other storage systems, then work through requirements, capacity estimation, the high-level architecture, disk-based data persistence, durability strategies, metadata design, object versioning<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a>, large-file uploads, and garbage collection.</p><p>At each step, we&#8217;ll explain the why behind each decision&#8230;</p><div><hr></div><h3><strong><a href="https://codenewsletter.ai/subscribe?utm_source=nl_ad_system">Find out why 150K+ engineers read The Code twice a week (Partner)</a></strong></h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://codenewsletter.ai/subscribe?utm_source=nl_ad_system" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!w80U!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe30ba00c-653e-421b-af50-f5b48536f36b_1271x699.jpeg 424w, https://substackcdn.com/image/fetch/$s_!w80U!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe30ba00c-653e-421b-af50-f5b48536f36b_1271x699.jpeg 848w, https://substackcdn.com/image/fetch/$s_!w80U!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe30ba00c-653e-421b-af50-f5b48536f36b_1271x699.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!w80U!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe30ba00c-653e-421b-af50-f5b48536f36b_1271x699.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!w80U!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe30ba00c-653e-421b-af50-f5b48536f36b_1271x699.jpeg" width="1271" height="699" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e30ba00c-653e-421b-af50-f5b48536f36b_1271x699.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:699,&quot;width&quot;:1271,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:303786,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:&quot;image/jpeg&quot;,&quot;href&quot;:&quot;https://codenewsletter.ai/subscribe?utm_source=nl_ad_system&quot;,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/179236490?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe30ba00c-653e-421b-af50-f5b48536f36b_1271x699.jpeg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!w80U!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe30ba00c-653e-421b-af50-f5b48536f36b_1271x699.jpeg 424w, https://substackcdn.com/image/fetch/$s_!w80U!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe30ba00c-653e-421b-af50-f5b48536f36b_1271x699.jpeg 848w, https://substackcdn.com/image/fetch/$s_!w80U!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe30ba00c-653e-421b-af50-f5b48536f36b_1271x699.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!w80U!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe30ba00c-653e-421b-af50-f5b48536f36b_1271x699.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Tech moves fast, but you&#8217;re still playing catch-up?</p><p>That&#8217;s exactly why 150K+ engineers working at Google, Meta, and Apple read <a href="https://codenewsletter.ai/subscribe?utm_source=nl_ad_system">The Code</a> twice a week.</p><p>Here&#8217;s what you get:</p><ul><li><p><strong>Curated tech news that shapes your career </strong>- Filtered from thousands of sources so you know what&#8217;s coming 6 months early.</p></li><li><p><strong>Practical resources you can use immediately</strong> - Real tutorials and tools that solve actual engineering problems.</p></li><li><p><strong>Research papers and insights decoded</strong> - We break down complex tech so you understand what matters.</p></li></ul><p>All delivered twice a week in just 2 short emails.</p><p><strong>Sign up and get access to the Ultimate Claude code guide to ship 5X faster.</strong></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://codenewsletter.ai/subscribe?utm_source=nl_ad_system&quot;,&quot;text&quot;:&quot;Join 150K+ Engineers&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://codenewsletter.ai/subscribe?utm_source=nl_ad_system"><span>Join 150K+ Engineers</span></a></p><p>(Thanks for partnering on this post and sharing the ultimate <a href="https://codenewsletter.ai/subscribe?utm_source=nl_ad_system">claude code guide</a>.)</p><div><hr></div><p>I want to reintroduce <a href="https://linkedin.com/in/hayksimonyan">Hayk Simonyan</a> as a guest author.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://youtube.com/@hayk.simonyan" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!TNRZ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe42ce2a7-78b8-43b3-b7cf-b293d660240a_1748x720.png 424w, https://substackcdn.com/image/fetch/$s_!TNRZ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe42ce2a7-78b8-43b3-b7cf-b293d660240a_1748x720.png 848w, https://substackcdn.com/image/fetch/$s_!TNRZ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe42ce2a7-78b8-43b3-b7cf-b293d660240a_1748x720.png 1272w, https://substackcdn.com/image/fetch/$s_!TNRZ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe42ce2a7-78b8-43b3-b7cf-b293d660240a_1748x720.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!TNRZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe42ce2a7-78b8-43b3-b7cf-b293d660240a_1748x720.png" width="1456" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e42ce2a7-78b8-43b3-b7cf-b293d660240a_1748x720.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:387657,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:&quot;https://youtube.com/@hayk.simonyan&quot;,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/188825279?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe42ce2a7-78b8-43b3-b7cf-b293d660240a_1748x720.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!TNRZ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe42ce2a7-78b8-43b3-b7cf-b293d660240a_1748x720.png 424w, https://substackcdn.com/image/fetch/$s_!TNRZ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe42ce2a7-78b8-43b3-b7cf-b293d660240a_1748x720.png 848w, https://substackcdn.com/image/fetch/$s_!TNRZ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe42ce2a7-78b8-43b3-b7cf-b293d660240a_1748x720.png 1272w, https://substackcdn.com/image/fetch/$s_!TNRZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe42ce2a7-78b8-43b3-b7cf-b293d660240a_1748x720.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>He&#8217;s a senior software engineer specializing in helping developers break through their career plateaus and secure senior roles.</p><p>If you want to master the essential system design skills and land senior developer roles, I highly recommend checking out Hayk&#8217;s <strong><a href="https://youtube.com/@hayk.simonyan">YouTube channel</a></strong>.</p><p>His approach focuses on what top employers actually care about: system design expertise, advanced project experience, and elite-level interview performance.</p><div><hr></div><h2><strong>What is Object Storage?</strong></h2><p>Before we design anything, we need to understand what object storage actually is&#8230;</p><p>Engineers often confuse the three main storage categories. Each one exists for a reason, and choosing the wrong one at design time is expensive to fix later.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!eRmE!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fe80ed2-8937-4208-b353-e12f8908ef15_1600x906.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!eRmE!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fe80ed2-8937-4208-b353-e12f8908ef15_1600x906.png 424w, https://substackcdn.com/image/fetch/$s_!eRmE!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fe80ed2-8937-4208-b353-e12f8908ef15_1600x906.png 848w, https://substackcdn.com/image/fetch/$s_!eRmE!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fe80ed2-8937-4208-b353-e12f8908ef15_1600x906.png 1272w, https://substackcdn.com/image/fetch/$s_!eRmE!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fe80ed2-8937-4208-b353-e12f8908ef15_1600x906.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!eRmE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fe80ed2-8937-4208-b353-e12f8908ef15_1600x906.png" width="1456" height="824" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8fe80ed2-8937-4208-b353-e12f8908ef15_1600x906.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:824,&quot;width&quot;:1456,&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_!eRmE!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fe80ed2-8937-4208-b353-e12f8908ef15_1600x906.png 424w, https://substackcdn.com/image/fetch/$s_!eRmE!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fe80ed2-8937-4208-b353-e12f8908ef15_1600x906.png 848w, https://substackcdn.com/image/fetch/$s_!eRmE!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fe80ed2-8937-4208-b353-e12f8908ef15_1600x906.png 1272w, https://substackcdn.com/image/fetch/$s_!eRmE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fe80ed2-8937-4208-b353-e12f8908ef15_1600x906.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><strong>Block Storage</strong></h3><p>Block storage is the oldest and lowest-level.</p><p>When you plug a hard drive or SSD into a server, the operating system (<strong>OS</strong>) sees it as a sequence of raw blocks, each typically 4KB in size. The OS decides how to format those blocks and build a file system on top of them. Some applications, such as databases and virtual machine engines, skip the file system entirely and manage blocks directly, which gives them maximum control and performance.</p><p>Block storage doesn&#8217;t have to be physically attached&#8230;</p><p>You can connect to block storage over a network using protocols like Fibre Channel or iSCSI<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-2" href="#footnote-2" target="_self">2</a>. The server still sees raw blocks, as if the drive were directly attached, but the data resides elsewhere on the network. This is how cloud providers like AWS offer Elastic Block Store (<strong>EBS</strong>): you attach a network drive to your VM, and it behaves like a local disk.</p><p>Block storage is fast and flexible, but it&#8217;s also expensive and doesn&#8217;t scale cheaply to petabytes.</p><h3><strong>File Storage</strong></h3><p>File storage is built on top of block storage.</p><p>It adds a layer that handles the complexity of managing blocks and gives you a familiar directory hierarchy: folders, subfolders, and files. You don&#8217;t deal with blocks at all. You just read and write files using paths like <code>/documents/report.pdf.</code></p><p>File storage becomes especially useful when many servers need to share the same files.</p><p>Protocols like NFS and SMB/CIFS<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-3" href="#footnote-3" target="_self">3</a> allow many machines to mount the same file share and read and write to it concurrently. This is how shared drives inside organizations typically work, and it&#8217;s how many legacy enterprise applications store data.</p><p>File storage is easier to use than block storage, but it still doesn&#8217;t scale to the level object storage does. Hierarchical directory structures become slow and complex when you have billions of files.</p><h3><strong>Object Storage</strong></h3><p>Object storage is the newest of the three and the most different&#8230;</p><p>It makes a deliberate tradeoff: <em>give up performance and mutability in exchange for near-unlimited scalability, very high durability, and low cost.</em></p><p>There are no directories in object storage.</p><p>Everything lives in a flat namespace inside containers called buckets. Every object is accessed via a RESTful HTTP API using a unique key. You can&#8217;t partially update an object. If you want to change a file, you replace the entire object or create a new version. This immutability<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-4" href="#footnote-4" target="_self">4</a> constraint sounds limiting, but it&#8217;s actually what makes object storage so cheap to operate at scale, because it simplifies replication and consistency considerably.</p><p>AWS S3, Google Cloud Storage, and Azure Blob Storage are all object storage systems. They&#8217;re the foundation of most modern cloud architectures: video files, backups, data lake storage, machine learning datasets, static website assets, and more.</p><h3><strong>Comparison Table</strong></h3><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!bk1n!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbe044726-8beb-4aec-bc25-468b5794d782_1600x379.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!bk1n!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbe044726-8beb-4aec-bc25-468b5794d782_1600x379.png 424w, https://substackcdn.com/image/fetch/$s_!bk1n!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbe044726-8beb-4aec-bc25-468b5794d782_1600x379.png 848w, https://substackcdn.com/image/fetch/$s_!bk1n!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbe044726-8beb-4aec-bc25-468b5794d782_1600x379.png 1272w, https://substackcdn.com/image/fetch/$s_!bk1n!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbe044726-8beb-4aec-bc25-468b5794d782_1600x379.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!bk1n!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbe044726-8beb-4aec-bc25-468b5794d782_1600x379.png" width="1456" height="345" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/be044726-8beb-4aec-bc25-468b5794d782_1600x379.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:345,&quot;width&quot;:1456,&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_!bk1n!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbe044726-8beb-4aec-bc25-468b5794d782_1600x379.png 424w, https://substackcdn.com/image/fetch/$s_!bk1n!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbe044726-8beb-4aec-bc25-468b5794d782_1600x379.png 848w, https://substackcdn.com/image/fetch/$s_!bk1n!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbe044726-8beb-4aec-bc25-468b5794d782_1600x379.png 1272w, https://substackcdn.com/image/fetch/$s_!bk1n!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbe044726-8beb-4aec-bc25-468b5794d782_1600x379.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>The key constraint to internalize: objects are immutable.</p><p>You cannot edit part of an object. You replace the whole thing, or you version it. This constraint is not an accident. It&#8217;s a deliberate design choice that enables the durability and scale properties that make object storage useful in the first place.</p><div><hr></div><h2><strong>Key Terms</strong></h2><p>These are the concepts you need to know before we get into the design:</p><h3><strong>Bucket</strong></h3><p>A bucket is a logical container for objects.</p><p>Think of it like a top-level folder, except it&#8217;s not really a folder since there&#8217;s no hierarchy inside it. Bucket names must be globally unique across all system users, not just within your account.</p><p>You have to create a bucket before you can store anything in it.</p><h3><strong>Object</strong></h3><p>An object is an individual piece of data stored in a bucket.</p><p>It has two parts:</p><ul><li><p>Payload is the actual data bytes, which can be anything: a photo, a video, a CSV file, a binary blob.</p></li><li><p>Metadata is a set of key-value pairs that describe an object, such as content type, creation timestamp, custom tags, and anything else the application needs to store alongside the data.</p></li></ul><p>The metadata is stored separately from the payload and is much smaller.</p><h3><strong>Object Key</strong></h3><p>Every object is identified by a key, which is just a string.</p><p>In S3, that key looks like a file path: <code>photos/2024/vacation.jpg</code>. But there are no actual directories. The entire string, slashes and all, is just the key. S3 lets you use slashes as a convention to simulate folders, but under the hood, it&#8217;s still a flat namespace.</p><p>This distinction matters when we design the listing feature later.</p><h3><strong>Versioning</strong></h3><p>Versioning is a bucket-level feature that keeps all previous versions of an object instead of overwriting them.</p><p>When versioning is enabled, uploading an object with the same key as an existing object doesn&#8217;t replace it. Instead, it creates a new version alongside the old one. You can retrieve, restore, or delete any version at any time.</p><p>This protects against accidental overwrites and deletions.</p><h3><strong>Durability SLA</strong></h3><p>S3 Standard storage class is designed for 99.999999999% durability, also known as eleven nines.</p><p>In practical terms, if you store 10 million objects for 10,000 years, you&#8217;d expect to lose one. That&#8217;s not an accident. It comes from specific engineering decisions around replication and error correction, which we&#8217;ll get into in the durability section.</p><div><hr></div><h2><strong>Clarifying Requirements</strong></h2><p>Before touching any design, you need to understand what you&#8217;re actually building and at what scale. Candidates who skip this step in interviews fail immediately, because they end up designing the wrong thing at the wrong scale&#8230;</p><h3><strong>Questions to Ask</strong></h3><ul><li><p>What are the core operations? Upload, download, delete, list?</p></li><li><p>Do we need versioning?</p></li><li><p>How much data do we need to store in year one?</p></li><li><p>What durability and availability targets do we need?</p></li><li><p>Do we need to support large file uploads, such as files over multiple gigabytes?</p></li><li><p>Any access control requirements? Do different users own different buckets?</p></li></ul><h3><strong>Our Assumptions</strong></h3><p>For this design, we&#8217;ll assume:</p><ul><li><p>Core operations: bucket creation, object upload and download, object versioning, and listing objects in a bucket by prefix</p></li><li><p>100 petabytes of total data</p></li><li><p>Durability target: six nines, which is 99.9999%</p></li><li><p>Availability target: four nines, which is 99.99%</p></li><li><p>Must handle both small objects (tens of kilobytes) and large objects (several gigabytes)</p></li></ul><p>Now, let&#8217;s figure out what these requirements actually mean for infrastructure&#8230;</p><div><hr></div><h2><strong>Capacity Estimation</strong></h2><p>Math matters in system design because it tells you what kind of infrastructure you need. Vague statements like <em>&#8220;we&#8217;ll need a distributed database&#8221;</em> aren&#8217;t useful without concrete numbers.</p><p>Let&#8217;s work through the estimates:</p><h3><strong>Object Size Distribution</strong></h3><p>In practice, object storage systems see a mix of object sizes. A reasonable assumption for a general-purpose system:</p><ul><li><p>20% of objects are small, under 1MB, with a median size of about 0.5MB. These might be thumbnails, config files, or short documents.</p></li><li><p>60% of objects are medium-sized, ranging from 1MB to 64MB, with a median of about 32MB. These might be images, audio files, or compressed datasets.</p></li><li><p>20% of objects are large (&gt;64MB), with a median of about 200MB. These might be videos, database backups, or large archives.</p></li></ul><h3><strong>Total Object Count</strong></h3><p>We&#8217;re targeting 100 petabytes of stored data.</p><p>In practice, storage systems don&#8217;t fill to capacity, so let&#8217;s assume 40% utilization, meaning we provision enough storage to hold 100PB when 40% full.</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;plaintext&quot;,&quot;nodeId&quot;:&quot;9f89fa67-a6d0-4507-9c79-287873746c8a&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-plaintext">100 PB = 10^11 MB

Weighted average object size: (0.2 x 0.5MB) + (0.6 x 32MB) + (0.2 x 200MB)

= 0.1 + 19.2 + 40.0

= 59.3 MB per object (average)

Total objects at 40% utilization: (10^11 x 0.4) / 59.3

= approximately 680 million objects</code></pre></div><p>680 million objects are a lot.</p><p>This tells us immediately that no single machine can store or index all of this. We need distributed storage and a distributed metadata index from day one.</p><h3><strong>Metadata Storage</strong></h3><p>Each object needs a metadata record. If we assume roughly 1KB per record (object name, bucket, timestamps, UUID, tags), then:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;plaintext&quot;,&quot;nodeId&quot;:&quot;c68210ce-24dd-409c-a907-a5f0d5b3a41c&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-plaintext">680 million objects x 1KB = ~680GB of metadata</code></pre></div><p>680GB of metadata is manageable in a database, but the access patterns will require sharding as we scale. The metadata store is separate from the data store, which we&#8217;ll cover in the design.</p><h3><strong>IOPS Constraints</strong></h3><p>A standard SATA hard drive<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-5" href="#footnote-5" target="_self">5</a> spinning at 7200 RPM can handle roughly 100-150 random seeks per second.</p><p>This is called IOPS<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-6" href="#footnote-6" target="_self">6</a>, or input/output operations per second. At 680 million objects spread across many disks, the IOPS constraint becomes a real bottleneck, especially for small object workloads where you&#8217;re doing many small reads and writes rather than a few large sequential ones.</p><p>This is one reason we&#8217;ll later choose to merge many small objects into a single larger file on disk, instead of storing each object as its own file.</p><div><hr></div><h2><strong>Design Philosophy: Separating Metadata from Data</strong></h2><p>Before we look at the full architecture, there&#8217;s one core design principle that shapes everything else:<em> metadata and data are stored separately, and for good reason.</em></p><p>This idea comes from how UNIX file systems work:</p><p>In UNIX, when you save a file, the filename and the actual data bytes are not stored together. The filename and other file information (size, permissions, timestamps, disk location) live in a data structure called an inode<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-7" href="#footnote-7" target="_self">7</a>. The actual data bytes live in separate disk blocks that the inode points to.</p><p>Object storage works the same way.</p><p>The metadata store is like the inode layer. It holds the object name, bucket, size, and a UUID that points to the location of the actual bytes. The data store is like the disk. It holds the raw bytes, and it only knows about UUIDs, not names or paths.</p><p>So why separate them?</p><p>Because they have completely different characteristics. The data is immutable. Once written, it never changes. The metadata is mutable. You can update tags, rename objects (in some implementations), or add versioning records. They need different consistency guarantees, different storage engines, and different scaling strategies.</p><p>Keeping them separate lets us optimize each independently.</p><div><hr></div><h2><strong>High-Level Architecture</strong></h2><p>With that principle in mind, here&#8217;s how the full system is structured:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!BBL9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ac43646-5c7a-439d-bac8-76dad7c2ae21_1600x1553.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!BBL9!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ac43646-5c7a-439d-bac8-76dad7c2ae21_1600x1553.png 424w, https://substackcdn.com/image/fetch/$s_!BBL9!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ac43646-5c7a-439d-bac8-76dad7c2ae21_1600x1553.png 848w, https://substackcdn.com/image/fetch/$s_!BBL9!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ac43646-5c7a-439d-bac8-76dad7c2ae21_1600x1553.png 1272w, https://substackcdn.com/image/fetch/$s_!BBL9!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ac43646-5c7a-439d-bac8-76dad7c2ae21_1600x1553.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!BBL9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ac43646-5c7a-439d-bac8-76dad7c2ae21_1600x1553.png" width="1456" height="1413" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4ac43646-5c7a-439d-bac8-76dad7c2ae21_1600x1553.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1413,&quot;width&quot;:1456,&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_!BBL9!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ac43646-5c7a-439d-bac8-76dad7c2ae21_1600x1553.png 424w, https://substackcdn.com/image/fetch/$s_!BBL9!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ac43646-5c7a-439d-bac8-76dad7c2ae21_1600x1553.png 848w, https://substackcdn.com/image/fetch/$s_!BBL9!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ac43646-5c7a-439d-bac8-76dad7c2ae21_1600x1553.png 1272w, https://substackcdn.com/image/fetch/$s_!BBL9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ac43646-5c7a-439d-bac8-76dad7c2ae21_1600x1553.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><strong>Components</strong></h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ccAA!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66ba3358-bf5a-4462-9ad0-9e84be6f0fd3_1600x716.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ccAA!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66ba3358-bf5a-4462-9ad0-9e84be6f0fd3_1600x716.png 424w, https://substackcdn.com/image/fetch/$s_!ccAA!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66ba3358-bf5a-4462-9ad0-9e84be6f0fd3_1600x716.png 848w, https://substackcdn.com/image/fetch/$s_!ccAA!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66ba3358-bf5a-4462-9ad0-9e84be6f0fd3_1600x716.png 1272w, https://substackcdn.com/image/fetch/$s_!ccAA!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66ba3358-bf5a-4462-9ad0-9e84be6f0fd3_1600x716.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ccAA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66ba3358-bf5a-4462-9ad0-9e84be6f0fd3_1600x716.png" width="1456" height="652" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/66ba3358-bf5a-4462-9ad0-9e84be6f0fd3_1600x716.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:652,&quot;width&quot;:1456,&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_!ccAA!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66ba3358-bf5a-4462-9ad0-9e84be6f0fd3_1600x716.png 424w, https://substackcdn.com/image/fetch/$s_!ccAA!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66ba3358-bf5a-4462-9ad0-9e84be6f0fd3_1600x716.png 848w, https://substackcdn.com/image/fetch/$s_!ccAA!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66ba3358-bf5a-4462-9ad0-9e84be6f0fd3_1600x716.png 1272w, https://substackcdn.com/image/fetch/$s_!ccAA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66ba3358-bf5a-4462-9ad0-9e84be6f0fd3_1600x716.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><strong>Upload Flow</strong></h3><p>Let&#8217;s trace exactly what happens when a user uploads a file named <code>report.pdf</code> to a bucket called <code>company-docs</code>:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!6Ae2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd8ba7f28-260d-4063-b9e0-64dabd429ea1_1600x1262.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!6Ae2!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd8ba7f28-260d-4063-b9e0-64dabd429ea1_1600x1262.png 424w, https://substackcdn.com/image/fetch/$s_!6Ae2!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd8ba7f28-260d-4063-b9e0-64dabd429ea1_1600x1262.png 848w, https://substackcdn.com/image/fetch/$s_!6Ae2!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd8ba7f28-260d-4063-b9e0-64dabd429ea1_1600x1262.png 1272w, https://substackcdn.com/image/fetch/$s_!6Ae2!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd8ba7f28-260d-4063-b9e0-64dabd429ea1_1600x1262.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!6Ae2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd8ba7f28-260d-4063-b9e0-64dabd429ea1_1600x1262.png" width="1456" height="1148" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d8ba7f28-260d-4063-b9e0-64dabd429ea1_1600x1262.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1148,&quot;width&quot;:1456,&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_!6Ae2!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd8ba7f28-260d-4063-b9e0-64dabd429ea1_1600x1262.png 424w, https://substackcdn.com/image/fetch/$s_!6Ae2!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd8ba7f28-260d-4063-b9e0-64dabd429ea1_1600x1262.png 848w, https://substackcdn.com/image/fetch/$s_!6Ae2!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd8ba7f28-260d-4063-b9e0-64dabd429ea1_1600x1262.png 1272w, https://substackcdn.com/image/fetch/$s_!6Ae2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd8ba7f28-260d-4063-b9e0-64dabd429ea1_1600x1262.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><ol><li><p>Client sends a <code>HTTP PUT /company-docs/report.pdf</code> request with the file bytes in the request body.</p></li><li><p>Request hits the load balancer and gets routed to one of the API service instances.</p></li><li><p>API service calls the IAM service<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-8" href="#footnote-8" target="_self">8</a> to confirm the user has WRITE permission on the <code>company-docs</code> bucket. If not, the request is rejected immediately with a 403 Forbidden.</p></li><li><p>API service forwards the file bytes to the data store. The data store persists the bytes and returns a UUID, a unique identifier for this specific object.</p></li><li><p>API service then writes a metadata record to the metadata store. This record contains the object name (<code>report.pdf</code>), bucket ID, UUID returned from the data store, file size, creation timestamp, and any metadata tags the user provided.</p></li><li><p>A <code>200 OK</code> response is returned to the client.</p></li></ol><p>The metadata record now serves as the bridge between the human-readable path (<code>company-docs/report.pdf</code>) and the actual bytes stored under the UUID in the data store.</p><h3><strong>Download Flow</strong></h3><p>Now, let&#8217;s trace what happens when someone requests the same 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_!ySqR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01ea95e6-c6ae-4944-b89b-80817ef6c827_1600x1282.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ySqR!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01ea95e6-c6ae-4944-b89b-80817ef6c827_1600x1282.png 424w, https://substackcdn.com/image/fetch/$s_!ySqR!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01ea95e6-c6ae-4944-b89b-80817ef6c827_1600x1282.png 848w, https://substackcdn.com/image/fetch/$s_!ySqR!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01ea95e6-c6ae-4944-b89b-80817ef6c827_1600x1282.png 1272w, https://substackcdn.com/image/fetch/$s_!ySqR!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01ea95e6-c6ae-4944-b89b-80817ef6c827_1600x1282.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ySqR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01ea95e6-c6ae-4944-b89b-80817ef6c827_1600x1282.png" width="1456" height="1167" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/01ea95e6-c6ae-4944-b89b-80817ef6c827_1600x1282.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1167,&quot;width&quot;:1456,&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_!ySqR!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01ea95e6-c6ae-4944-b89b-80817ef6c827_1600x1282.png 424w, https://substackcdn.com/image/fetch/$s_!ySqR!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01ea95e6-c6ae-4944-b89b-80817ef6c827_1600x1282.png 848w, https://substackcdn.com/image/fetch/$s_!ySqR!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01ea95e6-c6ae-4944-b89b-80817ef6c827_1600x1282.png 1272w, https://substackcdn.com/image/fetch/$s_!ySqR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F01ea95e6-c6ae-4944-b89b-80817ef6c827_1600x1282.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><ol><li><p>Client sends a <code>GET /company-docs/report.pdf</code> request.</p></li><li><p>API service calls IAM to verify READ permission.</p></li><li><p>API service queries the metadata store: <em>&#8220;What is the UUID for the object named report.pdf in the bucket company-docs?&#8221;</em></p></li><li><p>API service then uses that UUID to fetch the actual bytes from the data store.</p></li><li><p>The bytes get returned to the client.</p></li></ol><p>Notice that the data store never knows the file was called <code>report.pdf</code>.</p><p>From its perspective, someone asked for the object with a specific UUID, and it returned the bytes. The translation from name to UUID always happens in the metadata store.</p><div><hr></div><p><em><strong>Reminder: this is a teaser of the subscriber-only newsletter series, exclusive to my golden members.</strong></em></p><p>When you upgrade, you&#8217;ll get:</p><ul><li><p><strong>High-level architecture of real-world systems.</strong></p></li><li><p>Deep dive into how popular real-world systems actually work.</p></li><li><p><strong>How real-world systems handle scale, reliability, and performance.</strong></p></li></ul><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/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://newsletter.systemdesign.one/subscribe?"><span>Subscribe now</span></a></p><div><hr></div><h2><strong>Deep Dive: Data Store</strong></h2><p>The data store is where most of the interesting engineering happens&#8230;</p><p>Let&#8217;s break down its internal architecture:</p><h3><strong>Internal Components</strong></h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!5Oiu!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5faa566c-99a2-4140-8087-253c6a27e6ca_1600x765.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!5Oiu!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5faa566c-99a2-4140-8087-253c6a27e6ca_1600x765.png 424w, https://substackcdn.com/image/fetch/$s_!5Oiu!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5faa566c-99a2-4140-8087-253c6a27e6ca_1600x765.png 848w, https://substackcdn.com/image/fetch/$s_!5Oiu!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5faa566c-99a2-4140-8087-253c6a27e6ca_1600x765.png 1272w, https://substackcdn.com/image/fetch/$s_!5Oiu!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5faa566c-99a2-4140-8087-253c6a27e6ca_1600x765.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!5Oiu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5faa566c-99a2-4140-8087-253c6a27e6ca_1600x765.png" width="1456" height="696" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5faa566c-99a2-4140-8087-253c6a27e6ca_1600x765.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:696,&quot;width&quot;:1456,&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_!5Oiu!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5faa566c-99a2-4140-8087-253c6a27e6ca_1600x765.png 424w, https://substackcdn.com/image/fetch/$s_!5Oiu!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5faa566c-99a2-4140-8087-253c6a27e6ca_1600x765.png 848w, https://substackcdn.com/image/fetch/$s_!5Oiu!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5faa566c-99a2-4140-8087-253c6a27e6ca_1600x765.png 1272w, https://substackcdn.com/image/fetch/$s_!5Oiu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5faa566c-99a2-4140-8087-253c6a27e6ca_1600x765.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><strong>Data Routing Service</strong></h4><p>The data routing service is the entry point into the data store&#8230;</p><p>It&#8217;s stateless, meaning it holds no state itself, so you can scale it horizontally by adding more instances. When a <em>write</em> comes in, the placement service determines which data node should receive the data, then sends the data there.</p><p>When a <em>read</em> comes in, it asks the placement service where the data lives, then fetches it.</p><h4><strong>Placement Service</strong></h4><p>The placement service<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-9" href="#footnote-9" target="_self">9</a> is responsible for knowing the physical layout of the entire storage cluster&#8230;</p><p>It maintains a virtual cluster map<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-10" href="#footnote-10" target="_self">10</a>, which is essentially a registry of every data node, including the rack and availability zone it&#8217;s in, how many disks it has, and how much space is used on each disk.</p><p>Placement service continuously receives heartbeat messages from every data node.</p><p>A heartbeat is a small message a node sends every few seconds, saying, <em>&#8220;I&#8217;m alive, here&#8217;s my current state.&#8221;</em> If the placement service doesn&#8217;t hear from a node within a configurable grace period (typically 15 seconds), it marks that node as down and stops sending new data to it.</p><p>Because the placement service is so critical, you run it as a cluster of 5 or 7 nodes using a consensus algorithm<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-11" href="#footnote-11" target="_self">11</a> like Raft or Paxos.</p><p>A consensus algorithm ensures the cluster agrees on a single consistent view of the world, even if some nodes fail. With a 7-node cluster, you can lose 3 nodes simultaneously, and the service keeps running. With a 5-node cluster, you can lose 2. You never run this as a single instance, because if it goes down, the entire storage cluster becomes unavailable for writes.</p><h4><strong>Data Nodes</strong></h4><p>Data nodes are where the actual bytes live&#8230;</p><p>Each data node manages one or more physical disks. Each node runs a daemon process that sends heartbeats to the placement service with information about disk count and available space. When the placement service receives a heartbeat from a new node it hasn&#8217;t seen before, it assigns that node an ID, adds it to the virtual cluster map, and tells the node where to replicate data.</p><p>Durability is the central promise of object storage and the hardest engineering problem in this design.</p><p>We'll get there.</p><p>But before we can talk about how data survives hardware failures and entire node outages, we need to understand exactly how a write moves through this system.</p><p>The decisions made in the next few steps determine whether durability can be guaranteed&#8230;</p>
      <p>
          <a href="https://newsletter.systemdesign.one/p/aws-s3-system-design">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[The 53 Concepts for Highly Effective Mobile System Design]]></title><description><![CDATA[#135: Part 1 - Client-Server Architecture, Push Notifications, Offline-First, and 16 others.]]></description><link>https://newsletter.systemdesign.one/p/mobile-system-design</link><guid isPermaLink="false">https://newsletter.systemdesign.one/p/mobile-system-design</guid><dc:creator><![CDATA[Shefali Jangid]]></dc:creator><pubDate>Wed, 25 Mar 2026 15:28:41 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/6c0254e3-929f-4131-9c21-1ba491cc0bb3_1280x720.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/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">Get my system design playbook for FREE on newsletter signup:</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><ul><li><p><em><a href="https://newsletter.systemdesign.one/p/mobile-system-design/?action=share">Share this post</a> &amp; I'll send you some rewards for the referrals.</em></p></li></ul><div><hr></div><p>Since people are always asking me for more &#8220;practical&#8221; system design content:</p><p>Following is the free edition of a <em>premium</em> 3-part newsletter series... This covers how mobile apps work under the hood. And it&#8217;s explained in a simple, realistic, and useful way.</p><p>On with part 1 of the newsletter:</p><div><hr></div><h3><strong><a href="https://blog.sentry.io/monitoring-microservices-distributed-systems-with-sentry/?utm_source=systemdesign&amp;utm_medium=paid-community&amp;utm_campaign=debugging-fy27q1-microservices&amp;utm_content=newsletter-primary-microservices-blog-learnmore">Trying to debug a request that touched 5 services? (Partner)</a></strong></h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://blog.sentry.io/monitoring-microservices-distributed-systems-with-sentry/?utm_source=systemdesign&amp;utm_medium=paid-community&amp;utm_campaign=debugging-fy27q1-microservices&amp;utm_content=newsletter-primary-microservices-blog-learnmore" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!_dcB!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44a91a4e-b8d3-4c6c-84f3-4acab1b4eddf_2520x945.jpeg 424w, https://substackcdn.com/image/fetch/$s_!_dcB!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44a91a4e-b8d3-4c6c-84f3-4acab1b4eddf_2520x945.jpeg 848w, https://substackcdn.com/image/fetch/$s_!_dcB!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44a91a4e-b8d3-4c6c-84f3-4acab1b4eddf_2520x945.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!_dcB!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44a91a4e-b8d3-4c6c-84f3-4acab1b4eddf_2520x945.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!_dcB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44a91a4e-b8d3-4c6c-84f3-4acab1b4eddf_2520x945.jpeg" width="1456" height="546" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/44a91a4e-b8d3-4c6c-84f3-4acab1b4eddf_2520x945.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:546,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:181803,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/jpeg&quot;,&quot;href&quot;:&quot;https://blog.sentry.io/monitoring-microservices-distributed-systems-with-sentry/?utm_source=systemdesign&amp;utm_medium=paid-community&amp;utm_campaign=debugging-fy27q1-microservices&amp;utm_content=newsletter-primary-microservices-blog-learnmore&quot;,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/191673121?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44a91a4e-b8d3-4c6c-84f3-4acab1b4eddf_2520x945.jpeg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!_dcB!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44a91a4e-b8d3-4c6c-84f3-4acab1b4eddf_2520x945.jpeg 424w, https://substackcdn.com/image/fetch/$s_!_dcB!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44a91a4e-b8d3-4c6c-84f3-4acab1b4eddf_2520x945.jpeg 848w, https://substackcdn.com/image/fetch/$s_!_dcB!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44a91a4e-b8d3-4c6c-84f3-4acab1b4eddf_2520x945.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!_dcB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44a91a4e-b8d3-4c6c-84f3-4acab1b4eddf_2520x945.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Distributed systems help you move faster&#8230;until you have to debug them.</p><p>This <a href="https://blog.sentry.io/monitoring-microservices-distributed-systems-with-sentry/?utm_source=systemdesign&amp;utm_medium=paid-community&amp;utm_campaign=debugging-fy27q1-microservices&amp;utm_content=newsletter-primary-microservices-blog-learnmore">blog</a> shows how to use Sentry tracing and logging to follow a request end-to-end. You don&#8217;t need prior microservices experience to follow these steps.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.sentry.io/monitoring-microservices-distributed-systems-with-sentry/?utm_source=systemdesign&amp;utm_medium=paid-community&amp;utm_campaign=debugging-fy27q1-microservices&amp;utm_content=newsletter-primary-microservices-blog-learnmore&quot;,&quot;text&quot;:&quot;Read the blog and start fixing&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://blog.sentry.io/monitoring-microservices-distributed-systems-with-sentry/?utm_source=systemdesign&amp;utm_medium=paid-community&amp;utm_campaign=debugging-fy27q1-microservices&amp;utm_content=newsletter-primary-microservices-blog-learnmore"><span>Read the blog and start fixing</span></a></p><p>(Thanks to <a href="https://blog.sentry.io/monitoring-microservices-distributed-systems-with-sentry/?utm_source=systemdesign&amp;utm_medium=paid-community&amp;utm_campaign=debugging-fy27q1-microservices&amp;utm_content=newsletter-primary-microservices-blog-learnmore">Sentry</a> for partnering on this post.)</p><div><hr></div><p>I want to reintroduce <a href="https://x.com/Shefali__J">Shefali Jangid</a> as a guest author.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://x.com/Shefali__J" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!9raK!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facd58707-3a96-4850-a5f0-6e3bd8429d06_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!9raK!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facd58707-3a96-4850-a5f0-6e3bd8429d06_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!9raK!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facd58707-3a96-4850-a5f0-6e3bd8429d06_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!9raK!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facd58707-3a96-4850-a5f0-6e3bd8429d06_1200x630.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!9raK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facd58707-3a96-4850-a5f0-6e3bd8429d06_1200x630.png" width="1200" height="630" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/acd58707-3a96-4850-a5f0-6e3bd8429d06_1200x630.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:630,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:152918,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:&quot;https://x.com/Shefali__J&quot;,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/178020218?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facd58707-3a96-4850-a5f0-6e3bd8429d06_1200x630.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!9raK!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facd58707-3a96-4850-a5f0-6e3bd8429d06_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!9raK!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facd58707-3a96-4850-a5f0-6e3bd8429d06_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!9raK!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facd58707-3a96-4850-a5f0-6e3bd8429d06_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!9raK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facd58707-3a96-4850-a5f0-6e3bd8429d06_1200x630.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>She&#8217;s a web developer, technical writer, and content creator with a love for frontend architecture and building things that scale.</p><p>Check out her work and socials:</p><ul><li><p><a href="https://shefali.dev/">Shefali.dev</a></p></li><li><p><a href="https://github.com/WebdevShefali">GitHub</a></p></li><li><p><a href="https://x.com/Shefali__J">Twitter</a></p></li></ul><p>You&#8217;ll often find her writing about web development, sharing UI tips, and building tools that make developers&#8217; lives easier.</p><div><hr></div><p>Building &#8220;scalable mobile apps&#8221; is not just about writing frontend code and calling APIs&#8230;</p><p>It&#8217;s actually one of the toughest parts of software engineering!</p><p>Mobile apps don&#8217;t run in ideal environments. The network can go down, batteries run low, the operating system can close your app in the background, devices vary, and users still expect everything to work instantly, even offline.</p><p>When building mobile apps, you always have to think about limits. Every decision affects speed, stability, data safety, security, and user experience simultaneously. And making the right choices turns a simple app into a strong, production-ready package.</p><p>In this newsletter, we&#8217;ll focus on 19 concepts as the foundation:</p><ol><li><p>Client-Server Architecture,</p></li><li><p>WebSockets &amp; Persistent Connections,</p></li><li><p>Push Notifications,</p></li><li><p>Polling, Long Polling &amp; SSE,</p></li><li><p>REST vs GraphQL vs gRPC,</p></li><li><p>Network Resilience,</p></li><li><p>Idempotency in APIs,</p></li><li><p>Request Batching &amp; Payload Optimisation,</p></li><li><p>Resumable Uploads,</p></li><li><p>Handling Intermittent Connectivity,</p></li><li><p>On-Device Caching,</p></li><li><p>HTTP Caching (ETag, Cache-Control),</p></li><li><p>Offline-First Architecture,</p></li><li><p>CDN Strategy &amp; Media Optimisation,</p></li><li><p>Cache Invalidation Strategies,</p></li><li><p>Local Database Design,</p></li><li><p>Schema Migration Strategy,</p></li><li><p>Pagination (Cursor vs Offset vs Page Number),</p></li><li><p>Data Modeling for Mobile Constraints.</p></li></ol><p>(&#8230;and much more in parts 2 &amp; 3!)</p><p>For each concept, I&#8217;ll cover:</p><ul><li><p>What it is and how it works</p></li><li><p>Real-world example</p></li><li><p>The tradeoffs</p></li><li><p>Why it matters for mobile</p></li></ul><p>But before we get into the concepts, let&#8217;s first understand what mobile system design really means&#8230;</p><h4><strong>What is Mobile System Design?</strong></h4><p>Mobile system design is about planning how a mobile app works in the background.</p><p>It includes how the app connects to servers, saves and reads data, stays fast, keeps user data safe, and handles errors.</p><p>It&#8217;s not just about designing screens. It&#8217;s about understanding how data flows within the app, what happens when the network goes down, how the app runs in the background, and how it works across different devices.</p><p>Now that we understand what mobile system design means, let&#8217;s start with one of the most important parts: <em>how your app connects and communicates with the outside world.</em></p><div><hr></div><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/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">Get the full premium newsletter series and max your system design career leverage:</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><h1><strong>Networking &amp; Real-Time Communication</strong></h1><p>This section explains how a mobile app connects to servers and handles real-time data&#8230;</p><p>You&#8217;ll learn how apps send and receive data, choose the right APIs, and handle slow or unstable networks so the app stays fast and reliable.</p><h3><strong>1. Client-Server Architecture (Thick vs Thin Clients)</strong></h3><p>When building a mobile app, an important question to ask is: <em>how much work should the phone handle, and how much should the server do?</em></p><p>There are two main approaches:</p><p><strong>a. Thick Client</strong></p><p>A thick client means the app does most of the work on the device.</p><p>It can:</p><ul><li><p>Save data on the phone</p></li><li><p>Handle some logic by itself</p></li><li><p>Sync data later in the background</p></li><li><p>Work without network connectivity</p></li></ul><p>Most modern apps use this approach because:</p><ul><li><p>The network is not always stable</p></li><li><p>Phones are powerful now</p></li><li><p>Users expect apps to work offline</p></li></ul><p><strong>b. Thin Client</strong></p><p>A thin client means the app does very little on the device.</p><p>It:</p><ul><li><p>Sends requests to the server</p></li><li><p>Waits for the server to process everything</p></li><li><p>Shows whatever the server returns</p></li></ul><p>If the network fails, the app mostly stops working.</p><h4><strong>Why It Matters</strong></h4><p>This decision affects your entire app design:</p><ul><li><p>Whether your app can work offline</p></li><li><p>How difficult syncing will be</p></li><li><p>How easily you can update features</p></li><li><p>How much important logic stays on the server</p></li></ul><h4><strong>Real-World Example</strong></h4><ul><li><p>Gmail is a &#8220;thick&#8221; client. You can read emails and write drafts even without network connectivity. It syncs later.</p></li><li><p>A simple app that only loads a website is a thin client. It&#8217;s useless without the network.</p></li></ul><h4><strong>Trade-offs</strong></h4><ul><li><p><strong>Thick client:</strong> Faster and works offline, but syncing and updates can be harder.</p></li><li><p><strong>Thin client:</strong> Easy to update and simpler to build, but it doesn&#8217;t work well with a bad network.</p></li></ul><h4><strong>Practical Advice</strong></h4><p>For most apps:</p><ul><li><p>Keep the main app logic thick (use local storage and background sync).</p></li><li><p>Keep sensitive logic on the server (like payments, login, pricing, fraud detection).</p></li></ul><p>This gives you the best balance between speed, reliability, and security.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!-Iek!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0be310ca-6d34-4958-ac62-e0634722213b_1600x716.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!-Iek!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0be310ca-6d34-4958-ac62-e0634722213b_1600x716.png 424w, https://substackcdn.com/image/fetch/$s_!-Iek!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0be310ca-6d34-4958-ac62-e0634722213b_1600x716.png 848w, https://substackcdn.com/image/fetch/$s_!-Iek!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0be310ca-6d34-4958-ac62-e0634722213b_1600x716.png 1272w, https://substackcdn.com/image/fetch/$s_!-Iek!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0be310ca-6d34-4958-ac62-e0634722213b_1600x716.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!-Iek!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0be310ca-6d34-4958-ac62-e0634722213b_1600x716.png" width="1456" height="652" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0be310ca-6d34-4958-ac62-e0634722213b_1600x716.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:652,&quot;width&quot;:1456,&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_!-Iek!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0be310ca-6d34-4958-ac62-e0634722213b_1600x716.png 424w, https://substackcdn.com/image/fetch/$s_!-Iek!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0be310ca-6d34-4958-ac62-e0634722213b_1600x716.png 848w, https://substackcdn.com/image/fetch/$s_!-Iek!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0be310ca-6d34-4958-ac62-e0634722213b_1600x716.png 1272w, https://substackcdn.com/image/fetch/$s_!-Iek!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0be310ca-6d34-4958-ac62-e0634722213b_1600x716.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>Once you decide what the app and the server should handle, the next question to ask is: <em>How they should communicate, especially when you need real-time updates?</em></p><h3><strong>2. WebSockets &amp; Persistent Connections</strong></h3><p>Usually, mobile apps use HTTP requests to talk to a server.</p><p>That means:</p><ol><li><p>App asks for data</p></li><li><p>Server sends a response</p></li><li><p>Connection closes</p></li></ol><p>If the app needs new data, it has to ask again.</p><p><em>WebSocket</em> <em>works differently&#8230;</em></p><p>It creates a long-lasting connection between the app and the server.</p><p>Once connected:</p><ul><li><p>App can send data anytime</p></li><li><p>Server can also send data anytime</p></li><li><p>Connection stays open</p></li></ul><p>This is called <strong>real-time communication</strong>.</p><h4><strong>Why It Matters</strong></h4><p>With normal HTTP, the app must keep asking:</p><ul><li><p><em>&#8220;Any new messages?&#8221;</em></p></li><li><p><em>&#8220;Any updates?&#8221;</em></p></li></ul><p>With WebSockets, the server sends updates immediately when something happens.</p><p>This is very important for:</p><ul><li><p>Chat apps</p></li><li><p>Live sports scores</p></li><li><p>Stock price updates</p></li><li><p>Multiplayer games</p></li><li><p>Collaborative tools</p></li></ul><p>If updates are slow, users feel like the app is broken.</p><h4><strong>Real-World Example</strong></h4><p>Apps like Slack, WhatsApp, and Figma use WebSockets.</p><p>When someone sends a message, you see it instantly because the server pushes it directly to your app.</p><h4><strong>Important Things to Remember (For Mobile)</strong></h4><p>On mobile devices, keeping a connection open all the time can drain the battery, use more data, and cause the operating system to close it.</p><p>Instead:</p><ul><li><p>Send small &#8216;heartbeat&#8217; signals to keep it alive</p></li><li><p>Reconnect if the network drops</p></li><li><p>Close the connection when the app goes to the background</p></li></ul><p>Otherwise, the connection may appear active but stop working.</p><h4><strong>How It Works</strong></h4><ol><li><p>App starts with a normal HTTP request.</p></li><li><p>Server upgrades it to a WebSocket connection.</p></li><li><p>After that, both sides can send messages at any time.</p></li><li><p>Connection stays open until one side closes it.</p></li></ol><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!5DET!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f987c94-15ac-4024-9396-64f7a879cdad_1600x706.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!5DET!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f987c94-15ac-4024-9396-64f7a879cdad_1600x706.png 424w, https://substackcdn.com/image/fetch/$s_!5DET!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f987c94-15ac-4024-9396-64f7a879cdad_1600x706.png 848w, https://substackcdn.com/image/fetch/$s_!5DET!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f987c94-15ac-4024-9396-64f7a879cdad_1600x706.png 1272w, https://substackcdn.com/image/fetch/$s_!5DET!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f987c94-15ac-4024-9396-64f7a879cdad_1600x706.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!5DET!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f987c94-15ac-4024-9396-64f7a879cdad_1600x706.png" width="1456" height="642" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2f987c94-15ac-4024-9396-64f7a879cdad_1600x706.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;: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_!5DET!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f987c94-15ac-4024-9396-64f7a879cdad_1600x706.png 424w, https://substackcdn.com/image/fetch/$s_!5DET!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f987c94-15ac-4024-9396-64f7a879cdad_1600x706.png 848w, https://substackcdn.com/image/fetch/$s_!5DET!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f987c94-15ac-4024-9396-64f7a879cdad_1600x706.png 1272w, https://substackcdn.com/image/fetch/$s_!5DET!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f987c94-15ac-4024-9396-64f7a879cdad_1600x706.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><strong>Trade-offs</strong></h4><p><strong>Pros</strong></p><ul><li><p>Very fast (low latency)</p></li><li><p>Instant updates</p></li><li><p>Two-way communication</p></li></ul><p><strong>Cons</strong></p><ul><li><p>Harder to manage</p></li><li><p>Needs reconnect logic</p></li><li><p>Can affect the battery if not handled properly</p></li></ul><p>In simple words, use WebSockets when your app needs instant updates. Just manage the connection carefully on mobile devices.</p><p>But not all updates require a constant open connection.</p><p><em>What if the app is completely closed?</em></p><p>That&#8217;s when push notifications become useful&#8230;</p><h3><strong>3. Push Notifications (APNs &amp; FCM)</strong></h3><p>Push notifications let your app send updates, such as <em>&#8220;Your order has been picked up&#8221;, &#8220;You got a new message&#8221;, &#8220;Your payment was successful&#8221;,</em> to users even when the app is closed.</p><p>But here&#8217;s the important part: Your app does not stay connected to your server all the time.</p><p>Instead, special services handle this for you:</p><ul><li><p><a href="https://en.wikipedia.org/wiki/Apple_Push_Notification_service">APNs (Apple Push Notification Service)</a> for iPhones</p></li><li><p><a href="https://firebase.google.com/docs/cloud-messaging">FCM (Firebase Cloud Messaging)</a> for Android</p></li></ul><p>These services act like messengers between your server and the user&#8217;s phone.</p><h4><strong>How It Works</strong></h4><ol><li><p>Something happens on the server (e.g., a new message).</p></li><li><p>Server sends the notification to APNs (iOS) or FCM (Android).</p></li><li><p>APNs/FCM deliver it to the user&#8217;s device.</p></li><li><p>The mobile phone&#8217;s operating system shows the notification.</p></li><li><p>If needed, the app wakes up in the background.</p></li></ol><p>Your app does NOT keep a permanent connection.</p><p>The phone&#8217;s operating system manages a &#8220;single&#8221; shared connection for all apps to conserve battery.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!G0e8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0af50997-a93d-4bdf-bf8c-eacb6bb6ee82_1600x781.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!G0e8!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0af50997-a93d-4bdf-bf8c-eacb6bb6ee82_1600x781.png 424w, https://substackcdn.com/image/fetch/$s_!G0e8!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0af50997-a93d-4bdf-bf8c-eacb6bb6ee82_1600x781.png 848w, https://substackcdn.com/image/fetch/$s_!G0e8!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0af50997-a93d-4bdf-bf8c-eacb6bb6ee82_1600x781.png 1272w, https://substackcdn.com/image/fetch/$s_!G0e8!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0af50997-a93d-4bdf-bf8c-eacb6bb6ee82_1600x781.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!G0e8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0af50997-a93d-4bdf-bf8c-eacb6bb6ee82_1600x781.png" width="1456" height="711" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0af50997-a93d-4bdf-bf8c-eacb6bb6ee82_1600x781.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:711,&quot;width&quot;:1456,&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_!G0e8!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0af50997-a93d-4bdf-bf8c-eacb6bb6ee82_1600x781.png 424w, https://substackcdn.com/image/fetch/$s_!G0e8!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0af50997-a93d-4bdf-bf8c-eacb6bb6ee82_1600x781.png 848w, https://substackcdn.com/image/fetch/$s_!G0e8!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0af50997-a93d-4bdf-bf8c-eacb6bb6ee82_1600x781.png 1272w, https://substackcdn.com/image/fetch/$s_!G0e8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0af50997-a93d-4bdf-bf8c-eacb6bb6ee82_1600x781.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><strong>Why It Matters</strong></h4><p>Without push notifications, your app would need to stay connected all the time and keep checking for new updates. Neither iOS nor Android allows this because it drains battery.</p><p>Push services solve this problem in a battery-efficient way.</p><h4><strong>Real-World Example</strong></h4><p>Imagine a food delivery app. When your order is picked up:</p><ol><li><p>The backend sends a push notification using FCM or APNs.</p></li><li><p>Your phone receives it instantly.</p></li><li><p>Even if the app is fully closed, you still get the update.</p></li></ol><h4><strong>Trade-offs</strong></h4><p><strong>Pros</strong></p><ul><li><p>Saves battery</p></li><li><p>Works even if the app is closed</p></li><li><p>Delivers updates quickly</p></li><li><p>No need for a constant background connection</p></li></ul><p><strong>Cons</strong></p><ul><li><p>Delivery is not 100% guaranteed</p></li><li><p>Can fail on a poor network</p></li><li><p>Limited message size</p></li><li><p>Should not be used for very critical data</p></li></ul><p>You should never assume the user received the notification. Always refresh or sync data when the app opens.</p><h4><strong>Pro Tip</strong></h4><p>You can send a <strong>silent push notification</strong> (background push).</p><p>This shows nothing to the user. It simply wakes the app in the background to fetch fresh data. So when the user opens the app, everything updates without a loading spinner.</p><p>Push notifications are useful for sending updates to users even when the app is closed. But in many cases, the app itself needs to fetch updates from the server while it&#8217;s running.</p><p>In such situations, use techniques such as polling, long polling, or Server-Sent Events.</p><h3><strong>4. Polling, Long Polling &amp; SSE</strong></h3><p>Sometimes apps need server updates, but using WebSockets isn&#8217;t always necessary or practical. In those cases, use simpler methods such as polling, Long Polling, or Server-Sent Events (<strong>SSE</strong>) to receive updates from the server.</p><p>Each method works a little differently.</p><h4><strong>Why It Matters</strong></h4><p>Not every feature needs instant real-time updates:</p><ul><li><p>Metrics dashboard might refresh every 30 seconds.</p></li><li><p>Notification count might update every few seconds.</p></li></ul><p>Using WebSockets for these cases can be unnecessary and complex. Choosing the right approach can save server resources and keep the system simple.</p><p><strong>a. Polling (Short Polling)</strong></p><p>Polling is the simplest method.</p><p>The app requests updates from the server at fixed intervals:</p><ol><li><p>Every 10 seconds, the app sends a request.</p></li><li><p>The server responds with new data (if any).</p></li></ol><p>So the process looks like this:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!dyjt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefd3aa39-f851-4348-97a6-7e3a90216265_1600x406.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!dyjt!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefd3aa39-f851-4348-97a6-7e3a90216265_1600x406.png 424w, https://substackcdn.com/image/fetch/$s_!dyjt!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefd3aa39-f851-4348-97a6-7e3a90216265_1600x406.png 848w, https://substackcdn.com/image/fetch/$s_!dyjt!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefd3aa39-f851-4348-97a6-7e3a90216265_1600x406.png 1272w, https://substackcdn.com/image/fetch/$s_!dyjt!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefd3aa39-f851-4348-97a6-7e3a90216265_1600x406.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!dyjt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefd3aa39-f851-4348-97a6-7e3a90216265_1600x406.png" width="1456" height="369" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/efd3aa39-f851-4348-97a6-7e3a90216265_1600x406.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:369,&quot;width&quot;:1456,&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_!dyjt!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefd3aa39-f851-4348-97a6-7e3a90216265_1600x406.png 424w, https://substackcdn.com/image/fetch/$s_!dyjt!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefd3aa39-f851-4348-97a6-7e3a90216265_1600x406.png 848w, https://substackcdn.com/image/fetch/$s_!dyjt!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefd3aa39-f851-4348-97a6-7e3a90216265_1600x406.png 1272w, https://substackcdn.com/image/fetch/$s_!dyjt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefd3aa39-f851-4348-97a6-7e3a90216265_1600x406.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>Problem:</strong></p><p>Most of the time, there's no new data, yet the app keeps asking the server. This wastes network and server resources.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!k5p9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc571bff7-e3b3-4f8f-a376-7608d59bf66a_1094x641.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!k5p9!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc571bff7-e3b3-4f8f-a376-7608d59bf66a_1094x641.png 424w, https://substackcdn.com/image/fetch/$s_!k5p9!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc571bff7-e3b3-4f8f-a376-7608d59bf66a_1094x641.png 848w, https://substackcdn.com/image/fetch/$s_!k5p9!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc571bff7-e3b3-4f8f-a376-7608d59bf66a_1094x641.png 1272w, https://substackcdn.com/image/fetch/$s_!k5p9!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc571bff7-e3b3-4f8f-a376-7608d59bf66a_1094x641.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!k5p9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc571bff7-e3b3-4f8f-a376-7608d59bf66a_1094x641.png" width="1094" height="641" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c571bff7-e3b3-4f8f-a376-7608d59bf66a_1094x641.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:641,&quot;width&quot;:1094,&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_!k5p9!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc571bff7-e3b3-4f8f-a376-7608d59bf66a_1094x641.png 424w, https://substackcdn.com/image/fetch/$s_!k5p9!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc571bff7-e3b3-4f8f-a376-7608d59bf66a_1094x641.png 848w, https://substackcdn.com/image/fetch/$s_!k5p9!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc571bff7-e3b3-4f8f-a376-7608d59bf66a_1094x641.png 1272w, https://substackcdn.com/image/fetch/$s_!k5p9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc571bff7-e3b3-4f8f-a376-7608d59bf66a_1094x641.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>b. Long Polling</strong></p><p>Long polling improves on basic polling.</p><p>Instead of responding immediately, the server keeps the request open until new data is available.</p><p>How it works:</p><ol><li><p>App sends a request.</p></li><li><p>Server waits until something changes.</p></li><li><p>When new data arrives, the server sends the response.</p></li><li><p>The app immediately sends another request.</p></li></ol><p>This reduces unnecessary requests compared to short polling.</p><p>Yet it still requires managing many open connections on the server.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ZJ5Y!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2847992c-09d8-4d49-9a9b-e32b07c95e38_1404x661.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ZJ5Y!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2847992c-09d8-4d49-9a9b-e32b07c95e38_1404x661.png 424w, https://substackcdn.com/image/fetch/$s_!ZJ5Y!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2847992c-09d8-4d49-9a9b-e32b07c95e38_1404x661.png 848w, https://substackcdn.com/image/fetch/$s_!ZJ5Y!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2847992c-09d8-4d49-9a9b-e32b07c95e38_1404x661.png 1272w, https://substackcdn.com/image/fetch/$s_!ZJ5Y!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2847992c-09d8-4d49-9a9b-e32b07c95e38_1404x661.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ZJ5Y!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2847992c-09d8-4d49-9a9b-e32b07c95e38_1404x661.png" width="1404" height="661" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2847992c-09d8-4d49-9a9b-e32b07c95e38_1404x661.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:661,&quot;width&quot;:1404,&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_!ZJ5Y!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2847992c-09d8-4d49-9a9b-e32b07c95e38_1404x661.png 424w, https://substackcdn.com/image/fetch/$s_!ZJ5Y!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2847992c-09d8-4d49-9a9b-e32b07c95e38_1404x661.png 848w, https://substackcdn.com/image/fetch/$s_!ZJ5Y!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2847992c-09d8-4d49-9a9b-e32b07c95e38_1404x661.png 1272w, https://substackcdn.com/image/fetch/$s_!ZJ5Y!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2847992c-09d8-4d49-9a9b-e32b07c95e38_1404x661.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>c. Server-Sent Events (SSE)</strong></p><p>SSE allows the server to push updates to the client over a single open HTTP connection.</p><p>How it works:</p><ol><li><p>Client sends a request.</p></li><li><p>Connection stays open.</p></li><li><p>Server sends updates whenever something happens.</p></li></ol><p>The client keeps listening for these updates.</p><p>SSE also has automatic reconnection built into browsers through the <a href="https://developer.mozilla.org/en-US/docs/Web/API/EventSource">EventSource API</a>.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Y2ru!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf6b5441-56db-461c-83cd-c59b0f82aa93_1600x681.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Y2ru!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf6b5441-56db-461c-83cd-c59b0f82aa93_1600x681.png 424w, https://substackcdn.com/image/fetch/$s_!Y2ru!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf6b5441-56db-461c-83cd-c59b0f82aa93_1600x681.png 848w, https://substackcdn.com/image/fetch/$s_!Y2ru!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf6b5441-56db-461c-83cd-c59b0f82aa93_1600x681.png 1272w, https://substackcdn.com/image/fetch/$s_!Y2ru!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf6b5441-56db-461c-83cd-c59b0f82aa93_1600x681.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Y2ru!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf6b5441-56db-461c-83cd-c59b0f82aa93_1600x681.png" width="1456" height="620" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/af6b5441-56db-461c-83cd-c59b0f82aa93_1600x681.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:620,&quot;width&quot;:1456,&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_!Y2ru!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf6b5441-56db-461c-83cd-c59b0f82aa93_1600x681.png 424w, https://substackcdn.com/image/fetch/$s_!Y2ru!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf6b5441-56db-461c-83cd-c59b0f82aa93_1600x681.png 848w, https://substackcdn.com/image/fetch/$s_!Y2ru!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf6b5441-56db-461c-83cd-c59b0f82aa93_1600x681.png 1272w, https://substackcdn.com/image/fetch/$s_!Y2ru!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf6b5441-56db-461c-83cd-c59b0f82aa93_1600x681.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><strong>Real-World Example</strong></h4><ul><li><p>GitHub uses SSE to stream live action logs.</p></li><li><p>Many analytics dashboards use polling every few seconds.</p></li><li><p>Early versions of Twitter used long polling for real-time updates.</p></li></ul><h4><strong>Trade-offs</strong></h4><ul><li><p>Short Polling: Simple to implement, but wastes resources if there are no updates.</p></li><li><p>Long Polling: More efficient than polling, but harder to manage on the server.</p></li><li><p>SSE: Efficient for real-time updates and simple compared to WebSockets, but communication is one-way (server &#8594; client only).</p></li></ul><p><strong>The bottom line:</strong></p><ul><li><p><strong>Polling:</strong> Client repeatedly asks for updates.</p></li><li><p><strong>Long Polling:</strong> Server waits until new data appears.</p></li><li><p><strong>SSE:</strong> Server pushes updates over a single open connection.</p></li></ul><p>These approaches are useful when WebSockets are unnecessary or unavailable, which helps you keep the system simple and efficient.</p><p>Once you understand how apps receive updates from the server, the next step is deciding how the app requests data from the server.</p><p>This is where API design becomes important.</p><p>APIs define how the mobile app and server communicate, what data is requested, and how that data is returned.</p><h3><strong>5. REST vs GraphQL vs gRPC</strong></h3><p>There are different ways to design APIs.</p><p>Three common approaches are <em>REST, GraphQL, and gRPC</em>. Each one has its own advantages depending on the type of app you&#8217;re building.</p><h4><strong>REST</strong></h4><p>REST (Representational State Transfer) is the most common and widely used API style:</p><ol><li><p>App calls specific endpoints like <code>/users, /orders, /products</code>.</p></li><li><p>Server returns predefined data.</p></li></ol><p>It is simple and easy to understand, which is why many mobile apps use it.</p><p>But REST can sometimes return too much or too little data.</p><p>For example, a screen needs only the user&#8217;s name and profile photo, but the API returns email, address, preferences, and more. This is called <strong>over-fetching</strong>.</p><p>Sometimes the opposite happens: the app needs multiple API requests to load one screen. This is called <strong>under-fetching</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_!zVqQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd964e467-df7d-4b63-b1b1-90c1b78c4eed_1344x459.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!zVqQ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd964e467-df7d-4b63-b1b1-90c1b78c4eed_1344x459.png 424w, https://substackcdn.com/image/fetch/$s_!zVqQ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd964e467-df7d-4b63-b1b1-90c1b78c4eed_1344x459.png 848w, https://substackcdn.com/image/fetch/$s_!zVqQ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd964e467-df7d-4b63-b1b1-90c1b78c4eed_1344x459.png 1272w, https://substackcdn.com/image/fetch/$s_!zVqQ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd964e467-df7d-4b63-b1b1-90c1b78c4eed_1344x459.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!zVqQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd964e467-df7d-4b63-b1b1-90c1b78c4eed_1344x459.png" width="1344" height="459" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d964e467-df7d-4b63-b1b1-90c1b78c4eed_1344x459.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:459,&quot;width&quot;:1344,&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_!zVqQ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd964e467-df7d-4b63-b1b1-90c1b78c4eed_1344x459.png 424w, https://substackcdn.com/image/fetch/$s_!zVqQ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd964e467-df7d-4b63-b1b1-90c1b78c4eed_1344x459.png 848w, https://substackcdn.com/image/fetch/$s_!zVqQ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd964e467-df7d-4b63-b1b1-90c1b78c4eed_1344x459.png 1272w, https://substackcdn.com/image/fetch/$s_!zVqQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd964e467-df7d-4b63-b1b1-90c1b78c4eed_1344x459.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><strong>GraphQL</strong></h4><p>GraphQL was designed to address the problems of over-fetching and under-fetching.</p><p>With GraphQL:</p><ol><li><p>Client asks for exactly the data it needs.</p></li><li><p>Server returns only that data.</p></li></ol><p>Example request:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;plaintext&quot;,&quot;nodeId&quot;:&quot;6fe40942-3070-44e3-bff0-d2742e7a0486&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-plaintext">GetUser {
  name
  profilePhoto
}</code></pre></div><p>This makes GraphQL very useful for complex mobile interfaces where different screens need different types of data. Yet GraphQL can be harder to cache and secure compared to REST.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!jSpL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66f14610-031e-4746-af5c-e674daa7a769_1464x450.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!jSpL!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66f14610-031e-4746-af5c-e674daa7a769_1464x450.png 424w, https://substackcdn.com/image/fetch/$s_!jSpL!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66f14610-031e-4746-af5c-e674daa7a769_1464x450.png 848w, https://substackcdn.com/image/fetch/$s_!jSpL!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66f14610-031e-4746-af5c-e674daa7a769_1464x450.png 1272w, https://substackcdn.com/image/fetch/$s_!jSpL!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66f14610-031e-4746-af5c-e674daa7a769_1464x450.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!jSpL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66f14610-031e-4746-af5c-e674daa7a769_1464x450.png" width="1456" height="448" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/66f14610-031e-4746-af5c-e674daa7a769_1464x450.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:448,&quot;width&quot;:1456,&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_!jSpL!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66f14610-031e-4746-af5c-e674daa7a769_1464x450.png 424w, https://substackcdn.com/image/fetch/$s_!jSpL!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66f14610-031e-4746-af5c-e674daa7a769_1464x450.png 848w, https://substackcdn.com/image/fetch/$s_!jSpL!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66f14610-031e-4746-af5c-e674daa7a769_1464x450.png 1272w, https://substackcdn.com/image/fetch/$s_!jSpL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66f14610-031e-4746-af5c-e674daa7a769_1464x450.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><strong>gRPC</strong></h4><p>gRPC is another approach focused on high performance.</p><p>Instead of sending JSON data like REST or GraphQL, gRPC uses a binary format called <strong>Protocol Buffers</strong>, which is smaller and faster.</p><p>It runs over HTTP/2, which allows faster communication between services. Because of this, gRPC is often used for internal microservices, backend communication, and high-performance mobile systems.</p><p>But it requires special tooling and is less common for public APIs.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!SnKU!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0b3bfc60-15f7-4db0-82d6-c0b0fa0390df_1600x438.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!SnKU!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0b3bfc60-15f7-4db0-82d6-c0b0fa0390df_1600x438.png 424w, https://substackcdn.com/image/fetch/$s_!SnKU!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0b3bfc60-15f7-4db0-82d6-c0b0fa0390df_1600x438.png 848w, https://substackcdn.com/image/fetch/$s_!SnKU!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0b3bfc60-15f7-4db0-82d6-c0b0fa0390df_1600x438.png 1272w, https://substackcdn.com/image/fetch/$s_!SnKU!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0b3bfc60-15f7-4db0-82d6-c0b0fa0390df_1600x438.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!SnKU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0b3bfc60-15f7-4db0-82d6-c0b0fa0390df_1600x438.png" width="1456" height="399" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0b3bfc60-15f7-4db0-82d6-c0b0fa0390df_1600x438.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:399,&quot;width&quot;:1456,&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_!SnKU!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0b3bfc60-15f7-4db0-82d6-c0b0fa0390df_1600x438.png 424w, https://substackcdn.com/image/fetch/$s_!SnKU!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0b3bfc60-15f7-4db0-82d6-c0b0fa0390df_1600x438.png 848w, https://substackcdn.com/image/fetch/$s_!SnKU!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0b3bfc60-15f7-4db0-82d6-c0b0fa0390df_1600x438.png 1272w, https://substackcdn.com/image/fetch/$s_!SnKU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0b3bfc60-15f7-4db0-82d6-c0b0fa0390df_1600x438.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><strong>Why It Matters</strong></h4><p>The API style you choose affects network speed, battery usage, number of requests, and app performance.</p><p>If an API returns too much data, it wastes bandwidth and battery. If it returns too little, the app needs more requests, which increases latency. Choosing the right approach helps keep the app fast and efficient.</p><h4><strong>Real-World Example</strong></h4><ul><li><p>Facebook created GraphQL because its mobile apps needed many REST requests to load a single screen.</p></li><li><p>GitHub moved its public API to GraphQL.</p></li><li><p>Google uses gRPC internally for inter-service communication.</p></li></ul><h4><strong>Trade-offs</strong></h4><ul><li><p>REST: Simple, widely supported, and easy to cache, but sometimes returns too much or too little data.</p></li><li><p>GraphQL:  Clients request exactly the data they need and great for complex UIs, but caching and security can be more complicated.</p></li><li><p>gRPC: Very fast, efficient, and great for internal services, but requires HTTP/2 and special tooling.</p></li></ul><h4><strong>Practical Advice</strong></h4><p>A common approach in real systems is:</p><ul><li><p>REST for simple CRUD APIs.</p></li><li><p>GraphQL for complex UI data requirements.</p></li><li><p>gRPC for internal communication between services where performance matters most.</p></li></ul><p>Once you decide how the app will request data from the server, the next step is making sure those requests still work properly when the internet connection is unstable.</p><h3><strong>6. Network Resilience (Exponential Backoff &amp; Retry Strategy)</strong></h3><p>Mobile networks can be slow, unstable, or unavailable.</p><p>As a result, requests may fail due to weak signals, timeouts, or temporary server issues. Instead of failing immediately, most apps retry the request after a short delay.</p><p>Yet retrying requests often can cause serious problems.</p><h4><strong>Why It Matters</strong></h4><p>Imagine thousands of mobile apps trying to reconnect at the same time after a server outage.</p><p>If every app retries instantly, the server suddenly receives a huge number of requests at once. This can overload the server again, causing another failure. This situation is called the <strong>thundering herd problem,</strong> when many clients try at the same time and overwhelm the system.</p><p>A good retry strategy spreads these retries over time so the server can recover&#8230;</p><h4><strong>Exponential Backoff (The Common Solution)</strong></h4><p>To avoid retrying too aggressively, apps use exponential backoff. This means the app waits longer between each retry:</p><ul><li><p>First retry &#8594; wait 1 second</p></li><li><p>Second retry &#8594; wait 2 seconds</p></li><li><p>Third retry &#8594; wait 4 seconds</p></li><li><p>Fourth retry &#8594; wait 8 seconds</p></li></ul><p>Each retry waits longer than the previous one. Thus reducing pressure on the server.</p><h4><strong>Adding Jitter</strong></h4><p>If every app waited the exact same time, they would still retry together.</p><p>To avoid that, add <strong>jitter</strong>, which is a small random delay. For example, retry after 4 seconds + random delay.</p><p>This spreads the requests over time instead of sending them all at once.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Y_wh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d787a8f-d96c-4f3f-a961-e803393f16ef_1600x453.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Y_wh!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d787a8f-d96c-4f3f-a961-e803393f16ef_1600x453.png 424w, https://substackcdn.com/image/fetch/$s_!Y_wh!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d787a8f-d96c-4f3f-a961-e803393f16ef_1600x453.png 848w, https://substackcdn.com/image/fetch/$s_!Y_wh!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d787a8f-d96c-4f3f-a961-e803393f16ef_1600x453.png 1272w, https://substackcdn.com/image/fetch/$s_!Y_wh!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d787a8f-d96c-4f3f-a961-e803393f16ef_1600x453.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Y_wh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d787a8f-d96c-4f3f-a961-e803393f16ef_1600x453.png" width="1456" height="412" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7d787a8f-d96c-4f3f-a961-e803393f16ef_1600x453.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:412,&quot;width&quot;:1456,&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_!Y_wh!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d787a8f-d96c-4f3f-a961-e803393f16ef_1600x453.png 424w, https://substackcdn.com/image/fetch/$s_!Y_wh!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d787a8f-d96c-4f3f-a961-e803393f16ef_1600x453.png 848w, https://substackcdn.com/image/fetch/$s_!Y_wh!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d787a8f-d96c-4f3f-a961-e803393f16ef_1600x453.png 1272w, https://substackcdn.com/image/fetch/$s_!Y_wh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d787a8f-d96c-4f3f-a961-e803393f16ef_1600x453.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><strong>Real-World Example</strong></h4><p>Many popular services, such as AWS SDK, Google Cloud client libraries, and Stripe API clients, use this strategy by default. This approach is considered the standard for reliable network communication.</p><h4><strong>Trade-offs</strong></h4><p>Retry strategies must balance reliability and user experience.</p><p>If the app takes too long to retry, the user may wait too long for a response. If it retries too quickly, it might overload the server.</p><p>To handle this, many systems use a <strong>circuit breaker</strong>.</p><p>A circuit breaker stops retrying after several failures and shows a clear error message instead of retrying forever.</p><p>After adding retries to handle network failures, another challenge arises: <em>what happens if the same request is sent many times?</em></p><p>Sometimes a request reaches the server successfully, but the response never reaches the app because the network drops.</p><p>If the app retries the request, it could perform the same action again&#8230;</p><h3><strong>7. Idempotency in APIs (Safe Retries)</strong></h3><p>In mobile apps, network requests can fail halfway through.</p><p>For example:</p><ol><li><p>App sends a request to the server</p></li><li><p>Server successfully processes it</p></li><li><p>But the response never reaches the app because the internet connection drops</p></li></ol><p>From the app&#8217;s perspective, the request appears to have failed, so it retries it. If the server processes the request again, the action may happen twice.</p><p>This is where <em>idempotency</em> becomes important.</p><p>Idempotency means sending the same request many times produces the same result, rather than repeating the action.</p><h4><strong>How Idempotency Works</strong></h4><p>To make retries safe, the client sends a unique identifier with each request, called an <strong>idempotency key</strong>. This key is usually a <strong>unique ID (UUID)</strong> generated by the app.</p><p>Example request header:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;plaintext&quot;,&quot;nodeId&quot;:&quot;9d58a35d-7e89-4dec-89db-42f1d512a615&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-plaintext">Idempotency-Key: 8f3c2c2e-92f1-4f9b-b8b0-1b0f1b1a3e3f</code></pre></div><p>When the server receives a request:</p><ol><li><p>It checks whether this key was used before.</p></li><li><p>If the key is new, the server processes the request normally.</p></li><li><p>If the same key appears again, the server <strong>does NOT repeat the action</strong>. Instead, it returns the previous response.</p></li></ol><p>This prevents duplicate operations.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!6ZuB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bc6cc48-71c4-4b91-8c65-9ef16db57d6b_1600x367.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!6ZuB!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bc6cc48-71c4-4b91-8c65-9ef16db57d6b_1600x367.png 424w, https://substackcdn.com/image/fetch/$s_!6ZuB!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bc6cc48-71c4-4b91-8c65-9ef16db57d6b_1600x367.png 848w, https://substackcdn.com/image/fetch/$s_!6ZuB!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bc6cc48-71c4-4b91-8c65-9ef16db57d6b_1600x367.png 1272w, https://substackcdn.com/image/fetch/$s_!6ZuB!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bc6cc48-71c4-4b91-8c65-9ef16db57d6b_1600x367.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!6ZuB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bc6cc48-71c4-4b91-8c65-9ef16db57d6b_1600x367.png" width="1456" height="334" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4bc6cc48-71c4-4b91-8c65-9ef16db57d6b_1600x367.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:334,&quot;width&quot;:1456,&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_!6ZuB!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bc6cc48-71c4-4b91-8c65-9ef16db57d6b_1600x367.png 424w, https://substackcdn.com/image/fetch/$s_!6ZuB!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bc6cc48-71c4-4b91-8c65-9ef16db57d6b_1600x367.png 848w, https://substackcdn.com/image/fetch/$s_!6ZuB!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bc6cc48-71c4-4b91-8c65-9ef16db57d6b_1600x367.png 1272w, https://substackcdn.com/image/fetch/$s_!6ZuB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bc6cc48-71c4-4b91-8c65-9ef16db57d6b_1600x367.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><h4><strong>Why It Matters</strong></h4><p>Imagine a user taps the <strong>&#8220;</strong>Pay<strong>&#8221;</strong> button.</p><ol><li><p>The payment request reaches the server.</p></li><li><p>Server processes the payment successfully.</p></li><li><p>But the response never reaches the phone because the network drops.</p></li></ol><p>So the user taps <strong>&#8220;</strong>Pay<strong>&#8221;</strong> again!</p><p>Without idempotency, the user might be charged twice.</p><p>This is why idempotency is extremely important for operations that change data.</p><h4><strong>Real-World Example</strong></h4><p>Many large systems rely on idempotency:</p><ul><li><p>Stripe requires an Idempotency-Key for payment API calls.</p></li><li><p>Uber uses idempotency keys for ride requests.</p></li><li><p>Most financial systems use this approach to prevent duplicate transactions.</p></li></ul><h4><strong>Trade-offs</strong></h4><p>To support idempotency, the server must store previously used keys and their responses for a period of time (typically 24 hours).</p><p>This requires some storage, but the cost is small compared to the problems caused by duplicate operations.</p><p>It&#8217;s also important to design the key carefully, usually combining:</p><ul><li><p>user ID</p></li><li><p>operation type</p></li><li><p>unique request ID</p></li></ul><h4><strong>Practical Tip</strong></h4><p>The idempotency key should be generated on the client before the request is sent. The app should also save the key locally.</p><p>If the app crashes or restarts, it can retry the request using the same key, ensuring the action is not repeated.</p><p>After making retries safe, the next step is to improve the app's efficiency when communicating with the server. One important way to do this is by reducing the number of network requests the app sends.</p><h3><strong>8. Request Batching &amp; Payload Optimisation</strong></h3><p>Every time a mobile app sends a request to the server, it adds latency and uses battery.</p><p>The total time for a request to reach the server and its response to return is called a <strong>network round-trip</strong>.</p><p>If an app sends many small requests separately, it can slow down the app and drain the device&#8217;s battery.</p><p>To solve this, use these two techniques:</p><ul><li><p>Request batching</p></li><li><p>Payload optimisation</p></li></ul><p><strong>a. Request Batching</strong></p><p>Request batching combines multiple requests into a single request.</p><p>Instead of doing this:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;plaintext&quot;,&quot;nodeId&quot;:&quot;380c69b6-60a6-4e09-99e8-dd2271ea4219&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-plaintext">App &#8594; Request 1
App &#8594; Request 2
App &#8594; Request 3</code></pre></div><p>The app sends one combined request:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;plaintext&quot;,&quot;nodeId&quot;:&quot;8c637ab1-4ce4-4d80-ba70-f2aa1d355925&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-plaintext">App &#8594; Batch Request (Request 1 + Request 2 + Request 3)</code></pre></div><p>This reduces the number of times the app needs to communicate with the server.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!SqRP!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff752d8ca-cbff-4fce-ba31-53c2b264c996_1341x617.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!SqRP!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff752d8ca-cbff-4fce-ba31-53c2b264c996_1341x617.png 424w, https://substackcdn.com/image/fetch/$s_!SqRP!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff752d8ca-cbff-4fce-ba31-53c2b264c996_1341x617.png 848w, https://substackcdn.com/image/fetch/$s_!SqRP!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff752d8ca-cbff-4fce-ba31-53c2b264c996_1341x617.png 1272w, https://substackcdn.com/image/fetch/$s_!SqRP!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff752d8ca-cbff-4fce-ba31-53c2b264c996_1341x617.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!SqRP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff752d8ca-cbff-4fce-ba31-53c2b264c996_1341x617.png" width="1341" height="617" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f752d8ca-cbff-4fce-ba31-53c2b264c996_1341x617.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:617,&quot;width&quot;:1341,&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_!SqRP!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff752d8ca-cbff-4fce-ba31-53c2b264c996_1341x617.png 424w, https://substackcdn.com/image/fetch/$s_!SqRP!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff752d8ca-cbff-4fce-ba31-53c2b264c996_1341x617.png 848w, https://substackcdn.com/image/fetch/$s_!SqRP!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff752d8ca-cbff-4fce-ba31-53c2b264c996_1341x617.png 1272w, https://substackcdn.com/image/fetch/$s_!SqRP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff752d8ca-cbff-4fce-ba31-53c2b264c996_1341x617.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>b. Payload Optimisation</strong></p><p>Payload is the data sent between the app and the server.</p><p>Payload optimisation focuses on reducing the amount of data being transferred.</p><p>This can be achieved by:</p><ul><li><p>Compression (like gzip or Brotli)</p></li><li><p>Sending only the needed fields</p></li><li><p>Using efficient formats like binary data instead of large text formats</p></li></ul><p>Reducing the app's payload size helps it load faster and use less network data.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ZpSR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60bdad54-c059-43c4-83cf-171fb9ec77de_1494x550.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ZpSR!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60bdad54-c059-43c4-83cf-171fb9ec77de_1494x550.png 424w, https://substackcdn.com/image/fetch/$s_!ZpSR!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60bdad54-c059-43c4-83cf-171fb9ec77de_1494x550.png 848w, https://substackcdn.com/image/fetch/$s_!ZpSR!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60bdad54-c059-43c4-83cf-171fb9ec77de_1494x550.png 1272w, https://substackcdn.com/image/fetch/$s_!ZpSR!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60bdad54-c059-43c4-83cf-171fb9ec77de_1494x550.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ZpSR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60bdad54-c059-43c4-83cf-171fb9ec77de_1494x550.png" width="1456" height="536" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/60bdad54-c059-43c4-83cf-171fb9ec77de_1494x550.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:536,&quot;width&quot;:1456,&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_!ZpSR!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60bdad54-c059-43c4-83cf-171fb9ec77de_1494x550.png 424w, https://substackcdn.com/image/fetch/$s_!ZpSR!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60bdad54-c059-43c4-83cf-171fb9ec77de_1494x550.png 848w, https://substackcdn.com/image/fetch/$s_!ZpSR!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60bdad54-c059-43c4-83cf-171fb9ec77de_1494x550.png 1272w, https://substackcdn.com/image/fetch/$s_!ZpSR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60bdad54-c059-43c4-83cf-171fb9ec77de_1494x550.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><strong>Why It Matters</strong></h4><p>On mobile devices, sending a request wakes up the device&#8217;s <strong>network radio</strong> (the hardware responsible for communication).</p><p>This wake-up process takes time and consumes battery.</p><p>For example:</p><ul><li><p>Sending 10 separate requests means the radio wakes up 10 times.</p></li><li><p>Sending 1 batched request wakes the radio only once.</p></li></ul><p>So batching requests can significantly reduce both latency and battery usage.</p><h4><strong>Real-World Example</strong></h4><p>Many popular apps use batching to improve performance.</p><ul><li><p>Facebook batches many GraphQL queries into a single HTTP request.</p></li><li><p>Instagram loads images gradually but fetches data for the next screen in a single batched request.</p></li></ul><p>This makes the app feel faster and smoother.</p><h4><strong>Trade-offs</strong></h4><p>Batching improves efficiency but also introduces challenges.</p><ul><li><p>If the app waits too long to collect requests before batching them, it can add extra delay.</p></li><li><p>Another challenge is handling errors. For example, if a batched request contains 10 operations and 3 fail, the system must handle those failures properly.</p></li></ul><p>To balance this, many systems use a short batching window, usually around 50&#8211;100 milliseconds, to collect requests before sending them together.</p><p>After reducing the number of network requests, another challenge appears when apps need to upload large files, such as photos, videos, or documents.</p><p>Large uploads can easily fail on mobile networks because connections may drop or become unstable. To handle this, apps use a technique called <strong>resumable uploads</strong>.</p><h3><strong>9. Resumable Uploads (Chunked Uploads)</strong></h3><p>When a mobile app uploads a large file, such as a 100MB video, sending the entire file in a single request is risky.</p><p>If the network disconnects halfway through the upload, the whole upload may fail. The app would have to start again from the beginning.</p><p>To avoid this problem, use resumable uploads, also called <em>chunked uploads</em>.</p><h4><strong>How Chunked Uploads Work</strong></h4><p>Instead of uploading the entire file at once, it&#8217;s split into smaller parts, called <strong>chunks</strong>.</p><p>For example, a 100MB file might be divided into 10 chunks of 10MB each, and each chunk is uploaded separately.</p><p>The process usually works like this:</p><ol><li><p>App starts the upload and creates an <strong>upload session</strong>.</p></li><li><p>Server returns a <strong>session ID </strong>or<strong> upload URL</strong>.</p></li><li><p>App uploads the file <strong>chunk by chunk</strong>.</p></li><li><p>Server keeps track of how much data it has already received.</p></li><li><p>If the network fails, the app asks the server <strong>where the upload stopped</strong>.</p></li><li><p>The upload continues from that point instead of starting from the beginning.</p></li></ol><p>This makes large uploads much more reliable on mobile networks.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!w3W4!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93c356ff-1dbd-44f9-801a-f9b4299c6c04_1600x303.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!w3W4!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93c356ff-1dbd-44f9-801a-f9b4299c6c04_1600x303.png 424w, https://substackcdn.com/image/fetch/$s_!w3W4!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93c356ff-1dbd-44f9-801a-f9b4299c6c04_1600x303.png 848w, https://substackcdn.com/image/fetch/$s_!w3W4!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93c356ff-1dbd-44f9-801a-f9b4299c6c04_1600x303.png 1272w, https://substackcdn.com/image/fetch/$s_!w3W4!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93c356ff-1dbd-44f9-801a-f9b4299c6c04_1600x303.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!w3W4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93c356ff-1dbd-44f9-801a-f9b4299c6c04_1600x303.png" width="1456" height="276" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/93c356ff-1dbd-44f9-801a-f9b4299c6c04_1600x303.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:276,&quot;width&quot;:1456,&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_!w3W4!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93c356ff-1dbd-44f9-801a-f9b4299c6c04_1600x303.png 424w, https://substackcdn.com/image/fetch/$s_!w3W4!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93c356ff-1dbd-44f9-801a-f9b4299c6c04_1600x303.png 848w, https://substackcdn.com/image/fetch/$s_!w3W4!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93c356ff-1dbd-44f9-801a-f9b4299c6c04_1600x303.png 1272w, https://substackcdn.com/image/fetch/$s_!w3W4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93c356ff-1dbd-44f9-801a-f9b4299c6c04_1600x303.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><h4><strong>Why It Matters</strong></h4><p>Mobile networks are often unstable.</p><p>Imagine uploading a 200MB video that reaches 99% when the network suddenly disconnects, causing the upload to fail&#8230;</p><p>Without resumable uploads, the app would have to restart the entire upload from the beginning, which wastes time, data, and battery.</p><p>With resumable uploads, the app can resume uploading from where it left off instead of starting over.</p><h4><strong>Real-World Example</strong></h4><p>Many popular apps use resumable uploads:</p><ul><li><p>YouTube for video uploads</p></li><li><p>Google Drive for file uploads</p></li><li><p>Dropbox for syncing files</p></li></ul><p>Any app that allows users to upload media usually uses this approach.</p><p>Even with reliable upload systems, mobile apps still face a major challenge: <em>network connections can drop at any time.</em></p><p>Users may lose connectivity when entering a subway tunnel, switching to airplane mode, or moving to an area with poor network coverage. Because of this, mobile apps must be designed to handle unstable or missing network connections without breaking.</p><h3><strong>10. Handling Intermittent Connectivity</strong></h3><p>Mobile apps should continue working as smoothly as possible even when the internet connection is weak or temporarily unavailable. Instead of failing immediately, the app should adapt to the network situation and recover when the connection returns.</p><p>Use these techniques to handle this:</p><p><strong>a. Local Request Queuing</strong></p><p>When the device is offline, the app can store user actions locally rather than sending them to the server immediately.</p><p>For example:</p><ol><li><p>A user sends a message.</p></li><li><p>The app saves the message locally.</p></li><li><p>When the internet connection returns, the app sends it to the server.</p></li></ol><p>This is called <strong>request queuing</strong>. The app keeps a list of pending actions and processes them once the network is available again.</p><p><strong>b. Optimistic UI</strong></p><p>Another common technique is optimistic UI.</p><p>With optimistic UI, the app updates the interface immediately, assuming the request will succeed.</p><p>For example:</p><ul><li><p>A user likes a post.</p></li><li><p>App shows the post as liked instantly.</p></li><li><p>Request is sent to the server in the background.</p></li></ul><p>If the request fails later, the app can correct the state.</p><p>This makes the app feel fast and responsive, even when the network is slow.</p><p><strong>c. Network State Awareness</strong></p><p>Apps can also monitor the device&#8217;s network status.</p><p>This allows the app to know when it is online, offline, or on a slow connection.</p><p>Based on this information, the app can adjust its behaviour. For example, it might delay data syncing while offline and resume syncing when connectivity returns.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!P2_3!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb05560eb-49fb-42ea-b215-6bb5dc1a60e4_1600x524.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!P2_3!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb05560eb-49fb-42ea-b215-6bb5dc1a60e4_1600x524.png 424w, https://substackcdn.com/image/fetch/$s_!P2_3!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb05560eb-49fb-42ea-b215-6bb5dc1a60e4_1600x524.png 848w, https://substackcdn.com/image/fetch/$s_!P2_3!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb05560eb-49fb-42ea-b215-6bb5dc1a60e4_1600x524.png 1272w, https://substackcdn.com/image/fetch/$s_!P2_3!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb05560eb-49fb-42ea-b215-6bb5dc1a60e4_1600x524.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!P2_3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb05560eb-49fb-42ea-b215-6bb5dc1a60e4_1600x524.png" width="1456" height="477" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b05560eb-49fb-42ea-b215-6bb5dc1a60e4_1600x524.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:477,&quot;width&quot;:1456,&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_!P2_3!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb05560eb-49fb-42ea-b215-6bb5dc1a60e4_1600x524.png 424w, https://substackcdn.com/image/fetch/$s_!P2_3!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb05560eb-49fb-42ea-b215-6bb5dc1a60e4_1600x524.png 848w, https://substackcdn.com/image/fetch/$s_!P2_3!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb05560eb-49fb-42ea-b215-6bb5dc1a60e4_1600x524.png 1272w, https://substackcdn.com/image/fetch/$s_!P2_3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb05560eb-49fb-42ea-b215-6bb5dc1a60e4_1600x524.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><strong>Why It Matters</strong></h4><p>Users frequently lose internet access during normal usage.</p><p>For example, in subway tunnels, on airplanes, or in areas with weak network coverage. If an app crashes, freezes, or loses user data, it feels unreliable.</p><p>Properly handling connectivity problems makes the app feel stable and trustworthy.</p><h4><strong>Real-World Example</strong></h4><p>Many modern apps handle intermittent connectivity this way:</p><ul><li><p>Notion queues edits locally and syncs them later.</p></li><li><p>Google Docs allows you to continue editing even when offline.</p></li><li><p>Messaging apps show a &#8220;sending&#8221; or &#8220;pending&#8221; status until the message is delivered.</p></li></ul><h4><strong>Practical Tip</strong></h4><p>Mobile operating systems provide built-in tools to monitor network connectivity:</p><ul><li><p><a href="https://developer.apple.com/documentation/network/nwpathmonitor">NWPathMonitor</a> on iOS</p></li><li><p><a href="https://developer.android.com/reference/android/net/ConnectivityManager">ConnectivityManager</a> on Android</p></li></ul><p>These tools notify the app when the network status changes.</p><p>This approach is event-driven and battery-efficient, unlike constantly checking the network in a loop.</p><p>Even with reliable networking strategies, mobile apps cannot always depend on an internet connection. To keep the app fast and usable even without internet access, developers use caching.</p><div><hr></div><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/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">Get the full premium newsletter series and max your system design career leverage:</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><h1><strong>Caching &amp; Offline</strong></h1><p>This section focuses on how mobile apps store and reuse data to reduce network requests and improve performance.</p><p>You&#8217;ll learn how caching strategies and offline-first approaches help apps stay fast and usable even when the internet is slow or unavailable.</p><h3><strong>11. On-Device Caching (Memory vs Disk)</strong></h3><p>Mobile apps usually store cached data in two places on the device:</p><ul><li><p>Memory (RAM)</p></li><li><p>Disk (device storage)</p></li></ul><p>Using both together creates a two-layer caching system.</p><p><strong>a. Memory Cache (RAM)</strong></p><p>Memory cache stores data in device RAM, which is extremely fast to access.</p><p>When data is stored in memory:</p><ul><li><p>App can load it almost instantly.</p></li><li><p>It avoids making a network request.</p></li></ul><p>Yet memory has a limitation:</p><ul><li><p>Data disappears when the app closes.</p></li><li><p>Operating system may remove cached data if the device runs low on memory.</p></li></ul><p>So memory caching is fast but temporary.</p><p><strong>b. Disk Cache (Storage)</strong></p><p>Disk cache stores data on the device&#8217;s permanent storage.</p><p>This means:</p><ul><li><p>Data remains available even after the app restarts.</p></li><li><p>App can load previously downloaded data without contacting the server again.</p></li></ul><p>But disk access is slower than memory access.</p><p>So disk caching is slower than RAM but more persistent.</p><h4><strong>Why It Matters</strong></h4><p>Fetching data from the server can take 50&#8211;500 milliseconds, depending on the network. But reading data from memory happens in nanoseconds, which is almost instantaneous.</p><p>So if the app can load data from the cache instead of the network, the user interface feels much faster. For example, profile pictures, app configurations, or recently viewed content.</p><p>These are perfect candidates for caching.</p><h4><strong>Real-World Example</strong></h4><p>Many image-loading libraries use this two-layer caching approach. For example, SDWebImage and Kingfisher.</p><p>When an image is requested:</p><ol><li><p>App first checks the <em>memory cache.</em></p></li><li><p>If it&#8217;s not there, it checks the <em>disk cache.</em></p></li><li><p>Only if both are missing does it requests image from the network.</p></li></ol><p>This makes images load almost instantly.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!jshU!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa9ecfb5-c5f3-4b64-b8c0-fc88de3a1201_1600x515.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!jshU!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa9ecfb5-c5f3-4b64-b8c0-fc88de3a1201_1600x515.png 424w, https://substackcdn.com/image/fetch/$s_!jshU!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa9ecfb5-c5f3-4b64-b8c0-fc88de3a1201_1600x515.png 848w, https://substackcdn.com/image/fetch/$s_!jshU!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa9ecfb5-c5f3-4b64-b8c0-fc88de3a1201_1600x515.png 1272w, https://substackcdn.com/image/fetch/$s_!jshU!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa9ecfb5-c5f3-4b64-b8c0-fc88de3a1201_1600x515.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!jshU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa9ecfb5-c5f3-4b64-b8c0-fc88de3a1201_1600x515.png" width="1456" height="469" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/aa9ecfb5-c5f3-4b64-b8c0-fc88de3a1201_1600x515.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:469,&quot;width&quot;:1456,&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_!jshU!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa9ecfb5-c5f3-4b64-b8c0-fc88de3a1201_1600x515.png 424w, https://substackcdn.com/image/fetch/$s_!jshU!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa9ecfb5-c5f3-4b64-b8c0-fc88de3a1201_1600x515.png 848w, https://substackcdn.com/image/fetch/$s_!jshU!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa9ecfb5-c5f3-4b64-b8c0-fc88de3a1201_1600x515.png 1272w, https://substackcdn.com/image/fetch/$s_!jshU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faa9ecfb5-c5f3-4b64-b8c0-fc88de3a1201_1600x515.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><strong>Trade-offs</strong></h4><p>Both types of caching have advantages and limitations:</p><ul><li><p><strong>Memory Cache:</strong> Extremely fast, but cleared when the app closes.</p></li><li><p><strong>Disk Cache:</strong> Data remains available after restarting the app, but reading from disk is slower than memory.</p></li></ul><p>Cache size also needs to be controlled carefully.</p><p>If too much memory is used for caching, the operating system may remove the cached data or close the app to free memory.</p><h4><strong>Practical Tip</strong></h4><p>Mobile platforms provide built-in caching tools that automatically manage memory. For example, NSCache on iOS and LruCache on Android.</p><p>These systems automatically remove older items from memory when the device is running low on resources. This helps prevent the app from using too much memory.</p><p>Using simple data structures like dictionaries or hash maps for caching is NOT ideal, because they do not automatically respond to memory pressure. As a result, they may keep too much data in memory, increasing the risk that the app will be terminated by the operating system.</p><p>Local caching stores data on the device, which helps apps load faster.</p><p>But the internet itself also has built-in caching mechanisms that can reduce unnecessary network requests. This is where HTTP caching becomes useful.</p><h3><strong>12. HTTP Caching (ETag, Cache-Control)</strong></h3><p>HTTP caching allows apps and browsers to reuse previously downloaded responses instead of requesting the same data again.</p><p>This is controlled using special HTTP headers, <code>Cache-Control</code>, and <code>ETag</code>. These headers tell the app two important things:</p><ul><li><p>How long can cached data be reused</p></li><li><p>How to check if the data has changed</p></li></ul><p><strong>a. Cache-Control</strong></p><p>This header tells the app how long it can reuse the cached data before asking the server again.</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;plaintext&quot;,&quot;nodeId&quot;:&quot;30915655-115f-46f2-88f3-06395de74a23&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-plaintext">Cache-Control: max-age=300</code></pre></div><p>This means the response can be reused for 300 seconds (5 minutes).</p><p>During those 5 minutes, the app can load the data directly from cache instead of making a new request to the server.</p><p>This improves speed and reduces network usage.</p><p><strong>b. ETag</strong></p><p>An ETag is a unique identifier that represents a specific version of the data.</p><p>When the server sends a response, it also includes an ETag value:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;plaintext&quot;,&quot;nodeId&quot;:&quot;e492e2de-6397-4716-b569-d25c84598b74&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-plaintext">ETag: &#8220;abc123&#8221;</code></pre></div><p>When the app requests the same data again, it sends that value back to the server:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;plaintext&quot;,&quot;nodeId&quot;:&quot;f4246bd4-52c8-43bc-a34f-fc2a1fe458d6&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-plaintext">If-None-Match: &#8220;abc123&#8221;</code></pre></div><p>The server checks whether the data has changed:</p><ul><li><p>If the data has NOT changed, the server returns <code>304 Not Modified</code> with no response body.</p></li><li><p>If the data has changed, the server sends the new data.</p></li></ul><p>This saves bandwidth because the server does NOT need to resend the entire response.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!XC3I!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f9ce961-68e7-4111-a302-aa7b1dc50f55_1600x699.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!XC3I!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f9ce961-68e7-4111-a302-aa7b1dc50f55_1600x699.png 424w, https://substackcdn.com/image/fetch/$s_!XC3I!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f9ce961-68e7-4111-a302-aa7b1dc50f55_1600x699.png 848w, https://substackcdn.com/image/fetch/$s_!XC3I!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f9ce961-68e7-4111-a302-aa7b1dc50f55_1600x699.png 1272w, https://substackcdn.com/image/fetch/$s_!XC3I!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f9ce961-68e7-4111-a302-aa7b1dc50f55_1600x699.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!XC3I!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f9ce961-68e7-4111-a302-aa7b1dc50f55_1600x699.png" width="1456" height="636" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9f9ce961-68e7-4111-a302-aa7b1dc50f55_1600x699.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:636,&quot;width&quot;:1456,&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_!XC3I!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f9ce961-68e7-4111-a302-aa7b1dc50f55_1600x699.png 424w, https://substackcdn.com/image/fetch/$s_!XC3I!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f9ce961-68e7-4111-a302-aa7b1dc50f55_1600x699.png 848w, https://substackcdn.com/image/fetch/$s_!XC3I!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f9ce961-68e7-4111-a302-aa7b1dc50f55_1600x699.png 1272w, https://substackcdn.com/image/fetch/$s_!XC3I!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f9ce961-68e7-4111-a302-aa7b1dc50f55_1600x699.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><strong>Why It Matters</strong></h4><p>HTTP caching reduces unnecessary network requests.</p><p>For example, if an API response is 200 KB, returning a <code>304 Not Modified</code> response avoids downloading that 200 KB again.</p><p>This helps improve app performance, network efficiency, and battery usage. The best part is that HTTP caching works automatically when the correct headers are set.</p><h4><strong>Real-World Example</strong></h4><p>A news app might load a list of articles using an API. The server might return a header like this:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;plaintext&quot;,&quot;nodeId&quot;:&quot;ccec6c50-4ba7-4d51-980b-6aec6e4b0f70&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-plaintext">Cache-Control: max-age=60, stale-while-revalidate=300</code></pre></div><p>This means cached response can be used for 60 seconds. After that, the app can still show the cached content while checking for updates in the background.</p><p>As a result, the articles appear instantly without showing a loading spinner.</p><h4><strong>Trade-offs</strong></h4><p>Different caching strategies have different advantages:</p><ul><li><p><strong>Strong caching (long max-age): </strong>Faster loading and fewer network requests, but the data may become outdated.</p></li><li><p><strong>Weak caching (ETag validation): </strong>Always checks if data is fresh, but still requires a small network request.</p></li></ul><p>Because of this, cache durations should match the frequency of data changes.</p><p>Caching helps apps load data faster, but it still depends on the network at some point. When the network connection disappears completely, caching alone cannot solve the problem.</p><p>To keep apps usable even without a network connection, many apps use a design approach called <em>offline-first architecture.</em></p><h3><strong>13. Offline-First Architecture</strong></h3><p>Offline-first architecture means the app is designed to work normally even without a network connection.</p><p>Instead of always asking the server for data, the app mainly works with data stored locally on the device. The app shows and updates local data first, and then synchronises changes with the server when the network becomes available.</p><p>This approach helps the app stay fast and responsive, even when the network is slow or unavailable.</p><h4><strong>How It Works</strong></h4><p>In an offline-first system, the app reads and writes data from local storage first.</p><p>The process usually works like this:</p><ol><li><p>The app reads data from the local database instead of requesting it from the server.</p></li><li><p>When the user makes a change, the app updates the local database immediately.</p></li><li><p>A background process then sends those changes to the server when a connection is available.</p></li><li><p>If the server has new updates, the app downloads them and updates the local database.</p></li><li><p>When the local data changes, the app automatically updates the user interface.</p></li></ol><p>Because the UI always reads from local data, the app feels fast and responsive.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!L_ER!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F96e35bc1-ca02-4cc4-975c-1e1ad1f8f505_1411x662.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!L_ER!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F96e35bc1-ca02-4cc4-975c-1e1ad1f8f505_1411x662.png 424w, https://substackcdn.com/image/fetch/$s_!L_ER!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F96e35bc1-ca02-4cc4-975c-1e1ad1f8f505_1411x662.png 848w, https://substackcdn.com/image/fetch/$s_!L_ER!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F96e35bc1-ca02-4cc4-975c-1e1ad1f8f505_1411x662.png 1272w, https://substackcdn.com/image/fetch/$s_!L_ER!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F96e35bc1-ca02-4cc4-975c-1e1ad1f8f505_1411x662.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!L_ER!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F96e35bc1-ca02-4cc4-975c-1e1ad1f8f505_1411x662.png" width="1411" height="662" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/96e35bc1-ca02-4cc4-975c-1e1ad1f8f505_1411x662.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:662,&quot;width&quot;:1411,&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_!L_ER!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F96e35bc1-ca02-4cc4-975c-1e1ad1f8f505_1411x662.png 424w, https://substackcdn.com/image/fetch/$s_!L_ER!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F96e35bc1-ca02-4cc4-975c-1e1ad1f8f505_1411x662.png 848w, https://substackcdn.com/image/fetch/$s_!L_ER!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F96e35bc1-ca02-4cc4-975c-1e1ad1f8f505_1411x662.png 1272w, https://substackcdn.com/image/fetch/$s_!L_ER!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F96e35bc1-ca02-4cc4-975c-1e1ad1f8f505_1411x662.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><strong>Why It Matters</strong></h4><p>Apps that depend entirely on the network often feel slow.</p><p>Every action requires a request to the server, which can take 100&#8211;300 milliseconds or more. This delay often appears as loading spinners.</p><p>Offline-first apps avoid this problem.</p><p>Since the UI reads from local data, interactions feel instant, while the network syncing happens quietly in the background.</p><h4><strong>Real-World Example</strong></h4><p>Many popular apps use an offline-first architecture:</p><ul><li><p>Spotify downloads playlists so they can be played without internet.</p></li><li><p>Notion saves edits locally and syncs them later.</p></li><li><p>Google Maps stores map tiles for offline navigation.</p></li></ul><p>Apps dealing with media, productivity, or travel benefit from this approach.</p><h4><strong>Trade-offs</strong></h4><p>Offline-first systems provide a better user experience, but they are complex to build.</p><p>They require:</p><ul><li><p>Local database to store data</p></li><li><p>Sync system to send and receive updates</p></li><li><p>A way to handle conflicts when local and server data differ</p></li><li><p>Plan for updating the data structure over time</p></li></ul><p>Because of this complexity, an offline-first design usually needs to be planned early in app development.</p><p>Caching helps apps reuse data locally, but another challenge is delivering large files like images and videos efficiently. These files often make up most of the data in app downloads.</p><p>To improve speed and reduce data usage, use techniques like CDNs and media optimisation.</p><h3><strong>14. CDN Strategy &amp; Media Optimisation</strong></h3><p>Images and videos usually make up a large part of the data used by mobile apps.</p><p>To deliver this content quickly and efficiently, apps often rely on Content Delivery Networks (<strong>CDNs</strong>) and various optimisation techniques. A CDN is a network of servers distributed around the world. Instead of downloading content from a central server, the app downloads it from the nearest server, reducing load time.</p><p>While media files can be optimised, the app only downloads what it actually needs.</p><h4><strong>What a CDN Does</strong></h4><p>When a user opens an app and requests an image/video:</p><ol><li><p>The request is sent to the closest CDN server.</p></li><li><p>CDN returns the file from a nearby location instead of a distant server.</p></li><li><p>The content loads faster because the distance and network delay are reduced.</p></li></ol><p>This speeds up and improves the reliability of content delivery, especially for users in different parts of the world.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!bpIB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6788c34d-b98c-4d80-a1a8-aef1f92338ad_1451x575.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!bpIB!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6788c34d-b98c-4d80-a1a8-aef1f92338ad_1451x575.png 424w, https://substackcdn.com/image/fetch/$s_!bpIB!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6788c34d-b98c-4d80-a1a8-aef1f92338ad_1451x575.png 848w, https://substackcdn.com/image/fetch/$s_!bpIB!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6788c34d-b98c-4d80-a1a8-aef1f92338ad_1451x575.png 1272w, https://substackcdn.com/image/fetch/$s_!bpIB!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6788c34d-b98c-4d80-a1a8-aef1f92338ad_1451x575.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!bpIB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6788c34d-b98c-4d80-a1a8-aef1f92338ad_1451x575.png" width="1451" height="575" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6788c34d-b98c-4d80-a1a8-aef1f92338ad_1451x575.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:575,&quot;width&quot;:1451,&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_!bpIB!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6788c34d-b98c-4d80-a1a8-aef1f92338ad_1451x575.png 424w, https://substackcdn.com/image/fetch/$s_!bpIB!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6788c34d-b98c-4d80-a1a8-aef1f92338ad_1451x575.png 848w, https://substackcdn.com/image/fetch/$s_!bpIB!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6788c34d-b98c-4d80-a1a8-aef1f92338ad_1451x575.png 1272w, https://substackcdn.com/image/fetch/$s_!bpIB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6788c34d-b98c-4d80-a1a8-aef1f92338ad_1451x575.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><strong>Media Optimisation</strong></h4><p>Another important improvement is optimising the size and format of images and videos.</p><p>Some common techniques include:</p><ul><li><p><strong>Image resizing:</strong> Instead of sending a large image (e.g., 4K), the server sends a smaller version that fits the device screen, such as 200&#215;200 pixels.</p></li><li><p><strong>Modern image formats:</strong> Newer formats like WebP or AVIF store images more efficiently than older formats like JPEG or PNG. They provide similar image quality with smaller file sizes.</p></li><li><p><strong>Lazy loading:</strong> Images are loaded only when they are about to appear on the screen. This avoids downloading content that the user might never see.</p></li></ul><p>Together, these techniques significantly reduce data usage and improve loading speed.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!WM5e!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3509288-42cf-43d4-9180-acb2aa16f469_1600x478.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!WM5e!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3509288-42cf-43d4-9180-acb2aa16f469_1600x478.png 424w, https://substackcdn.com/image/fetch/$s_!WM5e!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3509288-42cf-43d4-9180-acb2aa16f469_1600x478.png 848w, https://substackcdn.com/image/fetch/$s_!WM5e!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3509288-42cf-43d4-9180-acb2aa16f469_1600x478.png 1272w, https://substackcdn.com/image/fetch/$s_!WM5e!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3509288-42cf-43d4-9180-acb2aa16f469_1600x478.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!WM5e!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3509288-42cf-43d4-9180-acb2aa16f469_1600x478.png" width="1456" height="435" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f3509288-42cf-43d4-9180-acb2aa16f469_1600x478.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:435,&quot;width&quot;:1456,&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_!WM5e!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3509288-42cf-43d4-9180-acb2aa16f469_1600x478.png 424w, https://substackcdn.com/image/fetch/$s_!WM5e!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3509288-42cf-43d4-9180-acb2aa16f469_1600x478.png 848w, https://substackcdn.com/image/fetch/$s_!WM5e!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3509288-42cf-43d4-9180-acb2aa16f469_1600x478.png 1272w, https://substackcdn.com/image/fetch/$s_!WM5e!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3509288-42cf-43d4-9180-acb2aa16f469_1600x478.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><strong>Why It Matters</strong></h4><p>Large media files can slow down apps and consume a lot of mobile data.</p><p>For example, loading a 4MB image on a small phone screen wastes most of its pixels because the device only displays a small portion of the image&#8217;s resolution.</p><p>Serving images that match the device size <a href="https://imageengine.io/improve-pagespeed-image-cdn-vs-traditional-cdn/">can reduce total data usage by up to 80%</a>, making the app faster and more efficient.</p><h4><strong>Real-World Example</strong></h4><p>Many popular apps rely on CDN and media optimisation:</p><ul><li><p>Cloudinary and Imgix dynamically resize images based on URL parameters.</p></li><li><p>Instagram serves images that match the exact resolution of the user&#8217;s device.</p></li><li><p>On modern Android devices, Instagram also uses the AVIF format to reduce image size.</p></li></ul><h4><strong>Trade-offs</strong></h4><p>Using a CDN improves performance but introduces additional cost, as CDN providers charge based on data transfer.</p><p>As a result, CDN assets are usually cached for long periods. Apps often use versioned or hashed URLs to update assets. This process ensures that the new version gets downloaded when needed.</p><h4><strong>Practical Tip</strong></h4><p>To make images appear faster, apps often show a temporary low-quality preview while the full image loads.</p><p>Techniques like <a href="https://blurha.sh/">BlurHash</a> or <a href="https://cloudinary.com/blog/low_quality_image_placeholders_lqip_explained">LQIP (Low Quality Image Placeholder)</a> display a blurred or low-resolution version first. This makes the page feel fast, even before the high-quality image finishes loading.</p><p>Even with strong caching and efficient content delivery, one important challenge remains: <em>keeping cached data accurate and up to date.</em></p><h3><strong>15. Cache Invalidation Strategies</strong></h3><p>Caching helps apps load data faster by storing it locally.</p><p>But cached data can become outdated when the original data on the server changes. Because of this, apps need a way to update or remove old cached data. This process is called <strong>cache invalidation</strong>.</p><p>In simple terms, cache invalidation means deciding when cached data should no longer be used and needs to be refreshed.</p><h4><strong>Why It Matters</strong></h4><p>If outdated data stays in the cache for too long, the app may show incorrect information.</p><p>For example, a user might see an old product price, a deleted message, or an outdated address. In these situations, showing stale cached data can be worse than not using a cache at all.</p><p>That&#8217;s why managing cached data correctly is very important!</p><h4><strong>Common Cache Invalidation Strategies</strong></h4><p>There are several common ways to control when cached data should expire or update:</p><p><strong>a. TTL (Time-To-Live)</strong></p><p>TTL means cached data is only valid for a certain amount of time.</p><p>For example, if a cache has a TTL of 5 minutes, the app will reuse the cached data for five minutes. After that, it must fetch fresh data from the server.</p><p>This approach is simple but may briefly show outdated data.</p><p><strong>b. Event-Driven Invalidation</strong></p><p>In this approach, the server actively tells the app when cached data is no longer valid.</p><p>For example, a product price changes, and the server sends an event to clear or update the cache.</p><p>This ensures the app always shows the latest data, but it requires more complex systems to send these updates.</p><p><strong>c. Stale-While-Revalidate</strong></p><p>This strategy allows the app to show cached data immediately, even if it is slightly outdated.</p><p>The app quietly requests fresh data in the background. When the new data arrives, the cache is updated.</p><p>This approach improves the user experience by loading the app instantly while keeping data up to date.</p><p><strong>d. Versioned URLs</strong></p><p>Sometimes cached assets like images or style sheets are stored for a very long time.</p><p>To update them safely, the filename or URL includes a version or hash.</p><p>Example:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;plaintext&quot;,&quot;nodeId&quot;:&quot;36849cbe-157e-4e80-82ff-5b71caac2b92&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-plaintext">style.abc123.css</code></pre></div><p>When the file changes, the version in the URL changes. Because the URL is different, the cache automatically downloads the new 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_!eQk5!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d7bb3ca-e3b2-4196-929f-f0a1cf9a9173_1471x843.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!eQk5!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d7bb3ca-e3b2-4196-929f-f0a1cf9a9173_1471x843.png 424w, https://substackcdn.com/image/fetch/$s_!eQk5!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d7bb3ca-e3b2-4196-929f-f0a1cf9a9173_1471x843.png 848w, https://substackcdn.com/image/fetch/$s_!eQk5!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d7bb3ca-e3b2-4196-929f-f0a1cf9a9173_1471x843.png 1272w, https://substackcdn.com/image/fetch/$s_!eQk5!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d7bb3ca-e3b2-4196-929f-f0a1cf9a9173_1471x843.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!eQk5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d7bb3ca-e3b2-4196-929f-f0a1cf9a9173_1471x843.png" width="1456" height="834" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8d7bb3ca-e3b2-4196-929f-f0a1cf9a9173_1471x843.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:834,&quot;width&quot;:1456,&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_!eQk5!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d7bb3ca-e3b2-4196-929f-f0a1cf9a9173_1471x843.png 424w, https://substackcdn.com/image/fetch/$s_!eQk5!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d7bb3ca-e3b2-4196-929f-f0a1cf9a9173_1471x843.png 848w, https://substackcdn.com/image/fetch/$s_!eQk5!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d7bb3ca-e3b2-4196-929f-f0a1cf9a9173_1471x843.png 1272w, https://substackcdn.com/image/fetch/$s_!eQk5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d7bb3ca-e3b2-4196-929f-f0a1cf9a9173_1471x843.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><strong>Real-World Example</strong></h4><p>An e-commerce app might use different caching strategies depending on the data.</p><p>For example:</p><ul><li><p>Product listings may use a TTL of 5 minutes, since a short delay in updates is acceptable.</p></li><li><p>Inventory or pricing data may use event-driven invalidation because it must always be accurate.</p></li><li><p>Static assets, such as images or stylesheets, can use versioned URLs, allowing them to be cached for a long time.</p></li></ul><h4><strong>Trade-offs</strong></h4><p>Each caching strategy has its advantages and limitations:</p><ul><li><p><strong>TTL-based caching:</strong> Simple to implement, but cached data may briefly become outdated.</p></li><li><p><strong>Event-driven invalidation:</strong> Keeps data accurate but requires more complex infrastructure.</p></li><li><p><strong>Stale-while-revalidate:</strong> Makes the app feel fast, but temporarily shows slightly outdated data.</p></li></ul><h4><strong>Important Tip</strong></h4><p>Caches should never have infinite expiration times for data that changes frequently.</p><p>If cached data never expires, the app may continue showing outdated information, making it difficult to detect and debug.</p><p>Once data is cached or fetched, the app also needs a reliable way to store and organise that data locally, which leads to the next part: <em>storage and database design.</em></p><div><hr></div><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/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">Get the full premium newsletter series and max your system design career leverage:</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><h1><strong>Storage &amp; Data</strong></h1><p>Mobile apps need efficient ways to store and manage data on the device.</p><p>This section explains how local databases, schema design, and pagination help apps handle large datasets while maintaining smooth performance on resource-limited devices.</p><h3><strong>16. Local Database Design (Schema Modeling)</strong></h3><p>Mobile apps often store data locally on the device so they can load information quickly and continue working even when the network is slow or unavailable.</p><p>To do this, apps use local databases such as SQLite, which is commonly used on both Android and iOS. A database schema simply describes how data is organised in the database. It defines tables, columns, and how different pieces of data are connected.</p><p>Good schema design is important because it helps the app load and display data quickly.</p><h4><strong>How Data Is Often Structured on Mobile</strong></h4><p>On servers, databases are usually designed to avoid duplicating data across many places. This approach is called <strong>normalisation</strong>.</p><p>But mobile apps often use a slightly different approach called <strong>denormalisation</strong>.</p><p>Denormalisation involves storing related data in the same table, enabling quick reads without complex queries.</p><p>This helps mobile apps load data faster because the app does NOT need to combine multiple tables every time it displays information.</p><h4><strong>Why It Matters</strong></h4><p>Mobile apps need to display data quickly.</p><p>For example, imagine an app showing a list of 50,000 messages. If the database is poorly designed, finding the right messages might take much longer than expected.</p><p>A missing <strong>index</strong> (a structure that helps the database locate data quickly) can cause the database to scan every row in a table. This can turn a 1-millisecond query into a 500-millisecond query, causing visible delays or lag in the user interface.</p><p>So the way a database is designed directly affects how smooth the app feels.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!KAJK!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c075758-73c7-42b9-a870-b96a1d14dc2a_1600x539.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!KAJK!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c075758-73c7-42b9-a870-b96a1d14dc2a_1600x539.png 424w, https://substackcdn.com/image/fetch/$s_!KAJK!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c075758-73c7-42b9-a870-b96a1d14dc2a_1600x539.png 848w, https://substackcdn.com/image/fetch/$s_!KAJK!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c075758-73c7-42b9-a870-b96a1d14dc2a_1600x539.png 1272w, https://substackcdn.com/image/fetch/$s_!KAJK!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c075758-73c7-42b9-a870-b96a1d14dc2a_1600x539.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!KAJK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c075758-73c7-42b9-a870-b96a1d14dc2a_1600x539.png" width="1456" height="490" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6c075758-73c7-42b9-a870-b96a1d14dc2a_1600x539.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:490,&quot;width&quot;:1456,&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_!KAJK!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c075758-73c7-42b9-a870-b96a1d14dc2a_1600x539.png 424w, https://substackcdn.com/image/fetch/$s_!KAJK!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c075758-73c7-42b9-a870-b96a1d14dc2a_1600x539.png 848w, https://substackcdn.com/image/fetch/$s_!KAJK!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c075758-73c7-42b9-a870-b96a1d14dc2a_1600x539.png 1272w, https://substackcdn.com/image/fetch/$s_!KAJK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c075758-73c7-42b9-a870-b96a1d14dc2a_1600x539.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><strong>Real-World Example</strong></h4><p>Consider a messaging app.</p><p>Instead of storing only a user ID with each message, the app may also store the sender&#8217;s name and profile image directly inside the message record.</p><p>This means the app can display messages immediately without looking up additional data from another table.</p><p>This approach speeds up loading when thousands of messages need to be shown quickly.</p><h4><strong>Trade-offs</strong></h4><p>Each database design approach has advantages and disadvantages:</p><ul><li><p><strong>Denormalised structure: </strong>Faster data reading and works well for displaying lists in the UI, but updating repeated data can be harder. For example, if a user changes their name, multiple records may need to be updated.</p></li><li><p><strong>Normalised structure: </strong>Cleaner, more organised, and easier to maintain consistent data, but requires more complex queries, which may slow down UI rendering.</p></li></ul><p>Because mobile apps mostly read data to display it on the screen, they often prefer denormalised structures for faster reads.</p><h4><strong>Practical Tip</strong></h4><p>When writing many records to the database, it&#8217;s usually faster to group them into a single transaction.</p><p>Instead of saving each item one by one, the app saves many items together in a single operation. This reduces overhead and makes database writes much more efficient.</p><p>As apps grow and evolve over time, the database structure may need to change as well. Because of this, apps must handle database schema updates carefully, which leads to the next topic: <em>schema migration strategies.</em></p><h3><strong>17. Schema Migration Strategy</strong></h3><p>Mobile apps often store data in a local database on the device.</p><p>Over time, the app may change how this data is structured. For example, a new version of the app might add a new column, change a table, or introduce new data fields.</p><p>When this happens, the database structure must be updated safely. This process is called <strong>schema migration</strong>.</p><p>A schema migration ensures that the existing database on a user&#8217;s device is updated to match the new version of the app.</p><h4><strong>Why It Matters</strong></h4><p>Unlike a web server, mobile databases exist on millions of individual devices that developers cannot directly control.</p><p>Some users may update the app immediately, while others may skip several versions before updating. For example, a user installs version 1 of an app and later updates directly to version 5.</p><p>The database must correctly apply every change that happened between those versions. So the migrations must run step-by-step:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;plaintext&quot;,&quot;nodeId&quot;:&quot;b17fbb8a-048a-4455-a49f-9b445d37fb20&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-plaintext">1 &#8594; 2 &#8594; 3 &#8594; 4 &#8594; 5</code></pre></div><p>If a migration fails, the app may crash on launch. Because the database exists on the user&#8217;s device, fixing it later can be difficult&#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_!qDff!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e41d26f-d812-4eb4-9d94-78b3ae1c39db_1600x599.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!qDff!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e41d26f-d812-4eb4-9d94-78b3ae1c39db_1600x599.png 424w, https://substackcdn.com/image/fetch/$s_!qDff!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e41d26f-d812-4eb4-9d94-78b3ae1c39db_1600x599.png 848w, https://substackcdn.com/image/fetch/$s_!qDff!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e41d26f-d812-4eb4-9d94-78b3ae1c39db_1600x599.png 1272w, https://substackcdn.com/image/fetch/$s_!qDff!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e41d26f-d812-4eb4-9d94-78b3ae1c39db_1600x599.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!qDff!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e41d26f-d812-4eb4-9d94-78b3ae1c39db_1600x599.png" width="1456" height="545" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7e41d26f-d812-4eb4-9d94-78b3ae1c39db_1600x599.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:545,&quot;width&quot;:1456,&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_!qDff!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e41d26f-d812-4eb4-9d94-78b3ae1c39db_1600x599.png 424w, https://substackcdn.com/image/fetch/$s_!qDff!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e41d26f-d812-4eb4-9d94-78b3ae1c39db_1600x599.png 848w, https://substackcdn.com/image/fetch/$s_!qDff!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e41d26f-d812-4eb4-9d94-78b3ae1c39db_1600x599.png 1272w, https://substackcdn.com/image/fetch/$s_!qDff!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e41d26f-d812-4eb4-9d94-78b3ae1c39db_1600x599.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><strong>Real-World Example</strong></h4><p>Many mobile frameworks provide tools to manage database migrations.</p><p>For example, Room on Android requires every database version to define how the schema should be updated.</p><p>This helps prevent mistakes where the app changes the database structure without providing a safe upgrade path.</p><h4><strong>Trade-offs</strong></h4><p>There are two main ways to handle schema changes:</p><p><strong>a. Destructive Migration</strong></p><p>In this approach, the app deletes the existing database and creates a new one.</p><p>This is simple and safe for the app structure, but it removes all locally stored data.</p><p><strong>b. Additive Migration</strong></p><p>In this approach, the database is updated without deleting existing data.</p><p>For example, adding new columns, adding new tables, and keeping old data intact.</p><p>This method is usually preferred because it preserves user data.</p><h4><strong>Practical Tip</strong></h4><p>Sometimes migrations may fail due to issues like a corrupted database.</p><p>In these situations, it is better for the app to reset the database and re-download the data from the server rather than crash. Losing cached data can be recovered, but an app that keeps crashing when it starts creates a much worse experience.</p><p>As apps handle larger amounts of stored data, another important challenge appears: loading and displaying large datasets efficiently, which is where pagination becomes useful.</p><h3><strong>18. Pagination (Cursor vs Offset vs Page Number)</strong></h3><p>Mobile apps often display long lists of data, such as messages, posts, products, or search results.</p><p>Sometimes these lists can contain thousands of items.</p><p>Loading all of that data at once would be slow and would use a lot of memory. Because of this, apps usually load data in smaller chunks called <strong>pages</strong>. This technique is called <strong>pagination</strong>.</p><p>Pagination helps apps load content gradually as users scroll, keeping the app fast and responsive.</p><h4><strong>How It Works</strong></h4><p>Instead of loading everything at once, the app requests a small set of items at a time.</p><p>For example:</p><ol><li><p>App requests page 1 of data.</p></li><li><p>The server returns the first group of items.</p></li><li><p>When the user scrolls further, the app requests the next page.</p></li></ol><p>This process continues until the user reaches the end of the list&#8230;</p><h4><strong>Common Pagination Methods</strong></h4><p>There are three common ways to implement pagination:</p><p><strong>a. Page Number Pagination</strong></p><p>This is the simplest method. The client requests data using page numbers.</p><p>For example:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;plaintext&quot;,&quot;nodeId&quot;:&quot;0d9e305f-49d1-40ac-ba44-a2ae93b7ab5d&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-plaintext">?page=1
?page=2
?page=3</code></pre></div><p>Each page contains a fixed number of items.</p><p>This approach is easy to understand and works well for things like search results or product listings.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!5J9w!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F41040c41-f786-4d9f-848a-d25bead94c58_1376x530.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!5J9w!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F41040c41-f786-4d9f-848a-d25bead94c58_1376x530.png 424w, https://substackcdn.com/image/fetch/$s_!5J9w!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F41040c41-f786-4d9f-848a-d25bead94c58_1376x530.png 848w, https://substackcdn.com/image/fetch/$s_!5J9w!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F41040c41-f786-4d9f-848a-d25bead94c58_1376x530.png 1272w, https://substackcdn.com/image/fetch/$s_!5J9w!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F41040c41-f786-4d9f-848a-d25bead94c58_1376x530.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!5J9w!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F41040c41-f786-4d9f-848a-d25bead94c58_1376x530.png" width="1376" height="530" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/41040c41-f786-4d9f-848a-d25bead94c58_1376x530.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:530,&quot;width&quot;:1376,&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_!5J9w!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F41040c41-f786-4d9f-848a-d25bead94c58_1376x530.png 424w, https://substackcdn.com/image/fetch/$s_!5J9w!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F41040c41-f786-4d9f-848a-d25bead94c58_1376x530.png 848w, https://substackcdn.com/image/fetch/$s_!5J9w!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F41040c41-f786-4d9f-848a-d25bead94c58_1376x530.png 1272w, https://substackcdn.com/image/fetch/$s_!5J9w!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F41040c41-f786-4d9f-848a-d25bead94c58_1376x530.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>b. Offset Pagination</strong></p><p>Offset pagination retrieves data starting from a specific position.</p><p>For example:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;plaintext&quot;,&quot;nodeId&quot;:&quot;56c6dff5-cfe3-422a-b9e7-8f2273a3da26&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-plaintext">?limit=20&amp;offset=40</code></pre></div><p>This means skip the first 40 items and return the next 20 items.</p><p>This method works well for static data, but dynamically adding new items while the user is browsing can cause problems.</p><p>For example, if new posts appear at the top of a feed, the list may show duplicate items or skip items.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!L_0v!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F465bb9eb-0156-4845-a4bb-1cbcc2d4d375_1204x646.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!L_0v!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F465bb9eb-0156-4845-a4bb-1cbcc2d4d375_1204x646.png 424w, https://substackcdn.com/image/fetch/$s_!L_0v!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F465bb9eb-0156-4845-a4bb-1cbcc2d4d375_1204x646.png 848w, https://substackcdn.com/image/fetch/$s_!L_0v!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F465bb9eb-0156-4845-a4bb-1cbcc2d4d375_1204x646.png 1272w, https://substackcdn.com/image/fetch/$s_!L_0v!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F465bb9eb-0156-4845-a4bb-1cbcc2d4d375_1204x646.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!L_0v!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F465bb9eb-0156-4845-a4bb-1cbcc2d4d375_1204x646.png" width="1204" height="646" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/465bb9eb-0156-4845-a4bb-1cbcc2d4d375_1204x646.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:646,&quot;width&quot;:1204,&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_!L_0v!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F465bb9eb-0156-4845-a4bb-1cbcc2d4d375_1204x646.png 424w, https://substackcdn.com/image/fetch/$s_!L_0v!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F465bb9eb-0156-4845-a4bb-1cbcc2d4d375_1204x646.png 848w, https://substackcdn.com/image/fetch/$s_!L_0v!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F465bb9eb-0156-4845-a4bb-1cbcc2d4d375_1204x646.png 1272w, https://substackcdn.com/image/fetch/$s_!L_0v!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F465bb9eb-0156-4845-a4bb-1cbcc2d4d375_1204x646.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>c. Cursor Pagination</strong></p><p>Cursor pagination uses a <strong>cursor token</strong> that represents the last item the user has seen. Instead of requesting a page number, the app requests the next items after a specific position.</p><p>For example:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;plaintext&quot;,&quot;nodeId&quot;:&quot;49268bda-9d4c-4dd7-8d9e-abc8bfcb380a&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-plaintext">next_cursor = &#8220;abc123&#8221;</code></pre></div><p>Then the next request might look like:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;plaintext&quot;,&quot;nodeId&quot;:&quot;100a9965-3647-4caa-9c40-b67138417ae6&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-plaintext">?after=abc123</code></pre></div><p>The cursor usually represents a stable value, such as the ID or timestamp of the last item. This approach works well for data that constantly changes, such as social media feeds.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!27_3!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b12a6d8-c01a-4f7b-967c-a714b152ce3a_1146x513.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!27_3!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b12a6d8-c01a-4f7b-967c-a714b152ce3a_1146x513.png 424w, https://substackcdn.com/image/fetch/$s_!27_3!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b12a6d8-c01a-4f7b-967c-a714b152ce3a_1146x513.png 848w, https://substackcdn.com/image/fetch/$s_!27_3!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b12a6d8-c01a-4f7b-967c-a714b152ce3a_1146x513.png 1272w, https://substackcdn.com/image/fetch/$s_!27_3!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b12a6d8-c01a-4f7b-967c-a714b152ce3a_1146x513.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!27_3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b12a6d8-c01a-4f7b-967c-a714b152ce3a_1146x513.png" width="1146" height="513" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1b12a6d8-c01a-4f7b-967c-a714b152ce3a_1146x513.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:513,&quot;width&quot;:1146,&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_!27_3!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b12a6d8-c01a-4f7b-967c-a714b152ce3a_1146x513.png 424w, https://substackcdn.com/image/fetch/$s_!27_3!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b12a6d8-c01a-4f7b-967c-a714b152ce3a_1146x513.png 848w, https://substackcdn.com/image/fetch/$s_!27_3!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b12a6d8-c01a-4f7b-967c-a714b152ce3a_1146x513.png 1272w, https://substackcdn.com/image/fetch/$s_!27_3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b12a6d8-c01a-4f7b-967c-a714b152ce3a_1146x513.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><strong>Why It Matters</strong></h4><p>Imagine a social feed with 10,000 posts. If the app tried to load everything at once:</p><ul><li><p>The request would take a long time</p></li><li><p>Rendering the UI would be slow</p></li><li><p>Device might run out of memory</p></li></ul><p>Pagination solves this by loading only a small portion of the data at a time, which keeps scrolling smooth.</p><h4><strong>Real-World Example</strong></h4><p>Many popular apps, such as Twitter, Instagram, and TikTok, rely on cursor-based pagination.</p><p>These apps load new posts as the user scrolls, using a cursor that points to the last item that was displayed.</p><p>This ensures the feed remains stable even when new posts appear&#8230;</p><h4><strong>Trade-offs</strong></h4><p>Each pagination method has advantages and limitations:</p><ul><li><p><strong>Page number pagination: </strong>Simple to understand and works well for search results, but less efficient for large datasets.</p></li><li><p><strong>Offset pagination: </strong>Easy to implement and allows jumping to any position, but it can break when new data is inserted.</p></li><li><p><strong>Cursor pagination: </strong>Stable and efficient for live feeds and prevents duplicates and skipped items, but does not easily support jumping directly to a specific page.</p></li></ul><p>Because mobile devices have limited memory and storage, loading and storing data must be done carefully! Therefore, it&#8217;s important to design efficient data models that work well within these constraints.</p><h3><strong>19. Data Modeling for Mobile Constraints</strong></h3><p>Mobile apps often store data locally on the device so they can load information quickly and continue working even when the network is slow.</p><p>Yet mobile devices have limited storage, CPU power, and battery, so the way data is structured must be carefully designed.</p><p>Because of these limits, mobile apps usually store and organise data to help the UI load quickly, even if it means repeating some information.</p><h4><strong>Things Mobile Data Models Must Consider</strong></h4><p>When designing data models for mobile apps, several important constraints should be considered:</p><p><strong>a. Limited storage</strong></p><p>Mobile devices cannot store unlimited data.</p><p>Apps should avoid caching everything and instead remove old or unused data after a period of time. For example, an app might store cached data for a few hours or days, then automatically delete it.</p><p><strong>b. CPU performance</strong></p><p>Complex database queries can slow down the app.</p><p>Queries that join many tables may take longer to process. To keep the app fast, store related data together so the app can read it quickly without performing complicated queries.</p><p><strong>c. Battery usage</strong></p><p>Every time an app writes data to disk, it uses battery power.</p><p>Frequent database writes can drain the battery over time. Because of this, apps try to minimise unnecessary writes and batch operations when possible.</p><h4><strong>Why It Matters</strong></h4><p>Data models used on backend servers are usually designed to save storage space and keep data perfectly structured.</p><p>But mobile apps have a different goal: <em>fast rendering on the screen</em>.</p><p>This means the data model on mobile may look different from the backend data model, because it&#8217;s optimised for speed and user experience rather than strict structure.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!T5xu!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66021ef4-e515-4be6-aa4d-eb034dc30976_1450x726.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!T5xu!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66021ef4-e515-4be6-aa4d-eb034dc30976_1450x726.png 424w, https://substackcdn.com/image/fetch/$s_!T5xu!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66021ef4-e515-4be6-aa4d-eb034dc30976_1450x726.png 848w, https://substackcdn.com/image/fetch/$s_!T5xu!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66021ef4-e515-4be6-aa4d-eb034dc30976_1450x726.png 1272w, https://substackcdn.com/image/fetch/$s_!T5xu!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66021ef4-e515-4be6-aa4d-eb034dc30976_1450x726.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!T5xu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66021ef4-e515-4be6-aa4d-eb034dc30976_1450x726.png" width="1450" height="726" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/66021ef4-e515-4be6-aa4d-eb034dc30976_1450x726.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:726,&quot;width&quot;:1450,&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_!T5xu!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66021ef4-e515-4be6-aa4d-eb034dc30976_1450x726.png 424w, https://substackcdn.com/image/fetch/$s_!T5xu!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66021ef4-e515-4be6-aa4d-eb034dc30976_1450x726.png 848w, https://substackcdn.com/image/fetch/$s_!T5xu!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66021ef4-e515-4be6-aa4d-eb034dc30976_1450x726.png 1272w, https://substackcdn.com/image/fetch/$s_!T5xu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66021ef4-e515-4be6-aa4d-eb034dc30976_1450x726.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><strong>Real-World Example</strong></h4><p>Imagine a contacts app that shows a list of people.</p><p>Instead of calculating everything each time the list loads, the app may store some information in advance, such as display name, profile picture URL, and the first letter used for alphabetical sections.</p><p>Because this information is already stored, the app can render the list instantly without performing extra calculations.</p><h4><strong>Trade-offs</strong></h4><p>Storing extra or pre-computed data improves speed, but it also has some downsides.</p><p>Pre-computed data uses more storage space and must be updated whenever the original data changes.</p><p>Yet this trade-off is usually acceptable because storage is relatively cheap, while slow or laggy interfaces are immediately noticeable to users.</p><div><hr></div><h2><strong>Final Words</strong></h2><p>None of these concepts works on its own.</p><p>The choices you make in one area affect everything else. Networking affects caching, caching affects sync, and sync affects how conflicts are handled.</p><p>It&#8217;s all connected.</p><p>The best engineers aren&#8217;t the ones who know the most concepts. They&#8217;re the ones who understand the tradeoffs and know when to use what.</p><p>So remember this:</p><p><em>Start simple. Add complexity only when you really need it. And when that time comes, you&#8217;ll know what to use.</em></p><div><hr></div><p>&#128075; I&#8217;d like to thank <strong><a href="https://x.com/Shefali__J">Shefali</a></strong> for writing this newsletter!</p><p>Plus, don&#8217;t forget to check out her work and socials:</p><ul><li><p><a href="https://shefali.dev/">Shefali.dev</a></p></li><li><p><a href="https://github.com/WebdevShefali">GitHub</a></p></li><li><p><a href="https://x.com/Shefali__J">Twitter</a></p></li></ul><p>You&#8217;ll often find her writing about web development, sharing UI tips, and building tools that make developers&#8217; lives easier.</p><div><hr></div><p>Get the full <em>premium</em> newsletter series and max your system design career leverage:</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/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://newsletter.systemdesign.one/subscribe?"><span>Subscribe now</span></a></p><p>Plus, there are <a href="http://newsletter.systemdesign.one/subscribe?group=true">group discounts</a>, <a href="http://newsletter.systemdesign.one/subscribe?gift=true">gift options</a>, and <a href="https://newsletter.systemdesign.one/leaderboard">referral rewards</a> available.</p><div><hr></div><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://www.linkedin.com/in/nk-systemdesign-one/" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!bEFk!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 424w, https://substackcdn.com/image/fetch/$s_!bEFk!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 848w, https://substackcdn.com/image/fetch/$s_!bEFk!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 1272w, https://substackcdn.com/image/fetch/$s_!bEFk!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!bEFk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png" width="152" height="152" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:320,&quot;width&quot;:320,&quot;resizeWidth&quot;:152,&quot;bytes&quot;:74009,&quot;alt&quot;:&quot;Author Neo Kim; System design case studies&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:&quot;https://www.linkedin.com/in/nk-systemdesign-one/&quot;,&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="Author Neo Kim; System design case studies" title="Author Neo Kim; System design case studies" srcset="https://substackcdn.com/image/fetch/$s_!bEFk!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 424w, https://substackcdn.com/image/fetch/$s_!bEFk!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 848w, https://substackcdn.com/image/fetch/$s_!bEFk!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 1272w, https://substackcdn.com/image/fetch/$s_!bEFk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption"><strong>&#128075; Find me on <a href="https://www.linkedin.com/in/nk-systemdesign-one/">LinkedIn</a> | <a href="https://x.com/intent/follow?screen_name=systemdesignone">Twitter</a> | <a href="https://www.threads.net/@systemdesignone">Threads</a> | <a href="https://www.instagram.com/systemdesignone/">Instagram</a></strong></figcaption></figure></div><div><hr></div><p><strong>Want to reach 210K+ tech professionals at scale? </strong>&#128240;</p><p>If your company wants to reach 210K+ tech professionals, <a href="https://newsletter.systemdesign.one/p/sponsorship">advertise with me</a>.</p><div><hr></div><p>Thank you for supporting this newsletter.</p><p>You are now 210,001+ readers strong, very close to 210k. Let&#8217;s try to get 211k readers by 27 March. Consider sharing this post with your friends and get rewards.</p><p>Y&#8217;all are the best.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!6oWl!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!6oWl!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png 424w, https://substackcdn.com/image/fetch/$s_!6oWl!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png 848w, https://substackcdn.com/image/fetch/$s_!6oWl!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png 1272w, https://substackcdn.com/image/fetch/$s_!6oWl!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!6oWl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png" width="590" height="368.75" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2e739087-a910-4643-be36-997b6dd5b4af_800x500.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:500,&quot;width&quot;:800,&quot;resizeWidth&quot;:590,&quot;bytes&quot;:87878,&quot;alt&quot;:&quot;system design newsletter&quot;,&quot;title&quot;:&quot;system design newsletter&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/163380418?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="system design newsletter" title="system design newsletter" srcset="https://substackcdn.com/image/fetch/$s_!6oWl!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png 424w, https://substackcdn.com/image/fetch/$s_!6oWl!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png 848w, https://substackcdn.com/image/fetch/$s_!6oWl!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png 1272w, https://substackcdn.com/image/fetch/$s_!6oWl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.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 class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/p/mobile-system-design?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesign.one/p/mobile-system-design?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><div><hr></div><ul><li><p>Block diagrams created using <a href="https://app.eraser.io/auth/sign-up?ref=neo">Eraser</a>.</p></li></ul>]]></content:encoded></item><item><title><![CDATA[The Mobile Engineer's Guide to System Design Interviews]]></title><description><![CDATA[#134: Mobile System Design Interview]]></description><link>https://newsletter.systemdesign.one/p/mobile-system-design-interview</link><guid isPermaLink="false">https://newsletter.systemdesign.one/p/mobile-system-design-interview</guid><dc:creator><![CDATA[Neo Kim]]></dc:creator><pubDate>Tue, 24 Mar 2026 13:40:42 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/6968c1a0-7187-4c26-ab1b-c0c731466554_1280x720.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/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">Get my system design playbook for FREE on newsletter signup:</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><ul><li><p><em><a href="https://newsletter.systemdesign.one/p/mobile-system-design-interview/?action=share">Share this post</a> &amp; I'll send you some rewards for the referrals.</em></p></li></ul><div><hr></div><p>You&#8217;ve probably been there: You&#8217;re sitting across from two engineers (or staring at them through a webcam), and they&#8217;ve just asked you to design Instagram&#8217;s feed. Or a ride-sharing app. Or some chat system with offline support and end-to-end encryption.</p><p>The clock is ticking&#8230;</p><p>You have 45 minutes to turn a vague prompt into something that looks like you know what you&#8217;re doing.</p><p>Your mind races: <em>Where do I even start? Do I draw boxes first? Ask about the user numbers? Talk about databases? What if I forget something critical?</em></p><p>Most mobile engineers don&#8217;t realize this about system design interviews: <strong>They&#8217;re NOT testing whether you can build Instagram.</strong> They&#8217;re testing whether you can take something fuzzy and turn it into something concrete.</p><p>This is the same skill you use every day when your PM says, <em>&#8220;We need push notifications,&#8221;</em> or your designer drops a Figma file in Slack with the message <em>&#8220;Thoughts?</em>&#8221; in your day job.</p><div><hr></div><h4 style="text-align: justify;"><strong><a href="https://platform.minimax.io/">12% OFF MiniMax M2.7 - The SOTA Cowork Agent Model That Just Outranked Opus and Gemini 3.1. (Partner)</a></strong></h4><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://platform.minimax.io" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!4CuL!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61da77e5-6a17-4176-9714-ed285e414a98_1600x795.png 424w, https://substackcdn.com/image/fetch/$s_!4CuL!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61da77e5-6a17-4176-9714-ed285e414a98_1600x795.png 848w, https://substackcdn.com/image/fetch/$s_!4CuL!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61da77e5-6a17-4176-9714-ed285e414a98_1600x795.png 1272w, https://substackcdn.com/image/fetch/$s_!4CuL!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61da77e5-6a17-4176-9714-ed285e414a98_1600x795.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!4CuL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61da77e5-6a17-4176-9714-ed285e414a98_1600x795.png" width="1456" height="723" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/61da77e5-6a17-4176-9714-ed285e414a98_1600x795.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:723,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:&quot;https://platform.minimax.io&quot;,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!4CuL!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61da77e5-6a17-4176-9714-ed285e414a98_1600x795.png 424w, https://substackcdn.com/image/fetch/$s_!4CuL!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61da77e5-6a17-4176-9714-ed285e414a98_1600x795.png 848w, https://substackcdn.com/image/fetch/$s_!4CuL!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61da77e5-6a17-4176-9714-ed285e414a98_1600x795.png 1272w, https://substackcdn.com/image/fetch/$s_!4CuL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61da77e5-6a17-4176-9714-ed285e414a98_1600x795.png 1456w" sizes="100vw" loading="lazy" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p style="text-align: justify;"><strong><a href="https://platform.minimax.io/subscribe/coding-plan?code=KGlGYHegnw&amp;source=link">MiniMax M2.7</a></strong> is here, and it&#8217;s unlike any agent model released before it.</p><p style="text-align: justify;">Built on their proprietary SOTA Cowork Agent Model architecture, M2.7 shows early echoes of self-evolution: the ability to follow complex, layered instructions across long workflows without losing the thread.</p><p style="text-align: justify;">At 5 tools, every model looks sharp.</p><p style="text-align: justify;">At 40, almost all fall apart silently.</p><p style="text-align: justify;">Wrong tool invoked. Step missed. No error thrown. You find out 3 days post-deploy.</p><p style="text-align: justify;">M2.7 was tested across 40 complex skills, each exceeding 2,000 tokens.<br>Skill adherence rate: 97%.</p><p style="text-align: justify;">Here&#8217;s what that looks like in production:</p><ul><li><p>Alert fires &#8594; metrics correlated &#8594; root cause traced across systems</p></li><li><p>DB queried to verify &#8594; fix submitted</p></li><li><p>Recovery time: under 3 minutes. Manual process: 4+ hours.</p></li></ul><p style="text-align: justify;">Most models are built to write code.</p><p style="text-align: justify;">M2.7 is built to understand your production systems.</p><p style="text-align: justify;">And it ships inside something new: the world&#8217;s first subscription plan for an all-modality-capable model. One API key covers M2.7, Speech, Image, Video, and Music generation; the full stack, no provider switching.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://platform.minimax.io/subscribe/coding-plan?code=KGlGYHegnw&amp;source=link&quot;,&quot;text&quot;:&quot;MiniMax Token Plan 12% OFF&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://platform.minimax.io/subscribe/coding-plan?code=KGlGYHegnw&amp;source=link"><span>MiniMax Token Plan 12% OFF</span></a></p><div><hr></div><p>I want to introduce <strong><a href="https://www.linkedin.com/in/tjeerdintveen/">Tjeerd in &#8216;t Veen</a></strong> as the guest author.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://www.mobilesystemdesign.com/book" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!cuNb!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb1c7e4b-6898-4d5c-98c1-79db5b9a9675_1238x581.png 424w, https://substackcdn.com/image/fetch/$s_!cuNb!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb1c7e4b-6898-4d5c-98c1-79db5b9a9675_1238x581.png 848w, https://substackcdn.com/image/fetch/$s_!cuNb!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb1c7e4b-6898-4d5c-98c1-79db5b9a9675_1238x581.png 1272w, https://substackcdn.com/image/fetch/$s_!cuNb!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb1c7e4b-6898-4d5c-98c1-79db5b9a9675_1238x581.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!cuNb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb1c7e4b-6898-4d5c-98c1-79db5b9a9675_1238x581.png" width="1238" height="581" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/db1c7e4b-6898-4d5c-98c1-79db5b9a9675_1238x581.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:581,&quot;width&quot;:1238,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:&quot;https://www.mobilesystemdesign.com/book&quot;,&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_!cuNb!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb1c7e4b-6898-4d5c-98c1-79db5b9a9675_1238x581.png 424w, https://substackcdn.com/image/fetch/$s_!cuNb!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb1c7e4b-6898-4d5c-98c1-79db5b9a9675_1238x581.png 848w, https://substackcdn.com/image/fetch/$s_!cuNb!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb1c7e4b-6898-4d5c-98c1-79db5b9a9675_1238x581.png 1272w, https://substackcdn.com/image/fetch/$s_!cuNb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb1c7e4b-6898-4d5c-98c1-79db5b9a9675_1238x581.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>He recently released the <strong><a href="https://www.mobilesystemdesign.com/book">Mobile System Design book bundle</a></strong> based on years of interviewing mobile engineers and building large-scale mobile apps. This newsletter distills the core process (framework) from the books into something you can use to prep for interviews or plan features at work.</p><p>If you want to go deeper, the <a href="https://www.mobilesystemdesign.com/book">full book bundle</a> has more examples, detailed architecture patterns, and code-level implementation strategies. </p><div><hr></div><h2>What this newsletter covers</h2><p>There are plenty of great general system design guides. This one is about mobile constraints and how they shape the architecture.</p><p>This newsletter walks through the actual process:</p><ul><li><p>How to take a vague prompt and figure out what the interviewer <em>actually</em> wants</p></li><li><p>How to uncover the hidden requirements nobody mentioned (because they&#8217;re testing if <em>you&#8217;ll</em> think of them)</p></li><li><p>How to structure your thinking so you don&#8217;t forget the mobile-specific stuff (offline state, battery drain, app lifecycle, memory constraints)</p></li><li><p>How to turn abstract architecture talk into concrete implementation details</p></li></ul><p>This works whether you&#8217;re in an interview or planning a real feature at work.</p><p>The process is the same.</p><div><hr></div><h2>Who this is for</h2><p>If you&#8217;re a mobile engineer (iOS, Android, Flutter, React Native, etc.) and you need to:</p><ul><li><p>Prepare for system design interviews</p></li><li><p>Stop feeling like you&#8217;re fumbling when asked to &#8220;design something.&#8221;</p></li><li><p>Learn how to think through mobile architecture in a structured way</p></li><li><p>Get good at turning vague requirements into actual plans</p></li></ul><p>Then this is for you&#8230;</p><p>I&#8217;m assuming you already know how to develop mobile apps. You understand the basics of networking, data persistence, and why you shouldn&#8217;t do heavy work on the main thread. You&#8217;ve shipped something to production and dealt with the consequences.</p><p>What you might not have is a structured way to <em>think</em> about system design. That&#8217;s what we&#8217;re covering here&#8230;</p><div><hr></div><h1>Interview Structure</h1><p>Let&#8217;s talk about what actually happens in a mobile system design interview:</p><p>The format can vary wildly between companies. Some give you 45 minutes, others give you 60. Some want you on a whiteboard, others use tools like <a href="https://codesignal.com">CodeSignal</a> or <a href="https://www.hackerrank.com">HackerRank</a>. Some companies even ask backend system design questions in mobile interviews, which is a separate discussion entirely.</p><p>But most mobile-focused interviews follow a similar arc.</p><p>Here&#8217;s what you can typically expect&#8230;</p><div><hr></div><h2>Typical flow</h2><p>Most interviews break down roughly like this:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!mmwm!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F961017fd-3581-4a7e-8f46-d141979a981a_1052x181.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!mmwm!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F961017fd-3581-4a7e-8f46-d141979a981a_1052x181.png 424w, https://substackcdn.com/image/fetch/$s_!mmwm!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F961017fd-3581-4a7e-8f46-d141979a981a_1052x181.png 848w, https://substackcdn.com/image/fetch/$s_!mmwm!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F961017fd-3581-4a7e-8f46-d141979a981a_1052x181.png 1272w, https://substackcdn.com/image/fetch/$s_!mmwm!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F961017fd-3581-4a7e-8f46-d141979a981a_1052x181.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!mmwm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F961017fd-3581-4a7e-8f46-d141979a981a_1052x181.png" width="1052" height="181" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/961017fd-3581-4a7e-8f46-d141979a981a_1052x181.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:181,&quot;width&quot;:1052,&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_!mmwm!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F961017fd-3581-4a7e-8f46-d141979a981a_1052x181.png 424w, https://substackcdn.com/image/fetch/$s_!mmwm!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F961017fd-3581-4a7e-8f46-d141979a981a_1052x181.png 848w, https://substackcdn.com/image/fetch/$s_!mmwm!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F961017fd-3581-4a7e-8f46-d141979a981a_1052x181.png 1272w, https://substackcdn.com/image/fetch/$s_!mmwm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F961017fd-3581-4a7e-8f46-d141979a981a_1052x181.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>At a high level, the flow is:</p><ul><li><p>Requirements and scope (5-10 minutes): clarify what you&#8217;re designing and the constraints</p></li><li><p>API and data needs (5-10 minutes): define what the app needs from the server</p></li><li><p>Architecture (10-15 minutes): outline client components and data flow</p></li><li><p>Deep dive (15-20 minutes): walk one critical flow or adjust for a new constraint</p></li><li><p>Wrap-up (1-5 minutes): summarize decisions and tradeoffs</p></li></ul><p>I&#8217;ll go deep on how to execute each phase in the next section&#8230;</p><div><hr></div><h2>What&#8217;s expected at different levels</h2><p>Interviewers don&#8217;t judge all mobile engineers the same way.</p><p>Here&#8217;s what interviewers are actually looking for based on your level:</p><h3>Junior to mid-level engineers</h3><p>You&#8217;re expected to:</p><ul><li><p>Ask clarifying questions (even if they seem obvious)</p></li><li><p>Draw a reasonable architecture diagram without major gaps</p></li><li><p>Explain common mobile patterns (caching, background tasks, handling lifecycle)</p></li><li><p>Discuss basic tradeoffs - <em>&#8221;This approach is simpler but uses more memory.&#8221;</em></p></li></ul><p>You&#8217;re <em>not</em> expected to:</p><ul><li><p>Know every edge case off the top of your head</p></li><li><p>Have opinions on monorepo versus multi-repo</p></li><li><p>Design for 100 million users on day one</p></li></ul><p><strong>If you get stuck on something complex (like offline conflict resolution), just say so. </strong><em>&#8220;I haven&#8217;t built a system that merges offline edits before, but I&#8217;d start with last-write-wins and ask about requirements,&#8221;</em> is fine.</p><p>Honesty beats bullshitting.</p><h3>Senior engineers</h3><p>Everything from junior/mid, plus:</p><ul><li><p>Proactively uncover hidden requirements without prompting - <em>&#8221;What about users on limited data plans?&#8221;</em></p></li><li><p>Propose architecture with clear reasoning for your choices - <em>&#8221;I&#8217;m using a repository pattern here because we need to support offline-first&#8221;</em></p></li><li><p>Demonstrate deep knowledge of mobile-specific challenges (app lifecycle, memory pressure, battery drain, offline sync)</p></li><li><p>Adapt when requirements change mid-interview - <em>&#8221;Okay, if we need to support 50MB video uploads, we&#8217;ll need background upload with chunking&#8230;&#8221;</em></p></li></ul><p><em><strong>You should drive the conversation.</strong></em></p><p>The interviewer shouldn&#8217;t have to pull answers out of you.</p><h3>Staff and principal engineers</h3><p>Everything from senior, plus:</p><ul><li><p>Frame the problem: <em>&#8220;Before we design this, let&#8217;s talk about whether we even need offline support for this use case.&#8221;</em></p></li><li><p>Consider team structure: <em>&#8220;If we structure this as a separate module, we can have one team own it independently.&#8221;</em></p></li><li><p>Think long-term: <em>&#8220;This works for v1, but if we add feature X later, we&#8217;ll need to refactor. Let&#8217;s design for that now.&#8221;</em></p></li><li><p>Make architectural tradeoffs at the system level: modularization strategy, build times, deployment, backward compatibility</p></li></ul><p><strong>You&#8217;re expected to think like a tech lead or architect</strong>, not just an IC implementing a feature. The interviewer wants to see if you can make decisions that affect the entire team or org.</p><p>Now that you know what the interview <em>structure</em> looks like, let&#8217;s talk about the actual <em>process</em> you&#8217;ll use during those 45 minutes.</p><div><hr></div><h1>Core Process</h1><p>The interview structure gives you the timeline. But what do you actually <em>do</em> in each phase?</p><p>This is the process you&#8217;ll follow, roughly in order, during the first 30-40 minutes of the interview. Think of it as a checklist for making sure you forget nothing critical.</p><p>You won&#8217;t always do these steps in exactly this order. Sometimes you&#8217;ll jump back and forth. Sometimes the interviewer will steer you in a different direction. That&#8217;s fine.</p><p>But this is the general flow that works:</p><div><hr></div><h2>A reusable pattern (applies to every step)</h2><p>Most steps look different, but the rhythm is the same:</p><ul><li><p>Ask 2-3 high-impact questions before designing.</p></li><li><p>Restate what you heard and get a clear &#8220;<em>yes</em>.&#8221;</p></li><li><p>Write down decisions: constraints, must-haves versus nice-to-haves, and open questions.</p></li><li><p>Call out red flags early instead of waiting.</p></li><li><p>You don&#8217;t have to solve everything on the spot. Show you see the issue, pick a reasonable tradeoff, and move on.</p></li></ul><div><hr></div><h2>Capturing the briefing</h2><p>Here&#8217;s how most system design interviews start:</p><p>The interviewer says something like, <em>&#8220;Design a feed for a social media app,&#8221; </em>or<em> &#8220;Build a way for users to share photos with friends.&#8221;</em></p><p>And your brain immediately starts racing: <em>Should I ask about the backend? Should I start drawing? What if I forget to mention caching?</em></p><p>Before you do any of that, pause.</p><p><em><strong>Your first job is not to design anything. It&#8217;s understanding what you&#8217;re being asked to design.</strong></em></p><p>This sounds obvious, but most candidates blow past this step in 60 seconds and then spend 40 minutes designing the wrong thing&#8230;</p><div><hr></div><h3>What you&#8217;re actually trying to do</h3><p>In the first 5-10 minutes, you&#8217;re trying to turn a vague prompt into something concrete enough that you know what problem you&#8217;re solving.</p><p>You&#8217;re not trying to get <em>every</em> detail. You&#8217;re trying to get <em>enough</em> clarity that you&#8217;re not completely guessing.</p><p>Think of it like this: If someone asks you to &#8220;<em>design a messaging feature</em>,&#8221; do they want:</p><ul><li><p>WhatsApp (end-to-end encrypted, real-time, requires phone number)</p></li><li><p>Slack (threaded, searchable, integrates with other tools)</p></li><li><p>Twitter/X DMs (simple, text-only, tied to social graph)</p></li></ul><p>All of those are &#8220;messaging.&#8221; They&#8217;re also completely different architectures.</p><p><em><strong>So your job is to ask questions that reveal which one they actually want.</strong></em></p><div><hr></div><h3>Questions that actually matter</h3><p>Here&#8217;s what you should ask:</p><p><strong>About success criteria:</strong></p><ul><li><p>&#8220;What does success look like for this feature?&#8221; (Are we optimizing for speed? Reliability? Simplicity?)</p></li><li><p>&#8220;What&#8217;s the most important thing this needs to do well?&#8221; (If we could only do one thing right, what would it be?)</p></li></ul><p><strong>About scope:</strong></p><ul><li><p>&#8220;Is this the whole app, or are we focusing on one part?&#8221; (Don&#8217;t design all of Instagram if they just want the feed)</p></li><li><p>&#8220;What platforms are we targeting?&#8221; (iOS only? Android? Cross-platform?)</p></li></ul><p><strong>About constraints:</strong></p><ul><li><p>&#8220;What network conditions should we plan for?&#8221; (Always online? Intermittent? Fully offline?)</p></li><li><p>&#8220;Are there any technical constraints I should know about?&#8221; (Existing systems we need to integrate with? Legacy code?)</p></li></ul><p><strong>About users:</strong></p><ul><li><p>&#8220;Who are the primary users?&#8221; (Consumers? Enterprise? Internal tools?)</p></li><li><p>&#8220;What devices are they on?&#8221; (Flagship phones? Low-end Android? Tablets?)</p></li></ul><p><em><strong>Don&#8217;t ask everything.</strong></em></p><p>Pick the questions that will most change your design. You have limited time.</p><div><hr></div><h3>A bad and a good example</h3><p><strong>Bad example:</strong></p><blockquote><p>Interviewer: &#8220;Design a feed for a social media app.&#8221;</p><p>You: &#8220;Okay, so I&#8217;ll use MVVM for the architecture. We&#8217;ll have a ViewModel that fetches data from a Repository, which talks to both a local database and a REST API. UI will be built with&#8212;&#8221;</p><p>Interviewer (internally): <em>They didn&#8217;t ask a single question. Do they even know what they&#8217;re designing?</em></p></blockquote><p>You just spent 3 minutes designing an architecture without knowing:</p><ul><li><p>Whether it needs to work offline</p></li><li><p>Whether it&#8217;s a text-based feed or heavy on images and video</p></li><li><p>Whether it requires pre-caching for a smoother scrolling experience</p></li></ul><p>That&#8217;s a red flag. Interviewers are <em>explicitly</em> looking for whether you ask questions.</p><p><strong>Good example:</strong></p><blockquote><p>Interviewer: &#8220;Design a feed for a social media app.&#8221;</p><p>You: &#8220;Okay, let me make sure I understand what we&#8217;re designing. Is this feed mostly images and video, or mostly text? That affects caching and pre-fetching on mobile.&#8221;</p><p>Interviewer: &#8220;Mostly images, some video.&#8221;</p><p>You: &#8220;Got it. For mobile, I&#8217;d plan on disk caching images (and maybe short videos) and pre-fetching upcoming content so the feed loads fast and works offline. Is that aligned with what you want?&#8221;</p><p>Interviewer: &#8220;Yes, basic offline support for previously loaded content is important.&#8221;</p><p>You: &#8220;Makes sense. One more thing: do we need live updates, or is pull-to-refresh enough for v1?&#8221;</p><p>Interviewer: &#8220;Pull-to-refresh is fine.&#8221;</p><p>You: &#8220;Perfect. So, to summarize: we&#8217;re designing a media-heavy feed with basic offline support. We&#8217;ll cache images (and maybe short videos), pre-fetch upcoming content for fast loads, and start with pull-to-refresh for updates. Does that sound right?&#8221;</p><p>Interviewer: &#8220;Yep, that&#8217;s it.&#8221;</p></blockquote><div><hr></div><p><em><strong>Reminder: this is a teaser of the subscriber-only newsletter series, exclusive to my golden members.</strong></em></p><p>When you upgrade, you&#8217;ll get:</p><ul><li><p><strong>High-level architecture of real-world systems.</strong></p></li><li><p>Deep dive into how popular real-world systems actually work.</p></li><li><p><strong>How real-world systems handle scale, reliability, and performance.</strong></p></li></ul><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/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://newsletter.systemdesign.one/subscribe?"><span>Subscribe now</span></a></p><div><hr></div><h2>Briefing wrap-up (red flags + next steps)</h2><p>Sometimes the briefing is incomplete or contradictory. Call it out early instead of guessing&#8230;</p><p><strong>Common red flags:</strong></p><ul><li><p>Requirements that are vague or overly broad - <em>&#8221;make it fast.&#8221;</em></p></li><li><p>Contradictory statements -<em> &#8221;we want it simple, but also highly customizable.&#8221;</em></p></li><li><p>Missing critical info (no mention of offline, auth, or data sources)</p></li></ul><p><strong>When you spot these, call them out:</strong></p><p><em>&#8220;You mentioned we want it to be &#8216;fast.&#8217; Can you be more specific? Are we talking about load time under 1 second, smooth scrolling, or something else?&#8221;</em></p><p><em>&#8220;I&#8217;m noticing we haven&#8217;t talked about where the data comes from. Should I assume we&#8217;re pulling from a REST API, or is there a different data source?&#8221;</em></p><p>Don&#8217;t rush ahead, hoping it&#8217;ll become clear later. It won&#8217;t. You&#8217;ll end up designing something that doesn&#8217;t match what they wanted&#8230;</p><p><strong>Next steps once the briefing is clear:</strong></p><ul><li><p>Write down key constraints in the shared doc or on the whiteboard (&#8221;Offline support required&#8221;, &#8220;100k users&#8221;, &#8220;Existing auth system&#8221;)</p></li><li><p>Mentally categorize what is a must-have versus a nice-to-have</p></li><li><p>Identify the biggest unknowns you&#8217;ll need to address</p></li></ul><p><em><strong>Lesson: Don&#8217;t start designing until you know what you&#8217;re designing.</strong></em></p><p>This can feel slow, but it&#8217;s faster than designing the wrong thing&#8230;</p><div><hr></div><h2>Defining scope and requirements</h2><p>Okay, so you&#8217;ve asked your questions, and you have a basic understanding of what you&#8217;re designing. Now comes the hard part: figuring out what you&#8217;re <em>actually</em> going to design.</p><p>Here&#8217;s the problem: If someone asks you to <em>&#8220;design a messaging feature,&#8221;</em> there are about 47 different things they could mean. Do they want read receipts? Typing indicators? Group chats? Voice messages? End-to-end encryption? Reactions? Threads?</p><p>You can&#8217;t fit all of that into v1. You probably can&#8217;t even fit half of it.</p><p><em><strong>So your job is to separate what&#8217;s essential from what&#8217;s nice-to-have.</strong></em></p><p>This is where most people mess up. They either:</p><ol><li><p>Try to include everything at once and run out of time</p></li><li><p>Design the wrong things and miss what actually matters</p></li><li><p>Don&#8217;t ask at all and just guess</p></li></ol><p>All three are bad. Let&#8217;s talk about how to do this right:</p><div><hr></div><h3>What you&#8217;re trying to figure out</h3><p>You need to answer these questions:</p>
      <p>
          <a href="https://newsletter.systemdesign.one/p/mobile-system-design-interview">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[RAG - A Deep Dive]]></title><description><![CDATA[#133: Understanding Retrieval-Augmented Generation]]></description><link>https://newsletter.systemdesign.one/p/how-rag-works</link><guid isPermaLink="false">https://newsletter.systemdesign.one/p/how-rag-works</guid><dc:creator><![CDATA[Neo Kim]]></dc:creator><pubDate>Mon, 23 Mar 2026 11:45:50 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/8d630c6b-2576-4b38-8561-e3b88cf47d0e_1280x720.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/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">Get my system design playbook for FREE on newsletter signup:</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><ul><li><p><em><a href="https://newsletter.systemdesign.one/p/how-rag-works/?action=share">Share this post</a> &amp; I'll send you some rewards for the referrals.</em></p></li></ul><div><hr></div><p>Every large language model<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a> (<strong>LLM</strong>) you use has lied to you with confidence, fluency, and frequency&#8230;</p><p>Ask any model about something that happened last week. It doesn&#8217;t know. It can&#8217;t know. Its knowledge was frozen months ago. They might try, and if they do, they will hallucinate.</p><p>This isn&#8217;t a bug.</p><p>It&#8217;s a fundamental architectural limitation. LLMs keep knowledge in their parameters<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-2" href="#footnote-2" target="_self">2</a>. These are billions of numerical weights learned during training. Once training ends, the knowledge is locked. The model doesn&#8217;t know what it doesn&#8217;t know, so it fills the gaps with confident fabrication. Studies show that hallucination<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-3" href="#footnote-3" target="_self">3</a> rates can be as low as 1% for simple summarization tasks. However, they can exceed 58% for complex work.</p><p>This is exactly what Retrieval-Augmented Generation<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-4" href="#footnote-4" target="_self">4</a> (<strong>RAG</strong>) solves.</p><p>RAG doesn&#8217;t bake knowledge into the model. Instead, it pulls in relevant context when you ask a question. The model stays smart, your data stays current, and every answer is traceable back to its source.</p><p>This is the architectural pattern that makes AI actually useful.</p><p>Here&#8217;s how it works, why it works, and how to build it:</p><div><hr></div><h2><a href="https://link.outskill.com/NEOKIMMAR4">Still juggling 10 different tools? Learn AI workflows and replace 80% of them (Partner)</a></h2><p>Perplexity&#8217;s new computer thinks, designs, codes, and manages projects &#8212; all without you lifting a finger to switch tools.</p><p>This is where AI is headed: one place to get everything done. Smarter, faster, and built to make you 10x more productive.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://link.outskill.com/NEOKIMMAR4" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!knkf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3234eb1b-ca33-4b13-bc85-4e599170e1d4_1600x902.png 424w, https://substackcdn.com/image/fetch/$s_!knkf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3234eb1b-ca33-4b13-bc85-4e599170e1d4_1600x902.png 848w, https://substackcdn.com/image/fetch/$s_!knkf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3234eb1b-ca33-4b13-bc85-4e599170e1d4_1600x902.png 1272w, https://substackcdn.com/image/fetch/$s_!knkf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3234eb1b-ca33-4b13-bc85-4e599170e1d4_1600x902.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!knkf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3234eb1b-ca33-4b13-bc85-4e599170e1d4_1600x902.png" width="1456" height="821" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3234eb1b-ca33-4b13-bc85-4e599170e1d4_1600x902.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:821,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:&quot;https://link.outskill.com/NEOKIMMAR4&quot;,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!knkf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3234eb1b-ca33-4b13-bc85-4e599170e1d4_1600x902.png 424w, https://substackcdn.com/image/fetch/$s_!knkf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3234eb1b-ca33-4b13-bc85-4e599170e1d4_1600x902.png 848w, https://substackcdn.com/image/fetch/$s_!knkf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3234eb1b-ca33-4b13-bc85-4e599170e1d4_1600x902.png 1272w, https://substackcdn.com/image/fetch/$s_!knkf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3234eb1b-ca33-4b13-bc85-4e599170e1d4_1600x902.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>Now is your chance to enter into your most productive era!<br><strong><br></strong>That&#8217;s why we recommend joining <strong><a href="https://link.outskill.com/NEOKIMMAR4">Outskill</a></strong>- the world&#8217;s first AI learning platform where over 10+ Million Learners have learnt from top industry leaders like Microsoft, NVIDIA, and Google.</p><p style="text-align: justify;">They are hosting a 2-day LIVE AI Mastermind where you&#8217;ll build automations, create personalized agents, and learn to turn AI into your ultimate competitive edge.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://link.outskill.com/NEOKIMMAR4&quot;,&quot;text&quot;:&quot;START LEARNING NOW&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://link.outskill.com/NEOKIMMAR4"><span>START LEARNING NOW</span></a></p><p style="text-align: justify;">You will also unlock exclusive bonuses for free when you show up: A Prompt Bible, AI monetization roadmap, and a personalized toolkit builder - for which you would have to pay $1000+ outside. <br><br><strong>&#129504; Happening LIVE- Saturday and Sunday<br>&#128348; 10 AM EST to 7PM EST</strong></p><p><strong><a href="https://link.outskill.com/NEOKIMMAR4">Register here</a> </strong>before they run out of seats. (free for the next 72 hours only!)</p><div><hr></div><p>I want to introduce <strong><a href="https://www.linkedin.com/in/codingwithroby/">Eric Roby</a></strong> as a guest author.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="http://cwroby.com/M9xR2bK7tQs" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!1zG8!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3bb9b58-3c53-4e9d-bf40-fb19cadb4850_1600x811.png 424w, https://substackcdn.com/image/fetch/$s_!1zG8!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3bb9b58-3c53-4e9d-bf40-fb19cadb4850_1600x811.png 848w, https://substackcdn.com/image/fetch/$s_!1zG8!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3bb9b58-3c53-4e9d-bf40-fb19cadb4850_1600x811.png 1272w, https://substackcdn.com/image/fetch/$s_!1zG8!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3bb9b58-3c53-4e9d-bf40-fb19cadb4850_1600x811.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!1zG8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3bb9b58-3c53-4e9d-bf40-fb19cadb4850_1600x811.png" width="1456" height="738" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c3bb9b58-3c53-4e9d-bf40-fb19cadb4850_1600x811.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:738,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:&quot;http://cwroby.com/M9xR2bK7tQs&quot;,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!1zG8!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3bb9b58-3c53-4e9d-bf40-fb19cadb4850_1600x811.png 424w, https://substackcdn.com/image/fetch/$s_!1zG8!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3bb9b58-3c53-4e9d-bf40-fb19cadb4850_1600x811.png 848w, https://substackcdn.com/image/fetch/$s_!1zG8!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3bb9b58-3c53-4e9d-bf40-fb19cadb4850_1600x811.png 1272w, https://substackcdn.com/image/fetch/$s_!1zG8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3bb9b58-3c53-4e9d-bf40-fb19cadb4850_1600x811.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>He&#8217;s a senior backend and AI engineer focused on building real-world systems and teaching developers how to do the same. He runs the YouTube channel <a href="https://www.youtube.com/@codingwithroby">@codingwithroby</a>, where he focuses on backend engineering, and created the platform <a href="http://cwroby.com/M9xR2bK7tQs">The Backend OS</a>.</p><p>Through his content and courses, he helps engineers go beyond tutorials, think in systems, and develop the skills that actually matter for real backend roles.</p><p>Check out <strong><a href="http://cwroby.com/M9xR2bK7tQs">The Backend OS</a></strong>, built to close the knowledge gaps you don&#8217;t even know you have.</p><div><hr></div><h2><strong>The Knowledge Problem</strong></h2><p>We need to understand why LLMs struggle with real-world knowledge before we fix them. The problem has <em>three</em> layers, and none of the obvious solutions work&#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_!Knyq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fee59d528-eb06-4bac-b934-4eabe279e7e6_1280x720.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Knyq!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fee59d528-eb06-4bac-b934-4eabe279e7e6_1280x720.png 424w, https://substackcdn.com/image/fetch/$s_!Knyq!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fee59d528-eb06-4bac-b934-4eabe279e7e6_1280x720.png 848w, https://substackcdn.com/image/fetch/$s_!Knyq!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fee59d528-eb06-4bac-b934-4eabe279e7e6_1280x720.png 1272w, https://substackcdn.com/image/fetch/$s_!Knyq!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fee59d528-eb06-4bac-b934-4eabe279e7e6_1280x720.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Knyq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fee59d528-eb06-4bac-b934-4eabe279e7e6_1280x720.png" width="1280" height="720" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ee59d528-eb06-4bac-b934-4eabe279e7e6_1280x720.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:720,&quot;width&quot;:1280,&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_!Knyq!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fee59d528-eb06-4bac-b934-4eabe279e7e6_1280x720.png 424w, https://substackcdn.com/image/fetch/$s_!Knyq!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fee59d528-eb06-4bac-b934-4eabe279e7e6_1280x720.png 848w, https://substackcdn.com/image/fetch/$s_!Knyq!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fee59d528-eb06-4bac-b934-4eabe279e7e6_1280x720.png 1272w, https://substackcdn.com/image/fetch/$s_!Knyq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fee59d528-eb06-4bac-b934-4eabe279e7e6_1280x720.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><strong>LLM knowledge is frozen at training time</strong></h3><p>Every LLM has a cutoff date for its knowledge.</p><p>Everything the model knows was scraped, processed, and compressed into parameters during training. After that date, the model is blind. It isn&#8217;t aware of your new product launch, yesterday&#8217;s security issue, or this morning&#8217;s HR policy change.</p><p>This isn&#8217;t a minor inconvenience.</p><p>In business, accuracy is crucial. This includes areas like customer support, legal analysis, internal search, and compliance. A model that can&#8217;t access current information is a liability. It doesn&#8217;t help the business at all.</p><h3><strong>Context Windows Aren&#8217;t the Answer</strong></h3><p>The brute-force approach is tempting: <em>dump everything into the prompt.</em></p><p>Context windows<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-5" href="#footnote-5" target="_self">5</a> have increased a lot. Some models can now handle over a million tokens<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-6" href="#footnote-6" target="_self">6</a>. But this approach has three fatal problems.</p><p><strong>First, it&#8217;s expensive</strong>.</p><p>You pay for each token. Sending your entire knowledge base with every query will wipe out your budget.</p><p><strong>Second, there are hard limits.</strong></p><p>A million-token window can&#8217;t fit all of a large enterprise&#8217;s documents or its databases.</p><p><strong>Third, and this is the one most people miss, models get </strong><em><strong>worse</strong></em><strong> with more context.</strong></p><p>Research from Stanford and UC Berkeley shows LLM performance follows a U-shaped curve. Models do best when key information is at the start or end, but accuracy drops sharply when important facts are buried in the middle. In Liu et al.&#8217;s multi-document QA experiments, accuracy for some models dropped to roughly 25% when key information was placed in the middle of a 20-document context.</p><p>It&#8217;s clear: adding more context to the prompt doesn&#8217;t guarantee the model will use it.</p><div><hr></div><h2><strong>Fine-tuning isn&#8217;t the answer either</strong></h2><p>Fine-tuning<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-7" href="#footnote-7" target="_self">7</a> is when you take a pre-trained model and continue training it on your own specific data, so it learns new knowledge or behavior.</p><p>Fine-tuning changes the model&#8217;s weights to incorporate new knowledge. Think of it like sending someone back to school for a specialized course. In theory, this lets you teach the model about your domain.</p><p>In practice, it creates more problems than it solves&#8230;</p><p>It requires GPU compute, machine learning expertise, and carefully prepared training data. It takes days or weeks to complete. The result is a snapshot. Once your underlying data changes, your fine-tuned model becomes stale.</p><h3><strong>What&#8217;s Actually Needed</strong></h3><p>The key is to provide the AI with the right information at the right time for each query. And it should be done without changing the model itself.</p><p>That&#8217;s RAG.</p><p>Now let&#8217;s investigate RAG deeper:</p><div><hr></div><h2><strong>What RAG actually is</strong></h2><p>Retrieval-Augmented Generation is an architectural pattern, not a product. The concept is straightforward, and the best analogy is an open-book exam.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!WV5q!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50ac6e9d-d48d-403a-aafa-40092392d779_1280x720.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!WV5q!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50ac6e9d-d48d-403a-aafa-40092392d779_1280x720.png 424w, https://substackcdn.com/image/fetch/$s_!WV5q!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50ac6e9d-d48d-403a-aafa-40092392d779_1280x720.png 848w, https://substackcdn.com/image/fetch/$s_!WV5q!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50ac6e9d-d48d-403a-aafa-40092392d779_1280x720.png 1272w, https://substackcdn.com/image/fetch/$s_!WV5q!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50ac6e9d-d48d-403a-aafa-40092392d779_1280x720.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!WV5q!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50ac6e9d-d48d-403a-aafa-40092392d779_1280x720.png" width="1280" height="720" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/50ac6e9d-d48d-403a-aafa-40092392d779_1280x720.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:720,&quot;width&quot;:1280,&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_!WV5q!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50ac6e9d-d48d-403a-aafa-40092392d779_1280x720.png 424w, https://substackcdn.com/image/fetch/$s_!WV5q!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50ac6e9d-d48d-403a-aafa-40092392d779_1280x720.png 848w, https://substackcdn.com/image/fetch/$s_!WV5q!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50ac6e9d-d48d-403a-aafa-40092392d779_1280x720.png 1272w, https://substackcdn.com/image/fetch/$s_!WV5q!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50ac6e9d-d48d-403a-aafa-40092392d779_1280x720.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>A student taking a closed-book exam relies on what they have memorized.</p><p>That&#8217;s a standard LLM. It&#8217;s smart and can reason, but it&#8217;s limited to what&#8217;s in its parameters. A student with an open-book exam has the same reasoning skills. They can check relevant pages before answering.</p><p>That&#8217;s RAG.</p><p>The formal definition comes from a 2020 paper by Patrick Lewis and his team at Facebook AI Research and University College London. RAG models combine parametric memory<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-8" href="#footnote-8" target="_self">8</a> with a pre-trained language model and non-parametric memory<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-9" href="#footnote-9" target="_self">9</a>. This non-parametric memory uses an external knowledge index. It&#8217;s accessed by a neural retriever<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-10" href="#footnote-10" target="_self">10</a>.</p><p>You can still update the model&#8217;s knowledge by swapping the retrieval index. No one needs to retrain.</p><p>In practice, RAG follows a three-step loop:</p><ol><li><p>Query comes in: a user asks a question.</p></li><li><p>Retrieve: System looks in an external knowledge base for the best information chunks.</p></li><li><p>Question and context go to the LLM. It then creates an answer based on the retrieved documents.</p></li></ol><p>You&#8217;re not changing the model. You&#8217;re changing what it sees. That distinction makes RAG so powerful and so practical.</p><p>The open-book analogy makes sense at a high level. But understanding why it works so well means diving deeper into the topic&#8230;</p><div><hr></div><h2><strong>How RAG Works Under the Hood</strong></h2><p>The three-step loop sounds simple. The engineering that makes it work is where things get interesting.</p><p>A RAG system has two main parts:</p><ul><li><p>An <strong>offline ingestion pipeline</strong> that gets your data ready.</p></li><li><p>An <strong>online retrieval pipeline</strong> that answers queries.</p></li></ul><p>Let&#8217;s walk through each one&#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_!y9LI!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F821e9ca3-44bb-4aae-87c9-26d932f2f67a_1280x720.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!y9LI!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F821e9ca3-44bb-4aae-87c9-26d932f2f67a_1280x720.png 424w, https://substackcdn.com/image/fetch/$s_!y9LI!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F821e9ca3-44bb-4aae-87c9-26d932f2f67a_1280x720.png 848w, https://substackcdn.com/image/fetch/$s_!y9LI!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F821e9ca3-44bb-4aae-87c9-26d932f2f67a_1280x720.png 1272w, https://substackcdn.com/image/fetch/$s_!y9LI!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F821e9ca3-44bb-4aae-87c9-26d932f2f67a_1280x720.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!y9LI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F821e9ca3-44bb-4aae-87c9-26d932f2f67a_1280x720.png" width="1280" height="720" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/821e9ca3-44bb-4aae-87c9-26d932f2f67a_1280x720.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:720,&quot;width&quot;:1280,&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_!y9LI!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F821e9ca3-44bb-4aae-87c9-26d932f2f67a_1280x720.png 424w, https://substackcdn.com/image/fetch/$s_!y9LI!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F821e9ca3-44bb-4aae-87c9-26d932f2f67a_1280x720.png 848w, https://substackcdn.com/image/fetch/$s_!y9LI!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F821e9ca3-44bb-4aae-87c9-26d932f2f67a_1280x720.png 1272w, https://substackcdn.com/image/fetch/$s_!y9LI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F821e9ca3-44bb-4aae-87c9-26d932f2f67a_1280x720.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><strong>Embeddings: Core Mechanism</strong></h3><p>Before anything else, you need to understand embeddings<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-11" href="#footnote-11" target="_self">11</a>. This is the concept that enables semantic search<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-12" href="#footnote-12" target="_self">12</a>.</p><p>Text embeddings turn text into dense numerical vectors<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-13" href="#footnote-13" target="_self">13</a>. These are arrays of floating-point numbers, usually with 1,536 or 3,072 dimensions. They capture the text meaning. The magic is in what &#8220;capture meaning&#8221; means. Words and sentences with similar intent are close together in vector space. This happens even with different words.</p><p>Consider this: <em>&#8220;How do I reset my password?&#8221;</em> and <em>&#8220;I can&#8217;t log into my account&#8221;</em> use completely different words.</p><p>But when converted to embeddings, they produce nearly identical vectors. The distance between them is tiny because their meanings are similar. This is measured using cosine similarity<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-14" href="#footnote-14" target="_self">14</a>, dot product, or Euclidean distance.</p><p>The key insight for RAG is clear.</p><p>System finds relevant content. It does this even if the user&#8217;s question doesn&#8217;t use the exact words from the source document. It searches by meaning, not by keywords.</p><h3><strong>Data Ingestion Pipeline (Offline Phase)</strong></h3><p>First, process your knowledge base. Then, index it. Only then can your RAG system answer questions.</p><p>This happens in five steps:</p><p><strong>What triggers the offline phase?</strong></p><p>In traditional workflows, this pipeline runs when new data is available. This can happen when documents are added or updated. It can also occur when a database changes or on a regular schedule, like nightly or weekly. Some teams trigger re-ingestion if retrieval quality drops.</p><p>They also do this when a new data source connects:</p><ol><li><p><strong>Load documents from anywhere</strong>: PDFs, databases, APIs, wikis, Slack channels, and Confluence pages. Frameworks like LangChain<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-15" href="#footnote-15" target="_self">15</a> and LlamaIndex<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-16" href="#footnote-16" target="_self">16</a> offer ready-made connectors for many common sources.</p></li><li><p><strong>Chunking</strong><a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-17" href="#footnote-17" target="_self">17</a><strong>: </strong>Split documents into semantically meaningful pieces. This is the single highest-leverage step to get right, and we will cover it in depth later.</p></li><li><p><strong>Embedding:</strong> Convert each chunk into a vector using an embedding model.</p></li><li><p><strong>Storage:</strong> Store the vectors in a vector database<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-18" href="#footnote-18" target="_self">18</a> optimized for similarity search.</p></li><li><p><strong>Metadata tagging:</strong> Tag each chunk with source, timestamp, category, and access control information. This metadata becomes critical for filtering, attribution, and security later.</p></li></ol><h3><strong>Retrieval Pipeline (Online Phase)</strong></h3><p>When a user asks a question, the retrieval pipeline kicks in:</p><ol><li><p><strong>Query embedding</strong>: User&#8217;s question turns into a vector. This uses the same embedding model from ingestion. This is critical: the query and the documents must live in the same vector space.</p></li><li><p><strong>Similarity search</strong>: The system finds the top-K<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-19" href="#footnote-19" target="_self">19</a> similar chunks. It compares the query vector to each vector in the database.</p></li><li><p><strong>Retrieval strategy</strong>: This is where the real engineering decisions happen. Three primary approaches exist:</p><ol><li><p>Sparse retrieval<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-20" href="#footnote-20" target="_self">20</a> uses a statistical method that matches exact keywords. It weighs these matches using term frequency and inverse document frequency.</p></li><li><p>Dense retrieval (embeddings):<strong> </strong>Semantic search via vectors. Finds conceptually relevant content even when the wording differs.</p></li><li><p>Hybrid search (combining both): Use both sparse and dense retrieval. Then, merge the results with Reciprocal Rank Fusion<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-21" href="#footnote-21" target="_self">21</a> (RRF). This boosts documents that rank high in both systems.</p></li></ol></li><li><p><strong>Re-ranking</strong>: After retrieving results, a cross-encoder model rescans them. It processes the query and each document as one input. This captures fine-grained relevance that bi-encoders miss.</p></li></ol><h3><strong>Generation Phase</strong></h3><p>With the most relevant chunks in hand, the system assembles the final prompt:</p><ol><li><p><strong>Prompt Construction:</strong></p><ol><li><p><strong>System Prompt:</strong> Combine the system prompt (the instructions that tell the LLM how to behave, like <em>&#8220;You are a helpful customer support agent&#8221;</em>) with the user&#8217;s request.</p></li><li><p><strong>Retrieved Context Chunks:</strong> Integrate the relevant pieces of text pulled from your knowledge base. For instance, if someone asks, <em>&#8220;What&#8217;s your refund policy?&#8221;</em> You might pull two paragraphs from your company&#8217;s policy document.</p></li><li><p><strong>User&#8217;s Original Query:</strong> Include the user&#8217;s actual question or task &#8212; exactly as they typed it.</p></li></ol></li><li><p><strong>LLM Call:</strong> The model generates an answer grounded in the retrieved documents. The key facts are in the prompt. The model uses these facts to reason instead of relying on its trained memory. Think of it like giving someone an open-book exam instead of asking them to answer from memory.</p></li><li><p><strong>Citation and Attribution:</strong> The system shows which source documents were used and provides verifiable citations. For example, the response might say, <em>&#8220;Based on Section 3.2 of the Employee Handbook...&#8221;</em> so the user knows exactly where the answer came from. This is one of RAG&#8217;s biggest advantages over fine-tuning: transparency.</p></li></ol><p>Now that you know how RAG works mechanically, the real question is whether it&#8217;s the right tool. That depends on what you&#8217;re comparing it to&#8230;</p><div><hr></div><h2><strong>Why RAG over alternatives?</strong></h2><p>RAG isn&#8217;t the only approach to giving AI access to knowledge.</p><p>You need to know when to use it and when not to. This means comparing it to other options.</p><h3><strong>RAG vs. Fine-Tuning</strong></h3><p>This is the comparison most teams face first. Here&#8217;s how they stack up:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!1-2N!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80bd91be-a383-4f21-a05e-1a2acadabb96_1164x814.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!1-2N!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80bd91be-a383-4f21-a05e-1a2acadabb96_1164x814.png 424w, https://substackcdn.com/image/fetch/$s_!1-2N!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80bd91be-a383-4f21-a05e-1a2acadabb96_1164x814.png 848w, https://substackcdn.com/image/fetch/$s_!1-2N!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80bd91be-a383-4f21-a05e-1a2acadabb96_1164x814.png 1272w, https://substackcdn.com/image/fetch/$s_!1-2N!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80bd91be-a383-4f21-a05e-1a2acadabb96_1164x814.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!1-2N!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80bd91be-a383-4f21-a05e-1a2acadabb96_1164x814.png" width="1164" height="814" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/80bd91be-a383-4f21-a05e-1a2acadabb96_1164x814.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:814,&quot;width&quot;:1164,&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_!1-2N!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80bd91be-a383-4f21-a05e-1a2acadabb96_1164x814.png 424w, https://substackcdn.com/image/fetch/$s_!1-2N!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80bd91be-a383-4f21-a05e-1a2acadabb96_1164x814.png 848w, https://substackcdn.com/image/fetch/$s_!1-2N!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80bd91be-a383-4f21-a05e-1a2acadabb96_1164x814.png 1272w, https://substackcdn.com/image/fetch/$s_!1-2N!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80bd91be-a383-4f21-a05e-1a2acadabb96_1164x814.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 key nuance: fine-tuning and RAG are complementary, not competing.</p><p>Fine-tuning is the best option when you want to adjust the model&#8217;s behavior, style, or output format, not just its knowledge. The best production systems do two things: they fine-tune style and behavior, and then they use RAG for knowledge. You can adjust a model to produce structured JSON in a certain format.</p><p>Then, use RAG to fill it with up-to-date data.</p><h3><strong>RAG vs. Long Context Windows</strong></h3><p>Context windows keep growing. Why not dump everything in the prompt?</p><p>Cost and precision. RAG retrieves only the 5-20 most relevant chunks. Long context stuffs everything in and hopes the model finds the needle. RAG is cheaper per query. It&#8217;s also more precise in what it finds. Plus, it can search millions of documents, unlike others that have a token limit.</p><p>They work well together: first, use RAG to get the right 20 chunks.</p><p>Then, use long context to process them all at once. The &#8220;lost in the middle&#8221; research shows that retrieving small, relevant chunks works better than using large context windows.</p><div><hr></div><p><em><strong>Reminder: this is a teaser of the subscriber-only newsletter series, exclusive to my golden members.</strong></em></p><p>When you upgrade, you&#8217;ll get:</p><ul><li><p><strong>High-level architecture of real-world systems.</strong></p></li><li><p>Deep dive into how popular real-world systems actually work.</p></li><li><p><strong>How real-world systems handle scale, reliability, and performance.</strong></p></li></ul><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://newsletter.systemdesign.one/subscribe?"><span>Subscribe now</span></a></p><div><hr></div><h2><strong>Traditional RAG vs. Agentic RAG</strong></h2><p>Traditional RAG follows the straightforward three-step loop described above: retrieve, then generate. It works well for simple question-answering but has limitations. What happens when the first retrieval doesn&#8217;t return good results? Traditional RAG just pushes forward with whatever it finds.</p><p>Agentic RAG adds a reasoning layer on top.</p><p>An AI agent decides how to handle each query. It can change the search, link several retrievals, pick a knowledge base, or skip retrieval completely. Think of Traditional RAG as a student who looks up one page and writes their answer. Agentic RAG is like a student. They check several sources. They re-read sections that seem off and cross-reference information before writing.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!WJ3i!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb15a5d41-dd18-4a64-bd28-79621c669aec_1404x570.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!WJ3i!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb15a5d41-dd18-4a64-bd28-79621c669aec_1404x570.png 424w, https://substackcdn.com/image/fetch/$s_!WJ3i!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb15a5d41-dd18-4a64-bd28-79621c669aec_1404x570.png 848w, https://substackcdn.com/image/fetch/$s_!WJ3i!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb15a5d41-dd18-4a64-bd28-79621c669aec_1404x570.png 1272w, https://substackcdn.com/image/fetch/$s_!WJ3i!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb15a5d41-dd18-4a64-bd28-79621c669aec_1404x570.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!WJ3i!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb15a5d41-dd18-4a64-bd28-79621c669aec_1404x570.png" width="1404" height="570" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b15a5d41-dd18-4a64-bd28-79621c669aec_1404x570.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:570,&quot;width&quot;:1404,&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_!WJ3i!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb15a5d41-dd18-4a64-bd28-79621c669aec_1404x570.png 424w, https://substackcdn.com/image/fetch/$s_!WJ3i!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb15a5d41-dd18-4a64-bd28-79621c669aec_1404x570.png 848w, https://substackcdn.com/image/fetch/$s_!WJ3i!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb15a5d41-dd18-4a64-bd28-79621c669aec_1404x570.png 1272w, https://substackcdn.com/image/fetch/$s_!WJ3i!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb15a5d41-dd18-4a64-bd28-79621c669aec_1404x570.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><div><hr></div><h2><strong>Multi-Step RAG Pipeline</strong></h2><p>Production RAG systems often go beyond the simple retrieve-and-generate loop. A multi-step pipeline adds intelligence before and after retrieval:</p><ol><li><p>Query Intent Parsing: Before searching, the system analyzes what the user actually wants. Is it a factual question? A comparison? A request for a summary? Understanding intent helps the system choose the right retrieval strategy and knowledge base.</p></li><li><p>Query Reformulation: The system may rewrite the user&#8217;s question to improve retrieval quality. For example, <em>&#8220;Why is my app slow?&#8221;</em> might become <em>&#8220;application performance bottleneck causes and solutions.&#8221;</em></p></li><li><p>Retrieval: System searches for relevant chunks (as described above).</p></li><li><p>Live Web Search: If internal documents aren&#8217;t enough, some RAG systems can do live web searches. This helps them get current information from the internet.</p></li><li><p>Reranking<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-22" href="#footnote-22" target="_self">22</a> and Filtering: Results are scored, filtered, and reranked for relevance.</p></li><li><p>Generation: LLM produces an answer grounded in all the gathered context.</p></li></ol><p>This multi-step approach is what separates demo-quality RAG from production-quality RAG.</p><div><hr></div><h2><strong>RAG Limitations</strong></h2><p>RAG is powerful, but it&#8217;s not a silver bullet&#8230;</p><p>Understanding its limitations helps you decide when to use it and when to look elsewhere:</p>
      <p>
          <a href="https://newsletter.systemdesign.one/p/how-rag-works">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[I struggled with AI agents until I built an incident response agent ]]></title><description><![CDATA[#131: Step-by-step guide to building your first AI agent]]></description><link>https://newsletter.systemdesign.one/p/how-do-ai-agents-work</link><guid isPermaLink="false">https://newsletter.systemdesign.one/p/how-do-ai-agents-work</guid><dc:creator><![CDATA[Neo Kim]]></dc:creator><pubDate>Wed, 18 Mar 2026 14:17:46 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/f7e5768b-0414-42da-a26b-8d52dce3dbad_1280x720.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/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">Get my system design playbook for FREE on newsletter signup:</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><ul><li><p><em><a href="https://newsletter.systemdesign.one/p/how-do-ai-agents-work/?action=share">Share this post</a> &amp; I'll send you some rewards for the referrals.</em></p></li></ul><div><hr></div><p>Everyone is talking about AI agents, but only very few people are actually building them.</p><p>Plugging a chatbot into your website is just a UI update. The biggest opportunity is in agentic AI, and most people are missing it&#8230;</p><p>Onward.</p><div><hr></div><h2><strong><a href="https://orchidsapp.link/neokim">The best way to build any app (Partner)</a></strong></h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://orchidsapp.link/neokim" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Yv56!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7ea1369-7f5d-400e-8b47-3c49bf1e055e_1600x900.png 424w, https://substackcdn.com/image/fetch/$s_!Yv56!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7ea1369-7f5d-400e-8b47-3c49bf1e055e_1600x900.png 848w, https://substackcdn.com/image/fetch/$s_!Yv56!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7ea1369-7f5d-400e-8b47-3c49bf1e055e_1600x900.png 1272w, https://substackcdn.com/image/fetch/$s_!Yv56!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7ea1369-7f5d-400e-8b47-3c49bf1e055e_1600x900.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Yv56!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7ea1369-7f5d-400e-8b47-3c49bf1e055e_1600x900.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e7ea1369-7f5d-400e-8b47-3c49bf1e055e_1600x900.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:&quot;https://orchidsapp.link/neokim&quot;,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!Yv56!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7ea1369-7f5d-400e-8b47-3c49bf1e055e_1600x900.png 424w, https://substackcdn.com/image/fetch/$s_!Yv56!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7ea1369-7f5d-400e-8b47-3c49bf1e055e_1600x900.png 848w, https://substackcdn.com/image/fetch/$s_!Yv56!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7ea1369-7f5d-400e-8b47-3c49bf1e055e_1600x900.png 1272w, https://substackcdn.com/image/fetch/$s_!Yv56!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7ea1369-7f5d-400e-8b47-3c49bf1e055e_1600x900.png 1456w" sizes="100vw" loading="lazy" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The real tax on vibe builders right now isn&#8217;t effort, it&#8217;s cost.</p><p>Every tool wants you to pay for its model usage and hosting forever. <strong><a href="https://orchidsapp.link/neokim">Orchids.app</a></strong> lets you bring your own and use tools/SDKs that already exist elsewhere.</p><p>Plug in your ChatGPT, Claude Code, Gemini, Copilot, GLM, or any API key you already pay for.</p><p>You keep control of the bill. And the best part is: you don&#8217;t get price locked because you shipped with Orchids. Deploy your code straight to Vercel with one click.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://orchidsapp.link/neokim&quot;,&quot;text&quot;:&quot;Get Started Today&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://orchidsapp.link/neokim"><span>Get Started Today</span></a></p><p><em>(Use this discount code to get a onetime 15% off during checkout: MARCH15)</em></p><div><hr></div><p>I want to introduce <strong><a href="https://strategizeyourcareer.com/5eca9a08">Fran Soto</a></strong> as a guest author.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://strategizeyourcareer.com/5eca9a08" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!niZ1!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1a17bef-6a7e-4b53-ad17-52124c0a8fe8_755x467.png 424w, https://substackcdn.com/image/fetch/$s_!niZ1!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1a17bef-6a7e-4b53-ad17-52124c0a8fe8_755x467.png 848w, https://substackcdn.com/image/fetch/$s_!niZ1!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1a17bef-6a7e-4b53-ad17-52124c0a8fe8_755x467.png 1272w, https://substackcdn.com/image/fetch/$s_!niZ1!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1a17bef-6a7e-4b53-ad17-52124c0a8fe8_755x467.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!niZ1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1a17bef-6a7e-4b53-ad17-52124c0a8fe8_755x467.png" width="755" height="467" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c1a17bef-6a7e-4b53-ad17-52124c0a8fe8_755x467.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:467,&quot;width&quot;:755,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:&quot;https://strategizeyourcareer.com/5eca9a08&quot;,&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_!niZ1!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1a17bef-6a7e-4b53-ad17-52124c0a8fe8_755x467.png 424w, https://substackcdn.com/image/fetch/$s_!niZ1!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1a17bef-6a7e-4b53-ad17-52124c0a8fe8_755x467.png 848w, https://substackcdn.com/image/fetch/$s_!niZ1!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1a17bef-6a7e-4b53-ad17-52124c0a8fe8_755x467.png 1272w, https://substackcdn.com/image/fetch/$s_!niZ1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1a17bef-6a7e-4b53-ad17-52124c0a8fe8_755x467.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>Fran is a software engineer at Amazon. He&#8217;s responsible for most of the &#8220;Add to Cart&#8221; and other buttons you see in the search results of the Amazon marketplace, and now works at Ring.</p><p>Fran helps software engineers grow their careers. He teaches them productivity and the AI automation skills they need to grow to the next level.</p><p>To celebrate this collaboration, Fran is giving away his premium <strong><a href="https://strategizeyourcareer.com/5eca9a08">System Design Template</a></strong> completely free to all new subscribers. This template is the perfect tool to structure your architectural decisions before you write any code. You can practice filling it with the case studies and deep dives from this newsletter!</p><p>For the next few days, you can also claim a <a href="https://strategizeyourcareer.com/5eca9a08">25% discount on the StrategizeYourCareer</a> annual subscription from the links in this newsletter. Whether you grab the annual discount or just want the free template, join today to become a productive engineer.</p><p>Check out his newsletter: <strong><a href="https://strategizeyourcareer.com/5eca9a08">StrategizeYourCareer</a></strong>.</p><div><hr></div><p>Imagine you have just bought some furniture and now you have to assemble it&#8230;</p><p>The fixed set of instructions that comes in the box is a <em>workflow</em>. It is a linear path that works perfectly as long as everything goes right. It&#8217;s the equivalent of scripts and programming languages. But if you make a mistake and break a wooden part, the instructions cannot help you.</p><p>There is no recovery from that.</p><p>An <em>LLM</em> would be like having a customer support line available for you to call.</p><p>You can describe the broken piece, and they will give you a brilliant, empathetic answer. They might even explain why the wood snapped. But at the end of the call, you are still sitting on the floor with a broken piece. No matter how nice the other person is, they don&#8217;t have hands to help you with your broken piece.</p><p>You are the <em>agent</em> in this scenario.</p><p>You are the one with the tools, like a hammer, nails, glue, and a drill. You are the one with the brain to make decisions on how to best use those tools and how to recover from errors that were never in the initial instructions.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!wQlo!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77387cc1-ff47-45fd-a0d7-a925acd69fd0_1456x769.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!wQlo!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77387cc1-ff47-45fd-a0d7-a925acd69fd0_1456x769.jpeg 424w, https://substackcdn.com/image/fetch/$s_!wQlo!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77387cc1-ff47-45fd-a0d7-a925acd69fd0_1456x769.jpeg 848w, https://substackcdn.com/image/fetch/$s_!wQlo!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77387cc1-ff47-45fd-a0d7-a925acd69fd0_1456x769.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!wQlo!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77387cc1-ff47-45fd-a0d7-a925acd69fd0_1456x769.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!wQlo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77387cc1-ff47-45fd-a0d7-a925acd69fd0_1456x769.jpeg" width="1456" height="769" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/77387cc1-ff47-45fd-a0d7-a925acd69fd0_1456x769.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:769,&quot;width&quot;:1456,&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_!wQlo!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77387cc1-ff47-45fd-a0d7-a925acd69fd0_1456x769.jpeg 424w, https://substackcdn.com/image/fetch/$s_!wQlo!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77387cc1-ff47-45fd-a0d7-a925acd69fd0_1456x769.jpeg 848w, https://substackcdn.com/image/fetch/$s_!wQlo!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77387cc1-ff47-45fd-a0d7-a925acd69fd0_1456x769.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!wQlo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77387cc1-ff47-45fd-a0d7-a925acd69fd0_1456x769.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>In this newsletter, I want to show you how to build AI agents, providing the tools and knowledge they need to do work on your behalf.</p><p>I will use an <strong>incident response agent</strong> as an example, but the principles of giving an AI both a brain and a set of hands apply to almost any process.</p><h4><strong>In this newsletter, you&#8217;ll learn:</strong></h4><ul><li><p>The differences between LLMs, workflows, and agents.</p></li><li><p>Why the non-deterministic nature of AI is a good feature.</p></li><li><p>A 10-step framework to evolve from manual work to autonomous agents.</p></li><li><p>How and when to keep the human in the loop.</p></li></ul><p>Let&#8217;s get started:</p><div><hr></div><h2><strong>Why the lack of determinism in AI is good for reliability and self-healing</strong></h2><p>I see a lot of skepticism about AI because it is NOT as reliable as traditional code.</p><p>We are used to code that does exactly the same thing every time. However, I believe this lack of determinism is actually a good thing for certain tasks.</p><p>Humans are not as reliable as a machine, yet we are the ones who fix machines when they break. We prefer humans using machines because it brings the best of both worlds. Machines give us the speed and precision of determinism, while humans make things not go as expected.</p><p>An agent mimics this human ability to adapt to new situations. When a system fails in a way you did not anticipate, an agent can review the logs and adjust its approach.</p><p>It&#8217;s self-healing.</p><p>However, to get the most out of agents, instead of using the out-of-the-box generic tool, you need to create your own agents tailored to your use case.</p><div><hr></div><h2><strong>How to build your first AI agent</strong></h2><p>AI companies provide us with generic agents that have planning capabilities and built-in tools. While these are useful, I do not think we want a generic assistant for specialized tasks.</p><p>They also offer integration points to our own memories and tools.</p><p>This is where the opportunity is. The same way a company would hire a software engineer rather than a &#8220;generic human&#8221;, we want that same level of expertise in our agents.</p><p>Building an agent is not a one-step process where you just flip a switch and everything works perfectly. It is an iterative process in which you gradually offload parts of your cognitive load to the machine while keeping a close eye on its performance.</p><p>I&#8217;ve followed this <strong>10-step framework</strong> that starts with pure manual work and ends with a fleet of autonomous agents working together&#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_!9eSj!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F224202ec-78af-409e-b926-aeef281cff43_1600x883.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!9eSj!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F224202ec-78af-409e-b926-aeef281cff43_1600x883.png 424w, https://substackcdn.com/image/fetch/$s_!9eSj!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F224202ec-78af-409e-b926-aeef281cff43_1600x883.png 848w, https://substackcdn.com/image/fetch/$s_!9eSj!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F224202ec-78af-409e-b926-aeef281cff43_1600x883.png 1272w, https://substackcdn.com/image/fetch/$s_!9eSj!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F224202ec-78af-409e-b926-aeef281cff43_1600x883.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!9eSj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F224202ec-78af-409e-b926-aeef281cff43_1600x883.png" width="1456" height="804" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/224202ec-78af-409e-b926-aeef281cff43_1600x883.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:804,&quot;width&quot;:1456,&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_!9eSj!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F224202ec-78af-409e-b926-aeef281cff43_1600x883.png 424w, https://substackcdn.com/image/fetch/$s_!9eSj!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F224202ec-78af-409e-b926-aeef281cff43_1600x883.png 848w, https://substackcdn.com/image/fetch/$s_!9eSj!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F224202ec-78af-409e-b926-aeef281cff43_1600x883.png 1272w, https://substackcdn.com/image/fetch/$s_!9eSj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F224202ec-78af-409e-b926-aeef281cff43_1600x883.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>(This process starts with the way we have always worked: Solving it manually.)</em></p><div><hr></div><h3><strong>Step 1. Do the work manually</strong></h3><p>The first step is always to do the work yourself&#8230;</p><p>I recommend outlining the steps as if you were documenting the runbook for someone else to follow:</p><ol><li><p><em>You open the monitoring dashboard and check any metric outside the usual pattern.</em></p></li><li><p><em>You check the runbooks for troubleshooting info for that specific metric.</em></p></li><li><p><em>You query the error logs for the last 15 minutes, looking for requests that resulted in an HTTP 500 error.</em></p></li></ol><p><strong>Current state:</strong> At this stage, you are the bottleneck in the entire process. Every step requires your manual intervention and your attention. This is the baseline that we want to improve.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!SGGl!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9105ef28-954b-49e9-8e5a-166a8d25c75e_569x471.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!SGGl!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9105ef28-954b-49e9-8e5a-166a8d25c75e_569x471.png 424w, https://substackcdn.com/image/fetch/$s_!SGGl!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9105ef28-954b-49e9-8e5a-166a8d25c75e_569x471.png 848w, https://substackcdn.com/image/fetch/$s_!SGGl!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9105ef28-954b-49e9-8e5a-166a8d25c75e_569x471.png 1272w, https://substackcdn.com/image/fetch/$s_!SGGl!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9105ef28-954b-49e9-8e5a-166a8d25c75e_569x471.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!SGGl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9105ef28-954b-49e9-8e5a-166a8d25c75e_569x471.png" width="569" height="471" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9105ef28-954b-49e9-8e5a-166a8d25c75e_569x471.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:471,&quot;width&quot;:569,&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_!SGGl!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9105ef28-954b-49e9-8e5a-166a8d25c75e_569x471.png 424w, https://substackcdn.com/image/fetch/$s_!SGGl!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9105ef28-954b-49e9-8e5a-166a8d25c75e_569x471.png 848w, https://substackcdn.com/image/fetch/$s_!SGGl!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9105ef28-954b-49e9-8e5a-166a8d25c75e_569x471.png 1272w, https://substackcdn.com/image/fetch/$s_!SGGl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9105ef28-954b-49e9-8e5a-166a8d25c75e_569x471.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><div><hr></div><h3><strong>Step 2. Start using an LLM</strong></h3><p>Now that you have a solid manual process, you can use it as a guide for an LLM.</p><p>This moves us from manual labor to having an assistant who can analyze the data for you. You can prompt the AI by copy-pasting the logs from your terminal or the metrics from your dashboard.</p><p>I suggest paying close attention to the prompts you usually use.</p><ul><li><p><em>&#8220;Review these logs to find what error is happening:</em> <em>&lt;copy-paste of logs&gt;&#8221;</em></p></li></ul><p>At this point, it&#8217;s important to notice the areas where the AI does not do what you want, and how you steer it back to the right path when it goes off track.</p><p><strong>Current state:</strong> The AI can start analyzing patterns, but you still have to orchestrate everything and move data around manually.</p><div><hr></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!xQae!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13dba869-5e2d-4ee5-8635-c7914ebe28bf_570x666.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!xQae!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13dba869-5e2d-4ee5-8635-c7914ebe28bf_570x666.png 424w, https://substackcdn.com/image/fetch/$s_!xQae!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13dba869-5e2d-4ee5-8635-c7914ebe28bf_570x666.png 848w, https://substackcdn.com/image/fetch/$s_!xQae!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13dba869-5e2d-4ee5-8635-c7914ebe28bf_570x666.png 1272w, https://substackcdn.com/image/fetch/$s_!xQae!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13dba869-5e2d-4ee5-8635-c7914ebe28bf_570x666.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!xQae!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13dba869-5e2d-4ee5-8635-c7914ebe28bf_570x666.png" width="616" height="719.7473684210527" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/13dba869-5e2d-4ee5-8635-c7914ebe28bf_570x666.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:666,&quot;width&quot;:570,&quot;resizeWidth&quot;:616,&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_!xQae!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13dba869-5e2d-4ee5-8635-c7914ebe28bf_570x666.png 424w, https://substackcdn.com/image/fetch/$s_!xQae!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13dba869-5e2d-4ee5-8635-c7914ebe28bf_570x666.png 848w, https://substackcdn.com/image/fetch/$s_!xQae!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13dba869-5e2d-4ee5-8635-c7914ebe28bf_570x666.png 1272w, https://substackcdn.com/image/fetch/$s_!xQae!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13dba869-5e2d-4ee5-8635-c7914ebe28bf_570x666.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><div><hr></div><h3><strong>Step 3. Add MCP Tools</strong></h3><p>At this stage, you have an AI partner helping with the analysis, but you are still stuck in the middle, acting as a bridge.</p><p>The next step is to stop copy-pasting data. You can use the Model Context Protocol (<strong>MCP<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a></strong>) to allow the AI to take actions for you. MCP is like HTTP for AI agents. It&#8217;s an API that enables the model to execute operations in other systems.</p><p>Once you connect to the right MCP servers and enable the MCP tools, your prompts will look like this:</p><ul><li><p><em>&#8220;Obtain the alarms that fired in the last 15 minutes. You must give me only the alarm name.&#8221;</em></p></li><li><p><em>&#8220;Check the logs for requests ending with an HTTP 500 error. You must give me the message of the log, the error message, and the stack trace...&#8221;</em></p></li></ul><p>The AI can get the incident details on its own!</p><p><strong>Current state:</strong> The human can drive the entire process through the AI interface without switching between tabs and tools.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!cWMn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fffd37a94-e18c-499e-8097-16dec45a32ce_928x601.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!cWMn!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fffd37a94-e18c-499e-8097-16dec45a32ce_928x601.png 424w, https://substackcdn.com/image/fetch/$s_!cWMn!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fffd37a94-e18c-499e-8097-16dec45a32ce_928x601.png 848w, https://substackcdn.com/image/fetch/$s_!cWMn!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fffd37a94-e18c-499e-8097-16dec45a32ce_928x601.png 1272w, https://substackcdn.com/image/fetch/$s_!cWMn!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fffd37a94-e18c-499e-8097-16dec45a32ce_928x601.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!cWMn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fffd37a94-e18c-499e-8097-16dec45a32ce_928x601.png" width="928" height="601" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ffd37a94-e18c-499e-8097-16dec45a32ce_928x601.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:601,&quot;width&quot;:928,&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_!cWMn!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fffd37a94-e18c-499e-8097-16dec45a32ce_928x601.png 424w, https://substackcdn.com/image/fetch/$s_!cWMn!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fffd37a94-e18c-499e-8097-16dec45a32ce_928x601.png 848w, https://substackcdn.com/image/fetch/$s_!cWMn!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fffd37a94-e18c-499e-8097-16dec45a32ce_928x601.png 1272w, https://substackcdn.com/image/fetch/$s_!cWMn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fffd37a94-e18c-499e-8097-16dec45a32ce_928x601.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><div><hr></div><h3><strong>Step 4. Add Agent Skills</strong></h3><p>Up to this point, you still have to be an expert in incident response&#8230;</p><p>AI is useful for doing everything from one place. Now we&#8217;ll start looking at the notes we have been taking on how to improve the process and where AI usually goes wrong.</p><p>We have to onboard the AI to incident response the same way we&#8217;d onboard a junior engineer recently hired:</p><ul><li><p>Teach exactly how to use each tool.</p></li><li><p>Teach how you want the work done.</p></li></ul><p>We can combine guides and Standard Operating Procedures.</p><p>These provide step-by-step instructions for routine tasks. We&#8217;d write them in human language, using small scripts, to address a problem with determinism.</p><p>For example, if the MCP tools require a query as input, we can create the <em>Skill</em> of building a query. We&#8217;ll combine a markdown guide containing the fields from the logs with a few scripts to build queries from a template. This is much better than having the AI write complex queries every time. Plus, it reduces the hallucinations of fields that don&#8217;t exist in your logs.</p><p>We call these reusable pieces of logic <strong>Agent Skills</strong>.</p><p>Agent Skills are great because they&#8217;re loaded into the model ONLY when needed. The agent may have skills for metrics and logs. If we only ask about fired alarms, the agent ignores the log data. It just doesn&#8217;t need it.</p><p>This saves memory.</p><p>With agent skills, our interaction would be like this (Slash is the syntax used in IDEs like Cursor<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-2" href="#footnote-2" target="_self">2</a> to force the agent to load a particular skill):</p><ul><li><p><em>/Metrics-and-alarm-management Find the alarms fired</em></p></li><li><p><em>&lt;LLM response with metrics information&gt;</em></p></li><li><p><em>/My-service-logs-management Find the logs with errors in these endpoints</em></p></li><li><p><em>&lt;LLM response with the logs information&gt;</em></p></li><li><p><em>/Code-expert Where in code is this log emitted?</em></p></li><li><p><em>&lt;LLM response with the code information&gt;</em></p></li></ul><p><strong>Current state:</strong> We have now taught AI how we want certain tasks done, such as metrics and log information. The human is orchestrating the process to do things in order.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!CYT9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F261798a3-0b8b-4805-ac8b-00817488b602_905x560.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!CYT9!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F261798a3-0b8b-4805-ac8b-00817488b602_905x560.png 424w, https://substackcdn.com/image/fetch/$s_!CYT9!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F261798a3-0b8b-4805-ac8b-00817488b602_905x560.png 848w, https://substackcdn.com/image/fetch/$s_!CYT9!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F261798a3-0b8b-4805-ac8b-00817488b602_905x560.png 1272w, https://substackcdn.com/image/fetch/$s_!CYT9!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F261798a3-0b8b-4805-ac8b-00817488b602_905x560.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!CYT9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F261798a3-0b8b-4805-ac8b-00817488b602_905x560.png" width="905" height="560" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/261798a3-0b8b-4805-ac8b-00817488b602_905x560.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:560,&quot;width&quot;:905,&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_!CYT9!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F261798a3-0b8b-4805-ac8b-00817488b602_905x560.png 424w, https://substackcdn.com/image/fetch/$s_!CYT9!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F261798a3-0b8b-4805-ac8b-00817488b602_905x560.png 848w, https://substackcdn.com/image/fetch/$s_!CYT9!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F261798a3-0b8b-4805-ac8b-00817488b602_905x560.png 1272w, https://substackcdn.com/image/fetch/$s_!CYT9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F261798a3-0b8b-4805-ac8b-00817488b602_905x560.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><div><hr></div><h3><strong>Step 5. Add memory</strong></h3><p>We have given our agent tools and domain expertise, but every time you start a new chat, it&#8217;s like the agent has amnesia. It knows how to solve an incident, but it doesn&#8217;t remember the one you fixed yesterday.</p><p>An agent needs context to be effective&#8230;</p><p>You can add simple <em>short-term memory</em> <em>and</em> <em>long-term memory</em> files to your system.</p><p>The short-term memory is built by design into the agent. This is essentially the AI&#8217;s ability to remember the previous messages in your current conversation. It helps it stay on track without you having to repeat yourself. When making an API call to get the model&#8217;s response, it sends the previous messages along with the new ones.</p><p>For an incident response agent, we also want some long-term memory.</p><p>We have added some memory thanks to the skills, but we can add more context by creating files that the AI can access.</p><p>Some time ago, each company had its own format, but now they have agreed on a standard called <code>Agents.md</code><a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-3" href="#footnote-3" target="_self">3</a>. This means the information inside <code>Agents.md</code> file will be read by the AI regardless of which AI it is.</p><p>Also, each implementation allows you to point to which folders/files to use for the agent&#8217;s context.</p><p><strong>Current state:</strong> We still prompt AI the same way. It uses data from skills and logs. It also reads files to understand the system it is debugging. This helps the AI find past errors and the solutions that worked.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!a1RB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0475afed-6dde-470a-ba4b-1936f09917b2_952x535.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!a1RB!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0475afed-6dde-470a-ba4b-1936f09917b2_952x535.png 424w, https://substackcdn.com/image/fetch/$s_!a1RB!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0475afed-6dde-470a-ba4b-1936f09917b2_952x535.png 848w, https://substackcdn.com/image/fetch/$s_!a1RB!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0475afed-6dde-470a-ba4b-1936f09917b2_952x535.png 1272w, https://substackcdn.com/image/fetch/$s_!a1RB!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0475afed-6dde-470a-ba4b-1936f09917b2_952x535.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!a1RB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0475afed-6dde-470a-ba4b-1936f09917b2_952x535.png" width="952" height="535" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0475afed-6dde-470a-ba4b-1936f09917b2_952x535.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:535,&quot;width&quot;:952,&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_!a1RB!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0475afed-6dde-470a-ba4b-1936f09917b2_952x535.png 424w, https://substackcdn.com/image/fetch/$s_!a1RB!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0475afed-6dde-470a-ba4b-1936f09917b2_952x535.png 848w, https://substackcdn.com/image/fetch/$s_!a1RB!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0475afed-6dde-470a-ba4b-1936f09917b2_952x535.png 1272w, https://substackcdn.com/image/fetch/$s_!a1RB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0475afed-6dde-470a-ba4b-1936f09917b2_952x535.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><div><hr></div><h3><strong>Step 6. Orchestrate with Agent SOPs</strong></h3><p>Up to this point, we have given our agent a brain, a set of hands through MCP tools, and a memory.</p><p>But you are still the one directing every move. While the agent is now more capable, it still requires you to decide manually what to use and when. This is the bottleneck that we solve with Agent SOPs.</p><p>Instead of prompting the AI to use a series of skills one by one, you can create a step-by-step process for the AI to follow. This is what&#8217;s called a Standard Operating Procedure (<strong>SOP</strong>) for your agent.</p><p>An Agent SOP is a file written in accordance with RFC 2119<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-4" href="#footnote-4" target="_self">4</a>. This RFC defines key capitalized words (MUST, SHOULD, MAY, etc.) to specify requirement levels. Besides, it contains the steps in order.</p><p>I learned about this concept at work, as Amazon uses it in its Kiro<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-5" href="#footnote-5" target="_self">5</a> and Strands<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-6" href="#footnote-6" target="_self">6</a> agents. However, I&#8217;m also using Agent SOPs with Cursor and Claude Code<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-7" href="#footnote-7" target="_self">7</a> easily. You just have to write the markdown file as an Agent Skill.</p><p>Now, instead of prompting step by step, we just execute our agent with that SOP. For example, if we wrap our SOP in a skill:</p><ul><li><p><em>/Incident-response-agent-sop Investigate the incident reported at JIRA-1234</em></p></li></ul><p><strong>Current state:</strong> This makes the agent much more autonomous. The human just invokes the right SOP, and the agent handles the rest. It&#8217;s like a high-level manager finding the right engineer to loop into a call.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!VdRL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44d8abaf-2c06-4df1-b9ee-58cdab0fe20c_952x557.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!VdRL!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44d8abaf-2c06-4df1-b9ee-58cdab0fe20c_952x557.png 424w, https://substackcdn.com/image/fetch/$s_!VdRL!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44d8abaf-2c06-4df1-b9ee-58cdab0fe20c_952x557.png 848w, https://substackcdn.com/image/fetch/$s_!VdRL!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44d8abaf-2c06-4df1-b9ee-58cdab0fe20c_952x557.png 1272w, https://substackcdn.com/image/fetch/$s_!VdRL!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44d8abaf-2c06-4df1-b9ee-58cdab0fe20c_952x557.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!VdRL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44d8abaf-2c06-4df1-b9ee-58cdab0fe20c_952x557.png" width="952" height="557" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/44d8abaf-2c06-4df1-b9ee-58cdab0fe20c_952x557.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:557,&quot;width&quot;:952,&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_!VdRL!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44d8abaf-2c06-4df1-b9ee-58cdab0fe20c_952x557.png 424w, https://substackcdn.com/image/fetch/$s_!VdRL!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44d8abaf-2c06-4df1-b9ee-58cdab0fe20c_952x557.png 848w, https://substackcdn.com/image/fetch/$s_!VdRL!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44d8abaf-2c06-4df1-b9ee-58cdab0fe20c_952x557.png 1272w, https://substackcdn.com/image/fetch/$s_!VdRL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44d8abaf-2c06-4df1-b9ee-58cdab0fe20c_952x557.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><div><hr></div><h3><strong>Step 7. Define an agent</strong></h3><p>At this point, we have many MCP tools, skills agent SOPs that need to be configured and made available for our agent to work.</p><p>This is easy if this is your first agent, but when you have dozens of them, each using their own set of artifacts, things get hard&#8230;</p><p>We solved this problem in traditional software with dependencies. We declare which packages our software depends on, so it can run in different environments.</p><p>Now it&#8217;s time to declare those dependencies with a new artifact called an <em>agent</em>. This way, we&#8217;d have our incident response agent, and we can define other agents for other purposes.</p><p>This guarantees the AI has all the tools it needs, so you do not need to provide them manually. Currently, there isn&#8217;t a proper package manager to install all of these, but it&#8217;s just a matter of time&#8230;</p><p><strong>Current state:</strong> We now have our agent, and we can delegate the entire incident response investigation to it. We just invoke it and wait for the results.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!UyN-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3d77f20-c556-4b76-b7fa-b4d875ab7f74_958x563.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!UyN-!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3d77f20-c556-4b76-b7fa-b4d875ab7f74_958x563.png 424w, https://substackcdn.com/image/fetch/$s_!UyN-!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3d77f20-c556-4b76-b7fa-b4d875ab7f74_958x563.png 848w, https://substackcdn.com/image/fetch/$s_!UyN-!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3d77f20-c556-4b76-b7fa-b4d875ab7f74_958x563.png 1272w, https://substackcdn.com/image/fetch/$s_!UyN-!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3d77f20-c556-4b76-b7fa-b4d875ab7f74_958x563.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!UyN-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3d77f20-c556-4b76-b7fa-b4d875ab7f74_958x563.png" width="958" height="563" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f3d77f20-c556-4b76-b7fa-b4d875ab7f74_958x563.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:563,&quot;width&quot;:958,&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_!UyN-!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3d77f20-c556-4b76-b7fa-b4d875ab7f74_958x563.png 424w, https://substackcdn.com/image/fetch/$s_!UyN-!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3d77f20-c556-4b76-b7fa-b4d875ab7f74_958x563.png 848w, https://substackcdn.com/image/fetch/$s_!UyN-!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3d77f20-c556-4b76-b7fa-b4d875ab7f74_958x563.png 1272w, https://substackcdn.com/image/fetch/$s_!UyN-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3d77f20-c556-4b76-b7fa-b4d875ab7f74_958x563.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><div><hr></div><h3><strong>Step 8. Execute your agent periodically</strong></h3><p>Up to this point, we have a fully defined agent that knows exactly what to do, but it only moves when you tell it to.</p><p>You have built a great tool, but you are still the one holding the power button&#8230;</p><p>Now that we can delegate most work to AI, you may ask: <em>Why am I still getting paged at 3 am just to invoke the agent and wait?</em></p><p>It&#8217;s time to set the AI agent to run autonomously&#8230;</p><p>I recommend using CLI tools to run your AI agent independently. We can start with a simple script that checks for work and runs the AI agent when found; otherwise, sleep for N minutes.</p><p><strong>Current state:</strong> Now the human isn&#8217;t involved in triggering the agent, but it will find the alarm and the agent&#8217;s output together.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!lsQO!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd7e6e4d-7e57-4425-a72f-31a8f6dbda20_1038x636.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!lsQO!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd7e6e4d-7e57-4425-a72f-31a8f6dbda20_1038x636.png 424w, https://substackcdn.com/image/fetch/$s_!lsQO!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd7e6e4d-7e57-4425-a72f-31a8f6dbda20_1038x636.png 848w, https://substackcdn.com/image/fetch/$s_!lsQO!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd7e6e4d-7e57-4425-a72f-31a8f6dbda20_1038x636.png 1272w, https://substackcdn.com/image/fetch/$s_!lsQO!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd7e6e4d-7e57-4425-a72f-31a8f6dbda20_1038x636.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!lsQO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd7e6e4d-7e57-4425-a72f-31a8f6dbda20_1038x636.png" width="1038" height="636" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bd7e6e4d-7e57-4425-a72f-31a8f6dbda20_1038x636.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:636,&quot;width&quot;:1038,&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_!lsQO!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd7e6e4d-7e57-4425-a72f-31a8f6dbda20_1038x636.png 424w, https://substackcdn.com/image/fetch/$s_!lsQO!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd7e6e4d-7e57-4425-a72f-31a8f6dbda20_1038x636.png 848w, https://substackcdn.com/image/fetch/$s_!lsQO!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd7e6e4d-7e57-4425-a72f-31a8f6dbda20_1038x636.png 1272w, https://substackcdn.com/image/fetch/$s_!lsQO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd7e6e4d-7e57-4425-a72f-31a8f6dbda20_1038x636.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><div><hr></div><h3><strong>Step 9. Improve state management</strong></h3><p>The agent is now running on its own, but it&#8217;s still isolated on your local machine using basic loops. To make it a true part of your team, it needs to be integrated into your production environment&#8230;</p><p>The goal is to define an end-to-end workflow that triggers AI agents at the right time without human involvement. For example, a webhook from PagerDuty could automatically trigger the AI agent in Lambda.</p><p>For periodic reports, you may want to set up a cron<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-8" href="#footnote-8" target="_self">8</a> job that triggers the AI agent at regular intervals.</p><p>The AI agent performs the investigation and then posts a summary of the root cause or a periodic report to a Slack channel. This means your agent is working while you sleep, even if it only does one specific thing well.</p><p><strong>Current state:</strong> Now our agent is like a real engineer involved when an incident happens, or an engineer who has scheduled work in their calendar.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!-kv2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7388cd2-038b-4bb9-af67-2dd27746cea3_1046x605.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!-kv2!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7388cd2-038b-4bb9-af67-2dd27746cea3_1046x605.png 424w, https://substackcdn.com/image/fetch/$s_!-kv2!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7388cd2-038b-4bb9-af67-2dd27746cea3_1046x605.png 848w, https://substackcdn.com/image/fetch/$s_!-kv2!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7388cd2-038b-4bb9-af67-2dd27746cea3_1046x605.png 1272w, https://substackcdn.com/image/fetch/$s_!-kv2!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7388cd2-038b-4bb9-af67-2dd27746cea3_1046x605.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!-kv2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7388cd2-038b-4bb9-af67-2dd27746cea3_1046x605.png" width="1046" height="605" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c7388cd2-038b-4bb9-af67-2dd27746cea3_1046x605.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:605,&quot;width&quot;:1046,&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_!-kv2!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7388cd2-038b-4bb9-af67-2dd27746cea3_1046x605.png 424w, https://substackcdn.com/image/fetch/$s_!-kv2!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7388cd2-038b-4bb9-af67-2dd27746cea3_1046x605.png 848w, https://substackcdn.com/image/fetch/$s_!-kv2!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7388cd2-038b-4bb9-af67-2dd27746cea3_1046x605.png 1272w, https://substackcdn.com/image/fetch/$s_!-kv2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7388cd2-038b-4bb9-af67-2dd27746cea3_1046x605.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><div><hr></div><h3><strong>Step 10. Scale to multiple agents</strong></h3><p>At this stage, you have a specialized agent working 24/7.</p><p>But as your system grows, one agent can become overloaded with too many responsibilities. Just as you wouldn&#8217;t ask one engineer to handle every single microservice, we shouldn&#8217;t ask one agent to do it all.</p><p>The final step is to have multiple agents collaborating on the same incident. Each agent can have a different function based on its expertise:</p><ul><li><p>One agent gathers the raw logs while another checks for known infrastructure issues.</p></li><li><p>Another agent could review the recent code deployments for errors.</p></li></ul><p>There are different orchestration paradigms you can use, like sequential, routing, or swarms.</p><p>Even for the same function, there&#8217;s no limit to how much you specialize. If an incident response agent has too many details, you can create agents to check different parts of the system.</p><p>You need a bit of abstraction to manage your AI workforce, just as a manager coordinates a team of specialists. You just do the same: multiple specialist agents, and a manager that invokes each subagent.</p><p>You can use different triggers, such as schedules or events, to make agents collaborate via the file system. No need to start with complex agent-communication protocols; instead:</p><ol><li><p>Start with an orchestrator agent triggered by events, schedule, or polling.</p></li><li><p>The orchestrator invokes other subagents that you have also defined. Most AI companies already implement subagents.</p></li><li><p>All agents write to the filesystem, so they see each other&#8217;s work.</p></li></ol><p>I suggest running agents on your own computer and letting them work together by sharing files.</p><p><strong>Current state:</strong> At this point, the AI performs complex work with multiple steps without your involvement. Humans are no longer the bottleneck.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!bGMs!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7fb3aca7-ad8f-474c-802b-2263e9b97578_1019x594.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!bGMs!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7fb3aca7-ad8f-474c-802b-2263e9b97578_1019x594.png 424w, https://substackcdn.com/image/fetch/$s_!bGMs!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7fb3aca7-ad8f-474c-802b-2263e9b97578_1019x594.png 848w, https://substackcdn.com/image/fetch/$s_!bGMs!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7fb3aca7-ad8f-474c-802b-2263e9b97578_1019x594.png 1272w, https://substackcdn.com/image/fetch/$s_!bGMs!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7fb3aca7-ad8f-474c-802b-2263e9b97578_1019x594.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!bGMs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7fb3aca7-ad8f-474c-802b-2263e9b97578_1019x594.png" width="1019" height="594" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7fb3aca7-ad8f-474c-802b-2263e9b97578_1019x594.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:594,&quot;width&quot;:1019,&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_!bGMs!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7fb3aca7-ad8f-474c-802b-2263e9b97578_1019x594.png 424w, https://substackcdn.com/image/fetch/$s_!bGMs!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7fb3aca7-ad8f-474c-802b-2263e9b97578_1019x594.png 848w, https://substackcdn.com/image/fetch/$s_!bGMs!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7fb3aca7-ad8f-474c-802b-2263e9b97578_1019x594.png 1272w, https://substackcdn.com/image/fetch/$s_!bGMs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7fb3aca7-ad8f-474c-802b-2263e9b97578_1019x594.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>We did it!</p><p>Now we have our autonomous AI agent for incident response.</p><p>I know it looks easier in diagrams than in practice, and the AI doesn&#8217;t work as expected. Let me also share some lessons from building AI agents.</p><div><hr></div><h2><strong>Lessons from the trenches</strong></h2><p>I&#8217;ve spent a lot of time building these agents, and I want to share some practical advice that will save you hours of frustration:</p><ul><li><p><strong>Make sure you have enough examples to build a robust agent.</strong> You wouldn&#8217;t want to automate a task that isn't frequent, so you're likely to have multiple instances to iterate on. I asked my team to handle all intakes of a service for a month. I&#8217;m sure your manager will be happy you're taking on more work.</p></li><li><p><strong>Iterate multiple times per step.</strong> Don&#8217;t move to the next step of the automation until you have solved several tickets or tasks to find the real patterns and failure modes.</p></li><li><p><strong>Don&#8217;t switch tabs while AI works.</strong> Watch the agent work live to catch its mistakes instead of letting it run in the background.</p></li><li><p><strong>Use tmux</strong><a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-9" href="#footnote-9" target="_self">9</a><strong> for persistent loops.</strong> Run your agents from your computer in a tmux session so they keep working even if you lose your terminal connection.</p></li><li><p><strong>Log everything for observability.</strong> Pipe all the agent&#8217;s output into a dedicated log file to give you the same level of visibility when you move to executing it 24/7.</p></li><li><p><strong>Refine prompts based on observations.</strong> Even after you consider the 10 steps done, new edge cases will arise. Make AI keep learning, either by updating it yourself or by letting the AI update its memory files between iterations.</p></li></ul><div><hr></div><h2><strong>Defining the role of the human in the loop</strong></h2><p>I want to be clear that this is not about all-human or all-AI systems&#8230;</p><p>I&#8217;ve focused the incident response agent examples on read-only tasks, such as checking alarms, metrics, and logs.</p><p>Each of us has to define where and when to involve humans for the highest leverage. You can have the agent triage the incident and suggest a fix, then wait for your approval and execution.</p><p>Maybe someone else wants to plug the AI into the codebase to create a PR with the fix and wait for a human to approve it and deploy the hotfix.</p><p>I still think we don&#8217;t want AI making changes in production without human oversight. I have read postmortems where AI ran unauthorized production operations in an AWS account without any human review.</p><p>If we think about the incident response process and a code change, there are many steps before we change something in the system&#8230;</p><p>My current stance on agents is to push the human to the right as much as possible. This is all about making the human do less work, but still overseeing. This is important because no one will ask the AI for ownership or accountability.</p><p>They&#8217;ll ask the humans for it!</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!pTtY!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea0fb247-5a41-4c75-b22a-c7570de02078_681x225.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!pTtY!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea0fb247-5a41-4c75-b22a-c7570de02078_681x225.png 424w, https://substackcdn.com/image/fetch/$s_!pTtY!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea0fb247-5a41-4c75-b22a-c7570de02078_681x225.png 848w, https://substackcdn.com/image/fetch/$s_!pTtY!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea0fb247-5a41-4c75-b22a-c7570de02078_681x225.png 1272w, https://substackcdn.com/image/fetch/$s_!pTtY!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea0fb247-5a41-4c75-b22a-c7570de02078_681x225.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!pTtY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea0fb247-5a41-4c75-b22a-c7570de02078_681x225.png" width="681" height="225" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ea0fb247-5a41-4c75-b22a-c7570de02078_681x225.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:225,&quot;width&quot;:681,&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_!pTtY!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea0fb247-5a41-4c75-b22a-c7570de02078_681x225.png 424w, https://substackcdn.com/image/fetch/$s_!pTtY!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea0fb247-5a41-4c75-b22a-c7570de02078_681x225.png 848w, https://substackcdn.com/image/fetch/$s_!pTtY!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea0fb247-5a41-4c75-b22a-c7570de02078_681x225.png 1272w, https://substackcdn.com/image/fetch/$s_!pTtY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea0fb247-5a41-4c75-b22a-c7570de02078_681x225.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><div><hr></div><h2><strong>TLDR: The Building Blocks of AI Agents</strong></h2><ul><li><p><strong>Brain (LLM):</strong> The Large Language Model processes information, makes decisions, and determines which steps to take.</p></li><li><p><strong>Hands (Tools &amp; MCP):</strong> They are the interfaces that allow the AI to interact with the real world. Using the MCP, an agent can execute code, query databases, or fetch logs instead of just &#8220;talking&#8221; back to you.</p></li><li><p><strong>Skills (Agent Skills &amp; SOPs):</strong> They teach the model how to perform tasks. This is like a junior engineer following a runbook. It reduces errors and hallucinations.</p></li><li><p><strong>Memory (Context &amp; Agents.md):</strong> This allows the agent to remember past actions. Short-term memory handles the current conversation. Long-term memory provides historical context through shared files. This prevents the agent from repeating mistakes.</p></li><li><p><strong>Manager (Orchestrator):</strong> Use an orchestrator to manage multiple specialized agents as you scale. One agent might find the error, while another suggests a fix, all working together toward a final result.</p></li><li><p><strong>Alarm clock (Cron job):</strong> It lets the agent run on a schedule without you having to manually start it.</p></li><li><p><strong>Workspace (Local filesystem):</strong> A common area where agents read and write. This allows them to collaborate on complex problems.</p></li></ul><div><hr></div><h2><strong>Closing Thoughts: The future of agentic work</strong></h2><p>It is often said that AI will not take your job, but someone using AI will.</p><p>I truly believe this.</p><p>But &#8220;using AI&#8221; does not just mean installing a new extension in your IDE. I have seen many people get frustrated when the AI does not do exactly what they want on the first try, thinking the AI is just dumb.</p><p>The people who succeed are the ones who build an army of AI agents to do the heavy lifting for them. All those AI companies are giving us default tools, but we are the ones who must adapt them to our specific needs.</p><p>I hope this guide was helpful and that you start building your own agents today.</p><div><hr></div><p>&#128075; I&#8217;d like to thank <a href="https://strategizeyourcareer.com/5eca9a08">Fran</a> for writing this newsletter!</p><ul><li><p>Also subscribe to his newsletter, <strong><a href="https://strategizeyourcareer.com/5eca9a08">StrategizeYourCareer</a>.</strong></p></li></ul><p>It will help you master productivity and the AI automation skills needed to thrive in your career, just like we learned in this post.</p><p><em>Remember to claim your free System Design Template by signing up today at <a href="https://strategizeyourcareer.com/5eca9a08">StrategizeYourCareer</a>. You can also take advantage of his special discount before it expires!</em></p><div><hr></div><p>If you find this newsletter valuable, share it with a friend, and subscribe if you haven&#8217;t already. There are <a href="http://newsletter.systemdesign.one/subscribe?group=true">group discounts</a>, <a href="http://newsletter.systemdesign.one/subscribe?gift=true">gift options</a>, and <a href="https://newsletter.systemdesign.one/leaderboard">referral rewards</a> available.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/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://newsletter.systemdesign.one/subscribe?"><span>Subscribe now</span></a></p><div><hr></div><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://www.linkedin.com/in/nk-systemdesign-one/" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!bEFk!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 424w, https://substackcdn.com/image/fetch/$s_!bEFk!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 848w, https://substackcdn.com/image/fetch/$s_!bEFk!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 1272w, https://substackcdn.com/image/fetch/$s_!bEFk!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!bEFk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png" width="152" height="152" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:320,&quot;width&quot;:320,&quot;resizeWidth&quot;:152,&quot;bytes&quot;:74009,&quot;alt&quot;:&quot;Author Neo Kim; System design case studies&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:&quot;https://www.linkedin.com/in/nk-systemdesign-one/&quot;,&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="Author Neo Kim; System design case studies" title="Author Neo Kim; System design case studies" srcset="https://substackcdn.com/image/fetch/$s_!bEFk!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 424w, https://substackcdn.com/image/fetch/$s_!bEFk!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 848w, https://substackcdn.com/image/fetch/$s_!bEFk!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 1272w, https://substackcdn.com/image/fetch/$s_!bEFk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption"><strong>&#128075; Find me on <a href="https://www.linkedin.com/in/nk-systemdesign-one/">LinkedIn</a> | <a href="https://x.com/intent/follow?screen_name=systemdesignone">Twitter</a> | <a href="https://www.threads.net/@systemdesignone">Threads</a> | <a href="https://www.instagram.com/systemdesignone/">Instagram</a></strong></figcaption></figure></div><div><hr></div><p>Thank you for supporting this newsletter.</p><p>You are now 210,001+ readers strong, very close to 210k. Let&#8217;s try to get 211k readers by 21 March. Consider sharing this post with your friends and get rewards.</p><p>Y&#8217;all are the best.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!6oWl!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!6oWl!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png 424w, https://substackcdn.com/image/fetch/$s_!6oWl!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png 848w, https://substackcdn.com/image/fetch/$s_!6oWl!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png 1272w, https://substackcdn.com/image/fetch/$s_!6oWl!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!6oWl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png" width="590" height="368.75" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2e739087-a910-4643-be36-997b6dd5b4af_800x500.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:500,&quot;width&quot;:800,&quot;resizeWidth&quot;:590,&quot;bytes&quot;:87878,&quot;alt&quot;:&quot;system design newsletter&quot;,&quot;title&quot;:&quot;system design newsletter&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/163380418?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="system design newsletter" title="system design newsletter" srcset="https://substackcdn.com/image/fetch/$s_!6oWl!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png 424w, https://substackcdn.com/image/fetch/$s_!6oWl!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png 848w, https://substackcdn.com/image/fetch/$s_!6oWl!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png 1272w, https://substackcdn.com/image/fetch/$s_!6oWl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.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 class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/p/how-do-ai-agents-work?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesign.one/p/how-do-ai-agents-work?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</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>An open standard that enables AI models to interact with local and remote data and tools. https://modelcontextprotocol.io/docs/getting-started/intro</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>An AI-powered code editor designed for pair programming and agentic workflows. It also has a CLI available. https://cursor.com/</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 standard format for providing context and instructions to AI agents within a repository. https://agents.md/</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 document defining requirement levels like &#8220;MUST&#8221; and &#8220;SHOULD&#8221; used in engineering documentation. https://datatracker.ietf.org/doc/html/rfc2119</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>An AI agent framework designed to automate engineering tasks and workflows. It has an IDE and CLI as products https://kiro.dev/</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>An open-source framework for building and orchestrating autonomous AI agents. https://strandsagents.com/latest/</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>Anthropic's agentic CLI tool that can reason about and edit your codebase directly. https://claude.com/product/claude-code</p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-8" href="#footnote-anchor-8" class="footnote-number" contenteditable="false" target="_self">8</a><div class="footnote-content"><p>A tool to execute commands on a schedule https://en.wikipedia.org/wiki/Cron</p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-9" href="#footnote-anchor-9" class="footnote-number" contenteditable="false" target="_self">9</a><div class="footnote-content"><p>A terminal multiplexer that allows you to keep terminal sessions running in the background. https://github.com/tmux/tmux/wiki</p><p></p></div></div>]]></content:encoded></item><item><title><![CDATA[21 Reinforcement Learning (RL) Concepts Explained Simply]]></title><description><![CDATA[#130: Finally understand RL without getting confused by its fancy math equations]]></description><link>https://newsletter.systemdesign.one/p/what-is-reinforcement-learning</link><guid isPermaLink="false">https://newsletter.systemdesign.one/p/what-is-reinforcement-learning</guid><dc:creator><![CDATA[Neo Kim]]></dc:creator><pubDate>Sat, 14 Mar 2026 12:20:34 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/782723cc-fb12-4234-9759-4149a3cd7a78_1280x720.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/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">Get my system design playbook for FREE on newsletter signup:</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><ul><li><p><em><a href="https://newsletter.systemdesign.one/p/what-is-reinforcement-learning/?action=share">Share this post</a> &amp; I'll send you some rewards for the referrals.</em></p></li></ul><div><hr></div><p>Reinforcement learning (<strong>RL</strong>) is making a comeback and becoming mainstream.</p><p>From humanoid robots and game-playing AIs that beat world champions to the LLMs you chat with every day, all are trained using RL, which lets them learn from experience and get better through feedback.</p><p>Contrary to many tutorials that can make it look so hard, RL is actually pretty intuitive, and you really don&#8217;t need a PhD to understand how it works.</p><p>In this newsletter, we will go through 21 key RL concepts to build a solid foundation from the ground up. These terms are all explained in plain language without using any fancy math equations.</p><p>Let&#8217;s start from the very beginning&#8230;</p><div><hr></div><h2><a href="https://coderabbit.link/neo-mar">Want to reduce AI coding bugs before they hit production? (Partner)</a></h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://coderabbit.link/neo-mar" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!l5WB!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71527969-46aa-4ba3-b906-9cf60b671161_1271x699.png 424w, https://substackcdn.com/image/fetch/$s_!l5WB!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71527969-46aa-4ba3-b906-9cf60b671161_1271x699.png 848w, https://substackcdn.com/image/fetch/$s_!l5WB!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71527969-46aa-4ba3-b906-9cf60b671161_1271x699.png 1272w, https://substackcdn.com/image/fetch/$s_!l5WB!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71527969-46aa-4ba3-b906-9cf60b671161_1271x699.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!l5WB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71527969-46aa-4ba3-b906-9cf60b671161_1271x699.png" width="1271" height="699" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/71527969-46aa-4ba3-b906-9cf60b671161_1271x699.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:699,&quot;width&quot;:1271,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:&quot;https://coderabbit.link/neo-mar&quot;,&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_!l5WB!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71527969-46aa-4ba3-b906-9cf60b671161_1271x699.png 424w, https://substackcdn.com/image/fetch/$s_!l5WB!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71527969-46aa-4ba3-b906-9cf60b671161_1271x699.png 848w, https://substackcdn.com/image/fetch/$s_!l5WB!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71527969-46aa-4ba3-b906-9cf60b671161_1271x699.png 1272w, https://substackcdn.com/image/fetch/$s_!l5WB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71527969-46aa-4ba3-b906-9cf60b671161_1271x699.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>AI is writing more production code than ever, but it also introduces more risk.</p><p>CodeRabbit&#8217;s research found that AI-generated code contains 1.7x more issues, including 75% more logic errors.</p><p>That&#8217;s exactly why you should grab a copy of the <strong><a href="https://coderabbit.link/neo-mar">Ultimate Prompting Cheat Sheet</a></strong>.</p><p>Here&#8217;s what you get:</p><ul><li><p><strong>Proven prompting techniques to reduce AI coding errors.</strong></p></li><li><p>Actionable workflows for AI-assisted development.</p></li><li><p><strong>Clear frameworks for safer AI-generated code.</strong></p></li><li><p>Practical examples you can apply immediately.</p></li></ul><p>And many more!</p><p>These techniques reduce defects without slowing velocity, regardless of which AI coding tool you use.</p><p>Sign up and get access to the ultimate prompting cheat sheet right now:</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://coderabbit.link/neo-mar&quot;,&quot;text&quot;:&quot;GET INSTANT ACCESS&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://coderabbit.link/neo-mar"><span>GET INSTANT ACCESS</span></a></p><p>(Thanks to CodeRabbit for partnering on this post &amp; sharing the <a href="https://coderabbit.link/neo-mar">ultimate prompting cheat sheet</a>.)</p><div><hr></div><p>I want to reintroduce <strong><a href="https://www.linkedin.com/in/ashishbamania/">Ashish Bamania</a></strong> as a guest author.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://www.linkedin.com/in/ashishbamania/" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Shux!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F470743b8-73e1-411b-85a6-80c14b0d8d54_1558x906.png 424w, https://substackcdn.com/image/fetch/$s_!Shux!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F470743b8-73e1-411b-85a6-80c14b0d8d54_1558x906.png 848w, https://substackcdn.com/image/fetch/$s_!Shux!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F470743b8-73e1-411b-85a6-80c14b0d8d54_1558x906.png 1272w, https://substackcdn.com/image/fetch/$s_!Shux!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F470743b8-73e1-411b-85a6-80c14b0d8d54_1558x906.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Shux!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F470743b8-73e1-411b-85a6-80c14b0d8d54_1558x906.png" width="1456" height="847" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/470743b8-73e1-411b-85a6-80c14b0d8d54_1558x906.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:847,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:null,&quot;href&quot;:&quot;https://www.linkedin.com/in/ashishbamania/&quot;,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!Shux!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F470743b8-73e1-411b-85a6-80c14b0d8d54_1558x906.png 424w, https://substackcdn.com/image/fetch/$s_!Shux!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F470743b8-73e1-411b-85a6-80c14b0d8d54_1558x906.png 848w, https://substackcdn.com/image/fetch/$s_!Shux!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F470743b8-73e1-411b-85a6-80c14b0d8d54_1558x906.png 1272w, https://substackcdn.com/image/fetch/$s_!Shux!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F470743b8-73e1-411b-85a6-80c14b0d8d54_1558x906.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>He&#8217;s a self-taught software engineer and an emergency physician. He is also the editor and primary author of the newsletters <a href="https://intoai.pub/">Into AI</a> and <a href="https://intoquantum.pub/">Into Quantum</a>.</p><p>The images used in this newsletter come from his books:</p><ul><li><p><strong><a href="https://bamaniaashish.gumroad.com/l/llmbook/NEO20">LLMs In 100 Images</a></strong></p></li></ul><ul><li><p><strong>Reinforcement Learning in 100 Images </strong>(upcoming)</p></li></ul><p>Grab the book at <strong>20% discount today</strong> with the discount code <strong><a href="https://bamaniaashish.gumroad.com/l/llmbook/NEO20">NEO20</a></strong>, pre-applied to the link above!</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://bamaniaashish.gumroad.com/l/llmbook/NEO20" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!OdW0!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28809feb-c484-45a6-a7ef-ca9c42d63270_6912x3456.png 424w, https://substackcdn.com/image/fetch/$s_!OdW0!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28809feb-c484-45a6-a7ef-ca9c42d63270_6912x3456.png 848w, https://substackcdn.com/image/fetch/$s_!OdW0!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28809feb-c484-45a6-a7ef-ca9c42d63270_6912x3456.png 1272w, https://substackcdn.com/image/fetch/$s_!OdW0!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28809feb-c484-45a6-a7ef-ca9c42d63270_6912x3456.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!OdW0!,w_2400,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28809feb-c484-45a6-a7ef-ca9c42d63270_6912x3456.png" width="730" height="365" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/28809feb-c484-45a6-a7ef-ca9c42d63270_6912x3456.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;large&quot;,&quot;height&quot;:728,&quot;width&quot;:1456,&quot;resizeWidth&quot;:730,&quot;bytes&quot;:834004,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:&quot;https://bamaniaashish.gumroad.com/l/llmbook/NEO20&quot;,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.intoai.pub/i/189764942?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28809feb-c484-45a6-a7ef-ca9c42d63270_6912x3456.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:&quot;center&quot;,&quot;offset&quot;:false}" class="sizing-large" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!OdW0!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28809feb-c484-45a6-a7ef-ca9c42d63270_6912x3456.png 424w, https://substackcdn.com/image/fetch/$s_!OdW0!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28809feb-c484-45a6-a7ef-ca9c42d63270_6912x3456.png 848w, https://substackcdn.com/image/fetch/$s_!OdW0!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28809feb-c484-45a6-a7ef-ca9c42d63270_6912x3456.png 1272w, https://substackcdn.com/image/fetch/$s_!OdW0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28809feb-c484-45a6-a7ef-ca9c42d63270_6912x3456.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><div><hr></div><h3><strong>1. What is Reinforcement learning?</strong></h3><p>Let&#8217;s start with the definition of Reinforcement Learning (<strong>RL</strong>).</p><p>RL is a type of machine learning (besides Supervised and Unsupervised learning) that deals with an entity called an &#8216;Agent&#8217;, trying to learn to perform a task better in its &#8216;Environment&#8217; through trial and error.</p><p>For example, a deer (Agent) foraging in a forest (Environment) to survive, avoiding being eaten by its predators.</p><p>We will soon move to more AI-related examples, I promise, but first, let&#8217;s better understand what the terms &#8216;Agent&#8217; and &#8216;Environment&#8217; mean.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!KWWU!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f659f9a-ad05-41bf-ad19-3aa5fb54ea19_1080x1080.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!KWWU!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f659f9a-ad05-41bf-ad19-3aa5fb54ea19_1080x1080.png 424w, https://substackcdn.com/image/fetch/$s_!KWWU!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f659f9a-ad05-41bf-ad19-3aa5fb54ea19_1080x1080.png 848w, https://substackcdn.com/image/fetch/$s_!KWWU!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f659f9a-ad05-41bf-ad19-3aa5fb54ea19_1080x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!KWWU!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f659f9a-ad05-41bf-ad19-3aa5fb54ea19_1080x1080.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!KWWU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f659f9a-ad05-41bf-ad19-3aa5fb54ea19_1080x1080.png" width="1080" height="1080" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6f659f9a-ad05-41bf-ad19-3aa5fb54ea19_1080x1080.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1080,&quot;width&quot;:1080,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:58194,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.intoai.pub/i/189764942?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f659f9a-ad05-41bf-ad19-3aa5fb54ea19_1080x1080.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!KWWU!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f659f9a-ad05-41bf-ad19-3aa5fb54ea19_1080x1080.png 424w, https://substackcdn.com/image/fetch/$s_!KWWU!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f659f9a-ad05-41bf-ad19-3aa5fb54ea19_1080x1080.png 848w, https://substackcdn.com/image/fetch/$s_!KWWU!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f659f9a-ad05-41bf-ad19-3aa5fb54ea19_1080x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!KWWU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f659f9a-ad05-41bf-ad19-3aa5fb54ea19_1080x1080.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><div><hr></div><h3><strong>2. Agent</strong></h3><p>An agent is the central entity in RL.</p><p>It is one that studies and interacts with its environment, makes decisions, takes actions, and learns from its outcomes.</p><p>In our previous case, we used a deer as an agent example, but from now on, we will discuss concepts assuming an LLM as the agent as well.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!G36e!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F39eff2da-de63-42f3-99cf-a5c0a70e864d_1080x1080.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!G36e!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F39eff2da-de63-42f3-99cf-a5c0a70e864d_1080x1080.png 424w, https://substackcdn.com/image/fetch/$s_!G36e!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F39eff2da-de63-42f3-99cf-a5c0a70e864d_1080x1080.png 848w, https://substackcdn.com/image/fetch/$s_!G36e!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F39eff2da-de63-42f3-99cf-a5c0a70e864d_1080x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!G36e!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F39eff2da-de63-42f3-99cf-a5c0a70e864d_1080x1080.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!G36e!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F39eff2da-de63-42f3-99cf-a5c0a70e864d_1080x1080.png" width="1080" height="1080" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/39eff2da-de63-42f3-99cf-a5c0a70e864d_1080x1080.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1080,&quot;width&quot;:1080,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:37902,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.intoai.pub/i/189764942?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F39eff2da-de63-42f3-99cf-a5c0a70e864d_1080x1080.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!G36e!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F39eff2da-de63-42f3-99cf-a5c0a70e864d_1080x1080.png 424w, https://substackcdn.com/image/fetch/$s_!G36e!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F39eff2da-de63-42f3-99cf-a5c0a70e864d_1080x1080.png 848w, https://substackcdn.com/image/fetch/$s_!G36e!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F39eff2da-de63-42f3-99cf-a5c0a70e864d_1080x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!G36e!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F39eff2da-de63-42f3-99cf-a5c0a70e864d_1080x1080.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><div><hr></div><h3><strong>3. Environment</strong></h3><p>The environment is everything outside the agent with which it interacts.</p><p>The function of an environment is to:</p><ul><li><p>Get affected by an agent&#8217;s actions</p></li><li><p>Change its state (or maybe hold its state constant) depending on the agent&#8217;s actions</p></li><li><p>Give the agent a reward or punishment based on its actions, so that the agent can modify its intent the next time it takes an action</p></li></ul><p>In the first case, the deer was functioning in a forest as its environment. Based on the deer&#8217;s actions (moving around in different directions), either the forest (environment) lets it progress towards food (reward) or it exposes it to a cheetah (punishment).</p><p>In the case of an LLM as an agent, everything outside it, such as the following, is part of its environment:</p><ul><li><p>User inputs</p></li><li><p>System prompt</p></li><li><p>Tools / APIs it can call</p></li><li><p>System responses (tool results, API outputs, error messages)</p></li><li><p>Context (documents, conversation history, files)</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_!46u0!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa56e779c-0fa0-4bba-b950-203d27617524_1080x1080.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!46u0!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa56e779c-0fa0-4bba-b950-203d27617524_1080x1080.png 424w, https://substackcdn.com/image/fetch/$s_!46u0!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa56e779c-0fa0-4bba-b950-203d27617524_1080x1080.png 848w, https://substackcdn.com/image/fetch/$s_!46u0!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa56e779c-0fa0-4bba-b950-203d27617524_1080x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!46u0!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa56e779c-0fa0-4bba-b950-203d27617524_1080x1080.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!46u0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa56e779c-0fa0-4bba-b950-203d27617524_1080x1080.png" width="1080" height="1080" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a56e779c-0fa0-4bba-b950-203d27617524_1080x1080.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1080,&quot;width&quot;:1080,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:34579,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.intoai.pub/i/189764942?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa56e779c-0fa0-4bba-b950-203d27617524_1080x1080.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!46u0!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa56e779c-0fa0-4bba-b950-203d27617524_1080x1080.png 424w, https://substackcdn.com/image/fetch/$s_!46u0!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa56e779c-0fa0-4bba-b950-203d27617524_1080x1080.png 848w, https://substackcdn.com/image/fetch/$s_!46u0!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa56e779c-0fa0-4bba-b950-203d27617524_1080x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!46u0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa56e779c-0fa0-4bba-b950-203d27617524_1080x1080.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><div><hr></div><h3><strong>4. State</strong></h3><p>A State is a snapshot of an environment at a time. It is everything an agent sees at a given moment that it can use to make its next decision.</p><p>For a deer agent, it could be its current location in the forest, nearby predators, and the time of day.</p><p>For an LLM agent, it is all the context it has access to at a moment, which it can use to decide its next action.</p><p><em>But what&#8217;s action?</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_!9jG5!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72b4c95a-3713-4961-aecd-583635e1917c_1080x1080.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!9jG5!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72b4c95a-3713-4961-aecd-583635e1917c_1080x1080.png 424w, https://substackcdn.com/image/fetch/$s_!9jG5!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72b4c95a-3713-4961-aecd-583635e1917c_1080x1080.png 848w, https://substackcdn.com/image/fetch/$s_!9jG5!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72b4c95a-3713-4961-aecd-583635e1917c_1080x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!9jG5!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72b4c95a-3713-4961-aecd-583635e1917c_1080x1080.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!9jG5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72b4c95a-3713-4961-aecd-583635e1917c_1080x1080.png" width="1080" height="1080" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/72b4c95a-3713-4961-aecd-583635e1917c_1080x1080.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1080,&quot;width&quot;:1080,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:113427,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.intoai.pub/i/189764942?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72b4c95a-3713-4961-aecd-583635e1917c_1080x1080.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!9jG5!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72b4c95a-3713-4961-aecd-583635e1917c_1080x1080.png 424w, https://substackcdn.com/image/fetch/$s_!9jG5!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72b4c95a-3713-4961-aecd-583635e1917c_1080x1080.png 848w, https://substackcdn.com/image/fetch/$s_!9jG5!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72b4c95a-3713-4961-aecd-583635e1917c_1080x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!9jG5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72b4c95a-3713-4961-aecd-583635e1917c_1080x1080.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><div><hr></div><h3><strong>5. Action</strong></h3>
      <p>
          <a href="https://newsletter.systemdesign.one/p/what-is-reinforcement-learning">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[I struggled with system design until I learned these 114 concepts]]></title><description><![CDATA[#129: Part 3 - Webhooks, WebRTC, CQRS, and 35 others.]]></description><link>https://newsletter.systemdesign.one/p/system-design-fundamentals</link><guid isPermaLink="false">https://newsletter.systemdesign.one/p/system-design-fundamentals</guid><dc:creator><![CDATA[Neo Kim]]></dc:creator><pubDate>Tue, 10 Mar 2026 16:27:36 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/7b3dab87-3707-4525-852e-201fb95d33fb_1280x720.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/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">Get my system design playbook for FREE on newsletter signup:</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><ul><li><p><em><a href="https://newsletter.systemdesign.one/p/system-design-fundamentals/?action=share">Share this post</a> &amp; I'll send you some rewards for the referrals.</em></p></li><li><p><em>Block diagrams created using <a href="https://app.eraser.io/auth/sign-up?ref=neo">Eraser</a>.</em></p></li></ul><div><hr></div><p>No time for small talk today:</p><p>Following is the third of a premium 3-part newsletter series... if you want to be successful with system design in 2026, then this newsletter is for YOU.</p><p>On with part 3 of the newsletter:</p><p>===</p><p>Some of these are foundational, and some are quite advanced. ALL of them are super useful to engineers building production-ready systems.</p><p>Curious to know how many were new to you:</p><ol start="77"><li><p>Webhooks,</p></li><li><p>WebRTC,</p></li><li><p>CQRS,</p></li><li><p>Event Sourcing,</p></li><li><p>Service Discovery,</p></li><li><p>Circuit Breaker Pattern,</p></li><li><p>Bulkhead Pattern,</p></li><li><p>Strangler Fig Pattern,</p></li><li><p>Backend for Frontend.</p></li><li><p>Sidecar Pattern,</p></li><li><p>Service Mesh,</p></li><li><p>Observability,</p></li><li><p>Logging,</p></li><li><p>Metrics,</p></li><li><p>Distributed Tracing,</p></li><li><p>Correlation IDs,</p></li><li><p>Full-Text Search Engine,</p></li><li><p>Time Series Database,</p></li><li><p>Vector Database,</p></li><li><p>Materialized Views,</p></li><li><p>Query Optimization,</p></li><li><p>Connection Pooling,</p></li><li><p>Cache Stampede,</p></li><li><p>Cache Warming,</p></li><li><p>PACELC Theorem,</p></li><li><p>Security Secrets Management,</p></li><li><p>Role-Based Access Control,</p></li><li><p>Single Sign-On,</p></li><li><p>Checksums,</p></li><li><p>Bloom Filter,</p></li><li><p>B-trees and B+ trees,</p></li><li><p>LSM Tree,</p></li><li><p>Merkle Tree,</p></li><li><p>HyperLogLog,</p></li><li><p>Batch vs Stream Processing,</p></li><li><p>ETL Pipelines,</p></li><li><p>MapReduce,</p></li><li><p>Erasure Coding.</p></li></ol><p>For each, I&#8217;ll share:</p><ul><li><p>What it is &amp; how it works--in simple words</p></li><li><p>A real-world analogy</p></li><li><p>Tradeoffs</p></li><li><p>Why it matters</p></li></ul><p>Let&#8217;s go.</p><div><hr></div><h2><a href="https://orchidsapp.link/neokim">The best way to build any app (Partner)</a></h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://orchidsapp.link/neokim" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Yv56!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7ea1369-7f5d-400e-8b47-3c49bf1e055e_1600x900.png 424w, https://substackcdn.com/image/fetch/$s_!Yv56!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7ea1369-7f5d-400e-8b47-3c49bf1e055e_1600x900.png 848w, https://substackcdn.com/image/fetch/$s_!Yv56!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7ea1369-7f5d-400e-8b47-3c49bf1e055e_1600x900.png 1272w, https://substackcdn.com/image/fetch/$s_!Yv56!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7ea1369-7f5d-400e-8b47-3c49bf1e055e_1600x900.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Yv56!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7ea1369-7f5d-400e-8b47-3c49bf1e055e_1600x900.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e7ea1369-7f5d-400e-8b47-3c49bf1e055e_1600x900.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:&quot;https://orchidsapp.link/neokim&quot;,&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_!Yv56!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7ea1369-7f5d-400e-8b47-3c49bf1e055e_1600x900.png 424w, https://substackcdn.com/image/fetch/$s_!Yv56!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7ea1369-7f5d-400e-8b47-3c49bf1e055e_1600x900.png 848w, https://substackcdn.com/image/fetch/$s_!Yv56!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7ea1369-7f5d-400e-8b47-3c49bf1e055e_1600x900.png 1272w, https://substackcdn.com/image/fetch/$s_!Yv56!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7ea1369-7f5d-400e-8b47-3c49bf1e055e_1600x900.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>Most &#8220;AI app builders&#8221; aren&#8217;t actually app builders. They are infrastructure middlemen. You live inside their box, choose from their secret stack, and force you to start over the moment you want to use a different database, payment processor, or tool.</p><p>With <a href="https://orchidsapp.link/neokim">Orchids</a>:</p><ul><li><p>You&#8217;re not locked-in to Supabase or Stripe.</p></li><li><p>Not forced to spend credits, bring your own AI subscriptions with you.</p></li><li><p>One-click deployment straight to Vercel</p></li></ul><p>Build  anything. From web, mobile, internal tools, browser extensions, scripts, and bots. <a href="https://orchidsapp.link/neokim">Orchids.app</a> is capable of building anything that you can put your mind to.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://orchidsapp.link/neokim&quot;,&quot;text&quot;:&quot;Get Started Today&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://orchidsapp.link/neokim"><span>Get Started Today</span></a></p><p><strong>Use this discount code to get a onetime 15% off during checkout: MARCH15</strong></p><div><hr></div><h2><strong>77. Webhooks</strong></h2><blockquote><p>Webhooks are HTTP callbacks that allow one system to notify another system when an event occurs by sending a POST request to a configured URL.</p></blockquote><p>Instead of constantly polling for updates, the source system pushes data to your endpoint when something happens.</p><p>You register a URL with the provider, and they call it when events trigger. Webhooks enable real-time, event-driven integrations between 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_!YE7V!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfa596d6-05ab-4ee3-830c-9dd42c440094_1554x956.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!YE7V!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfa596d6-05ab-4ee3-830c-9dd42c440094_1554x956.png 424w, https://substackcdn.com/image/fetch/$s_!YE7V!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfa596d6-05ab-4ee3-830c-9dd42c440094_1554x956.png 848w, https://substackcdn.com/image/fetch/$s_!YE7V!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfa596d6-05ab-4ee3-830c-9dd42c440094_1554x956.png 1272w, https://substackcdn.com/image/fetch/$s_!YE7V!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfa596d6-05ab-4ee3-830c-9dd42c440094_1554x956.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!YE7V!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfa596d6-05ab-4ee3-830c-9dd42c440094_1554x956.png" width="1456" height="896" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/dfa596d6-05ab-4ee3-830c-9dd42c440094_1554x956.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;: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_!YE7V!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfa596d6-05ab-4ee3-830c-9dd42c440094_1554x956.png 424w, https://substackcdn.com/image/fetch/$s_!YE7V!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfa596d6-05ab-4ee3-830c-9dd42c440094_1554x956.png 848w, https://substackcdn.com/image/fetch/$s_!YE7V!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfa596d6-05ab-4ee3-830c-9dd42c440094_1554x956.png 1272w, https://substackcdn.com/image/fetch/$s_!YE7V!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfa596d6-05ab-4ee3-830c-9dd42c440094_1554x956.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>Analogy</h3><p>A doorbell that alerts you when someone arrives instead of you checking the door every few minutes&#8230;</p><p>When a package arrives, the delivery person rings the bell, and you respond immediately. You don&#8217;t waste time repeatedly checking if anyone&#8217;s there.</p><h3>Tradeoff</h3><p>Webhooks eliminate polling overhead and provide near-instant notifications.</p><p>Yet they require exposing a public endpoint, handling retries when your server is down, securing the endpoint against unauthorized requests, and handling duplicate or out-of-order events.</p><p>The sender controls retry logic, and you can&#8217;t always guarantee delivery.</p><h3>Why it matters</h3><p>Integrating with payment providers like Stripe, receiving GitHub repository events, getting Slack notifications, building event-driven workflows, or any system needing real-time notifications from external services.</p><p>Essential for modern API integrations. Combine with message queues for reliable processing and idempotency for handling duplicates.</p><h2><strong>78. WebRTC</strong></h2><blockquote><p>WebRTC (Web Real-Time Communication) is a technology that enables peer-to-peer<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a> audio, video, and data sharing directly between browsers without requiring servers to relay media.</p></blockquote><p>After initial signaling through a server to establish the connection, media flows directly between peers.</p><p>WebRTC automatically handles:</p><ul><li><p>Getting through NAT and firewalls</p></li><li><p>Encrypting the connection</p></li><li><p>Adjusting video quality based on network speed (adaptive bitrate streaming)</p></li></ul><p>It&#8217;s built into modern browsers, so users don&#8217;t need to install plugins.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!9fWh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ffd443a-7b01-44af-bcdf-a75adc56d0ab_1600x547.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!9fWh!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ffd443a-7b01-44af-bcdf-a75adc56d0ab_1600x547.png 424w, https://substackcdn.com/image/fetch/$s_!9fWh!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ffd443a-7b01-44af-bcdf-a75adc56d0ab_1600x547.png 848w, https://substackcdn.com/image/fetch/$s_!9fWh!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ffd443a-7b01-44af-bcdf-a75adc56d0ab_1600x547.png 1272w, https://substackcdn.com/image/fetch/$s_!9fWh!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ffd443a-7b01-44af-bcdf-a75adc56d0ab_1600x547.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!9fWh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ffd443a-7b01-44af-bcdf-a75adc56d0ab_1600x547.png" width="1456" height="498" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6ffd443a-7b01-44af-bcdf-a75adc56d0ab_1600x547.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:498,&quot;width&quot;:1456,&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_!9fWh!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ffd443a-7b01-44af-bcdf-a75adc56d0ab_1600x547.png 424w, https://substackcdn.com/image/fetch/$s_!9fWh!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ffd443a-7b01-44af-bcdf-a75adc56d0ab_1600x547.png 848w, https://substackcdn.com/image/fetch/$s_!9fWh!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ffd443a-7b01-44af-bcdf-a75adc56d0ab_1600x547.png 1272w, https://substackcdn.com/image/fetch/$s_!9fWh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ffd443a-7b01-44af-bcdf-a75adc56d0ab_1600x547.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>Analogy</h3><p>It is like two people being introduced by a mutual friend:</p><p>The friend shares their phone number, but once they start talking, the friend is no longer on the call.</p><h3>Tradeoff</h3><p>WebRTC offers very low latency, thus making it ideal for live conversations. It can also reduce server costs because media often bypasses backend servers.</p><p>But:</p><ul><li><p>It&#8217;s difficult to implement correctly</p></li><li><p>You usually need a TURN server as a backup when a direct connection cannot be made</p></li><li><p>Debugging network problems can be hard</p></li><li><p>Some corporate networks block peer-to-peer connections</p></li></ul><h3>Why it matters</h3><p>WebRTC powers:</p><ul><li><p>Video calls</p></li><li><p>Screen sharing</p></li><li><p>Voice chat in games</p></li><li><p>Live collaboration tools</p></li></ul><p>It&#8217;s used in Zoom, Google Meet, and Discord.</p><p>If you&#8217;re building a real-time app, you can use WebRTC directly. But consider managed services like Twilio or Agora so you do not have to run your own signaling and TURN servers.</p><h2><strong>79. CQRS</strong></h2><blockquote><p>CQRS (Command Query Responsibility Segregation) means separating how your system writes data from how it reads data.</p></blockquote><ul><li><p>Commands are used to change data. They use a write model optimized to handle updates.</p></li><li><p>Queries are used to read data. They go to a separate read model designed for fast retrieval.</p></li></ul><p>The read model is often eventually consistent, updated asynchronously from the write model using events.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!G-b3!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37241a29-75d8-448a-b7ae-7b76dac7db8f_1600x978.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!G-b3!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37241a29-75d8-448a-b7ae-7b76dac7db8f_1600x978.png 424w, https://substackcdn.com/image/fetch/$s_!G-b3!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37241a29-75d8-448a-b7ae-7b76dac7db8f_1600x978.png 848w, https://substackcdn.com/image/fetch/$s_!G-b3!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37241a29-75d8-448a-b7ae-7b76dac7db8f_1600x978.png 1272w, https://substackcdn.com/image/fetch/$s_!G-b3!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37241a29-75d8-448a-b7ae-7b76dac7db8f_1600x978.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!G-b3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37241a29-75d8-448a-b7ae-7b76dac7db8f_1600x978.png" width="1456" height="890" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/37241a29-75d8-448a-b7ae-7b76dac7db8f_1600x978.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:890,&quot;width&quot;:1456,&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_!G-b3!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37241a29-75d8-448a-b7ae-7b76dac7db8f_1600x978.png 424w, https://substackcdn.com/image/fetch/$s_!G-b3!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37241a29-75d8-448a-b7ae-7b76dac7db8f_1600x978.png 848w, https://substackcdn.com/image/fetch/$s_!G-b3!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37241a29-75d8-448a-b7ae-7b76dac7db8f_1600x978.png 1272w, https://substackcdn.com/image/fetch/$s_!G-b3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37241a29-75d8-448a-b7ae-7b76dac7db8f_1600x978.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>Analogy</h3><p>Imagine a restaurant with two separate counters:</p><p>One counter takes orders... it focuses on taking them correctly. The other counter only handles pickups. It focuses on quickly delivering food to customers.</p><p>Both handle the same orders, but each serves a different purpose.</p><h3>Tradeoff</h3><p>Benefits:</p><ul><li><p>Scale reads &amp; writes separately</p></li><li><p>Design different data models for reading and writing</p></li><li><p>Create specialized read models from the same write model</p></li></ul><p>Drawbacks:</p><ul><li><p>Adds architectural complexity</p></li><li><p>Read side may not reflect changes immediately</p></li><li><p>Requires event handling or synchronization between models</p></li><li><p>Makes the system harder to understand and maintain</p></li></ul><p>It is usually too complex for simple CRUD applications.</p><h3>Why it matters</h3><p>CQRS is useful when:</p><ul><li><p>Your system has very different read &amp; write workloads</p></li><li><p>Reads significantly outnumber writes</p></li><li><p>You need many views of the same data</p></li><li><p>Domain &amp; business logic is complex</p></li></ul><p>It&#8217;s often used together with Event Sourcing.</p><p>But a single model for both reads and writes is usually enough for simple systems.</p><h2><strong>80. Event Sourcing</strong></h2><blockquote><p>Event Sourcing is a way of storing data in which you record every change that happens in the system, rather than only saving the latest state.</p></blockquote><p>Each change gets captured as an immutable event.</p><p>You can rebuild the current state by replaying events from the beginning or from a snapshot. You can also rebuild the state at any point in time and audit the complete history of changes.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!9Q8m!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37bd0fa7-24fd-4e0b-8c01-48a52f771577_1600x969.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!9Q8m!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37bd0fa7-24fd-4e0b-8c01-48a52f771577_1600x969.png 424w, https://substackcdn.com/image/fetch/$s_!9Q8m!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37bd0fa7-24fd-4e0b-8c01-48a52f771577_1600x969.png 848w, https://substackcdn.com/image/fetch/$s_!9Q8m!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37bd0fa7-24fd-4e0b-8c01-48a52f771577_1600x969.png 1272w, https://substackcdn.com/image/fetch/$s_!9Q8m!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37bd0fa7-24fd-4e0b-8c01-48a52f771577_1600x969.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!9Q8m!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37bd0fa7-24fd-4e0b-8c01-48a52f771577_1600x969.png" width="1456" height="882" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/37bd0fa7-24fd-4e0b-8c01-48a52f771577_1600x969.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:882,&quot;width&quot;:1456,&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_!9Q8m!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37bd0fa7-24fd-4e0b-8c01-48a52f771577_1600x969.png 424w, https://substackcdn.com/image/fetch/$s_!9Q8m!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37bd0fa7-24fd-4e0b-8c01-48a52f771577_1600x969.png 848w, https://substackcdn.com/image/fetch/$s_!9Q8m!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37bd0fa7-24fd-4e0b-8c01-48a52f771577_1600x969.png 1272w, https://substackcdn.com/image/fetch/$s_!9Q8m!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37bd0fa7-24fd-4e0b-8c01-48a52f771577_1600x969.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>Analogy</h3><p>Think of a bank that records every transaction in a ledger:</p><p>Instead of only storing your current balance, bank keeps a list of all deposits and withdrawals. Your balance can always be calculated by adding up all those transactions.</p><h3>Tradeoff</h3><p>Benefits:</p><ul><li><p>You get a history of all changes</p></li><li><p>Easy to audit what happened and when</p></li><li><p>You can rebuild the system state at any time</p></li><li><p>You can create new views or reports from past events</p></li></ul><p>Drawbacks:</p><ul><li><p>Harder to design &amp; implement</p></li><li><p>Events are immutable, so fixing mistakes requires new corrective events</p></li><li><p>Getting the current state often requires projections or snapshots</p></li><li><p>Event formats may change over time, which makes schema evolution difficult</p></li><li><p>Event storage grows unbounded without snapshots</p></li></ul><h3>Why it matters</h3><ul><li><p>Audit-heavy domains such as financial systems</p></li><li><p>Systems that need historical queries</p></li><li><p>Systems that need many views built from the same data</p></li></ul><p>It&#8217;s often used together with CQRS.</p><h2><strong>81. Service Discovery</strong></h2><blockquote><p>Service discovery allows services within a system to automatically find and communicate with each other, eliminating the need for fixed IP addresses.</p></blockquote><p>When a service starts, it registers itself in a service registry. The registry tracks where each service instance is running. When another service wants to call it, it asks the registry for the instances and connects to one of them.</p><p>Common tools: Consul, etcd, and Eureka.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!LWg3!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F087b7f71-5e95-4550-9b26-c8c8fd74894b_1600x823.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!LWg3!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F087b7f71-5e95-4550-9b26-c8c8fd74894b_1600x823.png 424w, https://substackcdn.com/image/fetch/$s_!LWg3!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F087b7f71-5e95-4550-9b26-c8c8fd74894b_1600x823.png 848w, https://substackcdn.com/image/fetch/$s_!LWg3!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F087b7f71-5e95-4550-9b26-c8c8fd74894b_1600x823.png 1272w, https://substackcdn.com/image/fetch/$s_!LWg3!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F087b7f71-5e95-4550-9b26-c8c8fd74894b_1600x823.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!LWg3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F087b7f71-5e95-4550-9b26-c8c8fd74894b_1600x823.png" width="1456" height="749" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/087b7f71-5e95-4550-9b26-c8c8fd74894b_1600x823.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:749,&quot;width&quot;:1456,&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_!LWg3!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F087b7f71-5e95-4550-9b26-c8c8fd74894b_1600x823.png 424w, https://substackcdn.com/image/fetch/$s_!LWg3!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F087b7f71-5e95-4550-9b26-c8c8fd74894b_1600x823.png 848w, https://substackcdn.com/image/fetch/$s_!LWg3!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F087b7f71-5e95-4550-9b26-c8c8fd74894b_1600x823.png 1272w, https://substackcdn.com/image/fetch/$s_!LWg3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F087b7f71-5e95-4550-9b26-c8c8fd74894b_1600x823.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>Analogy</h3><p>Think of it like a phone directory:</p><p>Instead of remembering everyone&#8217;s phone number, you look them up in the directory. If someone changes their number, the directory gets updated so people can still reach them.</p><h3>Tradeoff</h3><ul><li><p>Requires health checks</p></li><li><p>Adds infrastructure complexity</p></li><li><p>It can become a critical dependency</p></li><li><p>Service lookups can add a small amount of latency</p></li><li><p>Cached results might sometimes point to instances that are no longer healthy</p></li></ul><h3>Why it matters</h3><p>Service discovery is important in environments where services move or scale frequently:</p><ul><li><p>Microservices architecture</p></li><li><p>Container platforms like Kubernetes</p></li><li><p>Cloud systems with auto-scaling</p></li></ul><p>It allows services to locate and communicate with each other even when their IP addresses or instances change dynamically.</p><h2><strong>82. Circuit Breaker Pattern</strong></h2><blockquote><p>Circuit breaker pattern protects a system from repeatedly calling a failing service.</p></blockquote><p>A circuit breaker sits between a service and the dependency it calls (for example, another service, API, or database). It monitors failures such as errors or timeouts.</p><p>If failures pass a threshold, the circuit breaker &#8220;opens&#8221; and stops sending requests to the failing service. Instead, it immediately returns an error or a fallback response.</p><p>After a set time, the circuit breaker moves to a &#8220;half-open&#8221; state. It allows a small number of test requests.</p><ul><li><p>If those succeed, the circuit &#8220;closes&#8221; and normal traffic resumes.</p></li><li><p>If they fail, the circuit &#8220;opens&#8221; again.</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_!cxjV!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72b03643-4967-49be-ade0-bdf90d213c71_1600x616.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!cxjV!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72b03643-4967-49be-ade0-bdf90d213c71_1600x616.png 424w, https://substackcdn.com/image/fetch/$s_!cxjV!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72b03643-4967-49be-ade0-bdf90d213c71_1600x616.png 848w, https://substackcdn.com/image/fetch/$s_!cxjV!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72b03643-4967-49be-ade0-bdf90d213c71_1600x616.png 1272w, https://substackcdn.com/image/fetch/$s_!cxjV!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72b03643-4967-49be-ade0-bdf90d213c71_1600x616.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!cxjV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72b03643-4967-49be-ade0-bdf90d213c71_1600x616.png" width="1456" height="561" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/72b03643-4967-49be-ade0-bdf90d213c71_1600x616.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:561,&quot;width&quot;:1456,&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_!cxjV!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72b03643-4967-49be-ade0-bdf90d213c71_1600x616.png 424w, https://substackcdn.com/image/fetch/$s_!cxjV!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72b03643-4967-49be-ade0-bdf90d213c71_1600x616.png 848w, https://substackcdn.com/image/fetch/$s_!cxjV!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72b03643-4967-49be-ade0-bdf90d213c71_1600x616.png 1272w, https://substackcdn.com/image/fetch/$s_!cxjV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72b03643-4967-49be-ade0-bdf90d213c71_1600x616.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>Analogy</h3><p>It works like an electrical circuit breaker in a house:</p><p>If too much current flows, the breaker cuts power to prevent damage. After the problem gets fixed, you reset the breaker and power flows again.</p><h3>Tradeoff</h3><p>Benefits:</p><ul><li><p>Prevents cascading failures in distributed systems</p></li><li><p>Reduces load on failing services so they can recover</p></li><li><p>Fails fast instead of waiting for long timeouts</p></li><li><p>Protects system resources</p></li></ul><p>Drawbacks:</p><ul><li><p>Adds complexity to service calls</p></li><li><p>Requires tuning thresholds &amp; timeout values</p></li><li><p>Can open unnecessarily if thresholds are set incorrectly</p></li><li><p>Needs monitoring to detect when circuits are open</p></li></ul><h3>Why it matters</h3><p>It&#8217;s useful when systems make network calls that can fail, such as:</p><ul><li><p>Microservices calling other services</p></li><li><p>Services calling external APIs</p></li><li><p>Systems that depend on remote databases or infrastructure</p></li></ul><p>It helps prevent one failing dependency from causing failures across the entire system.</p><p>Common libraries: Resilience4j &amp; Polly.</p><div><hr></div><p><em><strong>Reminder: this is a teaser of the subscriber-only post, exclusive to my golden members.</strong></em></p><p>When you upgrade, you&#8217;ll get:</p><ul><li><p><strong>Full access to system design case studies</strong></p></li><li><p>FREE access to (coming) Design, Build, Scale newsletter series</p></li><li><p><strong>FREE access to (coming) popular interview question breakdowns</strong></p></li></ul><p>And more!</p><p>Get 10x the results you currently get with 1/10th the time, energy &amp; effort.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/subscribe&quot;,&quot;text&quot;:&quot;Get Instant Access&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesign.one/subscribe"><span>Get Instant Access</span></a></p>
      <p>
          <a href="https://newsletter.systemdesign.one/p/system-design-fundamentals">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[I Struggled With System Design Interview Until I Learned This Framework]]></title><description><![CDATA[#128: From Someone Who Failed and Then Passed]]></description><link>https://newsletter.systemdesign.one/p/how-to-prepare-for-system-design-interview</link><guid isPermaLink="false">https://newsletter.systemdesign.one/p/how-to-prepare-for-system-design-interview</guid><dc:creator><![CDATA[Neo Kim]]></dc:creator><pubDate>Sat, 07 Mar 2026 12:50:35 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/ed5c1145-c042-4545-b6e9-d41f7579fd92_1280x720.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p> </p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/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">Get my system design playbook for FREE on newsletter signup:</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><ul><li><p><em><a href="https://newsletter.systemdesign.one/p/how-to-prepare-for-system-design-interview/?action=share">Share this post</a> &amp; I'll send you some rewards for the referrals.</em></p></li></ul><div><hr></div><p>In 2021, I applied to Amazon and <em>failed</em> the system design interview.</p><p>I knew something was off during the interview, but I couldn&#8217;t figure out what. At that time, I was a Software Engineer at Trainline on the Search/Checkout Web Services team, building software for over 100 million customers across Europe. I could code, I understood distributed systems, and I had shipped real features.</p><p>On paper, everything looked fine.</p><p>Looking back, I can see exactly what I missed&#8230;</p><p>I jumped straight into designing without clarifying requirements, never validated my assumptions, and never asked what actually mattered. I just started drawing boxes and arrows. I felt great in the moment and got smiles from the interviewer, but ultimately I failed.</p><p>Fast forward today&#8230;</p><p>I&#8217;m an L5 Software Engineer at AWS, who has contributed to CloudWatch, EC2, and Regional Services. I conduct system design interviews for candidates. That journey from failure to interviewer taught me something important: most engineers who fail these interviews aren&#8217;t bad engineers. They just don&#8217;t have a framework for turning vague problems into conversations.</p><p>This newsletter is everything I wish I knew before my 2021 interview.</p><p>I&#8217;m going to share what you actually need to pass: the framework, the pacing, the collaboration checkpoints, and the mindset that separates candidates who pass from those who don&#8217;t.</p><p>Before we get into frameworks and strategies, let&#8217;s explore why these interviews feel so different from everything else you do as an engineer.</p><p>Onward.</p><div><hr></div><h3><strong><a href="https://serpapi.com/?utm_source=thesystemdesignnewsletter">Need public web data, without scraper headaches? (Partner)</a></strong></h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://serpapi.com/?utm_source=thesystemdesignnewsletter" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Hdlc!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56bb41d0-a9df-40dd-9253-e67c930cc2ad_1200x1171.jpeg 424w, https://substackcdn.com/image/fetch/$s_!Hdlc!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56bb41d0-a9df-40dd-9253-e67c930cc2ad_1200x1171.jpeg 848w, https://substackcdn.com/image/fetch/$s_!Hdlc!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56bb41d0-a9df-40dd-9253-e67c930cc2ad_1200x1171.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!Hdlc!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56bb41d0-a9df-40dd-9253-e67c930cc2ad_1200x1171.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Hdlc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56bb41d0-a9df-40dd-9253-e67c930cc2ad_1200x1171.jpeg" width="1200" height="1171" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/56bb41d0-a9df-40dd-9253-e67c930cc2ad_1200x1171.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1171,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:182785,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:&quot;image/jpeg&quot;,&quot;href&quot;:&quot;https://serpapi.com/?utm_source=thesystemdesignnewsletter&quot;,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/180977546?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56bb41d0-a9df-40dd-9253-e67c930cc2ad_1200x1171.jpeg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!Hdlc!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56bb41d0-a9df-40dd-9253-e67c930cc2ad_1200x1171.jpeg 424w, https://substackcdn.com/image/fetch/$s_!Hdlc!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56bb41d0-a9df-40dd-9253-e67c930cc2ad_1200x1171.jpeg 848w, https://substackcdn.com/image/fetch/$s_!Hdlc!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56bb41d0-a9df-40dd-9253-e67c930cc2ad_1200x1171.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!Hdlc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56bb41d0-a9df-40dd-9253-e67c930cc2ad_1200x1171.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong><a href="https://serpapi.com/?utm_source=thesystemdesignnewsletter">SerpApi</a></strong> turns search results into predictable JSON with built-in scale, location options, and protection from blocks.</p><p>That&#8217;s why engineers use it to ship:</p><ul><li><p>AI applications</p></li><li><p>Product research</p></li><li><p>Price tracking</p></li><li><p>SEO insights</p></li></ul><p>All without maintaining scrapers or infrastructure.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://serpapi.com/?utm_source=thesystemdesignnewsletter&quot;,&quot;text&quot;:&quot;Try For Free&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://serpapi.com/?utm_source=thesystemdesignnewsletter"><span>Try For Free</span></a></p><p>(I&#8217;d like to thank <a href="https://serpapi.com/?utm_source=thesystemdesignnewsletter">SerpApi</a> for partnering on this post.)</p><div><hr></div><p>I want to introduce <strong><a href="http://linkedin.com/in/abdirahman-sj">Abdirahman Jama</a></strong> as the guest author.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="http://linkedin.com/in/abdirahman-sj" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!C231!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4724c28-286f-461d-8cb0-82ea2dc5eb64_1570x870.png 424w, https://substackcdn.com/image/fetch/$s_!C231!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4724c28-286f-461d-8cb0-82ea2dc5eb64_1570x870.png 848w, https://substackcdn.com/image/fetch/$s_!C231!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4724c28-286f-461d-8cb0-82ea2dc5eb64_1570x870.png 1272w, https://substackcdn.com/image/fetch/$s_!C231!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4724c28-286f-461d-8cb0-82ea2dc5eb64_1570x870.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!C231!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4724c28-286f-461d-8cb0-82ea2dc5eb64_1570x870.png" width="1456" height="807" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e4724c28-286f-461d-8cb0-82ea2dc5eb64_1570x870.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:807,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:&quot;http://linkedin.com/in/abdirahman-sj&quot;,&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_!C231!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4724c28-286f-461d-8cb0-82ea2dc5eb64_1570x870.png 424w, https://substackcdn.com/image/fetch/$s_!C231!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4724c28-286f-461d-8cb0-82ea2dc5eb64_1570x870.png 848w, https://substackcdn.com/image/fetch/$s_!C231!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4724c28-286f-461d-8cb0-82ea2dc5eb64_1570x870.png 1272w, https://substackcdn.com/image/fetch/$s_!C231!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4724c28-286f-461d-8cb0-82ea2dc5eb64_1570x870.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>He&#8217;s a Software Engineer at AWS, where he&#8217;s contributed to production services like CloudWatch and EC2. He also conducts system design interviews for engineering candidates.</p><p>Before AWS, he worked at Trainline and BT, building software for over 100 million customers across Europe. He was an AWS Community Builder and served as a coding instructor at Code First Girls in collaboration with Skyscanner.</p><p>He regularly shares free software engineering tips, system design breakdowns, and career advice for engineers breaking into big tech.</p><p>You can connect with Abdirahman here:</p><ul><li><p><strong><a href="http://linkedin.com/in/abdirahman-sj">LinkedIn</a></strong></p></li><li><p><a href="http://instagram.com/abdirahmancodes">Instagram</a></p></li><li><p><strong><a href="https://softwaredevweekly.substack.com/">Newsletter</a></strong></p></li></ul><div><hr></div><h1><strong>Why System Design Interviews Feel Hard</strong></h1><p>In coding interviews, the problem is clear: <em>&#8220;Write a function that does X.&#8221;</em></p><p>You can write the function, add some tests, and confirm whether it works. The feedback loop is immediate and obvious.</p><p>When you&#8217;re building systems at work, you have context.</p><p>You know your users, your constraints, and the internal components you can integrate. Also, you have teammates to bounce ideas off and challenge assumptions. Plus, you have time to assess different options, weigh pros/cons, and make informed decisions. And most importantly, you can use Google.</p><p>System design interviews strip all of that away:</p><p>You&#8217;re given a vague problem like <em>&#8220;Design ChatGPT&#8221;</em> and roughly 30-40 minutes to propose a solution. You can&#8217;t search for anything. Yet somehow you&#8217;re expected to show enough depth and breadth to cover important concepts.</p><p>Now that you understand the challenge, let&#8217;s look at what&#8217;s actually being evaluated. Knowing the scoring criteria changes how you prepare.</p><div><hr></div><h1><strong>What Interviewers Look For (&amp; Mental Model You Need)</strong></h1><p>Here&#8217;s what I learned as an interviewer: we&#8217;re not looking for the &#8220;<em>right answer.</em>&#8221;</p><p>There isn&#8217;t one! We&#8217;re evaluating whether you can think &#8220;systematically&#8221; about ambiguous problems&#8230;</p><p>Here are five dimensions most companies will assess you on:</p><h3><strong>1. Communication and Collaboration</strong></h3><ul><li><p>Do you ask clarifying questions?</p></li><li><p>Do you validate assumptions throughout the interview?</p></li><li><p>Do you treat the interviewer as a partner, or do you just talk at them for 40 minutes straight?</p></li></ul><p>This is crucial as it shows if you&#8217;d be a good teammate.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!XN0u!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec496a26-9fe9-4692-9ea5-4027a70bc8de_1600x1149.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!XN0u!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec496a26-9fe9-4692-9ea5-4027a70bc8de_1600x1149.png 424w, https://substackcdn.com/image/fetch/$s_!XN0u!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec496a26-9fe9-4692-9ea5-4027a70bc8de_1600x1149.png 848w, https://substackcdn.com/image/fetch/$s_!XN0u!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec496a26-9fe9-4692-9ea5-4027a70bc8de_1600x1149.png 1272w, https://substackcdn.com/image/fetch/$s_!XN0u!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec496a26-9fe9-4692-9ea5-4027a70bc8de_1600x1149.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!XN0u!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec496a26-9fe9-4692-9ea5-4027a70bc8de_1600x1149.png" width="1456" height="1046" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ec496a26-9fe9-4692-9ea5-4027a70bc8de_1600x1149.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1046,&quot;width&quot;:1456,&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_!XN0u!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec496a26-9fe9-4692-9ea5-4027a70bc8de_1600x1149.png 424w, https://substackcdn.com/image/fetch/$s_!XN0u!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec496a26-9fe9-4692-9ea5-4027a70bc8de_1600x1149.png 848w, https://substackcdn.com/image/fetch/$s_!XN0u!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec496a26-9fe9-4692-9ea5-4027a70bc8de_1600x1149.png 1272w, https://substackcdn.com/image/fetch/$s_!XN0u!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec496a26-9fe9-4692-9ea5-4027a70bc8de_1600x1149.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><strong>2. Structured Thinking</strong></h3><ul><li><p>Can you break down a vague problem systematically?</p></li><li><p>Do you tackle things logically or jump around between different database choices, caching strategies, and API design?</p></li></ul><p>Strong candidates show how they can organise their thoughts even when the problem is ambiguous.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!rOy0!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3528d07-b1e6-4960-9ed5-e96854fc9c82_1600x894.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!rOy0!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3528d07-b1e6-4960-9ed5-e96854fc9c82_1600x894.png 424w, https://substackcdn.com/image/fetch/$s_!rOy0!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3528d07-b1e6-4960-9ed5-e96854fc9c82_1600x894.png 848w, https://substackcdn.com/image/fetch/$s_!rOy0!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3528d07-b1e6-4960-9ed5-e96854fc9c82_1600x894.png 1272w, https://substackcdn.com/image/fetch/$s_!rOy0!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3528d07-b1e6-4960-9ed5-e96854fc9c82_1600x894.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!rOy0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3528d07-b1e6-4960-9ed5-e96854fc9c82_1600x894.png" width="1456" height="814" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d3528d07-b1e6-4960-9ed5-e96854fc9c82_1600x894.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:814,&quot;width&quot;:1456,&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_!rOy0!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3528d07-b1e6-4960-9ed5-e96854fc9c82_1600x894.png 424w, https://substackcdn.com/image/fetch/$s_!rOy0!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3528d07-b1e6-4960-9ed5-e96854fc9c82_1600x894.png 848w, https://substackcdn.com/image/fetch/$s_!rOy0!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3528d07-b1e6-4960-9ed5-e96854fc9c82_1600x894.png 1272w, https://substackcdn.com/image/fetch/$s_!rOy0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3528d07-b1e6-4960-9ed5-e96854fc9c82_1600x894.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><strong>3. Technical Judgment</strong></h3><ul><li><p>When you pick a technology, a database, a cache, or a message queue, can you explain why?</p></li><li><p>Can you walk through the trade-offs? For example, why DynamoDB over PostgreSQL for this specific use case?</p></li></ul><p>This shows you choose tools based on requirements, not habit.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!8BbU!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facf458dd-c3a0-4a7b-9815-7480574d3a2e_1600x948.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!8BbU!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facf458dd-c3a0-4a7b-9815-7480574d3a2e_1600x948.png 424w, https://substackcdn.com/image/fetch/$s_!8BbU!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facf458dd-c3a0-4a7b-9815-7480574d3a2e_1600x948.png 848w, https://substackcdn.com/image/fetch/$s_!8BbU!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facf458dd-c3a0-4a7b-9815-7480574d3a2e_1600x948.png 1272w, https://substackcdn.com/image/fetch/$s_!8BbU!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facf458dd-c3a0-4a7b-9815-7480574d3a2e_1600x948.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!8BbU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facf458dd-c3a0-4a7b-9815-7480574d3a2e_1600x948.png" width="1456" height="863" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/acf458dd-c3a0-4a7b-9815-7480574d3a2e_1600x948.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:863,&quot;width&quot;:1456,&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_!8BbU!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facf458dd-c3a0-4a7b-9815-7480574d3a2e_1600x948.png 424w, https://substackcdn.com/image/fetch/$s_!8BbU!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facf458dd-c3a0-4a7b-9815-7480574d3a2e_1600x948.png 848w, https://substackcdn.com/image/fetch/$s_!8BbU!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facf458dd-c3a0-4a7b-9815-7480574d3a2e_1600x948.png 1272w, https://substackcdn.com/image/fetch/$s_!8BbU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facf458dd-c3a0-4a7b-9815-7480574d3a2e_1600x948.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><strong>4. Practical Depth</strong></h3><ul><li><p>Do you think about failure modes, scale, and operations?</p></li><li><p>Or do you only design the happy path?</p></li></ul><p>This is where we spot engineers who&#8217;ve shipped production systems and those who haven&#8217;t. Real systems fail. Databases go down. Networks partition. Strong candidates anticipate and design for this.</p><h3><strong>5. Time Management</strong></h3><ul><li><p>Can you pace yourself to cover breadth and depth in 40 minutes?</p></li><li><p>Do you spend a long period covering a specific area?</p></li></ul><p>It&#8217;s always worth working with your interviewer to understand if there&#8217;s an area of interest for them, or you should propose what you&#8217;ll focus on. Get alignment.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!dCqO!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2dedc724-326b-4e7d-b25b-7a20d941854f_1600x1093.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!dCqO!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2dedc724-326b-4e7d-b25b-7a20d941854f_1600x1093.png 424w, https://substackcdn.com/image/fetch/$s_!dCqO!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2dedc724-326b-4e7d-b25b-7a20d941854f_1600x1093.png 848w, https://substackcdn.com/image/fetch/$s_!dCqO!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2dedc724-326b-4e7d-b25b-7a20d941854f_1600x1093.png 1272w, https://substackcdn.com/image/fetch/$s_!dCqO!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2dedc724-326b-4e7d-b25b-7a20d941854f_1600x1093.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!dCqO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2dedc724-326b-4e7d-b25b-7a20d941854f_1600x1093.png" width="1456" height="995" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2dedc724-326b-4e7d-b25b-7a20d941854f_1600x1093.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:995,&quot;width&quot;:1456,&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_!dCqO!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2dedc724-326b-4e7d-b25b-7a20d941854f_1600x1093.png 424w, https://substackcdn.com/image/fetch/$s_!dCqO!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2dedc724-326b-4e7d-b25b-7a20d941854f_1600x1093.png 848w, https://substackcdn.com/image/fetch/$s_!dCqO!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2dedc724-326b-4e7d-b25b-7a20d941854f_1600x1093.png 1272w, https://substackcdn.com/image/fetch/$s_!dCqO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2dedc724-326b-4e7d-b25b-7a20d941854f_1600x1093.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>Between my failed 2021 interview and the ones I passed, the biggest shift was adopting a mental model, a framework that works for any system design problem. This framework keeps people organised and shows how to solve ambiguous problems.</p><p>Let&#8217;s walk through each step&#8230;</p><div><hr></div><h1><strong>Framework: 5 Simple Steps to System Design Interviews</strong></h1><h3><strong>Step 1: Clarify the problem</strong></h3><ul><li><p>Goal: Understand the problem before you design anything.</p></li><li><p>Estimated time: 5 minutes</p></li></ul><p>Start by understanding what&#8217;s in scope and what isn&#8217;t:</p><ul><li><p>Are you focusing on Feature A or Feature B, or both?</p></li><li><p>Are you targeting a specific platform?</p></li><li><p>How many users are you building for?</p></li><li><p>Where are they located?</p></li></ul><p>These aren&#8217;t just theoretical questions&#8230;</p><p>The answers can fundamentally change your design.</p><h4><strong>Functional Requirements (What Are We Building?)</strong></h4><p>Be specific about what your system needs to do:</p><ul><li><p>What are the main use cases?</p></li><li><p>Who are the users?</p></li><li><p>What core features are you building?</p></li><li><p>What are you explicitly leaving out of scope?</p></li></ul><h4><strong>Non-Functional Requirements (What Are the Constraints?)</strong></h4><p>This is where numbers matter:</p><ul><li><p>How many daily and monthly users do you have?</p></li><li><p>How many requests per second?</p></li><li><p>What&#8217;s the read-to-write ratio?</p></li><li><p>What are the latency requirements? Is 200ms acceptable, or do we need sub-100ms?</p></li><li><p>What&#8217;s an acceptable downtime?</p></li></ul><p>These constraints will drive every technical decision you make&#8230;</p><p>A system for 1000 users looks completely different from one serving 200 million daily active users.</p><p>TIP: Check with your interviewer and ask if the scope and requirements make sense.</p><h3><strong>Step 2: Define Core Data &amp; APIs</strong></h3><ul><li><p>Goal: Model what you&#8217;re storing and how clients interact with it.</p></li><li><p>Estimated time: 10 minutes</p></li></ul><h4><strong>Data Model</strong></h4><p>Identify the core entities and their attributes:</p><ul><li><p>What are the main &#8220;things&#8221; in your system? Think about how they relate to each other.</p></li><li><p>Define your primary keys, foreign keys, and the indexes you&#8217;ll need for common queries.</p></li></ul><h4><strong>Data Characteristics</strong></h4><p>Understand the shape of your data:</p><ul><li><p>How big is each record?</p></li><li><p>Is the data append-only or mutable?</p></li><li><p>What&#8217;s the growth rate?</p></li><li><p>How will the data be queried?</p><ul><li><p>Are you doing point lookups by ID or complex joins?</p></li><li><p>Which data needs strong consistency, and what can be eventually consistent?</p></li><li><p>What absolutely cannot be lost?</p></li></ul></li></ul><h4><strong>API Contracts</strong></h4><p>Define your main endpoints with clear request and response formats. Think about pagination strategies, error handling, rate limiting, and versioning.</p><h4><strong>Database Choice</strong></h4><p>Pick a technology and explain why.</p><p>Don&#8217;t just say: &#8220;<em>Use PostgreSQL.</em>&#8221; Justify your choice based on the requirements, discuss alternatives, and explain why you chose one over another.</p><p>TIP: Check again with your interviewer: <em>&#8220;Does this data model and API structure make sense for the requirements?&#8221;</em></p><h3><strong>Step 3: High-Level Architecture</strong></h3><ul><li><p>Goal: Design system components and show how data flows through them.</p></li><li><p>Estimated time: 15 minutes</p></li></ul><p>You should spend most of your interview time here.</p><p>Start by identifying your core components: load balancers, API servers, a cache layer, and queues. Keep this list focused and include only what your design needs.</p><h4><strong>Draw Data Flow</strong></h4><p>Walk through how a request moves through your system.</p><p>From the client, through the load balancer, to the API server, into the cache or database, and back. Do this for both reads and writes.</p><h4><strong>Discuss Asynchronous Workflows Where Appropriate</strong></h4><p>When appropriate, explain why you&#8217;d decouple work into background processing. Also discuss trade-offs: faster responses, but eventual consistency.</p><h4><strong>Caching Strategy</strong></h4><p>Be specific about what you&#8217;re caching, for how long, and how you handle invalidation. Plus, explain the trade-offs between freshness and performance.</p><h4><strong>CAP Theorem Considerations</strong></h4><p>For different parts of your system, choose between consistency, availability, and partition tolerance. Explain why each part of the system may need a different approach.</p><h3><strong>Step 4: Bottlenecks, Scale, and Reliability</strong></h3><ul><li><p>Goal: Show you understand what breaks at scale and how to handle failures.</p></li><li><p>Estimated time: 5 minutes</p></li></ul><p>Don&#8217;t just design the happy path; show you think about failure and scale.</p><h4><strong>Identify Bottlenecks</strong></h4><p>Where will your system struggle under load?</p><p>Name the component, quantify the limit, and propose a mitigation.</p><h4><strong>Single Points of Failure</strong></h4><p>What happens if a component goes down? Identify the risks and explain the mitigation.</p><h4><strong>Failure Modes and Graceful Degradation</strong></h4><ul><li><p>Cache failure: fallback to a slower but functional path</p></li><li><p>Message queue backed up: serve stale data instead of failing requests</p></li><li><p>Network partition: degrade gracefully rather than returning errors</p></li></ul><h4><strong>Redundancy</strong></h4><ul><li><p>Database: multi-AZ replicas for high availability</p></li><li><p>Application servers: auto-scaling across availability zones</p></li><li><p>Cache: distributed cache with replication</p></li></ul><h4><strong>Monitoring, Logging, and Alerting</strong></h4><p>This is my favourite part of the interview. It shows you&#8217;re thinking about operations and observability--one of the clearest signals separating junior from senior engineers.</p><p>You should cover:</p><ul><li><p>API latency at p50, p95, and p99</p></li><li><p>Error rates and thresholds</p></li><li><p>Queue depth and backlog alerts</p></li><li><p>Structured logs with request IDs for distributed tracing</p></li></ul><p>TIP: Ask your interviewer: <em>&#8220;Are there specific failure scenarios you&#8217;d like me to explore further?&#8221;</em></p><h3><strong>Step 5: Tradeoffs and Extensions</strong></h3><ul><li><p>Goal: Summarise key decisions and discuss what you&#8217;d build next.</p></li><li><p>Estimated time: 5 minutes</p></li></ul><p>Wrap up by summarising the key trade-offs you made. What did you prioritise, and what did you sacrifice? Be explicit about the why.</p><p>Then discuss extensions. What would you add if you had more time? This shows you&#8217;re thinking beyond the immediate problem. That&#8217;s the framework.</p><p>Next let&#8217;s see it in action with a real example:</p><div><hr></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="http://linkedin.com/in/abdirahman-sj" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!C231!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4724c28-286f-461d-8cb0-82ea2dc5eb64_1570x870.png 424w, https://substackcdn.com/image/fetch/$s_!C231!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4724c28-286f-461d-8cb0-82ea2dc5eb64_1570x870.png 848w, https://substackcdn.com/image/fetch/$s_!C231!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4724c28-286f-461d-8cb0-82ea2dc5eb64_1570x870.png 1272w, https://substackcdn.com/image/fetch/$s_!C231!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4724c28-286f-461d-8cb0-82ea2dc5eb64_1570x870.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!C231!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4724c28-286f-461d-8cb0-82ea2dc5eb64_1570x870.png" width="1456" height="807" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e4724c28-286f-461d-8cb0-82ea2dc5eb64_1570x870.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:807,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:&quot;http://linkedin.com/in/abdirahman-sj&quot;,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!C231!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4724c28-286f-461d-8cb0-82ea2dc5eb64_1570x870.png 424w, https://substackcdn.com/image/fetch/$s_!C231!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4724c28-286f-461d-8cb0-82ea2dc5eb64_1570x870.png 848w, https://substackcdn.com/image/fetch/$s_!C231!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4724c28-286f-461d-8cb0-82ea2dc5eb64_1570x870.png 1272w, https://substackcdn.com/image/fetch/$s_!C231!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4724c28-286f-461d-8cb0-82ea2dc5eb64_1570x870.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>Connect with Abdirahman here:</p><ul><li><p><strong><a href="http://linkedin.com/in/abdirahman-sj">LinkedIn</a></strong></p></li><li><p><a href="http://instagram.com/abdirahmancodes">Instagram</a></p></li><li><p><strong><a href="https://softwaredevweekly.substack.com/">Newsletter</a></strong></p></li></ul><p>He regularly shares free software engineering tips, system design breakdowns, and career advice for engineers breaking into big tech.</p><div><hr></div><p><em>Reminder: this is a teaser of the subscriber-only post, exclusive to my golden members.</em></p><p>When you upgrade, you&#8217;ll get:</p><ul><li><p>Full access to system design case studies</p></li><li><p>FREE access to (coming) Design, Build, Scale newsletter series</p></li><li><p>FREE access to (coming) popular interview question breakdowns</p></li></ul><p>And more!</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/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://newsletter.systemdesign.one/subscribe?"><span>Subscribe now</span></a></p><h4><em><strong>Access the interview example and quick reference framework &#128071;</strong></em></h4>
      <p>
          <a href="https://newsletter.systemdesign.one/p/how-to-prepare-for-system-design-interview">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Context Engineering vs Prompt Engineering]]></title><description><![CDATA[#127: A Developer&#8217;s Guide to Writing Better Prompts and Building Better Context]]></description><link>https://newsletter.systemdesign.one/p/context-engineering-vs-prompt-engineering</link><guid isPermaLink="false">https://newsletter.systemdesign.one/p/context-engineering-vs-prompt-engineering</guid><dc:creator><![CDATA[Neo Kim]]></dc:creator><pubDate>Tue, 03 Mar 2026 09:33:24 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/b8c31bd3-0a00-44a6-994d-4e8554533bba_1280x720.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/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">Get my system design playbook for FREE on newsletter signup:</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><ul><li><p><em><a href="https://newsletter.systemdesign.one/p/context-engineering-vs-prompt-engineering/?action=share">Share this post</a> &amp; I&#8217;ll send you some rewards for the referrals.</em></p></li></ul><div><hr></div><p>You&#8217;ve spent three days crafting the perfect prompt.</p><p>You&#8217;ve added role-playing instructions, sprinkled in a few-shot<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a> examples, and even included that magic phrase everyone swears by, &#8220;<em>Let&#8217;s think step by step</em>&#8221;.</p><p>Your <em>AI travel assistant</em> is ready for production.</p><p>Then your first real user types: <em>&#8220;Book me a hotel in Paris for the DevOps conference.&#8221;</em></p><p>Your agent cheerfully books the Best Western in Paris, Kentucky.</p><p>This isn&#8217;t a prompting failure. It&#8217;s an architecture failure. And if you&#8217;ve been building AI agents in production, you&#8217;ve probably hit this wall where no amount of clever phrasing can make up for missing information.</p><p>The solution isn&#8217;t to write better prompts. It&#8217;s engineering a better context!</p><p>Onward.</p><div><hr></div><h2><strong><a href="https://getunblocked.com/?utm_source=systemdesign&amp;utm_medium=email&amp;utm_campaign=contextengine">Unblocked: The context layer your AI tools are missing (Partner)</a></strong></h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://getunblocked.com/?utm_source=systemdesign&amp;utm_medium=email&amp;utm_campaign=contextengine" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!-9qf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4157723-5d61-4d04-b699-f15d7670aeb4_1200x600.png 424w, https://substackcdn.com/image/fetch/$s_!-9qf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4157723-5d61-4d04-b699-f15d7670aeb4_1200x600.png 848w, https://substackcdn.com/image/fetch/$s_!-9qf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4157723-5d61-4d04-b699-f15d7670aeb4_1200x600.png 1272w, https://substackcdn.com/image/fetch/$s_!-9qf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4157723-5d61-4d04-b699-f15d7670aeb4_1200x600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!-9qf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4157723-5d61-4d04-b699-f15d7670aeb4_1200x600.png" width="1200" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b4157723-5d61-4d04-b699-f15d7670aeb4_1200x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:307185,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:&quot;https://getunblocked.com/?utm_source=systemdesign&amp;utm_medium=email&amp;utm_campaign=contextengine&quot;,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/188825279?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4157723-5d61-4d04-b699-f15d7670aeb4_1200x600.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!-9qf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4157723-5d61-4d04-b699-f15d7670aeb4_1200x600.png 424w, https://substackcdn.com/image/fetch/$s_!-9qf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4157723-5d61-4d04-b699-f15d7670aeb4_1200x600.png 848w, https://substackcdn.com/image/fetch/$s_!-9qf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4157723-5d61-4d04-b699-f15d7670aeb4_1200x600.png 1272w, https://substackcdn.com/image/fetch/$s_!-9qf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4157723-5d61-4d04-b699-f15d7670aeb4_1200x600.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>Give your agents the understanding they need to generate reliable code, reviews, and answers. <strong><a href="https://getunblocked.com/?utm_source=systemdesign&amp;utm_medium=email&amp;utm_campaign=contextengine">Unblocked</a></strong> builds context from your team&#8217;s code, PR history, conversations, documentation, planning tools, and runtime signals. It surfaces the insights that matter so AI outputs reflect how your system actually works.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://getunblocked.com/?utm_source=systemdesign&amp;utm_medium=email&amp;utm_campaign=contextengine&quot;,&quot;text&quot;:&quot;See How It Works&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://getunblocked.com/?utm_source=systemdesign&amp;utm_medium=email&amp;utm_campaign=contextengine"><span>See How It Works</span></a></p><p>(Thanks, <a href="https://getunblocked.com/?utm_source=systemdesign&amp;utm_medium=email&amp;utm_campaign=contextengine">Unblocked</a>, for partnering on this post.)</p><div><hr></div><p>I want to introduce <a href="https://www.linkedin.com/in/pvergadia/">Priyanka Vergadia (&#8220;Cloud Girl&#8221;)</a> as the guest author.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://www.linkedin.com/in/pvergadia/" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!1xqh!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc817e61a-7d37-4551-9b30-42e15e19a6f3_1600x480.png 424w, https://substackcdn.com/image/fetch/$s_!1xqh!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc817e61a-7d37-4551-9b30-42e15e19a6f3_1600x480.png 848w, https://substackcdn.com/image/fetch/$s_!1xqh!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc817e61a-7d37-4551-9b30-42e15e19a6f3_1600x480.png 1272w, https://substackcdn.com/image/fetch/$s_!1xqh!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc817e61a-7d37-4551-9b30-42e15e19a6f3_1600x480.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!1xqh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc817e61a-7d37-4551-9b30-42e15e19a6f3_1600x480.png" width="1456" height="437" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c817e61a-7d37-4551-9b30-42e15e19a6f3_1600x480.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:437,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:&quot;https://www.linkedin.com/in/pvergadia/&quot;,&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_!1xqh!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc817e61a-7d37-4551-9b30-42e15e19a6f3_1600x480.png 424w, https://substackcdn.com/image/fetch/$s_!1xqh!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc817e61a-7d37-4551-9b30-42e15e19a6f3_1600x480.png 848w, https://substackcdn.com/image/fetch/$s_!1xqh!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc817e61a-7d37-4551-9b30-42e15e19a6f3_1600x480.png 1272w, https://substackcdn.com/image/fetch/$s_!1xqh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc817e61a-7d37-4551-9b30-42e15e19a6f3_1600x480.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>She is a cloud and AI expert who has worked at two of the hyperscalers: Google and Microsoft. Check out her newsletter and social media:</p><ul><li><p><a href="https://www.thecloudgirl.dev/subscribe-to-cloud-girl-bytes">Cloud Girl Bytes (newsletter)</a></p></li><li><p><a href="https://www.linkedin.com/in/pvergadia/">LinkedIn</a></p></li><li><p><a href="https://x.com/pvergadia">Twitter</a></p></li><li><p><a href="https://www.youtube.com/@pvergadia">YouTube</a></p></li><li><p><a href="https://www.thecloudgirl.dev/">Website</a></p></li><li><p><a href="https://www.instagram.com/pvergadia/">Instagram</a></p></li></ul><p>It&#8217;ll help you quickly master cloud and AI.</p><div><hr></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!T4MM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1d0d5d4-14ab-4044-a3a1-a857fcf665d5_1080x1080.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!T4MM!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1d0d5d4-14ab-4044-a3a1-a857fcf665d5_1080x1080.png 424w, https://substackcdn.com/image/fetch/$s_!T4MM!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1d0d5d4-14ab-4044-a3a1-a857fcf665d5_1080x1080.png 848w, https://substackcdn.com/image/fetch/$s_!T4MM!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1d0d5d4-14ab-4044-a3a1-a857fcf665d5_1080x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!T4MM!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1d0d5d4-14ab-4044-a3a1-a857fcf665d5_1080x1080.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!T4MM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1d0d5d4-14ab-4044-a3a1-a857fcf665d5_1080x1080.png" width="1080" height="1080" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d1d0d5d4-14ab-4044-a3a1-a857fcf665d5_1080x1080.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1080,&quot;width&quot;:1080,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1439234,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/188715439?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1d0d5d4-14ab-4044-a3a1-a857fcf665d5_1080x1080.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_!T4MM!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1d0d5d4-14ab-4044-a3a1-a857fcf665d5_1080x1080.png 424w, https://substackcdn.com/image/fetch/$s_!T4MM!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1d0d5d4-14ab-4044-a3a1-a857fcf665d5_1080x1080.png 848w, https://substackcdn.com/image/fetch/$s_!T4MM!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1d0d5d4-14ab-4044-a3a1-a857fcf665d5_1080x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!T4MM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1d0d5d4-14ab-4044-a3a1-a857fcf665d5_1080x1080.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 newsletter will walk you through the shift from <strong>Prompt Engineering</strong> (optimizing what you write) to <strong>Context Engineering</strong> (architecting what the model receives).</p><p>By the end, you&#8217;ll understand why this distinction matters and how to implement it in your own systems. But first, let&#8217;s make sure we&#8217;re speaking the same language&#8230;</p><div><hr></div><h2><strong>Key Concepts: A Quick Primer</strong></h2><p>Whether you&#8217;re just getting started with AI development or looking for a refresher, here are the foundational terms we&#8217;ll use throughout this post:</p><p><strong>LLM (Large Language Model)</strong></p><p>Think of this as the &#8220;brain&#8221; of your AI application.</p><p>Models like GPT-4, Claude, or Llama<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-2" href="#footnote-2" target="_self">2</a> are trained on massive amounts of text to understand and generate human-like language. They don&#8217;t &#8220;know&#8221; things the way you do&#8212;they &#8220;predict&#8221; what text should come next based on patterns they&#8217;ve learned.</p><p><strong>Prompt</strong></p><p>The instructions or text you send to an LLM.</p><p>If the LLM is an actor, the prompt is the script you hand them. A prompt might be as simple as &#8220;<em>Summarize this email</em>&#8221; or as complex as a multi-paragraph system message with examples and constraints.</p><p><strong>Context</strong></p><p>All the information the LLM has access to when generating a response.</p><p>This includes your prompt, as well as any additional data you provide: conversation history, retrieved documents, user profiles, tool outputs, and more. Context is everything in the model&#8217;s &#8220;working memory&#8221; at the moment of inference.</p><p><strong>Context Window</strong></p><p>The maximum amount of text (measured in &#8220;tokens&#8221;&#8212;roughly 3/4 of a word) that an LLM can process at once.</p><p>Think of it as the model&#8217;s short-term memory capacity. GPT-4 Turbo has a 128K token window; Claude 3 offers up to 200K. Anything beyond this limit simply won&#8217;t be seen by the model.</p><p><strong>Inference</strong></p><p>The moment when the model actually generates a response.</p><p>Everything you send&#8212;prompts, context, conversation history&#8212;gets processed at inference time. It&#8217;s the &#8220;go&#8221; moment.</p><p><strong>RAG (Retrieval-Augmented Generation)</strong></p><p>A technique where you fetch relevant documents or data from an external source (like a database or search engine) and inject them into the context before inference. This gives the LLM access to information it wasn&#8217;t trained on&#8212;like your company&#8217;s travel policy or today&#8217;s flight prices.</p><p><strong>Agent</strong></p><p>An AI system that can take actions, not just generate text.</p><p>Agents typically operate in loops: they reason about a task, call tools<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-3" href="#footnote-3" target="_self">3</a> (such as APIs or databases), observe the results, and iterate until the task is complete. Your travel booking assistant is an agent.</p><p><strong>Hallucination</strong></p><p>When an LLM confidently generates information that isn&#8217;t true.</p><p>Without proper context, models fill in gaps with plausible-sounding but incorrect details&#8212;like assuming &#8220;Paris&#8221; means Kentucky when the user clearly meant France.</p><p>With these concepts in hand, let&#8217;s explore why traditional prompt engineering often falls short&#8212;and what to do instead.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!h3gr!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F83ae996b-af30-4472-8715-5a5298bde70e_893x1600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!h3gr!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F83ae996b-af30-4472-8715-5a5298bde70e_893x1600.png 424w, https://substackcdn.com/image/fetch/$s_!h3gr!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F83ae996b-af30-4472-8715-5a5298bde70e_893x1600.png 848w, https://substackcdn.com/image/fetch/$s_!h3gr!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F83ae996b-af30-4472-8715-5a5298bde70e_893x1600.png 1272w, https://substackcdn.com/image/fetch/$s_!h3gr!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F83ae996b-af30-4472-8715-5a5298bde70e_893x1600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!h3gr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F83ae996b-af30-4472-8715-5a5298bde70e_893x1600.png" width="893" height="1600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/83ae996b-af30-4472-8715-5a5298bde70e_893x1600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1600,&quot;width&quot;:893,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&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="" title="" srcset="https://substackcdn.com/image/fetch/$s_!h3gr!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F83ae996b-af30-4472-8715-5a5298bde70e_893x1600.png 424w, https://substackcdn.com/image/fetch/$s_!h3gr!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F83ae996b-af30-4472-8715-5a5298bde70e_893x1600.png 848w, https://substackcdn.com/image/fetch/$s_!h3gr!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F83ae996b-af30-4472-8715-5a5298bde70e_893x1600.png 1272w, https://substackcdn.com/image/fetch/$s_!h3gr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F83ae996b-af30-4472-8715-5a5298bde70e_893x1600.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><div><hr></div><h2><strong>1. The Micro-Optimization: Prompt Engineering</strong></h2><p><em>The &#8220;Static Script&#8221;.</em></p><p>If you&#8217;ve been working with LLMs, you already know Prompt Engineering. It&#8217;s the craft of writing effective instructions for a model, and for the past two years, it&#8217;s been the primary way developers have tried to improve AI output.</p><p>Think of an LLM as a talented improv actor:</p><p><strong>Prompt Engineering</strong> is the script you hand them before the curtain rises. It defines their character, the scene's tone, and the rules of engagement. A good script can make a significant difference in 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_!_Cxe!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb44c988f-a748-49b5-892d-326d19d4d774_1200x630.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!_Cxe!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb44c988f-a748-49b5-892d-326d19d4d774_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!_Cxe!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb44c988f-a748-49b5-892d-326d19d4d774_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!_Cxe!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb44c988f-a748-49b5-892d-326d19d4d774_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!_Cxe!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb44c988f-a748-49b5-892d-326d19d4d774_1200x630.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!_Cxe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb44c988f-a748-49b5-892d-326d19d4d774_1200x630.png" width="1200" height="630" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b44c988f-a748-49b5-892d-326d19d4d774_1200x630.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:630,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:89946,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/188715439?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb44c988f-a748-49b5-892d-326d19d4d774_1200x630.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_!_Cxe!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb44c988f-a748-49b5-892d-326d19d4d774_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!_Cxe!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb44c988f-a748-49b5-892d-326d19d4d774_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!_Cxe!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb44c988f-a748-49b5-892d-326d19d4d774_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!_Cxe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb44c988f-a748-49b5-892d-326d19d4d774_1200x630.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 standard developer toolkit for prompt engineering includes:</p><ul><li><p><strong>Role Assignment </strong>&#8211; Setting the persona with instructions like <em>&#8220;You are an expert travel agent.&#8221;</em> This primes the model to use vocabulary and behaviors associated with that role.</p></li><li><p><strong>Few-Shot Examples</strong> &#8211; Providing input/output pairs demonstrating the exact format you want. For example, showing the model three examples of properly formatted JSON responses before asking it to generate one.</p></li><li><p><strong>Chain of Thought (CoT)</strong> &#8211; Instructions like <em>&#8220;Let&#8217;s think step by step&#8221;</em> that encourage the model to show its reasoning. This dramatically reduces errors in logic and math problems by forcing the model to &#8220;work through&#8221; the problem rather than jumping to an answer.</p></li><li><p><strong>Constraint Setting </strong>&#8211; Hard limits on output, like <em>&#8220;Limit your response to 50 words,</em>&#8221; or <em>&#8220;Respond only with valid JSON.&#8221;</em></p></li></ul><p>These techniques are valuable and worth mastering.</p><p>But they share a fundamental limitation that becomes apparent when you move from demos to production.</p><h3><strong>The &#8220;Paris, Kentucky&#8221; Failure</strong></h3><p>The limitation of Prompt Engineering is that it is <strong>static</strong>.</p><p>Let&#8217;s return to our travel agent. The user says: <em>&#8220;Book me a hotel in Paris for the DevOps conference.&#8221;</em></p><p>An agent relying only on prompt engineering sees the words &#8220;Paris&#8221; and &#8220;DevOps.&#8221; It has no access to external data, so it does what LLMs do when they lack information: it makes a <em>probabilistic guess</em>. There&#8217;s a Paris in France, sure, but there&#8217;s also a Paris in Kentucky, Texas, Tennessee, and several other states. Without additional context, the model has no way of knowing which one you mean.</p><p>The result?</p><p>Your user gets booked into the Best Western in Paris, Kentucky.</p><p>No amount of clever prompt phrasing can fix this. You could write <em>&#8220;Always book hotels in major international cities&#8221;</em>&#8212;but what about the user who actually wants Paris, Texas? The problem isn&#8217;t the prompt. The problem is that the model lacks three critical pieces of information:</p><ol><li><p>User lives in London (suggesting international travel is more likely)</p></li><li><p>DevOps conference this year is actually in Paris, France</p></li><li><p>The user&#8217;s company policy requires booking Marriott properties under &#8364;200/night</p></li></ol><p>This is where the paradigm shifts.</p><p>We need to move from optimizing static scripts to dynamically assembling the right information at runtime. We need Context Engineering.</p><div><hr></div><h2><strong>2. The Macro-Architecture: Context Engineering</strong></h2><p><em>The &#8220;Dynamic Set Design&#8221;.</em></p><p>If Prompt Engineering is handing a script to your improv actor, Context Engineering is building the entire stage, providing the props, dressing the set, and handing them a dossier about their scene partners&#8212;all before they speak a single line.</p><p>Context Engineering is the <strong>programmatic assembly </strong>of the &#8220;Context Package&#8221;&#8212;the exact bundle of tokens sent to the LLM at inference<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-4" href="#footnote-4" target="_self">4</a> time. It&#8217;s not about writing a better sentence; it&#8217;s about building an Orchestrator Loop that fetches the right information from multiple sources before the model ever generates a response.</p><p>This is a systems engineering challenge, involving data pipelines<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-5" href="#footnote-5" target="_self">5</a>, vector databases<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-6" href="#footnote-6" target="_self">6</a>, state machines, and API integrations.</p><p>The traditional flow looks like this:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;plaintext&quot;,&quot;nodeId&quot;:&quot;e1eaa8af-1041-4d98-b225-4ac256d001eb&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-plaintext">User Input &#8594; LLM</code></pre></div><p>The context-engineered flow looks like this:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;plaintext&quot;,&quot;nodeId&quot;:&quot;69ff3dfe-051d-42f8-8cdb-d97defbfa6c8&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-plaintext">User Input &#8594; [Memory + RAG + State + Tools] &#8594; Assembled Context &#8594; LLM</code></pre></div><p>Let&#8217;s break down each component of this architecture.</p><div><hr></div><h2><strong>The Four Pillars of Context Engineering</strong></h2><h4><strong>1. Memory Management (The Brain)</strong></h4><p>Here&#8217;s a <em>naive</em> approach that doesn&#8217;t scale: dump the entire conversation history into the context window every time.</p><p>With a 128K token context window and $10/million tokens, this gets expensive fast&#8212;and it significantly slows response time (a metric called Time to First Token, or <strong>TTFT</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_!yRAZ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3322f7f8-265f-4f89-82ed-efaf208750b3_1783x514.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!yRAZ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3322f7f8-265f-4f89-82ed-efaf208750b3_1783x514.png 424w, https://substackcdn.com/image/fetch/$s_!yRAZ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3322f7f8-265f-4f89-82ed-efaf208750b3_1783x514.png 848w, https://substackcdn.com/image/fetch/$s_!yRAZ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3322f7f8-265f-4f89-82ed-efaf208750b3_1783x514.png 1272w, https://substackcdn.com/image/fetch/$s_!yRAZ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3322f7f8-265f-4f89-82ed-efaf208750b3_1783x514.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!yRAZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3322f7f8-265f-4f89-82ed-efaf208750b3_1783x514.png" width="1456" height="420" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3322f7f8-265f-4f89-82ed-efaf208750b3_1783x514.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:420,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:101111,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/188715439?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3322f7f8-265f-4f89-82ed-efaf208750b3_1783x514.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_!yRAZ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3322f7f8-265f-4f89-82ed-efaf208750b3_1783x514.png 424w, https://substackcdn.com/image/fetch/$s_!yRAZ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3322f7f8-265f-4f89-82ed-efaf208750b3_1783x514.png 848w, https://substackcdn.com/image/fetch/$s_!yRAZ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3322f7f8-265f-4f89-82ed-efaf208750b3_1783x514.png 1272w, https://substackcdn.com/image/fetch/$s_!yRAZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3322f7f8-265f-4f89-82ed-efaf208750b3_1783x514.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>Smart memory management means being strategic about what you include:</p><p><em><strong>Short-term memory</strong></em></p><p>A rolling window of the last N conversations is used to maintain immediate context. The user said,&nbsp;<em>&#8220;Actually, make it a window seat&#8221;.</em>&nbsp;The model needs to remember they were just discussing flight preferences.</p><p><em><strong>Long-term memory</strong></em></p><p>Persistent facts about the user, retrieved semantically. Instead of storing every conversation verbatim, you extract and index key facts: &#8220;User location: London&#8221;, &#8220;Seating preference: Aisle.&#8221; At inference time, you query this memory store to retrieve only what&#8217;s relevant to the current task.</p><p><em><strong>Travel Agent Example:</strong></em></p><p>When the user asks about booking a hotel, the system retrieves &#8220;User: London-based&#8221; and &#8220;Preference: Aisle seat&#8221; from long-term memory, while keeping the last 3 conversation turns in short-term memory.</p><h4><strong>2. RAG (Retrieval Augmented Generation)</strong></h4><p>RAG is your connection to &#8220;ground truth&#8221;&#8212;information that exists outside the model&#8217;s training data. This might be company policies, product documentation, real-time pricing, or any other external data source.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!rKIs!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bb84819-7808-4a51-9f8e-a9eedd2620b6_2149x512.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!rKIs!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bb84819-7808-4a51-9f8e-a9eedd2620b6_2149x512.png 424w, https://substackcdn.com/image/fetch/$s_!rKIs!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bb84819-7808-4a51-9f8e-a9eedd2620b6_2149x512.png 848w, https://substackcdn.com/image/fetch/$s_!rKIs!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bb84819-7808-4a51-9f8e-a9eedd2620b6_2149x512.png 1272w, https://substackcdn.com/image/fetch/$s_!rKIs!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bb84819-7808-4a51-9f8e-a9eedd2620b6_2149x512.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!rKIs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bb84819-7808-4a51-9f8e-a9eedd2620b6_2149x512.png" width="1456" height="347" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7bb84819-7808-4a51-9f8e-a9eedd2620b6_2149x512.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:347,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:112283,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/188715439?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bb84819-7808-4a51-9f8e-a9eedd2620b6_2149x512.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_!rKIs!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bb84819-7808-4a51-9f8e-a9eedd2620b6_2149x512.png 424w, https://substackcdn.com/image/fetch/$s_!rKIs!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bb84819-7808-4a51-9f8e-a9eedd2620b6_2149x512.png 848w, https://substackcdn.com/image/fetch/$s_!rKIs!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bb84819-7808-4a51-9f8e-a9eedd2620b6_2149x512.png 1272w, https://substackcdn.com/image/fetch/$s_!rKIs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bb84819-7808-4a51-9f8e-a9eedd2620b6_2149x512.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>A robust RAG implementation typically combines:</p><p><em><strong>Hybrid Search</strong></em></p><p>Combining traditional keyword search (BM25)<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-7" href="#footnote-7" target="_self">7</a> with semantic vector search<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-8" href="#footnote-8" target="_self">8</a>. Keyword search catches exact matches (&#8220;policy ID 998&#8221;); semantic search catches conceptual matches (&#8220;rules about hotel spending&#8221;).</p><p><em><strong>Smart Filtering</strong></em></p><p>You don&#8217;t want to retrieve the entire company handbook&#8212;that would blow your token budget. The context engine must extract only the relevant chunks, ranked by relevance to the current query.</p><p><em><strong>Travel Agent Example:</strong></em></p><p>When the user mentions booking a hotel, the retrieval system queries the corporate travel policy database and pulls the specific snippet: &#8220;Max Hotel Spend: &#8364;200/night, Approved Chains: Marriott, Hilton.&#8221; This grounds the agent&#8217;s booking decisions in the company's actual rules.</p><h4><strong>3. State Management (The Workflow)</strong></h4><p>Unlike simple chatbots, agents are <strong>stateful</strong>&#8212;they operate within multi-step workflows where sequence matters.</p><p>You can&#8217;t book a hotel before you&#8217;ve searched for options. You can&#8217;t confirm a reservation until the user approves the price.</p><p>The LLM needs to know where it is in this business process. State management includes:</p><p><em><strong>Workflow Tracking</strong></em></p><p>What phase are we in? Discovery, Search, Selection, Booking, Confirmation?</p><p><em><strong>Progress Indicators</strong></em></p><p>What constraints have already been satisfied? What&#8217;s still needed?</p><p><em><strong>Travel Agent Example:</strong></em></p><p>The system injects a state object like:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;json&quot;,&quot;nodeId&quot;:&quot;15ff388d-42c7-4200-b627-f1460f02be91&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-json">{
  "Phase": "Booking",
  "Status": "Searching",
  "Constraints_Met": ["dates", "location"],
  "Constraints_Pending": ["user_approval", "payment"]
}</code></pre></div><p>This prevents the agent from accidentally jumping ahead to book before search results are reviewed.</p><h4><strong>4. Tool Access (The Hands)</strong></h4><p>The LLM is a reasoning engine, not a database.</p><p>It can&#8217;t check flight prices, look up conference locations, or execute bookings on its own. We must give it &#8220;hands&#8221;&#8212;well-defined interfaces (APIs) it can call.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!MBjJ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2539484-d60a-4cf3-a49b-fd5639f3ccd2_1680x230.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!MBjJ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2539484-d60a-4cf3-a49b-fd5639f3ccd2_1680x230.png 424w, https://substackcdn.com/image/fetch/$s_!MBjJ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2539484-d60a-4cf3-a49b-fd5639f3ccd2_1680x230.png 848w, https://substackcdn.com/image/fetch/$s_!MBjJ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2539484-d60a-4cf3-a49b-fd5639f3ccd2_1680x230.png 1272w, https://substackcdn.com/image/fetch/$s_!MBjJ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2539484-d60a-4cf3-a49b-fd5639f3ccd2_1680x230.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!MBjJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2539484-d60a-4cf3-a49b-fd5639f3ccd2_1680x230.png" width="1456" height="199" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d2539484-d60a-4cf3-a49b-fd5639f3ccd2_1680x230.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:199,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:51753,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/188715439?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2539484-d60a-4cf3-a49b-fd5639f3ccd2_1680x230.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_!MBjJ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2539484-d60a-4cf3-a49b-fd5639f3ccd2_1680x230.png 424w, https://substackcdn.com/image/fetch/$s_!MBjJ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2539484-d60a-4cf3-a49b-fd5639f3ccd2_1680x230.png 848w, https://substackcdn.com/image/fetch/$s_!MBjJ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2539484-d60a-4cf3-a49b-fd5639f3ccd2_1680x230.png 1272w, https://substackcdn.com/image/fetch/$s_!MBjJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2539484-d60a-4cf3-a49b-fd5639f3ccd2_1680x230.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Tool integration involves:</p><p><em><strong>Function Schemas</strong></em></p><p>JSON definitions of available tools.</p><p>For example:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;plaintext&quot;,&quot;nodeId&quot;:&quot;2ce545a3-0c7a-4afa-b29e-233b2fa28dc7&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-plaintext">search_conference_details(name: string),
search_hotels(location: string, check_in: date, max_price: number),
execute_booking(hotel_id: string)</code></pre></div><p>The model learns what tools exist and what parameters they accept.</p><p><em><strong>Orchestrator Execution</strong></em></p><p>When the model decides to call a tool, it outputs a structured request.</p><p>The Orchestrator intercepts this request, executes the actual code, and returns the result to the context for the next inference step.</p><p><em><strong>Handling Failures</strong></em></p><p>Tools don&#8217;t always work perfectly. A robust context engine must handle failure scenarios gracefully:</p><p><em>Timeouts:</em></p><p>If a tool call takes too long (e.g., an API doesn&#8217;t respond), the system might retry with exponential backoff, try an alternative tool, or inform the user of the delay.</p><p><em>Errors:</em></p><p>If a tool returns an error (e.g., &#8220;No hotels found matching criteria&#8221;), the agent should recognize this and either adjust parameters or ask the user for clarification.</p><p><em>Ambiguous Results:</em></p><p>If a tool returns unclear or partial data, the agent might call additional tools to verify, request human confirmation, or explicitly note the uncertainty to the user before proceeding.</p><p><em><strong>Travel Agent Example:</strong></em></p><p>The agent calls:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;plaintext&quot;,&quot;nodeId&quot;:&quot;69844d5c-2d67-42c1-9111-3afa50d84781&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-plaintext">search_conference_details(&#8221;DevOps Conference&#8221;)</code></pre></div><p>&#8230;and receives:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;plaintext&quot;,&quot;nodeId&quot;:&quot;9a032ee7-5c89-4983-a490-652022c381f4&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-plaintext">{ &#8220;Location&#8221;: &#8220;Paris, France&#8221;, &#8220;Dates&#8221;: &#8220;Oct 12-15&#8221; }</code></pre></div><p>Now it knows exactly which Paris the user means. If this API times out, the system retries twice, then asks the user: <em>&#8220;I&#8217;m having trouble looking up the conference details. Can you confirm the location?&#8221;</em></p><div><hr></div><h2><strong>When Context Exceeds Capacity: Prioritization</strong></h2><p>Even with large context windows, you&#8217;ll often have more relevant information than you can fit. When the assembled context exceeds your token budget, the system must prioritize.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!iSCe!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59bb33ad-8158-4b96-a84b-48ac03b49295_1200x630.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!iSCe!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59bb33ad-8158-4b96-a84b-48ac03b49295_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!iSCe!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59bb33ad-8158-4b96-a84b-48ac03b49295_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!iSCe!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59bb33ad-8158-4b96-a84b-48ac03b49295_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!iSCe!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59bb33ad-8158-4b96-a84b-48ac03b49295_1200x630.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!iSCe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59bb33ad-8158-4b96-a84b-48ac03b49295_1200x630.png" width="646" height="339.15" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/59bb33ad-8158-4b96-a84b-48ac03b49295_1200x630.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:630,&quot;width&quot;:1200,&quot;resizeWidth&quot;:646,&quot;bytes&quot;:44085,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/188715439?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59bb33ad-8158-4b96-a84b-48ac03b49295_1200x630.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_!iSCe!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59bb33ad-8158-4b96-a84b-48ac03b49295_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!iSCe!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59bb33ad-8158-4b96-a84b-48ac03b49295_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!iSCe!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59bb33ad-8158-4b96-a84b-48ac03b49295_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!iSCe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59bb33ad-8158-4b96-a84b-48ac03b49295_1200x630.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>Here&#8217;s a typical priority hierarchy:</p><p><strong>1. System Instructions </strong>(always included) &#8211; The core behavioral rules and role definition never get cut.</p><p><strong>2. Current State </strong>(highest priority) &#8211; Where are we in the workflow? This prevents the agent from taking nonsensical actions.</p><p><strong>3. Active Tool Outputs </strong>(high priority) &#8211; Results from the most recent tool calls are essential for the current reasoning step.</p><p><strong>4. Retrieved Policies/Documents </strong>(high priority) &#8211; Compliance rules and ground truth data that constrain valid actions.</p><p><strong>5. User Profile/Long-term Memory </strong>(medium priority) &#8211; Persistent facts about the user that improve personalization.</p><p><strong>6. Conversation History </strong>(lower priority) &#8211; Earlier turns can be summarized or dropped when space is tight. Keep the most recent turns intact.</p><p><strong>7. Few-shot Examples </strong>(lowest priority) &#8211; These can often be reduced or removed once the model is performing well on the task.</p><p>Think of it this way: if your agent forgets a few-shot example, the output format might drift slightly. If it forgets a compliance policy, it might book an unauthorized hotel. If it forgets its current state, it might try to book a hotel that doesn&#8217;t exist.</p><p>Prioritize accordingly.</p><div><hr></div><h2><strong>3. The Solution: &#8220;Runtime Prompt&#8221;</strong></h2><p>When you move from Prompt Engineering to Context Engineering, the actual text sent to the model (<strong>Runtime Prompt</strong>) is dynamically generated.</p><p>Here is what the &#8220;Real&#8221; System Architecture sends to the LLM for <em>Travel AI Agent Example</em>:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;plaintext&quot;,&quot;nodeId&quot;:&quot;25306f6e-5db9-426e-aa5e-d88bc82aad60&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-plaintext">*** SYSTEM INSTRUCTIONS ***

You are an Expert Travel Agent.
Review the memory, policy, and state below before answering.


*** STATE ***

Phase: Booking
Status: Searching


*** MEMORY &amp; USER PROFILE ***

- User Location: London, UK
- Preference: Aisle seats
- History: Prefers Europe for conferences


*** RAG / RETRIEVED POLICY ***

- Corporate Policy ID: 998
- Max Hotel Spend: &#8364;200
- Approved Chains: Marriott, Hilton


*** TOOL OUTPUTS ***

&gt; search_conference_details(&#8221;DevOps Conference&#8221;)
  Result: &#8220;Location: Paris, France. Dates: Oct 12-15&#8221;


*** USER INPUT ***

&#8220;Book me a hotel in Paris for the DevOps conference.&#8221;</code></pre></div><h3><strong>The Result</strong></h3><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!iAks!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5386434a-13e9-4481-b5c6-7b0e7f793aec_1200x630.gif" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!iAks!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5386434a-13e9-4481-b5c6-7b0e7f793aec_1200x630.gif 424w, https://substackcdn.com/image/fetch/$s_!iAks!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5386434a-13e9-4481-b5c6-7b0e7f793aec_1200x630.gif 848w, https://substackcdn.com/image/fetch/$s_!iAks!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5386434a-13e9-4481-b5c6-7b0e7f793aec_1200x630.gif 1272w, https://substackcdn.com/image/fetch/$s_!iAks!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5386434a-13e9-4481-b5c6-7b0e7f793aec_1200x630.gif 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!iAks!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5386434a-13e9-4481-b5c6-7b0e7f793aec_1200x630.gif" width="420" height="220.5" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5386434a-13e9-4481-b5c6-7b0e7f793aec_1200x630.gif&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:630,&quot;width&quot;:1200,&quot;resizeWidth&quot;:420,&quot;bytes&quot;:236467,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/gif&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/188715439?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5386434a-13e9-4481-b5c6-7b0e7f793aec_1200x630.gif&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!iAks!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5386434a-13e9-4481-b5c6-7b0e7f793aec_1200x630.gif 424w, https://substackcdn.com/image/fetch/$s_!iAks!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5386434a-13e9-4481-b5c6-7b0e7f793aec_1200x630.gif 848w, https://substackcdn.com/image/fetch/$s_!iAks!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5386434a-13e9-4481-b5c6-7b0e7f793aec_1200x630.gif 1272w, https://substackcdn.com/image/fetch/$s_!iAks!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5386434a-13e9-4481-b5c6-7b0e7f793aec_1200x630.gif 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Because the context was engineered before inference, the model now has everything it needs to make a correct decision:</p><ul><li><p>Disambiguation: The tool output explicitly clarifies &#8220;Paris, France.&#8221; No ambiguity remains.</p></li><li><p>Compliance: The RAG retrieval enforces the &#8364;200/night limit and approved hotel chains. The agent won&#8217;t even consider the &#8364;400/night boutique hotel.</p></li><li><p>Reasoning: With all constraints visible, the LLM selects the Paris Marriott Champs-&#201;lys&#233;es (&#8364;190/night) instead of making a blind guess.</p></li></ul><p>This is the power of Context Engineering: transforming the LLM from a probabilistic text generator into a reliable reasoning engine constrained by real-world data.</p><div><hr></div><h2>Understanding the Tradeoffs</h2><p>More context isn&#8217;t free. As you implement these systems, be mindful of the costs:</p><p><strong>Token Costs: </strong>Each additional token you send to the model costs money. At $10 per million input tokens, a 10K token context package processed 100,000 times costs $10,000. The prioritization hierarchy discussed earlier becomes essential at scale.</p><p><strong>Latency: </strong>Larger context windows increase Time to First Token (TTFT). Users waiting 3+ seconds for a response may disengage. You&#8217;ll need to balance comprehensiveness with responsiveness.</p><p><strong>System Complexity:</strong> Memory stores, RAG pipelines, state machines, and tool integrations all require maintenance, monitoring, and debugging. Every component is a potential point of failure.</p><p><strong>Retrieval Quality:</strong> Bad retrieval is worse than no retrieval. If your RAG system surfaces irrelevant documents, you&#8217;re paying token costs to confuse the model. Invest in retrieval quality metrics and continuous improvement.</p><p><strong>The right approach is iterative: </strong>start with the minimum viable context, measure what&#8217;s missing when failures occur, and expand strategically.</p><div><hr></div><h2><strong>Closing Thoughts</strong></h2><p>Context Engineering represents a fundamental shift in how we build AI applications.</p><p>It moves us from treating LLMs as chatbots that need cleverer instructions to treating them as reasoning engines that need better inputs.</p><p>The investment is real, but the payoff is production-grade reliability that prompt tweaking alone can never achieve.</p><div><hr></div><p>&#128075; I&#8217;d like to thank <strong><a href="https://www.linkedin.com/in/pvergadia/">Priyanka</a></strong> for writing this newsletter!</p><p>Also subscribe to her newsletter, <a href="https://www.thecloudgirl.dev/subscribe-to-cloud-girl-bytes">Cloud Girl Bytes</a>, and follow her on <a href="https://www.linkedin.com/in/pvergadia/">LinkedIn</a>, <a href="https://x.com/pvergadia">Twitter</a>, <a href="https://www.youtube.com/@pvergadia">YouTube</a>, or the social network of your choice. It&#8217;ll help you quickly master cloud and AI.</p><div><hr></div><p>I launched <strong>Design, Build, Scale</strong> (newsletter series exclusive to PAID subscribers).</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://newsletter.systemdesign.one/subscribe?yearly=true" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!jG0C!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63fca468-adce-4713-97a0-203c35bc1c60_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!jG0C!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63fca468-adce-4713-97a0-203c35bc1c60_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!jG0C!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63fca468-adce-4713-97a0-203c35bc1c60_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!jG0C!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63fca468-adce-4713-97a0-203c35bc1c60_1200x630.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!jG0C!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63fca468-adce-4713-97a0-203c35bc1c60_1200x630.png" width="1200" height="630" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/63fca468-adce-4713-97a0-203c35bc1c60_1200x630.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:630,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:null,&quot;href&quot;:&quot;https://newsletter.systemdesign.one/subscribe?yearly=true&quot;,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/179076610?img=https%3A%2F%2Fsubstackcdn.com%2Fimage%2Ffetch%2F%24s_%21jG0C%21%2Cf_auto%2Cq_auto%3Agood%2Cfl_progressive%3Asteep%2Fhttps%253A%252F%252Fsubstack-post-media.s3.amazonaws.com%252Fpublic%252Fimages%252F63fca468-adce-4713-97a0-203c35bc1c60_1200x630.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!jG0C!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63fca468-adce-4713-97a0-203c35bc1c60_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!jG0C!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63fca468-adce-4713-97a0-203c35bc1c60_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!jG0C!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63fca468-adce-4713-97a0-203c35bc1c60_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!jG0C!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63fca468-adce-4713-97a0-203c35bc1c60_1200x630.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 you upgrade, you&#8217;ll get:</p><ul><li><p><strong>High-level architecture of real-world systems.</strong></p></li><li><p>Deep dive into how popular real-world systems actually work.</p></li><li><p><strong>How real-world systems handle scale, reliability, and performance.</strong></p></li><li><p>10x the results you currently get with 1/10th of your time, energy, and effort.</p></li></ul><p><strong>&#128073; <a href="https://newsletter.systemdesign.one/subscribe?yearly=true">CLICK HERE TO ACCESS DESIGN, BUILD, SCALE!</a></strong></p><div><hr></div><p>If you find this newsletter valuable, share it with a friend, and subscribe if you haven&#8217;t already. There are <a href="http://newsletter.systemdesign.one/subscribe?group=true">group discounts</a>, <a href="http://newsletter.systemdesign.one/subscribe?gift=true">gift options</a>, and <a href="https://newsletter.systemdesign.one/leaderboard">referral rewards</a> available.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/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://newsletter.systemdesign.one/subscribe?"><span>Subscribe now</span></a></p><div><hr></div><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://www.linkedin.com/in/nk-systemdesign-one/" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!bEFk!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 424w, https://substackcdn.com/image/fetch/$s_!bEFk!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 848w, https://substackcdn.com/image/fetch/$s_!bEFk!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 1272w, https://substackcdn.com/image/fetch/$s_!bEFk!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!bEFk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png" width="152" height="152" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:320,&quot;width&quot;:320,&quot;resizeWidth&quot;:152,&quot;bytes&quot;:74009,&quot;alt&quot;:&quot;Author Neo Kim; System design case studies&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:&quot;https://www.linkedin.com/in/nk-systemdesign-one/&quot;,&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="Author Neo Kim; System design case studies" title="Author Neo Kim; System design case studies" srcset="https://substackcdn.com/image/fetch/$s_!bEFk!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 424w, https://substackcdn.com/image/fetch/$s_!bEFk!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 848w, https://substackcdn.com/image/fetch/$s_!bEFk!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 1272w, https://substackcdn.com/image/fetch/$s_!bEFk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption"><strong>&#128075; Find me on <a href="https://www.linkedin.com/in/nk-systemdesign-one/">LinkedIn</a> | <a href="https://x.com/intent/follow?screen_name=systemdesignone">Twitter</a> | <a href="https://www.threads.net/@systemdesignone">Threads</a> | <a href="https://www.instagram.com/systemdesignone/">Instagram</a></strong></figcaption></figure></div><div><hr></div><p>Thank you for supporting this newsletter.</p><p>You are now 210,001+ readers strong, very close to 210k. Let&#8217;s try to get 211k readers by 7 March. Consider sharing this post with your friends and get rewards.</p><p>Y&#8217;all are the best.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!6oWl!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!6oWl!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png 424w, https://substackcdn.com/image/fetch/$s_!6oWl!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png 848w, https://substackcdn.com/image/fetch/$s_!6oWl!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png 1272w, https://substackcdn.com/image/fetch/$s_!6oWl!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!6oWl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png" width="590" height="368.75" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2e739087-a910-4643-be36-997b6dd5b4af_800x500.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:500,&quot;width&quot;:800,&quot;resizeWidth&quot;:590,&quot;bytes&quot;:87878,&quot;alt&quot;:&quot;system design newsletter&quot;,&quot;title&quot;:&quot;system design newsletter&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/163380418?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="system design newsletter" title="system design newsletter" srcset="https://substackcdn.com/image/fetch/$s_!6oWl!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png 424w, https://substackcdn.com/image/fetch/$s_!6oWl!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png 848w, https://substackcdn.com/image/fetch/$s_!6oWl!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png 1272w, https://substackcdn.com/image/fetch/$s_!6oWl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.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 class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/p/context-engineering-vs-prompt-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://newsletter.systemdesign.one/p/context-engineering-vs-prompt-engineering?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><div><hr></div><ul><li><p><em>Block diagrams created using <a href="https://app.eraser.io/auth/sign-up?ref=neo">Eraser</a>.</em></p></li></ul><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>Few-shot prompting is a technique where a model is given a small number of input-output examples within the prompt to guide its responses.</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>Llama is used for more control, customization, or data privacy compared to closed API-only models</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 tool is an external function or API that an AI model can call to retrieve real-world data or perform actions beyond generating text.</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>Inference time is the moment when the model receives your prompt and generates a response.</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>Data pipelines are automated workflows that ingest, transform, and route data from source systems to destinations for storage or analysis.</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>Vector databases are specialized storage systems designed to index and query high-dimensional embeddings for fast similarity search.</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>BM25 (best matching) is a ranking function used by search engines to estimate the relevance of documents to a search query.</p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-8" href="#footnote-anchor-8" class="footnote-number" contenteditable="false" target="_self">8</a><div class="footnote-content"><p>Semantic vector search is a method of finding information by comparing the meanings of text using numerical embeddings (vectors) rather than matching exact keywords.</p><p></p></div></div>]]></content:encoded></item><item><title><![CDATA[A Crash Course on High Availability]]></title><description><![CDATA[#126: What Is High Availability]]></description><link>https://newsletter.systemdesign.one/p/what-is-high-availability</link><guid isPermaLink="false">https://newsletter.systemdesign.one/p/what-is-high-availability</guid><dc:creator><![CDATA[Neo Kim]]></dc:creator><pubDate>Sat, 28 Feb 2026 12:57:09 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/3dcd543a-ebea-4765-a859-d4bae681e495_1280x720.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/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">Get my system design playbook for FREE on newsletter signup:</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><ul><li><p><em><a href="https://newsletter.systemdesign.one/p/what-is-high-availability/?action=share">Share this post</a> &amp; I'll send you some rewards for the referrals.</em></p></li><li><p><em>Block diagrams created using <a href="https://app.eraser.io/auth/sign-up?ref=neo">Eraser</a>.</em></p></li></ul><div><hr></div><p>Why should we care about uptime? And what exactly is high availability?</p><p>Downtime is expensive&#8230;</p><p>A payment system that goes down during peak shopping hours bleeds revenue. A hospital record system that crashes mid-shift puts patients at risk. An app going offline for ten minutes triggers trending hashtags from angry users.</p><p>Downtime is never abstract&#8230;</p><p>It translates into lost money, lost trust, and sometimes even legal penalties. Some of it can never be recovered. High availability started long before the cloud. In the 1960s, defense and finance systems had to run nonstop. Those engineers designed machines that could keep working even when parts failed. When the internet arrived, that same discipline moved online. Banks, retailers, and payment networks learned that a brief outage can erase months of profit.</p><p>With the widespread use of technology, the expectation of &#8220;always on&#8221; has never been greater. Now, uptime is not a luxury but a baseline.</p><p>The goal never changed: build systems that keep running when the world shakes.</p><p>So failures will happen. No matter how hard we try, we can&#8217;t avoid them. Hardware burns out, networks drop packets, software engineers create bugs. High availability (<strong>HA</strong>) is about absorbing those failures behind the scenes&#8230;it&#8217;s about the service being available regardless of failures.</p><p>People don&#8217;t think about their car tires until one goes flat.</p><p>High availability is having a spare one in the trunk. After we replace them, we can drive again. We can&#8217;t always control why the tire got flat, but we can carry a spare one. This is the core idea of high availability.</p><p>Now let&#8217;s put some numbers to it.</p><p>Onward.</p><div><hr></div><h2><a href="https://orchidsapp.link/neokim">The best way to build any app (Partner)</a></h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://orchidsapp.link/neokim" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!td_i!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F676ee402-cd35-46bd-b6a7-dee96527e3d1_1600x900.png 424w, https://substackcdn.com/image/fetch/$s_!td_i!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F676ee402-cd35-46bd-b6a7-dee96527e3d1_1600x900.png 848w, https://substackcdn.com/image/fetch/$s_!td_i!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F676ee402-cd35-46bd-b6a7-dee96527e3d1_1600x900.png 1272w, https://substackcdn.com/image/fetch/$s_!td_i!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F676ee402-cd35-46bd-b6a7-dee96527e3d1_1600x900.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!td_i!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F676ee402-cd35-46bd-b6a7-dee96527e3d1_1600x900.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/676ee402-cd35-46bd-b6a7-dee96527e3d1_1600x900.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:&quot;https://orchidsapp.link/neokim&quot;,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!td_i!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F676ee402-cd35-46bd-b6a7-dee96527e3d1_1600x900.png 424w, https://substackcdn.com/image/fetch/$s_!td_i!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F676ee402-cd35-46bd-b6a7-dee96527e3d1_1600x900.png 848w, https://substackcdn.com/image/fetch/$s_!td_i!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F676ee402-cd35-46bd-b6a7-dee96527e3d1_1600x900.png 1272w, https://substackcdn.com/image/fetch/$s_!td_i!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F676ee402-cd35-46bd-b6a7-dee96527e3d1_1600x900.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>Treat your app like an Orchid: A beautiful flower that needs sunlight and a bit of water &#127800;</p><p>Most &#8220;AI builders&#8221; make you grow your app in their pot. Same stack. Same limits. Same rules. And on their databases.</p><p><a href="https://orchidsapp.link/neokim">Orchids</a> is different:</p><ul><li><p>It&#8217;s your build space, set up your way.</p></li><li><p>Build anything, Web app, mobile app, Slack bot, Chrome extension, Python script, whatever.</p></li><li><p>Bring your own AI subscriptions so you&#8217;re not paying twice.</p></li><li><p>Plug in the database you already use and trust.</p></li><li><p>Use any payment infra you want.</p></li></ul><p>Try <strong><a href="https://orchidsapp.link/neokim">Orchids.app</a></strong> and build it the way you were meant to:</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://orchidsapp.link/neokim&quot;,&quot;text&quot;:&quot;Get Started Today&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://orchidsapp.link/neokim"><span>Get Started Today</span></a></p><p>(Thanks, <a href="https://orchidsapp.link/neokim">Orchids</a>, for partnering on this post.)</p><p><strong>Use this discount code to get a one time 15% off during checkout: MARCH15</strong></p><div><hr></div><h1>Fundamentals</h1><p>HA means keeping a system running even when parts of it fail.</p><p>The higher the availability, the less impact each individual failure has. To manage HA, engineers use <strong><a href="https://www.pagerduty.com/resources/digital-operations/learn/what-is-slo-sla-sli/">SLAs, SLOs, and SLIs</a></strong>. These turn vague ideas like &#8220;keep it up and running&#8221; into numbers we can measure:</p><ul><li><p><strong>Service Level Agreement (SLA):</strong> Contract with customers about service performance.</p><ul><li><p>This contract keeps a record of what the service provider promises to deliver</p></li><li><p>There are penalties or costs if the contract is not respected</p></li><li><p>In HA, this is an agreement about how much downtime is acceptable</p></li><li><p>For example, &#8220;our app will be online 99.9% of the time. If not, we&#8217;ll give your money back.&#8221;</p></li></ul></li><li><p><strong>Service Level Objective (SLO):</strong> Specific internal goal for the service performance.</p><ul><li><p>This is the target that internal teams are trying to hit with a desired metric</p></li><li><p>Your SLA is the minimum you promise customers; your SLO is the better performance you target internally</p></li><li><p>For example, if the SLA is 95% uptime, the SLO might be 98% to leave a 3% safety margin</p></li></ul></li><li><p><strong>Service Level Indicator (SLI):</strong> Metric used to measure service performance.</p><ul><li><p>Without measuring service performance, we can&#8217;t know if we&#8217;re hitting the targets</p></li><li><p>These metrics should reflect the SLO and SLA</p></li><li><p>For example, &#8220;Percentage of failed requests.&#8221;</p></li></ul></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!dpG_!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa1d541b4-041a-42f8-86c9-aab5de6e1592_1200x630.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!dpG_!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa1d541b4-041a-42f8-86c9-aab5de6e1592_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!dpG_!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa1d541b4-041a-42f8-86c9-aab5de6e1592_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!dpG_!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa1d541b4-041a-42f8-86c9-aab5de6e1592_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!dpG_!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa1d541b4-041a-42f8-86c9-aab5de6e1592_1200x630.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!dpG_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa1d541b4-041a-42f8-86c9-aab5de6e1592_1200x630.png" width="1200" height="630" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a1d541b4-041a-42f8-86c9-aab5de6e1592_1200x630.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:630,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:65316,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/189243555?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa1d541b4-041a-42f8-86c9-aab5de6e1592_1200x630.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_!dpG_!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa1d541b4-041a-42f8-86c9-aab5de6e1592_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!dpG_!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa1d541b4-041a-42f8-86c9-aab5de6e1592_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!dpG_!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa1d541b4-041a-42f8-86c9-aab5de6e1592_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!dpG_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa1d541b4-041a-42f8-86c9-aab5de6e1592_1200x630.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">SLA vs SLO vs SLI</figcaption></figure></div><p>Let&#8217;s illustrate it with an example:</p><ul><li><p>A restaurant promises customers that their food will be delivered within 20 minutes of ordering (SLA).</p></li><li><p>The kitchen aims to finish orders in 15 minutes to stay ahead (SLO).</p></li><li><p>They track the average order completion time (SLI).</p></li></ul><p>These targets get expressed in &#8220;nines of availability&#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_!Jxj3!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65ef7aa6-5075-492b-b76a-bdf9ea60ae86_1200x630.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Jxj3!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65ef7aa6-5075-492b-b76a-bdf9ea60ae86_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!Jxj3!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65ef7aa6-5075-492b-b76a-bdf9ea60ae86_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!Jxj3!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65ef7aa6-5075-492b-b76a-bdf9ea60ae86_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!Jxj3!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65ef7aa6-5075-492b-b76a-bdf9ea60ae86_1200x630.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Jxj3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65ef7aa6-5075-492b-b76a-bdf9ea60ae86_1200x630.png" width="1200" height="630" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/65ef7aa6-5075-492b-b76a-bdf9ea60ae86_1200x630.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:630,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:92909,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/189243555?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65ef7aa6-5075-492b-b76a-bdf9ea60ae86_1200x630.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_!Jxj3!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65ef7aa6-5075-492b-b76a-bdf9ea60ae86_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!Jxj3!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65ef7aa6-5075-492b-b76a-bdf9ea60ae86_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!Jxj3!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65ef7aa6-5075-492b-b76a-bdf9ea60ae86_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!Jxj3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65ef7aa6-5075-492b-b76a-bdf9ea60ae86_1200x630.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">Nines of availability</figcaption></figure></div><p>One nine means 90% uptime; two nines mean 99%; and so on&#8230;</p><p>Each extra nine sounds small, but cuts downtime by a ton. For example, 99% uptime allows over 3 days of outage a year, while 99.9% (&#8220;three nines&#8221;) allows only about 8 hours. Every nine added costs more. It needs better hardware, more redundancy, and more monitoring.</p><p>The closer you aim for perfect uptime, the more effort and money it takes to maintain it.</p><p>When failures occur,&nbsp;<a href="https://www.atlassian.com/incident-management/kpis/common-metrics">recovery metrics</a>&nbsp;help us measure how quickly and effectively we can recover. Here are the most important ones:</p><ul><li><p><strong>Recovery Time Objective (RTO)</strong></p><ul><li><p>How fast should the system recover from failure? How long can it be down for?</p></li><li><p>Larger RTO means more downtime is acceptable; smaller RTO means less downtime</p></li><li><p>For example, an RTO of 10 minutes means that the system should be able to recover within 10 minutes of failing</p></li></ul></li><li><p><strong>Recovery Point Objective (RPO)</strong></p><ul><li><p>To what point in time does the system recover? How much data loss is acceptable?</p></li><li><p>Larger RPO means more data loss, smaller RPO means less</p></li><li><p>For example, an RPO of 5 minutes means 5 minutes of data gets lost</p></li></ul></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!fPWZ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6396a491-c1e9-4b7d-8dd6-3d00ac688e24_1200x630.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!fPWZ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6396a491-c1e9-4b7d-8dd6-3d00ac688e24_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!fPWZ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6396a491-c1e9-4b7d-8dd6-3d00ac688e24_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!fPWZ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6396a491-c1e9-4b7d-8dd6-3d00ac688e24_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!fPWZ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6396a491-c1e9-4b7d-8dd6-3d00ac688e24_1200x630.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!fPWZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6396a491-c1e9-4b7d-8dd6-3d00ac688e24_1200x630.png" width="1200" height="630" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6396a491-c1e9-4b7d-8dd6-3d00ac688e24_1200x630.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:630,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:81930,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/189243555?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6396a491-c1e9-4b7d-8dd6-3d00ac688e24_1200x630.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_!fPWZ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6396a491-c1e9-4b7d-8dd6-3d00ac688e24_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!fPWZ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6396a491-c1e9-4b7d-8dd6-3d00ac688e24_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!fPWZ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6396a491-c1e9-4b7d-8dd6-3d00ac688e24_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!fPWZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6396a491-c1e9-4b7d-8dd6-3d00ac688e24_1200x630.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">RPO represents gap between last durable recovery point and an incident</figcaption></figure></div><ul><li><p><strong>MTTD (Mean Time to Detect)</strong></p><ul><li><p>This is the mean time needed to notice a failure</p></li><li><p>How long does it usually take for the system or team to detect that something is wrong?</p></li><li><p>Smaller MTTD means faster detection; larger MTTD means slower detection</p></li><li><p>For example, an MTTD of 30 seconds means issues get found half a minute after they occur on average</p></li></ul></li></ul><ul><li><p><strong>MTTR (Mean Time to Repair)</strong></p><ul><li><p>This is the mean time needed to fix a failure. How long does the system usually take to recover?</p></li><li><p>Larger MTTR means more time to recover, smaller MTTR means less</p></li><li><p>For example, an MTTR of 5 minutes means the failure will take 5 minutes to recover on average</p></li></ul></li><li><p><strong>MTBF (Mean Time Between Failures)</strong></p><ul><li><p>This is the mean time between two failures. How often does the system usually fail?</p></li><li><p>Larger MTBF means failures happen less often &amp; vice-versa</p></li><li><p>For example, an MTBF of 1h means failures usually happen every hour</p></li></ul></li><li><p><strong>MTTF (Mean Time to Failure)</strong></p><ul><li><p>This metric is designed for non-recoverable components. How long is the lifespan of this component?</p></li><li><p>This metric differs from MTBF because it lacks a recovery component. The component is alive, and then it crashes without recovery. MTTF is the time between those two points.</p></li><li><p>A larger MTTF means a component has a longer lifespan, and a smaller MTTF means a shorter one</p></li><li><p>For example, an MTTF of 3 years means a component usually lasts for 3 years before becoming unusable</p></li></ul></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!DgT0!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1cf9f0c-66af-4a82-8a8a-d0d5f067ce7c_1200x630.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!DgT0!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1cf9f0c-66af-4a82-8a8a-d0d5f067ce7c_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!DgT0!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1cf9f0c-66af-4a82-8a8a-d0d5f067ce7c_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!DgT0!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1cf9f0c-66af-4a82-8a8a-d0d5f067ce7c_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!DgT0!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1cf9f0c-66af-4a82-8a8a-d0d5f067ce7c_1200x630.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!DgT0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1cf9f0c-66af-4a82-8a8a-d0d5f067ce7c_1200x630.png" width="1200" height="630" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d1cf9f0c-66af-4a82-8a8a-d0d5f067ce7c_1200x630.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:630,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:68479,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/189243555?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1cf9f0c-66af-4a82-8a8a-d0d5f067ce7c_1200x630.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_!DgT0!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1cf9f0c-66af-4a82-8a8a-d0d5f067ce7c_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!DgT0!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1cf9f0c-66af-4a82-8a8a-d0d5f067ce7c_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!DgT0!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1cf9f0c-66af-4a82-8a8a-d0d5f067ce7c_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!DgT0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1cf9f0c-66af-4a82-8a8a-d0d5f067ce7c_1200x630.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">NOTE: MTTF is for non-repairable systems. For repairable systems, it&#8217;s uptime.</figcaption></figure></div><p><strong>Availability Formula</strong></p><p>Availability links uptime &amp; downtime in one line:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;plaintext&quot;,&quot;nodeId&quot;:&quot;2263ec8c-47cd-441d-988c-7e9d581966a6&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-plaintext">Availability = MTBF / (MTBF + MTTR)</code></pre></div><p>If the system runs for 1000 hours before a 1-hour fix, uptime is 99.9%.</p><p>Every extra nine costs more to achieve. Past &#8220;three nines,&#8221; you buy less outage and pay more in redundancy, automation, and testing.</p><p><em><strong>Takeaway:</strong></em></p><p>HA is measurable. Metrics turn abstract goals into clear engineering targets.</p><p>What gets measured gets managed.</p><p>Ready for the best part?</p><div><hr></div><p><em><strong>Reminder: this is a teaser of the subscriber-only post, exclusive to my golden members.</strong></em></p><p>When you upgrade, you&#8217;ll get:</p><ul><li><p><strong>Full access to System Design Case Studies</strong></p></li><li><p>FREE access to (coming) Interview Academy</p></li><li><p><strong>FREE access to (coming) Design, Build, Scale newsletter series</strong></p></li></ul><p>And more!</p><p>Get 10x the results you currently get with 1/10th the time, energy &amp; effort.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/subscribe&quot;,&quot;text&quot;:&quot;Unlock Your Next Level&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesign.one/subscribe"><span>Unlock Your Next Level</span></a></p>
      <p>
          <a href="https://newsletter.systemdesign.one/p/what-is-high-availability">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[System Design Interview: Design ChatGPT]]></title><description><![CDATA[#125: System Design Interview]]></description><link>https://newsletter.systemdesign.one/p/chatgpt-system-design</link><guid isPermaLink="false">https://newsletter.systemdesign.one/p/chatgpt-system-design</guid><dc:creator><![CDATA[Neo Kim]]></dc:creator><pubDate>Wed, 25 Feb 2026 16:30:56 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/f0475035-1015-4e4d-8d47-0c650b185661_1280x720.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/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">Get my system design playbook for FREE on newsletter signup:</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><ul><li><p><em><a href="https://newsletter.systemdesign.one/p/chatgpt-system-design/?action=share">Share this post</a> &amp; I'll send you some rewards for the referrals.</em></p></li><li><p><em>Block diagrams created using <a href="https://app.eraser.io/auth/sign-up?ref=neo">Eraser</a>.</em></p></li></ul><div><hr></div><p>Most engineers think designing an AI chat system is just <em>&#8220;calling OpenAI API and saving messages to a database&#8221;.</em></p><p><em>That approach doesn&#8217;t work when you need to handle ChatGPT&#8217;s scale:</em></p><ul><li><p><em>5.8 billion visits per month</em></p></li><li><p><em>1 billion weekly active users sending 2.5+ billion prompts per day</em></p></li></ul><p>Your database can&#8217;t store 500TB per year. API costs will hit $145 million per month. And you&#8217;ll need 11.4 million concurrent connections that no single server can handle.</p><p>This problem shows up in senior and staff-level interviews at companies building AI products because it tests the exact skills that separate mid-level engineers from seniors:</p><ul><li><p>handling stateful connections at scale,</p></li><li><p>managing expensive external dependencies,</p></li><li><p>keeping costs under control while maintaining good UX,</p></li><li><p>and designing for failures when parts of your system go down.</p></li></ul><p>We&#8217;re going to build this from scratch at ChatGPT&#8217;s real scale, starting with clarifying requirements, then moving through frontend and backend design, database sharding<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a>, the complete user flow, GPU infrastructure, and finally explaining how to scale even further to 1 billion users.</p><p>Before we design anything, we need to understand exactly what we&#8217;re building and at what scale&#8230;</p><div><hr></div><h3><a href="https://getunblocked.com/?utm_source=systemdesign&amp;utm_medium=email&amp;utm_campaign=contextengine">Unblocked: The context layer your AI tools are missing (Partner)</a></h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://getunblocked.com/?utm_source=systemdesign&amp;utm_medium=email&amp;utm_campaign=contextengine" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!-9qf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4157723-5d61-4d04-b699-f15d7670aeb4_1200x600.png 424w, https://substackcdn.com/image/fetch/$s_!-9qf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4157723-5d61-4d04-b699-f15d7670aeb4_1200x600.png 848w, https://substackcdn.com/image/fetch/$s_!-9qf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4157723-5d61-4d04-b699-f15d7670aeb4_1200x600.png 1272w, https://substackcdn.com/image/fetch/$s_!-9qf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4157723-5d61-4d04-b699-f15d7670aeb4_1200x600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!-9qf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4157723-5d61-4d04-b699-f15d7670aeb4_1200x600.png" width="1200" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b4157723-5d61-4d04-b699-f15d7670aeb4_1200x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:307185,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:&quot;https://getunblocked.com/?utm_source=systemdesign&amp;utm_medium=email&amp;utm_campaign=contextengine&quot;,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/188825279?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4157723-5d61-4d04-b699-f15d7670aeb4_1200x600.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!-9qf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4157723-5d61-4d04-b699-f15d7670aeb4_1200x600.png 424w, https://substackcdn.com/image/fetch/$s_!-9qf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4157723-5d61-4d04-b699-f15d7670aeb4_1200x600.png 848w, https://substackcdn.com/image/fetch/$s_!-9qf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4157723-5d61-4d04-b699-f15d7670aeb4_1200x600.png 1272w, https://substackcdn.com/image/fetch/$s_!-9qf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4157723-5d61-4d04-b699-f15d7670aeb4_1200x600.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>Give your agents the understanding they need to generate reliable code, reviews, and answers. <strong><a href="https://getunblocked.com/?utm_source=systemdesign&amp;utm_medium=email&amp;utm_campaign=contextengine">Unblocked</a></strong> builds context from your team&#8217;s code, PR history, conversations, documentation, planning tools, and runtime signals. It surfaces the insights that matter so AI outputs reflect how your system actually works.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://getunblocked.com/?utm_source=systemdesign&amp;utm_medium=email&amp;utm_campaign=contextengine&quot;,&quot;text&quot;:&quot;Try Unblocked Now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://getunblocked.com/?utm_source=systemdesign&amp;utm_medium=email&amp;utm_campaign=contextengine"><span>Try Unblocked Now</span></a></p><p>(Thank you, <a href="https://getunblocked.com/?utm_source=systemdesign&amp;utm_medium=email&amp;utm_campaign=contextengine">Unblocked</a>, for partnering on this post.)</p><div><hr></div><p>I want to reintroduce <a href="https://linkedin.com/in/hayksimonyan">Hayk Simonyan</a> as a guest author.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://youtube.com/@hayk.simonyan" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!TNRZ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe42ce2a7-78b8-43b3-b7cf-b293d660240a_1748x720.png 424w, https://substackcdn.com/image/fetch/$s_!TNRZ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe42ce2a7-78b8-43b3-b7cf-b293d660240a_1748x720.png 848w, https://substackcdn.com/image/fetch/$s_!TNRZ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe42ce2a7-78b8-43b3-b7cf-b293d660240a_1748x720.png 1272w, https://substackcdn.com/image/fetch/$s_!TNRZ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe42ce2a7-78b8-43b3-b7cf-b293d660240a_1748x720.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!TNRZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe42ce2a7-78b8-43b3-b7cf-b293d660240a_1748x720.png" width="1456" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e42ce2a7-78b8-43b3-b7cf-b293d660240a_1748x720.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:387657,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:&quot;https://youtube.com/@hayk.simonyan&quot;,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/188825279?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe42ce2a7-78b8-43b3-b7cf-b293d660240a_1748x720.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_!TNRZ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe42ce2a7-78b8-43b3-b7cf-b293d660240a_1748x720.png 424w, https://substackcdn.com/image/fetch/$s_!TNRZ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe42ce2a7-78b8-43b3-b7cf-b293d660240a_1748x720.png 848w, https://substackcdn.com/image/fetch/$s_!TNRZ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe42ce2a7-78b8-43b3-b7cf-b293d660240a_1748x720.png 1272w, https://substackcdn.com/image/fetch/$s_!TNRZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe42ce2a7-78b8-43b3-b7cf-b293d660240a_1748x720.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>He&#8217;s a senior software engineer specializing in helping developers break through their career plateaus and secure senior roles.</p><p>If you want to master the essential system design skills and land senior developer roles, I highly recommend checking out Hayk&#8217;s <strong><a href="https://youtube.com/@hayk.simonyan">YouTube channel</a></strong>.</p><p>His approach focuses on what top employers actually care about: system design expertise, advanced project experience, and elite-level interview performance.</p><div><hr></div><h2><strong>Clarifying Requirements</strong></h2><p> In interviews, candidates who skip this step fail immediately.</p><p><strong>Questions to ask:</strong></p><ul><li><p>Are we building the AI model itself or integrating with existing ones?</p></li><li><p>Do we need streaming responses (word by word) or complete responses?</p></li><li><p>What&#8217;s our expected scale? Thousands or millions of users?</p></li><li><p>Do users need accounts and conversation history?</p></li><li><p>Are conversations private or shareable?</p></li><li><p>Do we support multiple languages?</p></li><li><p>How do we handle rate limiting<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-2" href="#footnote-2" target="_self">2</a>? Free vs paid tiers?</p></li><li><p>Text only, or images and files too?</p></li><li><p>Do we need content moderation?</p></li></ul><p><strong>For this design, let&#8217;s assume:</strong></p><ul><li><p>Integrating with existing LLM (not building the model ourselves)</p></li><li><p>Streaming responses required for good UX</p></li><li><p>As of January 2026, ChatGPT has 800-900 million weekly active users, with an average of 2.5+ billion prompts per day</p></li><li><p>Users need accounts, private conversations with history</p></li><li><p>Text only, English first</p></li><li><p>Rate limiting on both requests and tokens</p></li><li><p>Basic content moderation required</p></li></ul><p>Now that we&#8217;ve defined our requirements, let&#8217;s start with what users actually see and interact with.</p><div><hr></div><h2><strong>Frontend Interface Design</strong></h2><p>Let&#8217;s visualize what we&#8217;re building. This clarifies requirements and influences backend decisions.</p><h4><strong>Main Interface:</strong></h4><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!v0AH!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61231358-4f6b-4ad1-a10e-a62cbd472977_1600x1357.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!v0AH!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61231358-4f6b-4ad1-a10e-a62cbd472977_1600x1357.png 424w, https://substackcdn.com/image/fetch/$s_!v0AH!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61231358-4f6b-4ad1-a10e-a62cbd472977_1600x1357.png 848w, https://substackcdn.com/image/fetch/$s_!v0AH!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61231358-4f6b-4ad1-a10e-a62cbd472977_1600x1357.png 1272w, https://substackcdn.com/image/fetch/$s_!v0AH!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61231358-4f6b-4ad1-a10e-a62cbd472977_1600x1357.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!v0AH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61231358-4f6b-4ad1-a10e-a62cbd472977_1600x1357.png" width="1456" height="1235" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/61231358-4f6b-4ad1-a10e-a62cbd472977_1600x1357.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1235,&quot;width&quot;:1456,&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_!v0AH!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61231358-4f6b-4ad1-a10e-a62cbd472977_1600x1357.png 424w, https://substackcdn.com/image/fetch/$s_!v0AH!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61231358-4f6b-4ad1-a10e-a62cbd472977_1600x1357.png 848w, https://substackcdn.com/image/fetch/$s_!v0AH!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61231358-4f6b-4ad1-a10e-a62cbd472977_1600x1357.png 1272w, https://substackcdn.com/image/fetch/$s_!v0AH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61231358-4f6b-4ad1-a10e-a62cbd472977_1600x1357.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><strong>Critical frontend decision: Streaming</strong></h4><p>You have two options:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!G-uA!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7f3057f-6f0c-4a34-9220-9186fdd769dc_1600x423.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!G-uA!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7f3057f-6f0c-4a34-9220-9186fdd769dc_1600x423.png 424w, https://substackcdn.com/image/fetch/$s_!G-uA!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7f3057f-6f0c-4a34-9220-9186fdd769dc_1600x423.png 848w, https://substackcdn.com/image/fetch/$s_!G-uA!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7f3057f-6f0c-4a34-9220-9186fdd769dc_1600x423.png 1272w, https://substackcdn.com/image/fetch/$s_!G-uA!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7f3057f-6f0c-4a34-9220-9186fdd769dc_1600x423.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!G-uA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7f3057f-6f0c-4a34-9220-9186fdd769dc_1600x423.png" width="1456" height="385" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b7f3057f-6f0c-4a34-9220-9186fdd769dc_1600x423.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:385,&quot;width&quot;:1456,&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_!G-uA!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7f3057f-6f0c-4a34-9220-9186fdd769dc_1600x423.png 424w, https://substackcdn.com/image/fetch/$s_!G-uA!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7f3057f-6f0c-4a34-9220-9186fdd769dc_1600x423.png 848w, https://substackcdn.com/image/fetch/$s_!G-uA!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7f3057f-6f0c-4a34-9220-9186fdd769dc_1600x423.png 1272w, https://substackcdn.com/image/fetch/$s_!G-uA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7f3057f-6f0c-4a34-9220-9186fdd769dc_1600x423.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>Option 1: Wait for complete response</strong></p><ul><li><p>Simple HTTP POST, and get a full response back</p></li><li><p>User waits 10-30 seconds staring at the loading spinner</p></li><li><p>Poor UX, feels slow</p></li></ul><p><strong>Option 2: Stream word by word</strong></p><ul><li><p>Requires a persistent connection</p></li><li><p>User sees progress immediately</p></li><li><p>Much better UX</p></li></ul><p>ChatGPT, Claude, and Gemini all use streaming.</p><p>Let me verify the exact implementation.</p><h3><strong>How streaming actually works:</strong></h3><p>All major AI chat products use Server-Sent Events<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-3" href="#footnote-3" target="_self">3</a> (SSE), not WebSockets.</p><p>Let me explain why:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!LbdH!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fd901b6-e22c-4826-9f8e-e70e627e4251_1600x1321.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!LbdH!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fd901b6-e22c-4826-9f8e-e70e627e4251_1600x1321.png 424w, https://substackcdn.com/image/fetch/$s_!LbdH!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fd901b6-e22c-4826-9f8e-e70e627e4251_1600x1321.png 848w, https://substackcdn.com/image/fetch/$s_!LbdH!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fd901b6-e22c-4826-9f8e-e70e627e4251_1600x1321.png 1272w, https://substackcdn.com/image/fetch/$s_!LbdH!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fd901b6-e22c-4826-9f8e-e70e627e4251_1600x1321.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!LbdH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fd901b6-e22c-4826-9f8e-e70e627e4251_1600x1321.png" width="1456" height="1202" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8fd901b6-e22c-4826-9f8e-e70e627e4251_1600x1321.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1202,&quot;width&quot;:1456,&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_!LbdH!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fd901b6-e22c-4826-9f8e-e70e627e4251_1600x1321.png 424w, https://substackcdn.com/image/fetch/$s_!LbdH!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fd901b6-e22c-4826-9f8e-e70e627e4251_1600x1321.png 848w, https://substackcdn.com/image/fetch/$s_!LbdH!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fd901b6-e22c-4826-9f8e-e70e627e4251_1600x1321.png 1272w, https://substackcdn.com/image/fetch/$s_!LbdH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8fd901b6-e22c-4826-9f8e-e70e627e4251_1600x1321.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>SSE (what ChatGPT uses):</strong></p><ul><li><p>Works over standard HTTP</p></li><li><p>Browser has a built-in EventSource API</p></li><li><p>Auto-reconnection handled automatically</p></li><li><p>One-way communication (server to client)</p></li><li><p>Simpler to implement and debug</p></li><li><p>Lower overhead than WebSockets</p></li></ul><p><strong>WebSockets (what ChatGPT doesn&#8217;t use):</strong></p><ul><li><p>Requires protocol upgrade from HTTP</p></li><li><p>Bidirectional communication</p></li><li><p>More complex to implement</p></li><li><p>Useful for collaborative features, typing indicators</p></li><li><p>Overkill for just streaming AI responses</p></li></ul><p><strong>Example of SSE streaming:</strong></p><p>User types: <em>&#8220;Explain React hooks&#8221;.</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_!Lw0g!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f217e2e-f93a-425f-9c8a-d04f9e2f7389_1102x1600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Lw0g!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f217e2e-f93a-425f-9c8a-d04f9e2f7389_1102x1600.png 424w, https://substackcdn.com/image/fetch/$s_!Lw0g!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f217e2e-f93a-425f-9c8a-d04f9e2f7389_1102x1600.png 848w, https://substackcdn.com/image/fetch/$s_!Lw0g!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f217e2e-f93a-425f-9c8a-d04f9e2f7389_1102x1600.png 1272w, https://substackcdn.com/image/fetch/$s_!Lw0g!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f217e2e-f93a-425f-9c8a-d04f9e2f7389_1102x1600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Lw0g!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f217e2e-f93a-425f-9c8a-d04f9e2f7389_1102x1600.png" width="724" height="1051.179673321234" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4f217e2e-f93a-425f-9c8a-d04f9e2f7389_1102x1600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1600,&quot;width&quot;:1102,&quot;resizeWidth&quot;:724,&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_!Lw0g!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f217e2e-f93a-425f-9c8a-d04f9e2f7389_1102x1600.png 424w, https://substackcdn.com/image/fetch/$s_!Lw0g!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f217e2e-f93a-425f-9c8a-d04f9e2f7389_1102x1600.png 848w, https://substackcdn.com/image/fetch/$s_!Lw0g!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f217e2e-f93a-425f-9c8a-d04f9e2f7389_1102x1600.png 1272w, https://substackcdn.com/image/fetch/$s_!Lw0g!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f217e2e-f93a-425f-9c8a-d04f9e2f7389_1102x1600.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>Each word appears in the UI as it arrives, creating the typing effect.</p><h4><strong>Frontend tech stack:</strong></h4><ul><li><p>React for UI components</p></li><li><p>EventSource API for SSE connection</p></li><li><p>State management (Zustand or Redux) for conversations</p></li><li><p>Optimistic updates (show user message immediately)</p></li><li><p>Error handling for network failures, rate limits</p></li></ul><p>The frontend sets user expectations for real-time streaming.</p><p>Now, let&#8217;s formalize what our system must do.</p><div><hr></div><h2><strong>Functional Requirements</strong></h2><ul><li><p>User registration and authentication</p></li><li><p>Create and manage conversations</p></li><li><p>Send messages and receive streaming AI responses via SSE</p></li><li><p>Save all conversations with full history</p></li><li><p>Retrieve past conversations</p></li><li><p>Stream responses token<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-4" href="#footnote-4" target="_self">4</a> by token</p></li><li><p>Rate limiting (requests + tokens)</p></li><li><p>Content moderation for harmful requests</p></li></ul><p>We&#8217;ve defined what the system does. But how well must it perform?</p><p>These requirements will drive our architectural decisions.</p><h2><strong>Non-Functional Requirements</strong></h2><p>How well it must perform (we&#8217;ll connect these to design decisions later):</p><ul><li><p>Availability: 99.9%</p><ul><li><p>Max 43 minutes of downtime per month</p></li></ul></li><li><p>Latency: First token &lt; 2 seconds</p><ul><li><p>Users wait no more than 2 seconds</p></li></ul></li><li><p>Scalability: 200M DAU, 20M concurrent conversations</p><ul><li><p>Assuming 10% concurrency</p></li></ul></li><li><p>Consistency: Zero message loss</p><ul><li><p>Every message must be saved</p></li></ul></li><li><p>Cost efficiency</p><ul><li><p>LLM APIs are expensive and need optimization</p></li></ul></li><li><p>Security: End-to-end encryption</p><ul><li><p>Private conversations</p></li></ul></li></ul><p>We&#8217;ll show how our design achieves each of these.</p><p>We&#8217;ve set our performance targets. Now let&#8217;s run the numbers to see what infrastructure we actually need.</p><div><hr></div><h2><strong>Capacity and Storage Estimation</strong></h2><p>Math matters because it drives infrastructure decisions.</p><p>Let&#8217;s use ChatGPT&#8217;s actual scale of growth projections:</p><p><strong>Traffic:</strong></p><ul><li><p>1 billion weekly active users (WAU)</p><ul><li><p>The current sources show 800-900 million weekly active users.</p></li><li><p>To accommodate growth and simplify our calculations, let&#8217;s design for 1 billion weekly active users.</p></li></ul></li><li><p>~200 million daily active users (DAU)</p></li><li><p>2.5 billion prompts/messages per day</p><ul><li><p>ChatGPT&#8217;s actual processing volume</p></li></ul></li><li><p>12.5 messages per user per day average</p></li><li><p>Peak hours (20% of daily traffic in 2 hours)</p><ul><li><p>69,444 messages/second</p></li></ul></li><li><p>Concurrent conversations at peak: ~20 million</p><ul><li><p>Assuming 10% of DAU are chatting simultaneously</p></li></ul></li></ul><p><strong>Storage per conversation:</strong></p><ul><li><p>User message: 100 characters = 100 bytes</p></li><li><p>AI response: 500 characters = 500 bytes</p></li><li><p>Per exchange: 600 bytes</p></li><li><p>12.5 exchanges/day/user: 7.5 KB/user/day</p></li><li><p>200M DAU &#215; 7.5KB = 1.5TB/day</p></li><li><p>Annual: 548 TB/year</p></li></ul><p><strong>Metadata storage:</strong></p><ul><li><p>User profiles (1KB each): 1B &#215; 1KB = 1TB</p></li><li><p>Conversation metadata (500 bytes each, 10 per user average): 10B conversations &#215; 500B = 5TB</p></li></ul><p><strong>Total Year 1: ~554TB</strong> (need distributed database, single PostgreSQL won&#8217;t cut it)</p><p><strong>Connection overhead:</strong></p><ul><li><p>20M concurrent SSE connections at peak</p></li><li><p>Each connection: ~10-30 seconds average</p></li><li><p>Need infrastructure that can handle millions of long-lived connections</p></li></ul><p><strong>Bandwidth:</strong></p><ul><li><p>Average response: 750 bytes streamed over 20 seconds</p></li><li><p>20M concurrent: 20M &#215; 750B / 20s = 750 MB/s = 6 Gbps</p></li><li><p>Peak outbound bandwidth requirement</p></li></ul><p><strong>Key insight:</strong> At ChatGPT&#8217;s scale, single-server solutions don&#8217;t work. We need distributed systems, sharding, and multi-region deployment from day one.</p><p>Now that we know the scale we&#8217;re dealing with, let&#8217;s design the actual system that can handle it.</p><div><hr></div><h2><strong>High-Level System Design</strong></h2><p>Before diving into costs and implementation details, let&#8217;s map out the complete system architecture.</p><p>OpenAI uses a multi-cloud setup to secure enough compute power and avoid relying on a single vendor:</p><ul><li><p><strong>Microsoft Azure:</strong> Still their leading provider. They have a massive, long-term partnership in which Microsoft builds specialized supercomputers for training OpenAI&#8217;s models.</p></li><li><p><strong>AWS:</strong> OpenAI signed a $38 billion deal with Amazon in late 2025. They now run significant workloads on AWS&#8217;s GPU clusters and specialized AI hardware.</p></li><li><p><strong>Google Cloud (GCP):</strong> As of mid-2025, OpenAI uses GCP to power parts of ChatGPT Enterprise and the Team tiers, as well as their API.</p></li><li><p><strong>Oracle:</strong> They have a multi-billion dollar agreement to use Oracle&#8217;s data center capacity, specifically for the massive &#8220;Stargate&#8221; infrastructure project.</p></li><li><p><strong>CoreWeave:</strong> They also use this specialized &#8220;neocloud&#8221; provider for dedicated access to high-performance NVIDIA GPUs.</p></li></ul><h3><strong>Components Overview</strong></h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!DEzf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a38f62a-6e58-41fc-a140-1c1c04654d25_1600x690.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!DEzf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a38f62a-6e58-41fc-a140-1c1c04654d25_1600x690.png 424w, https://substackcdn.com/image/fetch/$s_!DEzf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a38f62a-6e58-41fc-a140-1c1c04654d25_1600x690.png 848w, https://substackcdn.com/image/fetch/$s_!DEzf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a38f62a-6e58-41fc-a140-1c1c04654d25_1600x690.png 1272w, https://substackcdn.com/image/fetch/$s_!DEzf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a38f62a-6e58-41fc-a140-1c1c04654d25_1600x690.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!DEzf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a38f62a-6e58-41fc-a140-1c1c04654d25_1600x690.png" width="1456" height="628" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1a38f62a-6e58-41fc-a140-1c1c04654d25_1600x690.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:628,&quot;width&quot;:1456,&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_!DEzf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a38f62a-6e58-41fc-a140-1c1c04654d25_1600x690.png 424w, https://substackcdn.com/image/fetch/$s_!DEzf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a38f62a-6e58-41fc-a140-1c1c04654d25_1600x690.png 848w, https://substackcdn.com/image/fetch/$s_!DEzf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a38f62a-6e58-41fc-a140-1c1c04654d25_1600x690.png 1272w, https://substackcdn.com/image/fetch/$s_!DEzf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a38f62a-6e58-41fc-a140-1c1c04654d25_1600x690.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 system has three main layers:</p><ol><li><p>Client Layer</p><ul><li><p>React web application</p></li><li><p>Mobile apps (iOS/Android)</p></li><li><p>SSE connections for real-time streaming</p></li></ul></li></ol><ol start="2"><li><p>Service Layer (Microservices<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-5" href="#footnote-5" target="_self">5</a>)</p><ul><li><p>API Gateway: Entry point, SSL termination, request routing</p></li><li><p>Auth Service: JWT<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-6" href="#footnote-6" target="_self">6</a> authentication, user session management</p></li><li><p>Message Service: Core orchestrator for message processing and streaming</p></li><li><p>Conversation Service: CRUD operations for conversations and message history</p></li><li><p>Rate Limiter Service: Track and enforce request/token limits per user</p></li><li><p>Moderation Service: Content filtering for harmful requests</p></li><li><p>LLM Gateway Service: Routes requests to GPU clusters, handles streaming responses</p></li></ul></li></ol><ul><li><p><em>Why this order?</em></p><ul><li><p>Load Balancer is &#8220;dumb&#8221; - it just distributes TCP/HTTP connections across servers.</p></li><li><p>API Gateway is &#8220;smart&#8221; - reads the URL path and routes: <code>/auth/*</code> &#8594; Auth Service, <code>/conversations/* </code>&#8594; Conversation Service, etc.</p></li></ul></li></ul><ol start="3"><li><p>Data Layer</p><ul><li><p>PostgreSQL: Single primary + 20 read replicas<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-7" href="#footnote-7" target="_self">7</a> (user data, conversations, messages)</p></li><li><p>Redis<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-8" href="#footnote-8" target="_self">8</a> Cluster: Rate limiting state, conversation history cache, response cache</p></li><li><p>GPU Cluster: 17,500 H100<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-9" href="#footnote-9" target="_self">9</a> GPUs for model inference</p></li><li><p>Azure Blob Storage: Long-term archive for old conversations</p></li></ul></li></ol><h4><strong>How Does the User Receive the Response?</strong></h4><p>The response flows back through the SAME connection path, reversed:</p><ul><li><p>The HTTP connection stays open from:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;plaintext&quot;,&quot;nodeId&quot;:&quot;f8e55f7f-bc55-485a-9fa6-113aef0c44ab&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-plaintext"> Browser &#8594; Load Balancer &#8594; API Gateway &#8594; Message Service</code></pre></div></li><li><p>Message Service writes tokens to the response stream</p></li><li><p>Each token flows backward:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;plaintext&quot;,&quot;nodeId&quot;:&quot;88ebc8e3-65fe-418a-869a-50a9bbff9379&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-plaintext">Message Service &#8594; API Gateway &#8594; Load Balancer &#8594; Browser</code></pre></div></li><li><p>Browser&#8217;s EventSource API receives each event in real-time</p></li><li><p>Connection closes when streaming completes</p></li></ul><p>Think of it like a phone call:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;plaintext&quot;,&quot;nodeId&quot;:&quot;6df3e375-83fe-457d-8e3d-7b009eb68ba1&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-plaintext">You call (request) &#8594; they answer and KEEP TALKING for 20 seconds (streaming) &#8594; then hang up.</code></pre></div><p>Same connection, just stays open longer.</p><h3><strong>Key Architectural Decisions</strong></h3><p><strong>Single Primary PostgreSQL (not sharded)</strong></p><ul><li><p>Why: ChatGPT&#8217;s workload is 90% reads, 10% writes</p></li><li><p>OpenAI&#8217;s proven architecture: handles 800M users without sharding</p></li><li><p>Writes: All go through a single primary instance</p></li><li><p>Reads: Distributed across 20+ replicas in 6 regions</p></li><li><p>Trade-off: Single writer bottleneck, but application simplicity wins</p></li></ul><p><em><strong>Why reads dominate despite 2.5B prompts/day</strong></em></p><p>Think about what happens per user prompt:</p><ul><li><p>Load user account</p></li><li><p>Load subscription/quota info</p></li><li><p>Load conversation metadata</p></li><li><p>Load recent messages for context</p></li><li><p>Check rate limits</p></li><li><p>Maybe load feature flags, experiments, and so on.</p></li></ul><p>Those are all <em>reads</em>.</p><p>Writes usually happens only when:</p><ul><li><p>A new message is stored</p></li><li><p>Conversation metadata is updated</p></li><li><p>Usage counters are incremented</p></li><li><p>Logs are persisted</p></li></ul><p>So one prompt can trigger many reads, but only a few writes.</p><p><strong>Microservices Architecture</strong></p><ul><li><p>Why: Independent scaling and deployment</p></li><li><p>Each service scales independently based on its load</p></li><li><p>LLM Gateway can scale GPU clusters without touching other services</p></li><li><p>Rate Limiter needs different scaling than Conversation Service</p></li><li><p>Trade-off: Operational complexity vs scaling flexibility</p></li></ul><p><strong>SSE for Streaming (not WebSockets)</strong></p><ul><li><p>Why: Simpler, one-way communication is sufficient</p></li><li><p>Browser has a built-in EventSource API with auto-reconnection</p></li><li><p>Lower overhead than WebSockets</p></li><li><p>Most AI products (ChatGPT, Claude, Gemini) use SSE</p></li><li><p>Trade-off: Can&#8217;t do bidirectional communication (acceptable for chat)</p></li></ul><p><strong>Self-Hosted GPU Infrastructure</strong></p><ul><li><p>Why: At 2.5B messages/day, API costs would be $159M/month</p></li><li><p>Self-hosting: $52.4M/month (67% cheaper)</p></li><li><p>Requires: 17,500 H100 GPUs across multiple cloud providers</p></li><li><p>Trade-off: $525M upfront cost vs ongoing API expenses</p></li></ul><p><strong>Multi-Region Deployment</strong></p><ul><li><p>6 regions: 2 Americas, 2 Europe, 2 Asia-Pacific</p></li><li><p>Why: Global low-latency (users connect to the nearest region)</p></li><li><p>Each region has a full application stack + read replicas</p></li><li><p>GPU clusters are centralized in 3-4 major data centers</p></li><li><p>Trade-off: Operational complexity vs user experience</p></li></ul><p>We've mapped out the architecture.</p><p>The interesting part comes next: how much this actually costs to run, why OpenAI made the controversial choice to not shard their database, and what changes at 500M and 1B users.</p><p>First, let's trace a message from the send button to the AI response&#8230;</p>
      <p>
          <a href="https://newsletter.systemdesign.one/p/chatgpt-system-design">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[System Design Interview: Design Web Crawler and Search Engine]]></title><description><![CDATA[#124: System Design Interview]]></description><link>https://newsletter.systemdesign.one/p/web-crawler-system-design</link><guid isPermaLink="false">https://newsletter.systemdesign.one/p/web-crawler-system-design</guid><dc:creator><![CDATA[Neo Kim]]></dc:creator><pubDate>Sat, 21 Feb 2026 11:45:16 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/b92c2e4c-68dd-4314-a663-9d2eadd1f51b_1280x720.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/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">Get my system design playbook for FREE on newsletter signup:</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><ul><li><p><em><a href="https://newsletter.systemdesign.one/p/web-crawler-system-design/?action=share">Share this post</a> &amp; I&#8217;ll send you some rewards for the referrals.</em></p></li></ul><div><hr></div><p>You type something in the Google Search bar and get instant results.</p><p><em>How does this work?</em></p><p>Today&#8217;s newsletter will teach you the architecture of search systems.</p><p>At a high level, a search system has two components: <strong>a web crawler and a search engine.</strong></p><ul><li><p>A web crawler crawls webpages and stores them in a datastore.</p></li><li><p>A search engine looks through the data in the datastore to answer user search queries.</p></li></ul><p>Let&#8217;s start by understanding the system requirements&#8230;</p><div><hr></div><h3><a href="https://serpapi.com/?utm_source=thesystemdesignnewsletter">Need public web data, without scraper headaches? (Partner)</a></h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://serpapi.com/?utm_source=thesystemdesignnewsletter" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Hdlc!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56bb41d0-a9df-40dd-9253-e67c930cc2ad_1200x1171.jpeg 424w, https://substackcdn.com/image/fetch/$s_!Hdlc!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56bb41d0-a9df-40dd-9253-e67c930cc2ad_1200x1171.jpeg 848w, https://substackcdn.com/image/fetch/$s_!Hdlc!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56bb41d0-a9df-40dd-9253-e67c930cc2ad_1200x1171.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!Hdlc!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56bb41d0-a9df-40dd-9253-e67c930cc2ad_1200x1171.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Hdlc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56bb41d0-a9df-40dd-9253-e67c930cc2ad_1200x1171.jpeg" width="1200" height="1171" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/56bb41d0-a9df-40dd-9253-e67c930cc2ad_1200x1171.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1171,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:182785,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/jpeg&quot;,&quot;href&quot;:&quot;https://serpapi.com/?utm_source=thesystemdesignnewsletter&quot;,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/180977546?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56bb41d0-a9df-40dd-9253-e67c930cc2ad_1200x1171.jpeg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!Hdlc!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56bb41d0-a9df-40dd-9253-e67c930cc2ad_1200x1171.jpeg 424w, https://substackcdn.com/image/fetch/$s_!Hdlc!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56bb41d0-a9df-40dd-9253-e67c930cc2ad_1200x1171.jpeg 848w, https://substackcdn.com/image/fetch/$s_!Hdlc!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56bb41d0-a9df-40dd-9253-e67c930cc2ad_1200x1171.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!Hdlc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56bb41d0-a9df-40dd-9253-e67c930cc2ad_1200x1171.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong><a href="https://serpapi.com/?utm_source=thesystemdesignnewsletter">SerpApi</a></strong> turns search results into predictable JSON with built-in scale, location options, and protection from blocks.</p><p>That&#8217;s why engineers use it to ship:</p><ul><li><p>AI applications</p></li><li><p>Product research</p></li><li><p>Price tracking</p></li><li><p>SEO insights</p></li></ul><p>All without maintaining scrapers or infrastructure.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://serpapi.com/?utm_source=thesystemdesignnewsletter&quot;,&quot;text&quot;:&quot;Try For Free&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://serpapi.com/?utm_source=thesystemdesignnewsletter"><span>Try For Free</span></a></p><p>(I&#8217;d like to thank <a href="https://serpapi.com/?utm_source=thesystemdesignnewsletter">SerpApi</a> for partnering on this post.)</p><div><hr></div><p>I want to introduce <a href="https://www.linkedin.com/in/msdeep14/">Mandeep Singh</a> as a guest author.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://www.linkedin.com/in/msdeep14/" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!zk2R!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F30a90939-45e0-47ae-ad1d-8d2ad0b3ce61_1584x396.png 424w, https://substackcdn.com/image/fetch/$s_!zk2R!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F30a90939-45e0-47ae-ad1d-8d2ad0b3ce61_1584x396.png 848w, https://substackcdn.com/image/fetch/$s_!zk2R!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F30a90939-45e0-47ae-ad1d-8d2ad0b3ce61_1584x396.png 1272w, https://substackcdn.com/image/fetch/$s_!zk2R!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F30a90939-45e0-47ae-ad1d-8d2ad0b3ce61_1584x396.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!zk2R!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F30a90939-45e0-47ae-ad1d-8d2ad0b3ce61_1584x396.png" width="1456" height="364" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/30a90939-45e0-47ae-ad1d-8d2ad0b3ce61_1584x396.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:364,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1102236,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:&quot;https://www.linkedin.com/in/msdeep14/&quot;,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/188371881?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F30a90939-45e0-47ae-ad1d-8d2ad0b3ce61_1584x396.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_!zk2R!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F30a90939-45e0-47ae-ad1d-8d2ad0b3ce61_1584x396.png 424w, https://substackcdn.com/image/fetch/$s_!zk2R!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F30a90939-45e0-47ae-ad1d-8d2ad0b3ce61_1584x396.png 848w, https://substackcdn.com/image/fetch/$s_!zk2R!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F30a90939-45e0-47ae-ad1d-8d2ad0b3ce61_1584x396.png 1272w, https://substackcdn.com/image/fetch/$s_!zk2R!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F30a90939-45e0-47ae-ad1d-8d2ad0b3ce61_1584x396.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>He&#8217;s an author, educator, and software engineer with a strong passion for building simple, scalable systems. He authored the O'Reilly book "System Design on AWS" and supports others' learning and development by sharing lessons on Cloud and System Design on <a href="https://www.youtube.com/@MsDeepSingh">YouTube</a>.</p><p>Checkout his work:</p><ul><li><p><a href="https://oreil.ly/ruQbc">System Design on AWS Book</a> (Also find on <a href="https://amzn.to/3D3BIBJ">Amazon</a>)</p></li><li><p><a href="https://www.linkedin.com/in/msdeep14/">LinkedIn</a></p></li><li><p><a href="https://x.com/msdeep14">X</a></p></li><li><p><a href="https://discord.gg/98zTnzvGz2">Discord Server</a></p></li></ul><div><hr></div><h1>System Requirements</h1><p><em>(There are two kinds of requirements: functional and non-functional.)</em></p><p>Functional requirements are functionalities from the user's perspective.</p><p>It includes:</p><ul><li><p>Fetching top results for a search query.</p></li><li><p>Including the web page URL, title, and subtitle in each result.</p></li><li><p>Avoiding outdated results.</p></li></ul><p>Search systems are large and support many functionalities. So let&#8217;s limit the scope:</p><ul><li><p>Queries can only be done in English.</p></li><li><p>Exclude what, why, and how of machine learning components.</p></li></ul><p>The system must follow certain constraints to maintain quality. These are called non-functional requirements (<strong>NFRs</strong>).</p><p>Key NFRs include:</p><ul><li><p>Availability: System must be up and able to respond to search requests.</p></li><li><p>Reliability: System must return correct and consistent results.</p></li><li><p>Scalability: User traffic grows over time, so does the content on the internet. The system must handle this growth without performance issues.</p></li><li><p>Low Latency: Search results should be returned in milliseconds.</p></li></ul><p>These requirements guide the system design. Another important factor is the expected scale, which directly affects design decisions.</p><p>Let&#8217;s estimate the system scale next&#8230;</p><div><hr></div><h1>Back of the Envelope: Understanding Scale</h1><p>In system design interviews, it&#8217;s recommended to make some assumptions after discussion with the interviewer.</p><p>Here are some estimations:</p><h4>Web crawler</h4><p>The scale of a web crawler depends on how many pages it crawls.</p><p>Assume:</p><ul><li><p>Active websites: 200 million</p></li><li><p>Average pages per website: 50</p></li></ul><p>Now, for each website, there can be both internal and external redirects. The external redirects are part of 200 million.</p><p>Then, for internal redirects:</p><ul><li><p>Total pages = 200 million &#215; 50 = 10 billion pages</p></li></ul><p>Now estimate storage:</p><ul><li><p>Average page size: 2 MB</p></li><li><p>Total storage = 10 billion &#215; 2 MB = 20 PB</p></li></ul><p>NOTE: Web pages can include text, images, and videos. In practice, a crawler may store only the parts needed for search. This estimate assumes we store pages as-is, in the same format in which we download them.</p><p>Let&#8217;s look into the scale of the search engine system next&#8230;</p><h4>Search engine</h4><p>Assume Google scale traffic:</p><ul><li><p>Searches per day: 8.5 billion</p></li><li><p>Searches per second: ~100,000</p></li></ul><p>These rough numbers help shape the design choices.</p><p>Next, we&#8217;ll dive into the high-level system design&#8230;</p><div><hr></div><h1>High-Level System Design</h1><p>We&#8217;ll design a scalable system and discuss the key components of each subsystem separately. Keep in mind that Google has evolved significantly to support this scale, and it is not possible to capture all details in this post.</p><p>We&#8217;ll first design the web crawler, and then move on to the search engine:</p><h2>Web Crawler</h2><p>The crawler needs an initial list of URLs to start with. These are called <strong>seed URLs</strong>.</p><p>There is no single source that contains all websites. So we start with well-known domains and discover new URLs as we crawl.</p><p>Here are several ways to discover new website URLs:</p><ul><li><p>Create a platform for new website owners to submit their site details.</p></li><li><p>Retrieve the list of website links from the website being crawled.</p></li><li><p>New website URL queried by the user.</p></li></ul><p>The crawler does not visit every website at the same rate. Some sites change frequently, while others rarely update.</p><p>The process of deciding how often to visit a website is called <strong>crawl scheduling (politeness)</strong>. The component that decides which URL to crawl next is called the <strong>URL frontier</strong>.</p><h3>1. URL Frontier Design</h3><p>The design shown in Figure 1 is inspired by the <a href="https://www.cs.cornell.edu/courses/cs685/2002fa/mercator.pdf">Mercator</a> crawler. It uses a two-stage queue system to handle both priority and politeness.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!QNO0!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf2b6846-6131-48bf-b7ef-c70476f96d02_817x362.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!QNO0!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf2b6846-6131-48bf-b7ef-c70476f96d02_817x362.png 424w, https://substackcdn.com/image/fetch/$s_!QNO0!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf2b6846-6131-48bf-b7ef-c70476f96d02_817x362.png 848w, https://substackcdn.com/image/fetch/$s_!QNO0!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf2b6846-6131-48bf-b7ef-c70476f96d02_817x362.png 1272w, https://substackcdn.com/image/fetch/$s_!QNO0!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf2b6846-6131-48bf-b7ef-c70476f96d02_817x362.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!QNO0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf2b6846-6131-48bf-b7ef-c70476f96d02_817x362.png" width="817" height="362" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/af2b6846-6131-48bf-b7ef-c70476f96d02_817x362.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:362,&quot;width&quot;:817,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!QNO0!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf2b6846-6131-48bf-b7ef-c70476f96d02_817x362.png 424w, https://substackcdn.com/image/fetch/$s_!QNO0!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf2b6846-6131-48bf-b7ef-c70476f96d02_817x362.png 848w, https://substackcdn.com/image/fetch/$s_!QNO0!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf2b6846-6131-48bf-b7ef-c70476f96d02_817x362.png 1272w, https://substackcdn.com/image/fetch/$s_!QNO0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf2b6846-6131-48bf-b7ef-c70476f96d02_817x362.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">Figure 1. URL Frontier Architecture</figcaption></figure></div><p>Here&#8217;s the architecture overview:</p><ul><li><p>Front queues represent different priority levels. The prioritizer assigns a priority (for example, 1 to n) to each URL. Based on this value, the URL gets placed into a specific front queue. The front queue selector picks URLs using a weighted round-robin approach, so higher-priority URLs get chosen more often.</p></li><li><p>From the front queues, URLs move to the back queues. A domain-to-back-queue database ensures that all URLs from the same host (for example, example.com) go to the same back queue. This helps enforce politeness rules per host.</p></li><li><p>A priority queue (implemented as a min-heap) keeps track of when each host can be contacted again. There is one entry per back queue. The heap stores the next allowed fetch time for that host/domain.</p></li><li><p>The back queue selector removes the host with the earliest allowed time from the heap. It then fetches one URL from that host&#8217;s back queue. After the URL gets crawled, the system updates the heap with the next allowed fetch time according to politeness rules.</p></li></ul><p>While Mercator provides a strong foundation, there can be bottlenecks at internet scale:</p><ul><li><p>FIFO queues keep a fixed number of URLs in memory and store most URLs on disk to support a high crawl rate on commodity hardware. At a large scale, frequent disk reads and writes can become a bottleneck. More advanced disk-based algorithms (such as those discussed in <a href="https://irl.cs.tamu.edu/people/hsin-tsang/papers/www2008.pdf">IRLBot research paper</a>) can help reduce this overhead.</p></li><li><p>Another issue is static priority and politeness logic. If a website becomes slow or starts returning errors, the crawler should adjust its crawl rate dynamically. Instead of fixed rules, the system should use adaptive politeness. HTTP response code could be an important factor in this decision.</p><p>For example:</p><ul><li><p>HTTP 200: Crawl at normal rate.</p></li><li><p>HTTP 429: Reduce crawl rate and retry later.</p></li><li><p>HTTP 500: Retry only after a longer cooldown.</p></li></ul></li><li><p>Many domains could share the same IP address (shared hosting, CDNs, cloud providers). Using a single back queue per host can cause skew or a hotspot. The solution is to enforce limits at both the host and IP levels.</p><p>For example:</p><ul><li><p><code>hello.com</code> can be crawled once every 10 seconds.</p></li><li><p>IP <code>192.168.1.2</code> can be crawled up to 5 times per second across all domains hosted on that IP.</p></li></ul></li></ul><p>URL frontier acts on a continuous feedback loop. URL fetcher (Figure 2) reports metrics such as latency and error rate. URL frontier adjusts crawl rate and priority based on these signals.</p><p>For example:</p><ul><li><p>If a website responds slowly, increase politeness (reduce crawl rate).</p></li><li><p>If there are repeated 500 errors, lower the website&#8217;s priority.</p></li></ul><p>Once URL frontier selects a URL, the crawler visits the page. Before crawling, the system should check whether the page has already been fetched or modified. There is no benefit in fetching the same content repeatedly.</p><p>Next, let&#8217;s discuss URL duplication and content duplication handling...</p><h3>2. Web Page Similarity and URL Duplication</h3><p>A web crawler can run into infinite loops. This can happen if:</p><ul><li><p>A page links to itself.</p></li><li><p>The same URL appears many times in different places.</p></li><li><p>URLs are generated dynamically in large numbers.</p></li></ul><p>To prevent this, the crawler must detect duplicate URLs before crawling them.</p><h4>URL Deduplication</h4><p>How do we check if a URL was crawled?</p><p>One approach is to store all crawled URLs in a global lookup table (HashMap). As many crawler instances run in parallel, this lookup must be shared across machines. A distributed key-value database can be used for this purpose.</p><p>This lookup needs to be fast.</p><p>Disk-based databases increase latency because of disk reads. An in-memory system is faster but must handle very large amounts of data. The data can be partitioned (sharded) across many machines to scale.</p><p>We can use a Bloom filter to reduce memory usage.</p><p>A Bloom filter is a space-efficient data structure that checks whether an element already exists in a set. It&#8217;s probabilistic, that is:</p><ul><li><p>If it says &#8220;<em>no</em>,&#8221; the URL definitely has not been seen.</p></li><li><p>If it says &#8220;<em>yes</em>,&#8221; the URL <em>might</em> have been seen.</p></li></ul><p>This can sometimes cause a new URL to be skipped, but for large-scale crawling, this tradeoff is acceptable.</p><p>The URL set can be distributed across machines using consistent hashing. This ensures even distribution and supports adding or removing servers without major reshuffling.</p><p>Now let&#8217;s focus on content duplication&#8230;</p><h4>Content Deduplication</h4><p>Even if URLs are different, page content might be the same.</p><p>A simple word-by-word comparison is expensive and inefficient. Instead, crawlers compute a fingerprint of the page content. One common technique is <a href="https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/33026.pdf">Simhash algorithm</a>, which generates a compact representation of the page.</p><p>Similar pages will have similar fingerprints, making duplicate detection efficient.</p><h4>Handling Intentional Duplicates</h4><p>Some websites intentionally publish the same content under different URLs.</p><p>Search engines support a <a href="https://en.wikipedia.org/wiki/Canonical_link_element">canonical link element</a> to handle this scenario. Website owners can specify the preferred URL for a piece of content. The crawler stores only the canonical version for indexing.</p><p>The bottom line:</p><ul><li><p>URL deduplication occurs before crawling.</p></li><li><p>Content deduplication occurs after fetching the page.</p></li></ul><h4>Robots and Exclusions</h4><p>Before crawling, the system must check whether the URL is allowed.</p><p>Web servers can define rules in the robots.txt file to control crawler access. The crawler must respect these rules. Also, the crawler may maintain its own blocklist for certain websites or regions.</p><p>After passing these checks and finishing the crawl, the system stores the page content.</p><p>Next, let&#8217;s discuss storage design&#8230;</p><h3>3. Web Crawler Storage</h3><p>The choice of database depends on what we want to store and what format.</p><p>Here are a few options:</p><ol><li><p>Store the entire webpage as-is</p><ul><li><p>This is like saving a webpage using &#8220;Save Page As&#8221; in a browser. The full HTML content is stored without modification.</p></li></ul></li><li><p>Extract and store only the required data</p><ul><li><p>The crawler processes the page and saves only useful parts, such as text and metadata.</p></li></ul></li><li><p>Store the page in a document database</p><ul><li><p>Since a webpage is essentially a document, it can be stored in a document database.</p></li></ul></li></ol><p>In our case, the data has no fixed structure, and we do not need to run complex queries on it. So the simplest approach is to store the entire webpage.</p><p>An object store, such as Amazon S3, is a good fit for this.</p><p>Object stores are scalable and highly durable, so we don&#8217;t have to worry about scalability and reliability. At a very large scale, some companies build and manage their own distributed storage systems, but that is a separate and complex topic.</p><p>NOTE: <a href="https://cloud.google.com/blog/products/storage-data-transfer/a-peek-behind-colossus-googles-file-system">Colossus</a> is Google&#8217;s distributed storage system. It replaced Google File System (<strong>GFS</strong>) and is designed to support Google&#8217;s massive scale.</p><h4>Metadata Storage</h4><p>We also need to store metadata. It includes:</p><ul><li><p>URL</p></li><li><p>Location of stored content</p></li><li><p>Last crawled time</p></li><li><p>Status or crawl result</p></li></ul><p>This requires a key-value style database, where:</p><ul><li><p>Key = URL</p></li><li><p>Value = Metadata</p></li></ul><p>A relational database could also work, but since we do not need complex joins or relationships, a distributed key-value store is more suitable. The data should be partitioned (sharded) for scale.</p><p>Now that we have covered the main crawler components, let&#8217;s discuss how these components work together to crawl the web&#8230;</p><h3>4. Web Crawler Components Coordination</h3><p>There are a few ways to coordinate the crawler components. Each option has its tradeoffs:</p><h4>Approach #1: Synchronous communication</h4><p>Each component exposes an API and calls the next component directly. If different components run inside the same service (microservice), they can call each other via local method calls.</p><h4>Approach #2: Choreography</h4><p>Each component publishes an event when it finishes its work. The next component consumes the event and continues the workflow. This is also known as event-driven architecture.</p><h4>Approach #3: Orchestration</h4><p>Add an orchestrator to manage the crawler&#8217;s lifecycle. The orchestrator triggers each step, tracks progress, and handles retries. Components can still communicate synchronously or asynchronously, depending on what fits.</p><p><em>&#8230;So which approach fits best here?</em></p><p>You might have heard the statement: <em>&#8220;</em>Everything is a tradeoff in system design.&#8221; This is very true: all approaches are best in one scenario but can be the worst in others.</p><p>Let&#8217;s do a trade-off analysis for the web crawler 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_!WiZW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9ac2f8b-c9bd-41ab-9f9a-30fb3c7c9643_1298x768.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!WiZW!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9ac2f8b-c9bd-41ab-9f9a-30fb3c7c9643_1298x768.png 424w, https://substackcdn.com/image/fetch/$s_!WiZW!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9ac2f8b-c9bd-41ab-9f9a-30fb3c7c9643_1298x768.png 848w, https://substackcdn.com/image/fetch/$s_!WiZW!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9ac2f8b-c9bd-41ab-9f9a-30fb3c7c9643_1298x768.png 1272w, https://substackcdn.com/image/fetch/$s_!WiZW!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9ac2f8b-c9bd-41ab-9f9a-30fb3c7c9643_1298x768.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!WiZW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9ac2f8b-c9bd-41ab-9f9a-30fb3c7c9643_1298x768.png" width="1298" height="768" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f9ac2f8b-c9bd-41ab-9f9a-30fb3c7c9643_1298x768.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:768,&quot;width&quot;:1298,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!WiZW!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9ac2f8b-c9bd-41ab-9f9a-30fb3c7c9643_1298x768.png 424w, https://substackcdn.com/image/fetch/$s_!WiZW!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9ac2f8b-c9bd-41ab-9f9a-30fb3c7c9643_1298x768.png 848w, https://substackcdn.com/image/fetch/$s_!WiZW!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9ac2f8b-c9bd-41ab-9f9a-30fb3c7c9643_1298x768.png 1272w, https://substackcdn.com/image/fetch/$s_!WiZW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9ac2f8b-c9bd-41ab-9f9a-30fb3c7c9643_1298x768.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">Figure 2. Web Crawler Orchestration Approaches</figcaption></figure></div><p>For the crawler, Approach #3 (Orchestration) makes more sense. Here&#8217;s why:</p><ul><li><p>End-to-end monitoring: You can track, retry, or debug each component.</p></li><li><p>Failure handling: If a component is unhealthy, the orchestrator can trigger a retry, pause, or reroute work.</p></li><li><p>Scheduling support: Orchestrator can schedule recrawls and also handle new URLs discovered during crawling.</p></li></ul><p>Next, let&#8217;s combine these components and create a high-level diagram&#8230;</p><h3>5. Web Crawler System Components</h3><p>Figure 3 shows the end-to-end workflow.</p><p>The blocks in the diagram are logical components, not separate microservices. You can deploy them together or separately, depending on scale, cost, and operational needs.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!nKmH!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf4e560d-cf34-4434-a45e-c08c4bbc14bf_781x371.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!nKmH!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf4e560d-cf34-4434-a45e-c08c4bbc14bf_781x371.png 424w, https://substackcdn.com/image/fetch/$s_!nKmH!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf4e560d-cf34-4434-a45e-c08c4bbc14bf_781x371.png 848w, https://substackcdn.com/image/fetch/$s_!nKmH!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf4e560d-cf34-4434-a45e-c08c4bbc14bf_781x371.png 1272w, https://substackcdn.com/image/fetch/$s_!nKmH!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf4e560d-cf34-4434-a45e-c08c4bbc14bf_781x371.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!nKmH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf4e560d-cf34-4434-a45e-c08c4bbc14bf_781x371.png" width="781" height="371" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cf4e560d-cf34-4434-a45e-c08c4bbc14bf_781x371.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:371,&quot;width&quot;:781,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!nKmH!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf4e560d-cf34-4434-a45e-c08c4bbc14bf_781x371.png 424w, https://substackcdn.com/image/fetch/$s_!nKmH!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf4e560d-cf34-4434-a45e-c08c4bbc14bf_781x371.png 848w, https://substackcdn.com/image/fetch/$s_!nKmH!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf4e560d-cf34-4434-a45e-c08c4bbc14bf_781x371.png 1272w, https://substackcdn.com/image/fetch/$s_!nKmH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf4e560d-cf34-4434-a45e-c08c4bbc14bf_781x371.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">Figure 3. Web Crawler System Design</figcaption></figure></div><p>Let&#8217;s summarize all the components and workflow:</p><ol><li><p>URL Frontier</p><ul><li><p>Starts with seed URLs and outputs the next URLs to crawl.</p></li></ul></li><li><p>URL goes through certain validations, such as:</p><ul><li><p>URL uniqueness (have we seen this URL before?)</p></li><li><p>Verification in robots.txt cache (is crawling allowed?)</p></li><li><p>Fetch IP address from DNS cache. This cache is continuously updated once the URL is fetched from the internet.</p></li></ul></li><li><p>Webpage Fetcher System</p><ul><li><p>Downloads the page content and stores it in the content database.</p></li><li><p>Some pages load content in multiple steps using JavaScript. For this, fetcher may need a headless browser to render the page and get the final content.</p></li><li><p>To save bandwidth, the system can cache shared resources, such as common JavaScript and CSS files, instead of downloading them repeatedly.</p></li></ul></li><li><p>Webpage Processing System</p><ul><li><p>Parses the downloaded page to extract new links. Then it filters these links using rules such as:</p><ul><li><p>Blocklists</p></li><li><p>URL patterns</p></li><li><p>Region-based restrictions</p></li></ul></li></ul></li><li><p>Feedback loop</p><ul><li><p>The extracted URLs are then sent back to the URL frontier, and the crawl cycle continues.</p></li></ul></li></ol><p>NOTE: A Domain Name System (<strong>DNS</strong>) handles mapping between domain names (such as <code>google.com</code>) to their IP addresses. </p><p>Web crawler&#8217;s job finishes as soon as the web page is downloaded and stored. Search engine then takes this content, builds indexes, and serves user queries.</p><p>Next, let&#8217;s explore the architecture of the search engine system&#8230;</p><div><hr></div><blockquote><p><em><strong>This newsletter is inspired by Chapter 15 of the O&#8217;Reilly book &#8220;<a href="https://msdeepsingh.com/books/">System Design on AWS</a>&#8221;. Get a copy of the book right now.</strong></em></p></blockquote><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Onlo!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8e811b7-9ae4-42aa-8690-ab775f7d5058_2218x1402.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Onlo!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8e811b7-9ae4-42aa-8690-ab775f7d5058_2218x1402.png 424w, https://substackcdn.com/image/fetch/$s_!Onlo!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8e811b7-9ae4-42aa-8690-ab775f7d5058_2218x1402.png 848w, https://substackcdn.com/image/fetch/$s_!Onlo!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8e811b7-9ae4-42aa-8690-ab775f7d5058_2218x1402.png 1272w, https://substackcdn.com/image/fetch/$s_!Onlo!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8e811b7-9ae4-42aa-8690-ab775f7d5058_2218x1402.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Onlo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8e811b7-9ae4-42aa-8690-ab775f7d5058_2218x1402.png" width="1456" height="920" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b8e811b7-9ae4-42aa-8690-ab775f7d5058_2218x1402.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:920,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1732564,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/188371881?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8e811b7-9ae4-42aa-8690-ab775f7d5058_2218x1402.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_!Onlo!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8e811b7-9ae4-42aa-8690-ab775f7d5058_2218x1402.png 424w, https://substackcdn.com/image/fetch/$s_!Onlo!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8e811b7-9ae4-42aa-8690-ab775f7d5058_2218x1402.png 848w, https://substackcdn.com/image/fetch/$s_!Onlo!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8e811b7-9ae4-42aa-8690-ab775f7d5058_2218x1402.png 1272w, https://substackcdn.com/image/fetch/$s_!Onlo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8e811b7-9ae4-42aa-8690-ab775f7d5058_2218x1402.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><div><hr></div><p><em><strong>Reminder: this is a teaser of the subscriber-only post, exclusive to my golden members.</strong></em></p><p>When you upgrade, you&#8217;ll get:</p><ul><li><p><strong>Full access to system design case studies</strong></p></li><li><p>FREE access to (coming) Design, Build, Scale newsletter series</p></li><li><p><strong>FREE access to (coming) popular interview question breakdowns</strong></p></li></ul><p>And more!</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/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://newsletter.systemdesign.one/subscribe?"><span>Subscribe now</span></a></p>
      <p>
          <a href="https://newsletter.systemdesign.one/p/web-crawler-system-design">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Timsort Algorithm - A Deep Dive]]></title><description><![CDATA[#123: The Fastest Real-World Sorting Algorithm]]></description><link>https://newsletter.systemdesign.one/p/timsort-algorithm</link><guid isPermaLink="false">https://newsletter.systemdesign.one/p/timsort-algorithm</guid><dc:creator><![CDATA[Neo Kim]]></dc:creator><pubDate>Thu, 19 Feb 2026 11:20:21 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/911f89b9-13e8-4180-88c9-0125c1c6b654_1280x720.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/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">Get my system design playbook for FREE on newsletter signup:</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>This post outlines Timsort, a popular sorting algorithm known for its speed and efficiency.</p><ul><li><p><em><a href="https://newsletter.systemdesign.one/p/timsort-algorithm/?action=share">Share this post</a> &amp; I'll send you some rewards for the referrals.</em></p></li></ul><div><hr></div><p>Timsort is one of those foundational sorting algorithms used everywhere, but most explanations of how it works shy away from going into its behavior in depth.</p><p>We are going to fix that in this newsletter.</p><p>By the end, not only will you be able to explain how Timsort works at various levels of detail, but you will also see a simplified JavaScript implementation so you can see how the concepts translate into an implementation you can try out on your own computer.</p><p>Let&#8217;s dive in!</p><div><hr></div><h3><strong><a href="https://codenewsletter.ai/subscribe?utm_source=nl_ad_system">Find out why 150K+ engineers read The Code twice a week (Partner)</a></strong></h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://codenewsletter.ai/subscribe?utm_source=nl_ad_system" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!w80U!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe30ba00c-653e-421b-af50-f5b48536f36b_1271x699.jpeg 424w, https://substackcdn.com/image/fetch/$s_!w80U!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe30ba00c-653e-421b-af50-f5b48536f36b_1271x699.jpeg 848w, https://substackcdn.com/image/fetch/$s_!w80U!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe30ba00c-653e-421b-af50-f5b48536f36b_1271x699.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!w80U!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe30ba00c-653e-421b-af50-f5b48536f36b_1271x699.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!w80U!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe30ba00c-653e-421b-af50-f5b48536f36b_1271x699.jpeg" width="1271" height="699" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e30ba00c-653e-421b-af50-f5b48536f36b_1271x699.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:699,&quot;width&quot;:1271,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:303786,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:&quot;image/jpeg&quot;,&quot;href&quot;:&quot;https://codenewsletter.ai/subscribe?utm_source=nl_ad_system&quot;,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/179236490?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe30ba00c-653e-421b-af50-f5b48536f36b_1271x699.jpeg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!w80U!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe30ba00c-653e-421b-af50-f5b48536f36b_1271x699.jpeg 424w, https://substackcdn.com/image/fetch/$s_!w80U!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe30ba00c-653e-421b-af50-f5b48536f36b_1271x699.jpeg 848w, https://substackcdn.com/image/fetch/$s_!w80U!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe30ba00c-653e-421b-af50-f5b48536f36b_1271x699.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!w80U!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe30ba00c-653e-421b-af50-f5b48536f36b_1271x699.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Tech moves fast, but you&#8217;re still playing catch-up?</p><p>That&#8217;s exactly why 150K+ engineers working at Google, Meta, and Apple read <a href="https://codenewsletter.ai/subscribe?utm_source=nl_ad_system">The Code</a> twice a week.</p><p>Here&#8217;s what you get:</p><ul><li><p><strong>Curated tech news that shapes your career </strong>- Filtered from thousands of sources so you know what&#8217;s coming 6 months early.</p></li><li><p><strong>Practical resources you can use immediately</strong> - Real tutorials and tools that solve actual engineering problems.</p></li><li><p><strong>Research papers and insights decoded</strong> - We break down complex tech so you understand what matters.</p></li></ul><p>All delivered twice a week in just 2 short emails.</p><p><strong>Sign up and get access to the Ultimate Claude code guide to ship 5X faster.</strong></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://codenewsletter.ai/subscribe?utm_source=nl_ad_system&quot;,&quot;text&quot;:&quot;Join 150K+ Engineers&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://codenewsletter.ai/subscribe?utm_source=nl_ad_system"><span>Join 150K+ Engineers</span></a></p><p>(Thanks for partnering on this post and sharing the ultimate <a href="https://codenewsletter.ai/subscribe?utm_source=nl_ad_system">claude code guide</a>.)</p><div><hr></div><p>I want to introduce <a href="https://www.kirupa.com">Kirupa Chinnathambi</a>, a connoisseur of explaining hard technical topics in a simple, easy-to-digest way:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://www.kirupa.com" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!fHMF!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0f4cd89-1974-403d-a8be-18330cefcd10_1600x913.png 424w, https://substackcdn.com/image/fetch/$s_!fHMF!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0f4cd89-1974-403d-a8be-18330cefcd10_1600x913.png 848w, https://substackcdn.com/image/fetch/$s_!fHMF!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0f4cd89-1974-403d-a8be-18330cefcd10_1600x913.png 1272w, https://substackcdn.com/image/fetch/$s_!fHMF!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0f4cd89-1974-403d-a8be-18330cefcd10_1600x913.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!fHMF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0f4cd89-1974-403d-a8be-18330cefcd10_1600x913.png" width="1456" height="831" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a0f4cd89-1974-403d-a8be-18330cefcd10_1600x913.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:831,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:&quot;https://www.kirupa.com&quot;,&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_!fHMF!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0f4cd89-1974-403d-a8be-18330cefcd10_1600x913.png 424w, https://substackcdn.com/image/fetch/$s_!fHMF!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0f4cd89-1974-403d-a8be-18330cefcd10_1600x913.png 848w, https://substackcdn.com/image/fetch/$s_!fHMF!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0f4cd89-1974-403d-a8be-18330cefcd10_1600x913.png 1272w, https://substackcdn.com/image/fetch/$s_!fHMF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0f4cd89-1974-403d-a8be-18330cefcd10_1600x913.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>He has been blogging since 1998 (hello, Geocities!)&nbsp;and has turned this hobby into a way to help hundreds of thousands of people through numerous articles,&nbsp;<a href="https://www.youtube.com/kirupa">videos</a>,&nbsp;<a href="https://forum.kirupa.com">community forum posts</a>,&nbsp;<a href="https://www.kirupa.chat">a&nbsp;popular newsletter</a>, and <a href="https://www.amazon.com/stores/Kirupa-Chinnathambi/author/B001KCY8XW">best-selling books</a>.</p><p>In parallel, he is <a href="https://www.linkedin.com/in/kirupa/">a hands-on Product Manager</a>&nbsp;at Microsoft, working at the intersection of how AI and developers can build great things faster and more securely on Windows.</p><div><hr></div><h2><strong>Introduction</strong></h2><p>When it comes to sorting algorithms, none of them is perfect.</p><p>Take a look at the following table of running times for the sorting algorithms we&#8217;ve seen so far:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!iRr9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5536d79-6528-4272-a1b8-28433e5f60cd_1222x710.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!iRr9!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5536d79-6528-4272-a1b8-28433e5f60cd_1222x710.png 424w, https://substackcdn.com/image/fetch/$s_!iRr9!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5536d79-6528-4272-a1b8-28433e5f60cd_1222x710.png 848w, https://substackcdn.com/image/fetch/$s_!iRr9!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5536d79-6528-4272-a1b8-28433e5f60cd_1222x710.png 1272w, https://substackcdn.com/image/fetch/$s_!iRr9!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5536d79-6528-4272-a1b8-28433e5f60cd_1222x710.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!iRr9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5536d79-6528-4272-a1b8-28433e5f60cd_1222x710.png" width="1222" height="710" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d5536d79-6528-4272-a1b8-28433e5f60cd_1222x710.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:710,&quot;width&quot;:1222,&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_!iRr9!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5536d79-6528-4272-a1b8-28433e5f60cd_1222x710.png 424w, https://substackcdn.com/image/fetch/$s_!iRr9!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5536d79-6528-4272-a1b8-28433e5f60cd_1222x710.png 848w, https://substackcdn.com/image/fetch/$s_!iRr9!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5536d79-6528-4272-a1b8-28433e5f60cd_1222x710.png 1272w, https://substackcdn.com/image/fetch/$s_!iRr9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5536d79-6528-4272-a1b8-28433e5f60cd_1222x710.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 sorting algorithms that seem perfect often show really poor behavior in worst-case scenarios. Their best-case performance may be suboptimal, too.</p><p>Take quicksort<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a>, for example.</p><p>Quicksort looks pretty good, right? On average, it runs at a very respectable <strong>O(n log n)</strong> time. Now, what if we ask it to sort a fully sorted collection of values, and our pivot selection is having an off day? In this case, quicksort will slow to a crawl and sort our input with an <strong>O(n&#178;)</strong> time.</p><p>That makes it as bad as some of our slowest sorting algorithms.</p><p>The opposite holds true as well.</p><p>Our slowest sorting algorithms, like Selection Sort, Insertion Sort, or Bubble Sort, have the potential to run really fast. For example, Bubble Sort normally runs at <strong>O(n&#178;)</strong>. If the values we ask it to sort happen to already be sorted, Bubble Sort will sort the values at a blazing fast <strong>O(n)</strong> time.</p><p>That&#8217;s even faster than Quicksort&#8217;s best sorting 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_!2GH6!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65506452-7321-4bb3-9eb9-a4f5791acefe_1096x1052.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!2GH6!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65506452-7321-4bb3-9eb9-a4f5791acefe_1096x1052.jpeg 424w, https://substackcdn.com/image/fetch/$s_!2GH6!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65506452-7321-4bb3-9eb9-a4f5791acefe_1096x1052.jpeg 848w, https://substackcdn.com/image/fetch/$s_!2GH6!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65506452-7321-4bb3-9eb9-a4f5791acefe_1096x1052.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!2GH6!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65506452-7321-4bb3-9eb9-a4f5791acefe_1096x1052.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!2GH6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65506452-7321-4bb3-9eb9-a4f5791acefe_1096x1052.jpeg" width="1096" height="1052" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/65506452-7321-4bb3-9eb9-a4f5791acefe_1096x1052.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1052,&quot;width&quot;:1096,&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_!2GH6!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65506452-7321-4bb3-9eb9-a4f5791acefe_1096x1052.jpeg 424w, https://substackcdn.com/image/fetch/$s_!2GH6!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65506452-7321-4bb3-9eb9-a4f5791acefe_1096x1052.jpeg 848w, https://substackcdn.com/image/fetch/$s_!2GH6!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65506452-7321-4bb3-9eb9-a4f5791acefe_1096x1052.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!2GH6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65506452-7321-4bb3-9eb9-a4f5791acefe_1096x1052.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>How well our sorting algorithms work depends largely on the arrangement of our unsorted input values:</p><ol><li><p>Are the input values random?</p></li><li><p>Are they already sorted?</p></li><li><p>Are they sorted in reverse?</p></li><li><p>Is the range of values inside them large or small?</p></li></ol><p>Based on our answers to these questions, the performance of our sorting algorithms will vary.</p><p>As we described a few seconds ago, seemingly great sorting algorithms will crumble with the wrong arrangement of values, and terrible sorting algorithms will shine on the same arrangement of values.</p><p>So...what can we do here?</p><p>Instead of using a single sorting algorithm for our data, we can choose from a variety of sorting algorithms optimized for the kind of data we are dealing with. We can use something known as a <strong>hybrid sorting algorithm</strong>. A hybrid sorting algorithm takes advantage of the strengths of multiple sorting algorithms to create some sort of a super algorithm&#8230;<a href="https://upload.wikimedia.org/wikipedia/commons/0/09/Tyrannosaurus-rex-Profile-steveoc86.png">like our T-Rex over here</a>:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!f0uB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F192c747c-2995-46c8-992c-ba4bb9f33787_1600x727.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!f0uB!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F192c747c-2995-46c8-992c-ba4bb9f33787_1600x727.png 424w, https://substackcdn.com/image/fetch/$s_!f0uB!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F192c747c-2995-46c8-992c-ba4bb9f33787_1600x727.png 848w, https://substackcdn.com/image/fetch/$s_!f0uB!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F192c747c-2995-46c8-992c-ba4bb9f33787_1600x727.png 1272w, https://substackcdn.com/image/fetch/$s_!f0uB!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F192c747c-2995-46c8-992c-ba4bb9f33787_1600x727.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!f0uB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F192c747c-2995-46c8-992c-ba4bb9f33787_1600x727.png" width="1456" height="662" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/192c747c-2995-46c8-992c-ba4bb9f33787_1600x727.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:662,&quot;width&quot;:1456,&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_!f0uB!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F192c747c-2995-46c8-992c-ba4bb9f33787_1600x727.png 424w, https://substackcdn.com/image/fetch/$s_!f0uB!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F192c747c-2995-46c8-992c-ba4bb9f33787_1600x727.png 848w, https://substackcdn.com/image/fetch/$s_!f0uB!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F192c747c-2995-46c8-992c-ba4bb9f33787_1600x727.png 1272w, https://substackcdn.com/image/fetch/$s_!f0uB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F192c747c-2995-46c8-992c-ba4bb9f33787_1600x727.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>By relying on multiple sorting algorithms, we can <strong>minimize the worst-case behavior of individual sorting algorithms</strong> by switching between algorithms based on the characteristics of the unsorted input data being sorted.</p><p>In this newsletter, we are going to learn about one of the greatest hybrid sorting algorithms ever created. We are going to learn about <strong>Timsort</strong>.</p><p>Onward.</p><div><hr></div><div class="captioned-button-wrap" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/p/timsort-algorithm?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">Share this post &amp; earn rewards for referrals.</p></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/p/timsort-algorithm?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://newsletter.systemdesign.one/p/timsort-algorithm?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p></div><div><hr></div><h2>What is Timsort?</h2><blockquote><p>Timsort is a hybrid sorting algorithm that combines the best features of two other sorting algorithms:</p><ul><li><p>Merge sort (where you divide your input, sort, merge recursively),</p></li><li><p>Insertion sort (where you start from a blank output and insert elements into place).</p></li></ul></blockquote><p>The key idea behind Timsort is <strong>to take advantage of the existing order in the data</strong>. It&#8217;s especially efficient for real-world scenarios where the values we&#8217;ll be sorting will often have some pre-existing order or patterns.</p><p>The way Timsort works can be grossly oversimplified as follows:</p><ol><li><p>Divide the data into small chunks</p></li><li><p>Sort these chunks using Insertion sort</p></li><li><p>Merge the sorted chunks using a smart merging strategy found in Merge sort</p></li></ol><p>The best way to make sense of how Timsort works is by walking through an example, so we&#8217;ll do that next.</p><div><hr></div><h2>Walkthrough</h2><p>As with all great sorting algorithm walkthroughs, we&#8217;re going to start with some unsorted data that needs to be sorted:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!m0jS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5ebf99c-e853-43b9-a20f-303e0924593b_1169x174.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!m0jS!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5ebf99c-e853-43b9-a20f-303e0924593b_1169x174.png 424w, https://substackcdn.com/image/fetch/$s_!m0jS!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5ebf99c-e853-43b9-a20f-303e0924593b_1169x174.png 848w, https://substackcdn.com/image/fetch/$s_!m0jS!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5ebf99c-e853-43b9-a20f-303e0924593b_1169x174.png 1272w, https://substackcdn.com/image/fetch/$s_!m0jS!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5ebf99c-e853-43b9-a20f-303e0924593b_1169x174.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!m0jS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5ebf99c-e853-43b9-a20f-303e0924593b_1169x174.png" width="1169" height="174" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e5ebf99c-e853-43b9-a20f-303e0924593b_1169x174.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:174,&quot;width&quot;:1169,&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_!m0jS!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5ebf99c-e853-43b9-a20f-303e0924593b_1169x174.png 424w, https://substackcdn.com/image/fetch/$s_!m0jS!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5ebf99c-e853-43b9-a20f-303e0924593b_1169x174.png 848w, https://substackcdn.com/image/fetch/$s_!m0jS!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5ebf99c-e853-43b9-a20f-303e0924593b_1169x174.png 1272w, https://substackcdn.com/image/fetch/$s_!m0jS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5ebf99c-e853-43b9-a20f-303e0924593b_1169x174.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>This list of unsorted values is pretty long to help us better appreciate how Timsort works. To help make all of this data easier for us to visualize here, let&#8217;s wrap this long list of data as follows:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!lmgp!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b3f8d5a-f871-41e5-ba51-deab2e94c1f6_1078x407.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!lmgp!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b3f8d5a-f871-41e5-ba51-deab2e94c1f6_1078x407.png 424w, https://substackcdn.com/image/fetch/$s_!lmgp!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b3f8d5a-f871-41e5-ba51-deab2e94c1f6_1078x407.png 848w, https://substackcdn.com/image/fetch/$s_!lmgp!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b3f8d5a-f871-41e5-ba51-deab2e94c1f6_1078x407.png 1272w, https://substackcdn.com/image/fetch/$s_!lmgp!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b3f8d5a-f871-41e5-ba51-deab2e94c1f6_1078x407.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!lmgp!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b3f8d5a-f871-41e5-ba51-deab2e94c1f6_1078x407.png" width="1078" height="407" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1b3f8d5a-f871-41e5-ba51-deab2e94c1f6_1078x407.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:407,&quot;width&quot;:1078,&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_!lmgp!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b3f8d5a-f871-41e5-ba51-deab2e94c1f6_1078x407.png 424w, https://substackcdn.com/image/fetch/$s_!lmgp!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b3f8d5a-f871-41e5-ba51-deab2e94c1f6_1078x407.png 848w, https://substackcdn.com/image/fetch/$s_!lmgp!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b3f8d5a-f871-41e5-ba51-deab2e94c1f6_1078x407.png 1272w, https://substackcdn.com/image/fetch/$s_!lmgp!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b3f8d5a-f871-41e5-ba51-deab2e94c1f6_1078x407.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>Nothing about our data has changed except how we can represent it on this page.</p><p>The first thing we do with Timsort is divide the data we wish to sort into smaller chunks. These chunks are more formally known as <em><strong>runs</strong></em>. The size of these runs usually varies between 32 and 64 items, but for our example, we&#8217;ll keep the size of our runs much smaller at 4:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!o_n9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57a90a0e-fa1e-4a4c-8e61-804dca6a6db1_1078x439.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!o_n9!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57a90a0e-fa1e-4a4c-8e61-804dca6a6db1_1078x439.png 424w, https://substackcdn.com/image/fetch/$s_!o_n9!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57a90a0e-fa1e-4a4c-8e61-804dca6a6db1_1078x439.png 848w, https://substackcdn.com/image/fetch/$s_!o_n9!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57a90a0e-fa1e-4a4c-8e61-804dca6a6db1_1078x439.png 1272w, https://substackcdn.com/image/fetch/$s_!o_n9!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57a90a0e-fa1e-4a4c-8e61-804dca6a6db1_1078x439.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!o_n9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57a90a0e-fa1e-4a4c-8e61-804dca6a6db1_1078x439.png" width="1078" height="439" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/57a90a0e-fa1e-4a4c-8e61-804dca6a6db1_1078x439.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:439,&quot;width&quot;:1078,&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_!o_n9!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57a90a0e-fa1e-4a4c-8e61-804dca6a6db1_1078x439.png 424w, https://substackcdn.com/image/fetch/$s_!o_n9!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57a90a0e-fa1e-4a4c-8e61-804dca6a6db1_1078x439.png 848w, https://substackcdn.com/image/fetch/$s_!o_n9!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57a90a0e-fa1e-4a4c-8e61-804dca6a6db1_1078x439.png 1272w, https://substackcdn.com/image/fetch/$s_!o_n9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57a90a0e-fa1e-4a4c-8e61-804dca6a6db1_1078x439.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>Notice that we divided our entire unsorted collection into runs of four items each, except for the last run, which only has two values.</p><h3>Sorting with Insertion Sort</h3><p>Now that we have our runs, <strong>we apply insertion sort</strong> on each run to sort these values. We sort our first run:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!rltF!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35359dcb-aede-47bd-8a14-53e3e8d5c9f2_1078x533.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!rltF!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35359dcb-aede-47bd-8a14-53e3e8d5c9f2_1078x533.png 424w, https://substackcdn.com/image/fetch/$s_!rltF!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35359dcb-aede-47bd-8a14-53e3e8d5c9f2_1078x533.png 848w, https://substackcdn.com/image/fetch/$s_!rltF!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35359dcb-aede-47bd-8a14-53e3e8d5c9f2_1078x533.png 1272w, https://substackcdn.com/image/fetch/$s_!rltF!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35359dcb-aede-47bd-8a14-53e3e8d5c9f2_1078x533.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!rltF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35359dcb-aede-47bd-8a14-53e3e8d5c9f2_1078x533.png" width="1078" height="533" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/35359dcb-aede-47bd-8a14-53e3e8d5c9f2_1078x533.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:533,&quot;width&quot;:1078,&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_!rltF!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35359dcb-aede-47bd-8a14-53e3e8d5c9f2_1078x533.png 424w, https://substackcdn.com/image/fetch/$s_!rltF!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35359dcb-aede-47bd-8a14-53e3e8d5c9f2_1078x533.png 848w, https://substackcdn.com/image/fetch/$s_!rltF!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35359dcb-aede-47bd-8a14-53e3e8d5c9f2_1078x533.png 1272w, https://substackcdn.com/image/fetch/$s_!rltF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35359dcb-aede-47bd-8a14-53e3e8d5c9f2_1078x533.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>Next, we sort our second run:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Z6VZ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F812005d2-7105-456c-96f8-5b6a495c8046_1078x533.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Z6VZ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F812005d2-7105-456c-96f8-5b6a495c8046_1078x533.png 424w, https://substackcdn.com/image/fetch/$s_!Z6VZ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F812005d2-7105-456c-96f8-5b6a495c8046_1078x533.png 848w, https://substackcdn.com/image/fetch/$s_!Z6VZ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F812005d2-7105-456c-96f8-5b6a495c8046_1078x533.png 1272w, https://substackcdn.com/image/fetch/$s_!Z6VZ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F812005d2-7105-456c-96f8-5b6a495c8046_1078x533.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Z6VZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F812005d2-7105-456c-96f8-5b6a495c8046_1078x533.png" width="1078" height="533" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/812005d2-7105-456c-96f8-5b6a495c8046_1078x533.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:533,&quot;width&quot;:1078,&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_!Z6VZ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F812005d2-7105-456c-96f8-5b6a495c8046_1078x533.png 424w, https://substackcdn.com/image/fetch/$s_!Z6VZ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F812005d2-7105-456c-96f8-5b6a495c8046_1078x533.png 848w, https://substackcdn.com/image/fetch/$s_!Z6VZ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F812005d2-7105-456c-96f8-5b6a495c8046_1078x533.png 1272w, https://substackcdn.com/image/fetch/$s_!Z6VZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F812005d2-7105-456c-96f8-5b6a495c8046_1078x533.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 sorting repeats until all of our individual runs are sorted:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ejCR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46a5be24-c9bd-46ca-9702-9b441fe36031_1078x439.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ejCR!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46a5be24-c9bd-46ca-9702-9b441fe36031_1078x439.png 424w, https://substackcdn.com/image/fetch/$s_!ejCR!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46a5be24-c9bd-46ca-9702-9b441fe36031_1078x439.png 848w, https://substackcdn.com/image/fetch/$s_!ejCR!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46a5be24-c9bd-46ca-9702-9b441fe36031_1078x439.png 1272w, https://substackcdn.com/image/fetch/$s_!ejCR!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46a5be24-c9bd-46ca-9702-9b441fe36031_1078x439.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ejCR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46a5be24-c9bd-46ca-9702-9b441fe36031_1078x439.png" width="1078" height="439" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/46a5be24-c9bd-46ca-9702-9b441fe36031_1078x439.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:439,&quot;width&quot;:1078,&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_!ejCR!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46a5be24-c9bd-46ca-9702-9b441fe36031_1078x439.png 424w, https://substackcdn.com/image/fetch/$s_!ejCR!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46a5be24-c9bd-46ca-9702-9b441fe36031_1078x439.png 848w, https://substackcdn.com/image/fetch/$s_!ejCR!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46a5be24-c9bd-46ca-9702-9b441fe36031_1078x439.png 1272w, https://substackcdn.com/image/fetch/$s_!ejCR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46a5be24-c9bd-46ca-9702-9b441fe36031_1078x439.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>An important detail is that only the values within each run are sorted.</p><p>In aggregate, our collection of items is still unsorted. We will address that next.</p><h3>Merging Runs</h3><p>The final step is to take our individually sorted runs and merge them into larger and larger sorted runs. At the end of all this, the result will be one combined sorted collection of data.</p><p>We start by merging adjacent runs together, and I have color-coded the adjacent runs that will be merged 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_!aa8r!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F843efce7-68d1-4a27-85fc-bac0b3a4ce95_1078x439.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!aa8r!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F843efce7-68d1-4a27-85fc-bac0b3a4ce95_1078x439.png 424w, https://substackcdn.com/image/fetch/$s_!aa8r!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F843efce7-68d1-4a27-85fc-bac0b3a4ce95_1078x439.png 848w, https://substackcdn.com/image/fetch/$s_!aa8r!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F843efce7-68d1-4a27-85fc-bac0b3a4ce95_1078x439.png 1272w, https://substackcdn.com/image/fetch/$s_!aa8r!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F843efce7-68d1-4a27-85fc-bac0b3a4ce95_1078x439.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!aa8r!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F843efce7-68d1-4a27-85fc-bac0b3a4ce95_1078x439.png" width="1078" height="439" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/843efce7-68d1-4a27-85fc-bac0b3a4ce95_1078x439.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:439,&quot;width&quot;:1078,&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_!aa8r!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F843efce7-68d1-4a27-85fc-bac0b3a4ce95_1078x439.png 424w, https://substackcdn.com/image/fetch/$s_!aa8r!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F843efce7-68d1-4a27-85fc-bac0b3a4ce95_1078x439.png 848w, https://substackcdn.com/image/fetch/$s_!aa8r!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F843efce7-68d1-4a27-85fc-bac0b3a4ce95_1078x439.png 1272w, https://substackcdn.com/image/fetch/$s_!aa8r!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F843efce7-68d1-4a27-85fc-bac0b3a4ce95_1078x439.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 merging operation will use a subset of merge sort&#8217;s capabilities, where we need to merge the individually sorted runs into a final sorted order.</p><p>After the first round of merging, our collection will look as follows:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!HtID!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74b5bf2a-4d8a-41c4-b866-59668a441d97_1078x407.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!HtID!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74b5bf2a-4d8a-41c4-b866-59668a441d97_1078x407.png 424w, https://substackcdn.com/image/fetch/$s_!HtID!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74b5bf2a-4d8a-41c4-b866-59668a441d97_1078x407.png 848w, https://substackcdn.com/image/fetch/$s_!HtID!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74b5bf2a-4d8a-41c4-b866-59668a441d97_1078x407.png 1272w, https://substackcdn.com/image/fetch/$s_!HtID!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74b5bf2a-4d8a-41c4-b866-59668a441d97_1078x407.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!HtID!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74b5bf2a-4d8a-41c4-b866-59668a441d97_1078x407.png" width="1078" height="407" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/74b5bf2a-4d8a-41c4-b866-59668a441d97_1078x407.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:407,&quot;width&quot;:1078,&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_!HtID!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74b5bf2a-4d8a-41c4-b866-59668a441d97_1078x407.png 424w, https://substackcdn.com/image/fetch/$s_!HtID!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74b5bf2a-4d8a-41c4-b866-59668a441d97_1078x407.png 848w, https://substackcdn.com/image/fetch/$s_!HtID!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74b5bf2a-4d8a-41c4-b866-59668a441d97_1078x407.png 1272w, https://substackcdn.com/image/fetch/$s_!HtID!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74b5bf2a-4d8a-41c4-b866-59668a441d97_1078x407.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 runs are now around double in size. We now repeat the process by merging adjacent runs again. After this round of merging, we will be left with two sorted runs:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!-XZc!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b50739d-29e7-4cec-85c4-163683730706_1078x407.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!-XZc!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b50739d-29e7-4cec-85c4-163683730706_1078x407.png 424w, https://substackcdn.com/image/fetch/$s_!-XZc!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b50739d-29e7-4cec-85c4-163683730706_1078x407.png 848w, https://substackcdn.com/image/fetch/$s_!-XZc!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b50739d-29e7-4cec-85c4-163683730706_1078x407.png 1272w, https://substackcdn.com/image/fetch/$s_!-XZc!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b50739d-29e7-4cec-85c4-163683730706_1078x407.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!-XZc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b50739d-29e7-4cec-85c4-163683730706_1078x407.png" width="1078" height="407" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9b50739d-29e7-4cec-85c4-163683730706_1078x407.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:407,&quot;width&quot;:1078,&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_!-XZc!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b50739d-29e7-4cec-85c4-163683730706_1078x407.png 424w, https://substackcdn.com/image/fetch/$s_!-XZc!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b50739d-29e7-4cec-85c4-163683730706_1078x407.png 848w, https://substackcdn.com/image/fetch/$s_!-XZc!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b50739d-29e7-4cec-85c4-163683730706_1078x407.png 1272w, https://substackcdn.com/image/fetch/$s_!-XZc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b50739d-29e7-4cec-85c4-163683730706_1078x407.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>We are almost done here. All that remains is one last step, where we merge our two unsorted runs to create our sorted output:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!RAds!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77fe7c3f-52cb-4fad-bd87-bebd77cc3724_1078x407.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!RAds!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77fe7c3f-52cb-4fad-bd87-bebd77cc3724_1078x407.png 424w, https://substackcdn.com/image/fetch/$s_!RAds!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77fe7c3f-52cb-4fad-bd87-bebd77cc3724_1078x407.png 848w, https://substackcdn.com/image/fetch/$s_!RAds!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77fe7c3f-52cb-4fad-bd87-bebd77cc3724_1078x407.png 1272w, https://substackcdn.com/image/fetch/$s_!RAds!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77fe7c3f-52cb-4fad-bd87-bebd77cc3724_1078x407.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!RAds!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77fe7c3f-52cb-4fad-bd87-bebd77cc3724_1078x407.png" width="1078" height="407" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/77fe7c3f-52cb-4fad-bd87-bebd77cc3724_1078x407.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:407,&quot;width&quot;:1078,&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_!RAds!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77fe7c3f-52cb-4fad-bd87-bebd77cc3724_1078x407.png 424w, https://substackcdn.com/image/fetch/$s_!RAds!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77fe7c3f-52cb-4fad-bd87-bebd77cc3724_1078x407.png 848w, https://substackcdn.com/image/fetch/$s_!RAds!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77fe7c3f-52cb-4fad-bd87-bebd77cc3724_1078x407.png 1272w, https://substackcdn.com/image/fetch/$s_!RAds!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77fe7c3f-52cb-4fad-bd87-bebd77cc3724_1078x407.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>At this moment, no further runs need to be merged.</p><p>Timsort is finished sorting our data. Also, at this very moment, you probably have many questions about what exactly happened to make Timsort seem like a superior sorting algorithm to most other sorting algorithms out there.</p><p>We&#8217;ll address that next.</p><div><hr></div><div class="captioned-button-wrap" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/p/timsort-algorithm?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">Share this post &amp; earn rewards for referrals.</p></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/p/timsort-algorithm?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://newsletter.systemdesign.one/p/timsort-algorithm?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p></div><div><hr></div><h2>Optimizations</h2><p>The above walkthrough highlighted how we can use Timsort to sort our unsorted collection of numbers.</p><p>We broke our larger input into runs, sorted each run using insertion sort, and then merged adjacent runs until we had a single fully sorted run.</p><p>If we analyzed our walkthrough at face value, Timsort&#8217;s performance may not seem very fast when we have n items, n<sup>2</sup> running time for insertion sort, and a logarithmic running time for merging values. This is where some optimizations Timsort is known for kick in&#8230;dramatically speeding things up in many cases.</p><p>These optimizations focus on detecting common patterns in our data and customizing next steps based on how the data is structured.</p><h3>Detecting Ascending and Descending Runs</h3><p>The worst-case running time for insertion sort occurs when the values to be sorted are in reverse order.</p><p>To avoid this, Timsort will try to identify runs that are strictly in reverse (aka descending) order and do an in-place reverse on them first before attempting to sort and merge them:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!IXH-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faae72dc3-9e36-4c0c-8225-d61e9b12401f_885x772.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!IXH-!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faae72dc3-9e36-4c0c-8225-d61e9b12401f_885x772.png 424w, https://substackcdn.com/image/fetch/$s_!IXH-!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faae72dc3-9e36-4c0c-8225-d61e9b12401f_885x772.png 848w, https://substackcdn.com/image/fetch/$s_!IXH-!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faae72dc3-9e36-4c0c-8225-d61e9b12401f_885x772.png 1272w, https://substackcdn.com/image/fetch/$s_!IXH-!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faae72dc3-9e36-4c0c-8225-d61e9b12401f_885x772.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!IXH-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faae72dc3-9e36-4c0c-8225-d61e9b12401f_885x772.png" width="885" height="772" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/aae72dc3-9e36-4c0c-8225-d61e9b12401f_885x772.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:772,&quot;width&quot;:885,&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_!IXH-!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faae72dc3-9e36-4c0c-8225-d61e9b12401f_885x772.png 424w, https://substackcdn.com/image/fetch/$s_!IXH-!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faae72dc3-9e36-4c0c-8225-d61e9b12401f_885x772.png 848w, https://substackcdn.com/image/fetch/$s_!IXH-!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faae72dc3-9e36-4c0c-8225-d61e9b12401f_885x772.png 1272w, https://substackcdn.com/image/fetch/$s_!IXH-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faae72dc3-9e36-4c0c-8225-d61e9b12401f_885x772.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 best-case performance of insertion sort occurs when the runs are in ascending order.</p><p>In these cases, <strong>the runs are left as-is</strong>. There is no need to sort them. The only real work Timsort will need to perform is merging, which is consistently fast.</p><h3>Galloping Mode and Already Sorted Runs</h3><p>Galloping mode (also known as <em><strong>binary search insertion</strong></em> by distant friends and relatives) is an optimization technique used in Timsort algorithm <strong>during the merging phase</strong>. It&#8217;s designed to handle cases where a run has many elements that are already in their final sorted position relative to the other run.</p><p>Here&#8217;s how it works:</p><ol><li><p>During merging, if Timsort notices that many consecutive elements from one run are being chosen, it switches to galloping mode.</p></li><li><p>In galloping mode, instead of comparing elements one by one, Timsort jumps (or &#8220;gallops&#8221;) over multiple elements at a time, making the merging faster</p></li><li><p>This can significantly reduce the number of comparisons needed when merging runs that are already partially ordered relative to each other.</p></li></ol><p>This will make more sense with an example, so here are two sorted runs we would like to merge:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!nYJ_!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3682d308-215a-4c44-b38e-96e6d40c1f7d_872x255.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!nYJ_!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3682d308-215a-4c44-b38e-96e6d40c1f7d_872x255.png 424w, https://substackcdn.com/image/fetch/$s_!nYJ_!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3682d308-215a-4c44-b38e-96e6d40c1f7d_872x255.png 848w, https://substackcdn.com/image/fetch/$s_!nYJ_!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3682d308-215a-4c44-b38e-96e6d40c1f7d_872x255.png 1272w, https://substackcdn.com/image/fetch/$s_!nYJ_!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3682d308-215a-4c44-b38e-96e6d40c1f7d_872x255.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!nYJ_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3682d308-215a-4c44-b38e-96e6d40c1f7d_872x255.png" width="872" height="255" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3682d308-215a-4c44-b38e-96e6d40c1f7d_872x255.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:255,&quot;width&quot;:872,&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_!nYJ_!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3682d308-215a-4c44-b38e-96e6d40c1f7d_872x255.png 424w, https://substackcdn.com/image/fetch/$s_!nYJ_!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3682d308-215a-4c44-b38e-96e6d40c1f7d_872x255.png 848w, https://substackcdn.com/image/fetch/$s_!nYJ_!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3682d308-215a-4c44-b38e-96e6d40c1f7d_872x255.png 1272w, https://substackcdn.com/image/fetch/$s_!nYJ_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3682d308-215a-4c44-b38e-96e6d40c1f7d_872x255.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 an unoptimized merge, we would compare each element between both runs and add the smaller of the values to our merged collection.</p><p>When we look at the values in Run A, we can see that the first five numbers are all consistently less than the first value in Run B. If we elaborate on that using a loose array-like syntax, we have:</p><ul><li><p>Compare RunA[0] (1) with RunB[0] (10): 1 is smaller, so 1 is added to the merged collection.</p></li><li><p>Compare RunA[1] (2) with RunB[0] (10): 2 is smaller, so 2 is added to the merged collection.</p></li><li><p>Compare RunA[2] (3) with RunB[0] (10): 3 is smaller, so 3 is added to the merged collection.</p></li><li><p>Compare RunA[3] (4) with RunB[0] (10): 4 is smaller, so 4 is added to the merged collection.</p></li><li><p>Compare RunA[4] (5) with RunB[0] (10): 5 is smaller, so 5 is added to the merged collection.</p></li></ul><p>At this point, our merged collection looks as follows:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!cNEK!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a3ae8d5-ad5d-4f4f-8b8a-01e023058a3a_888x423.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!cNEK!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a3ae8d5-ad5d-4f4f-8b8a-01e023058a3a_888x423.png 424w, https://substackcdn.com/image/fetch/$s_!cNEK!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a3ae8d5-ad5d-4f4f-8b8a-01e023058a3a_888x423.png 848w, https://substackcdn.com/image/fetch/$s_!cNEK!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a3ae8d5-ad5d-4f4f-8b8a-01e023058a3a_888x423.png 1272w, https://substackcdn.com/image/fetch/$s_!cNEK!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a3ae8d5-ad5d-4f4f-8b8a-01e023058a3a_888x423.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!cNEK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a3ae8d5-ad5d-4f4f-8b8a-01e023058a3a_888x423.png" width="888" height="423" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0a3ae8d5-ad5d-4f4f-8b8a-01e023058a3a_888x423.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:423,&quot;width&quot;:888,&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_!cNEK!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a3ae8d5-ad5d-4f4f-8b8a-01e023058a3a_888x423.png 424w, https://substackcdn.com/image/fetch/$s_!cNEK!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a3ae8d5-ad5d-4f4f-8b8a-01e023058a3a_888x423.png 848w, https://substackcdn.com/image/fetch/$s_!cNEK!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a3ae8d5-ad5d-4f4f-8b8a-01e023058a3a_888x423.png 1272w, https://substackcdn.com/image/fetch/$s_!cNEK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a3ae8d5-ad5d-4f4f-8b8a-01e023058a3a_888x423.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>Now, Timsort will compare RunA[5] (31) with RunB[0] (10):</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!NCXQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e087b53-8ea3-4f3f-8276-9c14fcd622da_888x423.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!NCXQ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e087b53-8ea3-4f3f-8276-9c14fcd622da_888x423.png 424w, https://substackcdn.com/image/fetch/$s_!NCXQ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e087b53-8ea3-4f3f-8276-9c14fcd622da_888x423.png 848w, https://substackcdn.com/image/fetch/$s_!NCXQ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e087b53-8ea3-4f3f-8276-9c14fcd622da_888x423.png 1272w, https://substackcdn.com/image/fetch/$s_!NCXQ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e087b53-8ea3-4f3f-8276-9c14fcd622da_888x423.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!NCXQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e087b53-8ea3-4f3f-8276-9c14fcd622da_888x423.png" width="888" height="423" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3e087b53-8ea3-4f3f-8276-9c14fcd622da_888x423.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:423,&quot;width&quot;:888,&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_!NCXQ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e087b53-8ea3-4f3f-8276-9c14fcd622da_888x423.png 424w, https://substackcdn.com/image/fetch/$s_!NCXQ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e087b53-8ea3-4f3f-8276-9c14fcd622da_888x423.png 848w, https://substackcdn.com/image/fetch/$s_!NCXQ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e087b53-8ea3-4f3f-8276-9c14fcd622da_888x423.png 1272w, https://substackcdn.com/image/fetch/$s_!NCXQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e087b53-8ea3-4f3f-8276-9c14fcd622da_888x423.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>At this point, 10 is smaller than 31, so Timsort will now check the next few elements from Run B to see if they should be added in bulk:</p><ul><li><p>Compare RunA[5] (31) with RunB[1] (11): 11 is smaller, so Timsort continues.</p></li><li><p>Compare RunA[5] (20) with RunB[2] (12): 12 is smaller, so Timsort continues.</p></li><li><p>Compare RunA[5] (20) with RunB[3] (14): 14 is smaller, so Timsort continues.</p></li><li><p>Compare RunA[5] (20) with RunB[4] (16): 16 is smaller, so Timsort continues.</p></li><li><p>Compare RunA[5] (20) with RunB[5] (17): 17 is smaller, so Timsort continues.</p></li><li><p>Compare RunA[5] (20) with RunB[6] (18): 18 is smaller, so Timsort continues.</p></li></ul><p>Since all elements in Run B are smaller than RunA[5], Timsort <strong>adds them all at once</strong> to the merged collection:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Itir!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F00297836-84cf-4947-9c3c-1df30f9a2414_1386x423.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Itir!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F00297836-84cf-4947-9c3c-1df30f9a2414_1386x423.png 424w, https://substackcdn.com/image/fetch/$s_!Itir!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F00297836-84cf-4947-9c3c-1df30f9a2414_1386x423.png 848w, https://substackcdn.com/image/fetch/$s_!Itir!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F00297836-84cf-4947-9c3c-1df30f9a2414_1386x423.png 1272w, https://substackcdn.com/image/fetch/$s_!Itir!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F00297836-84cf-4947-9c3c-1df30f9a2414_1386x423.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Itir!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F00297836-84cf-4947-9c3c-1df30f9a2414_1386x423.png" width="1386" height="423" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/00297836-84cf-4947-9c3c-1df30f9a2414_1386x423.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:423,&quot;width&quot;:1386,&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_!Itir!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F00297836-84cf-4947-9c3c-1df30f9a2414_1386x423.png 424w, https://substackcdn.com/image/fetch/$s_!Itir!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F00297836-84cf-4947-9c3c-1df30f9a2414_1386x423.png 848w, https://substackcdn.com/image/fetch/$s_!Itir!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F00297836-84cf-4947-9c3c-1df30f9a2414_1386x423.png 1272w, https://substackcdn.com/image/fetch/$s_!Itir!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F00297836-84cf-4947-9c3c-1df30f9a2414_1386x423.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>After adding all the elements from Run B, Timsort reverts to the regular comparison mode and continues merging the remaining items. In this case, both 31 and 48 from Run A will be added to the end of the merged collection.</p><p>By using galloping mode, Timsort can speed up merging by quickly adding multiple consecutive elements from one run when it&#8217;s clear they are all smaller (or larger) than the next element in the other run.</p><p>This reduces the number of comparisons and overall sorting time, especially when merging runs of significantly different sizes.</p><h3>Adaptive Merging</h3><p>Timsort&#8217;s merging strategy is adaptive, meaning it can vary the merging order based on the sizes of the runs. The goal is to maintain balance among the runs and avoid having a single, large run at the end that would make the final merge costly.</p><p>For example, let&#8217;s say these are the runs we are dealing with:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!D0ei!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe10d8756-f520-46b7-b94a-956cc66614a3_656x556.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!D0ei!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe10d8756-f520-46b7-b94a-956cc66614a3_656x556.png 424w, https://substackcdn.com/image/fetch/$s_!D0ei!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe10d8756-f520-46b7-b94a-956cc66614a3_656x556.png 848w, https://substackcdn.com/image/fetch/$s_!D0ei!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe10d8756-f520-46b7-b94a-956cc66614a3_656x556.png 1272w, https://substackcdn.com/image/fetch/$s_!D0ei!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe10d8756-f520-46b7-b94a-956cc66614a3_656x556.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!D0ei!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe10d8756-f520-46b7-b94a-956cc66614a3_656x556.png" width="656" height="556" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e10d8756-f520-46b7-b94a-956cc66614a3_656x556.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:556,&quot;width&quot;:656,&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_!D0ei!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe10d8756-f520-46b7-b94a-956cc66614a3_656x556.png 424w, https://substackcdn.com/image/fetch/$s_!D0ei!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe10d8756-f520-46b7-b94a-956cc66614a3_656x556.png 848w, https://substackcdn.com/image/fetch/$s_!D0ei!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe10d8756-f520-46b7-b94a-956cc66614a3_656x556.png 1272w, https://substackcdn.com/image/fetch/$s_!D0ei!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe10d8756-f520-46b7-b94a-956cc66614a3_656x556.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 actual values of the runs aren&#8217;t important.</p><p>What is important is the size of the runs. To avoid any run from being too large and making the merge waaaaay unbalanced, we start by merging the two smallest runs:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!vssW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89e3f01b-2b87-4818-8a61-eb25f9ecec4a_804x556.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!vssW!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89e3f01b-2b87-4818-8a61-eb25f9ecec4a_804x556.png 424w, https://substackcdn.com/image/fetch/$s_!vssW!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89e3f01b-2b87-4818-8a61-eb25f9ecec4a_804x556.png 848w, https://substackcdn.com/image/fetch/$s_!vssW!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89e3f01b-2b87-4818-8a61-eb25f9ecec4a_804x556.png 1272w, https://substackcdn.com/image/fetch/$s_!vssW!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89e3f01b-2b87-4818-8a61-eb25f9ecec4a_804x556.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!vssW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89e3f01b-2b87-4818-8a61-eb25f9ecec4a_804x556.png" width="804" height="556" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/89e3f01b-2b87-4818-8a61-eb25f9ecec4a_804x556.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:556,&quot;width&quot;:804,&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_!vssW!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89e3f01b-2b87-4818-8a61-eb25f9ecec4a_804x556.png 424w, https://substackcdn.com/image/fetch/$s_!vssW!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89e3f01b-2b87-4818-8a61-eb25f9ecec4a_804x556.png 848w, https://substackcdn.com/image/fetch/$s_!vssW!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89e3f01b-2b87-4818-8a61-eb25f9ecec4a_804x556.png 1272w, https://substackcdn.com/image/fetch/$s_!vssW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89e3f01b-2b87-4818-8a61-eb25f9ecec4a_804x556.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 would result in Runs C and D merging to create Run CD:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!qFSd!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd289c60-a306-4f28-b699-c0c887ffdbc6_670x396.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!qFSd!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd289c60-a306-4f28-b699-c0c887ffdbc6_670x396.png 424w, https://substackcdn.com/image/fetch/$s_!qFSd!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd289c60-a306-4f28-b699-c0c887ffdbc6_670x396.png 848w, https://substackcdn.com/image/fetch/$s_!qFSd!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd289c60-a306-4f28-b699-c0c887ffdbc6_670x396.png 1272w, https://substackcdn.com/image/fetch/$s_!qFSd!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd289c60-a306-4f28-b699-c0c887ffdbc6_670x396.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!qFSd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd289c60-a306-4f28-b699-c0c887ffdbc6_670x396.png" width="670" height="396" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fd289c60-a306-4f28-b699-c0c887ffdbc6_670x396.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:396,&quot;width&quot;:670,&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_!qFSd!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd289c60-a306-4f28-b699-c0c887ffdbc6_670x396.png 424w, https://substackcdn.com/image/fetch/$s_!qFSd!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd289c60-a306-4f28-b699-c0c887ffdbc6_670x396.png 848w, https://substackcdn.com/image/fetch/$s_!qFSd!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd289c60-a306-4f28-b699-c0c887ffdbc6_670x396.png 1272w, https://substackcdn.com/image/fetch/$s_!qFSd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd289c60-a306-4f28-b699-c0c887ffdbc6_670x396.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 process continues to ensure that the smallest runs are merged into a final merge pair with similar sizes.</p><h3>Insertion Sort All the Way for Smaller Inputs</h3><p>Yes, insertion sort is a slow sorting algorithm.</p><p>When sorting a small number of values, though, this slowness isn&#8217;t very noticeable. This is especially true in a world where our computers can process millions and billions (and trillions?) of operations a second.</p><p>For this reason, Timsort will often fall back to using plain old insertion sort when the size of the input it is trying to sort is less than the run size threshold, which is usually 32 or 64 items in length:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!axD8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e84bc36-c984-4289-9e37-5ce3226dee75_969x924.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!axD8!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e84bc36-c984-4289-9e37-5ce3226dee75_969x924.png 424w, https://substackcdn.com/image/fetch/$s_!axD8!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e84bc36-c984-4289-9e37-5ce3226dee75_969x924.png 848w, https://substackcdn.com/image/fetch/$s_!axD8!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e84bc36-c984-4289-9e37-5ce3226dee75_969x924.png 1272w, https://substackcdn.com/image/fetch/$s_!axD8!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e84bc36-c984-4289-9e37-5ce3226dee75_969x924.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!axD8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e84bc36-c984-4289-9e37-5ce3226dee75_969x924.png" width="969" height="924" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4e84bc36-c984-4289-9e37-5ce3226dee75_969x924.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:924,&quot;width&quot;:969,&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_!axD8!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e84bc36-c984-4289-9e37-5ce3226dee75_969x924.png 424w, https://substackcdn.com/image/fetch/$s_!axD8!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e84bc36-c984-4289-9e37-5ce3226dee75_969x924.png 848w, https://substackcdn.com/image/fetch/$s_!axD8!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e84bc36-c984-4289-9e37-5ce3226dee75_969x924.png 1272w, https://substackcdn.com/image/fetch/$s_!axD8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e84bc36-c984-4289-9e37-5ce3226dee75_969x924.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 avoids the added overhead of the merging operation, breaking runs, and so on.</p><h3>Tying it All Together</h3><p>Why is Timsort so efficient?</p><p>It&#8217;s because it tries to detect patterns in the sorted data and special-case the sorting behavior accordingly. Whether by identifying natural runs, detecting reversed runs, using galloping mode to avoid unnecessary merging-related work, enforcing minimum run lengths, or performing adaptive merges, Timsort seeks the most efficient path whenever possible.</p><p>A subtle but important detail is that these pattern matching optimizations ensure that Timsort performs well on&nbsp;<em><strong>partially sorted</strong></em>&nbsp;data, which is the most common type&nbsp;we will encounter in the real world.</p><div><hr></div><h2>Performance Characteristics</h2><p>Timsort is one of the best sorting algorithms out there, and we can see it live up to its grandness when we summarize its time and memory complexity 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_!GLi7!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd146d73d-b6b3-4252-ba3a-3298b1f9f50c_1262x346.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!GLi7!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd146d73d-b6b3-4252-ba3a-3298b1f9f50c_1262x346.png 424w, https://substackcdn.com/image/fetch/$s_!GLi7!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd146d73d-b6b3-4252-ba3a-3298b1f9f50c_1262x346.png 848w, https://substackcdn.com/image/fetch/$s_!GLi7!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd146d73d-b6b3-4252-ba3a-3298b1f9f50c_1262x346.png 1272w, https://substackcdn.com/image/fetch/$s_!GLi7!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd146d73d-b6b3-4252-ba3a-3298b1f9f50c_1262x346.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!GLi7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd146d73d-b6b3-4252-ba3a-3298b1f9f50c_1262x346.png" width="1262" height="346" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d146d73d-b6b3-4252-ba3a-3298b1f9f50c_1262x346.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:346,&quot;width&quot;:1262,&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_!GLi7!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd146d73d-b6b3-4252-ba3a-3298b1f9f50c_1262x346.png 424w, https://substackcdn.com/image/fetch/$s_!GLi7!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd146d73d-b6b3-4252-ba3a-3298b1f9f50c_1262x346.png 848w, https://substackcdn.com/image/fetch/$s_!GLi7!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd146d73d-b6b3-4252-ba3a-3298b1f9f50c_1262x346.png 1272w, https://substackcdn.com/image/fetch/$s_!GLi7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd146d73d-b6b3-4252-ba3a-3298b1f9f50c_1262x346.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>At its best, Timsort can run in linear time.</p><p>This happens when the data is already sorted or nearly sorted as part of a few large runs, and we know that Insertion Sort runs in linear time for sorted data:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!5h7d!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3cbc59d2-2606-47eb-847e-7ad076bbf5d1_1047x1600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!5h7d!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3cbc59d2-2606-47eb-847e-7ad076bbf5d1_1047x1600.png 424w, https://substackcdn.com/image/fetch/$s_!5h7d!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3cbc59d2-2606-47eb-847e-7ad076bbf5d1_1047x1600.png 848w, https://substackcdn.com/image/fetch/$s_!5h7d!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3cbc59d2-2606-47eb-847e-7ad076bbf5d1_1047x1600.png 1272w, https://substackcdn.com/image/fetch/$s_!5h7d!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3cbc59d2-2606-47eb-847e-7ad076bbf5d1_1047x1600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!5h7d!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3cbc59d2-2606-47eb-847e-7ad076bbf5d1_1047x1600.png" width="1047" height="1600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3cbc59d2-2606-47eb-847e-7ad076bbf5d1_1047x1600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1600,&quot;width&quot;:1047,&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_!5h7d!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3cbc59d2-2606-47eb-847e-7ad076bbf5d1_1047x1600.png 424w, https://substackcdn.com/image/fetch/$s_!5h7d!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3cbc59d2-2606-47eb-847e-7ad076bbf5d1_1047x1600.png 848w, https://substackcdn.com/image/fetch/$s_!5h7d!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3cbc59d2-2606-47eb-847e-7ad076bbf5d1_1047x1600.png 1272w, https://substackcdn.com/image/fetch/$s_!5h7d!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3cbc59d2-2606-47eb-847e-7ad076bbf5d1_1047x1600.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>Merging runs is a fast operation as well, and if we throw in any optimizations, such as galloping mode if the range of sorted numbers doesn&#8217;t overlap, the merging is almost a trivial operation.</p><p>In the average and worst cases, Timsort runs at <strong>O(n log n)</strong>.</p><p>The bulk of the complexity here goes into identifying runs and merging them. This puts its performance on par with Quicksort&#8217;s average performance, but Timsort&#8217;s optimizations give it an edge as being a <em><strong>faster</strong></em> <strong>O(n log n)</strong>!</p><p>This is validated by benchmarks <a href="https://v8.dev/blog/array-sort">such as the following</a> that compares Timsort with Quicksort on partially sorted data:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!QoMd!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50155d7d-0996-46cb-a074-6630c751dbfc_1600x994.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!QoMd!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50155d7d-0996-46cb-a074-6630c751dbfc_1600x994.png 424w, https://substackcdn.com/image/fetch/$s_!QoMd!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50155d7d-0996-46cb-a074-6630c751dbfc_1600x994.png 848w, https://substackcdn.com/image/fetch/$s_!QoMd!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50155d7d-0996-46cb-a074-6630c751dbfc_1600x994.png 1272w, https://substackcdn.com/image/fetch/$s_!QoMd!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50155d7d-0996-46cb-a074-6630c751dbfc_1600x994.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!QoMd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50155d7d-0996-46cb-a074-6630c751dbfc_1600x994.png" width="1456" height="905" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/50155d7d-0996-46cb-a074-6630c751dbfc_1600x994.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:905,&quot;width&quot;:1456,&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_!QoMd!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50155d7d-0996-46cb-a074-6630c751dbfc_1600x994.png 424w, https://substackcdn.com/image/fetch/$s_!QoMd!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50155d7d-0996-46cb-a074-6630c751dbfc_1600x994.png 848w, https://substackcdn.com/image/fetch/$s_!QoMd!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50155d7d-0996-46cb-a074-6630c751dbfc_1600x994.png 1272w, https://substackcdn.com/image/fetch/$s_!QoMd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50155d7d-0996-46cb-a074-6630c751dbfc_1600x994.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>Notice how much faster Timsort is compared to Quicksort.</p><p>The more Timsort is used in real-world data scenarios, the more we&#8217;ll see it soaring faster than every other sorting algorithm we have seen so far.</p><p>Lastly, from a space point of view, Timsort needs an <strong>O(n)</strong> amount of memory to run. This has to do with the data structures Timsort creates behind the scenes when merging the runs.</p><div><hr></div><h2>The Code</h2><p>Timsort is a very complex sorting algorithm to implement.</p><p>The core insertion sort and merging capabilities are straightforward. Identifying and handling all the various patterns to optimize for...is less straightforward. For that reason, most examples of Timsort we will run into are based on the original Python implementation itself. I am not going to paste the massive amount of code needed to implement Timsort in JavaScript.</p><p>Instead, here is a <a href="https://github.com/kirupa/kirupa/blob/master/data_structures_algorithms/timsort.htm">link to the GitHub repo</a> where I took <a href="https://github.com/mziccard/node-timsort">Marco Ziccardi&#8217;s Node.js implementation</a> of Timsort and turned it into something that works in the browser:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!t2KH!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb83226ab-8e31-459b-8d75-46650f4e27bd_1600x1180.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!t2KH!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb83226ab-8e31-459b-8d75-46650f4e27bd_1600x1180.png 424w, https://substackcdn.com/image/fetch/$s_!t2KH!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb83226ab-8e31-459b-8d75-46650f4e27bd_1600x1180.png 848w, https://substackcdn.com/image/fetch/$s_!t2KH!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb83226ab-8e31-459b-8d75-46650f4e27bd_1600x1180.png 1272w, https://substackcdn.com/image/fetch/$s_!t2KH!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb83226ab-8e31-459b-8d75-46650f4e27bd_1600x1180.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!t2KH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb83226ab-8e31-459b-8d75-46650f4e27bd_1600x1180.png" width="1456" height="1074" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b83226ab-8e31-459b-8d75-46650f4e27bd_1600x1180.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;: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_!t2KH!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb83226ab-8e31-459b-8d75-46650f4e27bd_1600x1180.png 424w, https://substackcdn.com/image/fetch/$s_!t2KH!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb83226ab-8e31-459b-8d75-46650f4e27bd_1600x1180.png 848w, https://substackcdn.com/image/fetch/$s_!t2KH!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb83226ab-8e31-459b-8d75-46650f4e27bd_1600x1180.png 1272w, https://substackcdn.com/image/fetch/$s_!t2KH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb83226ab-8e31-459b-8d75-46650f4e27bd_1600x1180.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>As we scan through the code, we&#8217;ll see a lot of familiar patterns. Towards the bottom, the example code to initialize Timsort and use it to sort some values is provided:</p><pre><code>let example = [-7, 10, 50, 3, 940, 1, 4, -8, 24, 40, 33, 12, 10];

// Comparison function
function numberCompare(a, b) {
  return a - b;
}

// Sort our example array
timsort.sort(example, numberCompare);
console.log(example);</code></pre><p>Feel free to try it out and use this in your own projects, but as we will discuss in a few moments, Timsort is already the default sorting algorithm used in many situations in our favorite programming languages.</p><div><hr></div><h2>Conclusion</h2><p>Timsort, as the preeminent hybrid sorting algorithm, is among the fastest sorting algorithms available.</p><p>When we say this, this <em><strong>fastest</strong></em> isn&#8217;t qualified with caveats where the unsorted input needs to be of a certain arrangement. Timsort&#8217;s worst-case behavior is very good. Timsort&#8217;s best-case behavior is very, VERY good. The upper and lower bounds of its performance make it an excellent choice for any kind of unsorted (or sorted) input we throw at it. This flexibility and power are what make Timsort one of the&nbsp;<a href="https://www.kirupa.com/data_structures_algorithms/default_sorting_algorithms.htm">default sorting algorithms</a>&nbsp;in programming languages such as Python, Java, Rust, and more.</p><p>Now, Timsort isn&#8217;t the only hybrid sorting algorithm in town.</p><p>Another popular hybrid sorting algorithm is <strong><a href="https://en.wikipedia.org/wiki/Introsort">introsort</a></strong> (sometimes referred to as <strong>introspective sort</strong>), which uses a combination of quicksort, heapsort, and insertion sort for its sorting shenanigans. Introsort is the default sorting algorithm in Swift, C#, and other languages. As we look ahead into the future and run into more interesting and new data scenarios, we may see more hybrid sorting algorithms emerge.</p><p>We are in the early days, so there will be more fun times ahead with hybrid sorting algorithms.</p><div><hr></div><p>&#128075; I&#8217;d like to thank <strong><a href="https://www.linkedin.com/in/kirupa/">Kirupa</a></strong> for sharing this deep dive into Timsort.</p><p>For more explanations of popular data structures and algorithms, his <a href="https://www.amazon.com/exec/obidos/ASIN/0138222290/kirupacom">Absolute Beginner&#8217;s Guide to Algorithms</a> book is just what you (or a friend) will need.</p><p>You can catch all of his online content at <a href="http://kirupa.com">KIRUPA.com</a> and his <a href="https://www.kirupa.chat">newsletter</a>.</p><div><hr></div><p>I launched <strong>Design, Build, Scale</strong> (newsletter series exclusive to PAID subscribers).</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://newsletter.systemdesign.one/subscribe?yearly=true" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!jG0C!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63fca468-adce-4713-97a0-203c35bc1c60_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!jG0C!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63fca468-adce-4713-97a0-203c35bc1c60_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!jG0C!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63fca468-adce-4713-97a0-203c35bc1c60_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!jG0C!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63fca468-adce-4713-97a0-203c35bc1c60_1200x630.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!jG0C!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63fca468-adce-4713-97a0-203c35bc1c60_1200x630.png" width="1200" height="630" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/63fca468-adce-4713-97a0-203c35bc1c60_1200x630.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:630,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:null,&quot;href&quot;:&quot;https://newsletter.systemdesign.one/subscribe?yearly=true&quot;,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/179076610?img=https%3A%2F%2Fsubstackcdn.com%2Fimage%2Ffetch%2F%24s_%21jG0C%21%2Cf_auto%2Cq_auto%3Agood%2Cfl_progressive%3Asteep%2Fhttps%253A%252F%252Fsubstack-post-media.s3.amazonaws.com%252Fpublic%252Fimages%252F63fca468-adce-4713-97a0-203c35bc1c60_1200x630.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!jG0C!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63fca468-adce-4713-97a0-203c35bc1c60_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!jG0C!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63fca468-adce-4713-97a0-203c35bc1c60_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!jG0C!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63fca468-adce-4713-97a0-203c35bc1c60_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!jG0C!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63fca468-adce-4713-97a0-203c35bc1c60_1200x630.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 you upgrade, you&#8217;ll get:</p><ul><li><p><strong>High-level architecture of real-world systems.</strong></p></li><li><p>Deep dive into how popular real-world systems actually work.</p></li><li><p><strong>How real-world systems handle scale, reliability, and performance.</strong></p></li><li><p>10x the results you currently get with 1/10th of your time, energy, and effort.</p></li></ul><p><strong>&#128073; <a href="https://newsletter.systemdesign.one/subscribe?yearly=true">CLICK HERE TO ACCESS DESIGN, BUILD, SCALE!</a></strong></p><div><hr></div><p>If you find this newsletter valuable, share it with a friend, and subscribe if you haven&#8217;t already. There are <a href="http://newsletter.systemdesign.one/subscribe?group=true">group discounts</a>, <a href="http://newsletter.systemdesign.one/subscribe?gift=true">gift options</a>, and <a href="https://newsletter.systemdesign.one/leaderboard">referral rewards</a> available.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/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://newsletter.systemdesign.one/subscribe?"><span>Subscribe now</span></a></p><div><hr></div><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://www.linkedin.com/in/nk-systemdesign-one/" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!bEFk!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 424w, https://substackcdn.com/image/fetch/$s_!bEFk!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 848w, https://substackcdn.com/image/fetch/$s_!bEFk!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 1272w, https://substackcdn.com/image/fetch/$s_!bEFk!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!bEFk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png" width="152" height="152" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:320,&quot;width&quot;:320,&quot;resizeWidth&quot;:152,&quot;bytes&quot;:74009,&quot;alt&quot;:&quot;Author Neo Kim; System design case studies&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:&quot;https://www.linkedin.com/in/nk-systemdesign-one/&quot;,&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="Author Neo Kim; System design case studies" title="Author Neo Kim; System design case studies" srcset="https://substackcdn.com/image/fetch/$s_!bEFk!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 424w, https://substackcdn.com/image/fetch/$s_!bEFk!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 848w, https://substackcdn.com/image/fetch/$s_!bEFk!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 1272w, https://substackcdn.com/image/fetch/$s_!bEFk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption"><strong>&#128075; Find me on <a href="https://www.linkedin.com/in/nk-systemdesign-one/">LinkedIn</a> | <a href="https://x.com/intent/follow?screen_name=systemdesignone">Twitter</a> | <a href="https://www.threads.net/@systemdesignone">Threads</a> | <a href="https://www.instagram.com/systemdesignone/">Instagram</a></strong></figcaption></figure></div><div><hr></div><p><strong>Want to reach 200K+ tech professionals at scale? </strong>&#128240;</p><p>If your company wants to reach 200K+ tech professionals, <a href="https://newsletter.systemdesign.one/p/sponsorship">advertise with me</a>.</p><div><hr></div><p>Thank you for supporting this newsletter.</p><p>You are now 200,001+ readers strong, very close to 201k. Let&#8217;s try to get 201k readers by 25 February. Consider sharing this post with your friends and get rewards.</p><p>Y&#8217;all are the best.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!6oWl!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!6oWl!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png 424w, https://substackcdn.com/image/fetch/$s_!6oWl!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png 848w, https://substackcdn.com/image/fetch/$s_!6oWl!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png 1272w, https://substackcdn.com/image/fetch/$s_!6oWl!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!6oWl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png" width="590" height="368.75" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2e739087-a910-4643-be36-997b6dd5b4af_800x500.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:500,&quot;width&quot;:800,&quot;resizeWidth&quot;:590,&quot;bytes&quot;:87878,&quot;alt&quot;:&quot;system design newsletter&quot;,&quot;title&quot;:&quot;system design newsletter&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/163380418?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="system design newsletter" title="system design newsletter" srcset="https://substackcdn.com/image/fetch/$s_!6oWl!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png 424w, https://substackcdn.com/image/fetch/$s_!6oWl!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png 848w, https://substackcdn.com/image/fetch/$s_!6oWl!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png 1272w, https://substackcdn.com/image/fetch/$s_!6oWl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.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 class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/p/timsort-algorithm?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesign.one/p/timsort-algorithm?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</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>If you aren&#8217;t familiar with quicksort, glance through <a href="https://www.kirupa.com/sorts/quicksort.htm">this deep dive</a>.</p><p></p></div></div>]]></content:encoded></item><item><title><![CDATA[I struggled with system design until I learned these 114 concepts]]></title><description><![CDATA[#122: Part 2 - websockets, gateway, distributed cache, and 35 others.]]></description><link>https://newsletter.systemdesign.one/p/system-design-core-concepts</link><guid isPermaLink="false">https://newsletter.systemdesign.one/p/system-design-core-concepts</guid><dc:creator><![CDATA[Neo Kim]]></dc:creator><pubDate>Sat, 14 Feb 2026 16:20:26 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/e9e8cf9a-93be-4a9c-9512-1d9cdb098857_1280x720.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/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">Get my system design playbook for FREE on newsletter signup:</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><ul><li><p><em><a href="https://newsletter.systemdesign.one/p/system-design-core-concepts/?action=share">Share this post</a> &amp; I'll send you some rewards for the referrals.</em></p></li><li><p><em>Block diagrams created using <a href="https://app.eraser.io/auth/sign-up?ref=neo">Eraser</a>.</em></p></li></ul><div><hr></div><p>Onwards 'n downwards:</p><p>Following is the second of a premium 3-part newsletter series&#8230; If you&#8217;re just getting started with system design or want a super strong foundation, then this newsletter is for you.</p><p>On with part 2 of the newsletter:</p><p>===</p><p>Some of these are foundational, and some are quite advanced. ALL of them are super useful to software engineers building distributed systems&#8230;</p><p>Curious to know how many were new to you:</p><ol start="39"><li><p>WebSockets</p></li><li><p>API Gateways</p></li><li><p>Distributed Cache</p></li><li><p>Cache Eviction Policies</p></li><li><p>Proxy vs Reverse Proxy</p></li><li><p>HTTP vs HTTPS</p></li><li><p>TCP vs UDP</p></li><li><p>OSI Model</p></li><li><p>TLS/SSL</p></li><li><p>DNS Load Balancing</p></li><li><p>Anycast Routing</p></li><li><p>Object Storage</p></li><li><p>Distributed File Systems</p></li><li><p>Block vs File vs Object Storage</p></li><li><p>Data Compression</p></li><li><p>ACID vs BASE</p></li><li><p>Network Partitions</p></li><li><p>Split-Brain Problem</p></li><li><p>Heartbeats</p></li><li><p>Leader Election</p></li><li><p>Consensus Algorithms</p></li><li><p>Quorum</p></li><li><p>Paxos Algorithm</p></li><li><p>Raft Algorithm</p></li><li><p>Gossip Protocol</p></li><li><p>Clock Synchronization Problem</p></li><li><p>Logical Clocks</p></li><li><p>Lamport Timestamps</p></li><li><p>Vector Clocks</p></li><li><p>Distributed Transactions</p></li><li><p>Two-Phase Commit</p></li><li><p>SAGA Pattern</p></li><li><p>Outbox Pattern</p></li><li><p>Three-Phase Commit</p></li><li><p>Delivery Semantics</p></li><li><p>Change Data Capture</p></li><li><p>Long Polling</p></li><li><p>Server-Sent Events</p></li></ol><p>(&#8230;and much more in part 3!)</p><p>For each, I&#8217;ll share:</p><ul><li><p>What it is &amp; how it works--in simple words</p></li><li><p>A real-world analogy</p></li><li><p>Tradeoffs</p></li><li><p>Why it matters</p></li></ul><p>Let&#8217;s go.</p><div><hr></div><h3><strong><a href="https://getunblocked.com/code-review/?utm_source=systemdesign&amp;utm_medium=email&amp;utm_campaign=codereview&amp;utm_content=context">AI code review with your team&#8217;s knowledge (Partner)</a></strong></h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://getunblocked.com/code-review/?utm_source=systemdesign&amp;utm_medium=email&amp;utm_campaign=codereview&amp;utm_content=context" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ui-Q!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6649d8e-d6ef-477e-baab-c8cbe718c0f7_2880x2160.png 424w, https://substackcdn.com/image/fetch/$s_!ui-Q!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6649d8e-d6ef-477e-baab-c8cbe718c0f7_2880x2160.png 848w, https://substackcdn.com/image/fetch/$s_!ui-Q!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6649d8e-d6ef-477e-baab-c8cbe718c0f7_2880x2160.png 1272w, https://substackcdn.com/image/fetch/$s_!ui-Q!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6649d8e-d6ef-477e-baab-c8cbe718c0f7_2880x2160.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ui-Q!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6649d8e-d6ef-477e-baab-c8cbe718c0f7_2880x2160.png" width="728" height="546" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c6649d8e-d6ef-477e-baab-c8cbe718c0f7_2880x2160.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1092,&quot;width&quot;:1456,&quot;resizeWidth&quot;:728,&quot;bytes&quot;:2518565,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:&quot;https://getunblocked.com/code-review/?utm_source=systemdesign&amp;utm_medium=email&amp;utm_campaign=codereview&amp;utm_content=context&quot;,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/184952460?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6649d8e-d6ef-477e-baab-c8cbe718c0f7_2880x2160.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!ui-Q!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6649d8e-d6ef-477e-baab-c8cbe718c0f7_2880x2160.png 424w, https://substackcdn.com/image/fetch/$s_!ui-Q!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6649d8e-d6ef-477e-baab-c8cbe718c0f7_2880x2160.png 848w, https://substackcdn.com/image/fetch/$s_!ui-Q!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6649d8e-d6ef-477e-baab-c8cbe718c0f7_2880x2160.png 1272w, https://substackcdn.com/image/fetch/$s_!ui-Q!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc6649d8e-d6ef-477e-baab-c8cbe718c0f7_2880x2160.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><a href="https://getunblocked.com/code-review/?utm_source=systemdesign&amp;utm_medium=email&amp;utm_campaign=codereview&amp;utm_content=context">Unblocked</a></strong> is the only AI code review tool that has a deep understanding of your codebase, docs, and past decisions, giving you thoughtful feedback that feels like it came from your best engineer.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://getunblocked.com/code-review/?utm_source=systemdesign&amp;utm_medium=email&amp;utm_campaign=codereview&amp;utm_content=context&quot;,&quot;text&quot;:&quot;Try Right Now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://getunblocked.com/code-review/?utm_source=systemdesign&amp;utm_medium=email&amp;utm_campaign=codereview&amp;utm_content=context"><span>Try Right Now</span></a></p><div><hr></div><h2><strong>39. WebSockets</strong></h2><blockquote><p>WebSockets provide full-duplex, bidirectional communication between client &amp; server over a single, long-lived TCP connection.</p></blockquote><p>Unlike HTTP, where the client always initiates requests, WebSockets allow the server to push data to clients in real-time.</p><p>After an initial HTTP handshake, the connection upgrades to the WebSocket protocol. Both the client and the server can then send messages at any 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_!LcJZ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F400c4e99-1830-4f1d-86b1-3f518e5778ba_790x368.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!LcJZ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F400c4e99-1830-4f1d-86b1-3f518e5778ba_790x368.png 424w, https://substackcdn.com/image/fetch/$s_!LcJZ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F400c4e99-1830-4f1d-86b1-3f518e5778ba_790x368.png 848w, https://substackcdn.com/image/fetch/$s_!LcJZ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F400c4e99-1830-4f1d-86b1-3f518e5778ba_790x368.png 1272w, https://substackcdn.com/image/fetch/$s_!LcJZ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F400c4e99-1830-4f1d-86b1-3f518e5778ba_790x368.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!LcJZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F400c4e99-1830-4f1d-86b1-3f518e5778ba_790x368.png" width="790" height="368" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/400c4e99-1830-4f1d-86b1-3f518e5778ba_790x368.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:368,&quot;width&quot;:790,&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_!LcJZ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F400c4e99-1830-4f1d-86b1-3f518e5778ba_790x368.png 424w, https://substackcdn.com/image/fetch/$s_!LcJZ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F400c4e99-1830-4f1d-86b1-3f518e5778ba_790x368.png 848w, https://substackcdn.com/image/fetch/$s_!LcJZ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F400c4e99-1830-4f1d-86b1-3f518e5778ba_790x368.png 1272w, https://substackcdn.com/image/fetch/$s_!LcJZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F400c4e99-1830-4f1d-86b1-3f518e5778ba_790x368.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>Analogy</h3><p>WebSockets is like a phone call where both people can talk and listen simultaneously&#8230;</p><p>Compare this to HTTP, which is like sending letters back and forth,,, where you wait for a reply before sending the next message.</p><h3>Tradeoff</h3><p>They&#8217;re more complex to implement and scale since each connection consumes server resources. Also, load balancing becomes tricky because connections are long-lived and stateful.</p><p>Plus, some proxies/firewalls &#8220;block&#8221; WebSocket upgrades or long-lived connections, so compatibility can vary.</p><h3>Why it matters</h3><p>Use for real-time apps like chat systems, live sports scores, collaborative editing, online gaming, or stock trading platforms. But avoid for simple request-response patterns where HTTP is enough.</p><h2><strong>40. API Gateways</strong></h2><blockquote><p>An API gateway is a server that acts as a SINGLE entry point for all client requests to your microservices.</p></blockquote><p>It handles request routing, composition, and protocol translation<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a>. Instead of clients calling different microservices directly, they make &#8216;one call&#8217; to the gateway.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Zckl!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3999e1d-12ec-4bff-a0cd-8f7f9e188beb_872x275.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Zckl!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3999e1d-12ec-4bff-a0cd-8f7f9e188beb_872x275.png 424w, https://substackcdn.com/image/fetch/$s_!Zckl!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3999e1d-12ec-4bff-a0cd-8f7f9e188beb_872x275.png 848w, https://substackcdn.com/image/fetch/$s_!Zckl!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3999e1d-12ec-4bff-a0cd-8f7f9e188beb_872x275.png 1272w, https://substackcdn.com/image/fetch/$s_!Zckl!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3999e1d-12ec-4bff-a0cd-8f7f9e188beb_872x275.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Zckl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3999e1d-12ec-4bff-a0cd-8f7f9e188beb_872x275.png" width="872" height="275" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d3999e1d-12ec-4bff-a0cd-8f7f9e188beb_872x275.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:275,&quot;width&quot;:872,&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_!Zckl!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3999e1d-12ec-4bff-a0cd-8f7f9e188beb_872x275.png 424w, https://substackcdn.com/image/fetch/$s_!Zckl!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3999e1d-12ec-4bff-a0cd-8f7f9e188beb_872x275.png 848w, https://substackcdn.com/image/fetch/$s_!Zckl!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3999e1d-12ec-4bff-a0cd-8f7f9e188beb_872x275.png 1272w, https://substackcdn.com/image/fetch/$s_!Zckl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3999e1d-12ec-4bff-a0cd-8f7f9e188beb_872x275.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>Analogy</h3><p>An API gateway is like a hotel concierge:</p><p>Instead of guests figuring out which department to call, they call the concierge desk. The concierge knows which department to contact and gets back to the guest with answers.</p><h3>Tradeoff</h3><p>They can become a bottleneck or a single point of failure if not deployed redundantly. Besides, they increase latency because of the extra network hop. So the gateway itself needs to scale &amp; be highly available.</p><h3>Why it matters</h3><p>Useful in microservices because it provides clients with a single entry point.</p><p>Also, it handles common tasks like authentication, authorization, and rate limiting in one place, and can return different responses for different clients, such as web or mobile apps.</p><h2><strong>41. Distributed Cache</strong></h2><blockquote><p>Distributed cache spreads cached data across many cache servers instead of a single cache instance.</p></blockquote><p>Each cache node stores a portion of the data, typically determined by consistent hashing<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-2" href="#footnote-2" target="_self">2</a>. Popular implementations include Redis Cluster and Memcached.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!qZFX!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5121717e-5e70-44e9-bfec-e5265c39027d_1600x501.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!qZFX!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5121717e-5e70-44e9-bfec-e5265c39027d_1600x501.png 424w, https://substackcdn.com/image/fetch/$s_!qZFX!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5121717e-5e70-44e9-bfec-e5265c39027d_1600x501.png 848w, https://substackcdn.com/image/fetch/$s_!qZFX!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5121717e-5e70-44e9-bfec-e5265c39027d_1600x501.png 1272w, https://substackcdn.com/image/fetch/$s_!qZFX!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5121717e-5e70-44e9-bfec-e5265c39027d_1600x501.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!qZFX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5121717e-5e70-44e9-bfec-e5265c39027d_1600x501.png" width="1456" height="456" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5121717e-5e70-44e9-bfec-e5265c39027d_1600x501.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:456,&quot;width&quot;:1456,&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_!qZFX!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5121717e-5e70-44e9-bfec-e5265c39027d_1600x501.png 424w, https://substackcdn.com/image/fetch/$s_!qZFX!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5121717e-5e70-44e9-bfec-e5265c39027d_1600x501.png 848w, https://substackcdn.com/image/fetch/$s_!qZFX!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5121717e-5e70-44e9-bfec-e5265c39027d_1600x501.png 1272w, https://substackcdn.com/image/fetch/$s_!qZFX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5121717e-5e70-44e9-bfec-e5265c39027d_1600x501.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>Analogy</h3><p>Multiple fast-food locations across a city instead of one central kitchen.</p><p>Each location stores popular items for quick service. Total capacity increases by opening more locations, and no single location becomes overwhelmed during rush hour.</p><h3>Tradeoff</h3><p>They add operational complexity (partitioning, rebalancing, replication) and can incur overhead during rebalancing/failover. Also, there&#8217;s a risk of cache misses when keys get redistributed.</p><p>Plus, debugging becomes harder with many nodes.</p><h3>Why it matters</h3><p>Use a distributed cache in high-traffic sites when one cache server can&#8217;t handle the traffic, when the data no longer fits in one machine&#8217;s memory, or when you need high availability.</p><p>Start with a single cache server&#8230;Move to a distributed cache setup only when you reach scaling or reliability limits.</p><h2><strong>42. Cache Eviction Policies</strong></h2><blockquote><p>Cache eviction policies decide which data to remove when the cache is full and new data needs space.</p></blockquote><ul><li><p>Least Recently Used (<strong>LRU</strong>) removes the data that has NOT been accessed for the longest time.</p></li><li><p>Least Frequently Used (<strong>LFU</strong>) removes the data that is accessed the least often.</p></li><li><p>First In, First Out (<strong>FIFO</strong>) removes the oldest data first, based on when it was added.</p></li><li><p>Time To Live (<strong>TTL</strong>) automatically removes data after a fixed time period.</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_!OFUU!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2c99482-eb4a-4248-a6bc-d113ab177dd5_813x370.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!OFUU!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2c99482-eb4a-4248-a6bc-d113ab177dd5_813x370.png 424w, https://substackcdn.com/image/fetch/$s_!OFUU!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2c99482-eb4a-4248-a6bc-d113ab177dd5_813x370.png 848w, https://substackcdn.com/image/fetch/$s_!OFUU!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2c99482-eb4a-4248-a6bc-d113ab177dd5_813x370.png 1272w, https://substackcdn.com/image/fetch/$s_!OFUU!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2c99482-eb4a-4248-a6bc-d113ab177dd5_813x370.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!OFUU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2c99482-eb4a-4248-a6bc-d113ab177dd5_813x370.png" width="813" height="370" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d2c99482-eb4a-4248-a6bc-d113ab177dd5_813x370.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:370,&quot;width&quot;:813,&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_!OFUU!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2c99482-eb4a-4248-a6bc-d113ab177dd5_813x370.png 424w, https://substackcdn.com/image/fetch/$s_!OFUU!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2c99482-eb4a-4248-a6bc-d113ab177dd5_813x370.png 848w, https://substackcdn.com/image/fetch/$s_!OFUU!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2c99482-eb4a-4248-a6bc-d113ab177dd5_813x370.png 1272w, https://substackcdn.com/image/fetch/$s_!OFUU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2c99482-eb4a-4248-a6bc-d113ab177dd5_813x370.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>Analogy</h3><p>Think of your phone storage:</p><ul><li><p>LRU deletes photos you haven&#8217;t opened in a long time.</p></li><li><p>LFU deletes photos you rarely look at.</p></li><li><p>FIFO deletes the oldest photos first.</p></li><li><p>TTL is like a message that automatically disappears after 24 hours.</p></li></ul><h3>Tradeoff</h3><p>Different policies work well for different access patterns&#8230;</p><ul><li><p>LRU works well when recently accessed data is likely to be used again. Yet it can perform poorly if large amounts of data are accessed only once.</p></li><li><p>LFU works well when frequently accessed data stays popular over time, but it reacts slowly if usage patterns change.</p></li><li><p>FIFO is simple but does not consider how often or recently data is used.</p></li><li><p>TTL ensures data does not stay in the cache forever, but it may remove useful data too early or keep stale data too long.</p></li></ul><p>Each policy has overhead in tracking metadata for eviction decisions.</p><h3>Why it matters</h3><p>Use:</p><ul><li><p>LRU for general-purpose caching where recent data is likely to be reused.</p></li><li><p>LFU when certain data remains popular for long periods.</p></li><li><p>TTL when data naturally becomes stale after some time, such as API responses or session data.</p></li></ul><p>Most systems combine TTL with LRU or LFU.</p><h2><strong>43. Proxy vs Reverse Proxy</strong></h2><blockquote><p>A forward proxy sits between clients and the Internet. It sends requests to external servers on behalf of the client.</p><p>A reverse proxy sits in front of your servers. It receives requests from clients and forwards them to the correct backend server.</p></blockquote><p>With a forward proxy, client is configured to use it. With a reverse proxy, the client usually doesn&#8217;t know it exists.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!tDrX!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf7a4905-c791-4215-a8f3-f22ea30cde09_1536x1024.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!tDrX!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf7a4905-c791-4215-a8f3-f22ea30cde09_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!tDrX!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf7a4905-c791-4215-a8f3-f22ea30cde09_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!tDrX!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf7a4905-c791-4215-a8f3-f22ea30cde09_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!tDrX!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf7a4905-c791-4215-a8f3-f22ea30cde09_1536x1024.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!tDrX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf7a4905-c791-4215-a8f3-f22ea30cde09_1536x1024.png" width="1456" height="971" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bf7a4905-c791-4215-a8f3-f22ea30cde09_1536x1024.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:971,&quot;width&quot;:1456,&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_!tDrX!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf7a4905-c791-4215-a8f3-f22ea30cde09_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!tDrX!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf7a4905-c791-4215-a8f3-f22ea30cde09_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!tDrX!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf7a4905-c791-4215-a8f3-f22ea30cde09_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!tDrX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf7a4905-c791-4215-a8f3-f22ea30cde09_1536x1024.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>Analogy</h3><p>A forward proxy is like an assistant who makes calls for you, so the person on the other end doesn&#8217;t talk with you directly.</p><p>A reverse proxy is like a company receptionist. Callers think they are contacting the company directly,,, but the receptionist routes the call internally.</p><h3>Tradeoff</h3><p>Forward proxies can improve privacy, enforce security policies, and filter traffic. Yet they add extra network hops and can increase latency.</p><p>Reverse proxies provide load balancing, SSL termination, caching, and protection from direct exposure of backend servers. But they must be deployed redundantly to avoid becoming a single point of failure.</p><p>Both require proper configuration to prevent security risks&#8230;</p><h3>Why it matters</h3><ul><li><p>Use forward proxies in corporate networks for content filtering, monitoring &amp; privacy control.</p></li><li><p>Use reverse proxies in production systems for load balancing, SSL termination, traffic routing, and protection against attacks<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-3" href="#footnote-3" target="_self">3</a>.</p></li></ul><p>Most apps use reverse proxies such as Nginx, HAProxy, or cloud load balancers.</p><h2><strong>44. HTTP vs HTTPS</strong></h2><blockquote><p>Hypertext Transfer Protocol (HTTP) sends data in &#8216;plain text&#8217;.</p><p>Hypertext Transfer Protocol Secure (HTTPS) is HTTP encrypted using Transport Layer Security (TLS).</p></blockquote><p>HTTPS encrypts communication between the client and server, protecting data from eavesdropping and tampering. The server provides a certificate to prove its identity. Modern browsers mark HTTP sites as &#8220;Not Secure.&#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_!lv4n!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dd9c4b4-741b-47b0-a218-98bda88e90fd_859x428.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!lv4n!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dd9c4b4-741b-47b0-a218-98bda88e90fd_859x428.png 424w, https://substackcdn.com/image/fetch/$s_!lv4n!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dd9c4b4-741b-47b0-a218-98bda88e90fd_859x428.png 848w, https://substackcdn.com/image/fetch/$s_!lv4n!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dd9c4b4-741b-47b0-a218-98bda88e90fd_859x428.png 1272w, https://substackcdn.com/image/fetch/$s_!lv4n!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dd9c4b4-741b-47b0-a218-98bda88e90fd_859x428.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!lv4n!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dd9c4b4-741b-47b0-a218-98bda88e90fd_859x428.png" width="859" height="428" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9dd9c4b4-741b-47b0-a218-98bda88e90fd_859x428.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:428,&quot;width&quot;:859,&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_!lv4n!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dd9c4b4-741b-47b0-a218-98bda88e90fd_859x428.png 424w, https://substackcdn.com/image/fetch/$s_!lv4n!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dd9c4b4-741b-47b0-a218-98bda88e90fd_859x428.png 848w, https://substackcdn.com/image/fetch/$s_!lv4n!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dd9c4b4-741b-47b0-a218-98bda88e90fd_859x428.png 1272w, https://substackcdn.com/image/fetch/$s_!lv4n!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dd9c4b4-741b-47b0-a218-98bda88e90fd_859x428.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>Analogy</h3><p>HTTP is like sending a postcard. Anyone who intercepts it can read the message.</p><p>HTTPS is like sending a sealed, locked box. Even if someone intercepts it, they cannot read or change what&#8217;s inside.</p><h3>Tradeoff</h3><p>HTTPS requires managing digital certificates and adds a small performance cost because of the TLS handshake. Yet these costs are minimal compared to the security benefits.</p><h3>Why it matters</h3><p>HTTPS protects against eavesdropping and man-in-the-middle attacks, where attackers intercept or modify traffic.</p><p>HTTPS is also a positive ranking factor for search engines and is required for many modern web features, such as HTTP/2, service workers, and secure cookies.</p><h2><strong>45. TCP vs UDP</strong></h2><blockquote><p>Transmission Control Protocol (TCP) is a connection-oriented protocol that provides reliable, ordered delivery of data.</p><p>User Datagram Protocol (UDP) is connectionless and sends packets without guaranteeing delivery, order, or protection against duplication.</p></blockquote><p>TCP establishes a connection using a handshake, retransmits lost packets, and performs congestion control.</p><p>UDP sends packets independently with minimal overhead &amp; no built-in reliability. i.e., UDP is faster but less reliable.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!oc0S!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6888b2b1-b192-445f-ac3a-2d404b932f74_1086x631.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!oc0S!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6888b2b1-b192-445f-ac3a-2d404b932f74_1086x631.png 424w, https://substackcdn.com/image/fetch/$s_!oc0S!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6888b2b1-b192-445f-ac3a-2d404b932f74_1086x631.png 848w, https://substackcdn.com/image/fetch/$s_!oc0S!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6888b2b1-b192-445f-ac3a-2d404b932f74_1086x631.png 1272w, https://substackcdn.com/image/fetch/$s_!oc0S!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6888b2b1-b192-445f-ac3a-2d404b932f74_1086x631.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!oc0S!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6888b2b1-b192-445f-ac3a-2d404b932f74_1086x631.png" width="1086" height="631" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6888b2b1-b192-445f-ac3a-2d404b932f74_1086x631.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:631,&quot;width&quot;:1086,&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_!oc0S!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6888b2b1-b192-445f-ac3a-2d404b932f74_1086x631.png 424w, https://substackcdn.com/image/fetch/$s_!oc0S!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6888b2b1-b192-445f-ac3a-2d404b932f74_1086x631.png 848w, https://substackcdn.com/image/fetch/$s_!oc0S!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6888b2b1-b192-445f-ac3a-2d404b932f74_1086x631.png 1272w, https://substackcdn.com/image/fetch/$s_!oc0S!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6888b2b1-b192-445f-ac3a-2d404b932f74_1086x631.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>Analogy</h3><p>TCP is like certified mail with tracking and delivery confirmation.</p><p>UDP is like sending postcards. They usually arrive, but they might be lost or arrive out of order&#8230;</p><h3>Tradeoff</h3><p>TCP adds latency due to the handshake, acknowledgments, retransmissions, and head-of-line blocking (where a lost packet delays subsequent packets).</p><p>UDP doesn&#8217;t guarantee delivery or order. If reliability is needed,,, the application code must handle it.</p><h3>Why it matters</h3><ul><li><p>Use TCP for web browsing, email, file transfers, database connections, and APIs where accuracy matters more than speed.</p></li><li><p>Use UDP for real-time applications such as video calls, live streaming, and online gaming, where low latency is more important than reliability.</p></li></ul><p>NOTE: DNS typically uses UDP for speed, but it can fall back to TCP for large responses or specific operations.</p><div><hr></div><p><em><strong>Reminder: this is a teaser of the subscriber-only post, exclusive to my golden members.</strong></em></p><p>When you upgrade, you&#8217;ll get:</p><ul><li><p><strong>Full access to system design case studies</strong></p></li><li><p>FREE access to (coming) Design, Build, Scale newsletter series</p></li><li><p><strong>FREE access to (coming) popular interview question breakdowns</strong></p></li></ul><p>And more!</p><p>Get 10x the results you currently get with 1/10th the time, energy &amp; effort.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/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://newsletter.systemdesign.one/subscribe?"><span>Subscribe now</span></a></p>
      <p>
          <a href="https://newsletter.systemdesign.one/p/system-design-core-concepts">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Behavioral Interview Playbook for Software Engineers]]></title><description><![CDATA[#121: Proven strategies to ace behavioral interviews]]></description><link>https://newsletter.systemdesign.one/p/common-behavioral-interview-questions</link><guid isPermaLink="false">https://newsletter.systemdesign.one/p/common-behavioral-interview-questions</guid><dc:creator><![CDATA[Prasad Rao]]></dc:creator><pubDate>Thu, 12 Feb 2026 09:21:25 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/9cbd9776-19e8-49bd-b7ca-da811d09259e_1280x720.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/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">Get my system design playbook for FREE on newsletter signup:</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><ul><li><p><em><a href="https://newsletter.systemdesign.one/p/common-behavioral-interview-questions/?action=share">Share this post</a> &amp; I'll send you some rewards for the referrals.</em></p></li></ul><div><hr></div><p>You&#8217;ve prepared for the technical interview&#8230;You&#8217;ve solved the system design problem&#8230;You&#8217;ve written clean code&#8230;</p><p>Yet the hiring decision often comes down to something completely different: &#8220;your behavioral interview&#8221;.</p><p>This is the conversation where the interviewer asks, <em>&#8220;Tell me about a time when you disagreed with your manager,&#8221;</em> or <em>&#8220;Describe a situation where you had to make a decision with incomplete information.&#8221;</em></p><p>It&#8217;s where they assess not just what you can build, but how you work, how you think, and how you&#8217;ll show up in their organization.</p><p>Onward.</p><div><hr></div><h3><a href="https://serpapi.com/?utm_source=thesystemdesignnewsletter">Need public web data, without scraper headaches? (Partner)</a></h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://serpapi.com/?utm_source=thesystemdesignnewsletter" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!lbaQ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcfe5b26-34f1-4da5-a1b8-e7a785c44bc7_1750x734.png 424w, https://substackcdn.com/image/fetch/$s_!lbaQ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcfe5b26-34f1-4da5-a1b8-e7a785c44bc7_1750x734.png 848w, https://substackcdn.com/image/fetch/$s_!lbaQ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcfe5b26-34f1-4da5-a1b8-e7a785c44bc7_1750x734.png 1272w, https://substackcdn.com/image/fetch/$s_!lbaQ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcfe5b26-34f1-4da5-a1b8-e7a785c44bc7_1750x734.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!lbaQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcfe5b26-34f1-4da5-a1b8-e7a785c44bc7_1750x734.png" width="1456" height="611" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fcfe5b26-34f1-4da5-a1b8-e7a785c44bc7_1750x734.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:611,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:376428,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:&quot;https://serpapi.com/?utm_source=thesystemdesignnewsletter&quot;,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/180977546?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcfe5b26-34f1-4da5-a1b8-e7a785c44bc7_1750x734.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!lbaQ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcfe5b26-34f1-4da5-a1b8-e7a785c44bc7_1750x734.png 424w, https://substackcdn.com/image/fetch/$s_!lbaQ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcfe5b26-34f1-4da5-a1b8-e7a785c44bc7_1750x734.png 848w, https://substackcdn.com/image/fetch/$s_!lbaQ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcfe5b26-34f1-4da5-a1b8-e7a785c44bc7_1750x734.png 1272w, https://substackcdn.com/image/fetch/$s_!lbaQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcfe5b26-34f1-4da5-a1b8-e7a785c44bc7_1750x734.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><a href="https://serpapi.com/?utm_source=thesystemdesignnewsletter">SerpApi</a></strong> turns search results into predictable JSON with built-in scale, location options, and protection from blocks.</p><p>That&#8217;s why engineers use it to ship:</p><ul><li><p>AI applications</p></li><li><p>Product research</p></li><li><p>Price tracking</p></li><li><p>SEO insights</p></li></ul><p>All without maintaining scrapers or infrastructure.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://serpapi.com/?utm_source=thesystemdesignnewsletter&quot;,&quot;text&quot;:&quot;Try For Free&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://serpapi.com/?utm_source=thesystemdesignnewsletter"><span>Try For Free</span></a></p><div><hr></div><p>I want to introduce <a href="https://www.linkedin.com/in/kprasadrao/">Prasad Rao</a> as a guest author.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://www.linkedin.com/in/kprasadrao/" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!4OPV!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd36e6733-9640-42fb-bbda-d1f167eda53a_1090x549.jpeg 424w, https://substackcdn.com/image/fetch/$s_!4OPV!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd36e6733-9640-42fb-bbda-d1f167eda53a_1090x549.jpeg 848w, https://substackcdn.com/image/fetch/$s_!4OPV!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd36e6733-9640-42fb-bbda-d1f167eda53a_1090x549.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!4OPV!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd36e6733-9640-42fb-bbda-d1f167eda53a_1090x549.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!4OPV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd36e6733-9640-42fb-bbda-d1f167eda53a_1090x549.jpeg" width="1090" height="549" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d36e6733-9640-42fb-bbda-d1f167eda53a_1090x549.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:549,&quot;width&quot;:1090,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:&quot;https://www.linkedin.com/in/kprasadrao/&quot;,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!4OPV!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd36e6733-9640-42fb-bbda-d1f167eda53a_1090x549.jpeg 424w, https://substackcdn.com/image/fetch/$s_!4OPV!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd36e6733-9640-42fb-bbda-d1f167eda53a_1090x549.jpeg 848w, https://substackcdn.com/image/fetch/$s_!4OPV!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd36e6733-9640-42fb-bbda-d1f167eda53a_1090x549.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!4OPV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd36e6733-9640-42fb-bbda-d1f167eda53a_1090x549.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>He is a Principal Solutions Architect and co-founder of a FREE group mentoring initiative, <a href="https://besaprogram.com/">BeSA - Become a Solutions Architect</a> to help people excel in their cloud and AI careers. The next free mentoring cohort starts on 21 Feb and focuses on <a href="https://docs.google.com/forms/d/e/1FAIpQLSfL8KVlGXbQo8Ib8BdHh-meXYUsmy1xxu15r9hT5nZrSC5pXQ/viewform">Agentic AI on AWS</a>.</p><p>Check out his LinkedIn, newsletter, and offerings:</p><ul><li><p><strong><a href="https://www.linkedin.com/in/kprasadrao/">LinkedIn</a></strong></p></li><li><p><a href="https://newsletter.bigtechcareers.com/">Big Tech Careers</a> (flagship newsletter to develop your behavioral skills)</p></li><li><p><strong><a href="https://bigtechcareers.mykajabi.com/">Big Tech Interview preparation course</a></strong> - If you&#8217;re preparing for interviews, I highly recommend this course as it focuses specifically on behavioral interviews, setting it apart from other courses. You can use code NEO25 for 25% off.</p></li></ul><div><hr></div><h1>Why Behavioral Interviews Matter</h1><p>Let&#8217;s dive in!</p><p>Ask any experienced interviewer at Big Tech why candidates fail their interviews.</p><p>Their #1 reason is consistent:</p><blockquote><p><em>&#8220;Smart technical professionals who can&#8217;t clearly articulate their past work. They ramble too much, miss the main points, and can&#8217;t explain their decision-making process.&#8221;</em></p></blockquote><p>For many engineers, this feels unfair&#8230;</p><p>You&#8217;re hired to write code, not to tell stories. But behavioral interviews exist for a reason, and understanding that reason changes everything about how you prepare.</p><h4><strong>What We Mean by Behavioral Skills</strong></h4><p>Before we dive deeper, let&#8217;s clarify what behavioral skills actually are:</p><p>These are your personal attributes and interpersonal abilities that shape how you work, interact with others, and approach challenges. Unlike technical skills, which are specific to a particular job or industry, behavioral skills are transferable across various roles and sectors.</p><p>You might be an exceptional backend Java programmer, but that skill won&#8217;t directly transfer to a data engineer role&#8230; Your ability to handle conflict, though? That transfers everywhere. Your capacity to make decisions with incomplete information? That applies in any organization.</p><p>This is why companies prioritize these skills.</p><h4><strong>Why Companies Care About Behavior</strong></h4><p>Technical skills are table stakes.</p><p>Any engineer applying to a senior role can solve problems and write decent code. What separates a senior engineer from a staff/principal engineer, or what prevents someone from getting stuck at the senior level for years? It&#8217;s how they operate in ambiguity, how they lead without authority, how they make decisions that affect hundreds of engineers, and how they communicate complexity to non-technical leaders.</p><p>These are behavioral competencies&#8230;and they&#8217;re harder to assess in a coding or system design interview.</p><p>The primary reason employers focus on behavioral skills is that past behavior is often the best predictor of future performance. This concept, known as <strong>&#8220;behavioral consistency,&#8221;</strong> is a fundamental principle in psychology and human resources.</p><blockquote><p><em>Behavioral consistency suggests that the way a person has behaved in the past is likely to be consistent with how they will behave in the future, especially in similar situations.</em></p></blockquote><p>By asking about how you&#8217;ve handled situations in the past, interviewers get a sense of how you&#8217;re likely to act in similar scenarios if hired.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!N_BC!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9601685a-6ec2-4dd4-a6ff-0ab405960198_1456x838.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!N_BC!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9601685a-6ec2-4dd4-a6ff-0ab405960198_1456x838.png 424w, https://substackcdn.com/image/fetch/$s_!N_BC!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9601685a-6ec2-4dd4-a6ff-0ab405960198_1456x838.png 848w, https://substackcdn.com/image/fetch/$s_!N_BC!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9601685a-6ec2-4dd4-a6ff-0ab405960198_1456x838.png 1272w, https://substackcdn.com/image/fetch/$s_!N_BC!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9601685a-6ec2-4dd4-a6ff-0ab405960198_1456x838.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!N_BC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9601685a-6ec2-4dd4-a6ff-0ab405960198_1456x838.png" width="1456" height="838" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9601685a-6ec2-4dd4-a6ff-0ab405960198_1456x838.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:838,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;: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_!N_BC!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9601685a-6ec2-4dd4-a6ff-0ab405960198_1456x838.png 424w, https://substackcdn.com/image/fetch/$s_!N_BC!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9601685a-6ec2-4dd4-a6ff-0ab405960198_1456x838.png 848w, https://substackcdn.com/image/fetch/$s_!N_BC!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9601685a-6ec2-4dd4-a6ff-0ab405960198_1456x838.png 1272w, https://substackcdn.com/image/fetch/$s_!N_BC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9601685a-6ec2-4dd4-a6ff-0ab405960198_1456x838.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>A behavioral interview is a risk-mitigation tool for the hiring manager.</p><blockquote><p>When they ask about a conflict you resolved, they&#8217;re trying to understand:</p><p><em>Do you listen?</em></p><p><em>Do you escalate appropriately?</em></p><p><em>Do you compromise or dig in?</em></p><p><em>Do you think about the other person&#8217;s perspective?</em></p></blockquote><p>For example, if you can describe a time when you successfully resolved a conflict with a manager, it suggests you&#8217;ll be able to handle such situations in the new role as well. This gives employers confidence in your ability to navigate workplace challenges.</p><p>If you&#8217;ve successfully led a team project in the past, you&#8217;re likely to demonstrate good leadership skills in future team projects. If you&#8217;ve shown creativity in solving problems at your previous job, you&#8217;re likely to bring that same innovative thinking to new challenges.</p><h4><strong>How Behavioral Interviews Evaluate Seniority</strong></h4><p>Here&#8217;s something most engineers don&#8217;t realize: same behavioral question is asked to candidates at different levels, but the bar changes dramatically.</p><p><em>Same question. Completely different answers. The difference is scope, self-awareness, and impact.</em></p><p>Interviewers check behavioral responses for key signs.</p><p>They want to see if you understand complexity. They also look for how well you&#8217;ve handled ambiguity. Learning from mistakes is important as well. Finally, you need to communicate all this clearly.</p><p>As you climb the ladder, they want to see that you can make decisions for larger groups. They look for your ability to influence others without authority. Also, they want to know if you consider the organization&#8217;s impact, not just technical correctness.</p><p>Behavioral interviews are a gating mechanism:</p><p>Companies use them to calibrate your level. Get them right, and you move up. Get them wrong, and you get downleveled&#8212;placed in a role one or two levels below what you applied for.</p><p>Downleveling happens when your behavioral responses don&#8217;t match the seniority you&#8217;re targeting. You may have the skills for a staff role, but your stories matter. If you sound junior&#8212;focusing on your own work instead of the impact, or lacking proof of handling uncertainty or influencing others&#8212;then you might get a senior role instead. Same company, same team, potentially 20-30% lower salary, and a much slower path to where you wanted to be.</p><p>This is why behavioral interviews matter more than most engineers realize. They&#8217;re not a soft skill afterthought. They&#8217;re the primary mechanism through which companies evaluate whether you&#8217;re ready for the level you&#8217;re targeting.</p><blockquote><p><em>Technical skills get you hired. Behavioral skills get you hired at the right level.</em></p></blockquote><div class="captioned-button-wrap" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/p/common-behavioral-interview-questions?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">Share this post &amp; earn rewards for referrals.</p></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/p/common-behavioral-interview-questions?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://newsletter.systemdesign.one/p/common-behavioral-interview-questions?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p></div><h4><strong>What This Playbook Will Do</strong></h4><p>Over the next few sections, you&#8217;ll learn how you should be preparing for your behavioral interviews.</p><p>You&#8217;ll master the STAR framework&#8212;the real version, not the generic one you&#8217;ve likely heard. This one actually prevents downleveling. And you&#8217;ll see real examples of answers that landed offers at Big Tech companies.</p><p>More importantly, you&#8217;ll learn to think like an interviewer. When you understand what they really want to hear, you can tell stories that address their true questions. These aren&#8217;t just surface-level questions. They go deeper, focusing on your judgment, impact, and readiness for the role.</p><p>The engineers who excel at behavioral interviews aren&#8217;t necessarily the best storytellers. They&#8217;re the ones who understand what&#8217;s being evaluated and can connect their experiences to those evaluation criteria.</p><p>To start, let&#8217;s understand when and how your behavioral skills are evaluated during an interview process.</p><div><hr></div><h1>When Behavioral Skills Are Evaluated</h1><p>Here&#8217;s something that surprises most engineers: behavioral skills aren&#8217;t just evaluated during the dedicated behavioral interview round. They&#8217;re being evaluated from the very first question, often before the technical interview even starts.</p><p>Many candidates believe behavioral assessment happens in a separate block, usually near the end of the interview process.</p><p>In reality, hiring teams are evaluating your behavioral competencies across every single interview. Your ability to be hired at the right level depends on consistent performance across three distinct evaluation moments. Each one needs different preparation.</p><h3><strong>Three Moments When Behavioral Skills Are Evaluated</strong></h3><p>First, there&#8217;s the opening conversation&#8230;</p><p>This starts with your recruiter call and continues into the first technical interview. Then, behavioral evaluation occurs throughout your technical interviews. Finally, there&#8217;s the dedicated behavioral interview round.</p><p>Each moment assesses different aspects of your competencies and requires different strategies.</p><p>Most engineers focus only on the third moment&#8230;</p><p>They prepare answers to &#8220;<em>Tell me about a time when...&#8221;</em> questions but neglect the other two. This is a critical mistake. The interviewer who speaks to you first forms an impression that influences how every other interviewer perceives you. The technical interviewer who watches you explain your architectural choices is simultaneously assessing your judgment and decision-making process. By the time you reach the dedicated behavioral round, the narrative about you is already partially written.</p><p>Let&#8217;s look at each moment, what&#8217;s being evaluated, and how to prepare&#8230;</p><h4><strong>Moment 1: Tell Me About Yourself</strong></h4><p>The question &#8220;<em>Tell me about yourself</em>&#8221; appears everywhere.</p><ul><li><p>It&#8217;s asked by the recruiter on your initial call.</p></li><li><p>It&#8217;s asked by the technical interviewer at the beginning of the coding round.</p></li><li><p>It&#8217;s asked by the hiring manager.</p></li><li><p>It&#8217;s asked by the panel interviewer before the system design discussion. </p></li></ul><p>Some candidates face this question five times in a single interview loop, sometimes with slightly different framings like <em>&#8220;Walk me through your resume&#8221;</em> or <em>&#8220;Tell me about your background.&#8221;</em></p><p>Most engineers completely underestimate its importance. When you&#8217;re asked, &#8220;<em>Tell me about yourself,&#8221;</em> the interviewer isn&#8217;t looking for your resume recited out loud.</p><p>They&#8217;re assessing several behavioral competencies simultaneously.</p><blockquote><p>Can you communicate concisely?</p><p>Do you highlight impact or just responsibilities?</p><p>Do you show self-awareness about your growth?</p><p>Do you understand what matters for this specific role?</p><p>Can you tell a coherent story about your career progression?</p></blockquote><p>Your answer shapes how the interviewer perceives you before any technical question is asked.</p><p>If you ramble for five minutes without clarity, they&#8217;ve already formed an impression... If you jump between random accomplishments without connection, they&#8217;re questioning your communication skills&#8230; If you focus entirely on what you did without explaining the impact, they&#8217;re seeing a junior mindset.</p><p>This first impression compounds throughout the interview.</p><h4><strong>Moment 2: Behavioral Skills During Technical Interviews</strong></h4><p>Many candidates don&#8217;t realize that behavioral assessment happens throughout technical interviews, not just when answering explicit behavioral questions.</p><p>During a coding interview, the interviewer might ask, <em>&#8220;Why did you choose this data structure?&#8221;</em> or <em>&#8220;How would you optimize this further?&#8221;</em> These are behavioral moments. They&#8217;re assessing how you think about tradeoffs, whether you consider constraints, how you handle feedback, and whether you communicate reasoning clearly.</p><p>During a system design interview, when you&#8217;re drawing architecture on the whiteboard, behavioral evaluation is happening constantly.</p><blockquote><p>Can you explain your decision-making process?</p><p>Do you consider the viewpoint of your interviewer?</p><p>Do you ask clarifying questions before diving in?</p><p>Do you acknowledge tradeoffs, or do you present your solution as obviously optimal?</p><p>Do you listen when challenged, or do you defend rigidly?</p></blockquote><p>The technical answer is only part of the evaluation. How you arrive at that answer, how you explain your reasoning, and how you discuss tradeoffs all signal your seniority level.</p><p>This is where the behavioral framework from later in this playbook becomes critical.</p><p>You need to communicate not just your solution, but your thinking process. You need to show scope, evidence of learning, and organizational awareness.</p><h4><strong>Moment 3: Dedicated Behavioral Interview Questions</strong></h4><p>It&#8217;s where you have the most time and space to demonstrate behavioral competencies in depth.</p><p>It&#8217;s where you seal the narrative that&#8217;s been building throughout the interview and get hired at the right level. (We will dive into how to prepare for behavioral interviews in this playbook.)</p><p><strong>What This Means for Your Preparation</strong></p><p>You need to prepare for all three moments, not just the behavioral round.</p><p>First, master your <em>&#8220;Tell me about yourself&#8221;</em> answer.</p><p>This is your opening act. Make it strategic, concise, and tailored to the role. Practice it until it feels natural, not robotic. Know multiple versions for different interview contexts.</p><p>Second, develop the ability to articulate your thinking during technical interviews.</p><p>Learn to explain not just what you decided, but why. Practice talking through your decision-making process, assumptions, and trade-offs. When an interviewer asks a clarifying question or pushes back, view it as a chance to show your thought process. It&#8217;s not an attack.</p><p>Third, prepare deep answers for behavioral questions using the frameworks we&#8217;ll cover in this playbook.</p><p>Have eight to fifteen strong stories ready. You can adjust them for different questions based on the company you&#8217;re interviewing with. Know the underlying behavioral competencies you&#8217;re demonstrating with each story.</p><p>The engineers who get hired at the right level aren&#8217;t necessarily the smartest in the room. They&#8217;re the ones who <em>communicate clearly</em> across all three moments. They tell a coherent story about their career, their judgment, and their impact from the first question to the last.</p><p>Let&#8217;s dive into frameworks for preparing for each of these 3 moments, starting from <em>&#8220;Tell me about yourself.</em>&#8221;</p><div><hr></div><h1>Framework to Answer &#8220;Tell Me About Yourself&#8221;</h1><p>When an interviewer asks, <em>&#8220;Tell me about yourself,&#8221;</em> the interviewer is actually asking, <em>&#8220;Tell me why I should hire you?&#8221;</em></p><p>So instead of focusing on your entire career experience, you need to focus only on the highlights of your career experience that are most relevant to the job role you&#8217;re applying for.</p><p>You need to have a 1-minute elevator pitch for yourself.</p><p>That one minute not only helps you connect with the interviewer but also steers the interview. You subtly drop in the keywords and your strong areas on which you would like the interviewer to probe further.</p><p>I understand keeping it under one minute is extremely difficult. You can have it as 2 min max.</p><h4><strong>Here is the framework you can use to write your introduction:</strong></h4><ol><li><p>Career Summary [keep it to 20 seconds max]</p><ul><li><p>This is your hook to keep the interviewer engaged for the next 1-2 minutes as you power through your introduction.</p></li></ul></li><li><p>Main Body [45-90 seconds]</p><ul><li><p>This section should explain why you are a strong fit for the role. In no particular order or specific time allocation, talk about following:</p><ul><li><p>Relevant Experience</p></li><li><p>Key Skills</p></li><li><p>Recent Project</p></li></ul></li><li><p>You&#8217;ll notice in my example below that I start this section with a recent project, as it aligns with the role's experience requirements. I have not explicitly discussed key skills, but I have woven them into the two project examples I have provided.</p></li></ul></li><li><p>Personal Interest [Optional. Keep it very short]</p><ul><li><p>It&#8217;s a nice-to-have section where you can talk about what you do outside of your work.</p></li></ul></li></ol><p>As a mental model, to create your 1-2 mins introduction, you can use this flowchart:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ruuM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58abb4c0-39e6-4824-87d8-ac45822f6b60_1600x449.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ruuM!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58abb4c0-39e6-4824-87d8-ac45822f6b60_1600x449.png 424w, https://substackcdn.com/image/fetch/$s_!ruuM!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58abb4c0-39e6-4824-87d8-ac45822f6b60_1600x449.png 848w, https://substackcdn.com/image/fetch/$s_!ruuM!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58abb4c0-39e6-4824-87d8-ac45822f6b60_1600x449.png 1272w, https://substackcdn.com/image/fetch/$s_!ruuM!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58abb4c0-39e6-4824-87d8-ac45822f6b60_1600x449.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ruuM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58abb4c0-39e6-4824-87d8-ac45822f6b60_1600x449.png" width="1456" height="409" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/58abb4c0-39e6-4824-87d8-ac45822f6b60_1600x449.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:409,&quot;width&quot;:1456,&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_!ruuM!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58abb4c0-39e6-4824-87d8-ac45822f6b60_1600x449.png 424w, https://substackcdn.com/image/fetch/$s_!ruuM!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58abb4c0-39e6-4824-87d8-ac45822f6b60_1600x449.png 848w, https://substackcdn.com/image/fetch/$s_!ruuM!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58abb4c0-39e6-4824-87d8-ac45822f6b60_1600x449.png 1272w, https://substackcdn.com/image/fetch/$s_!ruuM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58abb4c0-39e6-4824-87d8-ac45822f6b60_1600x449.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><strong>Example of an Elevator Pitch</strong></h4><p>Let&#8217;s understand how you can put the framework I mentioned into action to write your own introduction using an example.</p><p>Here is the elevator pitch I used in my first technical round at AWS in 2019:</p><blockquote><p><em>I started my career as a .NET developer, and over the last 10 years, I have gained extensive experience in developing and architecting applications using Microsoft workloads stack.</em></p><p><em>In my current project, I&#8217;m working as a tech lead helping a UK financial institution in digitally transforming their re-mortgage platform. Their legacy platform was built as a monolithic application in .NET with Winforms as frontend and SQL Server Database as backend. Their team was following the waterfall SDLC. I, along with my team, are helping them adopt agile development methodology and are modernizing their monolithic application by breaking it into microservices and implementing Jenkins CI/CD pipeline.</em></p><p><em>Prior to it, in my previous project, I was involved in building a product called the Compliance Management Reporting System (CMRS). The tech stack was .NET, SQL Server, XSLT, Biztalk, WCF, Winforms /WPF - basically it was all Microsoft stack. I started on the project as a senior developer and then became a track lead. Once that product was launched, I moved from India to London and joined the pre-sales team. I helped pitch the product to multiple financial institutions here and implemented it for them.</em></p><p><em>Outside of work, I enjoy running. Last month I ran the London Marathon. It was tough, but was an amazing experience to train for it and run alongside 40,000 runners.</em></p><p>I&#8217;m happy to dive deep into any of my experiences.</p></blockquote><p>The pitch was in no way perfect. But it was specifically tailored for the job I was applying for and also the interviewer&#8217;s profile.</p><p>Job role:</p><blockquote><p><em>I applied for the role of Senior Solutions Architect, Microsoft Dev tools. The role was to help AWS customers/partners migrate and modernise Microsoft Workloads (like .NET applications and SQL Server) on AWS.</em></p></blockquote><p>Interviewer Profile:</p><blockquote><p><em>I looked up the interviewer on LinkedIn. Before joining AWS, they were working as Application Development Lead at one of the Microsoft consulting company and had written a book on cross-platform .NET.</em></p></blockquote><p>I didn&#8217;t have experience working with cloud/AWS at the time. My best approach was to leverage my strengths and highlight my experience developing applications on Microsoft workloads. As this was a customer-facing role, I discussed my pre-sales experience.</p><p>And it worked out pretty well&#8230;</p><p>Most of the technical questions were on .NET, SQL, application development, microservices, and CI/CD pipelines. In the behavioral question (yes, even in technical interviews, there are behavioral questions), I discussed a pre-sales experience with a major financial custodian.</p><h4><strong>Power of Customization</strong></h4><p>It&#8217;s easy to understand that an introduction needs to be tailored to the job role, but should it be tailored to the interviewer&#8217;s background?</p><p>If possible, yes!</p><p>For example, in my case, the interviewer had a .NET background, so I doubled down on that and mentioned the tech stack. Now, let&#8217;s say the interviewer had been from a Java background. I would have focused more on design patterns and my architectural skills rather than the Microsoft tech stack.</p><p>If the interviewer held a managerial or leadership position or came from a business background, I would have emphasized my business acumen and stakeholder management. I wouldn&#8217;t focus as much on my technical abilities.</p><p>It&#8217;s about finding common ground with the interviewer so the discussion can focus on topics we both know. Yes, it may be tedious, but you need to research the role and the interviewer and tailor your elevator pitch accordingly.</p><blockquote><p><em>If you like to see more examples of introductions from other successful candidates, check out my <a href="https://bigtechcareers.mykajabi.com/">Big Tech Interview Preparation course</a>.</em></p></blockquote><p>Next, let&#8217;s dive into how to showcase behavioral skills in technical interviews&#8230;</p><div><hr></div><h1>Standing Out in Technical Interviews using Behavioral Skills</h1><p>Let me start this section with a personal anecdote.</p><p>In one of my technical interview rounds at AWS in 2019, I was asked, &#8220;What is an Idempotent API?&#8221;</p><p>My response was in 3 steps:</p><ol><li><p><strong>Answered the technical question asked upfront</strong></p></li></ol><blockquote><p>I explained what an Idempotent API is, showcasing my technical knowledge.</p></blockquote><ol start="2"><li><p><strong>Shared my previous project where I implemented an idempotent API</strong></p></li></ol><blockquote><p>I showcased my actual hands-on work experience without the interviewer even asking me.</p></blockquote><ol start="3"><li><p><strong>Explained my project experience in STAR format</strong></p></li></ol><p>[<em>I&#8217;ll cover STAR (Situation Task Action Result) format in the next section</em>]</p><blockquote><p>While explaining my project experience in STAR format, I also explained WHY the idempotent API was required in that scenario. I talked about how the APIs I built were reporting trades worth millions in real-time to regulators and the reason I had to implement them as idempotent.</p><p>This is where I showcased my behavioral skills. I demonstrated I understand the business impact of the technical solutions I build.</p></blockquote><div class="captioned-button-wrap" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/p/common-behavioral-interview-questions?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">Share this post &amp; earn rewards for referrals.</p></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/p/common-behavioral-interview-questions?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://newsletter.systemdesign.one/p/common-behavioral-interview-questions?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p></div><h4><strong>The Problem with Pure Technical Answers</strong></h4><p>Many candidates show off their technical knowledge in technical interviews, and most get the technical answers right.</p><p>Let&#8217;s say 10 people interview:</p><p>7 of them answered the technical questions correctly. You&#8217;re one of those 7. So why should the interviewer pick you?</p><p>You need to stand out.</p><p>How? By sharing your real-world experience and behavioral skills.</p><p>While technical answers showcase that you have knowledge, they don&#8217;t paint a complete picture of your ability to succeed in a role.</p><p>For example, all engineers know what an idempotent API is. But how many can connect it to their experience in an interview and share real-world examples to boost the interviewer&#8217;s confidence in their skills? You stand out from other candidates by showing your experience and behavioral skills while you answer technical questions.</p><p>This also ensures that your interviewer does not downlevel you.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Cqy9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf1a47dd-60c4-4aa6-ba97-e31cdaa294bd_1456x719.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Cqy9!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf1a47dd-60c4-4aa6-ba97-e31cdaa294bd_1456x719.png 424w, https://substackcdn.com/image/fetch/$s_!Cqy9!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf1a47dd-60c4-4aa6-ba97-e31cdaa294bd_1456x719.png 848w, https://substackcdn.com/image/fetch/$s_!Cqy9!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf1a47dd-60c4-4aa6-ba97-e31cdaa294bd_1456x719.png 1272w, https://substackcdn.com/image/fetch/$s_!Cqy9!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf1a47dd-60c4-4aa6-ba97-e31cdaa294bd_1456x719.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Cqy9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf1a47dd-60c4-4aa6-ba97-e31cdaa294bd_1456x719.png" width="1456" height="719" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bf1a47dd-60c4-4aa6-ba97-e31cdaa294bd_1456x719.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:719,&quot;width&quot;:1456,&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_!Cqy9!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf1a47dd-60c4-4aa6-ba97-e31cdaa294bd_1456x719.png 424w, https://substackcdn.com/image/fetch/$s_!Cqy9!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf1a47dd-60c4-4aa6-ba97-e31cdaa294bd_1456x719.png 848w, https://substackcdn.com/image/fetch/$s_!Cqy9!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf1a47dd-60c4-4aa6-ba97-e31cdaa294bd_1456x719.png 1272w, https://substackcdn.com/image/fetch/$s_!Cqy9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf1a47dd-60c4-4aa6-ba97-e31cdaa294bd_1456x719.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>Let&#8217;s look at a couple of common technical questions&#8230;</p><p>I&#8217;ll show you how to answer them in a way that also shows off your behavioral skills and experience.</p><h4><strong>Question: &#8220;What are microservices, and what are their advantages and disadvantages?&#8221;</strong></h4><p><strong>Purely Technical Approach</strong></p><blockquote><p><em>&#8220;Microservices are an architectural style where an application is built as a collection of small, independent services. The advantages include scalability, flexibility, and easier maintenance. Disadvantages include increased complexity and potential performance overhead due to network communication.&#8221;</em></p></blockquote><p>(This is just an example. You&#8217;ll have your own version of a technical answer with much more depth to it!)</p><p><strong>Behavioral Skills Showcase Approach</strong></p><p>After you provide the technical answer, add your personal experience to it.</p><blockquote><p><em>&#8220;In fact, in one of my previous projects when I was consulting for a manufacturing company in 2022, I led a team that modernized our e-commerce platform by transitioning from a monolith to microservices.</em></p><p><em>We decided to make this shift because our monolithic application was becoming increasingly difficult to maintain and scale. For instance, deploying even small changes required testing the entire application, leading to a release cycle of 6 weeks.</em></p><p><em>To begin the transition, I initiated and facilitated an event storming session with stakeholders from development, operations, and business teams. This collaborative approach helped us identify natural service boundaries and ensured buy-in from all departments.</em></p><p><em>We started by extracting the product catalog service, as it was relatively self-contained. We faced several challenges, such as increased operational complexity and data consistency issues. I saw these as opportunities for the team to learn and grow. We invested time in upskilling, bringing in external experts for workshops on distributed systems and organizing internal knowledge-sharing sessions.</em></p><p><em>I&#8217;m happy to dive deep more into my experience. I&#8217;ve seen firsthand in this project the advantages of microservices and the challenges that come along with it.&#8221;</em></p></blockquote><p>This response not only demonstrates technical knowledge but also showcases your experience and several behavioral skills:</p><ul><li><p>Leadership: Leading the modernization project</p></li><li><p>Communication: Facilitating sessions with various stakeholders</p></li><li><p>Problem-solving: Addressing challenges that arose during the transition</p></li><li><p>Learning mindset and adaptability: Learning and applying new technologies</p></li></ul><p>Now, let&#8217;s look into another question.</p><h4><strong>Question: &#8220;What factors would you consider when choosing between SQL and NoSQL databases?&#8221;</strong></h4><p><strong>Purely Technical Approach:</strong></p><blockquote><p><em>&#8220;When choosing between SQL and NoSQL databases, several factors come into play.</em></p><p><em>Data structures are a primary consideration, with SQL being ideal for structured, relational data, while NoSQL is better suited for unstructured or semi-structured data.</em></p><p><em>Scalability needs often favor NoSQL, which typically scales horizontally more easily.</em></p><p><em>SQL databases offer stronger ACID compliance and excel at complex queries involving joins and transactions. However, NoSQL databases provide greater schema flexibility, allowing for more dynamic data models.</em></p><p><em>Performance requirements are also crucial, as NoSQL can offer faster read/write speeds for certain use cases.</em></p><p><em>Data consistency needs should be evaluated, with SQL providing immediate consistency and some NoSQL databases offering eventual consistency.</em></p><p><em>The choice ultimately depends on the specific requirements and constraints of the project at hand.&#8221;</em></p></blockquote><p>This is a good answer and will probably make the cut. But as I mentioned, most candidates will be able to provide this level of answer. You need to strive to go above and beyond.</p><p><strong>Behavioral Skills Showcase Approach:</strong></p><p>I understand you cannot have work experience for every technical question asked in an interview. And that is absolutely fine. Complement the technical answer above with how you would approach such a scenario.</p><blockquote><p><em>&#8220;To understand the requirements and constraints, I would organize a requirements gathering session with various stakeholders like the development team, product managers and, if possible, end-users. During this session, I would ask key questions such as:</em></p></blockquote><ul><li><p><em>How structured is the data? Do we need a fixed schema or flexibility for evolving structures?</em></p></li><li><p><em>What are our scalability requirements? What are the expected read/write ratios?</em></p></li><li><p><em>Do we need strong consistency for all operations, or is eventual consistency acceptable for some data?</em></p></li><li><p><em>What are our typical query patterns? Do we need complex joins and transactions?</em></p></li><li><p><em>How frequently will our data model change?</em></p></li></ul><blockquote><p><em>Once we have these answers, I would analyze them in the context of ACID (Atomicity, Consistency, Isolation, Durability) properties typically associated with SQL databases, and BASE (Basically Available, Soft state, Eventually consistent) properties often seen in NoSQL systems.</em></p><p><em>I would also consider the CAP theorem (Consistency, Availability, Partition tolerance) which states that in a distributed system, you can only have two of these three guarantees.</em></p><p><em>And most modern systems often benefit from a polyglot persistence approach, using different databases for different purposes within the same application.</em></p><p><em>For example:</em></p><p><em>PostgreSQL for user accounts and financial transactions, where ACID properties were crucial. MongoDB for storing product catalogs with varying attributes. Redis for caching and real-time analytics</em></p><p><em>This decision cannot be made in isolation. I would consider trade-offs of each approach, challenge assumptions and provide alternative viewpoints.&#8221;</em></p></blockquote><p>This response shows several behavioral skills:</p><ul><li><p>Analytical thinking: Systematically considering various factors</p></li><li><p>Stakeholder management: Involving different teams in the decision-making process</p></li><li><p>Communication: Organizing and facilitating requirements gathering and review sessions</p></li><li><p>Decision-making: Weighing pros and cons to arrive at a solution</p></li></ul><p>By answering technical questions in a way that showcases both your technical knowledge and behavioral skills, you present yourself as a well-rounded candidate who can not only do the job but also work effectively within a team and contribute to the company culture.</p><p>Companies are looking for more than just technical expertise. They want employees who can communicate effectively, work collaboratively, adapt to changing circumstances, and drive innovation.</p><p>So, as you prepare for your next technical interview, reflect not just on your technical accomplishments, but also on how you&#8217;ve demonstrated these crucial behavioral skills in your work.</p><p>Now, let&#8217;s dive into understanding the STAR framework to prepare for your behavioral interviews&#8230;</p><div><hr></div><h1>Use STAR Framework Effectively to Answer Behavioral Questions</h1><p>If you&#8217;ve been preparing for job interviews, you&#8217;ve likely encountered the STAR format.</p><p>It&#8217;s a powerful framework for structuring responses to behavioral questions. However, many candidates use this technique incorrectly, resulting in weak, unconvincing answers.</p><p>In this section, I&#8217;ll cover how to avoid common pitfalls and craft compelling STAR responses that will impress your interviewers.</p><p>As I explain the STAR format with an example and then go through more examples in the upcoming sections, I will adopt different personas.</p><p>I&#8217;ll start with the persona of a Cloud Solutions Architect, as that&#8217;s my current role!</p><h4><strong>What is the STAR Format?</strong></h4><p>Let&#8217;s have a quick refresher of what STAR stands for:</p><ul><li><p>Situation: Context or background of your example</p></li><li><p>Task: Specific challenge or responsibility you faced</p></li><li><p>Action: Steps you took to address the task</p></li><li><p>Result: Outcomes of your actions</p></li></ul><p>Now, let&#8217;s examine each component, identify common mistakes, and learn how to do it right with an example&#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_!OIb8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7b14979-819b-4047-b563-a8ce7436445f_1456x1179.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!OIb8!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7b14979-819b-4047-b563-a8ce7436445f_1456x1179.png 424w, https://substackcdn.com/image/fetch/$s_!OIb8!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7b14979-819b-4047-b563-a8ce7436445f_1456x1179.png 848w, https://substackcdn.com/image/fetch/$s_!OIb8!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7b14979-819b-4047-b563-a8ce7436445f_1456x1179.png 1272w, https://substackcdn.com/image/fetch/$s_!OIb8!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7b14979-819b-4047-b563-a8ce7436445f_1456x1179.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!OIb8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7b14979-819b-4047-b563-a8ce7436445f_1456x1179.png" width="1456" height="1179" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d7b14979-819b-4047-b563-a8ce7436445f_1456x1179.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1179,&quot;width&quot;:1456,&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_!OIb8!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7b14979-819b-4047-b563-a8ce7436445f_1456x1179.png 424w, https://substackcdn.com/image/fetch/$s_!OIb8!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7b14979-819b-4047-b563-a8ce7436445f_1456x1179.png 848w, https://substackcdn.com/image/fetch/$s_!OIb8!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7b14979-819b-4047-b563-a8ce7436445f_1456x1179.png 1272w, https://substackcdn.com/image/fetch/$s_!OIb8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7b14979-819b-4047-b563-a8ce7436445f_1456x1179.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><strong>Situation: Stop Being Vague</strong></h3><p>Situation sets the stage for your story.</p><p>It provides the context and background information necessary for the interviewer to understand the circumstances you were facing. When describing the situation, be specific about:</p><ul><li><p>Where you were working and what your role was</p></li><li><p>When the event occurred</p></li><li><p>Relevant data/metrics to showcase the importance of the situation</p></li></ul><p><strong>The Wrong Way:</strong></p><blockquote><p><em>&#8220;I was working as a Cloud Solutions Architect, and we had to move our mission-critical workloads to the cloud.&#8221;</em></p></blockquote><p>This situation lacks specificity and fails to set the stage effectively. It doesn&#8217;t give the interviewer any meaningful context.</p><p><strong>The Right Way:</strong></p><blockquote><p><em>&#8220;I was working as a Senior Cloud Solutions Architect with a Fortune 500 manufacturing company. In Q1 2023, 80% of our mission-critical applications were running on aging on-premises infrastructure, causing frequent outages and limiting our ability to scale. Our CIO had set an aggressive goal to migrate 50% of these applications to the cloud within six months to improve reliability and reduce operational costs.&#8221;</em></p></blockquote><p>This approach works because it specifies the exact role and company, provides a clear timeframe, and offers relevant data and metrics that highlight the importance of the situation.</p><h3><strong>Task: Don&#8217;t Undersell the Challenge</strong></h3><p>Task describes the specific challenge, problem, or responsibility you were facing in a situation.</p><p>This component should clearly outline:</p><ul><li><p>What you needed to accomplish</p></li><li><p>Goals or objectives you were working towards</p></li><li><p>Urgency and importance of the task</p></li></ul><p><strong>The Wrong Way:</strong></p><blockquote><p><em>&#8220;The task was to figure out how to move the applications to AWS within the given timeframe and make sure they worked properly.&#8221;</em></p></blockquote><p>This description undersells the complexity of the task and fails to convey its importance or urgency.</p><p><strong>The Right Way:</strong></p><blockquote><p><em>&#8220;The task was to identify, prioritize and migrate critical applications to AWS within six months. This required assessing applications, designing a secure architecture, creating a migration plan, minimizing operational disruptions, ensuring high uptime, and reducing costs. The timelines were aggressive, as the urgency was high because our aging infrastructure was putting us at risk of major system failures.&#8221;</em></p></blockquote><p>This approach works because it breaks down the task into key components, emphasizes the urgency and importance of the challenge, and demonstrates the scope and complexity of what needs to be accomplished.</p><h3><strong>Action: Get Specific and Show Your Expertise</strong></h3><p>Action is the core of your response.</p><p>It details the steps you took to address the task or challenge. When describing your actions:</p><ul><li><p>Be specific about what you did. Use &#8220;I&#8221; statements to clarify your personal contributions.</p></li><li><p>Explain your thought process and decision-making</p></li><li><p>Highlight any skills or qualities you demonstrated</p></li></ul><p><strong>The Wrong Way:</strong></p><blockquote><p><em>&#8220;I looked at our applications and decided to start the migration with our core ERP system as it was most critical. Then I set up the AWS accounts and worked with security, database, networking and other teams to migrate the application. We had to make some application architecture changes to make the apps work in the cloud.&#8221;</em></p></blockquote><p>This description is vague, lacks detail, and does not demonstrate any specific skills or expertise.</p><p><strong>The Right Way:</strong></p><blockquote><p><em>&#8220;To begin, I led a cross-functional team in conducting a thorough analysis of our application portfolio. We considered factors such as business criticality, dependencies, and architectural complexity to gain a complete understanding of our existing infrastructure.</em></p><p><em>Based on this assessment, I took the ownership to lead the migration of our core ERP system, which was critical to our manufacturing operations. This migration was also crucial to the overall goal as it would serve as a blueprint for future migrations.</em></p><p><em>I designed a multi-tiered AWS architecture for this application, ensuring high availability and scalability. Security was a top priority, so I collaborated closely with our security team to implement a robust model tailored to the ERP system&#8217;s requirements. I worked with the project manager to create a comprehensive project plan, including a phased approach to migrate different modules of the ERP system.</em></p><p><em>To streamline the migration process and reduce manual errors, I developed CloudFormation templates and leveraged AWS Migration Hub for automation. This significantly reduced migration time and improved consistency. Throughout the process, I worked closely with our database team to ensure data integrity and with our networking team to establish secure connectivity between our on-premises systems and AWS.</em></p><p><em>Additionally, I conducted several dry runs and extensive testing to minimize potential disruptions to our manufacturing operations.&#8221;</em></p></blockquote><p>In the STAR framework, the Action section is where you should invest the most detail and time.</p><p>Detailing your actions, explaining your choices, and highlighting your technical and leadership capabilities builds a powerful story. It shows your impact and value.</p><h3><strong>Result: Quantify Your Impact</strong></h3><p>Result is the conclusion of your story.</p><p>It describes the outcome of your actions and their impact. When discussing results:</p><ul><li><p>Be specific about what was achieved using quantifiable metrics when possible</p></li><li><p>Explain the positive impact on the company, team, or project</p></li><li><p>Mention any lessons learned or personal growth</p></li></ul><p><strong>The Wrong Way:</strong></p><blockquote><p><em>&#8220;We managed to move few applications to the cloud within the 6 months. The application is working better in the cloud and we overall reduced the cost of infrastructure of running these applications.&#8221;</em></p></blockquote><p>This result lacks specificity and demonstrates no significant impact or value.</p><p><strong>The Right Way:</strong></p><blockquote><p><em>&#8220;We successfully migrated our core ERP system to AWS in four months. The system&#8217;s response times decreased by 40%, and we improved scalability, handling a 200% increase in concurrent users during peak periods. We also reduced infrastructure costs for this application by 30%.</em></p><p><em>It took us more time than anticipated, but we learned a lot along the way. Based on the learnings, I created a blueprint, best practices document and SOP for other teams to migrate their respective applications. Using these documents, different teams have migrated 24 more applications so far.</em></p><p><em>Personally, this project deepened my expertise in large-scale cloud migrations and gave me the opportunity to work with multiple stakeholders and cross-functional teams.&#8221;</em></p></blockquote><p>This approach works because it shows clear, measurable wins. It explains the good impact on various business areas and highlights your personal growth.</p><p>Now that you understand how to structure your behavioral answers using the STAR format, let&#8217;s explore the key themes you should focus on&#8230;</p><div><hr></div><h1>8 Key Themes to Prepare for Your Behavioral Interviews</h1><p>Behavioral interviews can feel overwhelming because of their open-ended nature and the sheer volume of potential questions.</p><p>To streamline your preparation for your next tech company behavioral interview, I&#8217;ve organized these questions into eight main themes:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ngvg!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3029e616-6d1c-47ca-996e-17206592a2ec_1456x1174.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ngvg!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3029e616-6d1c-47ca-996e-17206592a2ec_1456x1174.png 424w, https://substackcdn.com/image/fetch/$s_!ngvg!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3029e616-6d1c-47ca-996e-17206592a2ec_1456x1174.png 848w, https://substackcdn.com/image/fetch/$s_!ngvg!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3029e616-6d1c-47ca-996e-17206592a2ec_1456x1174.png 1272w, https://substackcdn.com/image/fetch/$s_!ngvg!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3029e616-6d1c-47ca-996e-17206592a2ec_1456x1174.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ngvg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3029e616-6d1c-47ca-996e-17206592a2ec_1456x1174.png" width="1456" height="1174" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3029e616-6d1c-47ca-996e-17206592a2ec_1456x1174.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1174,&quot;width&quot;:1456,&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_!ngvg!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3029e616-6d1c-47ca-996e-17206592a2ec_1456x1174.png 424w, https://substackcdn.com/image/fetch/$s_!ngvg!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3029e616-6d1c-47ca-996e-17206592a2ec_1456x1174.png 848w, https://substackcdn.com/image/fetch/$s_!ngvg!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3029e616-6d1c-47ca-996e-17206592a2ec_1456x1174.png 1272w, https://substackcdn.com/image/fetch/$s_!ngvg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3029e616-6d1c-47ca-996e-17206592a2ec_1456x1174.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><strong>1. Customer/User Focus Stories</strong></h3><p>These stories showcase your ability to prioritize and enhance the customer experience. They might include:</p><ul><li><p>Improving user experience</p></li><li><p>Handling customer complaints</p></li><li><p>Going above and beyond for clients</p></li></ul><p><strong>Example Question</strong>: <em>&#8220;Give an example of a time when you had to deal with a challenging customer or user issue.&#8221;</em></p><p><strong>What your answer should address:</strong> Describe the problem and why it was difficult to resolve, explain how you understood the customer&#8217;s needs, outline the steps you took to address the issue, and discuss the final resolution and how you ensured customer satisfaction.</p><h3><strong>2. Success Stories</strong></h3><p>The interviewers would like to hear about your ability to deliver results and handle challenges. Think about stories like:</p><ul><li><p>Achievements and accomplishments</p></li><li><p>Overcoming significant challenges</p></li><li><p>Innovative solutions or improvements</p></li></ul><p><strong>Example Question:</strong> <em>&#8220;Tell me about a time when you significantly exceeded expectations on a project or task.&#8221;</em></p><p><strong>What your answer should address:</strong> Explain what the initial goals were and how you went above and beyond, describe the strategies you used to achieve results, and discuss how you measured your success.</p><h3><strong>3. Failure Stories</strong></h3><p>Interviewers are interested in how you handle adversity and grow from experiences. Prepare stories that showcase:</p><ul><li><p>Projects that didn&#8217;t meet expectations</p></li><li><p>Mistakes with significant consequences</p></li><li><p>Failures to anticipate major problems or challenges</p></li></ul><p><strong>Example Question:</strong> <em>&#8220;Tell me about a time when you failed to meet an important goal or deadline at work.&#8221;</em></p><p><strong>What your answer should address:</strong> Describe the situation and the factors that contributed to the failure, explain how you handled the aftermath, and discuss the lessons you learned and how you&#8217;ve applied them since.</p><h3><strong>4. Conflict Stories</strong></h3><p>Interviewers want to assess your interpersonal skills and ability to navigate challenging situations. Prepare examples that showcase:</p><ul><li><p>Dealing with difficult colleagues or clients</p></li><li><p>Resolving team disagreements</p></li><li><p>Navigating workplace dynamics</p></li></ul><p><strong>Example Question:</strong> <em>&#8220;Describe a situation where you had a conflict with a colleague or team member.&#8221;</em></p><p><strong>What your answer should address:</strong> Explain the source of the conflict and how you approached resolving it, describe the steps you took to maintain a professional relationship afterward, and discuss how this experience changed your approach to workplace conflicts.</p><h3><strong>5. Problem-Solving Stories</strong></h3><p>Interviewers aim to understand your analytical thinking and creative approach to challenges. Prepare examples that illustrate:</p><ul><li><p>Tackling complex challenges</p></li><li><p>Making decisions with limited information</p></li><li><p>Implementing process improvements</p></li></ul><p><strong>Example Question:</strong> <em>&#8220;Give an example of a complex problem you encountered at work that required an innovative solution.&#8221;</em></p><p><strong>What your answer should address:</strong> Explain what made this problem particularly challenging, walk through your problem-solving process, describe how you implemented your solution, and discuss the result and how you measured its success.</p><h3><strong>6. Learning/Growth Mindset Stories</strong></h3><p>Interviewers look for examples of your adaptability and commitment to continuous improvement. Share examples that demonstrate:</p><ul><li><p>Learning new skills quickly</p></li><li><p>Handling change or uncertainty</p></li><li><p>Embracing feedback for personal improvement</p></li></ul><p><strong>Example Question:</strong> <em>&#8220;Describe a time when you had to learn a completely new skill or technology that was crucial for your role or a project.&#8221;</em></p><p><strong>What your answer should address:</strong> Explain the situation and why this new skill was necessary, describe the challenges you faced and how you overcame them, and discuss how you applied this new knowledge and what the outcome was.</p><h3><strong>7. Leadership Stories</strong></h3><p>These anecdotes showcase your ability to guide, influence, and develop others:</p><ul><li><p>Motivating and inspiring team members</p></li><li><p>Navigating conflicts or difficult decisions</p></li><li><p>Developing and mentoring others</p></li></ul><p><strong>Example Question:</strong> <em>&#8220;Tell me about a time when you had to lead a team through a challenging situation or project.&#8221;</em></p><p><strong>What your answer should address:</strong> Describe the context and the specific leadership challenges you faced, explain how you approached motivating your team and keeping them aligned towards the goal, and discuss the project outcome and how this experience shaped your leadership style.</p><div class="captioned-button-wrap" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/p/common-behavioral-interview-questions?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">Share this post &amp; earn rewards for referrals.</p></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/p/common-behavioral-interview-questions?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://newsletter.systemdesign.one/p/common-behavioral-interview-questions?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p></div><h3><strong>8. Time Management Stories</strong></h3><p>Interviewers are looking to assess your ability to organize, prioritize, and deliver under pressure. Consider examples that highlight:</p><ul><li><p>Meeting tight deadlines</p></li><li><p>Prioritizing tasks</p></li><li><p>Balancing multiple responsibilities</p></li></ul><p><strong>Example Question:</strong><em> &#8220;Describe a period when you had to manage multiple high-priority tasks simultaneously.&#8221;</em></p><p><strong>What your answer should address:</strong> Explain what the tasks were and why they were all critical, describe how you prioritized them and your time, discuss the tools or techniques you used to stay organized, and explain how successful you were in meeting your deadlines and what you would do differently if faced with a similar situation.</p><p>For each theme, prepare one or two well-developed stories using the STAR framework.</p><p>Know the underlying behavioral competencies you&#8217;re demonstrating with each story. Then you can adapt these stories to different questions you encounter. Also, map the stories to the core values of the company you are interviewing for.</p><blockquote><p><em>Want a free behavioral interview question bank with 40 questions in 8 themes? Subscribe to my newsletter, <a href="https://newsletter.bigtechcareers.com/">Big Tech Careers</a>, and I&#8217;ll send it in your welcome kit.</em></p></blockquote><p>Now, let&#8217;s examine a strong response from the Learning/Growth Mindset category.</p><p>Many companies value this theme. It shows how quickly you can learn new skills and adapt in a fast-paced environment&#8230;</p><div><hr></div><h1>Example of a Real Answer That Landed a Job</h1>
      <p>
          <a href="https://newsletter.systemdesign.one/p/common-behavioral-interview-questions">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[I struggled with system design until I learned these 114 concepts]]></title><description><![CDATA[#120: Part 1 - scalability, availability, reliability, and 35 others.]]></description><link>https://newsletter.systemdesign.one/p/system-design-concepts</link><guid isPermaLink="false">https://newsletter.systemdesign.one/p/system-design-concepts</guid><dc:creator><![CDATA[Neo Kim]]></dc:creator><pubDate>Sat, 07 Feb 2026 13:58:55 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/e5da46f5-2df8-48bd-896b-4af2e5ab5b42_1280x720.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/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">Get my system design playbook for FREE on newsletter signup:</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><ul><li><p><em><a href="https://newsletter.systemdesign.one/p/system-design-concepts/?action=share">Share this post</a> &amp; I'll send you some rewards for the referrals.</em></p></li><li><p><em>Block diagrams created using <a href="https://app.eraser.io/auth/sign-up?ref=neo">Eraser</a>.</em></p></li></ul><div><hr></div><p>Some of these are foundational, and some are quite advanced. ALL of them are super useful to software engineers building scalable systems.</p><p>Curious to know how many were new to you:</p><ol><li><p>Scalability,</p></li><li><p>Availability,</p></li><li><p>Reliability,</p></li><li><p>Latency vs Throughput vs Bandwidth,</p></li><li><p>Client-Server Architecture,</p></li><li><p>Databases,</p></li><li><p>SQL vs NoSQL,</p></li><li><p>Load Balancing,</p></li><li><p>Load Balancing Algorithms,</p></li><li><p>Caching,</p></li><li><p>Cache Invalidation,</p></li><li><p>CDN,</p></li><li><p>DNS,</p></li><li><p>API Design,</p></li><li><p>REST APIs,</p></li><li><p>Authentication vs Authorization,</p></li><li><p>Session-based vs Token-based Authentication,</p></li><li><p>OAuth/OAuth2/OpenID Connect,</p></li><li><p>JWT,</p></li><li><p>Rate Limiting,</p></li><li><p>Single Point of Failure,</p></li><li><p>High Availability vs Fault Tolerance,</p></li><li><p>CAP Theorem,</p></li><li><p>Consistency Models,</p></li><li><p>Data Replication,</p></li><li><p>Read Replicas,</p></li><li><p>Sharding,</p></li><li><p>Data Partitioning,</p></li><li><p>Consistent Hashing,</p></li><li><p>Denormalization,</p></li><li><p>Indexing,</p></li><li><p>Microservices Architecture,</p></li><li><p>Monolithic Architecture,</p></li><li><p>Serverless Architecture,</p></li><li><p>Event-Driven Architecture,</p></li><li><p>Message Queues,</p></li><li><p>Pub/Sub,</p></li><li><p>Synchronous vs Asynchronous Communication.</p></li></ol><p>(&#8230;and many more in parts 2 &amp; 3!)</p><p>For each, I&#8217;ll share:</p><ul><li><p>What it is &amp; how it works--in simple words</p></li><li><p>A real-world analogy (if I found one)</p></li><li><p>Tradeoffs</p></li><li><p>Why it matters</p></li></ul><p>Let&#8217;s go.</p><div><hr></div><h3><a href="https://getunblocked.com/code-review/?utm_source=systemdesign&amp;utm_medium=email&amp;utm_campaign=codereview&amp;utm_content=judgment">AI code review with comments you'll actually implement (Partner)</a>.</h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://getunblocked.com/code-review/?utm_source=systemdesign&amp;utm_medium=email&amp;utm_campaign=codereview&amp;utm_content=judgment" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!mVS0!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47617583-4d7a-4064-907b-1ddbcde41b35_2880x2160.png 424w, https://substackcdn.com/image/fetch/$s_!mVS0!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47617583-4d7a-4064-907b-1ddbcde41b35_2880x2160.png 848w, https://substackcdn.com/image/fetch/$s_!mVS0!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47617583-4d7a-4064-907b-1ddbcde41b35_2880x2160.png 1272w, https://substackcdn.com/image/fetch/$s_!mVS0!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47617583-4d7a-4064-907b-1ddbcde41b35_2880x2160.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!mVS0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47617583-4d7a-4064-907b-1ddbcde41b35_2880x2160.png" width="1456" height="1092" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/47617583-4d7a-4064-907b-1ddbcde41b35_2880x2160.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1092,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2204551,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:&quot;https://getunblocked.com/code-review/?utm_source=systemdesign&amp;utm_medium=email&amp;utm_campaign=codereview&amp;utm_content=judgment&quot;,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/186884584?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47617583-4d7a-4064-907b-1ddbcde41b35_2880x2160.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_!mVS0!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47617583-4d7a-4064-907b-1ddbcde41b35_2880x2160.png 424w, https://substackcdn.com/image/fetch/$s_!mVS0!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47617583-4d7a-4064-907b-1ddbcde41b35_2880x2160.png 848w, https://substackcdn.com/image/fetch/$s_!mVS0!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47617583-4d7a-4064-907b-1ddbcde41b35_2880x2160.png 1272w, https://substackcdn.com/image/fetch/$s_!mVS0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47617583-4d7a-4064-907b-1ddbcde41b35_2880x2160.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><a href="https://getunblocked.com/code-review/?utm_source=systemdesign&amp;utm_medium=email&amp;utm_campaign=codereview&amp;utm_content=judgment">Unblocked</a></strong> is the only AI code review tool that reflects your team&#8217;s standards and judgment, delivering thoughtful feedback that feels like it came from your best engineer.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://getunblocked.com/code-review/?utm_source=systemdesign&amp;utm_medium=email&amp;utm_campaign=codereview&amp;utm_content=judgment&quot;,&quot;text&quot;:&quot;Try Unblocked Now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://getunblocked.com/code-review/?utm_source=systemdesign&amp;utm_medium=email&amp;utm_campaign=codereview&amp;utm_content=judgment"><span>Try Unblocked Now</span></a></p><div><hr></div><h2><strong>1. Scalability</strong></h2><blockquote><p>Scalability is the system&#8217;s ability to handle increased load without breaking.</p></blockquote><p>Vertical scaling means adding more power to your existing machine, such as a larger CPU, more RAM, or a faster disk. Horizontal scaling means adding more machines to distribute the work across multiple servers.</p><p>When traffic grows, vertical scaling upgrades a single machine, while horizontal scaling adds more machines to work together.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!okIu!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97f6b627-09ff-4f50-9dd4-1f3c6dd813ac_1600x651.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!okIu!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97f6b627-09ff-4f50-9dd4-1f3c6dd813ac_1600x651.png 424w, https://substackcdn.com/image/fetch/$s_!okIu!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97f6b627-09ff-4f50-9dd4-1f3c6dd813ac_1600x651.png 848w, https://substackcdn.com/image/fetch/$s_!okIu!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97f6b627-09ff-4f50-9dd4-1f3c6dd813ac_1600x651.png 1272w, https://substackcdn.com/image/fetch/$s_!okIu!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97f6b627-09ff-4f50-9dd4-1f3c6dd813ac_1600x651.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!okIu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97f6b627-09ff-4f50-9dd4-1f3c6dd813ac_1600x651.png" width="1456" height="592" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/97f6b627-09ff-4f50-9dd4-1f3c6dd813ac_1600x651.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:592,&quot;width&quot;:1456,&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_!okIu!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97f6b627-09ff-4f50-9dd4-1f3c6dd813ac_1600x651.png 424w, https://substackcdn.com/image/fetch/$s_!okIu!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97f6b627-09ff-4f50-9dd4-1f3c6dd813ac_1600x651.png 848w, https://substackcdn.com/image/fetch/$s_!okIu!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97f6b627-09ff-4f50-9dd4-1f3c6dd813ac_1600x651.png 1272w, https://substackcdn.com/image/fetch/$s_!okIu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97f6b627-09ff-4f50-9dd4-1f3c6dd813ac_1600x651.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>Analogy</h3><p>Vertical scaling is like upgrading from a small restaurant kitchen to a bigger one with industrial-grade equipment.</p><p>Horizontal scaling is like opening multiple restaurant locations instead of expanding one location.</p><h3>Tradeoff</h3><p>Vertical scaling is simpler but hits a ceiling. You can only make one machine so powerful, and it becomes a single point of failure.</p><p>Horizontal scaling can grow infinitely, but it introduces complexity in coordinating multiple machines and keeping data consistent across them.</p><h3>Why it matters</h3><p>Use vertical scaling when you&#8217;re starting out or when your application isn&#8217;t designed for distribution. Switch to horizontal scaling when you need to handle millions of users, want high availability, or when vertical scaling becomes very expensive.</p><h2><strong>2. Availability</strong></h2><blockquote><p>Availability measures the percentage of time your system is operational &amp; accessible to users.</p></blockquote><p>It&#8217;s typically expressed as &#8220;nines,&#8221; where 99.9% corresponds to about 8.76 hours of downtime per year, while 99.99% corresponds to only 52.6 minutes. Availability is achieved through redundancy, failover mechanisms, and the elimination of single points of failure.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!UUfo!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08d90522-abee-4aeb-9ccd-74d4e502095b_1600x975.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!UUfo!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08d90522-abee-4aeb-9ccd-74d4e502095b_1600x975.png 424w, https://substackcdn.com/image/fetch/$s_!UUfo!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08d90522-abee-4aeb-9ccd-74d4e502095b_1600x975.png 848w, https://substackcdn.com/image/fetch/$s_!UUfo!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08d90522-abee-4aeb-9ccd-74d4e502095b_1600x975.png 1272w, https://substackcdn.com/image/fetch/$s_!UUfo!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08d90522-abee-4aeb-9ccd-74d4e502095b_1600x975.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!UUfo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08d90522-abee-4aeb-9ccd-74d4e502095b_1600x975.png" width="1456" height="887" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/08d90522-abee-4aeb-9ccd-74d4e502095b_1600x975.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:887,&quot;width&quot;:1456,&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_!UUfo!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08d90522-abee-4aeb-9ccd-74d4e502095b_1600x975.png 424w, https://substackcdn.com/image/fetch/$s_!UUfo!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08d90522-abee-4aeb-9ccd-74d4e502095b_1600x975.png 848w, https://substackcdn.com/image/fetch/$s_!UUfo!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08d90522-abee-4aeb-9ccd-74d4e502095b_1600x975.png 1272w, https://substackcdn.com/image/fetch/$s_!UUfo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08d90522-abee-4aeb-9ccd-74d4e502095b_1600x975.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>Analogy</h3><p>Availability is like a 24/7 convenience store.</p><p>A store with 99% availability would be closed for 3.65 days per year. A store with 99.999% availability would only be closed for 5 minutes per year.</p><h3>Tradeoff</h3><p>Higher availability requires more resources, such as redundant servers, load balancers, complex failover systems, and multi-region deployments. Each additional &#8220;nine&#8221; gets exponentially more expensive.</p><p>You might also sacrifice consistency for availability (CAP theorem).</p><h3>Why it matters</h3><p>Customer-facing systems, e-commerce platforms, payment processing, or any service where downtime directly costs money or erodes user trust.</p><p>Yet internal tools or batch processing jobs can tolerate lower availability.</p><h2><strong>3. Reliability</strong></h2><blockquote><p>Reliability is your system&#8217;s ability to perform its intended function correctly over time, even when things go wrong.</p></blockquote><p>A reliable system handles failures gracefully. If a server crashes, requests get rerouted. If data gets corrupted, backups restore it. Reliability includes fault tolerance, data durability, and consistent behavior under various conditions.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ihh2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93b19120-12da-4738-ad71-1bc231e45b22_1600x649.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ihh2!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93b19120-12da-4738-ad71-1bc231e45b22_1600x649.png 424w, https://substackcdn.com/image/fetch/$s_!ihh2!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93b19120-12da-4738-ad71-1bc231e45b22_1600x649.png 848w, https://substackcdn.com/image/fetch/$s_!ihh2!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93b19120-12da-4738-ad71-1bc231e45b22_1600x649.png 1272w, https://substackcdn.com/image/fetch/$s_!ihh2!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93b19120-12da-4738-ad71-1bc231e45b22_1600x649.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ihh2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93b19120-12da-4738-ad71-1bc231e45b22_1600x649.png" width="1456" height="591" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/93b19120-12da-4738-ad71-1bc231e45b22_1600x649.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:591,&quot;width&quot;:1456,&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_!ihh2!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93b19120-12da-4738-ad71-1bc231e45b22_1600x649.png 424w, https://substackcdn.com/image/fetch/$s_!ihh2!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93b19120-12da-4738-ad71-1bc231e45b22_1600x649.png 848w, https://substackcdn.com/image/fetch/$s_!ihh2!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93b19120-12da-4738-ad71-1bc231e45b22_1600x649.png 1272w, https://substackcdn.com/image/fetch/$s_!ihh2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93b19120-12da-4738-ad71-1bc231e45b22_1600x649.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>Analogy</h3><p>Reliability is like a car that starts every morning, even in winter&#8230;</p><p>It doesn&#8217;t just work 99% of the time--it safely takes you to the right destination. A highly available but unreliable system is like a taxi that always shows up but sometimes takes you to the wrong address.</p><h3>Tradeoff</h3><p>Building reliable systems requires extensive testing, monitoring, error handling, retry logic, and redundancy. This increases development time &amp; operational complexity.</p><h3>Why it matters</h3><p>Prioritize reliability for financial transactions, healthcare systems, data pipelines where data loss is unacceptable, or any system where incorrect behavior is worse than being temporarily unavailable.</p><p>Remember, a personal blog doesn&#8217;t need the same reliability as a hospital patient monitoring system.</p><h2><strong>4. Latency vs Throughput vs Bandwidth</strong></h2><blockquote><p>Latency is the time it takes for a single request to travel from client to server and back, measured in milliseconds.</p><p>Throughput is how many requests your system can handle per unit of time, like requests per second.</p><p>Bandwidth is the maximum amount of data that can be transferred over a network connection in a given time, measured in Mbps or Gbps.</p></blockquote><p>These three metrics are related,,, but measure different aspects of 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_!L_0A!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ac64667-40a1-4290-8976-bc29bd631689_1600x804.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!L_0A!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ac64667-40a1-4290-8976-bc29bd631689_1600x804.png 424w, https://substackcdn.com/image/fetch/$s_!L_0A!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ac64667-40a1-4290-8976-bc29bd631689_1600x804.png 848w, https://substackcdn.com/image/fetch/$s_!L_0A!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ac64667-40a1-4290-8976-bc29bd631689_1600x804.png 1272w, https://substackcdn.com/image/fetch/$s_!L_0A!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ac64667-40a1-4290-8976-bc29bd631689_1600x804.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!L_0A!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ac64667-40a1-4290-8976-bc29bd631689_1600x804.png" width="1456" height="732" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4ac64667-40a1-4290-8976-bc29bd631689_1600x804.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:732,&quot;width&quot;:1456,&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_!L_0A!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ac64667-40a1-4290-8976-bc29bd631689_1600x804.png 424w, https://substackcdn.com/image/fetch/$s_!L_0A!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ac64667-40a1-4290-8976-bc29bd631689_1600x804.png 848w, https://substackcdn.com/image/fetch/$s_!L_0A!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ac64667-40a1-4290-8976-bc29bd631689_1600x804.png 1272w, https://substackcdn.com/image/fetch/$s_!L_0A!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ac64667-40a1-4290-8976-bc29bd631689_1600x804.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>Analogy</h3><p>Think of a highway:</p><ul><li><p>Latency is how long it takes one car to drive from point A to B.</p></li><li><p>Throughput is the number of cars that can complete the journey per hour.</p></li><li><p>Bandwidth is how many lanes a highway has.</p></li></ul><p>You can have an 8-lane highway with high latency over long distances, or a 2-lane road with low latency over short distances.</p><h3>Tradeoff</h3><p>Optimizing for one doesn&#8217;t automatically improve the others&#8230;</p><p>You can increase throughput by adding more servers, but it won&#8217;t reduce latency. You can reduce latency by caching or using a CDN, but it doesn&#8217;t increase throughput.</p><p>Increasing bandwidth helps with large data transfers but doesn&#8217;t reduce latency.</p><h3>Why it matters</h3><p>Focus on low latency for real-time applications such as gaming, video calls, and trading platforms. While optimize throughput for high-traffic APIs and web services. And prioritize bandwidth for video streaming, file transfers, and data-intensive applications.</p><p>Most production systems need to balance all three&#8230;</p><h2><strong>5. Client-Server Architecture</strong></h2><blockquote><p>A model where clients, such as users&#8217; devices, browsers, or mobile apps, send requests to servers, which process those requests and send back responses.</p></blockquote><p>The server hosts the business logic, databases, and resources, while clients provide the user interface. This separation allows multiple clients to access the same server resources simultaneously.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!8yRx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12843f9d-2683-4433-9c20-b3406126f196_1536x1024.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!8yRx!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12843f9d-2683-4433-9c20-b3406126f196_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!8yRx!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12843f9d-2683-4433-9c20-b3406126f196_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!8yRx!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12843f9d-2683-4433-9c20-b3406126f196_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!8yRx!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12843f9d-2683-4433-9c20-b3406126f196_1536x1024.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!8yRx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12843f9d-2683-4433-9c20-b3406126f196_1536x1024.png" width="1456" height="971" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/12843f9d-2683-4433-9c20-b3406126f196_1536x1024.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:971,&quot;width&quot;:1456,&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_!8yRx!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12843f9d-2683-4433-9c20-b3406126f196_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!8yRx!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12843f9d-2683-4433-9c20-b3406126f196_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!8yRx!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12843f9d-2683-4433-9c20-b3406126f196_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!8yRx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12843f9d-2683-4433-9c20-b3406126f196_1536x1024.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>Analogy</h3><p>Client-server is like a restaurant: you sit at a table, place your order with a waiter, and the waiter takes it to the kitchen.</p><p>The kitchen prepares your food and sends it back through the waiter. You don&#8217;t go into the kitchen yourself&#8230;there&#8217;s a clear separation of responsibilities.</p><h3>Tradeoff</h3><p>This architecture centralizes control and data management, making it easier to maintain and secure. Yet the server could become a bottleneck and a single point of failure. If the server goes down, all clients lose access.</p><p>The server also needs to scale to handle increasing numbers of clients.</p><h3>Why it matters</h3><p>Web applications, mobile apps, email systems, and most modern software.</p><p>It&#8217;s the foundation of how the internet works&#8230;Consider alternatives such as peer-to-peer file sharing or edge computing when you need to reduce dependence on central servers.</p><h2><strong>6. Databases</strong></h2><blockquote><p>A database is an organized collection of structured data stored electronically and managed by a Database Management System (DBMS).</p></blockquote><p>Databases allow you to create, read, update, and delete data efficiently.</p><p>They handle concurrent access, ensure data integrity through transactions with ACID properties, and provide query languages to retrieve data. Databases can be relational, with tables organized as rows and columns, or non-relational, such as documents, key-value pairs, or graphs.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!crHM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b498982-21f3-4159-baa3-fb98dc2f601b_1536x1024.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!crHM!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b498982-21f3-4159-baa3-fb98dc2f601b_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!crHM!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b498982-21f3-4159-baa3-fb98dc2f601b_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!crHM!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b498982-21f3-4159-baa3-fb98dc2f601b_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!crHM!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b498982-21f3-4159-baa3-fb98dc2f601b_1536x1024.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!crHM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b498982-21f3-4159-baa3-fb98dc2f601b_1536x1024.png" width="1456" height="971" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5b498982-21f3-4159-baa3-fb98dc2f601b_1536x1024.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:971,&quot;width&quot;:1456,&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_!crHM!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b498982-21f3-4159-baa3-fb98dc2f601b_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!crHM!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b498982-21f3-4159-baa3-fb98dc2f601b_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!crHM!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b498982-21f3-4159-baa3-fb98dc2f601b_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!crHM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b498982-21f3-4159-baa3-fb98dc2f601b_1536x1024.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>Analogy</h3><p>A database is like a highly organized library with a sophisticated cataloging system.</p><p>Instead of wandering through aisles hoping to find a book, you use the catalog to locate what you need instantly. The librarian ensures books don&#8217;t get lost, handles multiple people checking out books simultaneously, and maintains the organization system.</p><h3>Tradeoff</h3><p>Databases provide powerful data management but introduce complexity:</p><p>They require careful schema design, indexing strategies, backup procedures, and monitoring. Poorly designed databases become bottlenecks. Plus, slow queries can bring down your entire application.</p><p>Different database types optimize for different use cases&#8230;so choosing the wrong one can &#8216;hurt&#8217; performance.</p><h3>Why it matters</h3><p>Use databases whenever you need to persist data beyond application restarts, handle concurrent users accessing shared data, maintain data relationships, or query data in flexible ways.</p><p>Almost every production application needs a database&#8230;the question is which type fits your use case.</p><h2><strong>7. SQL vs NoSQL</strong></h2><blockquote><p>SQL databases organize data in tables with predefined schemas, using rows and columns.</p></blockquote><p>They support complex queries, joins across tables, and ACID transactions. Examples: PostgreSQL &amp; MySQL.</p><blockquote><p>NoSQL databases use flexible schemas and store data as documents, key-value pairs, wide columns, or graphs.</p></blockquote><p>They prioritize scalability and flexibility over strict consistency. Examples: MongoDB, Redis, Cassandra, and Neo4j.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!eXaX!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fee256086-881a-4dca-ad71-be8b27a7b10f_1379x1276.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!eXaX!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fee256086-881a-4dca-ad71-be8b27a7b10f_1379x1276.png 424w, https://substackcdn.com/image/fetch/$s_!eXaX!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fee256086-881a-4dca-ad71-be8b27a7b10f_1379x1276.png 848w, https://substackcdn.com/image/fetch/$s_!eXaX!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fee256086-881a-4dca-ad71-be8b27a7b10f_1379x1276.png 1272w, https://substackcdn.com/image/fetch/$s_!eXaX!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fee256086-881a-4dca-ad71-be8b27a7b10f_1379x1276.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!eXaX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fee256086-881a-4dca-ad71-be8b27a7b10f_1379x1276.png" width="1379" height="1276" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ee256086-881a-4dca-ad71-be8b27a7b10f_1379x1276.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1276,&quot;width&quot;:1379,&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_!eXaX!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fee256086-881a-4dca-ad71-be8b27a7b10f_1379x1276.png 424w, https://substackcdn.com/image/fetch/$s_!eXaX!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fee256086-881a-4dca-ad71-be8b27a7b10f_1379x1276.png 848w, https://substackcdn.com/image/fetch/$s_!eXaX!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fee256086-881a-4dca-ad71-be8b27a7b10f_1379x1276.png 1272w, https://substackcdn.com/image/fetch/$s_!eXaX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fee256086-881a-4dca-ad71-be8b27a7b10f_1379x1276.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>Analogy</h3><p>SQL is like a spreadsheet with strict columns&#8230;</p><p>Everyone must follow the same structure, but you can easily combine data from different sheets using formulas.</p><p>NoSQL is like a filing cabinet where each folder can contain different types of documents in different formats&#8230;more flexible, but harder to analyze across folders.</p><h3>Tradeoff</h3><p>SQL databases offer strong consistency, complex querying, and enforced data integrity. They can scale vertically and horizontally, but distributing data across many machines is often complex because of joins and transactional guarantees.</p><p>While NoSQL databases are built to scale horizontally and handle flexible data models. They often trade strong consistency or full relational features for scale and high availability.</p><p>Most companies use both SQL for transactional data and NoSQL for flexibility and scalability.</p><h3>Why it matters</h3><ul><li><p>Use SQL for financial systems, e-commerce orders, user authentication, or anywhere you need ACID guarantees and complex queries across related data.</p></li><li><p>Use NoSQL for user profiles, product catalogs, real-time analytics, session storage, or when your schema changes frequently.</p></li></ul><div><hr></div><p><em><strong>Reminder: this is a teaser of the subscriber-only post, exclusive to my golden members.</strong></em></p><p>When you upgrade, you&#8217;ll get:</p><ul><li><p><strong>Full access to system design case studies</strong></p></li><li><p>FREE access to (coming) Design, Build, Scale newsletter series</p></li><li><p><strong>FREE access to (coming) popular interview question breakdowns</strong></p></li></ul><p>And more!</p><p>Get 10x the results you currently get with 1/10th the time, energy &amp; effort.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/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://newsletter.systemdesign.one/subscribe?"><span>Subscribe now</span></a></p>
      <p>
          <a href="https://newsletter.systemdesign.one/p/system-design-concepts">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[I struggled to code with AI until I learned this workflow]]></title><description><![CDATA[#119: AI coding workflow]]></description><link>https://newsletter.systemdesign.one/p/ai-coding-workflow</link><guid isPermaLink="false">https://newsletter.systemdesign.one/p/ai-coding-workflow</guid><dc:creator><![CDATA[Neo Kim]]></dc:creator><pubDate>Mon, 02 Feb 2026 11:30:39 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/82fd5b97-da72-4489-b2e1-d50add2292cf_1280x720.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/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">Get my system design playbook for FREE on newsletter signup:</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><ul><li><p><em><a href="https://newsletter.systemdesign.one/p/ai-coding-workflow/?action=share">Share this post</a> &amp; I'll send you some rewards for the referrals.</em></p></li></ul><div><hr></div><blockquote><p>Everyone talks about using AI to write code like it&#8217;s a vending machine:</p><p><em>&#8220;Paste your problem, get a working solution.&#8221;</em></p></blockquote><p>The first time I tried it, I learned the hard way that this is not how it works in real projects&#8230;</p><p>The model would confidently suggest code that called functions that didn&#8217;t exist, assumed libraries we weren&#8217;t using, or skipped constraints that felt obvious to me<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a>. The output looked polished.</p><p>The moment I ran it&#8230; It fell apart.</p><p>After enough trial and error, I stopped trying to &#8220;prompt better&#8221; and started working differently. What finally made AI useful wasn&#8217;t a magic tool or a clever prompt. It was a simple loop that kept the model on a short leash and kept you in the driver&#8217;s seat:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!m84o!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffac50153-fc51-46f5-9080-7a641e343052_1390x134.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!m84o!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffac50153-fc51-46f5-9080-7a641e343052_1390x134.png 424w, https://substackcdn.com/image/fetch/$s_!m84o!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffac50153-fc51-46f5-9080-7a641e343052_1390x134.png 848w, https://substackcdn.com/image/fetch/$s_!m84o!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffac50153-fc51-46f5-9080-7a641e343052_1390x134.png 1272w, https://substackcdn.com/image/fetch/$s_!m84o!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffac50153-fc51-46f5-9080-7a641e343052_1390x134.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!m84o!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffac50153-fc51-46f5-9080-7a641e343052_1390x134.png" width="1390" height="134" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fac50153-fc51-46f5-9080-7a641e343052_1390x134.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:134,&quot;width&quot;:1390,&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_!m84o!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffac50153-fc51-46f5-9080-7a641e343052_1390x134.png 424w, https://substackcdn.com/image/fetch/$s_!m84o!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffac50153-fc51-46f5-9080-7a641e343052_1390x134.png 848w, https://substackcdn.com/image/fetch/$s_!m84o!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffac50153-fc51-46f5-9080-7a641e343052_1390x134.png 1272w, https://substackcdn.com/image/fetch/$s_!m84o!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffac50153-fc51-46f5-9080-7a641e343052_1390x134.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>This newsletter breaks that loop down step by step.</p><p>It&#8217;s written for software engineers who are new to AI coding tools and want a practical starting point: not a tour of every product on the market, but a repeatable method you can use tomorrow.</p><p>The core idea is simple:</p><p>AI works best as an iterative loop, not a one-shot request. You steer. The model fills in the gaps. And because it does less guessing, you spend less time cleaning up confident mistakes.</p><p>Onward.</p><div><hr></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://coderabbit.link/neo-jan" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Pvyy!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbef9f0b7-b6e9-49ab-b162-4c9b1313d5d1_1200x628.png 424w, https://substackcdn.com/image/fetch/$s_!Pvyy!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbef9f0b7-b6e9-49ab-b162-4c9b1313d5d1_1200x628.png 848w, https://substackcdn.com/image/fetch/$s_!Pvyy!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbef9f0b7-b6e9-49ab-b162-4c9b1313d5d1_1200x628.png 1272w, https://substackcdn.com/image/fetch/$s_!Pvyy!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbef9f0b7-b6e9-49ab-b162-4c9b1313d5d1_1200x628.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Pvyy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbef9f0b7-b6e9-49ab-b162-4c9b1313d5d1_1200x628.png" width="1200" height="628" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bef9f0b7-b6e9-49ab-b162-4c9b1313d5d1_1200x628.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:628,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:242997,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:&quot;https://coderabbit.link/neo-jan&quot;,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/178607500?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbef9f0b7-b6e9-49ab-b162-4c9b1313d5d1_1200x628.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!Pvyy!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbef9f0b7-b6e9-49ab-b162-4c9b1313d5d1_1200x628.png 424w, https://substackcdn.com/image/fetch/$s_!Pvyy!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbef9f0b7-b6e9-49ab-b162-4c9b1313d5d1_1200x628.png 848w, https://substackcdn.com/image/fetch/$s_!Pvyy!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbef9f0b7-b6e9-49ab-b162-4c9b1313d5d1_1200x628.png 1272w, https://substackcdn.com/image/fetch/$s_!Pvyy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbef9f0b7-b6e9-49ab-b162-4c9b1313d5d1_1200x628.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>I&#8217;m happy to partner with <strong><a href="https://coderabbit.link/neo-jan">CodeRabbit</a></strong> on this newsletter. Code reviews usually delay feature deliveries and overload reviewers. And I genuinely believe CodeRabbit solves this problem.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://coderabbit.link/neo-jan&quot;,&quot;text&quot;:&quot;Try CodeRabbit&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://coderabbit.link/neo-jan"><span>Try CodeRabbit</span></a></p><div><hr></div><p>I want to introduce <a href="https://www.linkedin.com/in/whats-ai/">Louis-Fran&#231;ois Bouchard</a> as a guest author.</p><p>He focuses on making AI more accessible by helping people learn practical AI skills for the industry alongside 500k+ fellow learners.</p><div><hr></div><h2><strong>TL;DR</strong></h2><p>If you&#8217;re new to using AI for coding, this is the set of habits that prevents most pain.</p><ul><li><p><strong>Treat AI output like a draft, not an answer.</strong> Models can sound certain while being completely wrong, so anything that matters still gets reviewed and verified.</p></li><li><p><strong>Start with context, the way you&#8217;d brief a teammate.</strong> If you don&#8217;t share constraints, library versions, project rules, and intended behavior, the model will &#8216;happily&#8217; invent them for you.</p></li><li><p><strong>Ask for a plan before you ask for code.</strong> Plans are cheap to change. Code is expensive to unwind. I&#8217;ll usually approve the approach first, then ask for small, step-by-step changes.</p></li><li><p><strong>Use reviews and tests as a safety net.</strong> I still do a normal pull request<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-2" href="#footnote-2" target="_self">2</a> review and rely on tests to verify behavior and catch edge cases<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-3" href="#footnote-3" target="_self">3</a>.</p></li></ul><div><hr></div><h2><strong>Quick Glossary</strong></h2><p>Before we dive in, here&#8217;s the small vocabulary I&#8217;ll use throughout.</p><p>It&#8217;s not exhaustive; it&#8217;s just enough to keep the rest of the article readable:</p><ul><li><p><strong>AI Editor</strong> (e.g., Cursor, VS Code + GitHub Copilot) is a code editor with AI built in. It can suggest completions, refactor functions<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-4" href="#footnote-4" target="_self">4</a>, and generate code using your project files as context.</p></li><li><p><strong>Chat model</strong> (e.g., ChatGPT, Claude, or Gemini) is a conversational AI you interact with in plain language. It&#8217;s useful when you&#8217;re still figuring out what to do: brainstorming approaches, explaining an error, comparing trade-offs, or sanity-checking a design before you write code.</p></li><li><p><strong>AI code review</strong> tools (e.g., <a href="https://coderabbit.link/neo-jan">CodeRabbit</a>) automatically review pull requests using AI, posting summaries and line-by-line suggestions.</p></li><li><p><strong>Search assistant</strong> (e.g., Perplexity) combines chat with web search. It&#8217;s what you reach for when you need to verify that a suggested API call is real, that a library feature exists in the version you&#8217;re using, or that you&#8217;re not about to copy-paste something that expired two releases ago.</p></li></ul><div><hr></div><h2><strong>The Mental Model</strong></h2><p>Before the workflow, it helps to be honest about what AI coding assistants are and aren&#8217;t.</p><p>They&#8217;re fantastic when the problem is well-scoped and sitting right in front of them. They&#8217;re unreliable the moment you assume they &#8220;know&#8221; what you didn&#8217;t explicitly provide. The workflow is basically a way to stay in the first zone and avoid the second.</p><p>When you give clear requirements, AI is great at drafting functions, refactoring code, scaffolding tests, and talking through error messages.</p><p>But it has a hard boundary: it only knows what it can see in the current context. It doesn&#8217;t remember your last chat; it doesn&#8217;t know your architecture or conventions, and it won&#8217;t reliably warn you when it&#8217;s guessing. It just keeps going confidently.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!M_YZ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b2a6210-bcf2-4bf8-be92-1f2ba0b4d4d2_1080x1080.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!M_YZ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b2a6210-bcf2-4bf8-be92-1f2ba0b4d4d2_1080x1080.png 424w, https://substackcdn.com/image/fetch/$s_!M_YZ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b2a6210-bcf2-4bf8-be92-1f2ba0b4d4d2_1080x1080.png 848w, https://substackcdn.com/image/fetch/$s_!M_YZ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b2a6210-bcf2-4bf8-be92-1f2ba0b4d4d2_1080x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!M_YZ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b2a6210-bcf2-4bf8-be92-1f2ba0b4d4d2_1080x1080.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!M_YZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b2a6210-bcf2-4bf8-be92-1f2ba0b4d4d2_1080x1080.png" width="520" height="520" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8b2a6210-bcf2-4bf8-be92-1f2ba0b4d4d2_1080x1080.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1080,&quot;width&quot;:1080,&quot;resizeWidth&quot;:520,&quot;bytes&quot;:851658,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/185649034?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b2a6210-bcf2-4bf8-be92-1f2ba0b4d4d2_1080x1080.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_!M_YZ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b2a6210-bcf2-4bf8-be92-1f2ba0b4d4d2_1080x1080.png 424w, https://substackcdn.com/image/fetch/$s_!M_YZ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b2a6210-bcf2-4bf8-be92-1f2ba0b4d4d2_1080x1080.png 848w, https://substackcdn.com/image/fetch/$s_!M_YZ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b2a6210-bcf2-4bf8-be92-1f2ba0b4d4d2_1080x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!M_YZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b2a6210-bcf2-4bf8-be92-1f2ba0b4d4d2_1080x1080.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>I&#8217;ve seen AI call library functions that don&#8217;t exist, use syntax from the wrong version, and ignore constraints I assumed were obvious. The pattern was always the same: the AI didn&#8217;t know what I hadn&#8217;t told it, so it filled the gaps by inventing something plausible.</p><p>Once I understood this, three principles shaped how I work:</p><p><strong>1. Give more context than you think you need.</strong> Just like I&#8217;d brief a colleague who just joined the project, I brief the AI every time. If I don&#8217;t share the details, it invents them.</p><p><strong>2. Guide it with specific steps.</strong> AI struggles with &#8220;build me a web app,&#8221; but does well with &#8220;add input validation for these fields, return a clear error message, and write a test that proves invalid input is rejected.&#8221; The more specific my request, the better the output.</p><p><strong>3. If it matters, verify it.</strong> Whenever the AI produces security-sensitive logic, a database migration, or an algorithm that must be correct, I review it myself and add tests that prove the behavior.</p><blockquote><p><em>A good way to hold all of this in your head is:</em></p><p>AI is a smart teammate who joined your project five minutes ago.</p><p>They can write quickly, but they don&#8217;t know your architecture, your conventions, or your constraints unless you tell them.</p><p>That&#8217;s why the mistakes look so predictable: the model isn&#8217;t &#8220;being dumb,&#8221; it&#8217;s filling in gaps you didn&#8217;t realise you left open.</p></blockquote><p>Once I started seeing it that way, the fix wasn&#8217;t a better one-shot prompt<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-5" href="#footnote-5" target="_self">5</a>.</p><p>It was a repeatable loop that forced me to brief the model, force clarity early, and keep changes small enough to verify.</p><div><hr></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://github.com/ScoopInstaller/Extras/pull/15266" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!IVbI!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F072e8c1c-10f6-494a-9b1a-e12a712d30b1_2828x1556.png 424w, https://substackcdn.com/image/fetch/$s_!IVbI!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F072e8c1c-10f6-494a-9b1a-e12a712d30b1_2828x1556.png 848w, https://substackcdn.com/image/fetch/$s_!IVbI!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F072e8c1c-10f6-494a-9b1a-e12a712d30b1_2828x1556.png 1272w, https://substackcdn.com/image/fetch/$s_!IVbI!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F072e8c1c-10f6-494a-9b1a-e12a712d30b1_2828x1556.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!IVbI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F072e8c1c-10f6-494a-9b1a-e12a712d30b1_2828x1556.png" width="728" height="400.5" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/072e8c1c-10f6-494a-9b1a-e12a712d30b1_2828x1556.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:801,&quot;width&quot;:1456,&quot;resizeWidth&quot;:728,&quot;bytes&quot;:395002,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:&quot;https://github.com/ScoopInstaller/Extras/pull/15266&quot;,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/176627115?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F072e8c1c-10f6-494a-9b1a-e12a712d30b1_2828x1556.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!IVbI!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F072e8c1c-10f6-494a-9b1a-e12a712d30b1_2828x1556.png 424w, https://substackcdn.com/image/fetch/$s_!IVbI!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F072e8c1c-10f6-494a-9b1a-e12a712d30b1_2828x1556.png 848w, https://substackcdn.com/image/fetch/$s_!IVbI!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F072e8c1c-10f6-494a-9b1a-e12a712d30b1_2828x1556.png 1272w, https://substackcdn.com/image/fetch/$s_!IVbI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F072e8c1c-10f6-494a-9b1a-e12a712d30b1_2828x1556.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>I&#8217;m not sure if you're aware of this&#8230;</p><p>When you open a pull request, <strong><a href="https://coderabbit.link/neo-jan">CodeRabbit</a></strong> can generate a summary of code changes for the reviewer. It helps them quickly understand complex changes and assess the impact on the codebase.</p><p>Speed up the code review process.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://coderabbit.link/neo-jan&quot;,&quot;text&quot;:&quot;Try CodeRabbit&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://coderabbit.link/neo-jan"><span>Try CodeRabbit</span></a></p><div><hr></div><h2><strong>The Workflow</strong></h2><p>The loop is the same whether I&#8217;m fixing a bug, adding a feature, or cleaning up a messy module.</p><p>It keeps the AI from freelancing, and it keeps me from treating &#8220;code that looks plausible&#8221; as &#8220;code that&#8217;s ready to ship.&#8221;</p><p>Here&#8217;s the loop:</p><ol><li><p><strong>Context:</strong> I share project background, constraints, and the relevant code so the AI isn&#8217;t guessing.</p></li><li><p><strong>Plan:</strong> I ask for a strategy before any code gets written.</p></li><li><p><strong>Code:</strong> I generate or edit code one step at a time, so changes stay small and reviewable.</p></li><li><p><strong>Review:</strong> I carefully check the output and often use AI-assisted pull request reviews as a second set of eyes.</p></li><li><p><strong>Test:</strong> I run tests, and I&#8217;ll often have AI generate new tests that lock in the intended behavior.</p></li><li><p><strong>Iterate:</strong> I debug failures, refine the request, and repeat until the change is solid.</p></li></ol><p>I use different tools at different points in the loop.</p><p>Each one is good at a specific job:</p><ul><li><p>An editor is good at working inside a repo,</p></li><li><p>A chat model is good at thinking in plain language,</p></li><li><p>And review/testing tools are good at catching things I&#8217;d miss when I&#8217;m tired.</p></li></ul><p>The rest of this newsletter breaks down each step.</p><blockquote><p>The most important step is the first one:</p><p>If the model is guessing about your setup, everything downstream becomes cleanup. So the workflow starts with context.</p></blockquote><h3><strong>Step 1: Context</strong></h3><p>Most AI mistakes in code have the same root cause.</p><p>The model is guessing in a vacuum. Someone pastes a function, types &#8220;fix this,&#8221; and acts surprised when the suggestion ignores half the system.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!6wJp!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcf11fbf-73e2-4f22-8e9e-73de8051904b_1080x1080.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!6wJp!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcf11fbf-73e2-4f22-8e9e-73de8051904b_1080x1080.png 424w, https://substackcdn.com/image/fetch/$s_!6wJp!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcf11fbf-73e2-4f22-8e9e-73de8051904b_1080x1080.png 848w, https://substackcdn.com/image/fetch/$s_!6wJp!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcf11fbf-73e2-4f22-8e9e-73de8051904b_1080x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!6wJp!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcf11fbf-73e2-4f22-8e9e-73de8051904b_1080x1080.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!6wJp!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcf11fbf-73e2-4f22-8e9e-73de8051904b_1080x1080.png" width="520" height="520" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fcf11fbf-73e2-4f22-8e9e-73de8051904b_1080x1080.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1080,&quot;width&quot;:1080,&quot;resizeWidth&quot;:520,&quot;bytes&quot;:2811772,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/185649034?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcf11fbf-73e2-4f22-8e9e-73de8051904b_1080x1080.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_!6wJp!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcf11fbf-73e2-4f22-8e9e-73de8051904b_1080x1080.png 424w, https://substackcdn.com/image/fetch/$s_!6wJp!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcf11fbf-73e2-4f22-8e9e-73de8051904b_1080x1080.png 848w, https://substackcdn.com/image/fetch/$s_!6wJp!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcf11fbf-73e2-4f22-8e9e-73de8051904b_1080x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!6wJp!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcf11fbf-73e2-4f22-8e9e-73de8051904b_1080x1080.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>&#8220;Fix this&#8221;</em> is the fastest way to make the model hallucinate&#8230;</p><p>Without a project background and constraints, it has no choice but to fill gaps with whatever sounds right: &#8216;functions that don&#8217;t exist, syntax from the wrong version, solutions that break conventions elsewhere in the repo&#8217;.</p><blockquote><p>So, for anything that is not small, I flip the default: documentation and rules go first. Code goes second.</p></blockquote><p>This is easiest with an AI editor that can automatically pull in files.</p><p>I use Cursor, which lets me highlight code, pull in other files from my project, and ask the AI to do specific work with all of that as context. The pleasant part is I can swap models on the fly: a fast one for quick edits, a heavier reasoning model when I need to solve a tricky bug.</p><p>VS Code with Copilot or Claude Code offers similar features if you prefer to stay in that ecosystem.</p><p>When a task is even <strong>moderately complex</strong>, I load three kinds of context:</p><h4><strong>1. Project background</strong></h4><p>I keep an updated README<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-6" href="#footnote-6" target="_self">6</a> for each project and start most AI sessions by attaching it with a simple opener:</p><pre><code>Read the README below to understand the project. Then I will give you a specific task.</code></pre><p>If the change touches something sensitive (like payments), I include the key files in that first message too. By the time I describe the change, the assistant has already seen the neighborhood.</p><h4><strong>2. Rules and constraints</strong></h4><p>I keep a rules file (sometimes called <code>AGENTS.md</code> or <code>CLAUDE.md</code>)<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-7" href="#footnote-7" target="_self">7</a> that bundles project scope, coding style, version constraints (for example, &#8220;this service runs on <code>Django 4.0</code>&#8221;), and a few hard rules (&#8220;never call this external API in development,&#8221; &#8220;all dates must be UTC&#8221;).</p><p>Some tools support &#8220;rules&#8221; or &#8220;custom instructions&#8221; that help me avoid repeating myself in every session.</p><h4><strong>3. Relevant source and signals</strong></h4><p>For bugs or features, I paste the function or file involved along with stack traces<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-8" href="#footnote-8" target="_self">8</a> or logs.</p><p>A single error line is like a screenshot of one pixel. The assistant needs more than that if I want real reasoning instead of optimistic guessing.</p><p><strong>Here&#8217;s a reusable prompt pattern:</strong></p><pre><code>Read @README to understand the project scope, architecture, and constraints.

Read @AGENTS.md to learn the coding style, rules, and constraints for this codebase.

Then read @main.py, @business_logic_1.py, and @business_logic_2.py carefully.

Your task is to update @business_logic_2.py to implement the following changes:

1. &lt;change 1&gt;
2. &lt;change 2&gt;
3. &lt;change 3&gt;

Follow the conventions in the README and AGENTS file.

Do not modify other files unless strictly necessary and explain any extra changes you make.</code></pre><p>The structure stays the same every time: context, then rules, then a precise task.</p><p>I swap out the filenames and the change list, but the pattern holds.</p><p>One thing I learned the hard way: <em>more text isn&#8217;t always better</em>. The best briefings are short and focused. They explain what the project is for, how the main pieces fit together, and which rules actually matter. If I notice I&#8217;m pasting more than a human would reasonably read before starting work, I cut it down.</p><p>One final detail that matters: context should be <strong>curated</strong>&#8230; not dumped.</p><p>The best briefings are short and decisive, enough to prevent guessing, but not so much that the model loses the signal. If I&#8217;m pasting more than a human would reasonably read before starting, I cut it down.</p><h3><strong>Step 2: Plan Before You Code</strong></h3><blockquote><p>Context answers &#8220;where am I?&#8221;</p><p>It doesn&#8217;t answer &#8220;what should I build?&#8221;</p></blockquote><p>That&#8217;s where things usually go sideways.</p><p>If you let AI write code immediately, it often picks a strange approach, optimizes the wrong thing, or quietly ignores constraints.</p><p>I&#8217;ve learned to force a two-step process: <em>plan first, then code.</em></p><p>I usually do the planning step in a chat model like Claude, ChatGPT, or Gemini. ChatGPT works well when the problem is fuzzy, and I need structured thinking. Once the design feels reasonable, I switch to an AI editor like Cursor or Claude Code in VS Code, where the implementation happens with the repo open.</p><p><strong>First: Ask for a plan only</strong></p><p>For any non-trivial change, I first describe the feature or bug in plain language. That initial exchange is just about getting the idea into a workable shape:</p><pre><code>Here is the feature I want to build and some context.

Help me design it.

What needs to change?

Which modules are involved?

What are the main steps?</code></pre><p>The key is to stop the AI from jumping straight into code. I&#8217;ll often say explicitly, &#8220;Do not write any code until I say approved.&#8221;</p><p><strong>Then: Approve and implement in small steps</strong></p><p>Once the plan looks reasonable, I approve it and ask the AI to implement one step at a time.</p><p>This is where I usually switch from a chat model to an AI editor like Cursor or VS Code with Copilot, since the implementation happens inside the actual codebase. For each step, I ask the AI to explain what it&#8217;s about to change and propose the code for that step only.</p><p>Small steps are easier to review and easier to undo if something goes wrong.</p><p><strong>Here&#8217;s a prompt template I reuse:</strong></p><pre><code>You are a senior engineer helping me with a new change.

First, read the description of the feature or bug:
&lt;insert feature or bug description and any relevant context&gt;

Step 1 &#8212; Plan only:

- Think step by step and outline a clear plan.
- List the main steps you would take.
- Call out important decisions or tradeoffs.
- Mention edge cases we should keep in mind.

Stop after the plan. Do not write any code until I say &#8220;approved.&#8221;


Step 2 &#8212; Implement:

Once I say &#8220;approved,&#8221; implement the plan one step at a time:

- For each step, explain what you are about to change.
- Propose the code changes for that step only.
- Write tests for that step where it makes sense.</code></pre><p>If the AI recommends a library or function I&#8217;ve never seen, I&#8217;ll verify it actually exists using a search assistant or official docs. Models sometimes hallucinate APIs that sound plausible but don&#8217;t exist.</p><p>This pattern is especially useful when I&#8217;m working in a new stack or unfamiliar codebase. Instead of reading docs for hours, I ask the AI to explain the stack, sketch a design, and then help me implement it. The AI explains before it writes, so I learn as I go.</p><p>It also helps when a change touches multiple parts of the system, since a plan lets me see the full scope before I make edits everywhere.</p><p>Same with subtle bugs I don&#8217;t fully understand. For a slow database query, instead of asking &#8220;make this faster,&#8221; I ask the AI to reason through why it might be slow and what options exist. Only after that reasoning do I ask for the actual fix.</p><p>Fixing a plan is cheaper than fixing a pile of code. The &#8220;approved&#8221; step forces me to agree with the approach before the AI starts typing.</p><h3><strong>Step 3: Lightweight Multi-Agent Coding</strong></h3><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!tECg!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15fb51f5-e743-42dc-b4ed-cd5e9601746a_1204x182.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!tECg!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15fb51f5-e743-42dc-b4ed-cd5e9601746a_1204x182.png 424w, https://substackcdn.com/image/fetch/$s_!tECg!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15fb51f5-e743-42dc-b4ed-cd5e9601746a_1204x182.png 848w, https://substackcdn.com/image/fetch/$s_!tECg!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15fb51f5-e743-42dc-b4ed-cd5e9601746a_1204x182.png 1272w, https://substackcdn.com/image/fetch/$s_!tECg!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15fb51f5-e743-42dc-b4ed-cd5e9601746a_1204x182.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!tECg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15fb51f5-e743-42dc-b4ed-cd5e9601746a_1204x182.png" width="1204" height="182" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/15fb51f5-e743-42dc-b4ed-cd5e9601746a_1204x182.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:182,&quot;width&quot;:1204,&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_!tECg!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15fb51f5-e743-42dc-b4ed-cd5e9601746a_1204x182.png 424w, https://substackcdn.com/image/fetch/$s_!tECg!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15fb51f5-e743-42dc-b4ed-cd5e9601746a_1204x182.png 848w, https://substackcdn.com/image/fetch/$s_!tECg!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15fb51f5-e743-42dc-b4ed-cd5e9601746a_1204x182.png 1272w, https://substackcdn.com/image/fetch/$s_!tECg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15fb51f5-e743-42dc-b4ed-cd5e9601746a_1204x182.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Once I got comfortable with planning before coding, I started using a simple trick that makes AI output more reliable: <em>I split the work into roles</em>.</p><p>This isn&#8217;t a complex &#8216;agent system<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-9" href="#footnote-9" target="_self">9</a>.&#8217; Most of the time, it&#8217;s the same AI model, just prompted differently for each job.</p><p>Sometimes I use different models for different roles: </p><ul><li><p>Claude or ChatGPT for the Planner role (where reasoning matters),</p></li><li><p>Then, a faster model for the Implementer role (where the task is already well-defined and speed matters more).</p></li></ul><p>In Cursor, I can switch models mid-task, which makes this easy.</p><h4><strong>The four roles I use:</strong></h4><p><strong>1. Planner:</strong> Breaks down the task into steps and calls out edge cases. (This is what we covered in Step 2.)</p><p><strong>2. Implementer:</strong> Writes code strictly based on the approved plan. I prompt it with something like: <code>&#8220;Follow the approved plan. Change only the files I list. Keep the change small. If something is unclear, ask before coding.&#8221;</code></p><p><strong>3. Tester:</strong> Writes tests and edge cases. I prompt it with: <code>&#8220;Write a unit test<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-10" href="#footnote-10" target="_self">10</a> for the happy path<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-11" href="#footnote-11" target="_self">11</a>. Write at least two edge case tests<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-12" href="#footnote-12" target="_self">12</a>. If this were a bug fix, write a regression test that would fail before the fix.&#8221;</code></p><p><strong>4. Explainer:</strong> Summarizes what changed and why. I prompt it with: <code>&#8220;Summarize changes by file. Explain the logic in plain language. List what could break and how the tests cover it.&#8221;</code></p><p>Big prompts encourage messy answers.</p><p>When I ask the AI to plan, implement, test, and explain all at once, the output gets tangled. When I split roles, I get a checklist, then a small change, then tests, then an explanation. Each piece is easier to review.</p><p>Long chats also drift. After enough back-and-forth, the AI forgets earlier context or recycles bad ideas. Short, focused threads stay sharp.</p><blockquote><p><strong>Practical tip: summarise between steps.</strong></p></blockquote><p>When I finish one role, I ask for a short summary before moving to the next. Then I paste that summary into the next prompt. This keeps each step focused and prevents context from getting lost across a long conversation.</p><h3><strong>Step 4: Review the Output</strong></h3><p>AI-generated code needs extra review.</p><p>The model is confident even when it&#8217;s wrong, and subtle bugs hide easily in code that looks plausible. This is where I add a layer of automated review before merging anything.</p><p>One way to do this is with an AI code review tool like <a href="https://coderabbit.link/neo-jan">CodeRabbit</a>, which integrates with GitHub and GitLab. When you open a pull request, it auto<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-13" href="#footnote-13" target="_self">13</a>matically reviews the diff<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-14" href="#footnote-14" target="_self">14</a> and posts comments directly in the PR thread. This kind of tool catches issues that slip past manual reviews, especially when you&#8217;re tired or rushing.</p><p>A tool like <a href="https://coderabbit.link/neo-jan">CodeRabbit</a> typically gives you two things:</p><ul><li><p>First, a summary of what changed, often with a file-by-file walkthrough. This helps confirm the pull request matches your intent before looking at the details.</p></li><li><p>Second, line-by-line comments with suggestions. These often flag missing error handling, edge cases, potential security issues, and logic bugs like off-by-one errors. It can also run the code through linters and security analyzers during the review.</p></li></ul><p>When you push more commits to the same PR, it reviews the new changes incrementally rather than repeating the entire review.</p><p><strong>An example pull request flow</strong></p><p>Here&#8217;s what a typical flow looks like:</p><ol><li><p>Open a PR with a small, focused change.</p></li><li><p>The AI review tool automatically posts comments.</p></li><li><p>Read the comments, fix real issues, and reply to anything that&#8217;s noise or missing context.</p></li><li><p>Then do a final human pass before merging.</p></li></ol><p>Not every comment requires action. Sort them into two buckets:</p><ul><li><p><strong>Must-fix:</strong> logic errors, missing error handling, security issues</p></li><li><p><strong>Worth considering:</strong> style preferences, naming suggestions, alternative approaches</p></li></ul><blockquote><p>If you&#8217;re unsure whether something matters, ask yourself: </p><ul><li><p>Would this likely cause a bug?</p></li><li><p>Or would this confuse someone reading the code later?</p></li></ul><p>If yes to either, fix it or add a test.</p></blockquote><p>AI review tools have the same limitations as other AI tools.</p><p>They sometimes flag things that aren&#8217;t problems or suggest patterns that don&#8217;t match the codebase. The goal is to catch obvious problems early, not to treat every comment as a mandate.</p><p>Always do a final human pass before merging.</p><h3><strong>Step 5: Test the Change</strong></h3><p>Tests are part of the flow, not a later chore.</p><p>After any change that isn&#8217;t small, I ask for tests immediately. I don&#8217;t wait until the feature is complete. Tests serve both as verification and as documentation. If the AI can&#8217;t write a sensible test for the code it just produced, that&#8217;s often a sign the code itself is unclear&#8230;</p><p>I request different tests depending on the situation.</p><p>For new functions, I ask for unit tests that cover the happy path and edge cases. When I used AI to build a React component in a stack I barely knew, my immediate follow-up was, &#8220;Now write unit tests for this component.&#8221; The tests showed me what the component was supposed to do and how it handled different inputs.</p><p>For bug fixes, I ask for a regression test that would have failed before the fix. This proves the fix works and helps prevent the bug from returning later. For changes that touch multiple components or an endpoint, I ask for one minimal integration or end-to-end test<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-15" href="#footnote-15" target="_self">15</a>.</p><p>I paste a short feature description and ask for a realistic user flow and a few edge cases.</p><h4><strong>Prompt templates I reuse</strong></h4><p><strong>For unit tests:</strong></p><pre><code>Write unit tests for this function.

Cover the happy path and at least two edge cases.</code></pre><p><strong>For regression tests:</strong></p><pre><code>Write a regression test for this bug.

The test should fail before the fix and pass after.</code></pre><p><strong>For integration or end-to-end tests:</strong></p><pre><code>Write a minimal integration test for this feature.

Include one realistic user flow and a few edge cases.</code></pre><p><strong>For reviewing existing tests:</strong></p><pre><code>Review these tests.

Are there obvious edge cases missing or any weak assertions?</code></pre><p>When I first started using AI for code, I would generate a function and move on.</p><p>Tests came later, if at all. Bugs shipped. And I didn&#8217;t always understand what the code was doing. Now I ask for tests right after the code. Reading the test often teaches me more than reading the function. It shows the inputs, the expected outputs, and the edge cases the code is supposed to handle.</p><p>If the generated test doesn&#8217;t make sense, I treat that as a signal. Either the code is unclear, or my prompt was incomplete. Either way, I go back before moving forward.</p><h3><strong>Step 6: Debug and Iterate</strong></h3><p>When something breaks&#8230; I don&#8217;t just paste an error and hope.</p><p>I give the model the same information I&#8217;d give a colleague: the error, the function, and enough context to reason through the problem.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!5hbn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78b5a135-e435-4de2-94ce-774eb5b5da7f_1164x848.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!5hbn!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78b5a135-e435-4de2-94ce-774eb5b5da7f_1164x848.png 424w, https://substackcdn.com/image/fetch/$s_!5hbn!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78b5a135-e435-4de2-94ce-774eb5b5da7f_1164x848.png 848w, https://substackcdn.com/image/fetch/$s_!5hbn!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78b5a135-e435-4de2-94ce-774eb5b5da7f_1164x848.png 1272w, https://substackcdn.com/image/fetch/$s_!5hbn!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78b5a135-e435-4de2-94ce-774eb5b5da7f_1164x848.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!5hbn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78b5a135-e435-4de2-94ce-774eb5b5da7f_1164x848.png" width="647" height="471.35395189003435" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/78b5a135-e435-4de2-94ce-774eb5b5da7f_1164x848.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:848,&quot;width&quot;:1164,&quot;resizeWidth&quot;:647,&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_!5hbn!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78b5a135-e435-4de2-94ce-774eb5b5da7f_1164x848.png 424w, https://substackcdn.com/image/fetch/$s_!5hbn!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78b5a135-e435-4de2-94ce-774eb5b5da7f_1164x848.png 848w, https://substackcdn.com/image/fetch/$s_!5hbn!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78b5a135-e435-4de2-94ce-774eb5b5da7f_1164x848.png 1272w, https://substackcdn.com/image/fetch/$s_!5hbn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78b5a135-e435-4de2-94ce-774eb5b5da7f_1164x848.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>A single error line is rarely enough. The model needs more than that to produce a useful diagnosis.</p><p>Here is what I include:</p><ul><li><p>Error message or stack trace.</p></li><li><p>Function where the error occurs.</p></li><li><p>Relevant surrounding code or types.</p></li><li><p>What I expected to happen and what actually happened.</p></li></ul><p>I avoid pasting only the error with no code, dumping an entire file without pointing to the relevant section, or just saying &#8220;it doesn&#8217;t work&#8221; without describing the failure.</p><p><strong>The prompt I use for debugging </strong>(I usually ask for both the explanation and the fix in one request):</p><pre><code>Here is the function and the error message.

Explain why this is happening.

Then rewrite the function using best practices, while keeping it efficient and readable.</code></pre><p>Asking for both gives me a diagnosis and a fix in one shot. It also helps me learn what went wrong, not just how to patch it.</p><p>If a fix doesn&#8217;t work and I keep saying &#8220;try again&#8221; in the same thread, the suggestions usually get worse. The model circles the same wrong idea with slightly different words.</p><blockquote><p>My rule: if I&#8217;ve asked twice and the answers are getting repetitive or worse, I stop.</p><p>I start a fresh chat, restate the problem with better context, and narrow the question.</p></blockquote><p>For example, instead of &#8220;fix this function,&#8221; I ask, &#8220;under what conditions could this variable be null here?&#8221; Fresh context plus a smaller question beats a tired thread most of the time.</p><p>Sometimes I realize I don&#8217;t understand the problem well enough to evaluate the fix. When that happens, I stop asking for code and start asking for an explanation:</p><pre><code>Do not fix anything yet.

Explain what this function does, step by step.

Then list the most likely failure cases.</code></pre><p>Once I understand the logic, I go back to asking for a targeted fix.</p><p>This avoids the loop of accepting fixes I don&#8217;t understand and hoping one of them works.</p><div><hr></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://coderabbit.link/neo-jan" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!tHi0!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccbf27ab-cea5-4105-81c0-4fe848b50c7e_1456x880.webp 424w, https://substackcdn.com/image/fetch/$s_!tHi0!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccbf27ab-cea5-4105-81c0-4fe848b50c7e_1456x880.webp 848w, https://substackcdn.com/image/fetch/$s_!tHi0!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccbf27ab-cea5-4105-81c0-4fe848b50c7e_1456x880.webp 1272w, https://substackcdn.com/image/fetch/$s_!tHi0!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccbf27ab-cea5-4105-81c0-4fe848b50c7e_1456x880.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!tHi0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccbf27ab-cea5-4105-81c0-4fe848b50c7e_1456x880.webp" width="1456" height="880" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ccbf27ab-cea5-4105-81c0-4fe848b50c7e_1456x880.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:880,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:27076,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:&quot;image/webp&quot;,&quot;href&quot;:&quot;https://coderabbit.link/neo-jan&quot;,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/176627115?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccbf27ab-cea5-4105-81c0-4fe848b50c7e_1456x880.webp&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!tHi0!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccbf27ab-cea5-4105-81c0-4fe848b50c7e_1456x880.webp 424w, https://substackcdn.com/image/fetch/$s_!tHi0!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccbf27ab-cea5-4105-81c0-4fe848b50c7e_1456x880.webp 848w, https://substackcdn.com/image/fetch/$s_!tHi0!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccbf27ab-cea5-4105-81c0-4fe848b50c7e_1456x880.webp 1272w, https://substackcdn.com/image/fetch/$s_!tHi0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccbf27ab-cea5-4105-81c0-4fe848b50c7e_1456x880.webp 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>Bet you didn&#8217;t know&#8230;</p><p><strong><a href="https://coderabbit.link/neo-jan">CodeRabbit CLI</a> </strong>brings instant code reviews directly to your terminal, seamlessly integrating with Claude Code, Cursor CLI, and other AI coding agents. While they generate code, CodeRabbit ensures it&#8217;s production-ready - catching bugs, security issues, and AI hallucinations before they hit your codebase.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://coderabbit.link/neo-jan&quot;,&quot;text&quot;:&quot;Install CodeRabbit CLI&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://coderabbit.link/neo-jan"><span>Install CodeRabbit CLI</span></a></p><div><hr></div><h2><strong>Common Failure Modes and Guardrails</strong></h2><p>After enough cycles, I started noticing the same failures repeating.</p><p>Here&#8217;s a short checklist I keep in mind:</p><h4><strong>Context drift in long chats</strong></h4><p>Long conversations cause the model to forget earlier decisions.</p><p>The fix: keep conversations short and scoped. One chat for design, one for part A, one for part B. When a thread feels messy, ask the model to summarize where you are, then start a fresh chat with that summary at the top.</p><h4><strong>Wrong API or version</strong></h4><p>Models are trained on data up to a certain point.</p><p>They sometimes write code for an older version of a library or generate methods that don&#8217;t exist. For anything new or fast-moving, I assume the suggestion might be wrong and verify against official docs. I also ask the model to state its assumptions: &#8220;Which version are you assuming?&#8221;</p><p>If the answer doesn&#8217;t match my setup, I rewrite it myself.</p><h4><strong>Off-rails debugging loops</strong></h4><p>Once a model gets stuck on a bad idea, it tends to dig deeper. It proposes variations of the same broken fix, sometimes reintroducing bugs from earlier attempts.</p><h4><strong>Code quality drift</strong></h4><p>AI rarely produces well-structured code by default.</p><p>It&#8217;s good at &#8220;something that runs,&#8221; less good at &#8220;something I&#8217;ll want to maintain in three months.&#8221;</p><p>I fix this by baking quality into the request: ask for tests, ask for a summary of what changed and why, and nudge toward structure (&#8220;refactor this into smaller functions,&#8221; &#8220;follow the pattern in file X&#8221;).</p><h4><strong>Over-reliance</strong></h4><p>This one has nothing to do with the model and everything to do with me.</p><p>If I let AI handle every decision, my own instincts start to dull. I push back by keeping important decisions human-owned, occasionally doing small tasks without AI, and asking the model to teach as well as do: explain its reasoning, compare approaches, and talk through trade-offs.</p><p>The goal is not just &#8220;ship faster&#8221; but &#8220;ship faster and understand what I shipped.&#8221;</p><div><hr></div><h2><strong>Closing Thoughts</strong></h2><p>The workflow I use comes back to a simple loop:</p><pre><code><strong>Context &#8594; Plan &#8594; Code &#8594; Review &#8594; Test &#8594; Iterate</strong></code></pre><p>I give the model enough context to see the real problem.</p><ul><li><p>I ask it to plan before writing code.</p></li><li><p>I generate and edit in small steps.</p></li><li><p>I review the output, often with AI-assisted tools.</p></li><li><p>I ask for tests right away.</p></li></ul><p>And when something breaks, I debug, refine, and repeat until it works.</p><p>Tools and models will change. Pricing will change. New products will appear. What survives is your method: how you give context, how you break work into steps, when to use a model, and when to rely on yourself.</p><p>If this newsletter did its job, you now have a clearer picture of what coding with AI looks like in practice.</p><p>Some days it&#8217;s a sprint&#8230; Some days it&#8217;s a wrestling match. But it has changed how I work. I ship features I wouldn&#8217;t have attempted before, and I feel less stuck when learning a new stack or working through an unfamiliar codebase.</p><p>The goal is not just to ship faster, but to ship faster and understand what I shipped.</p><div><hr></div><p>Anyway, if you want to catch bugs, security flaws, and performance issues as<em> </em>you write code&#8230; try <a href="https://coderabbit.link/neo-jan">CodeRabbit</a>.</p><p>It brings real-time, AI code reviews straight into VS Code, Cursor, and Windsurf.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://coderabbit.link/neo-jan&quot;,&quot;text&quot;:&quot;Install CodeRabbit in VSCode for FREE&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://coderabbit.link/neo-jan"><span>Install CodeRabbit in VSCode for FREE</span></a></p><div><hr></div><p>I launched <strong>Design, Build, Scale</strong> (newsletter series exclusive to PAID subscribers).</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://newsletter.systemdesign.one/subscribe?yearly=true" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!jG0C!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63fca468-adce-4713-97a0-203c35bc1c60_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!jG0C!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63fca468-adce-4713-97a0-203c35bc1c60_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!jG0C!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63fca468-adce-4713-97a0-203c35bc1c60_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!jG0C!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63fca468-adce-4713-97a0-203c35bc1c60_1200x630.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!jG0C!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63fca468-adce-4713-97a0-203c35bc1c60_1200x630.png" width="1200" height="630" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/63fca468-adce-4713-97a0-203c35bc1c60_1200x630.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:630,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:null,&quot;href&quot;:&quot;https://newsletter.systemdesign.one/subscribe?yearly=true&quot;,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/179076610?img=https%3A%2F%2Fsubstackcdn.com%2Fimage%2Ffetch%2F%24s_%21jG0C%21%2Cf_auto%2Cq_auto%3Agood%2Cfl_progressive%3Asteep%2Fhttps%253A%252F%252Fsubstack-post-media.s3.amazonaws.com%252Fpublic%252Fimages%252F63fca468-adce-4713-97a0-203c35bc1c60_1200x630.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!jG0C!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63fca468-adce-4713-97a0-203c35bc1c60_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!jG0C!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63fca468-adce-4713-97a0-203c35bc1c60_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!jG0C!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63fca468-adce-4713-97a0-203c35bc1c60_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!jG0C!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63fca468-adce-4713-97a0-203c35bc1c60_1200x630.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 you upgrade, you&#8217;ll get:</p><ul><li><p><strong>High-level architecture of real-world systems.</strong></p></li><li><p>Deep dive into how popular real-world systems actually work.</p></li><li><p><strong>How real-world systems handle scale, reliability, and performance.</strong></p></li><li><p>10x the results you currently get with 1/10th of your time, energy, and effort.</p></li></ul><p><strong>&#128073; <a href="https://newsletter.systemdesign.one/subscribe?yearly=true">CLICK HERE TO ACCESS DESIGN, BUILD, SCALE!</a></strong></p><div><hr></div><h4>&#128680; Guest Authors Wanted: System Design &amp; AI Engineering</h4><ul><li><p>You&#8217;ll get exposure to 200,000+ tech audience.</p></li><li><p>Along with hands-on support throughout the review &amp; editing process.</p></li></ul><p>Reply to this email with links to your prior work and a brief note on topics you&#8217;d like to write about.</p><div><hr></div><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://www.linkedin.com/in/nk-systemdesign-one/" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!bEFk!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 424w, https://substackcdn.com/image/fetch/$s_!bEFk!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 848w, https://substackcdn.com/image/fetch/$s_!bEFk!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 1272w, https://substackcdn.com/image/fetch/$s_!bEFk!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!bEFk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png" width="152" height="152" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:320,&quot;width&quot;:320,&quot;resizeWidth&quot;:152,&quot;bytes&quot;:74009,&quot;alt&quot;:&quot;Author Neo Kim; System design case studies&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:&quot;https://www.linkedin.com/in/nk-systemdesign-one/&quot;,&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="Author Neo Kim; System design case studies" title="Author Neo Kim; System design case studies" srcset="https://substackcdn.com/image/fetch/$s_!bEFk!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 424w, https://substackcdn.com/image/fetch/$s_!bEFk!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 848w, https://substackcdn.com/image/fetch/$s_!bEFk!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 1272w, https://substackcdn.com/image/fetch/$s_!bEFk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f94ab8c-0d67-4775-992e-05e09ab710db_320x320.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption"><strong>&#128075; Find me on <a href="https://www.linkedin.com/in/nk-systemdesign-one/">LinkedIn</a> | <a href="https://x.com/intent/follow?screen_name=systemdesignone">Twitter</a> | <a href="https://www.threads.net/@systemdesignone">Threads</a> | <a href="https://www.instagram.com/systemdesignone/">Instagram</a></strong></figcaption></figure></div><div><hr></div><p><strong>Want to reach 200K+ tech professionals at scale? </strong>&#128240;</p><p>If your company wants to reach 200K+ tech professionals, <a href="https://newsletter.systemdesign.one/p/sponsorship">advertise with me</a>.</p><div><hr></div><p>Thank you for supporting this newsletter.</p><p>You are now 200,001+ readers strong, very close to 201k. Let&#8217;s try to get 201k readers by 5 February. Consider sharing this post with your friends and get rewards.</p><p>Y&#8217;all are the best.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!6oWl!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!6oWl!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png 424w, https://substackcdn.com/image/fetch/$s_!6oWl!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png 848w, https://substackcdn.com/image/fetch/$s_!6oWl!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png 1272w, https://substackcdn.com/image/fetch/$s_!6oWl!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!6oWl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png" width="590" height="368.75" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2e739087-a910-4643-be36-997b6dd5b4af_800x500.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:500,&quot;width&quot;:800,&quot;resizeWidth&quot;:590,&quot;bytes&quot;:87878,&quot;alt&quot;:&quot;system design newsletter&quot;,&quot;title&quot;:&quot;system design newsletter&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/163380418?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="system design newsletter" title="system design newsletter" srcset="https://substackcdn.com/image/fetch/$s_!6oWl!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png 424w, https://substackcdn.com/image/fetch/$s_!6oWl!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png 848w, https://substackcdn.com/image/fetch/$s_!6oWl!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.png 1272w, https://substackcdn.com/image/fetch/$s_!6oWl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e739087-a910-4643-be36-997b6dd5b4af_800x500.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 class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/p/ai-coding-workflow?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://newsletter.systemdesign.one/p/ai-coding-workflow?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</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>When AI generates plausible-sounding but incorrect information, like referencing a function or API that doesn&#8217;t exist. This is called hallucination.</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 way to propose code changes in Git-based workflows. You create a PR to ask others to review and merge your changes into the main codebase.</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>Unusual or extreme inputs that might break your code, like empty strings, very large numbers, or null values.</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>Restructuring existing code without changing its behavior, usually to improve readability or maintainability.</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 one-shot prompt is when you give an AI a single example of what you want, and it uses that one example to figure out how to respond to a new request.</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 file in a project&#8217;s root directory that explains what the project does and how to use it.</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>Files that store project rules and constraints for AI tools. Some tools, like Claude Code, automatically look for these files.</p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-8" href="#footnote-anchor-8" class="footnote-number" contenteditable="false" target="_self">8</a><div class="footnote-content"><p>A list of function calls that shows where an error occurred, helping you trace the path the program took before crashing.</p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-9" href="#footnote-anchor-9" class="footnote-number" contenteditable="false" target="_self">9</a><div class="footnote-content"><p>An agent system is an AI setup where the model can plan, make decisions, and take actions - often using tools or other AIs - to achieve a goal with minimal human input.</p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-10" href="#footnote-anchor-10" class="footnote-number" contenteditable="false" target="_self">10</a><div class="footnote-content"><p>A test that checks a single function or component in isolation.</p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-11" href="#footnote-anchor-11" class="footnote-number" contenteditable="false" target="_self">11</a><div class="footnote-content"><p>The expected, error-free flow through a feature when everything goes right.</p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-12" href="#footnote-anchor-12" class="footnote-number" contenteditable="false" target="_self">12</a><div class="footnote-content"><p>A test designed to catch bugs that reappear after being fixed. It should fail before the fix and pass after.</p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-13" href="#footnote-anchor-13" class="footnote-number" contenteditable="false" target="_self">13</a><div class="footnote-content"><p>Tools that analyze code for potential errors, style issues, and suspicious patterns without running the code</p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-14" href="#footnote-anchor-14" class="footnote-number" contenteditable="false" target="_self">14</a><div class="footnote-content"><p>A comparison showing what changed between two versions of code.</p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-15" href="#footnote-anchor-15" class="footnote-number" contenteditable="false" target="_self">15</a><div class="footnote-content"><p>Tests that check how multiple parts of a system work together, or simulate a complete user flow.</p><p></p></div></div>]]></content:encoded></item><item><title><![CDATA[What a Supermarket Checkout Line Can Teach You About Message Queues]]></title><description><![CDATA[#118: What Is a Message Queue?]]></description><link>https://newsletter.systemdesign.one/p/what-is-a-message-queue</link><guid isPermaLink="false">https://newsletter.systemdesign.one/p/what-is-a-message-queue</guid><dc:creator><![CDATA[Neo Kim]]></dc:creator><pubDate>Sat, 31 Jan 2026 12:31:02 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/238c5926-10c8-491a-94e8-f35427d4a7c0_1280x720.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/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">Get my system design playbook for FREE on newsletter signup:</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><ul><li><p><em><a href="https://newsletter.systemdesign.one/p/what-is-a-message-queue/?action=share">Share this post</a> &amp; I'll send you some rewards for the referrals.</em></p></li></ul><ul><li><p><em>Block diagrams created using <a href="https://app.eraser.io/auth/sign-up?ref=neo">Eraser</a>.</em></p></li></ul><div><hr></div><blockquote><p>Picture your last grocery trip: you filled your cart &amp; headed to checkout.</p></blockquote><p>Then the big moment arrived&#8212;you had to choose a line&#8230;Maybe you compared the number of items in other carts. Or you might have observed how quickly each cashier worked. Either way, you were making queue choices.</p><p>These are the same choices found in software 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_!KOGa!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fed97da-a178-4ce2-97b0-22c01d056285_1200x630.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!KOGa!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fed97da-a178-4ce2-97b0-22c01d056285_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!KOGa!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fed97da-a178-4ce2-97b0-22c01d056285_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!KOGa!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fed97da-a178-4ce2-97b0-22c01d056285_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!KOGa!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fed97da-a178-4ce2-97b0-22c01d056285_1200x630.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!KOGa!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fed97da-a178-4ce2-97b0-22c01d056285_1200x630.png" width="1200" height="630" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5fed97da-a178-4ce2-97b0-22c01d056285_1200x630.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:630,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:568164,&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;:&quot;https://newsletter.systemdesign.one/i/185832274?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fed97da-a178-4ce2-97b0-22c01d056285_1200x630.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_!KOGa!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fed97da-a178-4ce2-97b0-22c01d056285_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!KOGa!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fed97da-a178-4ce2-97b0-22c01d056285_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!KOGa!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fed97da-a178-4ce2-97b0-22c01d056285_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!KOGa!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5fed97da-a178-4ce2-97b0-22c01d056285_1200x630.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>In today&#8217;s newsletter, I&#8217;ll teach you how message queues work by comparing them to waiting in grocery store queues. The read time is roughly the time most people spend in line.</p><p>By the end, you&#8217;ll understand:</p><ul><li><p>How message queues work</p></li><li><p>How queue behavior affects performance</p></li><li><p>How to apply these ideas to build better systems</p></li></ul><p>Onward.</p><div><hr></div><h3><a href="https://getunblocked.com/code-review/?utm_source=systemdesign&amp;utm_medium=email&amp;utm_campaign=codereview&amp;utm_content=signal">AI code review that knows when to stay quiet (Partner)</a></h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://getunblocked.com/code-review/?utm_source=systemdesign&amp;utm_medium=email&amp;utm_campaign=codereview&amp;utm_content=signal" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!9XTE!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3444f574-4f73-44a9-8675-2fb93645ff24_2880x2160.png 424w, https://substackcdn.com/image/fetch/$s_!9XTE!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3444f574-4f73-44a9-8675-2fb93645ff24_2880x2160.png 848w, https://substackcdn.com/image/fetch/$s_!9XTE!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3444f574-4f73-44a9-8675-2fb93645ff24_2880x2160.png 1272w, https://substackcdn.com/image/fetch/$s_!9XTE!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3444f574-4f73-44a9-8675-2fb93645ff24_2880x2160.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!9XTE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3444f574-4f73-44a9-8675-2fb93645ff24_2880x2160.png" width="1456" height="1092" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3444f574-4f73-44a9-8675-2fb93645ff24_2880x2160.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1092,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2240257,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:&quot;https://getunblocked.com/code-review/?utm_source=systemdesign&amp;utm_medium=email&amp;utm_campaign=codereview&amp;utm_content=signal&quot;,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/185832274?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3444f574-4f73-44a9-8675-2fb93645ff24_2880x2160.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_!9XTE!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3444f574-4f73-44a9-8675-2fb93645ff24_2880x2160.png 424w, https://substackcdn.com/image/fetch/$s_!9XTE!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3444f574-4f73-44a9-8675-2fb93645ff24_2880x2160.png 848w, https://substackcdn.com/image/fetch/$s_!9XTE!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3444f574-4f73-44a9-8675-2fb93645ff24_2880x2160.png 1272w, https://substackcdn.com/image/fetch/$s_!9XTE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3444f574-4f73-44a9-8675-2fb93645ff24_2880x2160.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><a href="https://getunblocked.com/code-review/?utm_source=systemdesign&amp;utm_medium=email&amp;utm_campaign=codereview&amp;utm_content=signal">Unblocked</a></strong> is the AI code review that surfaces real issues and meaningful feedback instead of flooding your PRs with stylistic nitpicks and low-value comments.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://getunblocked.com/code-review/?utm_source=systemdesign&amp;utm_medium=email&amp;utm_campaign=codereview&amp;utm_content=signal&quot;,&quot;text&quot;:&quot;Experience Now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://getunblocked.com/code-review/?utm_source=systemdesign&amp;utm_medium=email&amp;utm_campaign=codereview&amp;utm_content=signal"><span>Experience Now</span></a></p><div><hr></div><h1>Checkout Line = Queue</h1><p>The checkout lines are simple:</p><p>Customers come with their carts and wait. Eventually, they form a line. The first person in the line gets served first. The last one needs to wait for everyone in front of them. This is called <a href="https://en.wikipedia.org/wiki/FIFO_(computing_and_electronics)">FIFO</a> (First-In-First-Out) ordering.</p><p>It&#8217;s simple, fair, and predictable.</p><p>Software message queues work in the same way.</p><p>Requests arrive &amp; wait in order. Think of an app like Instagram. When many users upload photos simultaneously, the app can&#8217;t process them all at once. So each photo upload becomes a message that will be processed later.</p><blockquote><p>There&#8217;s a hidden insight here:<strong> queues exist to absorb bursts in demand.</strong></p></blockquote><p>Use a queue when you can&#8217;t handle every request right now but still need to handle them later.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!QoJo!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F738feb70-4501-4ef8-bb36-6d2454784c99_1335x468.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!QoJo!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F738feb70-4501-4ef8-bb36-6d2454784c99_1335x468.png 424w, https://substackcdn.com/image/fetch/$s_!QoJo!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F738feb70-4501-4ef8-bb36-6d2454784c99_1335x468.png 848w, https://substackcdn.com/image/fetch/$s_!QoJo!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F738feb70-4501-4ef8-bb36-6d2454784c99_1335x468.png 1272w, https://substackcdn.com/image/fetch/$s_!QoJo!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F738feb70-4501-4ef8-bb36-6d2454784c99_1335x468.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!QoJo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F738feb70-4501-4ef8-bb36-6d2454784c99_1335x468.png" width="1335" height="468" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/738feb70-4501-4ef8-bb36-6d2454784c99_1335x468.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:468,&quot;width&quot;:1335,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:58808,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/185832274?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F738feb70-4501-4ef8-bb36-6d2454784c99_1335x468.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_!QoJo!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F738feb70-4501-4ef8-bb36-6d2454784c99_1335x468.png 424w, https://substackcdn.com/image/fetch/$s_!QoJo!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F738feb70-4501-4ef8-bb36-6d2454784c99_1335x468.png 848w, https://substackcdn.com/image/fetch/$s_!QoJo!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F738feb70-4501-4ef8-bb36-6d2454784c99_1335x468.png 1272w, https://substackcdn.com/image/fetch/$s_!QoJo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F738feb70-4501-4ef8-bb36-6d2454784c99_1335x468.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>Queue mechanics are simple&#8230;</p><ul><li><p>New messages get placed at the back of the queue - this is called <em><strong>enqueueing</strong></em>.</p></li><li><p>Processed ones leave from the front of the queue - this is called <em><strong>dequeuing</strong></em>.</p></li></ul><p>This pattern of filling and emptying the queue is what makes it fair and predictable. Just like the supermarket checkout line.</p><p><strong>Takeaway: </strong>Use queues to absorb sudden traffic spikes and keep track of what to process later.</p><div><hr></div><h1>Cashiers = Servers</h1><p>In a supermarket, cashiers are responsible for handling customers&#8230;</p><p>Each cashier scans items, processes payments, and completes transactions. They work alone but share the same goal: move customers through checkout.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!rKaq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec57c679-58f1-4eb4-aa36-8e5fc372aa0b_1200x630.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!rKaq!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec57c679-58f1-4eb4-aa36-8e5fc372aa0b_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!rKaq!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec57c679-58f1-4eb4-aa36-8e5fc372aa0b_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!rKaq!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec57c679-58f1-4eb4-aa36-8e5fc372aa0b_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!rKaq!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec57c679-58f1-4eb4-aa36-8e5fc372aa0b_1200x630.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!rKaq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec57c679-58f1-4eb4-aa36-8e5fc372aa0b_1200x630.png" width="1200" height="630" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ec57c679-58f1-4eb4-aa36-8e5fc372aa0b_1200x630.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:630,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:247779,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/185832274?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec57c679-58f1-4eb4-aa36-8e5fc372aa0b_1200x630.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_!rKaq!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec57c679-58f1-4eb4-aa36-8e5fc372aa0b_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!rKaq!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec57c679-58f1-4eb4-aa36-8e5fc372aa0b_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!rKaq!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec57c679-58f1-4eb4-aa36-8e5fc372aa0b_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!rKaq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec57c679-58f1-4eb4-aa36-8e5fc372aa0b_1200x630.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 software systems, servers work the same way&#8230;</p><p>They pull messages from queues and process them in turn. A queue growing faster than it&#8217;s getting processed is a signal to scale servers.</p><p>You can scale in two ways:</p><ul><li><p>Horizontal scaling</p><ul><li><p>This means <strong>adding more servers</strong>, so the work gets spread across workers</p></li><li><p>It&#8217;s like adding a new cashier in a supermarket; customers notice a new line opened and spread out</p></li></ul></li><li><p>Vertical scaling</p><ul><li><p>This means <strong>making the existing servers more powerful</strong><a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a></p></li><li><p>It&#8217;s like training cashiers in a supermarket; trained cashiers scan the items or process payments faster and serve more customers faster</p></li></ul></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!NZNP!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac92e777-f0d5-49c4-a19a-7f1eebaf64a2_1303x989.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!NZNP!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac92e777-f0d5-49c4-a19a-7f1eebaf64a2_1303x989.png 424w, https://substackcdn.com/image/fetch/$s_!NZNP!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac92e777-f0d5-49c4-a19a-7f1eebaf64a2_1303x989.png 848w, https://substackcdn.com/image/fetch/$s_!NZNP!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac92e777-f0d5-49c4-a19a-7f1eebaf64a2_1303x989.png 1272w, https://substackcdn.com/image/fetch/$s_!NZNP!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac92e777-f0d5-49c4-a19a-7f1eebaf64a2_1303x989.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!NZNP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac92e777-f0d5-49c4-a19a-7f1eebaf64a2_1303x989.png" width="520" height="394.68917881811205" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ac92e777-f0d5-49c4-a19a-7f1eebaf64a2_1303x989.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:989,&quot;width&quot;:1303,&quot;resizeWidth&quot;:520,&quot;bytes&quot;:119859,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/185832274?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac92e777-f0d5-49c4-a19a-7f1eebaf64a2_1303x989.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_!NZNP!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac92e777-f0d5-49c4-a19a-7f1eebaf64a2_1303x989.png 424w, https://substackcdn.com/image/fetch/$s_!NZNP!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac92e777-f0d5-49c4-a19a-7f1eebaf64a2_1303x989.png 848w, https://substackcdn.com/image/fetch/$s_!NZNP!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac92e777-f0d5-49c4-a19a-7f1eebaf64a2_1303x989.png 1272w, https://substackcdn.com/image/fetch/$s_!NZNP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac92e777-f0d5-49c4-a19a-7f1eebaf64a2_1303x989.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 there&#8217;s a catch: <em>servers must confirm they finished processing.</em></p><p>At the supermarket, this is like a cashier calling &#8220;Next!&#8221; when ready. This is called an acknowledgment<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-2" href="#footnote-2" target="_self">2</a> in software systems. Without it, the system can&#8217;t tell if a message succeeded or failed, so it has to be redelivered.</p><p><strong>Takeaway: </strong>Match your processing power to demand by scaling out or scaling up servers.</p><p>Let&#8217;s keep going!</p><div><hr></div><h1>Line Length, Throughput, and Latency</h1><p>Longer lines mean longer waits&#8230;</p><p>Too many customers during rush hour makes waits much longer,,, and customers get frustrated. They might leave their carts or choose a different store next time.</p><p>Long queues also hurt performance in software systems:</p><p>Too many requests slow things down. Think of Twitter during big events when millions of tweets flood in. Servers can&#8217;t keep up, so users experience slow responses or errors. This is very bad for the business.</p><blockquote><p><em>So how do you make sure you see issues before they happen?</em></p><p>&#8220;One approach is to use throughput and latency metrics.&#8221;</p></blockquote><p>Throughput<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-3" href="#footnote-3" target="_self">3</a> means how many customers get handled per hour. Latency<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-4" href="#footnote-4" target="_self">4</a> means how long it takes to process one customer.</p><p><strong>A good system has high throughput &amp; low latency.</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_!S-QP!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F667b21a5-47af-4da1-803c-d7bdc50c7e5c_991x583.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!S-QP!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F667b21a5-47af-4da1-803c-d7bdc50c7e5c_991x583.png 424w, https://substackcdn.com/image/fetch/$s_!S-QP!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F667b21a5-47af-4da1-803c-d7bdc50c7e5c_991x583.png 848w, https://substackcdn.com/image/fetch/$s_!S-QP!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F667b21a5-47af-4da1-803c-d7bdc50c7e5c_991x583.png 1272w, https://substackcdn.com/image/fetch/$s_!S-QP!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F667b21a5-47af-4da1-803c-d7bdc50c7e5c_991x583.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!S-QP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F667b21a5-47af-4da1-803c-d7bdc50c7e5c_991x583.png" width="648" height="381.2149344096872" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/667b21a5-47af-4da1-803c-d7bdc50c7e5c_991x583.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:583,&quot;width&quot;:991,&quot;resizeWidth&quot;:648,&quot;bytes&quot;:104664,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/185832274?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F667b21a5-47af-4da1-803c-d7bdc50c7e5c_991x583.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_!S-QP!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F667b21a5-47af-4da1-803c-d7bdc50c7e5c_991x583.png 424w, https://substackcdn.com/image/fetch/$s_!S-QP!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F667b21a5-47af-4da1-803c-d7bdc50c7e5c_991x583.png 848w, https://substackcdn.com/image/fetch/$s_!S-QP!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F667b21a5-47af-4da1-803c-d7bdc50c7e5c_991x583.png 1272w, https://substackcdn.com/image/fetch/$s_!S-QP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F667b21a5-47af-4da1-803c-d7bdc50c7e5c_991x583.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>Store managers watch checkout lines to decide whether to open more lines.</p><p>Likewise, the engineers monitor queue length, throughput, and latency to make scaling decisions. It&#8217;s required to understand acceptable limits and scale before the system crashes.</p><p><strong>Low throughput</strong></p><ul><li><p><em>What it means</em>: system can&#8217;t handle enough requests at once</p></li><li><p><em>Why it happens:</em> there aren&#8217;t enough servers, or the work isn&#8217;t shared evenly</p></li><li><p><em>How to fix it:</em> add more servers or spread the work</p></li></ul><p><strong>High latency</strong></p><ul><li><p><em>What it means:</em> requests take too long to finish</p></li><li><p><em>Why it happens:</em> when code is slow, databases are lagging, or the network is busy</p></li><li><p><em>How to fix it: </em>make the code faster, use caching, or improve the slow parts</p></li></ul><p><strong>Takeaway: </strong>If queues keep growing, it means demand exceeds capacity. Use throughput and latency metrics to identify what to improve.</p><p>Ready for the next technique?</p><div><hr></div><h1>Express Lines = Priority Queues</h1><p>Supermarket express lines exist to speed up checkout for customers with fewer items.</p><p>They provide a faster option for quick trips and help the store increase throughput.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!u8rU!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52495815-f401-41bf-b39f-daa0384ed5f8_1200x630.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!u8rU!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52495815-f401-41bf-b39f-daa0384ed5f8_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!u8rU!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52495815-f401-41bf-b39f-daa0384ed5f8_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!u8rU!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52495815-f401-41bf-b39f-daa0384ed5f8_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!u8rU!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52495815-f401-41bf-b39f-daa0384ed5f8_1200x630.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!u8rU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52495815-f401-41bf-b39f-daa0384ed5f8_1200x630.png" width="1200" height="630" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/52495815-f401-41bf-b39f-daa0384ed5f8_1200x630.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:630,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:233700,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/185832274?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52495815-f401-41bf-b39f-daa0384ed5f8_1200x630.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_!u8rU!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52495815-f401-41bf-b39f-daa0384ed5f8_1200x630.png 424w, https://substackcdn.com/image/fetch/$s_!u8rU!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52495815-f401-41bf-b39f-daa0384ed5f8_1200x630.png 848w, https://substackcdn.com/image/fetch/$s_!u8rU!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52495815-f401-41bf-b39f-daa0384ed5f8_1200x630.png 1272w, https://substackcdn.com/image/fetch/$s_!u8rU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52495815-f401-41bf-b39f-daa0384ed5f8_1200x630.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 is similar to software using <a href="https://learn.microsoft.com/en-us/azure/architecture/patterns/priority-queue">priority queues,</a> where important messages are moved to the front instead of waiting in line. A priority queue assigns each message a level of importance. The system always processes the highest-priority task first, even if others arrived earlier.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!94eh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fe3edfa-f41d-41c0-a8f0-3320e3c3470f_1333x466.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!94eh!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fe3edfa-f41d-41c0-a8f0-3320e3c3470f_1333x466.png 424w, https://substackcdn.com/image/fetch/$s_!94eh!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fe3edfa-f41d-41c0-a8f0-3320e3c3470f_1333x466.png 848w, https://substackcdn.com/image/fetch/$s_!94eh!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fe3edfa-f41d-41c0-a8f0-3320e3c3470f_1333x466.png 1272w, https://substackcdn.com/image/fetch/$s_!94eh!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fe3edfa-f41d-41c0-a8f0-3320e3c3470f_1333x466.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!94eh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fe3edfa-f41d-41c0-a8f0-3320e3c3470f_1333x466.png" width="1333" height="466" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0fe3edfa-f41d-41c0-a8f0-3320e3c3470f_1333x466.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:466,&quot;width&quot;:1333,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:65668,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://newsletter.systemdesign.one/i/185832274?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fe3edfa-f41d-41c0-a8f0-3320e3c3470f_1333x466.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_!94eh!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fe3edfa-f41d-41c0-a8f0-3320e3c3470f_1333x466.png 424w, https://substackcdn.com/image/fetch/$s_!94eh!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fe3edfa-f41d-41c0-a8f0-3320e3c3470f_1333x466.png 848w, https://substackcdn.com/image/fetch/$s_!94eh!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fe3edfa-f41d-41c0-a8f0-3320e3c3470f_1333x466.png 1272w, https://substackcdn.com/image/fetch/$s_!94eh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fe3edfa-f41d-41c0-a8f0-3320e3c3470f_1333x466.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>Priority queues help systems improve performance, but they have downsides:</p><ul><li><p>Lower-priority work can get stuck if urgent jobs never finish</p></li><li><p>Priority queues are hard to debug since there&#8217;s no FIFO ordering</p></li><li><p>Managing priorities adds complexity in implementation/maintenance</p></li></ul><p>It&#8217;s a classic <strong>tradeoff between simplicity &amp; responsiveness</strong>. It&#8217;s best to use priority queues only when speed really matters, and to keep most workflows predictable and fair.</p><p><strong>Takeaway: </strong>Priority queues ensure time-sensitive messages aren&#8217;t delayed by less critical work.</p><p>Ready for the best part?</p><div><hr></div><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://newsletter.systemdesign.one/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">Golden members get all posts like these!...</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>
          <a href="https://newsletter.systemdesign.one/p/what-is-a-message-queue">
              Read more
          </a>
      </p>
   ]]></content:encoded></item></channel></rss>