<?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[AlgoMaster Newsletter]]></title><description><![CDATA[Master Coding and System Design Interviews. Level up your Software Engineering career. Subscribe and get a FREE System Design Interview Handbook in your inbox.]]></description><link>https://blog.algomaster.io</link><image><url>https://substackcdn.com/image/fetch/$s_!Byzl!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F662bfc37-956c-4898-b9ee-62676ecfafa1_256x256.png</url><title>AlgoMaster Newsletter</title><link>https://blog.algomaster.io</link></image><generator>Substack</generator><lastBuildDate>Mon, 13 Jul 2026 03:00:25 GMT</lastBuildDate><atom:link href="https://blog.algomaster.io/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[Ashish Pratap Singh]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[algomaster@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[algomaster@substack.com]]></itunes:email><itunes:name><![CDATA[Ashish Pratap Singh]]></itunes:name></itunes:owner><itunes:author><![CDATA[Ashish Pratap Singh]]></itunes:author><googleplay:owner><![CDATA[algomaster@substack.com]]></googleplay:owner><googleplay:email><![CDATA[algomaster@substack.com]]></googleplay:email><googleplay:author><![CDATA[Ashish Pratap Singh]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[Kafka vs RabbitMQ vs SQS]]></title><description><![CDATA[Most backend systems eventually need one service to hand off work to another asynchronously.]]></description><link>https://blog.algomaster.io/p/kafka-vs-rabbitmq-vs-sqs</link><guid isPermaLink="false">https://blog.algomaster.io/p/kafka-vs-rabbitmq-vs-sqs</guid><dc:creator><![CDATA[Ashish Pratap Singh]]></dc:creator><pubDate>Thu, 02 Jul 2026 03:31:11 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!rFO8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e20b933-c165-48b6-bbbb-66e1d7397396_1624x1264.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Most backend systems eventually need one service to hand off work to another asynchronously. For example: A payment service may need to send receipts, or an order service may need to trigger fulfillment.</p><p>That is where <strong>messaging systems</strong> come in. They sit between producers and consumers, buffer work, decouple services, and let each side scale independently.</p><p>But choosing a messaging system is not always obvious. <strong>Kafka</strong>, <strong>RabbitMQ</strong>, and <strong>Amazon SQS</strong> are populars solutions, but they are built for different kinds of workloads.</p><p>In this article, we&#8217;ll compare Kafka, RabbitMQ, and SQS across the key dimensions that matter when designing asynchronous systems, and explain when to choose each one.</p><div><hr></div><h1><a href="https://www.apodex.ai">&#128227; Research Agents That Find, Verify, and Explain (Sponsor)</a></h1><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!1s5_!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa2fc5bfe-8216-47a0-8dad-3630f6c048ae_1280x640.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!1s5_!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa2fc5bfe-8216-47a0-8dad-3630f6c048ae_1280x640.png 424w, https://substackcdn.com/image/fetch/$s_!1s5_!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa2fc5bfe-8216-47a0-8dad-3630f6c048ae_1280x640.png 848w, https://substackcdn.com/image/fetch/$s_!1s5_!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa2fc5bfe-8216-47a0-8dad-3630f6c048ae_1280x640.png 1272w, https://substackcdn.com/image/fetch/$s_!1s5_!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa2fc5bfe-8216-47a0-8dad-3630f6c048ae_1280x640.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!1s5_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa2fc5bfe-8216-47a0-8dad-3630f6c048ae_1280x640.png" width="1280" height="640" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a2fc5bfe-8216-47a0-8dad-3630f6c048ae_1280x640.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:640,&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;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!1s5_!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa2fc5bfe-8216-47a0-8dad-3630f6c048ae_1280x640.png 424w, https://substackcdn.com/image/fetch/$s_!1s5_!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa2fc5bfe-8216-47a0-8dad-3630f6c048ae_1280x640.png 848w, https://substackcdn.com/image/fetch/$s_!1s5_!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa2fc5bfe-8216-47a0-8dad-3630f6c048ae_1280x640.png 1272w, https://substackcdn.com/image/fetch/$s_!1s5_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa2fc5bfe-8216-47a0-8dad-3630f6c048ae_1280x640.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><span>Deep research agents should do more than find answers. They should show why those answers can be trusted.</span></p><p><strong><a href="https://www.apodex.ai"><span>Apodex</span></a></strong><span> is built for long-horizon research tasks where reliability matters. It plans the search, gathers evidence, uses tools, verifies findings, and synthesizes grounded responses.</span></p><p>Its verification-first design separates the solver from the verifier, using different context and tools to reduce unsupported conclusions.</p><p>Apodex recently launched <strong><a href="https://huggingface.co/collections/apodex/apodex-1">Apodex 1.0</a></strong>, a deep research agent family built around independent verification.</p><p><span>This release includes:</span></p><ul><li><p><span>Apodex-1.0-H, our flagship deep research model</span></p></li><li><p><span>AgentOS, a runtime for building and evaluating agent workflows</span></p></li><li><p><span>Apodex-1.0 and Apodex-mini</span></p></li><li><p><span>Open-weight Smol models at 0.8B, 2B, and 4B</span></p></li></ul><p>Apodex is now available for researchers, scientists, developers, and builders worldwide.</p><ul><li><p><span>Github:</span><a href="https://github.com/ApodexAI/AgentHarness"><span> https://github.com/ApodexAI/AgentHarness</span></a></p></li><li><p><span>Hugging Face: </span><a href="https://huggingface.co/collections/apodex/apodex-1"><span>https://huggingface.co/collections/apodex/apodex-1</span></a></p></li><li><p><span>Try Apodex (early access):</span> <a href="https://www.apodex.ai">https://www.apodex.ai</a></p></li><li><p><span>API Platform:</span> <a href="https://platform.apodex.ai/">https://platform.apodex.ai/</a></p></li><li><p><span>Join Discord:</span><a href="https://discord.gg/TDJA59TCng"><span> https://discord.gg/TDJA59TCng</span></a></p></li></ul><div><hr></div><h1>1. Three Different Models</h1><p>Before comparing them, it helps to understand what each system fundamentally is. Most confusion comes from treating Kafka, RabbitMQ, and SQS as interchangeable queues. They are not.</p><p>Here&#8217;s the core model behind each one.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!rFO8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e20b933-c165-48b6-bbbb-66e1d7397396_1624x1264.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!rFO8!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e20b933-c165-48b6-bbbb-66e1d7397396_1624x1264.png 424w, https://substackcdn.com/image/fetch/$s_!rFO8!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e20b933-c165-48b6-bbbb-66e1d7397396_1624x1264.png 848w, https://substackcdn.com/image/fetch/$s_!rFO8!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e20b933-c165-48b6-bbbb-66e1d7397396_1624x1264.png 1272w, https://substackcdn.com/image/fetch/$s_!rFO8!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e20b933-c165-48b6-bbbb-66e1d7397396_1624x1264.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!rFO8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e20b933-c165-48b6-bbbb-66e1d7397396_1624x1264.png" width="1456" height="1133" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4e20b933-c165-48b6-bbbb-66e1d7397396_1624x1264.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1133,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:137066,&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://blog.algomaster.io/i/173209695?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e20b933-c165-48b6-bbbb-66e1d7397396_1624x1264.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_!rFO8!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e20b933-c165-48b6-bbbb-66e1d7397396_1624x1264.png 424w, https://substackcdn.com/image/fetch/$s_!rFO8!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e20b933-c165-48b6-bbbb-66e1d7397396_1624x1264.png 848w, https://substackcdn.com/image/fetch/$s_!rFO8!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e20b933-c165-48b6-bbbb-66e1d7397396_1624x1264.png 1272w, https://substackcdn.com/image/fetch/$s_!rFO8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e20b933-c165-48b6-bbbb-66e1d7397396_1624x1264.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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>Kafka stores messages in an append-only log. Consumers track their position with offsets, and messages remain available until the retention period expires. This allows multiple consumers to read the same data independently and replay old messages when needed.</p><p>RabbitMQ works more like a traditional broker. Producers send messages to exchanges, exchanges route them to queues, and consumers receive messages from those queues. Once a consumer acknowledges a message, RabbitMQ removes it.</p><p>SQS is simpler. You send messages to a queue, consumers poll the queue, and AWS manages the infrastructure behind it.</p><p>The table below summarizes how they differ across different dimensions:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!2zH8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11d0c1a0-fe94-4ff5-8cb3-94b3c50e1e8b_965x310.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!2zH8!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11d0c1a0-fe94-4ff5-8cb3-94b3c50e1e8b_965x310.png 424w, https://substackcdn.com/image/fetch/$s_!2zH8!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11d0c1a0-fe94-4ff5-8cb3-94b3c50e1e8b_965x310.png 848w, https://substackcdn.com/image/fetch/$s_!2zH8!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11d0c1a0-fe94-4ff5-8cb3-94b3c50e1e8b_965x310.png 1272w, https://substackcdn.com/image/fetch/$s_!2zH8!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11d0c1a0-fe94-4ff5-8cb3-94b3c50e1e8b_965x310.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!2zH8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11d0c1a0-fe94-4ff5-8cb3-94b3c50e1e8b_965x310.png" width="724" height="232.58031088082902" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/11d0c1a0-fe94-4ff5-8cb3-94b3c50e1e8b_965x310.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:310,&quot;width&quot;:965,&quot;resizeWidth&quot;:724,&quot;bytes&quot;:69373,&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://blog.algomaster.io/i/173209695?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11d0c1a0-fe94-4ff5-8cb3-94b3c50e1e8b_965x310.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_!2zH8!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11d0c1a0-fe94-4ff5-8cb3-94b3c50e1e8b_965x310.png 424w, https://substackcdn.com/image/fetch/$s_!2zH8!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11d0c1a0-fe94-4ff5-8cb3-94b3c50e1e8b_965x310.png 848w, https://substackcdn.com/image/fetch/$s_!2zH8!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11d0c1a0-fe94-4ff5-8cb3-94b3c50e1e8b_965x310.png 1272w, https://substackcdn.com/image/fetch/$s_!2zH8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11d0c1a0-fe94-4ff5-8cb3-94b3c50e1e8b_965x310.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.algomaster.io/p/kafka-vs-rabbitmq-vs-sqs?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://blog.algomaster.io/p/kafka-vs-rabbitmq-vs-sqs?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><div><hr></div><h1>2. Apache Kafka: The Distributed Log</h1><p>Kafka was originally built at LinkedIn to move large volumes of activity data, such as page views, clicks, and searches, across many internal systems. Traditional message brokers were not a great fit for that scale, so Kafka took a different approach: it modeled messaging as a distributed append-only log.</p><p>The core idea is simple. Messages are appended to ordered, immutable logs. Each topic is split into partitions, and those partitions are spread across brokers for parallelism and fault tolerance.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!zIdH!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f0168e3-e745-4b50-9964-b70839d50346_1934x1158.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!zIdH!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f0168e3-e745-4b50-9964-b70839d50346_1934x1158.png 424w, https://substackcdn.com/image/fetch/$s_!zIdH!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f0168e3-e745-4b50-9964-b70839d50346_1934x1158.png 848w, https://substackcdn.com/image/fetch/$s_!zIdH!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f0168e3-e745-4b50-9964-b70839d50346_1934x1158.png 1272w, https://substackcdn.com/image/fetch/$s_!zIdH!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f0168e3-e745-4b50-9964-b70839d50346_1934x1158.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!zIdH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f0168e3-e745-4b50-9964-b70839d50346_1934x1158.png" width="1456" height="872" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0f0168e3-e745-4b50-9964-b70839d50346_1934x1158.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:872,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:131129,&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://blog.algomaster.io/i/173209695?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f0168e3-e745-4b50-9964-b70839d50346_1934x1158.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_!zIdH!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f0168e3-e745-4b50-9964-b70839d50346_1934x1158.png 424w, https://substackcdn.com/image/fetch/$s_!zIdH!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f0168e3-e745-4b50-9964-b70839d50346_1934x1158.png 848w, https://substackcdn.com/image/fetch/$s_!zIdH!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f0168e3-e745-4b50-9964-b70839d50346_1934x1158.png 1272w, https://substackcdn.com/image/fetch/$s_!zIdH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f0168e3-e745-4b50-9964-b70839d50346_1934x1158.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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>Producers write messages to a topic. A partition key decides which partition a message lands in, so related messages can stay ordered within the same partition.</p><p>Consumers read messages by offset. Kafka does not delete a message when it is read. Instead, messages stay in the log until the retention period expires. This is what makes replay possible.</p><p>Consumer groups are the main scaling mechanism. Within one consumer group, each partition is assigned to only one consumer. You can increase parallelism by adding more partitions and consumers.</p><p>If another consumer group reads the same topic, it gets its own independent view of the stream. That means the same event feed can power analytics, billing, search indexing, fraud detection, and other systems at the same time.</p><p>Kafka is fast because it is built around sequential I/O. Writes are appended to disk, reads are served efficiently from the operating system page cache, and messages are batched and compressed. This lets Kafka handle very high throughput across a cluster.</p><h4>Strengths</h4><ul><li><p>Very high throughput on commodity hardware</p></li><li><p>Messages are retained, so consumers can replay history</p></li><li><p>Multiple independent consumer groups read the same data</p></li><li><p>A mature stream-processing ecosystem (Kafka Streams, ksqlDB, Connect)</p></li></ul><h4>Weaknesses</h4><ul><li><p>Operationally heavy to run yourself (brokers, partitions, rebalancing, and historically ZooKeeper, now KRaft)</p></li><li><p>No per-message routing logic; consumers filter on their own</p></li><li><p>No native priority queues or per-message delay</p></li><li><p>Overkill for simple task queues</p></li></ul><p>Choose <strong>Kafka</strong> when you need replay, event sourcing, very high throughput, real-time stream processing, or multiple teams consuming the same event feed independently. Kafka is best when events become a long-lived stream of data, not just temporary work items.</p><div><hr></div><h1>3. RabbitMQ: The Flexible Broker</h1><p>RabbitMQ is a traditional message broker built around routing and reliable delivery. While Kafka is optimized for storing and replaying large event streams, RabbitMQ is optimized for getting each message to the right consumer quickly.</p><p>The key idea is that producers do not usually publish directly to queues. They publish to an <strong>exchange</strong>. The exchange then routes each message to one or more queues using rules called <strong>bindings</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_!pjXg!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F555d94f9-6198-4860-b839-785ea93f7f83_2186x1036.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!pjXg!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F555d94f9-6198-4860-b839-785ea93f7f83_2186x1036.png 424w, https://substackcdn.com/image/fetch/$s_!pjXg!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F555d94f9-6198-4860-b839-785ea93f7f83_2186x1036.png 848w, https://substackcdn.com/image/fetch/$s_!pjXg!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F555d94f9-6198-4860-b839-785ea93f7f83_2186x1036.png 1272w, https://substackcdn.com/image/fetch/$s_!pjXg!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F555d94f9-6198-4860-b839-785ea93f7f83_2186x1036.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!pjXg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F555d94f9-6198-4860-b839-785ea93f7f83_2186x1036.png" width="1456" height="690" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/555d94f9-6198-4860-b839-785ea93f7f83_2186x1036.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:690,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:142588,&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://blog.algomaster.io/i/173209695?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F555d94f9-6198-4860-b839-785ea93f7f83_2186x1036.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_!pjXg!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F555d94f9-6198-4860-b839-785ea93f7f83_2186x1036.png 424w, https://substackcdn.com/image/fetch/$s_!pjXg!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F555d94f9-6198-4860-b839-785ea93f7f83_2186x1036.png 848w, https://substackcdn.com/image/fetch/$s_!pjXg!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F555d94f9-6198-4860-b839-785ea93f7f83_2186x1036.png 1272w, https://substackcdn.com/image/fetch/$s_!pjXg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F555d94f9-6198-4860-b839-785ea93f7f83_2186x1036.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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>RabbitMQ supports several exchange types:</p><ul><li><p><strong>Direct: </strong>Routes by exact routing key match</p></li><li><p><strong>Topic: </strong>Routes by pattern, such as <code>order.*</code></p></li><li><p><strong>Fanout: </strong>Broadcasts to all bound queues</p></li><li><p><strong>Headers: </strong>Routes based on message headers</p></li></ul><p>This routing model is RabbitMQ&#8217;s biggest strength. It lets you express routing rules in the broker instead of hardcoding them in every producer or consumer.</p><p>RabbitMQ delivery is push-based. The broker sends messages to consumers, and each consumer acknowledges a message after processing it. Once RabbitMQ receives the acknowledgment, it removes the message from the queue. If the consumer crashes before acknowledging, the message can be requeued and delivered again.</p><p>This push-and-ack model makes RabbitMQ a good fit for low-latency task processing, background jobs, and workflows where each message needs to reach a specific worker.</p><h4>Strengths</h4><ul><li><p>Flexible routing through exchange types</p></li><li><p>Low per-message latency from push-based delivery</p></li><li><p>Native support for priority queues, per-message TTL, and delayed delivery (via plugin)</p></li><li><p>Multiple protocols (AMQP, MQTT, STOMP) and a built-in management UI</p></li></ul><h4>Weaknesses</h4><ul><li><p>Lower throughput than Kafka, typically tens of thousands of messages per second per node</p></li><li><p>No replay; once a message is acked, it&#8217;s gone</p></li><li><p>Throughput drops when queues grow very deep, since it&#8217;s tuned for queues that stay near empty</p></li><li><p>Clustering and mirrored/quorum queues add operational complexity</p></li></ul><p>Choose <strong>RabbitMQ</strong> when you need flexible routing, priority queues, request-reply patterns, per-message delays, or low latency for individual messages. It is a strong fit when the main problem is getting each message to the right worker quickly and reliably.</p><p>Kafka and RabbitMQ both require you to think about brokers, capacity, scaling, and operations. SQS takes a different approach by making the queue fully managed.</p><div><hr></div><h1>4. Amazon SQS: The Managed Queue</h1><p>Amazon SQS is the simplest of the three. It gives up Kafka&#8217;s replay model and RabbitMQ&#8217;s rich routing in exchange for one major benefit: almost no operational work.</p><p>There are no brokers to provision, no clusters to size, and no replication settings to manage. You create a queue, send messages to it, and AWS handles the infrastructure behind it.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!zEgT!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F363941f8-66f7-4038-9075-72744e6b75bf_2074x1038.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!zEgT!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F363941f8-66f7-4038-9075-72744e6b75bf_2074x1038.png 424w, https://substackcdn.com/image/fetch/$s_!zEgT!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F363941f8-66f7-4038-9075-72744e6b75bf_2074x1038.png 848w, https://substackcdn.com/image/fetch/$s_!zEgT!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F363941f8-66f7-4038-9075-72744e6b75bf_2074x1038.png 1272w, https://substackcdn.com/image/fetch/$s_!zEgT!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F363941f8-66f7-4038-9075-72744e6b75bf_2074x1038.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!zEgT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F363941f8-66f7-4038-9075-72744e6b75bf_2074x1038.png" width="1456" height="729" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/363941f8-66f7-4038-9075-72744e6b75bf_2074x1038.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:729,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:124603,&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://blog.algomaster.io/i/173209695?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F363941f8-66f7-4038-9075-72744e6b75bf_2074x1038.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_!zEgT!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F363941f8-66f7-4038-9075-72744e6b75bf_2074x1038.png 424w, https://substackcdn.com/image/fetch/$s_!zEgT!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F363941f8-66f7-4038-9075-72744e6b75bf_2074x1038.png 848w, https://substackcdn.com/image/fetch/$s_!zEgT!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F363941f8-66f7-4038-9075-72744e6b75bf_2074x1038.png 1272w, https://substackcdn.com/image/fetch/$s_!zEgT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F363941f8-66f7-4038-9075-72744e6b75bf_2074x1038.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 flow is straightforward. Producers send messages to a queue. Consumers poll the queue for messages. AWS manages durability, scaling, and availability.</p><p>The important concept is the <strong>visibility timeout</strong>. When a consumer receives a message, SQS does not delete it immediately. Instead, it hides the message from other consumers for a configured period. The consumer processes the message and then explicitly deletes it.</p><p>If the consumer crashes before deleting the message, the visibility timeout expires and the message becomes available again. Another consumer can then pick it up. After a configured number of failed attempts, the message can be moved to a dead-letter queue for later inspection.</p><p>SQS has two main queue types:</p><ul><li><p><strong>Standard queue: </strong>Very high throughput, at-least-once delivery, best-effort ordering</p></li><li><p><strong>FIFO queue: </strong>Preserves order within a message group and supports deduplication, but with lower throughput</p></li></ul><h4>Strengths</h4><ul><li><p>No infrastructure to manage (AWS manages it for you)</p></li><li><p>Scales automatically and absorbs traffic spikes</p></li><li><p>Deep AWS integration (Works well with Lambda, SNS, S3, CloudWatch, and other services)</p></li><li><p>Pay-per-request pricing with no idle cost</p></li></ul><h4>Weaknesses</h4><ul><li><p>AWS-only; no portability to other clouds or on-premise</p></li><li><p>No replay and 14-day maximum retention</p></li><li><p>No built-in routing (you pair it with SNS for fan-out)</p></li><li><p>256 KB message size limit, and FIFO throughput is capped</p></li></ul><p>Choose <strong>SQS</strong> when you are building on AWS and want a reliable queue with almost no operational overhead. It is ideal for serverless workflows, bursty background jobs, and simple asynchronous processing where you do not need replay or advanced routing.</p><div><hr></div><h1>5. Using Them Together</h1><p>Kafka, RabbitMQ, and SQS are not mutually exclusive. Mature systems often use more than one because they solve different problems.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!b1CM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F31e37258-755f-441a-8ca8-2a6beff373f2_2446x694.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!b1CM!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F31e37258-755f-441a-8ca8-2a6beff373f2_2446x694.png 424w, https://substackcdn.com/image/fetch/$s_!b1CM!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F31e37258-755f-441a-8ca8-2a6beff373f2_2446x694.png 848w, https://substackcdn.com/image/fetch/$s_!b1CM!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F31e37258-755f-441a-8ca8-2a6beff373f2_2446x694.png 1272w, https://substackcdn.com/image/fetch/$s_!b1CM!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F31e37258-755f-441a-8ca8-2a6beff373f2_2446x694.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!b1CM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F31e37258-755f-441a-8ca8-2a6beff373f2_2446x694.png" width="1456" height="413" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/31e37258-755f-441a-8ca8-2a6beff373f2_2446x694.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:413,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:118735,&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://blog.algomaster.io/i/173209695?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F31e37258-755f-441a-8ca8-2a6beff373f2_2446x694.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_!b1CM!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F31e37258-755f-441a-8ca8-2a6beff373f2_2446x694.png 424w, https://substackcdn.com/image/fetch/$s_!b1CM!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F31e37258-755f-441a-8ca8-2a6beff373f2_2446x694.png 848w, https://substackcdn.com/image/fetch/$s_!b1CM!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F31e37258-755f-441a-8ca8-2a6beff373f2_2446x694.png 1272w, https://substackcdn.com/image/fetch/$s_!b1CM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F31e37258-755f-441a-8ca8-2a6beff373f2_2446x694.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 common pattern is to use Kafka as the central event backbone. Services publish high-volume events to Kafka, and downstream systems consume those events for analytics, stream processing, search indexing, billing, or auditing.</p><p>From there, a bridge service can forward selected events to a task queue. Use RabbitMQ when the work needs flexible routing, priority handling, or dedicated worker pools. Use SQS when the work is AWS-native and you want services like Lambda, ECS, or EC2 workers to process it with minimal operations.</p><p>This split plays to each system&#8217;s strengths. Kafka handles durable, replayable, high-throughput event streams. RabbitMQ and SQS handle short-lived task processing, where messages represent work that disappears once completed.</p><div><hr></div><p>Thank you for reading!</p><p>If you found it valuable, hit a like &#10084;&#65039; and consider subscribing for more such content every week.</p><p>If you have any questions/suggestions, feel free to leave a comment</p><div class="captioned-button-wrap" data-attrs="{&quot;url&quot;:&quot;https://blog.algomaster.io/p/kafka-vs-rabbitmq-vs-sqs?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">This post is public so feel free to share it.</p></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.algomaster.io/p/kafka-vs-rabbitmq-vs-sqs?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://blog.algomaster.io/p/kafka-vs-rabbitmq-vs-sqs?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p></div>]]></content:encoded></item><item><title><![CDATA[I Created 1000+ Interactive Animations for Interviews]]></title><description><![CDATA[DSA, System Design, AI, SQL and more]]></description><link>https://blog.algomaster.io/p/i-created-1000-interactive-animations</link><guid isPermaLink="false">https://blog.algomaster.io/p/i-created-1000-interactive-animations</guid><dc:creator><![CDATA[Ashish Pratap Singh]]></dc:creator><pubDate>Sun, 28 Jun 2026 13:28:17 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!Aixq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feec69cda-a915-47aa-a64c-d9ba0de81fed_1128x778.gif" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Over the last few months, I&#8217;ve been building <strong>high quality interactive animations</strong> to make learning technical concepts easier, more visual, and more fun.</p><p>Excited to share that we now have <strong>1000+ animations live on <a href="https://algomaster.io/">AlgoMaster.io</a></strong> covering DSA, System Design, AI/ML, SQL and more.</p><p>These animations are designed to help you understand concepts quickly with clear and intuitive visuals instead of just reading theory, memorizing steps or watching an hour long video.</p><p>You can browse the full list <strong><a href="https://algomaster.io/animations">here</a></strong>. Many of these animations are free to explore. For full access, you can subscribe to <strong><a href="https://algomaster.io/premium">premium</a></strong>.</p><p>I&#8217;ve also started sharing animated videos on <strong><a href="https://www.instagram.com/algomasterio/">instagram</a>,</strong> and it just crossed 100k+ followers in 2 months. You can follow <strong><a href="https://www.instagram.com/algomasterio/">here</a></strong> to stay updated.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Aixq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feec69cda-a915-47aa-a64c-d9ba0de81fed_1128x778.gif" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Aixq!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feec69cda-a915-47aa-a64c-d9ba0de81fed_1128x778.gif 424w, https://substackcdn.com/image/fetch/$s_!Aixq!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feec69cda-a915-47aa-a64c-d9ba0de81fed_1128x778.gif 848w, https://substackcdn.com/image/fetch/$s_!Aixq!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feec69cda-a915-47aa-a64c-d9ba0de81fed_1128x778.gif 1272w, https://substackcdn.com/image/fetch/$s_!Aixq!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feec69cda-a915-47aa-a64c-d9ba0de81fed_1128x778.gif 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Aixq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feec69cda-a915-47aa-a64c-d9ba0de81fed_1128x778.gif" width="1128" height="778" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/eec69cda-a915-47aa-a64c-d9ba0de81fed_1128x778.gif&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:778,&quot;width&quot;:1128,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1274387,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/gif&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://blog.algomaster.io/i/203931244?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feec69cda-a915-47aa-a64c-d9ba0de81fed_1128x778.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_!Aixq!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feec69cda-a915-47aa-a64c-d9ba0de81fed_1128x778.gif 424w, https://substackcdn.com/image/fetch/$s_!Aixq!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feec69cda-a915-47aa-a64c-d9ba0de81fed_1128x778.gif 848w, https://substackcdn.com/image/fetch/$s_!Aixq!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feec69cda-a915-47aa-a64c-d9ba0de81fed_1128x778.gif 1272w, https://substackcdn.com/image/fetch/$s_!Aixq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feec69cda-a915-47aa-a64c-d9ba0de81fed_1128x778.gif 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>The animations are also integrated directly into <strong><a href="https://algomaster.io/">AlgoMaster.io</a></strong> courses, so you can learn a concept and visualize it at the same time.</p><p>Whether you are preparing for coding interviews, system design interviews, or trying to to get good at AI/ML, these should make the learning process much smoother.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!DaJ8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5269a00e-b249-4773-804f-47270b0b3758_1594x1184.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!DaJ8!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5269a00e-b249-4773-804f-47270b0b3758_1594x1184.png 424w, https://substackcdn.com/image/fetch/$s_!DaJ8!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5269a00e-b249-4773-804f-47270b0b3758_1594x1184.png 848w, https://substackcdn.com/image/fetch/$s_!DaJ8!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5269a00e-b249-4773-804f-47270b0b3758_1594x1184.png 1272w, https://substackcdn.com/image/fetch/$s_!DaJ8!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5269a00e-b249-4773-804f-47270b0b3758_1594x1184.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!DaJ8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5269a00e-b249-4773-804f-47270b0b3758_1594x1184.png" width="1456" height="1081" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5269a00e-b249-4773-804f-47270b0b3758_1594x1184.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1081,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:186414,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://blog.algomaster.io/i/203931244?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5269a00e-b249-4773-804f-47270b0b3758_1594x1184.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_!DaJ8!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5269a00e-b249-4773-804f-47270b0b3758_1594x1184.png 424w, https://substackcdn.com/image/fetch/$s_!DaJ8!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5269a00e-b249-4773-804f-47270b0b3758_1594x1184.png 848w, https://substackcdn.com/image/fetch/$s_!DaJ8!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5269a00e-b249-4773-804f-47270b0b3758_1594x1184.png 1272w, https://substackcdn.com/image/fetch/$s_!DaJ8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5269a00e-b249-4773-804f-47270b0b3758_1594x1184.png 1456w" sizes="100vw"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!XSlU!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d4ef672-dd4e-4bbe-8580-aeb765ddcf55_1580x910.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!XSlU!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d4ef672-dd4e-4bbe-8580-aeb765ddcf55_1580x910.png 424w, https://substackcdn.com/image/fetch/$s_!XSlU!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d4ef672-dd4e-4bbe-8580-aeb765ddcf55_1580x910.png 848w, https://substackcdn.com/image/fetch/$s_!XSlU!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d4ef672-dd4e-4bbe-8580-aeb765ddcf55_1580x910.png 1272w, https://substackcdn.com/image/fetch/$s_!XSlU!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d4ef672-dd4e-4bbe-8580-aeb765ddcf55_1580x910.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!XSlU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d4ef672-dd4e-4bbe-8580-aeb765ddcf55_1580x910.png" width="1456" height="839" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0d4ef672-dd4e-4bbe-8580-aeb765ddcf55_1580x910.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:839,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:101946,&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://blog.algomaster.io/i/203931244?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d4ef672-dd4e-4bbe-8580-aeb765ddcf55_1580x910.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_!XSlU!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d4ef672-dd4e-4bbe-8580-aeb765ddcf55_1580x910.png 424w, https://substackcdn.com/image/fetch/$s_!XSlU!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d4ef672-dd4e-4bbe-8580-aeb765ddcf55_1580x910.png 848w, https://substackcdn.com/image/fetch/$s_!XSlU!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d4ef672-dd4e-4bbe-8580-aeb765ddcf55_1580x910.png 1272w, https://substackcdn.com/image/fetch/$s_!XSlU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d4ef672-dd4e-4bbe-8580-aeb765ddcf55_1580x910.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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;ll keep adding more useful animations and improving the existing ones over time.</p><p>Hope you find them useful.</p><p>P.S. I&#8217;ve also started adding video content on the platform and plan to cover most of the important topics over the coming months.</p>]]></content:encoded></item><item><title><![CDATA[How LLMs are Actually Trained]]></title><description><![CDATA[In the last lesson, we learned how the Transformer architecture powers an LLM.]]></description><link>https://blog.algomaster.io/p/how-llms-are-actually-trained</link><guid isPermaLink="false">https://blog.algomaster.io/p/how-llms-are-actually-trained</guid><dc:creator><![CDATA[Ashish Pratap Singh]]></dc:creator><pubDate>Thu, 11 Jun 2026 04:50:19 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!cHps!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8ae87dd-9f8a-4d57-9d1b-b5f0e16e9895_1999x730.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In the <a href="https://blog.algomaster.io/p/transformer-architecture">last lesson</a>, we learned how the Transformer architecture powers an LLM. In this one, we will discuss how LLMs are trained from scratch to become helpful assistants.</p><p>LLM training occurs in stages, with each step guiding the model to become more useful than the previous one. These stages are as follows:</p><ol><li><p>Pretraining</p></li><li><p>Mid-training</p></li><li><p>Post-training</p></li></ol><p>In general, each subsequent stage of training requires:</p><ul><li><p>Less training data</p></li><li><p>Cleaner and more domain-specific datasets</p></li><li><p>More sophisticated algorithms</p></li></ul><p>Let&#8217;s learn about each stage in more depth in the subsequent sections.</p><div><hr></div><h1>Pretraining</h1><p>Pretraining is the first stage in LLM training that teaches it the basics of language (grammar, syntax, and semantic structure) and gives it foundational knowledge of the world.</p><p>Large datasets containing trillions of tokens of information scraped from the web are used for LLM pretraining. Some of these datasets are:</p><ul><li><p><a href="https://commoncrawl.org/">Common Crawl</a>: A massive raw dataset obtained by scraping the web. Most other pretraining datasets are filtered down from it.</p></li><li><p><a href="https://arxiv.org/abs/2306.01116">RefinedWeb</a>: A cleaned dataset derived from Common Crawl, used to train <a href="https://arxiv.org/abs/2311.16867">Falcon</a> models</p></li><li><p><a href="https://www.tensorflow.org/datasets/catalog/c4">C4 (Colossal Clean Crawled Corpus)</a>: A cleaned dataset derived from Common Crawl, introduced with <a href="https://huggingface.co/docs/transformers/en/model_doc/t5">Google&#8217;s T5 model</a></p></li><li><p><a href="https://huggingface.co/spaces/HuggingFaceFW/blogpost-fineweb-v1">FineWeb</a>: A cleaned dataset derived from Common Crawl with 15-trillion tokens, released by Hugging Face</p></li><li><p><a href="https://pile.eleuther.ai/">The Pile</a>: A dataset consisting of 22 smaller, high-quality datasets combined together, released by EleutherAI</p></li><li><p><a href="https://allenai.github.io/dolma/">Dolma</a>: Dataset of more than 3 trillion tokens from AllenAI, used to train their <a href="https://allenai.org/olmo">Olmo</a> models</p></li></ul><p>An LLM is trained using the next-token prediction objective by minimizing the cross-entropy loss between the ground truth and predicted tokens at this stage. This is the most compute-intensive stage of the whole LLM training pipeline.</p><p>The resulting pretrained model is called the &#8220;Base model&#8221;, and it can generate subsequent tokens for a given prompt (not necessarily helpful ones).</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!6kWI!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19511ec7-bf2b-4f08-a3db-d667d8592c4e_1614x1106.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!6kWI!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19511ec7-bf2b-4f08-a3db-d667d8592c4e_1614x1106.png 424w, https://substackcdn.com/image/fetch/$s_!6kWI!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19511ec7-bf2b-4f08-a3db-d667d8592c4e_1614x1106.png 848w, https://substackcdn.com/image/fetch/$s_!6kWI!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19511ec7-bf2b-4f08-a3db-d667d8592c4e_1614x1106.png 1272w, https://substackcdn.com/image/fetch/$s_!6kWI!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19511ec7-bf2b-4f08-a3db-d667d8592c4e_1614x1106.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!6kWI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19511ec7-bf2b-4f08-a3db-d667d8592c4e_1614x1106.png" width="1456" height="998" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/19511ec7-bf2b-4f08-a3db-d667d8592c4e_1614x1106.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:998,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:178619,&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://blog.algomaster.io/i/201470936?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19511ec7-bf2b-4f08-a3db-d667d8592c4e_1614x1106.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_!6kWI!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19511ec7-bf2b-4f08-a3db-d667d8592c4e_1614x1106.png 424w, https://substackcdn.com/image/fetch/$s_!6kWI!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19511ec7-bf2b-4f08-a3db-d667d8592c4e_1614x1106.png 848w, https://substackcdn.com/image/fetch/$s_!6kWI!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19511ec7-bf2b-4f08-a3db-d667d8592c4e_1614x1106.png 1272w, https://substackcdn.com/image/fetch/$s_!6kWI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19511ec7-bf2b-4f08-a3db-d667d8592c4e_1614x1106.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">An example of text generated using pretrained GPT-2</figcaption></figure></div><p>At this point, it would be very helpful to learn how a pretraining dataset is created from larger unfiltered datasets such as Common Crawl. Let&#8217;s look into how <strong>Dolma 3 Mix</strong>, the pretraining dataset used to train the Olmo 3 family of models, was created. This dataset contains approximately 6 trillion tokens!</p><p>Starting from raw web archives of Common Crawl, clean text is first extracted from them, and a technique called &#8216;Heuristic filtering&#8217; is then applied, which involves:</p><ul><li><p>Using URL filtering to remove spam and adult content</p></li><li><p>Applying length filters to remove documents that are either too short or too long</p></li><li><p>Filtering and removing documents that contain lots of symbols or insufficient quantities of alphabetic characters</p></li><li><p>Filtering and removing documents with a large amount of repetitive content inside them</p></li><li><p>Filtering and removing documents that contain Personally Identifiable Information (PII)</p></li><li><p>Filtering and removing documents that are in a language other than English</p></li><li><p>Applying <a href="https://arxiv.org/abs/2309.04662">sentence-level filters</a> to find low-quality samples</p></li></ul><p>The resulting documents then go through a stage of <strong>Deduplication</strong>. This is when documents are compared and copies that appear multiple times in the dataset are removed.</p><p>The deduplicated dataset is then further classified by topic and text quality and combined with other cleaned datasets from ArXiv, Wikipedia, GitHub repositories, and more.</p><p>The right mix of datasets is not guessed. Instead, small proxy models are trained on different dataset combinations, and evaluations determine which combination results in the best pretraining performance. The best-performing data is duplicated, while the lower-performing data is discarded. This step is called <strong>Quality-aware upsampling</strong>.</p><p>The resulting data mix is then used in the full pretraining.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Yc9O!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d19e8b0-7c0a-4568-aa86-f853a649581f_2696x970.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Yc9O!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d19e8b0-7c0a-4568-aa86-f853a649581f_2696x970.png 424w, https://substackcdn.com/image/fetch/$s_!Yc9O!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d19e8b0-7c0a-4568-aa86-f853a649581f_2696x970.png 848w, https://substackcdn.com/image/fetch/$s_!Yc9O!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d19e8b0-7c0a-4568-aa86-f853a649581f_2696x970.png 1272w, https://substackcdn.com/image/fetch/$s_!Yc9O!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d19e8b0-7c0a-4568-aa86-f853a649581f_2696x970.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Yc9O!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d19e8b0-7c0a-4568-aa86-f853a649581f_2696x970.png" width="1456" height="524" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3d19e8b0-7c0a-4568-aa86-f853a649581f_2696x970.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:524,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:227293,&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/200269936?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d19e8b0-7c0a-4568-aa86-f853a649581f_2696x970.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_!Yc9O!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d19e8b0-7c0a-4568-aa86-f853a649581f_2696x970.png 424w, https://substackcdn.com/image/fetch/$s_!Yc9O!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d19e8b0-7c0a-4568-aa86-f853a649581f_2696x970.png 848w, https://substackcdn.com/image/fetch/$s_!Yc9O!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d19e8b0-7c0a-4568-aa86-f853a649581f_2696x970.png 1272w, https://substackcdn.com/image/fetch/$s_!Yc9O!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d19e8b0-7c0a-4568-aa86-f853a649581f_2696x970.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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">Steps used to create the Dolma 3 pretraining dataset (<a href="https://arxiv.org/pdf/2512.13961">Source</a>)</figcaption></figure></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.algomaster.io/p/how-llms-are-actually-trained?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://blog.algomaster.io/p/how-llms-are-actually-trained?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><div><hr></div><h1>Mid-training</h1><p>Mid-training is the stage in which an LLM is trained on high-quality, domain-specific data to improve its capabilities. This data focuses on:</p><ul><li><p>Very high-quality web text</p></li><li><p>Domains like health, law, math, code, and general knowledge</p></li><li><p>Improving reasoning (training with reasoning traces)</p></li><li><p>Improving instruction following (training with instruction data)</p></li><li><p>Extending context length</p></li><li><p>Adding a new language</p></li></ul><p>Alongside these, Anthropic recently introduced <strong><a href="https://alignment.anthropic.com/2026/msm/">Model Spec Midtraining (MSM)</a>.</strong> This involves training an LLM on synthetic documents that explain its Model Spec or <a href="https://www-cdn.anthropic.com/9214f02e82c4489fb6cf45441d448a1ecd1a3aca/claudes-constitution.pdf">Constitution</a>. A Model Spec is a document that describes how an LLM should behave, including the rules it must follow and its core values and priorities.</p><p>Experiments show that a model that has undergone MSM generalizes better and is less prone to misalignment when further alignment-tuned. We will learn more about alignment tuning in the next section of this lesson.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!cHps!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8ae87dd-9f8a-4d57-9d1b-b5f0e16e9895_1999x730.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!cHps!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8ae87dd-9f8a-4d57-9d1b-b5f0e16e9895_1999x730.png 424w, https://substackcdn.com/image/fetch/$s_!cHps!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8ae87dd-9f8a-4d57-9d1b-b5f0e16e9895_1999x730.png 848w, https://substackcdn.com/image/fetch/$s_!cHps!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8ae87dd-9f8a-4d57-9d1b-b5f0e16e9895_1999x730.png 1272w, https://substackcdn.com/image/fetch/$s_!cHps!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8ae87dd-9f8a-4d57-9d1b-b5f0e16e9895_1999x730.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!cHps!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8ae87dd-9f8a-4d57-9d1b-b5f0e16e9895_1999x730.png" width="1456" height="532" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b8ae87dd-9f8a-4d57-9d1b-b5f0e16e9895_1999x730.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:532,&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;: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_!cHps!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8ae87dd-9f8a-4d57-9d1b-b5f0e16e9895_1999x730.png 424w, https://substackcdn.com/image/fetch/$s_!cHps!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8ae87dd-9f8a-4d57-9d1b-b5f0e16e9895_1999x730.png 848w, https://substackcdn.com/image/fetch/$s_!cHps!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8ae87dd-9f8a-4d57-9d1b-b5f0e16e9895_1999x730.png 1272w, https://substackcdn.com/image/fetch/$s_!cHps!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8ae87dd-9f8a-4d57-9d1b-b5f0e16e9895_1999x730.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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">Two Llama base models learn different values through MSM and retain them after the same alignment fine-tuning</figcaption></figure></div><p>Some examples of mid-training datasets are:</p><ul><li><p><a href="https://huggingface.co/datasets/allenai/dolmino-mix-1124">Dolmino Mix</a></p></li><li><p><a href="https://huggingface.co/datasets/OctoThinker/MegaMath-Web-Pro-Max">MegaMath-Web-Pro-Max</a></p></li><li><p><a href="https://huggingface.co/datasets/allenai/dolma3_longmino_mix-100B-1125">Longmino Mix</a></p></li></ul><p>A mid-trained model, just like the pretrained model, can generate subsequent tokens for a given prompt, but not necessarily helpful ones.</p><p>If you&#8217;re interested in learning more about the mid-training of language models, you can read a survey that discusses it in depth <a href="https://arxiv.org/abs/2510.06826">using this link</a>.</p><div><hr></div><h1>Post-training</h1><p>Post-training is the final phase that teaches a model to become a useful and human-value-aligned assistant, rather than one that just produces the next token.</p><p>Three post-training techniques that are popularly used are:</p><ul><li><p>Supervised fine-tuning (SFT)</p></li><li><p>Alignment tuning/ fine-tuning</p></li><li><p>Reinforcement learning for reasoning</p></li></ul><p>Let&#8217;s discuss these in more depth.</p><div><hr></div><h2>Supervised fine-tuning (SFT)</h2><p>This involves training the model on datasets consisting of prompt/instruction-response pairs (instruction data). This teaches a model how to follow instructions and produce desired responses.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!njdR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5f094d87-10c0-404b-b915-c4cb45e1b503_1080x1080.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!njdR!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5f094d87-10c0-404b-b915-c4cb45e1b503_1080x1080.png 424w, https://substackcdn.com/image/fetch/$s_!njdR!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5f094d87-10c0-404b-b915-c4cb45e1b503_1080x1080.png 848w, https://substackcdn.com/image/fetch/$s_!njdR!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5f094d87-10c0-404b-b915-c4cb45e1b503_1080x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!njdR!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5f094d87-10c0-404b-b915-c4cb45e1b503_1080x1080.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!njdR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5f094d87-10c0-404b-b915-c4cb45e1b503_1080x1080.png" width="1080" height="1080" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5f094d87-10c0-404b-b915-c4cb45e1b503_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;: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_!njdR!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5f094d87-10c0-404b-b915-c4cb45e1b503_1080x1080.png 424w, https://substackcdn.com/image/fetch/$s_!njdR!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5f094d87-10c0-404b-b915-c4cb45e1b503_1080x1080.png 848w, https://substackcdn.com/image/fetch/$s_!njdR!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5f094d87-10c0-404b-b915-c4cb45e1b503_1080x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!njdR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5f094d87-10c0-404b-b915-c4cb45e1b503_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><figcaption class="image-caption"><a href="https://gumroad.com/a/440621971/yasxkv">Source</a></figcaption></figure></div><p>Some examples of SFT datasets are:</p><ul><li><p><a href="https://huggingface.co/datasets/tatsu-lab/alpaca">Alpaca</a></p></li><li><p><a href="https://huggingface.co/datasets/allenai/Dolci-Think-SFT-32B">Dolci-Think-SFT</a></p></li><li><p><a href="https://huggingface.co/datasets/TIGER-Lab/MathInstruct">MathInstruct</a></p></li></ul><p>An example of a prompt-response pair is shown below.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!9FWs!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9228cdbe-fc30-4197-9784-2446121165a8_2088x346.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!9FWs!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9228cdbe-fc30-4197-9784-2446121165a8_2088x346.png 424w, https://substackcdn.com/image/fetch/$s_!9FWs!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9228cdbe-fc30-4197-9784-2446121165a8_2088x346.png 848w, https://substackcdn.com/image/fetch/$s_!9FWs!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9228cdbe-fc30-4197-9784-2446121165a8_2088x346.png 1272w, https://substackcdn.com/image/fetch/$s_!9FWs!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9228cdbe-fc30-4197-9784-2446121165a8_2088x346.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!9FWs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9228cdbe-fc30-4197-9784-2446121165a8_2088x346.png" width="728" height="120.5" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9228cdbe-fc30-4197-9784-2446121165a8_2088x346.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:241,&quot;width&quot;:1456,&quot;resizeWidth&quot;:728,&quot;bytes&quot;:80379,&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/200269936?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4de61aa-3c28-4dd3-b2a3-26614efccd00_2088x346.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_!9FWs!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9228cdbe-fc30-4197-9784-2446121165a8_2088x346.png 424w, https://substackcdn.com/image/fetch/$s_!9FWs!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9228cdbe-fc30-4197-9784-2446121165a8_2088x346.png 848w, https://substackcdn.com/image/fetch/$s_!9FWs!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9228cdbe-fc30-4197-9784-2446121165a8_2088x346.png 1272w, https://substackcdn.com/image/fetch/$s_!9FWs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9228cdbe-fc30-4197-9784-2446121165a8_2088x346.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Prompt (Instruction + Input) and response (output) pair from the <a href="https://huggingface.co/datasets/tatsu-lab/alpaca">Alpaca</a> dataset</figcaption></figure></div><p>SFT uses next-token prediction with a cross-entropy loss over the target tokens, similar to Pretraining. The main difference is that the loss is calculated only for the response tokens, not the prompt (instruction + input).</p><p>The resulting model after SFT is called the &#8220;Instruct model&#8221; (with the suffix &#8220;-Instruct&#8221; or &#8220;-it&#8221;).</p><p>This model can generate responses to a given instruction in the prompt, but these responses might not align with human values.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!N6DB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdd12961-ac76-46c8-a602-f10ea38335b7_2642x478.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!N6DB!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdd12961-ac76-46c8-a602-f10ea38335b7_2642x478.png 424w, https://substackcdn.com/image/fetch/$s_!N6DB!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdd12961-ac76-46c8-a602-f10ea38335b7_2642x478.png 848w, https://substackcdn.com/image/fetch/$s_!N6DB!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdd12961-ac76-46c8-a602-f10ea38335b7_2642x478.png 1272w, https://substackcdn.com/image/fetch/$s_!N6DB!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdd12961-ac76-46c8-a602-f10ea38335b7_2642x478.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!N6DB!,w_2400,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdd12961-ac76-46c8-a602-f10ea38335b7_2642x478.png" width="1290" height="233.0151098901099" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bdd12961-ac76-46c8-a602-f10ea38335b7_2642x478.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;large&quot;,&quot;height&quot;:263,&quot;width&quot;:1456,&quot;resizeWidth&quot;:1290,&quot;bytes&quot;:103232,&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/200269936?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdd12961-ac76-46c8-a602-f10ea38335b7_2642x478.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_!N6DB!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdd12961-ac76-46c8-a602-f10ea38335b7_2642x478.png 424w, https://substackcdn.com/image/fetch/$s_!N6DB!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdd12961-ac76-46c8-a602-f10ea38335b7_2642x478.png 848w, https://substackcdn.com/image/fetch/$s_!N6DB!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdd12961-ac76-46c8-a602-f10ea38335b7_2642x478.png 1272w, https://substackcdn.com/image/fetch/$s_!N6DB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdd12961-ac76-46c8-a602-f10ea38335b7_2642x478.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">A response produced by an Instruct model might not align with human values.</figcaption></figure></div><p><a href="https://arxiv.org/abs/2501.17161">Previous studies</a> have shown that excessive SFT is harmful because it can cause the model to memorize the training data too well and struggle to generalize to out-of-distribution scenarios. This means that SFT-trained models may perform well in domain-specific tasks but tend to <a href="https://arxiv.org/abs/2507.00432">lose their general capabilities</a>.</p><p>Also, SFT-trained models can lose their capability to explore and further improve with subsequent RL training. This is the reason why newer techniques like <strong><a href="https://www.intoai.pub/p/proximal-sft">Proximal SFT</a></strong> are being developed.</p><div><hr></div><h2>Alignment (Fine-)Tuning</h2><p>This involves training the model on preference datasets to produce helpful, honest, and safe responses aligned with human values and preferences. This step is also sometimes called <strong>Preference (Fine-) Tuning</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_!0auD!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9eb67be-cc51-447a-9e76-057453dda2bc_1080x1080.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!0auD!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9eb67be-cc51-447a-9e76-057453dda2bc_1080x1080.png 424w, https://substackcdn.com/image/fetch/$s_!0auD!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9eb67be-cc51-447a-9e76-057453dda2bc_1080x1080.png 848w, https://substackcdn.com/image/fetch/$s_!0auD!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9eb67be-cc51-447a-9e76-057453dda2bc_1080x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!0auD!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9eb67be-cc51-447a-9e76-057453dda2bc_1080x1080.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!0auD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9eb67be-cc51-447a-9e76-057453dda2bc_1080x1080.png" width="1080" height="1080" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d9eb67be-cc51-447a-9e76-057453dda2bc_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;:59516,&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/200269936?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9eb67be-cc51-447a-9e76-057453dda2bc_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_!0auD!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9eb67be-cc51-447a-9e76-057453dda2bc_1080x1080.png 424w, https://substackcdn.com/image/fetch/$s_!0auD!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9eb67be-cc51-447a-9e76-057453dda2bc_1080x1080.png 848w, https://substackcdn.com/image/fetch/$s_!0auD!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9eb67be-cc51-447a-9e76-057453dda2bc_1080x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!0auD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9eb67be-cc51-447a-9e76-057453dda2bc_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><figcaption class="image-caption"><a href="https://gumroad.com/a/440621971/yasxkv">Source</a></figcaption></figure></div><p>Each sample in a preference dataset is a prompt plus a better/preferred and a worse/rejected/non-preferred response. An example is shown below.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!XGy4!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d017f6c-e118-4154-98f4-be97e4db9a56_2222x412.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!XGy4!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d017f6c-e118-4154-98f4-be97e4db9a56_2222x412.png 424w, https://substackcdn.com/image/fetch/$s_!XGy4!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d017f6c-e118-4154-98f4-be97e4db9a56_2222x412.png 848w, https://substackcdn.com/image/fetch/$s_!XGy4!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d017f6c-e118-4154-98f4-be97e4db9a56_2222x412.png 1272w, https://substackcdn.com/image/fetch/$s_!XGy4!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d017f6c-e118-4154-98f4-be97e4db9a56_2222x412.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!XGy4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d017f6c-e118-4154-98f4-be97e4db9a56_2222x412.png" width="1456" height="270" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9d017f6c-e118-4154-98f4-be97e4db9a56_2222x412.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:270,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:104743,&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/200269936?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d017f6c-e118-4154-98f4-be97e4db9a56_2222x412.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_!XGy4!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d017f6c-e118-4154-98f4-be97e4db9a56_2222x412.png 424w, https://substackcdn.com/image/fetch/$s_!XGy4!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d017f6c-e118-4154-98f4-be97e4db9a56_2222x412.png 848w, https://substackcdn.com/image/fetch/$s_!XGy4!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d017f6c-e118-4154-98f4-be97e4db9a56_2222x412.png 1272w, https://substackcdn.com/image/fetch/$s_!XGy4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d017f6c-e118-4154-98f4-be97e4db9a56_2222x412.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Alignment tuning for LLMs was <a href="https://arxiv.org/abs/2203.02155">popularised by OpenAI</a> with the model &#8216;<em>InstructGPT</em>&#8217;. This was a GPT-3 model that was first fine-tuned using supervised learning and then aligned using a technique called <strong>Reinforcement Learning from Human Feedback (RLHF).</strong></p><p>Here is how RLHF works:</p><ol><li><p>The process of RLHF starts with an LLM that has been fine-tuned with supervised learning (SFT) to generate responses to user queries in a conversational style.</p></li><li><p>Multiple responses to different prompts are collected, and a human labels them from most preferred to least preferred.</p></li><li><p>Based on this preference data, a separate reward model (LLM) is trained to predict which response humans would prefer for a given prompt. This reward model assigns higher rewards to preferred responses and vice versa, functioning as a proxy for a human judge.</p></li><li><p>The LLM in training (called Policy) generates a response for a given prompt.</p></li><li><p>This response is evaluated by the reward model, which returns a reward.</p></li><li><p>Based on the reward, an algorithm called <strong><a href="https://levelup.gitconnected.com/21-reinforcement-learning-rl-concepts-explained-in-plain-english-79087514dba1#0b15">Proximal Policy Optimization (PPO)</a></strong> is used to update the LLM in training to produce higher-rewarded responses.</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_!nOXX!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc80635c3-b762-4b1f-af45-c9a79ac50db4_2010x1362.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!nOXX!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc80635c3-b762-4b1f-af45-c9a79ac50db4_2010x1362.png 424w, https://substackcdn.com/image/fetch/$s_!nOXX!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc80635c3-b762-4b1f-af45-c9a79ac50db4_2010x1362.png 848w, https://substackcdn.com/image/fetch/$s_!nOXX!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc80635c3-b762-4b1f-af45-c9a79ac50db4_2010x1362.png 1272w, https://substackcdn.com/image/fetch/$s_!nOXX!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc80635c3-b762-4b1f-af45-c9a79ac50db4_2010x1362.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!nOXX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc80635c3-b762-4b1f-af45-c9a79ac50db4_2010x1362.png" width="1456" height="987" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c80635c3-b762-4b1f-af45-c9a79ac50db4_2010x1362.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:987,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:532127,&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://blog.algomaster.io/i/201470936?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc80635c3-b762-4b1f-af45-c9a79ac50db4_2010x1362.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_!nOXX!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc80635c3-b762-4b1f-af45-c9a79ac50db4_2010x1362.png 424w, https://substackcdn.com/image/fetch/$s_!nOXX!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc80635c3-b762-4b1f-af45-c9a79ac50db4_2010x1362.png 848w, https://substackcdn.com/image/fetch/$s_!nOXX!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc80635c3-b762-4b1f-af45-c9a79ac50db4_2010x1362.png 1272w, https://substackcdn.com/image/fetch/$s_!nOXX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc80635c3-b762-4b1f-af45-c9a79ac50db4_2010x1362.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 process of RLHF with PPO is computationally and memory-intensive and hard to set up and orchestrate. This is because it uses 4 different LLMs (Policy, Reference, Reward, Value) working together.</p><p>Instead of RLHF with PPO, Alignment tuning today is commonly performed using another technique called <strong><a href="https://arxiv.org/pdf/2305.18290">Direct Preference Optimization (DPO)</a>. </strong>Here, we remove the RL component of RLHF and instead train the LLM directly on response-preference-pairs using a supervised objective.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!XVKR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdab11da1-4146-45f2-8ff9-929d7de84ae8_1232x902.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!XVKR!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdab11da1-4146-45f2-8ff9-929d7de84ae8_1232x902.png 424w, https://substackcdn.com/image/fetch/$s_!XVKR!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdab11da1-4146-45f2-8ff9-929d7de84ae8_1232x902.png 848w, https://substackcdn.com/image/fetch/$s_!XVKR!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdab11da1-4146-45f2-8ff9-929d7de84ae8_1232x902.png 1272w, https://substackcdn.com/image/fetch/$s_!XVKR!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdab11da1-4146-45f2-8ff9-929d7de84ae8_1232x902.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!XVKR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdab11da1-4146-45f2-8ff9-929d7de84ae8_1232x902.png" width="1232" height="902" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/dab11da1-4146-45f2-8ff9-929d7de84ae8_1232x902.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:902,&quot;width&quot;:1232,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:515076,&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://blog.algomaster.io/i/201470936?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdab11da1-4146-45f2-8ff9-929d7de84ae8_1232x902.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_!XVKR!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdab11da1-4146-45f2-8ff9-929d7de84ae8_1232x902.png 424w, https://substackcdn.com/image/fetch/$s_!XVKR!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdab11da1-4146-45f2-8ff9-929d7de84ae8_1232x902.png 848w, https://substackcdn.com/image/fetch/$s_!XVKR!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdab11da1-4146-45f2-8ff9-929d7de84ae8_1232x902.png 1272w, https://substackcdn.com/image/fetch/$s_!XVKR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdab11da1-4146-45f2-8ff9-929d7de84ae8_1232x902.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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">RLHF with PPO first learns a reward model from human feedback, then uses RL to optimize the LLM in training. DPO skips this by directly training the model to prefer better responses using a supervised objective, thereby implicitly learning reward.</figcaption></figure></div><p>Some examples of datasets used for Alignment tuning are:</p><ul><li><p><a href="https://huggingface.co/datasets/Anthropic/hh-rlhf">HH-RLHF</a></p></li><li><p><a href="https://huggingface.co/datasets/openbmb/UltraFeedback/viewer/default/train?p=1">UltraFeedback</a></p></li><li><p><a href="https://huggingface.co/datasets/allenai/Dolci-Think-DPO-7B">Dolci-Think-DPO-7B</a></p></li></ul><p>An aligned model can generate helpful, harmless outputs that align with human values and preferences in response to a given instruction in the prompt.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!zVoV!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb867099-89b8-4afa-9051-967be1601b6d_2654x878.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!zVoV!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb867099-89b8-4afa-9051-967be1601b6d_2654x878.png 424w, https://substackcdn.com/image/fetch/$s_!zVoV!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb867099-89b8-4afa-9051-967be1601b6d_2654x878.png 848w, https://substackcdn.com/image/fetch/$s_!zVoV!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb867099-89b8-4afa-9051-967be1601b6d_2654x878.png 1272w, https://substackcdn.com/image/fetch/$s_!zVoV!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb867099-89b8-4afa-9051-967be1601b6d_2654x878.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!zVoV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb867099-89b8-4afa-9051-967be1601b6d_2654x878.png" width="1456" height="482" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cb867099-89b8-4afa-9051-967be1601b6d_2654x878.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:482,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:229205,&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/200269936?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb867099-89b8-4afa-9051-967be1601b6d_2654x878.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_!zVoV!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb867099-89b8-4afa-9051-967be1601b6d_2654x878.png 424w, https://substackcdn.com/image/fetch/$s_!zVoV!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb867099-89b8-4afa-9051-967be1601b6d_2654x878.png 848w, https://substackcdn.com/image/fetch/$s_!zVoV!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb867099-89b8-4afa-9051-967be1601b6d_2654x878.png 1272w, https://substackcdn.com/image/fetch/$s_!zVoV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb867099-89b8-4afa-9051-967be1601b6d_2654x878.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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>Reinforcement learning for reasoning</h2><p>This involves using <a href="https://levelup.gitconnected.com/21-reinforcement-learning-rl-concepts-explained-in-plain-english-79087514dba1">Reinforcement learning (RL)</a> to train a model to think and reason before responding, especially for difficult questions.</p><p>A technique called <strong>Reinforcement Learning with Verifiable Rewards (RLVR)</strong>, introduced in the <a href="https://arxiv.org/abs/2411.15124">Tulu 3 paper</a>, is a method for training an LLM to reason, particularly for tasks whose results can be objectively verified. This includes tasks such as math, logic and coding, where a simpler rule-based verifier (not an LLM) can check whether the answer is correct.</p><p>Compare this to alignment tuning with RLHF, which uses a reward model (an LLM) to score the responses, because the correct results are highly subjective. Tasks like this cannot be handled by RLVR.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!G3lL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F49772f48-58f5-4373-9f60-a7ee0ab763ec_1080x1080.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!G3lL!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F49772f48-58f5-4373-9f60-a7ee0ab763ec_1080x1080.png 424w, https://substackcdn.com/image/fetch/$s_!G3lL!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F49772f48-58f5-4373-9f60-a7ee0ab763ec_1080x1080.png 848w, https://substackcdn.com/image/fetch/$s_!G3lL!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F49772f48-58f5-4373-9f60-a7ee0ab763ec_1080x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!G3lL!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F49772f48-58f5-4373-9f60-a7ee0ab763ec_1080x1080.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!G3lL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F49772f48-58f5-4373-9f60-a7ee0ab763ec_1080x1080.png" width="1080" height="1080" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/49772f48-58f5-4373-9f60-a7ee0ab763ec_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;:51752,&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/200269936?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F49772f48-58f5-4373-9f60-a7ee0ab763ec_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_!G3lL!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F49772f48-58f5-4373-9f60-a7ee0ab763ec_1080x1080.png 424w, https://substackcdn.com/image/fetch/$s_!G3lL!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F49772f48-58f5-4373-9f60-a7ee0ab763ec_1080x1080.png 848w, https://substackcdn.com/image/fetch/$s_!G3lL!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F49772f48-58f5-4373-9f60-a7ee0ab763ec_1080x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!G3lL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F49772f48-58f5-4373-9f60-a7ee0ab763ec_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><figcaption class="image-caption"><a href="https://gumroad.com/a/440621971/yasxkv">Source</a></figcaption></figure></div><p>This is how RLVR works:</p><ol><li><p>For a given prompt to solve a math or coding task, the LLM in training (called Policy) generates response(s) to it.</p></li><li><p>A rule-based verifier checks whether the answer is correct or incorrect. The correct response(s) receive a reward of 1, while the incorrect ones receive 0.</p></li><li><p>RL algorithms such as either <a href="https://levelup.gitconnected.com/21-reinforcement-learning-rl-concepts-explained-in-plain-english-79087514dba1#0b15">PPO</a> or <a href="https://levelup.gitconnected.com/21-reinforcement-learning-rl-concepts-explained-in-plain-english-79087514dba1#ef4e">GRPO</a> are used to update the Policy model and make the correct reasoning paths more likely.</p></li></ol><p>This is not the only way to train a reasoning model. A reward model or an LLM judge is used instead of a programmatic verifier to train a reasoning model in domains where answers can&#8217;t be automatically verified (such as open-ended dialogue, creative writing, legal analysis, or medical diagnosis).</p><p>Alongside this, a <strong><a href="https://arxiv.org/abs/2305.20050">Process Reward Model</a></strong> can also be used in the RL training process to grade all intermediate reasoning steps in an LLM&#8217;s reasoning chain, rather than just rewarding the final answer. This trains and prevents an LLM from getting the answer right but for the wrong reasons.</p><p>The resulting reasoning model, developed using the above techniques, is called the &#8220;Think model&#8221;.</p><p>Many LLMs are also trained using RL to reason directly from the pretrained / base model with no SFT. These models are named with the suffix &#8220;-Zero&#8221;. Some notable examples of such models include DeepSeek-R1-Zero and Olmo 3 RL-Zero.</p><p>These models have surprisingly high performance on tough benchmarks. For example, DeepSeek-R1-Zero has an average pass@1 score of 77.9% on <a href="https://artofproblemsolving.com/wiki/index.php/2024_AIME_I">AIME 2024</a> while the base model scores merely 15.6%.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!3duK!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F613211c5-d5e8-4edb-8c9e-b95b22e1e688_1836x1054.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!3duK!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F613211c5-d5e8-4edb-8c9e-b95b22e1e688_1836x1054.png 424w, https://substackcdn.com/image/fetch/$s_!3duK!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F613211c5-d5e8-4edb-8c9e-b95b22e1e688_1836x1054.png 848w, https://substackcdn.com/image/fetch/$s_!3duK!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F613211c5-d5e8-4edb-8c9e-b95b22e1e688_1836x1054.png 1272w, https://substackcdn.com/image/fetch/$s_!3duK!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F613211c5-d5e8-4edb-8c9e-b95b22e1e688_1836x1054.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!3duK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F613211c5-d5e8-4edb-8c9e-b95b22e1e688_1836x1054.png" width="1456" height="836" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/613211c5-d5e8-4edb-8c9e-b95b22e1e688_1836x1054.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:836,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:209859,&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/200269936?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F613211c5-d5e8-4edb-8c9e-b95b22e1e688_1836x1054.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_!3duK!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F613211c5-d5e8-4edb-8c9e-b95b22e1e688_1836x1054.png 424w, https://substackcdn.com/image/fetch/$s_!3duK!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F613211c5-d5e8-4edb-8c9e-b95b22e1e688_1836x1054.png 848w, https://substackcdn.com/image/fetch/$s_!3duK!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F613211c5-d5e8-4edb-8c9e-b95b22e1e688_1836x1054.png 1272w, https://substackcdn.com/image/fetch/$s_!3duK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F613211c5-d5e8-4edb-8c9e-b95b22e1e688_1836x1054.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://arxiv.org/abs/2501.12948">Source</a></figcaption></figure></div><div><hr></div><h1>Further user-specific training</h1><p>Once a model has been post-trained and released, users can further train it on their own data to make it stronger in specific domains (such as law, medicine, finance, and banking) or adapt it to their use case (such as customer support requests).</p><p>This is done by training the model on prompt-response pairs from a custom dataset using:</p><ul><li><p><strong>Full Supervised fine-tuning (SFT)</strong>, where all model parameters are updated using the supervised next-token objective. Although most effective, this is highly memory and compute-intensive.</p></li><li><p><strong>LoRA (Low-Rank Adaptation) fine-tuning</strong>, which is a parameter-efficient version of SFT, where instead of updating every parameter, the original model is frozen, small low-rank matrices are injected into it, and only these are trained. This reduces the memory and compute needed in the fine-tuning process.</p></li><li><p>A quantized variant of LoRA called <strong>QLoRA</strong>, which further reduces memory cost.</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_!SY65!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3eb14c4-9ba0-4657-b235-fc6c5f26d1b9_1200x588.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!SY65!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3eb14c4-9ba0-4657-b235-fc6c5f26d1b9_1200x588.png 424w, https://substackcdn.com/image/fetch/$s_!SY65!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3eb14c4-9ba0-4657-b235-fc6c5f26d1b9_1200x588.png 848w, https://substackcdn.com/image/fetch/$s_!SY65!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3eb14c4-9ba0-4657-b235-fc6c5f26d1b9_1200x588.png 1272w, https://substackcdn.com/image/fetch/$s_!SY65!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3eb14c4-9ba0-4657-b235-fc6c5f26d1b9_1200x588.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!SY65!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3eb14c4-9ba0-4657-b235-fc6c5f26d1b9_1200x588.png" width="1200" height="588" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b3eb14c4-9ba0-4657-b235-fc6c5f26d1b9_1200x588.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:588,&quot;width&quot;:1200,&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_!SY65!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3eb14c4-9ba0-4657-b235-fc6c5f26d1b9_1200x588.png 424w, https://substackcdn.com/image/fetch/$s_!SY65!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3eb14c4-9ba0-4657-b235-fc6c5f26d1b9_1200x588.png 848w, https://substackcdn.com/image/fetch/$s_!SY65!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3eb14c4-9ba0-4657-b235-fc6c5f26d1b9_1200x588.png 1272w, https://substackcdn.com/image/fetch/$s_!SY65!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3eb14c4-9ba0-4657-b235-fc6c5f26d1b9_1200x588.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://arxiv.org/abs/2305.14314">Source</a></figcaption></figure></div><p>Note that users could even use DPO, RLVR, or other RL algorithms to further tune the model for their use case, based on the compute available to them.</p><div><hr></div><p>Thank you for reading!</p><p>If you found it valuable, hit a like &#10084;&#65039; and consider subscribing for more such content every week.</p><p>If you have any questions/suggestions, feel free to leave a comment.</p><p>This post is public so feel free to share it.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.algomaster.io/p/transformer-architecture?utm_source=substack&amp;utm_medium=email&amp;utm_content=share&amp;action=share&amp;token=eyJ1c2VyX2lkIjo4MzYwMjc0MywicG9zdF9pZCI6MTk3MTg1Mzg0LCJpYXQiOjE3ODExMDYxMjQsImV4cCI6MTc4MzY5ODEyNCwiaXNzIjoicHViLTIyMDIyNjgiLCJzdWIiOiJwb3N0LXJlYWN0aW9uIn0.vwm_vgQ7aDm_WmBFRD7g8C_j_vO3NAVYjegsnYJs7QI&quot;,&quot;text&quot;:&quot;Share&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.algomaster.io/p/transformer-architecture?utm_source=substack&amp;utm_medium=email&amp;utm_content=share&amp;action=share&amp;token=eyJ1c2VyX2lkIjo4MzYwMjc0MywicG9zdF9pZCI6MTk3MTg1Mzg0LCJpYXQiOjE3ODExMDYxMjQsImV4cCI6MTc4MzY5ODEyNCwiaXNzIjoicHViLTIyMDIyNjgiLCJzdWIiOiJwb3N0LXJlYWN0aW9uIn0.vwm_vgQ7aDm_WmBFRD7g8C_j_vO3NAVYjegsnYJs7QI"><span>Share</span></a></p>]]></content:encoded></item><item><title><![CDATA[An Amazon Bar Raiser's Guide to Cracking Tech Interviews]]></title><description><![CDATA[This is a guest post by Apurv Singh, a Senior Engineer and Bar Raiser at Amazon. Having conducted 200+ technical interviews, Apurv shares practical lessons and insights to help you prepare better and crack tech interviews.]]></description><link>https://blog.algomaster.io/p/amazons-bar-raisers-guide-on-cracking-tech-interviews</link><guid isPermaLink="false">https://blog.algomaster.io/p/amazons-bar-raisers-guide-on-cracking-tech-interviews</guid><dc:creator><![CDATA[Ashish Pratap Singh]]></dc:creator><pubDate>Thu, 04 Jun 2026 12:06:04 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/0d3ee9b7-af65-4949-8a34-1940e1763a9b_2460x344.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>This is a guest post by <strong><a href="https://www.linkedin.com/in/ag-singh/">Apurv Singh</a></strong>, a Senior Engineer and Bar Raiser at <strong>Amazon</strong>. Having conducted <strong>200+ technical interviews</strong>, Apurv shares practical lessons and insights to help you prepare better and crack tech interviews.</p><div><hr></div><p>After conducting close to 200 interviews at Amazon, across entry-level to senior-level roles and job families such as SDE, TPM, MLE, Product Manager, and SDM, I have gained a deeper appreciation for what it means to sit on the other side of the table.</p><p>As an interviewer, my goal is not just to ask questions or judge answers. It is to objectively collect data points, identify strengths, notice potential red flags, and assess whether a candidate demonstrates the skills and behaviors expected for the role.</p><div><hr></div><h1>The Interviewer&#8217;s Responsibility</h1><p>The interview process at large tech companies like Amazon is highly structured and well defined. My responsibility as an interviewer is to drive the conversation, manage time effectively, and collect enough meaningful data points to make a fair assessment.</p><p>One of the most important skills is taking detailed notes while actively listening, so that no critical signal is missed. Every follow-up question is intentional. It helps uncover more depth, clarify ambiguities, and evaluate the candidate against the expectations of the role.</p><p>A good interviewer also tries to make the candidate feel comfortable. The best interviews do not feel like an interrogation. They feel like a thoughtful discussion between peers working through a problem together.</p><div><hr></div><h1>How Candidates Are Evaluated?</h1><p>As interviewers, we are assigned well-defined competencies to evaluate candidates against. These may include technical questions, role-specific expectations, and behavioral aspects such as Leadership Principles.</p><p>The evaluation criteria help us identify both strengths and areas of concern in a candidate&#8217;s performance.</p><p>A candidate is not evaluated only on whether they arrive at the correct answer. We also look at the overall signal across multiple dimensions, such as technical depth, problem-solving approach, communication clarity, ownership and accountability, ability to handle ambiguity, seniority signals, and behavioral competencies.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!k4Kc!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe28f881b-bcc5-4fe1-828d-20666a3fe8a5_2460x344.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!k4Kc!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe28f881b-bcc5-4fe1-828d-20666a3fe8a5_2460x344.png 424w, https://substackcdn.com/image/fetch/$s_!k4Kc!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe28f881b-bcc5-4fe1-828d-20666a3fe8a5_2460x344.png 848w, https://substackcdn.com/image/fetch/$s_!k4Kc!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe28f881b-bcc5-4fe1-828d-20666a3fe8a5_2460x344.png 1272w, https://substackcdn.com/image/fetch/$s_!k4Kc!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe28f881b-bcc5-4fe1-828d-20666a3fe8a5_2460x344.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!k4Kc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe28f881b-bcc5-4fe1-828d-20666a3fe8a5_2460x344.png" width="1456" height="204" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e28f881b-bcc5-4fe1-828d-20666a3fe8a5_2460x344.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:204,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:81402,&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://blog.algomaster.io/i/200460070?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe28f881b-bcc5-4fe1-828d-20666a3fe8a5_2460x344.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_!k4Kc!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe28f881b-bcc5-4fe1-828d-20666a3fe8a5_2460x344.png 424w, https://substackcdn.com/image/fetch/$s_!k4Kc!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe28f881b-bcc5-4fe1-828d-20666a3fe8a5_2460x344.png 848w, https://substackcdn.com/image/fetch/$s_!k4Kc!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe28f881b-bcc5-4fe1-828d-20666a3fe8a5_2460x344.png 1272w, https://substackcdn.com/image/fetch/$s_!k4Kc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe28f881b-bcc5-4fe1-828d-20666a3fe8a5_2460x344.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>At Amazon, Leadership Principles are especially important and are given equal weight alongside technical performance. Strong candidates demonstrate not only that they can solve problems, but also that they can take ownership, make sound decisions, communicate effectively, and operate at the expected level for the role.</p><p>Consistency across rounds matters too. Hiring decisions are based on the overall pattern of data points collected throughout the loop, not on a single strong or weak moment in one interview.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.algomaster.io/p/amazons-bar-raisers-guide-on-cracking-tech-interviews?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://blog.algomaster.io/p/amazons-bar-raisers-guide-on-cracking-tech-interviews?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><div><hr></div><h1>What Makes a Candidate Stand Out?</h1><p>One thing that immediately stands out to me is how a candidate approaches ambiguity. Jumping straight to a solution without first clarifying the requirements is often a red flag, because it can make the interview feel mechanically rehearsed rather than thoughtful.</p><p>On the other hand, a candidate who asks relevant <strong>clarifying questions</strong> early in the discussion creates a strong first impression. It shows that they are not just trying to solve a memorized problem, but are genuinely trying to understand the problem space.</p><p>Another important signal is the ability to explain the chosen approach clearly. A strong candidate should be able to walk the interviewer through their thought process, justify why they picked a particular solution, and discuss the tradeoffs involved. The final answer matters, but the reasoning behind it often matters even more.</p><p>The candidates who handle this well tend to move through the problem in a predictable, deliberate way:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!UJlq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2075212-04db-48b0-93d6-eccf2ba1125b_914x90.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!UJlq!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2075212-04db-48b0-93d6-eccf2ba1125b_914x90.png 424w, https://substackcdn.com/image/fetch/$s_!UJlq!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2075212-04db-48b0-93d6-eccf2ba1125b_914x90.png 848w, https://substackcdn.com/image/fetch/$s_!UJlq!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2075212-04db-48b0-93d6-eccf2ba1125b_914x90.png 1272w, https://substackcdn.com/image/fetch/$s_!UJlq!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2075212-04db-48b0-93d6-eccf2ba1125b_914x90.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!UJlq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2075212-04db-48b0-93d6-eccf2ba1125b_914x90.png" width="914" height="90" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d2075212-04db-48b0-93d6-eccf2ba1125b_914x90.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:90,&quot;width&quot;:914,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:17961,&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://blog.algomaster.io/i/200460070?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2075212-04db-48b0-93d6-eccf2ba1125b_914x90.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_!UJlq!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2075212-04db-48b0-93d6-eccf2ba1125b_914x90.png 424w, https://substackcdn.com/image/fetch/$s_!UJlq!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2075212-04db-48b0-93d6-eccf2ba1125b_914x90.png 848w, https://substackcdn.com/image/fetch/$s_!UJlq!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2075212-04db-48b0-93d6-eccf2ba1125b_914x90.png 1272w, https://substackcdn.com/image/fetch/$s_!UJlq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2075212-04db-48b0-93d6-eccf2ba1125b_914x90.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>As an interviewer, I also value originality. Since I am investing my time in the conversation as well, it is always exciting when I learn something new from a candidate. There have been interviews where a candidate came up with a unique or elegant approach that I had not considered before, and that immediately left a strong positive impression.</p><div><hr></div><h1>Common Red Flags Interviewers Notice</h1><p>One thing I genuinely appreciate is when candidates openly acknowledge that they do not know something. No one is expected to know everything, and honesty often creates a positive signal.</p><p>As an experienced interviewer, it is usually easy to identify when a candidate is trying to bluff or exaggerate. If a candidate does not know a concept but can reason through it logically, that is still a much better signal than pretending to know something they do not.</p><p>Some other common red flags interviewers notice include:</p><ul><li><p>Being defensive when challenged instead of engaging with the feedback</p></li><li><p>Claiming ownership of a project without clearly explaining their personal contribution</p></li><li><p>Over-engineering simple problems</p></li><li><p>Blaming others when describing past projects</p></li><li><p>Ignoring edge cases</p></li><li><p>Not testing the solution</p></li></ul><p>A strong interview is not about appearing perfect. It is about being thoughtful, honest, structured, and open to feedback. Candidates who can acknowledge gaps, clarify their thinking, and recover gracefully from mistakes often leave a much better impression than candidates who try to force confidence without substance.</p><div><hr></div><h1>How Behavioral Interviews are Assessed</h1><p>At Amazon, Leadership Principles are extremely important and are evaluated with the same seriousness as technical skills. Behavioral interviews are not casual conversations; they help interviewers understand how a candidate has acted in real situations and whether those behaviors align with the role&#8217;s expectations.</p><p>A strong answer is usually well-structured using the STAR format: Situation, Task, Action, and Result. Candidates should clearly explain the context, their specific responsibility, the actions they took, and the outcome they achieved.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Hdxk!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73a0d5ac-4bdc-408a-be3c-4756b96c0fed_841x94.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Hdxk!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73a0d5ac-4bdc-408a-be3c-4756b96c0fed_841x94.png 424w, https://substackcdn.com/image/fetch/$s_!Hdxk!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73a0d5ac-4bdc-408a-be3c-4756b96c0fed_841x94.png 848w, https://substackcdn.com/image/fetch/$s_!Hdxk!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73a0d5ac-4bdc-408a-be3c-4756b96c0fed_841x94.png 1272w, https://substackcdn.com/image/fetch/$s_!Hdxk!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73a0d5ac-4bdc-408a-be3c-4756b96c0fed_841x94.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Hdxk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73a0d5ac-4bdc-408a-be3c-4756b96c0fed_841x94.png" width="841" height="94" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/73a0d5ac-4bdc-408a-be3c-4756b96c0fed_841x94.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:94,&quot;width&quot;:841,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:16265,&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://blog.algomaster.io/i/200460070?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73a0d5ac-4bdc-408a-be3c-4756b96c0fed_841x94.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_!Hdxk!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73a0d5ac-4bdc-408a-be3c-4756b96c0fed_841x94.png 424w, https://substackcdn.com/image/fetch/$s_!Hdxk!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73a0d5ac-4bdc-408a-be3c-4756b96c0fed_841x94.png 848w, https://substackcdn.com/image/fetch/$s_!Hdxk!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73a0d5ac-4bdc-408a-be3c-4756b96c0fed_841x94.png 1272w, https://substackcdn.com/image/fetch/$s_!Hdxk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73a0d5ac-4bdc-408a-be3c-4756b96c0fed_841x94.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>A couple of things tend to weaken behavioral answers. Repeating the same example for multiple questions can be a weak signal, since it may suggest limited experience or thin preparation. Vague answers without concrete details also make it hard to assess what the candidate actually contributed.</p><p>Data matters here. Strong candidates quantify impact where possible, such as improved latency, reduced cost, saved time, increased adoption, or better customer experience. Strong behavioral answers are specific, authentic, and backed by measurable outcomes.</p><div><hr></div><h1>What Candidates Misunderstand About Interviews?</h1><p>One common misunderstanding candidates have is that interviews are only about getting the correct answer.</p><p>In reality, interviewers are equally interested in how the candidate approaches the problem, clarifies requirements, communicates their thought process, and handles feedback.</p><p>Another misconception is that taking hints is a negative signal. Getting stuck can happen to anyone. What matters more is how the candidate responds: whether they listen carefully, adapt their approach, and continue reasoning logically. Many candidates also underestimate behavioral interviews.</p><p>At companies like Amazon, Leadership Principles are evaluated very seriously, and behavioral rounds can carry as much weight as technical rounds.</p><p>Candidates sometimes believe they need to appear perfect, but honesty is more valuable than pretending to know everything. A candidate who acknowledges gaps and reasons through uncertainty often creates a stronger impression than someone who tries to bluff.</p><p>A strong interview is not a performance of perfection; it is a demonstration of clarity, ownership, problem-solving, and self-awareness.</p><div><hr></div><h1>Advice to Candidates From an Interviewer</h1><p>My biggest piece of advice to candidates is to treat the interview like a collaborative problem-solving discussion, not a test where you have to prove you know everything. Start by clarifying the requirements, state your assumptions, and explain your thought process clearly as you move toward a solution.</p><p>Do not rush to the answer. Interviewers care about how you think, how you handle ambiguity, and how you respond when challenged. If you get stuck, stay calm, listen to hints, and use them to adjust your approach.</p><p>For behavioral interviews, prepare multiple examples from your experience and structure them using the STAR format. Be specific about your personal contribution, the tradeoffs you made, and the impact you created. Whenever possible, support your answers with data.</p><p>Most importantly, be honest. If you do not know something, acknowledge it and reason through it logically. Strong candidates are not perfect; they are clear, thoughtful, coachable, and self-aware!</p><div><hr></div><p>Thank you for reading!</p><div class="captioned-button-wrap" data-attrs="{&quot;url&quot;:&quot;https://blog.algomaster.io/p/amazons-bar-raisers-guide-on-cracking-tech-interviews?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">This post is public so feel free to share it.</p></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.algomaster.io/p/amazons-bar-raisers-guide-on-cracking-tech-interviews?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://blog.algomaster.io/p/amazons-bar-raisers-guide-on-cracking-tech-interviews?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p></div>]]></content:encoded></item><item><title><![CDATA[20 Networking Concepts Explained in 15 Minutes]]></title><description><![CDATA[Networking can feel overwhelming, but a small set of concepts carries most of the weight in interviews and real-world systems.]]></description><link>https://blog.algomaster.io/p/20-networking-concepts-explained</link><guid isPermaLink="false">https://blog.algomaster.io/p/20-networking-concepts-explained</guid><dc:creator><![CDATA[Ashish Pratap Singh]]></dc:creator><pubDate>Tue, 02 Jun 2026 05:28:43 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!0KlT!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F091d46c7-b6be-48e4-a262-5118b1f57a5a_1870x800.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Networking can feel overwhelming, but a small set of concepts carries most of the weight in interviews and real-world systems.</p><p>In this article, we w&#8217;ll cover 20 most important networking concepts divided into 5 groups: <strong>Addressing, Packets and Layers, Protocols, Infrastructure, and Performance.</strong></p><p>Let&#8217;s start with the most basic question: how do devices find each other?</p><div><hr></div><h1>Addressing</h1><h2><a href="https://algomaster.io/learn/system-design/ip-address">1. IP Address</a></h2><p>Every device on a network needs an address so other devices can find it. That address is called an IP address.</p><p>There are two versions in use:</p><ul><li><p><strong>IPv4</strong> looks like <code>142.250.80.46</code>. It uses four numbers from 0 to 255 and supports about 4.3 billion addresses.</p></li><li><p><strong>IPv6</strong> looks like <code>2001:db8:85a3::8a2e:370:7334</code>. It uses a much larger address space built for the modern internet.</p></li></ul><p>IP addresses can also be public or private.</p><pre><code><code>Your laptop:    192.168.1.10     private
Home router:    73.128.42.15     public
Google server:  142.250.80.46    public</code></code></pre><p>Your laptop uses a private IP inside your home network. Your router has a public IP on the internet and translates traffic between the two.</p><p>But nobody wants to memorize IP addresses for every website server.</p><p>That is where DNS comes in.</p><div><hr></div><h2><a href="https://algomaster.io/learn/system-design/domain-name-system-dns">2. DNS</a></h2><p>DNS, or Domain Name System, translates a human-friendly name like <code>google.com</code> into an IP address like <code>142.250.80.46</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_!hRnS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e6d0fad-b7ac-4874-a832-22dab95965e1_2052x1430.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!hRnS!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e6d0fad-b7ac-4874-a832-22dab95965e1_2052x1430.png 424w, https://substackcdn.com/image/fetch/$s_!hRnS!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e6d0fad-b7ac-4874-a832-22dab95965e1_2052x1430.png 848w, https://substackcdn.com/image/fetch/$s_!hRnS!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e6d0fad-b7ac-4874-a832-22dab95965e1_2052x1430.png 1272w, https://substackcdn.com/image/fetch/$s_!hRnS!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e6d0fad-b7ac-4874-a832-22dab95965e1_2052x1430.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!hRnS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e6d0fad-b7ac-4874-a832-22dab95965e1_2052x1430.png" width="1456" height="1015" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6e6d0fad-b7ac-4874-a832-22dab95965e1_2052x1430.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1015,&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_!hRnS!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e6d0fad-b7ac-4874-a832-22dab95965e1_2052x1430.png 424w, https://substackcdn.com/image/fetch/$s_!hRnS!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e6d0fad-b7ac-4874-a832-22dab95965e1_2052x1430.png 848w, https://substackcdn.com/image/fetch/$s_!hRnS!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e6d0fad-b7ac-4874-a832-22dab95965e1_2052x1430.png 1272w, https://substackcdn.com/image/fetch/$s_!hRnS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e6d0fad-b7ac-4874-a832-22dab95965e1_2052x1430.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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>First, the browser and operating system check if they already know the answer. If not, the request goes to a recursive resolver, usually run by your ISP or a public provider like Google DNS.</p><p>The resolver then walks the DNS hierarchy: root server, TLD server like <code>.com</code>, and finally the authoritative name server for the domain.</p><p>The result is cached at multiple levels, so most DNS lookups are fast.</p><p>DNS and IP get traffic to the right machine. But a machine runs many programs, so how does traffic reach the right one?</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.algomaster.io/p/20-networking-concepts-explained?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://blog.algomaster.io/p/20-networking-concepts-explained?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><div><hr></div><h2>3. Ports</h2><p>An IP address gets traffic to the right machine. A port gets it to the right program on that machine.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!amGU!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe6fb45d-82b9-44b7-a218-666eaea72855_1052x442.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!amGU!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe6fb45d-82b9-44b7-a218-666eaea72855_1052x442.png 424w, https://substackcdn.com/image/fetch/$s_!amGU!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe6fb45d-82b9-44b7-a218-666eaea72855_1052x442.png 848w, https://substackcdn.com/image/fetch/$s_!amGU!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe6fb45d-82b9-44b7-a218-666eaea72855_1052x442.png 1272w, https://substackcdn.com/image/fetch/$s_!amGU!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe6fb45d-82b9-44b7-a218-666eaea72855_1052x442.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!amGU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe6fb45d-82b9-44b7-a218-666eaea72855_1052x442.png" width="613" height="257.5532319391635" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fe6fb45d-82b9-44b7-a218-666eaea72855_1052x442.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:442,&quot;width&quot;:1052,&quot;resizeWidth&quot;:613,&quot;bytes&quot;:21967,&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://blog.algomaster.io/i/173399461?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe6fb45d-82b9-44b7-a218-666eaea72855_1052x442.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_!amGU!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe6fb45d-82b9-44b7-a218-666eaea72855_1052x442.png 424w, https://substackcdn.com/image/fetch/$s_!amGU!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe6fb45d-82b9-44b7-a218-666eaea72855_1052x442.png 848w, https://substackcdn.com/image/fetch/$s_!amGU!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe6fb45d-82b9-44b7-a218-666eaea72855_1052x442.png 1272w, https://substackcdn.com/image/fetch/$s_!amGU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe6fb45d-82b9-44b7-a218-666eaea72855_1052x442.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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>Ports are numbers from <code>0</code> to <code>65535</code>. Some common ports are:</p><ul><li><p><strong>22: </strong>SSH</p></li><li><p><strong>53:</strong> DNS</p></li><li><p><strong>80:</strong> HTTP</p></li><li><p><strong>443:</strong> HTTPS</p></li><li><p><strong>5432:</strong> PostgreSQL</p></li><li><p><strong>6379:</strong> Redis</p></li></ul><p>When you visit a website, your browser connects to port 443 by default.</p><p>A server is usually identified by an <code>(IP, port)</code> pair. That is why two web servers on the same machine need different ports, like <code>8080</code> and <code>8081</code>.</p><p>Now we know how to reach the right machine and process. But inside a local network, how does traffic find the right physical device?</p><div><hr></div><h2>4. MAC Address</h2><p>A MAC address is a hardware address assigned to a network interface, usually written like <code>a4:83:e7:1b:22:9c</code>.</p><p>IP addresses help route traffic across networks. MAC addresses help deliver traffic inside the same local network, like your home Wi-Fi or office LAN.</p><p>When your laptop wants to talk to another device on the same network, it uses <a href="https://en.wikipedia.org/wiki/Address_Resolution_Protocol">ARP</a> to ask:</p><pre><code><code>Who has IP 192.168.1.20?</code></code></pre><p>The device with that IP replies with its MAC address. The switch then uses that MAC address to forward the data to the right device.</p><p>IPs can change when you move networks or get a new DHCP assignment. MAC addresses are meant to be fixed, though modern devices often randomize them on public Wi-Fi for privacy.</p><p>You rarely configure MAC addresses yourself, but you may see them in DHCP reservations, firewall rules, and switch settings.</p><div><hr></div><h2>5. NAT</h2><p>Most homes have many devices but only one public IP address. NAT, or Network Address Translation, lets all those devices share that one public IP.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!0KlT!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F091d46c7-b6be-48e4-a262-5118b1f57a5a_1870x800.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!0KlT!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F091d46c7-b6be-48e4-a262-5118b1f57a5a_1870x800.png 424w, https://substackcdn.com/image/fetch/$s_!0KlT!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F091d46c7-b6be-48e4-a262-5118b1f57a5a_1870x800.png 848w, https://substackcdn.com/image/fetch/$s_!0KlT!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F091d46c7-b6be-48e4-a262-5118b1f57a5a_1870x800.png 1272w, https://substackcdn.com/image/fetch/$s_!0KlT!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F091d46c7-b6be-48e4-a262-5118b1f57a5a_1870x800.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!0KlT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F091d46c7-b6be-48e4-a262-5118b1f57a5a_1870x800.png" width="711" height="304.22596153846155" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/091d46c7-b6be-48e4-a262-5118b1f57a5a_1870x800.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:623,&quot;width&quot;:1456,&quot;resizeWidth&quot;:711,&quot;bytes&quot;:63669,&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://blog.algomaster.io/i/173399461?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F091d46c7-b6be-48e4-a262-5118b1f57a5a_1870x800.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_!0KlT!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F091d46c7-b6be-48e4-a262-5118b1f57a5a_1870x800.png 424w, https://substackcdn.com/image/fetch/$s_!0KlT!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F091d46c7-b6be-48e4-a262-5118b1f57a5a_1870x800.png 848w, https://substackcdn.com/image/fetch/$s_!0KlT!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F091d46c7-b6be-48e4-a262-5118b1f57a5a_1870x800.png 1272w, https://substackcdn.com/image/fetch/$s_!0KlT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F091d46c7-b6be-48e4-a262-5118b1f57a5a_1870x800.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 your laptop sends a request to the internet, the router replaces the private IP and port with its own public IP and a new port.</p><pre><code><code>192.168.1.10:51234  &#8594;  73.128.42.15:40001
192.168.1.11:49876  &#8594;  73.128.42.15:40002</code></code></pre><p>The router stores this mapping in a NAT table, so when responses come back, it knows which internal device should receive them.</p><p>From the internet&#8217;s point of view, it looks like one machine making many connections.</p><p>NAT helped IPv4 survive the address shortage. It is also one reason peer-to-peer connections are harder, because two devices behind NAT cannot always connect directly without help.</p><div><hr></div><h2>6. DHCP</h2><p>DHCP, or Dynamic Host Configuration Protocol, gives a device its network settings automatically when it joins a network.</p><p>Without DHCP, you would have to manually configure the IP address, subnet mask, default gateway, and DNS server for every device.</p><p>The DHCP flow is often called DORA:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!VDDc!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9ea3390-245a-46d8-92ad-4970d9104843_1130x366.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!VDDc!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9ea3390-245a-46d8-92ad-4970d9104843_1130x366.png 424w, https://substackcdn.com/image/fetch/$s_!VDDc!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9ea3390-245a-46d8-92ad-4970d9104843_1130x366.png 848w, https://substackcdn.com/image/fetch/$s_!VDDc!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9ea3390-245a-46d8-92ad-4970d9104843_1130x366.png 1272w, https://substackcdn.com/image/fetch/$s_!VDDc!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9ea3390-245a-46d8-92ad-4970d9104843_1130x366.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!VDDc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9ea3390-245a-46d8-92ad-4970d9104843_1130x366.png" width="626" height="202.7575221238938" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a9ea3390-245a-46d8-92ad-4970d9104843_1130x366.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:366,&quot;width&quot;:1130,&quot;resizeWidth&quot;:626,&quot;bytes&quot;:32809,&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://blog.algomaster.io/i/173399461?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9ea3390-245a-46d8-92ad-4970d9104843_1130x366.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_!VDDc!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9ea3390-245a-46d8-92ad-4970d9104843_1130x366.png 424w, https://substackcdn.com/image/fetch/$s_!VDDc!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9ea3390-245a-46d8-92ad-4970d9104843_1130x366.png 848w, https://substackcdn.com/image/fetch/$s_!VDDc!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9ea3390-245a-46d8-92ad-4970d9104843_1130x366.png 1272w, https://substackcdn.com/image/fetch/$s_!VDDc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9ea3390-245a-46d8-92ad-4970d9104843_1130x366.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><ul><li><p><strong>Discover: </strong>Client asks, &#8220;Is there an IP for me?&#8221;</p></li><li><p><strong>Offer: </strong>DHCP server offers an available IP</p></li><li><p><strong>Request: </strong>Client asks to use that IP</p></li><li><p><strong>Acknowledge: </strong>Server confirms and records the lease</p></li></ul><p>The IP is usually leased for a limited time. When the lease is close to expiring, the device renews it.</p><div><hr></div><h1>Packets and Layers</h1><h2>7. Packets</h2><p>Data does not travel across a network as one big blob. It is broken into smaller chunks called packets.</p><p>Each packet carries metadata, such as source IP, destination IP, sequence number, and a small part of the actual data.</p><p>Example:</p><pre><code><code>Message: "Hello, this is a long message from the server"

Packet 1: seq=1, data="Hello, thi"
Packet 2: seq=2, data="s is a lon"
Packet 3: seq=3, data="g message "
Packet 4: seq=4, data="from the s"</code></code></pre><p>Packets may take different routes, arrive out of order, or get dropped. The receiving side has to put them back together.</p><p>That is why the transport layer matters.</p><div><hr></div><h2><a href="https://algomaster.io/learn/system-design/osi">8. OSI Model</a></h2><p>The OSI model is a 7-layer mental model for how networking is organized. Real systems often use the simpler TCP/IP model, but OSI is still useful vocabulary.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!LCyS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ad8eecd-270a-44b4-bd17-d22bce3f0b4c_1808x1058.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!LCyS!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ad8eecd-270a-44b4-bd17-d22bce3f0b4c_1808x1058.png 424w, https://substackcdn.com/image/fetch/$s_!LCyS!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ad8eecd-270a-44b4-bd17-d22bce3f0b4c_1808x1058.png 848w, https://substackcdn.com/image/fetch/$s_!LCyS!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ad8eecd-270a-44b4-bd17-d22bce3f0b4c_1808x1058.png 1272w, https://substackcdn.com/image/fetch/$s_!LCyS!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ad8eecd-270a-44b4-bd17-d22bce3f0b4c_1808x1058.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!LCyS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ad8eecd-270a-44b4-bd17-d22bce3f0b4c_1808x1058.png" width="1456" height="852" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4ad8eecd-270a-44b4-bd17-d22bce3f0b4c_1808x1058.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:852,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:153091,&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://blog.algomaster.io/i/173399461?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ad8eecd-270a-44b4-bd17-d22bce3f0b4c_1808x1058.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_!LCyS!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ad8eecd-270a-44b4-bd17-d22bce3f0b4c_1808x1058.png 424w, https://substackcdn.com/image/fetch/$s_!LCyS!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ad8eecd-270a-44b4-bd17-d22bce3f0b4c_1808x1058.png 848w, https://substackcdn.com/image/fetch/$s_!LCyS!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ad8eecd-270a-44b4-bd17-d22bce3f0b4c_1808x1058.png 1272w, https://substackcdn.com/image/fetch/$s_!LCyS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ad8eecd-270a-44b4-bd17-d22bce3f0b4c_1808x1058.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 layer only depends on the layer above and below it. HTTP does not need to know how IP routing works. TCP does not care whether bytes travel over Wi-Fi, Ethernet, or fiber.</p><p>That separation is why you can change the underlying network without rewriting your application.</p><p>For most engineers, layers 3, 4, and 7 matter the most:</p><ul><li><p><strong>Layer 3:</strong> IP and routing</p></li><li><p><strong>Layer 4:</strong> TCP and UDP</p></li><li><p><strong>Layer 7:</strong> HTTP, DNS, and application protocols</p></li></ul><div><hr></div><h2>9. Subnetting and CIDR</h2><p>A subnet is a smaller logical slice of an IP network. Subnetting lets us split one large network into smaller, manageable parts.</p><p>CIDR is the notation used to describe those slices.</p><p><em>Example</em>: <code>192.168.1.0/24</code></p><p>Here, <code>/24</code> means the first 24 bits identify the network. The remaining bits are used for devices inside that network.</p><p>Subnetting is common in cloud networks. For example, you might create a production VPC as <code>10.0.0.0/16</code> and give each availability zone a smaller slice.</p><p>It also makes firewall rules cleaner:</p><pre><code><code>Allow 10.0.1.0/24 to access the database</code></code></pre><p>That is much better than listing hundreds of IP addresses manually.</p><div><hr></div><h2>10. Router vs Switch</h2><p>Routers and switches both move traffic, but they work at different layers.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!FPPn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f3d16b0-cef8-41f7-9dcf-76c343a65cc7_2386x878.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!FPPn!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f3d16b0-cef8-41f7-9dcf-76c343a65cc7_2386x878.png 424w, https://substackcdn.com/image/fetch/$s_!FPPn!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f3d16b0-cef8-41f7-9dcf-76c343a65cc7_2386x878.png 848w, https://substackcdn.com/image/fetch/$s_!FPPn!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f3d16b0-cef8-41f7-9dcf-76c343a65cc7_2386x878.png 1272w, https://substackcdn.com/image/fetch/$s_!FPPn!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f3d16b0-cef8-41f7-9dcf-76c343a65cc7_2386x878.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!FPPn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f3d16b0-cef8-41f7-9dcf-76c343a65cc7_2386x878.png" width="1456" height="536" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4f3d16b0-cef8-41f7-9dcf-76c343a65cc7_2386x878.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;: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://blog.algomaster.io/i/173399461?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f3d16b0-cef8-41f7-9dcf-76c343a65cc7_2386x878.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_!FPPn!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f3d16b0-cef8-41f7-9dcf-76c343a65cc7_2386x878.png 424w, https://substackcdn.com/image/fetch/$s_!FPPn!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f3d16b0-cef8-41f7-9dcf-76c343a65cc7_2386x878.png 848w, https://substackcdn.com/image/fetch/$s_!FPPn!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f3d16b0-cef8-41f7-9dcf-76c343a65cc7_2386x878.png 1272w, https://substackcdn.com/image/fetch/$s_!FPPn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f3d16b0-cef8-41f7-9dcf-76c343a65cc7_2386x878.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 <strong>switch</strong> works at layer 2. It connects devices inside the same local network and forwards data using MAC addresses.</p><p>A <strong>router</strong> works at layer 3. It connects different networks and forwards packets using IP addresses.</p><p>Your home router is usually a router, switch, and Wi-Fi access point combined in one box.</p><p>Switches keep local traffic fast. Routers decide where packets should go next, including across the internet.</p><div><hr></div><h1>Protocols</h1><h2><a href="https://algomaster.io/learn/system-design/tcp-vs-udp">11. TCP vs UDP</a></h2><p>At the transport layer, the two most common protocols are TCP and UDP.</p><p><strong>TCP</strong> is reliable. It creates a connection before sending data, tracks what was sent, retries lost data, and delivers everything in order.</p><p>Use TCP when correctness matters: web pages, APIs, databases, SSH, and file transfers.</p><p><strong>UDP</strong> is lighter and faster. It sends data without creating a connection, and it does not guarantee delivery or ordering.</p><p>Use UDP when low latency matters more than perfect reliability: video calls, DNS, online gaming, and live telemetry.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!oiYJ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bbb67d1-a4e0-46e4-9031-e9a9f0230f65_865x379.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!oiYJ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bbb67d1-a4e0-46e4-9031-e9a9f0230f65_865x379.png 424w, https://substackcdn.com/image/fetch/$s_!oiYJ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bbb67d1-a4e0-46e4-9031-e9a9f0230f65_865x379.png 848w, https://substackcdn.com/image/fetch/$s_!oiYJ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bbb67d1-a4e0-46e4-9031-e9a9f0230f65_865x379.png 1272w, https://substackcdn.com/image/fetch/$s_!oiYJ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bbb67d1-a4e0-46e4-9031-e9a9f0230f65_865x379.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!oiYJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bbb67d1-a4e0-46e4-9031-e9a9f0230f65_865x379.png" width="865" height="379" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7bbb67d1-a4e0-46e4-9031-e9a9f0230f65_865x379.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:379,&quot;width&quot;:865,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:52641,&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://blog.algomaster.io/i/173399461?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bbb67d1-a4e0-46e4-9031-e9a9f0230f65_865x379.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_!oiYJ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bbb67d1-a4e0-46e4-9031-e9a9f0230f65_865x379.png 424w, https://substackcdn.com/image/fetch/$s_!oiYJ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bbb67d1-a4e0-46e4-9031-e9a9f0230f65_865x379.png 848w, https://substackcdn.com/image/fetch/$s_!oiYJ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bbb67d1-a4e0-46e4-9031-e9a9f0230f65_865x379.png 1272w, https://substackcdn.com/image/fetch/$s_!oiYJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bbb67d1-a4e0-46e4-9031-e9a9f0230f65_865x379.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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>Modern protocols like QUIC, used by HTTP/3, are built on UDP. They keep UDP&#8217;s speed benefits while adding reliability at the protocol level.</p><div><hr></div><h2><a href="https://algomaster.io/learn/system-design/http-https">12. HTTP / HTTPS</a></h2><p>HTTP is the request-response protocol behind the web.</p><p>A client sends a request. The server sends back a response with a status code, headers, and a body.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!z5pg!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62a6bc10-52c7-4ac2-a586-ad403bb119d0_1774x670.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!z5pg!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62a6bc10-52c7-4ac2-a586-ad403bb119d0_1774x670.png 424w, https://substackcdn.com/image/fetch/$s_!z5pg!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62a6bc10-52c7-4ac2-a586-ad403bb119d0_1774x670.png 848w, https://substackcdn.com/image/fetch/$s_!z5pg!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62a6bc10-52c7-4ac2-a586-ad403bb119d0_1774x670.png 1272w, https://substackcdn.com/image/fetch/$s_!z5pg!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62a6bc10-52c7-4ac2-a586-ad403bb119d0_1774x670.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!z5pg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62a6bc10-52c7-4ac2-a586-ad403bb119d0_1774x670.png" width="1456" height="550" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/62a6bc10-52c7-4ac2-a586-ad403bb119d0_1774x670.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:550,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:105181,&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://blog.algomaster.io/i/173399461?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62a6bc10-52c7-4ac2-a586-ad403bb119d0_1774x670.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_!z5pg!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62a6bc10-52c7-4ac2-a586-ad403bb119d0_1774x670.png 424w, https://substackcdn.com/image/fetch/$s_!z5pg!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62a6bc10-52c7-4ac2-a586-ad403bb119d0_1774x670.png 848w, https://substackcdn.com/image/fetch/$s_!z5pg!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62a6bc10-52c7-4ac2-a586-ad403bb119d0_1774x670.png 1272w, https://substackcdn.com/image/fetch/$s_!z5pg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62a6bc10-52c7-4ac2-a586-ad403bb119d0_1774x670.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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>HTTP is stateless. Each request is independent, so cookies, sessions, and tokens are used to remember who the user is between requests.</p><p>HTTPS is HTTP over TLS.</p><p>The request format stays mostly the same, but the connection is encrypted and the server&#8217;s identity is verified.</p><p>For public websites and APIs, HTTPS is the default today. Plain HTTP should be treated as the exception.</p><div><hr></div><h2><a href="https://algomaster.io/learn/system-design/ssl-tls">13. TLS</a></h2><p>TLS, or Transport Layer Security, is what puts the <strong>S</strong> in HTTPS.</p><p>It gives HTTPS three important guarantees:</p><ul><li><p><strong>Confidentiality: </strong>Others cannot read the data</p></li><li><p><strong>Integrity: </strong>Data cannot be silently changed in transit</p></li><li><p><strong>Authenticity: </strong>The server is really who it claims to be</p></li></ul><p>At a high level, the TLS handshake works 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_!t4CM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ba3879b-2fc1-48d4-8152-6191c4710c0f_1652x1040.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!t4CM!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ba3879b-2fc1-48d4-8152-6191c4710c0f_1652x1040.png 424w, https://substackcdn.com/image/fetch/$s_!t4CM!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ba3879b-2fc1-48d4-8152-6191c4710c0f_1652x1040.png 848w, https://substackcdn.com/image/fetch/$s_!t4CM!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ba3879b-2fc1-48d4-8152-6191c4710c0f_1652x1040.png 1272w, https://substackcdn.com/image/fetch/$s_!t4CM!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ba3879b-2fc1-48d4-8152-6191c4710c0f_1652x1040.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!t4CM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ba3879b-2fc1-48d4-8152-6191c4710c0f_1652x1040.png" width="662" height="416.9326923076923" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9ba3879b-2fc1-48d4-8152-6191c4710c0f_1652x1040.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:917,&quot;width&quot;:1456,&quot;resizeWidth&quot;:662,&quot;bytes&quot;:67988,&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://blog.algomaster.io/i/173399461?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ba3879b-2fc1-48d4-8152-6191c4710c0f_1652x1040.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_!t4CM!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ba3879b-2fc1-48d4-8152-6191c4710c0f_1652x1040.png 424w, https://substackcdn.com/image/fetch/$s_!t4CM!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ba3879b-2fc1-48d4-8152-6191c4710c0f_1652x1040.png 848w, https://substackcdn.com/image/fetch/$s_!t4CM!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ba3879b-2fc1-48d4-8152-6191c4710c0f_1652x1040.png 1272w, https://substackcdn.com/image/fetch/$s_!t4CM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ba3879b-2fc1-48d4-8152-6191c4710c0f_1652x1040.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 server certificate is signed by a trusted Certificate Authority. The browser verifies it before trusting the connection.</p><p>After the handshake, both sides use fast symmetric encryption for the actual data transfer.</p><p>TLS 1.3 made this process much faster by reducing the number of round trips. With session resumption, repeat connections can be even faster.</p><div><hr></div><h2><a href="https://algomaster.io/learn/system-design/websockets">14. WebSocket</a></h2><p>HTTP is request-response. The client asks, the server replies.</p><p>That works well for normal web pages and APIs, but not for apps where the server needs to push updates instantly, like chat, live scores, trading dashboards, multiplayer games, or collaborative editing.</p><p>A WebSocket is a persistent, two-way connection between a client and server.</p><p>It starts as an HTTP request and then upgrades to a WebSocket connection:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!sTM9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93c0c804-4a89-49b7-9268-247f44fc63c0_1348x1606.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!sTM9!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93c0c804-4a89-49b7-9268-247f44fc63c0_1348x1606.png 424w, https://substackcdn.com/image/fetch/$s_!sTM9!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93c0c804-4a89-49b7-9268-247f44fc63c0_1348x1606.png 848w, https://substackcdn.com/image/fetch/$s_!sTM9!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93c0c804-4a89-49b7-9268-247f44fc63c0_1348x1606.png 1272w, https://substackcdn.com/image/fetch/$s_!sTM9!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93c0c804-4a89-49b7-9268-247f44fc63c0_1348x1606.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!sTM9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93c0c804-4a89-49b7-9268-247f44fc63c0_1348x1606.png" width="650" height="774.406528189911" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/93c0c804-4a89-49b7-9268-247f44fc63c0_1348x1606.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1606,&quot;width&quot;:1348,&quot;resizeWidth&quot;:650,&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_!sTM9!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93c0c804-4a89-49b7-9268-247f44fc63c0_1348x1606.png 424w, https://substackcdn.com/image/fetch/$s_!sTM9!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93c0c804-4a89-49b7-9268-247f44fc63c0_1348x1606.png 848w, https://substackcdn.com/image/fetch/$s_!sTM9!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93c0c804-4a89-49b7-9268-247f44fc63c0_1348x1606.png 1272w, https://substackcdn.com/image/fetch/$s_!sTM9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93c0c804-4a89-49b7-9268-247f44fc63c0_1348x1606.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 the upgrade, both sides can send messages anytime without creating a new HTTP request for every update.</p><p>Use WebSockets when you need real-time, two-way communication.</p><p>For one-way server-to-client updates, Server-Sent Events, or SSE, is often a simpler option.</p><div><hr></div><h1>Infrastructure</h1><h2>15. Firewall</h2><p>A firewall controls which network traffic is allowed in or out.</p><p>It checks traffic against rules based on fields like source IP, destination IP, port, and protocol.</p><pre><code><code>ALLOW tcp from any to 10.0.1.0/24 port 443
ALLOW tcp from 10.0.0.0/16 to 10.0.2.10 port 5432
DENY  all from any to any</code></code></pre><p>The last rule is important: block everything that is not explicitly allowed.</p><p>Firewalls can be <strong>stateful</strong> or <strong>stateless</strong>.</p><p>A stateful firewall tracks active connections. If your server sends a request out, the response is allowed back in automatically.</p><p>A stateless firewall checks each packet independently. It is simpler, but less flexible.</p><p>In cloud platforms, you usually see firewalls as security groups in AWS, NSGs in Azure, or firewall rules in GCP.</p><div><hr></div><h2>16. VPN</h2><p>A VPN, or Virtual Private Network, creates an encrypted tunnel over the public internet.</p><p>It makes a remote device behave as if it is connected to a private network.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!kwOn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8926c347-f422-4301-856f-dfea0598d351_1910x372.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!kwOn!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8926c347-f422-4301-856f-dfea0598d351_1910x372.png 424w, https://substackcdn.com/image/fetch/$s_!kwOn!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8926c347-f422-4301-856f-dfea0598d351_1910x372.png 848w, https://substackcdn.com/image/fetch/$s_!kwOn!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8926c347-f422-4301-856f-dfea0598d351_1910x372.png 1272w, https://substackcdn.com/image/fetch/$s_!kwOn!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8926c347-f422-4301-856f-dfea0598d351_1910x372.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!kwOn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8926c347-f422-4301-856f-dfea0598d351_1910x372.png" width="684" height="133.41758241758242" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8926c347-f422-4301-856f-dfea0598d351_1910x372.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:284,&quot;width&quot;:1456,&quot;resizeWidth&quot;:684,&quot;bytes&quot;:36551,&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://blog.algomaster.io/i/173399461?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8926c347-f422-4301-856f-dfea0598d351_1910x372.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_!kwOn!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8926c347-f422-4301-856f-dfea0598d351_1910x372.png 424w, https://substackcdn.com/image/fetch/$s_!kwOn!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8926c347-f422-4301-856f-dfea0598d351_1910x372.png 848w, https://substackcdn.com/image/fetch/$s_!kwOn!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8926c347-f422-4301-856f-dfea0598d351_1910x372.png 1272w, https://substackcdn.com/image/fetch/$s_!kwOn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8926c347-f422-4301-856f-dfea0598d351_1910x372.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Two common use cases:</p><ul><li><p><strong>Corporate VPN: </strong>Lets employees access internal company systems from outside the office</p></li><li><p><strong>Consumer VPN: </strong>Routes traffic through a VPN provider to hide the user&#8217;s public IP or change apparent location</p></li></ul><p>VPNs are built using protocols like WireGuard, OpenVPN, or IPsec.</p><p>The key idea is simple: traffic goes through an encrypted tunnel before reaching the destination.</p><p>But a VPN does not make you fully anonymous. The VPN provider can still see where your traffic is going, so you are shifting trust from your ISP or network provider to the VPN provider.</p><div><hr></div><h2><a href="https://algomaster.io/learn/system-design/proxy-vs-reverse-proxy">17. Proxy vs Reverse Proxy</a></h2><p>A proxy sits between a client and a server. The difference is which side it represents.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!lXB_!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c475909-b189-4bc0-a505-d2e5bc16f03f_892x908.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!lXB_!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c475909-b189-4bc0-a505-d2e5bc16f03f_892x908.png 424w, https://substackcdn.com/image/fetch/$s_!lXB_!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c475909-b189-4bc0-a505-d2e5bc16f03f_892x908.png 848w, https://substackcdn.com/image/fetch/$s_!lXB_!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c475909-b189-4bc0-a505-d2e5bc16f03f_892x908.png 1272w, https://substackcdn.com/image/fetch/$s_!lXB_!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c475909-b189-4bc0-a505-d2e5bc16f03f_892x908.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!lXB_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c475909-b189-4bc0-a505-d2e5bc16f03f_892x908.png" width="502" height="511.00448430493276" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7c475909-b189-4bc0-a505-d2e5bc16f03f_892x908.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:908,&quot;width&quot;:892,&quot;resizeWidth&quot;:502,&quot;bytes&quot;:249040,&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://blog.algomaster.io/i/173399461?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c475909-b189-4bc0-a505-d2e5bc16f03f_892x908.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_!lXB_!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c475909-b189-4bc0-a505-d2e5bc16f03f_892x908.png 424w, https://substackcdn.com/image/fetch/$s_!lXB_!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c475909-b189-4bc0-a505-d2e5bc16f03f_892x908.png 848w, https://substackcdn.com/image/fetch/$s_!lXB_!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c475909-b189-4bc0-a505-d2e5bc16f03f_892x908.png 1272w, https://substackcdn.com/image/fetch/$s_!lXB_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c475909-b189-4bc0-a505-d2e5bc16f03f_892x908.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 <strong>forward proxy</strong> sits in front of clients. It forwards client requests to the internet.</p><p>Companies use forward proxies for content filtering, caching, and hiding internal IPs.</p><p>A <strong>reverse proxy</strong> sits in front of servers. Clients send requests to the reverse proxy, and it forwards them to the right backend server.</p><p>Reverse proxies are common in production systems. They can terminate TLS, cache responses, rate-limit clients, and route traffic to different backend services.</p><p>Tools like Nginx, HAProxy, Envoy, and Cloudflare often work as reverse proxies.</p><div><hr></div><h2><a href="https://algomaster.io/learn/system-design/load-balancers">18. Load Balancer</a></h2><p>Once you have multiple backend servers, you need a way to spread traffic across them. That is what a load balancer does.</p><p>A load balancer is usually a reverse proxy that decides which backend should handle each request.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!SvwJ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F555c4580-aba8-48e3-9bbd-f14e3372e898_1304x1044.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!SvwJ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F555c4580-aba8-48e3-9bbd-f14e3372e898_1304x1044.png 424w, https://substackcdn.com/image/fetch/$s_!SvwJ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F555c4580-aba8-48e3-9bbd-f14e3372e898_1304x1044.png 848w, https://substackcdn.com/image/fetch/$s_!SvwJ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F555c4580-aba8-48e3-9bbd-f14e3372e898_1304x1044.png 1272w, https://substackcdn.com/image/fetch/$s_!SvwJ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F555c4580-aba8-48e3-9bbd-f14e3372e898_1304x1044.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!SvwJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F555c4580-aba8-48e3-9bbd-f14e3372e898_1304x1044.png" width="544" height="435.53374233128835" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/555c4580-aba8-48e3-9bbd-f14e3372e898_1304x1044.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1044,&quot;width&quot;:1304,&quot;resizeWidth&quot;:544,&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_!SvwJ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F555c4580-aba8-48e3-9bbd-f14e3372e898_1304x1044.png 424w, https://substackcdn.com/image/fetch/$s_!SvwJ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F555c4580-aba8-48e3-9bbd-f14e3372e898_1304x1044.png 848w, https://substackcdn.com/image/fetch/$s_!SvwJ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F555c4580-aba8-48e3-9bbd-f14e3372e898_1304x1044.png 1272w, https://substackcdn.com/image/fetch/$s_!SvwJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F555c4580-aba8-48e3-9bbd-f14e3372e898_1304x1044.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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>Common algorithms:</p><ul><li><p><strong>Round robin:</strong> Send each request to the next server</p></li><li><p><strong>Least connections: </strong>Send traffic to the server with the fewest active connections</p></li><li><p><strong>IP hash: </strong>Send the same client IP to the same server</p></li><li><p><strong>Weighted: </strong>Send more traffic to stronger servers</p></li></ul><p>Load balancers also run health checks. If a server stops responding, the load balancer removes it from rotation and sends traffic to healthy servers.</p><p>This is how one bad instance does not bring down the whole service.</p><div><hr></div><h2><a href="https://algomaster.io/learn/system-design/content-delivery-network-cdn">19. CDN</a></h2><p>A CDN, or Content Delivery Network, is a group of servers spread across the world that cache content close to users.</p><p>Instead of every request going back to the origin server, the CDN serves cached content from a nearby edge location.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!L2Hz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc9ca64fe-1511-493e-8f3c-eba3a162ea59_2202x1048.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!L2Hz!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc9ca64fe-1511-493e-8f3c-eba3a162ea59_2202x1048.png 424w, https://substackcdn.com/image/fetch/$s_!L2Hz!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc9ca64fe-1511-493e-8f3c-eba3a162ea59_2202x1048.png 848w, https://substackcdn.com/image/fetch/$s_!L2Hz!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc9ca64fe-1511-493e-8f3c-eba3a162ea59_2202x1048.png 1272w, https://substackcdn.com/image/fetch/$s_!L2Hz!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc9ca64fe-1511-493e-8f3c-eba3a162ea59_2202x1048.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!L2Hz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc9ca64fe-1511-493e-8f3c-eba3a162ea59_2202x1048.png" width="1456" height="693" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c9ca64fe-1511-493e-8f3c-eba3a162ea59_2202x1048.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:693,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:376899,&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://blog.algomaster.io/i/173399461?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc9ca64fe-1511-493e-8f3c-eba3a162ea59_2202x1048.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_!L2Hz!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc9ca64fe-1511-493e-8f3c-eba3a162ea59_2202x1048.png 424w, https://substackcdn.com/image/fetch/$s_!L2Hz!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc9ca64fe-1511-493e-8f3c-eba3a162ea59_2202x1048.png 848w, https://substackcdn.com/image/fetch/$s_!L2Hz!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc9ca64fe-1511-493e-8f3c-eba3a162ea59_2202x1048.png 1272w, https://substackcdn.com/image/fetch/$s_!L2Hz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc9ca64fe-1511-493e-8f3c-eba3a162ea59_2202x1048.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 reduces latency because data travels a shorter distance.</p><p>CDNs are commonly used for static assets like images, CSS, JavaScript, and video. Modern CDNs can also cache API responses, terminate TLS, run edge functions, and help absorb DDoS attacks.</p><div><hr></div><h1>Performance</h1><h2><a href="https://algomaster.io/learn/system-design/latency-vs-throughput">20. Latency vs Bandwidth vs Throughput</a></h2><p>Latency, bandwidth, and throughput are often mixed up, but they mean different things.</p><ul><li><p><strong>Latency: </strong>How long one packet takes to travel from source to destination</p></li><li><p><strong>Bandwidth: </strong>The maximum amount of data a network can carry per second</p></li><li><p><strong>Throughput: </strong>The actual amount of data transferred per second</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_!vJmu!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc4c2bdf-e21f-48f7-9a8e-bda98027d668_988x1038.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!vJmu!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc4c2bdf-e21f-48f7-9a8e-bda98027d668_988x1038.png 424w, https://substackcdn.com/image/fetch/$s_!vJmu!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc4c2bdf-e21f-48f7-9a8e-bda98027d668_988x1038.png 848w, https://substackcdn.com/image/fetch/$s_!vJmu!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc4c2bdf-e21f-48f7-9a8e-bda98027d668_988x1038.png 1272w, https://substackcdn.com/image/fetch/$s_!vJmu!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc4c2bdf-e21f-48f7-9a8e-bda98027d668_988x1038.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!vJmu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc4c2bdf-e21f-48f7-9a8e-bda98027d668_988x1038.png" width="642" height="674.4898785425102" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bc4c2bdf-e21f-48f7-9a8e-bda98027d668_988x1038.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1038,&quot;width&quot;:988,&quot;resizeWidth&quot;:642,&quot;bytes&quot;:557836,&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://blog.algomaster.io/i/173399461?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc4c2bdf-e21f-48f7-9a8e-bda98027d668_988x1038.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_!vJmu!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc4c2bdf-e21f-48f7-9a8e-bda98027d668_988x1038.png 424w, https://substackcdn.com/image/fetch/$s_!vJmu!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc4c2bdf-e21f-48f7-9a8e-bda98027d668_988x1038.png 848w, https://substackcdn.com/image/fetch/$s_!vJmu!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc4c2bdf-e21f-48f7-9a8e-bda98027d668_988x1038.png 1272w, https://substackcdn.com/image/fetch/$s_!vJmu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc4c2bdf-e21f-48f7-9a8e-bda98027d668_988x1038.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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>More bandwidth does not always reduce latency.</p><p>A 1 Gbps connection can still feel slow if the server is on the other side of the world.</p><p>In system design:</p><ul><li><p>Caches and CDNs reduce latency.</p></li><li><p>More servers and network capacity increase bandwidth.</p></li><li><p>Compression, fewer round trips, and better protocols improve throughput.</p></li></ul><p>Good systems optimize all three, but they are not the same thing.</p><div><hr></div><p>Thank you for reading!</p>]]></content:encoded></item><item><title><![CDATA[A deep dive into the Transformer architecture]]></title><description><![CDATA[A single 2017 research paper changed the future of AI forever and gave rise to multiple unicorn companies.]]></description><link>https://blog.algomaster.io/p/transformer-architecture</link><guid isPermaLink="false">https://blog.algomaster.io/p/transformer-architecture</guid><dc:creator><![CDATA[Ashish Pratap Singh]]></dc:creator><pubDate>Thu, 14 May 2026 04:15:11 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!pTOn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26a59b2f-b4fb-4737-8259-0eeec934908f_2500x830.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>A single 2017 research paper changed the future of AI forever and gave rise to multiple unicorn companies.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!SO_7!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff101a1da-b4df-4193-b4da-a60a41a646c6_1852x1032.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!SO_7!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff101a1da-b4df-4193-b4da-a60a41a646c6_1852x1032.jpeg 424w, https://substackcdn.com/image/fetch/$s_!SO_7!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff101a1da-b4df-4193-b4da-a60a41a646c6_1852x1032.jpeg 848w, https://substackcdn.com/image/fetch/$s_!SO_7!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff101a1da-b4df-4193-b4da-a60a41a646c6_1852x1032.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!SO_7!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff101a1da-b4df-4193-b4da-a60a41a646c6_1852x1032.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!SO_7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff101a1da-b4df-4193-b4da-a60a41a646c6_1852x1032.jpeg" width="1456" height="811" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f101a1da-b4df-4193-b4da-a60a41a646c6_1852x1032.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:811,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Image&quot;,&quot;title&quot;:&quot;Image&quot;,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Image" title="Image" srcset="https://substackcdn.com/image/fetch/$s_!SO_7!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff101a1da-b4df-4193-b4da-a60a41a646c6_1852x1032.jpeg 424w, https://substackcdn.com/image/fetch/$s_!SO_7!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff101a1da-b4df-4193-b4da-a60a41a646c6_1852x1032.jpeg 848w, https://substackcdn.com/image/fetch/$s_!SO_7!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff101a1da-b4df-4193-b4da-a60a41a646c6_1852x1032.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!SO_7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff101a1da-b4df-4193-b4da-a60a41a646c6_1852x1032.jpeg 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://x.com/nathanbenaich/status/1524029269617295361/photo/1">Source</a></figcaption></figure></div><p>This paper, titled &#8216;<em><a href="https://arxiv.org/abs/1706.03762">Attention Is All You Need&#8217;</a></em>, introduced the Transformer architecture that powers all frontier LLMs of today. In this lesson, we will simply understand how this architecture works and enables LLMs to understand language so well.</p><div><hr></div><h3><strong>The birth of Transformers</strong></h3><p>The <em><a href="https://arxiv.org/abs/1706.03762">Attention Is All You Need</a> </em>paper introduced the Transformer architecture for language translation tasks. It consisted of:</p><ul><li><p><strong>Encoder block</strong>: That accepts an input to be translated</p></li><li><p><strong>Decoder block</strong>: That returns the translated input as an output</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_!KdOI!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe67add14-274e-438d-b5a9-961298dcad3e_2460x796.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!KdOI!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe67add14-274e-438d-b5a9-961298dcad3e_2460x796.png 424w, https://substackcdn.com/image/fetch/$s_!KdOI!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe67add14-274e-438d-b5a9-961298dcad3e_2460x796.png 848w, https://substackcdn.com/image/fetch/$s_!KdOI!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe67add14-274e-438d-b5a9-961298dcad3e_2460x796.png 1272w, https://substackcdn.com/image/fetch/$s_!KdOI!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe67add14-274e-438d-b5a9-961298dcad3e_2460x796.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!KdOI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe67add14-274e-438d-b5a9-961298dcad3e_2460x796.png" width="1456" height="471" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e67add14-274e-438d-b5a9-961298dcad3e_2460x796.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:471,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:126188,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.intoai.pub/i/196130098?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe67add14-274e-438d-b5a9-961298dcad3e_2460x796.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_!KdOI!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe67add14-274e-438d-b5a9-961298dcad3e_2460x796.png 424w, https://substackcdn.com/image/fetch/$s_!KdOI!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe67add14-274e-438d-b5a9-961298dcad3e_2460x796.png 848w, https://substackcdn.com/image/fetch/$s_!KdOI!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe67add14-274e-438d-b5a9-961298dcad3e_2460x796.png 1272w, https://substackcdn.com/image/fetch/$s_!KdOI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe67add14-274e-438d-b5a9-961298dcad3e_2460x796.png 1456w" sizes="100vw"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Transformer architecture with an Encoder and Decoder block for Hindi to English translation. Each Encoder and Decoder block consists of 6 identical Encoders and Decoders, respectively.</figcaption></figure></div><p>This architecture was modified for text generation tasks. This involved removing the Encoder and adopting a <strong>Decoder-only</strong> <strong>architecture</strong>. This Decoder-only transformer is the one that is used by modern LLMs.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!lopa!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a56e15c-8f6a-4603-9e1b-83295ea93ee8_2034x754.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!lopa!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a56e15c-8f6a-4603-9e1b-83295ea93ee8_2034x754.png 424w, https://substackcdn.com/image/fetch/$s_!lopa!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a56e15c-8f6a-4603-9e1b-83295ea93ee8_2034x754.png 848w, https://substackcdn.com/image/fetch/$s_!lopa!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a56e15c-8f6a-4603-9e1b-83295ea93ee8_2034x754.png 1272w, https://substackcdn.com/image/fetch/$s_!lopa!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a56e15c-8f6a-4603-9e1b-83295ea93ee8_2034x754.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!lopa!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a56e15c-8f6a-4603-9e1b-83295ea93ee8_2034x754.png" width="1456" height="540" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2a56e15c-8f6a-4603-9e1b-83295ea93ee8_2034x754.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:540,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:88398,&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/196130098?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a56e15c-8f6a-4603-9e1b-83295ea93ee8_2034x754.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_!lopa!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a56e15c-8f6a-4603-9e1b-83295ea93ee8_2034x754.png 424w, https://substackcdn.com/image/fetch/$s_!lopa!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a56e15c-8f6a-4603-9e1b-83295ea93ee8_2034x754.png 848w, https://substackcdn.com/image/fetch/$s_!lopa!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a56e15c-8f6a-4603-9e1b-83295ea93ee8_2034x754.png 1272w, https://substackcdn.com/image/fetch/$s_!lopa!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a56e15c-8f6a-4603-9e1b-83295ea93ee8_2034x754.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 learn what components make the Decoder-only Transformer so impressive.</p><div><hr></div><h3><strong>The components of the Decoder-only Transformer</strong></h3><p>A Decoder-only Transformer is composed of multiple identical Decoders stacked on top of each other (the output of one is passed as input to the next).</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!pTOn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26a59b2f-b4fb-4737-8259-0eeec934908f_2500x830.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!pTOn!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26a59b2f-b4fb-4737-8259-0eeec934908f_2500x830.png 424w, https://substackcdn.com/image/fetch/$s_!pTOn!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26a59b2f-b4fb-4737-8259-0eeec934908f_2500x830.png 848w, https://substackcdn.com/image/fetch/$s_!pTOn!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26a59b2f-b4fb-4737-8259-0eeec934908f_2500x830.png 1272w, https://substackcdn.com/image/fetch/$s_!pTOn!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26a59b2f-b4fb-4737-8259-0eeec934908f_2500x830.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!pTOn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26a59b2f-b4fb-4737-8259-0eeec934908f_2500x830.png" width="725.203125" height="240.57219050480768" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/26a59b2f-b4fb-4737-8259-0eeec934908f_2500x830.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:483,&quot;width&quot;:1456,&quot;resizeWidth&quot;:725.203125,&quot;bytes&quot;:131258,&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/196130098?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26a59b2f-b4fb-4737-8259-0eeec934908f_2500x830.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:&quot;center&quot;,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!pTOn!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26a59b2f-b4fb-4737-8259-0eeec934908f_2500x830.png 424w, https://substackcdn.com/image/fetch/$s_!pTOn!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26a59b2f-b4fb-4737-8259-0eeec934908f_2500x830.png 848w, https://substackcdn.com/image/fetch/$s_!pTOn!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26a59b2f-b4fb-4737-8259-0eeec934908f_2500x830.png 1272w, https://substackcdn.com/image/fetch/$s_!pTOn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26a59b2f-b4fb-4737-8259-0eeec934908f_2500x830.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 Decoder consists of 4 components:</p><ol><li><p>Causal (or Masked) Multi-Head Self-Attention</p></li><li><p>Feed-Forward Network</p></li><li><p>Layer Normalization</p></li><li><p>Residual or Skip connections</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_!p-A7!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe71295eb-22d4-41a0-98eb-353baa8d30e4_2636x928.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!p-A7!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe71295eb-22d4-41a0-98eb-353baa8d30e4_2636x928.png 424w, https://substackcdn.com/image/fetch/$s_!p-A7!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe71295eb-22d4-41a0-98eb-353baa8d30e4_2636x928.png 848w, https://substackcdn.com/image/fetch/$s_!p-A7!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe71295eb-22d4-41a0-98eb-353baa8d30e4_2636x928.png 1272w, https://substackcdn.com/image/fetch/$s_!p-A7!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe71295eb-22d4-41a0-98eb-353baa8d30e4_2636x928.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!p-A7!,w_2400,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe71295eb-22d4-41a0-98eb-353baa8d30e4_2636x928.png" width="1200" height="422.8021978021978" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e71295eb-22d4-41a0-98eb-353baa8d30e4_2636x928.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;large&quot;,&quot;height&quot;:513,&quot;width&quot;:1456,&quot;resizeWidth&quot;:1200,&quot;bytes&quot;:133875,&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/196130098?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe71295eb-22d4-41a0-98eb-353baa8d30e4_2636x928.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_!p-A7!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe71295eb-22d4-41a0-98eb-353baa8d30e4_2636x928.png 424w, https://substackcdn.com/image/fetch/$s_!p-A7!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe71295eb-22d4-41a0-98eb-353baa8d30e4_2636x928.png 848w, https://substackcdn.com/image/fetch/$s_!p-A7!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe71295eb-22d4-41a0-98eb-353baa8d30e4_2636x928.png 1272w, https://substackcdn.com/image/fetch/$s_!p-A7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe71295eb-22d4-41a0-98eb-353baa8d30e4_2636x928.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 above architecture is from <a href="https://cdn.openai.com/research-covers/language-unsupervised/language_understanding_paper.pdf">GPT-1, published in 2018</a>. Since then, it has been seen that applying Layer Normalization before Causal Multi-Head Self-Attention and Feed-Forward Network, an architecture pattern called <strong>Pre-LayerNorm</strong>, leads to better training performance. Hence, modern LLMs use the Pre-LayerNorm architecture.</p><p>Let&#8217;s learn the role of each of these components in detail next.</p><div><hr></div><h3><strong>1. Causal (or Masked) Multi-Head Self-Attention</strong></h3><p>Attention helps a model learn dependencies between different tokens so that it can understand context, syntax, and semantics in text well.</p><p>The term &#8220;Causal (or Masked) Multi-Head Self-Attention&#8221; is understood better when we break it down into parts as follows:</p><ul><li><p><strong>Attention: </strong>This general architecture allows tokens across different text sequences to focus on one another.</p></li><li><p><strong>Self-Attention: </strong>This is when Attention is applied in a way that lets tokens in the same text sequence focus on each other.</p></li><li><p><strong>Multi-Head Self-Attention: </strong>This architecture extends Self-Attention by using multiple parallel Self-Attention blocks (heads), rather than a single one. This helps it to better learn different types of semantic relationships within the input text sequence.</p></li><li><p><strong>Causal (or Masked) Multi-Head Self-Attention</strong></p><p>Decoder-only Transformer based LLMs generate text tokens one at a time, keeping past tokens as context at each step of generation.</p><p><br>During training, for a given input sequence, they must learn to generate each token based on previous tokens, without peeking at future tokens.<br><br>Consider this training text sequence: <code>&#8220;The sky is blue&#8221;</code></p><p><br>During training to generate the token &#8220;<code>is</code>&#8220;, the model can learn to generate it from both the past tokens (&#8221;<code>The</code>&#8220; and &#8220;<code>sky</code>&#8220;) and future ones (&#8221;<code>blue</code>&#8220;).</p><p><br>During generation, since the model has no access to future tokens (it hasn&#8217;t generated them yet), it can&#8217;t use the strategy of generating text from them, leading it to perform poorly. Hence, we need an Attention mechanism that can mask future tokens during training.</p><p>This is made possible using the Causal or Masked Multi-Head Self-Attention, which ensures that each token in the training sequence can attend only to previous tokens and itself, not to future tokens.</p></li></ul><p>Each of these attention mechanisms is <strong>Scaled dot-product attention</strong>, mathematically, as shown below.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!gQAy!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c0690b2-c8ae-40f0-bf34-072ccb946e77_1080x1080.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!gQAy!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c0690b2-c8ae-40f0-bf34-072ccb946e77_1080x1080.png 424w, https://substackcdn.com/image/fetch/$s_!gQAy!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c0690b2-c8ae-40f0-bf34-072ccb946e77_1080x1080.png 848w, https://substackcdn.com/image/fetch/$s_!gQAy!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c0690b2-c8ae-40f0-bf34-072ccb946e77_1080x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!gQAy!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c0690b2-c8ae-40f0-bf34-072ccb946e77_1080x1080.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!gQAy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c0690b2-c8ae-40f0-bf34-072ccb946e77_1080x1080.png" width="1080" height="1080" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3c0690b2-c8ae-40f0-bf34-072ccb946e77_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;: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_!gQAy!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c0690b2-c8ae-40f0-bf34-072ccb946e77_1080x1080.png 424w, https://substackcdn.com/image/fetch/$s_!gQAy!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c0690b2-c8ae-40f0-bf34-072ccb946e77_1080x1080.png 848w, https://substackcdn.com/image/fetch/$s_!gQAy!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c0690b2-c8ae-40f0-bf34-072ccb946e77_1080x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!gQAy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c0690b2-c8ae-40f0-bf34-072ccb946e77_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><figcaption class="image-caption"><a href="https://gumroad.com/a/440621971/yasxkv">Source</a></figcaption></figure></div><p>The internals of the <a href="https://www.intoai.pub/p/causal-mha">Causal multi-head self-attention mechanism</a> are shown below.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!qKoX!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d81719a-8a4b-43bc-86ef-27648da7f3eb_2722x1136.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!qKoX!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d81719a-8a4b-43bc-86ef-27648da7f3eb_2722x1136.png 424w, https://substackcdn.com/image/fetch/$s_!qKoX!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d81719a-8a4b-43bc-86ef-27648da7f3eb_2722x1136.png 848w, https://substackcdn.com/image/fetch/$s_!qKoX!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d81719a-8a4b-43bc-86ef-27648da7f3eb_2722x1136.png 1272w, https://substackcdn.com/image/fetch/$s_!qKoX!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d81719a-8a4b-43bc-86ef-27648da7f3eb_2722x1136.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!qKoX!,w_2400,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d81719a-8a4b-43bc-86ef-27648da7f3eb_2722x1136.png" width="1200" height="501.0989010989011" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1d81719a-8a4b-43bc-86ef-27648da7f3eb_2722x1136.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;large&quot;,&quot;height&quot;:608,&quot;width&quot;:1456,&quot;resizeWidth&quot;:1200,&quot;bytes&quot;:203249,&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/196130098?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d81719a-8a4b-43bc-86ef-27648da7f3eb_2722x1136.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_!qKoX!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d81719a-8a4b-43bc-86ef-27648da7f3eb_2722x1136.png 424w, https://substackcdn.com/image/fetch/$s_!qKoX!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d81719a-8a4b-43bc-86ef-27648da7f3eb_2722x1136.png 848w, https://substackcdn.com/image/fetch/$s_!qKoX!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d81719a-8a4b-43bc-86ef-27648da7f3eb_2722x1136.png 1272w, https://substackcdn.com/image/fetch/$s_!qKoX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d81719a-8a4b-43bc-86ef-27648da7f3eb_2722x1136.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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">Causal/ Masked multi-head self-attention is made up of &#8220;num_head&#8221; scaled dot-product attention heads</figcaption></figure></div><p>Modern LLMs use many other variants of the attention mechanism, such as:</p><ul><li><p><a href="https://www.intoai.pub/p/grouped-query-attention">Grouped query attention (GQA)</a> as in <a href="https://arxiv.org/abs/2407.21783">Meta Llama</a></p></li><li><p><a href="https://www.intoai.pub/p/multi-head-latent-attention-is-the">Multi-head Latent Attention (MLA)</a> as in <a href="https://arxiv.org/abs/2412.19437">DeepSeek-V3</a></p></li><li><p>Compressed Sparse Attention (CSA) and Heavily Compressed Attention (HCA) as in <a href="https://huggingface.co/deepseek-ai/DeepSeek-V4-Pro/blob/main/DeepSeek_V4.pdf">DeepSeek-V4</a></p></li></ul><div><hr></div><h3><strong>2. Feed-Forward Network</strong></h3><p>While the role of the Causal Multi-Head Self-Attention is to understand <strong>inter-token patterns</strong> (between different tokens) in text, the Feed-forward network (FFN) helps learn <strong>token-wise patterns</strong> or deeper individual representations of tokens.</p><p>The following Feed-forward network expands the input dimension using fully connected layers to increase representational capacity, then projects it back to the original dimension before passing it to the next layer.</p><p>A feed-forward network can use multiple wide, fully connected layers, along with different activation functions such as <a href="https://arxiv.org/abs/2002.05202">SwiGLU</a>. A simple feed-forward network is shown below.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!aie1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4fba60b6-07af-47ac-98ec-b2beb6bfefab_2584x1048.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!aie1!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4fba60b6-07af-47ac-98ec-b2beb6bfefab_2584x1048.png 424w, https://substackcdn.com/image/fetch/$s_!aie1!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4fba60b6-07af-47ac-98ec-b2beb6bfefab_2584x1048.png 848w, https://substackcdn.com/image/fetch/$s_!aie1!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4fba60b6-07af-47ac-98ec-b2beb6bfefab_2584x1048.png 1272w, https://substackcdn.com/image/fetch/$s_!aie1!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4fba60b6-07af-47ac-98ec-b2beb6bfefab_2584x1048.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!aie1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4fba60b6-07af-47ac-98ec-b2beb6bfefab_2584x1048.png" width="1456" height="591" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4fba60b6-07af-47ac-98ec-b2beb6bfefab_2584x1048.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;:112641,&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/196130098?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4fba60b6-07af-47ac-98ec-b2beb6bfefab_2584x1048.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_!aie1!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4fba60b6-07af-47ac-98ec-b2beb6bfefab_2584x1048.png 424w, https://substackcdn.com/image/fetch/$s_!aie1!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4fba60b6-07af-47ac-98ec-b2beb6bfefab_2584x1048.png 848w, https://substackcdn.com/image/fetch/$s_!aie1!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4fba60b6-07af-47ac-98ec-b2beb6bfefab_2584x1048.png 1272w, https://substackcdn.com/image/fetch/$s_!aie1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4fba60b6-07af-47ac-98ec-b2beb6bfefab_2584x1048.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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. Layer Normalization</strong></h3><p><a href="https://www.intoai.pub/p/normalization">Layer Normalization, or LayerNorm</a>, helps stabilize and speed up model training by keeping each token&#8217;s representation well-scaled and gradients numerically stable as they flow through the layers of a Transformer.</p><p>It does so by normalizing each token&#8217;s feature vector to zero mean and unit variance, then applies learned scaling and shifting.</p><p>There are two ways in which LayerNorm is used:</p><ol><li><p><strong>Post-LayerNorm (Post-LN):</strong> where LayerNorm is applied after each sublayer as in the original Transformer paper.</p></li><li><p><strong>Pre-LayerNorm (Pre-LN):</strong> where LayerNorm is applied before each sublayer, as in architectures like GPT-2, leading to more stable gradients during training.</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_!3kv4!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdad4ad88-9e4e-4fde-9440-a57269a043b8_1080x1080.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!3kv4!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdad4ad88-9e4e-4fde-9440-a57269a043b8_1080x1080.png 424w, https://substackcdn.com/image/fetch/$s_!3kv4!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdad4ad88-9e4e-4fde-9440-a57269a043b8_1080x1080.png 848w, https://substackcdn.com/image/fetch/$s_!3kv4!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdad4ad88-9e4e-4fde-9440-a57269a043b8_1080x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!3kv4!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdad4ad88-9e4e-4fde-9440-a57269a043b8_1080x1080.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!3kv4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdad4ad88-9e4e-4fde-9440-a57269a043b8_1080x1080.png" width="1080" height="1080" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/dad4ad88-9e4e-4fde-9440-a57269a043b8_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;: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_!3kv4!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdad4ad88-9e4e-4fde-9440-a57269a043b8_1080x1080.png 424w, https://substackcdn.com/image/fetch/$s_!3kv4!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdad4ad88-9e4e-4fde-9440-a57269a043b8_1080x1080.png 848w, https://substackcdn.com/image/fetch/$s_!3kv4!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdad4ad88-9e4e-4fde-9440-a57269a043b8_1080x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!3kv4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdad4ad88-9e4e-4fde-9440-a57269a043b8_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><figcaption class="image-caption"><a href="https://gumroad.com/a/440621971/yasxkv">Source</a></figcaption></figure></div><p>Many modern LLMs, such as <a href="https://arxiv.org/abs/2505.09388">Qwen 3,</a> use <strong><a href="https://arxiv.org/abs/1910.07467">RMSNorm</a></strong> <strong>with pre-normalization</strong> instead of Pre-LayerNorm because it is computationally cheaper and offers faster training and inference while maintaining comparable model performance.</p><div><hr></div><h3><strong>4. Residual/ Skip connection</strong></h3><p>A <a href="https://en.wikipedia.org/wiki/Residual_neural_network">Residual</a> or Skip connection adds the input of a layer directly to its output, bypassing the layer.</p><p>Such connections help information and gradients flow through deep networks, making training more stable and effective.</p><p>Residual connections were <a href="https://arxiv.org/abs/1512.03385">first implemented</a> in Image recognition models, and given their effectiveness, they are now used in all LLMs today, either in their original form or a modified form such as:</p><ul><li><p><a href="https://arxiv.org/abs/2409.19606">Hyper-Connections</a></p></li><li><p><a href="https://arxiv.org/abs/2512.24880">Manifold-Constrained Hyper-Connections</a> as in <a href="https://huggingface.co/deepseek-ai/DeepSeek-V4-Pro/blob/main/DeepSeek_V4.pdf">DeepSeek-V4</a></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_!BUKz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff82055fb-d7dc-4e22-b084-2956cf2648ac_2584x708.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!BUKz!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff82055fb-d7dc-4e22-b084-2956cf2648ac_2584x708.png 424w, https://substackcdn.com/image/fetch/$s_!BUKz!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff82055fb-d7dc-4e22-b084-2956cf2648ac_2584x708.png 848w, https://substackcdn.com/image/fetch/$s_!BUKz!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff82055fb-d7dc-4e22-b084-2956cf2648ac_2584x708.png 1272w, https://substackcdn.com/image/fetch/$s_!BUKz!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff82055fb-d7dc-4e22-b084-2956cf2648ac_2584x708.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!BUKz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff82055fb-d7dc-4e22-b084-2956cf2648ac_2584x708.png" width="1456" height="399" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f82055fb-d7dc-4e22-b084-2956cf2648ac_2584x708.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;:73346,&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/196130098?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff82055fb-d7dc-4e22-b084-2956cf2648ac_2584x708.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_!BUKz!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff82055fb-d7dc-4e22-b084-2956cf2648ac_2584x708.png 424w, https://substackcdn.com/image/fetch/$s_!BUKz!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff82055fb-d7dc-4e22-b084-2956cf2648ac_2584x708.png 848w, https://substackcdn.com/image/fetch/$s_!BUKz!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff82055fb-d7dc-4e22-b084-2956cf2648ac_2584x708.png 1272w, https://substackcdn.com/image/fetch/$s_!BUKz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff82055fb-d7dc-4e22-b084-2956cf2648ac_2584x708.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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>All of the above-described components come together to form the Decoder-only Transformer, an architecture that lies at the heart of modern LLMs.</p><p>The flow through an LLM goes like this:</p><ul><li><p>An input sequence is tokenized (broken down into tokens) and converted into input embeddings (which contain a high-dimensional representation of input tokens and their positions in the sequence)</p></li><li><p>These are processed by a stack of Decoder blocks in a Decoder-only transformer</p></li><li><p>A Layer Normalization is applied to the output of the transformer stack</p></li><li><p>A Linear output layer takes the last token&#8217;s vector and turns it into a list of logits</p></li><li><p>These logits are converted into token probabilities</p></li><li><p>Different <a href="https://www.intoai.pub/p/decoding-strategies-in-llms">decoding strategies</a> are used to pick a token from these probabilities. This is the next token produced by the LLM, given the input sequence.</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_!vNsc!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabb91ea2-4a7b-44e9-abea-5c488cabf553_1716x1084.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!vNsc!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabb91ea2-4a7b-44e9-abea-5c488cabf553_1716x1084.png 424w, https://substackcdn.com/image/fetch/$s_!vNsc!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabb91ea2-4a7b-44e9-abea-5c488cabf553_1716x1084.png 848w, https://substackcdn.com/image/fetch/$s_!vNsc!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabb91ea2-4a7b-44e9-abea-5c488cabf553_1716x1084.png 1272w, https://substackcdn.com/image/fetch/$s_!vNsc!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabb91ea2-4a7b-44e9-abea-5c488cabf553_1716x1084.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!vNsc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabb91ea2-4a7b-44e9-abea-5c488cabf553_1716x1084.png" width="1456" height="920" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/abb91ea2-4a7b-44e9-abea-5c488cabf553_1716x1084.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;:107860,&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/196130098?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabb91ea2-4a7b-44e9-abea-5c488cabf553_1716x1084.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_!vNsc!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabb91ea2-4a7b-44e9-abea-5c488cabf553_1716x1084.png 424w, https://substackcdn.com/image/fetch/$s_!vNsc!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabb91ea2-4a7b-44e9-abea-5c488cabf553_1716x1084.png 848w, https://substackcdn.com/image/fetch/$s_!vNsc!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabb91ea2-4a7b-44e9-abea-5c488cabf553_1716x1084.png 1272w, https://substackcdn.com/image/fetch/$s_!vNsc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabb91ea2-4a7b-44e9-abea-5c488cabf553_1716x1084.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 more detailed illustration of each component is shown below.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!3RtR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F09cd6d5f-e2ce-4113-ba3d-752211bc2346_1966x1084.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!3RtR!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F09cd6d5f-e2ce-4113-ba3d-752211bc2346_1966x1084.png 424w, https://substackcdn.com/image/fetch/$s_!3RtR!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F09cd6d5f-e2ce-4113-ba3d-752211bc2346_1966x1084.png 848w, https://substackcdn.com/image/fetch/$s_!3RtR!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F09cd6d5f-e2ce-4113-ba3d-752211bc2346_1966x1084.png 1272w, https://substackcdn.com/image/fetch/$s_!3RtR!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F09cd6d5f-e2ce-4113-ba3d-752211bc2346_1966x1084.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!3RtR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F09cd6d5f-e2ce-4113-ba3d-752211bc2346_1966x1084.png" width="1456" height="803" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/09cd6d5f-e2ce-4113-ba3d-752211bc2346_1966x1084.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:803,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:186665,&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/196130098?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F09cd6d5f-e2ce-4113-ba3d-752211bc2346_1966x1084.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_!3RtR!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F09cd6d5f-e2ce-4113-ba3d-752211bc2346_1966x1084.png 424w, https://substackcdn.com/image/fetch/$s_!3RtR!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F09cd6d5f-e2ce-4113-ba3d-752211bc2346_1966x1084.png 848w, https://substackcdn.com/image/fetch/$s_!3RtR!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F09cd6d5f-e2ce-4113-ba3d-752211bc2346_1966x1084.png 1272w, https://substackcdn.com/image/fetch/$s_!3RtR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F09cd6d5f-e2ce-4113-ba3d-752211bc2346_1966x1084.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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;re curious about learning more about these components and how a complete LLM works and is trained, with code, <a href="https://www.intoai.pub/t/build-an-llm-from-scratch">this series of articles will help</a>.</p><div><hr></div><p>Thank you for reading!</p><p>If you found it valuable, hit a like &#10084;&#65039; and consider subscribing for more such content every week.</p><p>If you have any questions/suggestions, feel free to leave a comment.</p><div class="captioned-button-wrap" data-attrs="{&quot;url&quot;:&quot;https://blog.algomaster.io/p/transformer-architecture?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">This post is public so feel free to share it.</p></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.algomaster.io/p/transformer-architecture?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://blog.algomaster.io/p/transformer-architecture?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p></div>]]></content:encoded></item><item><title><![CDATA[Monolith vs Microservices vs Modular Monoliths]]></title><description><![CDATA[Most software systems start simple. A small team, a single codebase, one database, and a few features.]]></description><link>https://blog.algomaster.io/p/monolith-vs-microservices-vs-modular-monoliths</link><guid isPermaLink="false">https://blog.algomaster.io/p/monolith-vs-microservices-vs-modular-monoliths</guid><dc:creator><![CDATA[Ashish Pratap Singh]]></dc:creator><pubDate>Tue, 12 May 2026 04:10:14 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!7Pzn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0174350-a4bc-4f86-a3b4-4e55dacc1a8e_1778x1334.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Most software systems start simple. A small team, a single codebase, one database, and a few features. At this stage, a <strong>monolith</strong> is often the fastest and simplest choice.</p><p>But as the product grows, that simplicity can become a bottleneck. Teams step on each other&#8217;s code, deployments become risky, and one small change can affect the entire system. That is when many teams start looking at <strong>microservices</strong>.</p><p>Microservices can help, but they also introduce distributed systems complexity: network failures, data consistency challenges, observability overhead, and more operational burden.</p><p>This is where <strong>modular monoliths</strong> offer a middle path. They keep the simplicity of a monolith while adding stronger internal boundaries and clearer ownership.</p><p>In this article, we will break down monoliths, microservices, and modular monoliths, understand how they differ, when each one makes sense, how to choose the right architecture for your system, and how to migrate between these architectures.</p><div><hr></div><h1>What is a Monolith?</h1><p>A monolithic application is built and deployed as a single unit.</p><p>The UI, business logic, and data access code all live in the same codebase. They are compiled into one artifact, deployed together, and usually run as one process.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!XFBB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0d2e693-060c-4985-a01f-6a6a95994f5f_1950x1440.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!XFBB!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0d2e693-060c-4985-a01f-6a6a95994f5f_1950x1440.png 424w, https://substackcdn.com/image/fetch/$s_!XFBB!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0d2e693-060c-4985-a01f-6a6a95994f5f_1950x1440.png 848w, https://substackcdn.com/image/fetch/$s_!XFBB!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0d2e693-060c-4985-a01f-6a6a95994f5f_1950x1440.png 1272w, https://substackcdn.com/image/fetch/$s_!XFBB!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0d2e693-060c-4985-a01f-6a6a95994f5f_1950x1440.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!XFBB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0d2e693-060c-4985-a01f-6a6a95994f5f_1950x1440.png" width="1456" height="1075" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e0d2e693-060c-4985-a01f-6a6a95994f5f_1950x1440.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1075,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:111271,&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://blog.algomaster.io/i/173397632?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0d2e693-060c-4985-a01f-6a6a95994f5f_1950x1440.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_!XFBB!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0d2e693-060c-4985-a01f-6a6a95994f5f_1950x1440.png 424w, https://substackcdn.com/image/fetch/$s_!XFBB!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0d2e693-060c-4985-a01f-6a6a95994f5f_1950x1440.png 848w, https://substackcdn.com/image/fetch/$s_!XFBB!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0d2e693-060c-4985-a01f-6a6a95994f5f_1950x1440.png 1272w, https://substackcdn.com/image/fetch/$s_!XFBB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0d2e693-060c-4985-a01f-6a6a95994f5f_1950x1440.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Different parts of the application communicate through direct function calls and often share the same database.</p><p>For example, a simple e-commerce monolith might organize code by technical layers:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;plaintext&quot;,&quot;nodeId&quot;:&quot;97964946-5116-4574-bcec-aaa26988b354&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-plaintext">ecommerce-app/
&#9500;&#9472;&#9472; controllers/
&#9500;&#9472;&#9472; services/
&#9500;&#9472;&#9472; repositories/
&#9492;&#9472;&#9472; models/</code></pre></div><p>This structure is easy to understand in the early stages of a product. You clone one repository, run one application, connect one database, and start building.</p><p>That simplicity is the biggest strength of a monolith.</p><p>There is one codebase to maintain, one deployment pipeline to manage, one process to monitor, and one place to look when something breaks. Database transactions are straightforward, and communication between modules is fast because it happens through normal function calls, not network requests.</p><p>But the same simplicity can become painful as the system grows.</p><p>A small change in one module may require rebuilding, retesting, and redeploying the entire application. If one module gets heavy traffic, you often have to scale the whole app. One bad query, memory leak, or unhandled exception can affect the entire system. Over time, internal boundaries can blur, and developers may start reaching across modules directly.</p><p>Almost every successful application starts as a monolith. The real question is not whether monoliths are bad. The real question is: <strong>what should you do when the monolith starts slowing you down?</strong></p><div><hr></div><h1>What is a Microservices Architecture?</h1>
      <p>
          <a href="https://blog.algomaster.io/p/monolith-vs-microservices-vs-modular-monoliths">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Neural Networks Explained In Plain English]]></title><description><![CDATA[All popular AI systems that you see today are made up of basic computing units called Neurons or Perceptrons. These connect to form a network called a Neural network that performs various complex computations.]]></description><link>https://blog.algomaster.io/p/neural-networks-explained-in-plain</link><guid isPermaLink="false">https://blog.algomaster.io/p/neural-networks-explained-in-plain</guid><dc:creator><![CDATA[Ashish Pratap Singh]]></dc:creator><pubDate>Tue, 21 Apr 2026 04:01:25 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!PqDA!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe339a61d-d43d-4421-9a05-c7e4fb06a541_2264x1120.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Welcome to another edition of the <strong>AI Engineering series,</strong> where we cover important AI/ML concepts and how to build modern AI applications.</p><p>This is a guest post by <a href="https://www.linkedin.com/in/ashishbamania/">Dr. Ashish Bamania</a>. He&#8217;s an AI engineer and author of multiple newsletters including <a href="https://www.intoai.pub/">Into AI</a> and <a href="https://www.intoquantum.pub/">Into Quantum</a>.</p><div><hr></div><p>All popular AI systems that you see today are made up of basic computing units called Neurons or <a href="https://en.wikipedia.org/wiki/Perceptron">Perceptrons</a>. These connect to form a network called a Neural network that performs various complex computations.</p><p>In this lesson, we will understand how neural networks work and how they solve challenging problems, such as generating text, recognizing objects, controlling a robot, and more.</p><p>Let&#8217;s begin!</p><div><hr></div><h3><strong>To Begin, What is a Neuron?</strong></h3><p>A <strong>Neuron</strong> (also called a <strong>Perceptron</strong>) is inspired by a nerve cell (also called a <a href="https://en.wikipedia.org/wiki/Neuron">Neuron</a>) in the body.</p><p>It accepts single or multiple inputs, performs calculations on them, and generates an output.</p><p>It is implemented using a simple <a href="https://en.wikipedia.org/wiki/Linear_function">linear</a> equation as shown below.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!WY4J!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F819d088a-a428-41c7-848e-4aad11ac1453_2374x750.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!WY4J!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F819d088a-a428-41c7-848e-4aad11ac1453_2374x750.png 424w, https://substackcdn.com/image/fetch/$s_!WY4J!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F819d088a-a428-41c7-848e-4aad11ac1453_2374x750.png 848w, https://substackcdn.com/image/fetch/$s_!WY4J!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F819d088a-a428-41c7-848e-4aad11ac1453_2374x750.png 1272w, https://substackcdn.com/image/fetch/$s_!WY4J!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F819d088a-a428-41c7-848e-4aad11ac1453_2374x750.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!WY4J!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F819d088a-a428-41c7-848e-4aad11ac1453_2374x750.png" width="1456" height="460" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/819d088a-a428-41c7-848e-4aad11ac1453_2374x750.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:460,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:303380,&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/194501100?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F819d088a-a428-41c7-848e-4aad11ac1453_2374x750.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_!WY4J!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F819d088a-a428-41c7-848e-4aad11ac1453_2374x750.png 424w, https://substackcdn.com/image/fetch/$s_!WY4J!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F819d088a-a428-41c7-848e-4aad11ac1453_2374x750.png 848w, https://substackcdn.com/image/fetch/$s_!WY4J!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F819d088a-a428-41c7-848e-4aad11ac1453_2374x750.png 1272w, https://substackcdn.com/image/fetch/$s_!WY4J!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F819d088a-a428-41c7-848e-4aad11ac1453_2374x750.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 job of a neuron is to <a href="https://en.wikipedia.org/wiki/Universal_approximation_theorem">find or approximate a function</a> that somehow connects the output to its inputs. This function can be as simple or complex as possible.</p><p>Now that&#8217;s tough, especially when a neuron is just a linear function. Since most real-world functions cannot be approximated with a linear function, a neuron uses an <a href="https://en.wikipedia.org/wiki/Activation_function">Activation function</a> to capture the non-linearities in its input.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!nO-x!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ac505e4-76e5-4654-9845-5988d4b0028a_2316x958.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!nO-x!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ac505e4-76e5-4654-9845-5988d4b0028a_2316x958.png 424w, https://substackcdn.com/image/fetch/$s_!nO-x!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ac505e4-76e5-4654-9845-5988d4b0028a_2316x958.png 848w, https://substackcdn.com/image/fetch/$s_!nO-x!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ac505e4-76e5-4654-9845-5988d4b0028a_2316x958.png 1272w, https://substackcdn.com/image/fetch/$s_!nO-x!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ac505e4-76e5-4654-9845-5988d4b0028a_2316x958.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!nO-x!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ac505e4-76e5-4654-9845-5988d4b0028a_2316x958.png" width="1456" height="602" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2ac505e4-76e5-4654-9845-5988d4b0028a_2316x958.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:602,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:242190,&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/194501100?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ac505e4-76e5-4654-9845-5988d4b0028a_2316x958.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_!nO-x!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ac505e4-76e5-4654-9845-5988d4b0028a_2316x958.png 424w, https://substackcdn.com/image/fetch/$s_!nO-x!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ac505e4-76e5-4654-9845-5988d4b0028a_2316x958.png 848w, https://substackcdn.com/image/fetch/$s_!nO-x!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ac505e4-76e5-4654-9845-5988d4b0028a_2316x958.png 1272w, https://substackcdn.com/image/fetch/$s_!nO-x!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ac505e4-76e5-4654-9845-5988d4b0028a_2316x958.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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>Some of the commonly used Activation functions in neural networks are as follows:</p><ul><li><p><strong><a href="https://en.wikipedia.org/wiki/Sigmoid_function">Sigmoid</a></strong>: An S-shaped function that squashes an input into a value between 0 and 1.</p></li><li><p><strong><a href="https://www.cuemath.com/trigonometry/tanh/">TanH</a></strong>: An S-shaped function that squashes an input into a value between -1 and 1.</p></li><li><p><strong><a href="https://en.wikipedia.org/wiki/Rectified_linear_unit">ReLU or Rectified linear unit</a></strong>: A function that outputs the input directly if it is positive, but converts all negative inputs into 0.</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_!Hsp3!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dadf368-d20a-45f3-b9f0-7d85912d5e4d_1080x1080.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Hsp3!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dadf368-d20a-45f3-b9f0-7d85912d5e4d_1080x1080.png 424w, https://substackcdn.com/image/fetch/$s_!Hsp3!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dadf368-d20a-45f3-b9f0-7d85912d5e4d_1080x1080.png 848w, https://substackcdn.com/image/fetch/$s_!Hsp3!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dadf368-d20a-45f3-b9f0-7d85912d5e4d_1080x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!Hsp3!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dadf368-d20a-45f3-b9f0-7d85912d5e4d_1080x1080.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Hsp3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dadf368-d20a-45f3-b9f0-7d85912d5e4d_1080x1080.png" width="1080" height="1080" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1dadf368-d20a-45f3-b9f0-7d85912d5e4d_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;:31224,&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/194501100?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dadf368-d20a-45f3-b9f0-7d85912d5e4d_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_!Hsp3!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dadf368-d20a-45f3-b9f0-7d85912d5e4d_1080x1080.png 424w, https://substackcdn.com/image/fetch/$s_!Hsp3!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dadf368-d20a-45f3-b9f0-7d85912d5e4d_1080x1080.png 848w, https://substackcdn.com/image/fetch/$s_!Hsp3!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dadf368-d20a-45f3-b9f0-7d85912d5e4d_1080x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!Hsp3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dadf368-d20a-45f3-b9f0-7d85912d5e4d_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>How does a Neuron learn?</strong></h3><p>A neuron uses parameters called <strong>Weights</strong> and <strong>Biases</strong> to learn the relationship between its inputs and outputs. These parameters are not fixed and change as a neuron learns.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!oIxW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2fa4699b-ac47-4255-8af2-53726b5c4816_2316x1076.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!oIxW!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2fa4699b-ac47-4255-8af2-53726b5c4816_2316x1076.png 424w, https://substackcdn.com/image/fetch/$s_!oIxW!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2fa4699b-ac47-4255-8af2-53726b5c4816_2316x1076.png 848w, https://substackcdn.com/image/fetch/$s_!oIxW!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2fa4699b-ac47-4255-8af2-53726b5c4816_2316x1076.png 1272w, https://substackcdn.com/image/fetch/$s_!oIxW!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2fa4699b-ac47-4255-8af2-53726b5c4816_2316x1076.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!oIxW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2fa4699b-ac47-4255-8af2-53726b5c4816_2316x1076.png" width="1456" height="676" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2fa4699b-ac47-4255-8af2-53726b5c4816_2316x1076.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:676,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:315901,&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/194501100?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2fa4699b-ac47-4255-8af2-53726b5c4816_2316x1076.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_!oIxW!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2fa4699b-ac47-4255-8af2-53726b5c4816_2316x1076.png 424w, https://substackcdn.com/image/fetch/$s_!oIxW!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2fa4699b-ac47-4255-8af2-53726b5c4816_2316x1076.png 848w, https://substackcdn.com/image/fetch/$s_!oIxW!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2fa4699b-ac47-4255-8af2-53726b5c4816_2316x1076.png 1272w, https://substackcdn.com/image/fetch/$s_!oIxW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2fa4699b-ac47-4255-8af2-53726b5c4816_2316x1076.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 neuron on its own isn&#8217;t a very powerful learner, and this is why multiple neurons are stacked together to form a <strong>Neural network</strong>. Since neurons are also called Perceptrons and these networks consist of multiple layers of them, this architecture is also called a <strong>Multi-layer Perceptron (MLP)</strong>.</p><div><hr></div><h3><strong>Stacking neurons into a network</strong></h3><p>Check out an example below where we have stacked 5 neurons together in 3 layers.</p><p>Since the output of each neuron is transmitted to every other neuron in the next layer, these are called <strong>Dense</strong> layers. (The other category being Sparse layers, which we won&#8217;t discuss in this article.)</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!HC3w!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d3dabb3-ff69-4e9d-a1aa-7b546d18a414_2394x788.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!HC3w!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d3dabb3-ff69-4e9d-a1aa-7b546d18a414_2394x788.png 424w, https://substackcdn.com/image/fetch/$s_!HC3w!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d3dabb3-ff69-4e9d-a1aa-7b546d18a414_2394x788.png 848w, https://substackcdn.com/image/fetch/$s_!HC3w!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d3dabb3-ff69-4e9d-a1aa-7b546d18a414_2394x788.png 1272w, https://substackcdn.com/image/fetch/$s_!HC3w!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d3dabb3-ff69-4e9d-a1aa-7b546d18a414_2394x788.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!HC3w!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d3dabb3-ff69-4e9d-a1aa-7b546d18a414_2394x788.png" width="1456" height="479" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1d3dabb3-ff69-4e9d-a1aa-7b546d18a414_2394x788.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:479,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:285831,&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/194501100?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d3dabb3-ff69-4e9d-a1aa-7b546d18a414_2394x788.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_!HC3w!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d3dabb3-ff69-4e9d-a1aa-7b546d18a414_2394x788.png 424w, https://substackcdn.com/image/fetch/$s_!HC3w!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d3dabb3-ff69-4e9d-a1aa-7b546d18a414_2394x788.png 848w, https://substackcdn.com/image/fetch/$s_!HC3w!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d3dabb3-ff69-4e9d-a1aa-7b546d18a414_2394x788.png 1272w, https://substackcdn.com/image/fetch/$s_!HC3w!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d3dabb3-ff69-4e9d-a1aa-7b546d18a414_2394x788.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 layers of the neural network are categorized as follows:</p><ol><li><p><strong>Input layer</strong> (with neurons 1 and 2): Takes an input</p></li><li><p><strong>Hidden layer</strong> (with neurons 3 and 4): Performs most calculations</p></li><li><p><strong>Output layer</strong> (with neuron 5): Outputs the result</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_!6sER!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F108b1deb-d7cb-4c0c-8f54-9259a79dae4a_2204x962.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!6sER!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F108b1deb-d7cb-4c0c-8f54-9259a79dae4a_2204x962.png 424w, https://substackcdn.com/image/fetch/$s_!6sER!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F108b1deb-d7cb-4c0c-8f54-9259a79dae4a_2204x962.png 848w, https://substackcdn.com/image/fetch/$s_!6sER!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F108b1deb-d7cb-4c0c-8f54-9259a79dae4a_2204x962.png 1272w, https://substackcdn.com/image/fetch/$s_!6sER!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F108b1deb-d7cb-4c0c-8f54-9259a79dae4a_2204x962.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!6sER!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F108b1deb-d7cb-4c0c-8f54-9259a79dae4a_2204x962.png" width="1456" height="636" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/108b1deb-d7cb-4c0c-8f54-9259a79dae4a_2204x962.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;:491712,&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/194501100?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F108b1deb-d7cb-4c0c-8f54-9259a79dae4a_2204x962.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_!6sER!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F108b1deb-d7cb-4c0c-8f54-9259a79dae4a_2204x962.png 424w, https://substackcdn.com/image/fetch/$s_!6sER!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F108b1deb-d7cb-4c0c-8f54-9259a79dae4a_2204x962.png 848w, https://substackcdn.com/image/fetch/$s_!6sER!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F108b1deb-d7cb-4c0c-8f54-9259a79dae4a_2204x962.png 1272w, https://substackcdn.com/image/fetch/$s_!6sER!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F108b1deb-d7cb-4c0c-8f54-9259a79dae4a_2204x962.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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>Zooming in, each neuron in these layers receives input, which is multiplied by a unique weight and bias terms specific to that neuron, and generates an output that is passed to another neuron.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!BaWh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3edb775-65bf-44f4-8260-94d66860a995_2092x974.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!BaWh!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3edb775-65bf-44f4-8260-94d66860a995_2092x974.png 424w, https://substackcdn.com/image/fetch/$s_!BaWh!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3edb775-65bf-44f4-8260-94d66860a995_2092x974.png 848w, https://substackcdn.com/image/fetch/$s_!BaWh!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3edb775-65bf-44f4-8260-94d66860a995_2092x974.png 1272w, https://substackcdn.com/image/fetch/$s_!BaWh!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3edb775-65bf-44f4-8260-94d66860a995_2092x974.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!BaWh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3edb775-65bf-44f4-8260-94d66860a995_2092x974.png" width="1456" height="678" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f3edb775-65bf-44f4-8260-94d66860a995_2092x974.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:678,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:350831,&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/194501100?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3edb775-65bf-44f4-8260-94d66860a995_2092x974.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_!BaWh!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3edb775-65bf-44f4-8260-94d66860a995_2092x974.png 424w, https://substackcdn.com/image/fetch/$s_!BaWh!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3edb775-65bf-44f4-8260-94d66860a995_2092x974.png 848w, https://substackcdn.com/image/fetch/$s_!BaWh!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3edb775-65bf-44f4-8260-94d66860a995_2092x974.png 1272w, https://substackcdn.com/image/fetch/$s_!BaWh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3edb775-65bf-44f4-8260-94d66860a995_2092x974.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 calculations continue till a final output from the neural network is generated. This process of calculating the output of a neural network from its inputs is called the <strong>Forward Pass,</strong> or <strong>Forward Propagation</strong>.</p><p>Since data flows from the Input layer to the Output layer, which is an imagined forward direction, this network is called a <strong>Feed-Forward Network</strong>. (The other category being <a href="https://en.wikipedia.org/wiki/Recurrent_neural_network">Recurrent neural networks</a>, which we won&#8217;t be discussing in this article.)</p><div><hr></div><h3><strong>How does a neural network learn?</strong></h3><p>A neural network learns by iteratively updating its parameters until it approximates the function that maps its inputs to outputs.</p><p>At the beginning of training, when a neural network generates an output given its inputs, the output is mostly gibberish because the parameters in each neuron are randomly set.</p><p>For learning, the generated output is compared with the true value (the output that we intend the neural network to generate) using a <strong>Loss function</strong>.</p><p>This loss function is a mathematical formula that measures the error between the network&#8217;s generated/predicted output and the true value.</p><p>Some commonly used loss functions are:</p><ul><li><p><strong><a href="https://en.wikipedia.org/wiki/Mean_absolute_error">Mean Absolute Error</a></strong>: The average of the absolute differences between the network&#8217;s output values and the true values (used for <a href="https://en.wikipedia.org/wiki/Regression_analysis">regression</a> problems)</p></li><li><p><strong>Mean Squared Error: </strong>The average squared difference between the network&#8217;s output values and the true values (used for regression problems)</p></li><li><p><strong><a href="https://en.wikipedia.org/wiki/Cross-entropy">Binary/ Categorical Cross-Entropy</a></strong>: Measure of the performance of a <a href="https://en.wikipedia.org/wiki/Statistical_classification">classification</a> model whose output is a probability value between 0 and 1.</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_!uvGJ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F347e1a75-4b78-4783-8408-51607a42a134_1456x729.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!uvGJ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F347e1a75-4b78-4783-8408-51607a42a134_1456x729.png 424w, https://substackcdn.com/image/fetch/$s_!uvGJ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F347e1a75-4b78-4783-8408-51607a42a134_1456x729.png 848w, https://substackcdn.com/image/fetch/$s_!uvGJ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F347e1a75-4b78-4783-8408-51607a42a134_1456x729.png 1272w, https://substackcdn.com/image/fetch/$s_!uvGJ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F347e1a75-4b78-4783-8408-51607a42a134_1456x729.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!uvGJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F347e1a75-4b78-4783-8408-51607a42a134_1456x729.png" width="1456" height="729" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/347e1a75-4b78-4783-8408-51607a42a134_1456x729.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:729,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:212569,&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/194501100?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F347e1a75-4b78-4783-8408-51607a42a134_1456x729.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_!uvGJ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F347e1a75-4b78-4783-8408-51607a42a134_1456x729.png 424w, https://substackcdn.com/image/fetch/$s_!uvGJ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F347e1a75-4b78-4783-8408-51607a42a134_1456x729.png 848w, https://substackcdn.com/image/fetch/$s_!uvGJ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F347e1a75-4b78-4783-8408-51607a42a134_1456x729.png 1272w, https://substackcdn.com/image/fetch/$s_!uvGJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F347e1a75-4b78-4783-8408-51607a42a134_1456x729.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 measure of error or <strong>Loss</strong> is used to update the parameters (weights and biases) in a process called the <strong>Backward Pass </strong>or<strong> Backpropagation.</strong></p><p>Each parameter is updated in proportion to its contribution to the overall loss. This ensures that, in the next forward pass, the loss is smaller than in this one, and the model learns by reducing the loss.</p><p>The algorithm used for this parameter update process is called an <strong><a href="https://www.intoai.pub/i/146844148/but-first-what-are-optimizers">Optimization algorithm</a></strong><a href="https://www.intoai.pub/i/146844148/but-first-what-are-optimizers">, or </a><strong><a href="https://www.intoai.pub/i/146844148/but-first-what-are-optimizers">Optimizer</a></strong>. Some commonly used optimizers are as follows:</p><ul><li><p><a href="https://www.intoai.pub/p/gradient-descent">Gradient Descent</a></p></li><li><p><a href="https://www.intoai.pub/i/146844148/here-comes-adam-adaptive-moment-estimation">Adam</a></p></li><li><p><a href="https://kellerjordan.github.io/posts/muon/">Muon</a></p></li></ul><p>To ensure that parameter values do not change a lot in a single step of optimization, updates are scaled using a value called the <strong><a href="https://en.wikipedia.org/wiki/Learning_rate">Learning rate</a></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_!PqDA!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe339a61d-d43d-4421-9a05-c7e4fb06a541_2264x1120.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!PqDA!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe339a61d-d43d-4421-9a05-c7e4fb06a541_2264x1120.png 424w, https://substackcdn.com/image/fetch/$s_!PqDA!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe339a61d-d43d-4421-9a05-c7e4fb06a541_2264x1120.png 848w, https://substackcdn.com/image/fetch/$s_!PqDA!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe339a61d-d43d-4421-9a05-c7e4fb06a541_2264x1120.png 1272w, https://substackcdn.com/image/fetch/$s_!PqDA!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe339a61d-d43d-4421-9a05-c7e4fb06a541_2264x1120.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!PqDA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe339a61d-d43d-4421-9a05-c7e4fb06a541_2264x1120.png" width="1456" height="720" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e339a61d-d43d-4421-9a05-c7e4fb06a541_2264x1120.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:720,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:498286,&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/194501100?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe339a61d-d43d-4421-9a05-c7e4fb06a541_2264x1120.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_!PqDA!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe339a61d-d43d-4421-9a05-c7e4fb06a541_2264x1120.png 424w, https://substackcdn.com/image/fetch/$s_!PqDA!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe339a61d-d43d-4421-9a05-c7e4fb06a541_2264x1120.png 848w, https://substackcdn.com/image/fetch/$s_!PqDA!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe339a61d-d43d-4421-9a05-c7e4fb06a541_2264x1120.png 1272w, https://substackcdn.com/image/fetch/$s_!PqDA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe339a61d-d43d-4421-9a05-c7e4fb06a541_2264x1120.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 training runs, each consisting of a forward and a backward pass, continue for multiple turns.</p><p>The loss value decreases in each run until the network starts outputting a value that is very close to the true value. This finishes the neural network training.</p><div><hr></div><h3><strong>An example of a neural network learning to identify images</strong></h3><p>Let&#8217;s take an example of a neural network learning to identify whether a given image is of a cat or a dog.</p><p>The training starts with a huge dataset of mixed images of dogs and cats. At each step, the network is given an image as input and asked to output what it thinks the image is (<strong>Forward pass</strong>).</p><p>In the following example, the untrained neural network outputs &#8220;Cat&#8221; for the dog&#8217;s image. We need to fix this.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!jDAW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4733514f-3a2a-40ef-8dac-b75a8df1e3f6_2552x616.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!jDAW!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4733514f-3a2a-40ef-8dac-b75a8df1e3f6_2552x616.png 424w, https://substackcdn.com/image/fetch/$s_!jDAW!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4733514f-3a2a-40ef-8dac-b75a8df1e3f6_2552x616.png 848w, https://substackcdn.com/image/fetch/$s_!jDAW!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4733514f-3a2a-40ef-8dac-b75a8df1e3f6_2552x616.png 1272w, https://substackcdn.com/image/fetch/$s_!jDAW!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4733514f-3a2a-40ef-8dac-b75a8df1e3f6_2552x616.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!jDAW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4733514f-3a2a-40ef-8dac-b75a8df1e3f6_2552x616.png" width="1456" height="351" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4733514f-3a2a-40ef-8dac-b75a8df1e3f6_2552x616.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:351,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:145533,&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/194501100?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4733514f-3a2a-40ef-8dac-b75a8df1e3f6_2552x616.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_!jDAW!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4733514f-3a2a-40ef-8dac-b75a8df1e3f6_2552x616.png 424w, https://substackcdn.com/image/fetch/$s_!jDAW!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4733514f-3a2a-40ef-8dac-b75a8df1e3f6_2552x616.png 848w, https://substackcdn.com/image/fetch/$s_!jDAW!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4733514f-3a2a-40ef-8dac-b75a8df1e3f6_2552x616.png 1272w, https://substackcdn.com/image/fetch/$s_!jDAW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4733514f-3a2a-40ef-8dac-b75a8df1e3f6_2552x616.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>The output (&#8220;Cat&#8221;) and the true value (&#8220;Dog&#8221;) are compared using a Loss function, which outputs an error called Loss.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!tpvv!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7ccbf91-d964-4bb0-bce1-a3de02351cbe_2262x670.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!tpvv!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7ccbf91-d964-4bb0-bce1-a3de02351cbe_2262x670.png 424w, https://substackcdn.com/image/fetch/$s_!tpvv!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7ccbf91-d964-4bb0-bce1-a3de02351cbe_2262x670.png 848w, https://substackcdn.com/image/fetch/$s_!tpvv!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7ccbf91-d964-4bb0-bce1-a3de02351cbe_2262x670.png 1272w, https://substackcdn.com/image/fetch/$s_!tpvv!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7ccbf91-d964-4bb0-bce1-a3de02351cbe_2262x670.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!tpvv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7ccbf91-d964-4bb0-bce1-a3de02351cbe_2262x670.png" width="1456" height="431" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d7ccbf91-d964-4bb0-bce1-a3de02351cbe_2262x670.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:431,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:165252,&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/194501100?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7ccbf91-d964-4bb0-bce1-a3de02351cbe_2262x670.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_!tpvv!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7ccbf91-d964-4bb0-bce1-a3de02351cbe_2262x670.png 424w, https://substackcdn.com/image/fetch/$s_!tpvv!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7ccbf91-d964-4bb0-bce1-a3de02351cbe_2262x670.png 848w, https://substackcdn.com/image/fetch/$s_!tpvv!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7ccbf91-d964-4bb0-bce1-a3de02351cbe_2262x670.png 1272w, https://substackcdn.com/image/fetch/$s_!tpvv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7ccbf91-d964-4bb0-bce1-a3de02351cbe_2262x670.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 loss value is then used to update the parameters during the backward pass. The parameter update is in a direction that leads to lower loss in the next training 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_!57aK!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F416f5468-ebce-4bd8-aca3-9b6be4ce2444_2034x654.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!57aK!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F416f5468-ebce-4bd8-aca3-9b6be4ce2444_2034x654.png 424w, https://substackcdn.com/image/fetch/$s_!57aK!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F416f5468-ebce-4bd8-aca3-9b6be4ce2444_2034x654.png 848w, https://substackcdn.com/image/fetch/$s_!57aK!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F416f5468-ebce-4bd8-aca3-9b6be4ce2444_2034x654.png 1272w, https://substackcdn.com/image/fetch/$s_!57aK!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F416f5468-ebce-4bd8-aca3-9b6be4ce2444_2034x654.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!57aK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F416f5468-ebce-4bd8-aca3-9b6be4ce2444_2034x654.png" width="1456" height="468" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/416f5468-ebce-4bd8-aca3-9b6be4ce2444_2034x654.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:468,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:95375,&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/194501100?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F416f5468-ebce-4bd8-aca3-9b6be4ce2444_2034x654.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_!57aK!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F416f5468-ebce-4bd8-aca3-9b6be4ce2444_2034x654.png 424w, https://substackcdn.com/image/fetch/$s_!57aK!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F416f5468-ebce-4bd8-aca3-9b6be4ce2444_2034x654.png 848w, https://substackcdn.com/image/fetch/$s_!57aK!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F416f5468-ebce-4bd8-aca3-9b6be4ce2444_2034x654.png 1272w, https://substackcdn.com/image/fetch/$s_!57aK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F416f5468-ebce-4bd8-aca3-9b6be4ce2444_2034x654.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 until the neural network generates the correct output (&#8220;Dog&#8221;) for the image.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!tVu4!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf2fdbe8-584d-423d-96c5-570a7b92b07e_2376x550.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!tVu4!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf2fdbe8-584d-423d-96c5-570a7b92b07e_2376x550.png 424w, https://substackcdn.com/image/fetch/$s_!tVu4!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf2fdbe8-584d-423d-96c5-570a7b92b07e_2376x550.png 848w, https://substackcdn.com/image/fetch/$s_!tVu4!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf2fdbe8-584d-423d-96c5-570a7b92b07e_2376x550.png 1272w, https://substackcdn.com/image/fetch/$s_!tVu4!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf2fdbe8-584d-423d-96c5-570a7b92b07e_2376x550.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!tVu4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf2fdbe8-584d-423d-96c5-570a7b92b07e_2376x550.png" width="1456" height="337" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/af2fdbe8-584d-423d-96c5-570a7b92b07e_2376x550.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:337,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:142872,&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/194501100?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf2fdbe8-584d-423d-96c5-570a7b92b07e_2376x550.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_!tVu4!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf2fdbe8-584d-423d-96c5-570a7b92b07e_2376x550.png 424w, https://substackcdn.com/image/fetch/$s_!tVu4!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf2fdbe8-584d-423d-96c5-570a7b92b07e_2376x550.png 848w, https://substackcdn.com/image/fetch/$s_!tVu4!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf2fdbe8-584d-423d-96c5-570a7b92b07e_2376x550.png 1272w, https://substackcdn.com/image/fetch/$s_!tVu4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf2fdbe8-584d-423d-96c5-570a7b92b07e_2376x550.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>I&#8217;ve only shown this for dog images, but a similar process applies to cat images as well. The training ends when the neural network starts identifying the correct label for the images.</p>]]></content:encoded></item><item><title><![CDATA[Top 10 API Gateway Use Cases in System Design]]></title><description><![CDATA[As your system evolves from a monolith to microservices, a pattern quickly emerges: every service starts rebuilding the same things.]]></description><link>https://blog.algomaster.io/p/top-10-api-gateway-use-cases</link><guid isPermaLink="false">https://blog.algomaster.io/p/top-10-api-gateway-use-cases</guid><dc:creator><![CDATA[Ashish Pratap Singh]]></dc:creator><pubDate>Sun, 12 Apr 2026 12:00:32 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!B7Hq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f829ba9-9c57-4301-8ad0-1bd1b82dc520_1682x642.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>As your system evolves from a <strong>monolith</strong> to <strong>microservices</strong>, a pattern quickly emerges: <strong>every service starts rebuilding the same things.</strong></p><p>Authentication. Rate limiting. Request logging. The same logic gets duplicated across services, with slight variations and inevitable bugs.</p><p>An <strong>API Gateway</strong> fixes this by introducing a single entry point for all client requests.</p><p>Instead of spreading these cross-cutting concerns across your services, you move them to one place. The gateway handles routing, security, traffic control, and more, so your services can stay focused on business logic.</p><p>In this article, we&#8217;ll break down the <strong>top 10 API Gateway use cases</strong>, how they work, and why they should belong at the gateway layer.</p><div><hr></div><h1>1. Request Routing</h1><p>At its core, an API Gateway is a traffic controller. Its primary job is simple: take an incoming request and send it to the right service.</p><p>In a microservices architecture, each service owns a specific domain such as users, orders, payments, or inventory. But clients don&#8217;t need to know where these services live or how many instances are running. They just send requests to the gateway, and the gateway takes care of the rest.</p><p>Routing decisions are usually based on things like the URL path, HTTP method, headers, or query parameters. For example, requests to <code>/api/users</code> go to the User Service, while <code>/api/orders</code> is handled by the Order Service.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!aEIB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b609a17-b935-4903-a617-11fc01b8afc3_767x289.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!aEIB!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b609a17-b935-4903-a617-11fc01b8afc3_767x289.png 424w, https://substackcdn.com/image/fetch/$s_!aEIB!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b609a17-b935-4903-a617-11fc01b8afc3_767x289.png 848w, https://substackcdn.com/image/fetch/$s_!aEIB!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b609a17-b935-4903-a617-11fc01b8afc3_767x289.png 1272w, https://substackcdn.com/image/fetch/$s_!aEIB!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b609a17-b935-4903-a617-11fc01b8afc3_767x289.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!aEIB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b609a17-b935-4903-a617-11fc01b8afc3_767x289.png" width="767" height="289" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9b609a17-b935-4903-a617-11fc01b8afc3_767x289.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:289,&quot;width&quot;:767,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:24086,&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://blog.algomaster.io/i/173210647?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b609a17-b935-4903-a617-11fc01b8afc3_767x289.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_!aEIB!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b609a17-b935-4903-a617-11fc01b8afc3_767x289.png 424w, https://substackcdn.com/image/fetch/$s_!aEIB!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b609a17-b935-4903-a617-11fc01b8afc3_767x289.png 848w, https://substackcdn.com/image/fetch/$s_!aEIB!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b609a17-b935-4903-a617-11fc01b8afc3_767x289.png 1272w, https://substackcdn.com/image/fetch/$s_!aEIB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b609a17-b935-4903-a617-11fc01b8afc3_767x289.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 what a routing configuration looks like in practice:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;yaml&quot;,&quot;nodeId&quot;:&quot;cda1ab10-11df-47e3-8ffd-f0015626eaf6&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-yaml"># API Gateway routing rules
routes:
  - path: /api/users/**
    service: user-service
    methods: [GET, POST, PUT, DELETE]

  - path: /api/orders/**
    service: order-service
    methods: [GET, POST]

  - path: /api/payments/**
    service: payment-service
    methods: [POST]

  - path: /api/inventory/**
    service: inventory-service
    methods: [GET]</code></pre></div><p>Behind the scenes, the gateway often integrates with service discovery systems like Consul or Kubernetes DNS. So when a new instance of a service spins up, the gateway can find it automatically without any manual updates.</p><p>This decouples clients from your backend. Services can scale, move, or even be renamed without breaking anything on the client side.</p><p>But routing alone isn&#8217;t enough. Once a request reaches your system, you still need to decide whether the client should be allowed to make that request in the first place.</p><div><hr></div><h1>2. Authentication and Authorization</h1><p>Every API request needs to answer two questions: Who is this? And are they allowed to do this?</p><p>Without an API Gateway, each microservice has to implement its own authentication and authorization logic. That quickly leads to duplicated code, inconsistent checks, and subtle security gaps.</p><p>An API Gateway fixes this by making security a first-class, centralized concern. It intercepts every request, validates the credentials, and only forwards requests that pass the checks. By the time a request reaches a backend service, it&#8217;s already trusted.</p><p>The most common approach is validating a <strong>JWT (JSON Web Token)</strong>. The client sends the token in the <code>Authorization</code> header, and the gateway verifies its signature, expiration, and permissions before routing the request.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!nhYM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5778b76-ea1a-4592-a48e-60e38ba554c6_1228x1118.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!nhYM!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5778b76-ea1a-4592-a48e-60e38ba554c6_1228x1118.png 424w, https://substackcdn.com/image/fetch/$s_!nhYM!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5778b76-ea1a-4592-a48e-60e38ba554c6_1228x1118.png 848w, https://substackcdn.com/image/fetch/$s_!nhYM!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5778b76-ea1a-4592-a48e-60e38ba554c6_1228x1118.png 1272w, https://substackcdn.com/image/fetch/$s_!nhYM!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5778b76-ea1a-4592-a48e-60e38ba554c6_1228x1118.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!nhYM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5778b76-ea1a-4592-a48e-60e38ba554c6_1228x1118.png" width="702" height="639.1172638436482" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f5778b76-ea1a-4592-a48e-60e38ba554c6_1228x1118.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1118,&quot;width&quot;:1228,&quot;resizeWidth&quot;:702,&quot;bytes&quot;:133688,&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://blog.algomaster.io/i/173210647?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5778b76-ea1a-4592-a48e-60e38ba554c6_1228x1118.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_!nhYM!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5778b76-ea1a-4592-a48e-60e38ba554c6_1228x1118.png 424w, https://substackcdn.com/image/fetch/$s_!nhYM!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5778b76-ea1a-4592-a48e-60e38ba554c6_1228x1118.png 848w, https://substackcdn.com/image/fetch/$s_!nhYM!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5778b76-ea1a-4592-a48e-60e38ba554c6_1228x1118.png 1272w, https://substackcdn.com/image/fetch/$s_!nhYM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5778b76-ea1a-4592-a48e-60e38ba554c6_1228x1118.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 typical token validation flow at the gateway looks like this:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:&quot;aa9646f9-e377-442d-88df-a83b8b80c765&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python">def authenticate_request(request):
    token = request.headers.get("Authorization", "").replace("Bearer ", "")

    if not token:
        return {"status": 401, "error": "Missing token"}

    try:
        # Verify JWT signature and decode claims
        payload = jwt.decode(token, PUBLIC_KEY, algorithms=["RS256"])

        # Check token expiration
        if payload["exp"] &lt; current_time():
            return {"status": 401, "error": "Token expired"}

        # Check if user has required role for this endpoint
        required_role = get_required_role(request.path, request.method)
        if required_role not in payload.get("roles", []):
            return {"status": 403, "error": "Insufficient permissions"}

        # Attach user context for downstream services
        request.headers["X-User-ID"] = payload["sub"]
        request.headers["X-User-Roles"] = ",".join(payload["roles"])
        return {"status": 200, "user": payload}

    except jwt.InvalidTokenError:
        return {"status": 401, "error": "Invalid token"}</code></pre></div><p>Gateways can also support <strong>API keys</strong> for internal services and <strong>OAuth 2.0</strong> flows for third-party integrations. The key idea is simple: enforce security once, at the edge, instead of reimplementing it everywhere.</p><p>Once you know who the client is and what they can do, the next challenge is controlling how much they can do without overwhelming your system.</p><div><hr></div><h1>3. Rate Limiting and Throttling</h1>
      <p>
          <a href="https://blog.algomaster.io/p/top-10-api-gateway-use-cases">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[How to build an autonomous AI agent like OpenClaw (from scratch)]]></title><description><![CDATA[This is a guest post by Dr.]]></description><link>https://blog.algomaster.io/p/how-to-build-an-autonomous-ai-agent-like-openclaw</link><guid isPermaLink="false">https://blog.algomaster.io/p/how-to-build-an-autonomous-ai-agent-like-openclaw</guid><dc:creator><![CDATA[Ashish Pratap Singh]]></dc:creator><pubDate>Tue, 07 Apr 2026 04:20:00 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!Mwz8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe097243e-193b-4d8d-9b10-d026f7abacf2_2354x1168.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>This is a guest post by <a href="https://www.linkedin.com/in/ashishbamania/">Dr. Ashish Bamania</a>. He&#8217;s an AI engineer and author of multiple newsletters including <a href="https://www.intoai.pub/">Into AI</a> and <a href="https://www.intoquantum.pub/">Into Quantum</a>.</p><div><hr></div><p>OpenClaw is one of the craziest AI tools launched this year. It became so popular that people started <a href="https://www.businessinsider.com/apple-mac-mini-having-a-moment-openclaw-craze-2026-2">hoarding Mac minis</a> to run it, and its founder, Peter Steinberger, was hired by OpenAI.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Mwz8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe097243e-193b-4d8d-9b10-d026f7abacf2_2354x1168.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Mwz8!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe097243e-193b-4d8d-9b10-d026f7abacf2_2354x1168.png 424w, https://substackcdn.com/image/fetch/$s_!Mwz8!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe097243e-193b-4d8d-9b10-d026f7abacf2_2354x1168.png 848w, https://substackcdn.com/image/fetch/$s_!Mwz8!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe097243e-193b-4d8d-9b10-d026f7abacf2_2354x1168.png 1272w, https://substackcdn.com/image/fetch/$s_!Mwz8!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe097243e-193b-4d8d-9b10-d026f7abacf2_2354x1168.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Mwz8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe097243e-193b-4d8d-9b10-d026f7abacf2_2354x1168.png" width="1456" height="722" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e097243e-193b-4d8d-9b10-d026f7abacf2_2354x1168.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:722,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:829024,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://www.intoai.pub/i/191856057?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe097243e-193b-4d8d-9b10-d026f7abacf2_2354x1168.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_!Mwz8!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe097243e-193b-4d8d-9b10-d026f7abacf2_2354x1168.png 424w, https://substackcdn.com/image/fetch/$s_!Mwz8!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe097243e-193b-4d8d-9b10-d026f7abacf2_2354x1168.png 848w, https://substackcdn.com/image/fetch/$s_!Mwz8!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe097243e-193b-4d8d-9b10-d026f7abacf2_2354x1168.png 1272w, https://substackcdn.com/image/fetch/$s_!Mwz8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe097243e-193b-4d8d-9b10-d026f7abacf2_2354x1168.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>If you haven&#8217;t yet heard of it, <a href="https://openclaw.ai/">OpenClaw</a> is a free and <a href="https://github.com/openclaw/openclaw">open-source</a> autonomous AI agent that can complete tasks for you. It can read your inbox, send emails, manage your calendar, and check you in for flights, all from WhatsApp, Telegram, or any chat app that you already use. (<em>That&#8217;s how the official website describes it.</em>)</p><p>A large audience believes that OpenClaw could be AGI. This is one of the reasons (besides my genuine curiosity about disassembling its components) why I decided to rebuild a simple version of it and teach you everything from scratch.</p><p>Let&#8217;s build &#8220;Tiny-Openclaw&#8221;!</p><div><hr></div><h3><strong>What Are We Building?</strong></h3><p>Before we begin, we need to know what the real OpenClaw can do.</p><ul><li><p>It can run on any Mac/ Windows/ Linux machine and use proprietary or local LLMs.</p></li><li><p>One can talk to it using any chat app.</p></li><li><p>It remembers your conversations and preferences (this means that it has persistent memory).</p></li><li><p>It can browse the internet, fill forms, and extract data from websites.</p></li><li><p>It has full access to all the files on your computer.</p></li><li><p>It can use <a href="https://www.intoai.pub/p/claude-skills">Skills</a> (either built by you or the community), which are simply bundles of instructions, scripts, and resources that help an AI agent to complete a specific task.</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_!ZCi6!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcaa81af1-e59c-4ff0-9d6b-91f14a6c7ae8_2658x1166.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ZCi6!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcaa81af1-e59c-4ff0-9d6b-91f14a6c7ae8_2658x1166.png 424w, https://substackcdn.com/image/fetch/$s_!ZCi6!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcaa81af1-e59c-4ff0-9d6b-91f14a6c7ae8_2658x1166.png 848w, https://substackcdn.com/image/fetch/$s_!ZCi6!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcaa81af1-e59c-4ff0-9d6b-91f14a6c7ae8_2658x1166.png 1272w, https://substackcdn.com/image/fetch/$s_!ZCi6!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcaa81af1-e59c-4ff0-9d6b-91f14a6c7ae8_2658x1166.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ZCi6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcaa81af1-e59c-4ff0-9d6b-91f14a6c7ae8_2658x1166.png" width="725.8125" height="318.5399639423077" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/caa81af1-e59c-4ff0-9d6b-91f14a6c7ae8_2658x1166.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:639,&quot;width&quot;:1456,&quot;resizeWidth&quot;:725.8125,&quot;bytes&quot;:521510,&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/191856057?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcaa81af1-e59c-4ff0-9d6b-91f14a6c7ae8_2658x1166.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:&quot;center&quot;,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!ZCi6!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcaa81af1-e59c-4ff0-9d6b-91f14a6c7ae8_2658x1166.png 424w, https://substackcdn.com/image/fetch/$s_!ZCi6!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcaa81af1-e59c-4ff0-9d6b-91f14a6c7ae8_2658x1166.png 848w, https://substackcdn.com/image/fetch/$s_!ZCi6!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcaa81af1-e59c-4ff0-9d6b-91f14a6c7ae8_2658x1166.png 1272w, https://substackcdn.com/image/fetch/$s_!ZCi6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcaa81af1-e59c-4ff0-9d6b-91f14a6c7ae8_2658x1166.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://openclaw.ai/">Source</a></figcaption></figure></div><p>Similarly, our tiny version of OpenClaw, called &#8220;Tiny-OpenClaw&#8221;:</p><ul><li><p>Runs on a Mac/ Windows/ Linux machine</p></li><li><p>Can browse the internet, fill forms, and gather data from websites</p></li><li><p>Uses <a href="https://www.intoai.pub/p/claude-skills">Skills</a></p></li><li><p>Has persistent memory</p></li><li><p>One can use Telegram to communicate with it</p></li></ul><p>Tiny-OpenClaw does not have full system access on a machine, as it poses significant security risks, and this tutorial is not intended for creating an AI bot for production use.</p><div><hr></div><h3><strong>Components That Make Up Tiny-OpenClaw</strong></h3><p>Before we start coding, let&#8217;s understand the 8 components that make up Tiny-OpenClaw.</p><ol><li><p><strong>Telegram Channel</strong>: This is an adapter specific to the messaging platform that translates messages from the platform&#8217;s format to a standard format that OpenClaw can work with.</p></li><li><p><strong>Session Manager</strong>: This manages separate sessions and conversation histories per user.</p></li><li><p><strong>Agent runtime</strong>: This is a loop that sends prompt and context to an LLM agent, runs tools if needed, and returns a final answer.</p></li><li><p><strong>Memory</strong>: This is the storage that helps persist a user&#8217;s data across different chat sessions.</p></li><li><p><strong>SOUL.md</strong>: This markdown file defines the agent&#8217;s personality and operating rules.</p></li><li><p><strong>Skills</strong>: These are folders containing instructions, scripts, and resources to help complete a specific task.</p></li><li><p><strong>Skills loader</strong>: This looks for the available Skills at startup, reads each Skill&#8217;s description and tools, and routes tool calls from the LLM to the right handler.</p></li><li><p><strong>Context builder</strong>: This combines the following and returns context for the LLM:</p><ul><li><p><code>SOUL.md</code></p></li><li><p>Skill descriptions</p></li><li><p>Saved memory about the user</p></li><li><p>Current time</p></li></ul></li></ol><p>We will build these one by one.</p><p>The following diagram shows how these components connect 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_!6uJu!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7299f5db-44a6-49b5-b71e-a2c9a8cc5fc4_2266x1098.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!6uJu!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7299f5db-44a6-49b5-b71e-a2c9a8cc5fc4_2266x1098.png 424w, https://substackcdn.com/image/fetch/$s_!6uJu!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7299f5db-44a6-49b5-b71e-a2c9a8cc5fc4_2266x1098.png 848w, https://substackcdn.com/image/fetch/$s_!6uJu!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7299f5db-44a6-49b5-b71e-a2c9a8cc5fc4_2266x1098.png 1272w, https://substackcdn.com/image/fetch/$s_!6uJu!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7299f5db-44a6-49b5-b71e-a2c9a8cc5fc4_2266x1098.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!6uJu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7299f5db-44a6-49b5-b71e-a2c9a8cc5fc4_2266x1098.png" width="1456" height="706" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7299f5db-44a6-49b5-b71e-a2c9a8cc5fc4_2266x1098.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:706,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:216339,&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/191856057?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7299f5db-44a6-49b5-b71e-a2c9a8cc5fc4_2266x1098.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_!6uJu!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7299f5db-44a6-49b5-b71e-a2c9a8cc5fc4_2266x1098.png 424w, https://substackcdn.com/image/fetch/$s_!6uJu!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7299f5db-44a6-49b5-b71e-a2c9a8cc5fc4_2266x1098.png 848w, https://substackcdn.com/image/fetch/$s_!6uJu!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7299f5db-44a6-49b5-b71e-a2c9a8cc5fc4_2266x1098.png 1272w, https://substackcdn.com/image/fetch/$s_!6uJu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7299f5db-44a6-49b5-b71e-a2c9a8cc5fc4_2266x1098.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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">Architecture of Tiny-OpenClaw</figcaption></figure></div><div><hr></div><p>Before we start, I want to introduce you to my book, <strong>LLMs In 100 Images</strong>, which is a collection of 100 easy-to-follow visuals that explain the most important concepts you need to master to understand LLMs today.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://gumroad.com/a/440621971/yasxkv&quot;,&quot;text&quot;:&quot;Grab your copy&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://gumroad.com/a/440621971/yasxkv"><span>Grab your copy</span></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_!_ysS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faac3d2c1-d1f6-4907-8bf1-b2ca3719e2f9_2400x1200.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!_ysS!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faac3d2c1-d1f6-4907-8bf1-b2ca3719e2f9_2400x1200.png 424w, https://substackcdn.com/image/fetch/$s_!_ysS!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faac3d2c1-d1f6-4907-8bf1-b2ca3719e2f9_2400x1200.png 848w, https://substackcdn.com/image/fetch/$s_!_ysS!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faac3d2c1-d1f6-4907-8bf1-b2ca3719e2f9_2400x1200.png 1272w, https://substackcdn.com/image/fetch/$s_!_ysS!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faac3d2c1-d1f6-4907-8bf1-b2ca3719e2f9_2400x1200.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!_ysS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faac3d2c1-d1f6-4907-8bf1-b2ca3719e2f9_2400x1200.png" width="1456" height="728" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/aac3d2c1-d1f6-4907-8bf1-b2ca3719e2f9_2400x1200.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:728,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;: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_!_ysS!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faac3d2c1-d1f6-4907-8bf1-b2ca3719e2f9_2400x1200.png 424w, https://substackcdn.com/image/fetch/$s_!_ysS!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faac3d2c1-d1f6-4907-8bf1-b2ca3719e2f9_2400x1200.png 848w, https://substackcdn.com/image/fetch/$s_!_ysS!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faac3d2c1-d1f6-4907-8bf1-b2ca3719e2f9_2400x1200.png 1272w, https://substackcdn.com/image/fetch/$s_!_ysS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faac3d2c1-d1f6-4907-8bf1-b2ca3719e2f9_2400x1200.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 move forward!</p><div><hr></div><h3><strong>1. Creating the Project</strong></h3><p>Start by typing the following bash commands in your terminal to create the scaffold for the project.</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;bash&quot;,&quot;nodeId&quot;:&quot;a0f72042-61f7-4398-92ef-834d32bf9d2f&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-bash"># Create project folder
mkdir tiny-openclaw &amp;&amp; cd tiny-openclaw

# Create folders for skills and frontend
mkdir -p skills/datetime skills/memory_work skills/browser_use

# Create core component files
touch main.py agent_runtime.py context_builder.py session_manager.py telegram_channel.py memory_store.py skill_loader.py SOUL.md .env

# Create datetime skill files
touch skills/datetime/SKILL.md skills/datetime/handler.py

# Create memory note skill files
touch skills/memory_work/SKILL.md skills/memory_work/handler.py

# Create Browser use skill files
touch skills/browser_use/SKILL.md skills/browser_use/handler.py</code></pre></div><p>Next, create a virtual environment and install all the dependencies using <a href="https://docs.astral.sh/uv/">uv</a> as follows.</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;bash&quot;,&quot;nodeId&quot;:&quot;7904a202-420d-4340-a43e-b73566d9ed9e&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-bash"># Create and activate virtual environment
uv venv
source .venv/bin/activate

# Install dependencies with uv
uv pip install httpx python-dotenv python-telegram-bot playwright

# Download the Chromium browser binary that Playwright needs for the Browser use skill
playwright install chromium</code></pre></div><div><hr></div><h3><strong>2. Building Memory</strong></h3><p>Tiny-OpenClaw&#8217;s memory is a simple key-value store (dictionary) that persists data as a JSON file on disk. It is used to store user preferences and facts for the LLM agent to retrieve later.</p><p>(Feel free to use an in-memory database like <a href="https://redis.io/about/">Redis</a> if you prefer it over the simple dictionary we are using here.)</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:&quot;2c6f4131-ce71-49d0-8be5-3464ba354748&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python"># ./memory_store.py

import json
import os

# Key-value store
class Memory:
    def __init__(self, path="MEMORY.json"):
        self.path = path

        # Load existing memory from disk if available
        if os.path.exists(path):
            with open(path) as f:
                self._data = json.load(f)
        else:
            self._data = {} # Dictionary used to store user memories

    # Set a key-value pair
    def set(self, key, value):
        self._data[key] = value
        self._save()

    # Get a value by key
    def get(self, key):
        return self._data.get(key)

    # Get all keys
    def keys(self):
        return list(self._data.keys())

    # Save memory to disk
    def _save(self):
        with open(self.path, "w") as f:
            json.dump(self._data, f, indent=2, default=str)</code></pre></div><div><hr></div><h3><strong>3. Building the Session Manager</strong></h3><p>The Session manager&#8217;s job is to create and track a separate conversation history for each user. It works like this:</p><ul><li><p>When a user connects to Tiny-Openclaw, it creates a session using their client ID and channel (which could look like <code>telegram:123</code>) to keep their conversations separate.</p></li><li><p>All messages (from the user and the LLM assistant) are added to that session&#8217;s history. This history is sent to the LLM as context on every turn, so that it knows what the user has been chatting about.</p></li><li><p>Sessions are saved to disk as a JSON file (<code>SESSIONS.json</code>) so that the conversations aren&#8217;t lost when the system restarts.</p></li></ul><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:&quot;dccbf469-0755-4242-ba91-0df76bc80368&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python"># ./session_manager.py

import json
import os
import time

class SessionManager:
    def __init__(self, path="SESSIONS.json"):
        self.path = path

        # Load sessions from the disk if available
        if os.path.exists(path):
            with open(path) as f:
                self.sessions = json.load(f)
            print(f" Restored previous session(s) from disk!")
        else:
            self.sessions = {}

    # Find an existing session or create a new one 
    def get_or_create_session(self, client_id, channel):
        session_id = f"{channel}:{client_id}" 

        if session_id not in self.sessions:
            self.sessions[session_id] = {
                "client_id": client_id,
                "channel": channel,
                "created_at": time.time(),
                "history": [],
            }

        return session_id

    # Append a message from user or LLM to the session history
    def add_message(self, session_id, message):
        session = self.sessions.get(session_id)
        if session:
            session["history"].append(message)
            self._save()

    # Return the full conversation history for a session to send to LLM as context on every turn 
    def get_history(self, session_id):
        session = self.sessions.get(session_id)
        return session["history"] if session else []

    # Save sessions to disk
    def _save(self):
        with open(self.path, "w") as f:
            json.dump(self.sessions, f, indent=2, default=str)</code></pre></div><p>A sample <code>SESSION.json</code> file is shown below to show what it stores.</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;json&quot;,&quot;nodeId&quot;:&quot;4fc6ff8b-41eb-41e8-8513-0605df8f449d&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-json">{
  "telegram:1191237804": {
    "client_id": "1191237804",
    "channel": "telegram",
    "created_at": 1774270494.7631621,
    "history": [
      {
        "role": "user",
        "content": "Hi!",
        "timestamp": 1774270494.7631638
      },
      {
        "role": "assistant",
        "content": "Hello! I'm your personal AI assistant. What can I help you with today?",
        "timestamp": 1774270497.646961
      },
      {
        "role": "user",
        "content": "Remember my name is ashish",
        "timestamp": 1774270609.259111
      },
      {
        "role": "assistant",
        "content": "Perfect! I've saved your name as Ashish in my memory. I'll remember this for future conversations. Nice to meet you, Ashish!",
        "timestamp": 1774270611.7315981
      }
    ]
  }
}</code></pre></div><div><hr></div><h3><strong>4. Setting Up Skills</strong></h3><p><a href="https://www.intoai.pub/p/claude-skills">Skills</a> give Tiny-OpenClaw the ability to solve specific tasks. Each Skill is implemented as a folder with two files:</p><ul><li><p><strong>SKILL.md</strong>: A Markdown file that contains the name and short description of the Skill. These are appended to the System prompt so the LLM knows this Skill exists and when to use it.</p></li><li><p><strong>handler.py</strong>: The code that executes when the LLM decides to use a particular Skill</p></li></ul><p>What&#8217;s interesting is that instead of hardcoding the logic, we let Tiny-OpenClaw know which Skills it has access to and let it figure out on its own whether to use them or not during a conversation turn.</p><p>We will be building three Skills for this project as follows:</p><ol><li><p><strong>Date/Time: </strong>Helps find the current date and time</p></li><li><p><strong>Memory work: </strong>Helps save personal notes about a user in memory</p></li><li><p><strong>Browser Use: </strong>Helps visit websites, extracts text content, clicks elements, and fills forms.</p></li></ol><div><hr></div><h4><strong>1. Date/Time Skill</strong></h4><p>Here is the <code>skills/datetime/SKILL.md</code> file for this Skill.</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;markdown&quot;,&quot;nodeId&quot;:&quot;0e55fbfe-4223-4ea8-bcd1-0bc9240dd0af&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-markdown">---
name: datetime
description: Get the current date and time.
---</code></pre></div><p>The <code>handler.py</code> for this Skill is as follows.</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:&quot;405081d8-3d2d-41e3-b0f9-f17425fabc9b&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python"># ./skills/datetime/handler.py

from datetime import datetime, timezone

# Tool definition to tell the agent about the available 'get_current_datetime' tool
tools = [
    {
        "name": "get_current_datetime",
        "description": "Get the current date and time.",
        "parameters": {
            "type": "object",
            "properties": {},
            "required": [],
        },
    }
]

# Function called when the agent invokes this tool
async def execute(tool_name, tool_input, context):
    if tool_name == "get_current_datetime":
        # Get the current date and time
        now = datetime.now(timezone.utc)

        # Return a human-readable format 
        return {
            "readable": now.strftime("%A, %B %d, %Y %I:%M:%S %p UTC"),
        }

    return {"error": f"Unknown tool: {tool_name}"}</code></pre></div><div><hr></div><h4><strong>2. Memory work Skill</strong></h4><p>Here is the <code>skills/memory_work/SKILL.md</code> file for this Skill.</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;markdown&quot;,&quot;nodeId&quot;:&quot;556bfab8-95c1-42cf-88d7-cecab7d61a02&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-markdown">---
name: memory_work
description: Save a note to the user&#8217;s personal memory.
---</code></pre></div><p>The <code>handler.py</code> for this Skill is as follows.</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:&quot;c4ad2083-c463-409c-9a0c-11ed2c826d93&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python"># ./skills/memory_work/handler.py

# Tool definition to tell the agent about the available 'save_note' tool
tools = [
    {
        "name": "save_note",
        "description": "Save a note or fact about the user to memory.",
        "parameters": {
            "type": "object",
            "properties": {
                "key": {"type": "string", "description": "Short descriptive key"},
                "content": {"type": "string", "description": "Note content"},
            },
            "required": ["key", "content"],
        },
    },
]

# Function called when the agent invokes this tool
async def execute(tool_name, tool_input, context):
    memory = context["memory"]

    if tool_name == "save_note":
        # Save to memory
        memory.set(f"note:{tool_input['key']}", {
            "content": tool_input["content"],
        })

        return {"success": True, "key": tool_input["key"]}

    return {"error": f"Unknown tool: {tool_name}"}</code></pre></div><div><hr></div><h4><strong>3. Browser Use Skill</strong></h4><p>Here is the <code>skills/browser_use/SKILL.md</code> file for this Skill.</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;markdown&quot;,&quot;nodeId&quot;:&quot;44fc5e52-893b-4825-846f-5d000dbf4bdc&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-markdown">---
name: browser_use
description: Browse the web, extract text from webpages, click elements, and fill and submit forms. Use when the user asks to visit a website, read a page, or interact with web content.
---</code></pre></div><p>The <code>handler.py</code> for this Skill uses <a href="https://playwright.dev/">Playwright</a>, a library for browser automation that gives Tiny-OpenClaw the ability to work with webpages.</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:&quot;77d888b4-c6dd-4844-9e8d-f3b105028db2&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python"># ./skills/browser_use/handler.py

from playwright.async_api import async_playwright

# Global browser state that is initialized on first tool call
_browser = None
_page = None

async def _get_page():
    global _browser, _page

    # If a browser and page are already active, reuse them instead of reopening
    if _browser and _page:
        return _page

    # Start Playwright
    pw = await async_playwright().start()

    # Launch a new Chromium browser instance
    # 'headless=True' means that the browser window will not be visible during execution
    _browser = await pw.chromium.launch(headless=True)

    # Open a new page (tab) in the launched browser
    _page = await _browser.new_page()

    return _page</code></pre></div><p>We add the definitions of all available tools next to this file.</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:&quot;726e5a77-73ed-4f35-aa24-ea0985d4f45d&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python"># ./skills/browser_use/handler.py (continued)

# Tool definitions for available tools
tools = [
    {
        "name": "browse_url",
        "description": "Navigate to a URL and return the page title and text content.",
        "parameters": {
            "type": "object",
            "properties": {
                "url": {"type": "string", "description": "The URL to visit"},
            },
            "required": ["url"],
        },
    },
    {
        "name": "click_element",
        "description": "Click an element on the page by CSS selector or text.",
        "parameters": {
            "type": "object",
            "properties": {
                "selector": {
                    "type": "string",
                    "description": "CSS selector or text content, e.g. 'button.submit' or 'text=Sign In'",
                },
            },
            "required": ["selector"],
        },
    },
    {
        "name": "fill_input",
        "description": "Type text into an input field.",
        "parameters": {
            "type": "object",
            "properties": {
                "selector": {"type": "string", "description": "CSS selector for the input"},
                "text": {"type": "string", "description": "Text to type"},
            },
            "required": ["selector", "text"],
        },
    },
    {
        "name": "get_page_content",
        "description": "Get the text content of the current page or a specific element.",
        "parameters": {
            "type": "object",
            "properties": {
                "selector": {
                    "type": "string",
                    "description": "Optional CSS selector to extract text from, e.g. '#title' or '.content' If empty, returns full page text.",
                },
            },
            "required": [],
        },
    },
]</code></pre></div><p>And then we add the functions that are executed when a tool is called.</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:&quot;46315308-8221-4e44-bdd8-31820431b3bc&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python"># ./skills/browser_use/handler.py (continued)

# Function called when the agent invokes a tool
async def execute(tool_name, tool_input, context):
    try:
        # Create a browser page
        page = await _get_page()

        if tool_name == "browse_url":
            url = tool_input["url"] # Extract the URL from the tool input

            # Add "https://" if the URL doesn&#8217;t already include it
            if not url.startswith("http"):
                url = "https://" + url 
            
            # Visit URL ('wait_until' ensures the DOM is ready, 'timeout' prevent hanging indefinitely)
            await page.goto(url, wait_until="domcontentloaded", timeout=10000)

            # Get the page title
            title = await page.title()

            # Get the all text from the &lt;body&gt; element
            text = await page.inner_text("body")

            # Return a structured response
            return {
                "title": title,
                "url": page.url,
                "content_preview": text.strip()[:3000],  # Trim to stay within LLM context limits
            }

        elif tool_name == "click_element":
            # Click using a CSS selector ('timeout' prevent hanging if element isn't found)
            await page.click(tool_input["selector"], timeout=3000)
            
            # Wait for page to update after the click
            await page.wait_for_load_state("domcontentloaded")

            # Return a structured response
            return {
                "clicked": tool_input["selector"],
                "new_url": page.url,
                "new_title": await page.title(),
            }

        elif tool_name == "fill_input":
            # Fill the specified input field with given text
            await page.fill(tool_input["selector"], tool_input["text"])
            
            # Return a structured response for confirmation
            return {
                "filled": tool_input["selector"],
                "text": tool_input["text"],
            }

        elif tool_name == "get_page_content":
            # Use the given selector or the page body
            selector = tool_input.get("selector") or "body"

            # Extract text from selected element 
            text = await page.inner_text(selector)

            # Return trimmed content to stay within LLM context limits
            return {
                "url": page.url,
                "content": text.strip()[:5000],
            }
        
        # Handle error for unknown tool
        return {"error": f"Unknown tool: {tool_name}"}

    except Exception as e:
        return {"error": str(e)}</code></pre></div><div><hr></div><h3><strong>5. Building the Skill Loader</strong></h3><p>The Skill loader goes through each Skill and:</p><ul><li><p>Reads its <code>SKILL.md</code> to get its name and description</p></li><li><p>Imports its <code>handler.py</code> to get the tool definitions and the execute function</p></li><li><p>Later, when Tiny-OpenClaw decides to call a tool, the Skill loader figures out which Skill owns that tool and runs its handler.</p></li></ul><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:&quot;841c2b55-e518-488b-af2c-a3031ee42ba2&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python">#./skill_loader.py

import os
import importlib.util

class SkillLoader:
    def __init__(self):
        self.skills = {}

    # Scan the 'Skills' folder and load each Skill
    def load_from_directory(self, skills_dir):
        if not os.path.isdir(skills_dir):
            print("No Skills directory found.")
            return

        for entry in os.listdir(skills_dir):
            skill_dir = os.path.join(skills_dir, entry)
            skill_md = os.path.join(skill_dir, "SKILL.md")
            handler_py = os.path.join(skill_dir, "handler.py")

            # Skip if folder doesn't have both required files
            if not os.path.isdir(skill_dir):
                continue
            if not os.path.exists(skill_md) or not os.path.exists(handler_py):
                continue

            try:
                # Read name and description from SKILL.md
                with open(skill_md) as f:
                    name, description = self._parse_skill_md(f.read())

                # Import handler.py at runtime
                # Tell Python where the file is
                spec = importlib.util.spec_from_file_location(f"skill_{entry}", handler_py)
                
                # Create an empty module from that spec
                module = importlib.util.module_from_spec(spec)
                
                # Run the file and fill the module with its contents
                spec.loader.exec_module(module)

                # Get the tools list and execute function from the loaded module
                self.skills[name] = {
                    "name": name,
                    "description": description,
                    "tools": getattr(module, "tools", []),
                    "execute": getattr(module, "execute", None),
                }

                print(f"Skill Loaded: {name}")

            except Exception as e:
                print(f"Failed to load {entry}: {e}")

    # Helper function to get Skill names and descriptions for the system prompt
    def get_active_skills(self):
        return [
            {"name": s["name"], "description": s["description"]}
            for s in self.skills.values()
        ]

    # All tool definitions from all skills, sent to the LLM
    def get_tools(self):
        tools = []

        for skill in self.skills.values():
            tools.extend(skill["tools"])

        return tools

    # Find which skill owns this tool and run it
    async def execute_tool(self, tool_name, tool_input, context):
        for skill in self.skills.values():
            if any(t["name"] == tool_name for t in skill["tools"]):
                if skill["execute"]:
                    return await skill["execute"](tool_name, tool_input, context)

        return {"error": f"Unknown tool: {tool_name}"}

    # Extract name and description from SKILL.md frontmatter
    def _parse_skill_md(self, content):
        # Defaults
        name = "unknown"       
        description = ""

        for line in content.split("\n"):
            if line.startswith("name:"):
                name = line.split(":", 1)[1].strip()
            elif line.startswith("description:"):
                description = line.split(":", 1)[1].strip()

        return name, description</code></pre></div><div><hr></div><h3><strong>6. Giving the Bot a Personality</strong></h3><p>We use a Markdown file called <code>SOUL.md</code> to give Tiny-OpenClaw its personality characteristics and operating rules.</p><p>Note that the original OpenClaw uses various workspace files, such as <code>SOUL.md</code>, <code>AGENTS.md</code>, <code>USER.md</code> and <code>IDENTITY.md</code> for different functions, but we just stick to one.</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;markdown&quot;,&quot;nodeId&quot;:&quot;f5a4d21c-f459-4eba-9e36-bbe9b27fbdf6&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-markdown"># Soul
You are Tiny-OpenClaw, a personal AI assistant running on the user's own machine. You have access to tools provided by installed skills.

## Personality
- Friendly, concise and occassionally funny
- Use a casual tone like when texting a smart friend
- When unsure, say so honestly, rather than making facts up

## Rules
- When saving notes, use short consistent keys like "name", "location", "job"
- When searching the web, always use DuckDuckGo instead of Google
- Use available tools wherever necessary
- Never run destructive commands without asking first
- Keep responses under 300 words unless asked for detail</code></pre></div><div><hr></div><h3><strong>7. Setting Up the Context Builder</strong></h3><p>The Context builder assembles everything Tiny-OpenClaw needs to know before responding.</p><p>It combines the following into a single System prompt sent with every LLM call to provide all the essential context.</p><ul><li><p><code>SOUL.md</code></p></li><li><p>Skill names and descriptions</p></li><li><p>Saved memory about the user</p></li><li><p>Current time</p></li></ul><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:&quot;107a5c2b-f495-4800-ae7d-24fe2d346d99&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python"># ./context_builder.py

import os
from datetime import datetime, timezone

BASE_PROMPT = """You are a helpful personal AI assistant powered by Tiny OpenClaw.
Be concise, friendly, and helpful. Use tools when they would help."""

# Load SOUL.md
def load_soul():
    # Path to SOUL.md
    soul_path = os.path.join(os.path.dirname(__file__), "SOUL.md")
    
    # Open the file
    try:
        with open(soul_path, "r") as f:
            return f.read()
    except FileNotFoundError:
        return BASE_PROMPT

# Combine Soul.md, Skills, User memory and Current time into a System prompt
def build_system_prompt(active_skills, memory=None):
    prompt = load_soul() # Load SOUL.md

    # Add name and descriptions of available Skills
    if active_skills:
        prompt += "\n\n## Available Skills\n"
        for skill in active_skills:
            prompt += f"### {skill['name']}\n"
            prompt += f"{skill['description']}\n\n"

    # Add details from saved memory about the user
    if memory:
        prefix = "note:"
        notes = {
            k[len(prefix):]: memory.get(k)
            for k in memory.keys()
            if k.startswith(prefix)
        }

        if notes:
            prompt += "\n\n## What you know about the user\n"
            for key, value in notes.items():
                content = value.get("content", value) if isinstance(value, dict) else value
                prompt += f"- {key}: {content}\n"

    # Add current time
    prompt += f"\nCurrent time: {datetime.now(timezone.utc).isoformat()}"

    return prompt</code></pre></div><div><hr></div><h3><strong>8. Getting the Agent Runtime Ready</strong></h3><p>The Agent runtime is the brain of Tiny-OpenClaw. It is based on the <a href="https://arxiv.org/abs/2210.03629">ReAct (Reasoning + Acting)</a> approach, where the loop consists of:</p><ul><li><p><strong>Think</strong>: LLM reads the conversation and decides its action</p></li><li><p><strong>Act</strong>: Calls a tool if required</p></li><li><p><strong>Observe</strong>: Reads the tool results</p></li><li><p><strong>Repeat</strong>: Goes back to the &#8216;Think&#8217; step until a final answer is generated</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_!3Gio!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7c841f9-b571-462d-bc7c-f1f1afed83cd_2750x1050.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!3Gio!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7c841f9-b571-462d-bc7c-f1f1afed83cd_2750x1050.png 424w, https://substackcdn.com/image/fetch/$s_!3Gio!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7c841f9-b571-462d-bc7c-f1f1afed83cd_2750x1050.png 848w, https://substackcdn.com/image/fetch/$s_!3Gio!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7c841f9-b571-462d-bc7c-f1f1afed83cd_2750x1050.png 1272w, https://substackcdn.com/image/fetch/$s_!3Gio!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7c841f9-b571-462d-bc7c-f1f1afed83cd_2750x1050.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!3Gio!,w_2400,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7c841f9-b571-462d-bc7c-f1f1afed83cd_2750x1050.png" width="1200" height="458.24175824175825" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a7c841f9-b571-462d-bc7c-f1f1afed83cd_2750x1050.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;large&quot;,&quot;height&quot;:556,&quot;width&quot;:1456,&quot;resizeWidth&quot;:1200,&quot;bytes&quot;:667311,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.intoai.pub/i/191856057?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7c841f9-b571-462d-bc7c-f1f1afed83cd_2750x1050.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_!3Gio!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7c841f9-b571-462d-bc7c-f1f1afed83cd_2750x1050.png 424w, https://substackcdn.com/image/fetch/$s_!3Gio!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7c841f9-b571-462d-bc7c-f1f1afed83cd_2750x1050.png 848w, https://substackcdn.com/image/fetch/$s_!3Gio!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7c841f9-b571-462d-bc7c-f1f1afed83cd_2750x1050.png 1272w, https://substackcdn.com/image/fetch/$s_!3Gio!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7c841f9-b571-462d-bc7c-f1f1afed83cd_2750x1050.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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">ReAct vs other prompting approaches (<a href="https://arxiv.org/abs/2210.03629">Source</a>)</figcaption></figure></div><p>In our case, the agent runtime takes the conversation history, builds the system prompt using the context builder, sends it to an LLM, and reads the response.</p><p>If an LLM wants to call a tool, the runtime executes that tool using the Skill loader. It then gives the tool result to the LLM and runs the loop again.</p><p>When the LLM gives a final response, this is returned to the user.</p><p>The loop runs for a maximum of 5 turns to avoid getting stuck in an infinite loop in case the LLM cannot find an answer and keeps making repeated tool calls.</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:&quot;75ca5bef-17ee-46fd-87ba-f951e2ca6fa5&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python"># ./agent_runtime.py

import json
import httpx
from context_builder import build_system_prompt

# Max times the agent can call tools before stopping
MAX_TOOL_ROUNDS = 5

class AgentRuntime:
    def __init__(self, provider, model, api_key, skills, memory):
        self.provider = provider  # LLM provider (we use "anthropic")
        self.model = model        # LLM to use (we use "claude-opus-4-6")
        self.api_key = api_key    # API key for the LLM provider
        self.skills = skills      # Skill loader instance
        self.memory = memory      # Memory store instance

    async def run(self, history, session_id, callbacks):
        # Callback to send the final response to the user (Defined in ./telegram_channel.py)
        on_token = callbacks.get("on_token")

        # Callback to notify the user when a tool is being used (Defined in ./telegram_channel.py)
        on_tool_use = callbacks.get("on_tool_use")

        # Build system prompt 
        system_prompt = build_system_prompt(self.skills.get_active_skills(), self.memory)

        # Convert session history to API message format
        messages = [{"role": m["role"], "content": m["content"]} for m in history]

        # Get tool definitions from all loaded skills
        tools = self.skills.get_tools()

        response = ""
        rounds = 0

        # ReAct loop that keeps going until LLM returns an answer or hits the limit
        while rounds &lt; MAX_TOOL_ROUNDS:
            rounds += 1

            # Send context to LLM and get a result
            result = await self._call_anthropic(
                system_prompt=system_prompt,
                messages=messages,
                tools=tools if tools else None,
            )

            # If the LLM wants to use tools, execute them and loop back
            if result["tool_calls"]:
                # Add the LLM's tool request to the conversation
                messages.append(
                    {"role": "assistant", "content": result["raw_content"]}
                )

                # Run each tool and feed the results back
                for tool_call in result["tool_calls"]:
                    if on_tool_use:
                        await on_tool_use(tool_call["name"], tool_call["input"])

                    # Execute the tool through the skill loader
                    tool_result = await self.skills.execute_tool(
                        tool_call["name"],
                        tool_call["input"],
                        {"session_id": session_id, "memory": self.memory},
                    )

                    # Add tool result to conversation history so the LLM 
                    # can see it in the next round
                    messages.append({
                        "role": "user",
                        "content": [{
                            "type": "tool_result",
                            "tool_use_id": tool_call["id"],
                            "content": json.dumps(tool_result),
                        }],
                    })

                continue  # Start the next loop with the new tool results added

            # If no tools needed, send the final response to the user
            if result["text"]:
                if on_token:
                    await on_token(result["text"])
                response = result["text"]
            
            # Exit once we have a final non-tool response
            break  

        return response

    # Call the Anthropic Messages API
    async def _call_anthropic(self, system_prompt, messages, tools):
        # Request payload (Anthropic separates system prompt from messages)
        body = {
            "model": self.model,
            "max_tokens": 4096,
            "system": system_prompt,
            "messages": messages,
        }

        # Add tool definitions for the loaded Skills
        if tools:
            body["tools"] = [{
                "name": t["name"],
                "description": t["description"],
                "input_schema": t["parameters"],
            } for t in tools]

        # Make async HTTP request to Anthropic API
        try:
            async with httpx.AsyncClient(timeout=120) as client:
                res = await client.post(
                    "https://api.anthropic.com/v1/messages",
                    headers={
                        "Content-Type": "application/json",
                        "x-api-key": self.api_key,
                        "anthropic-version": "2023-06-01",
                    },
                    json=body,
                )
        except httpx.ConnectError as e:
            raise Exception(f"Could not connect to Anthropic API: {e}")
        except httpx.TimeoutException as e:
            raise Exception(f"Anthropic API timed out: {e}")

        # Throw if the API returned an error
        if res.status_code != 200:
            raise Exception(f"Anthropic API error ({res.status_code}): {res.text}")

        data = res.json()
        text_parts = []
        tool_calls = []

        # Response can contain text blocks, "tool_use" blocks, or both
        for block in data["content"]:
            if block["type"] == "text":
                text_parts.append(block["text"])
            elif block["type"] == "tool_use":
                tool_calls.append({
                    "id": block["id"],
                    "name": block["name"],
                    "input": block["input"],
                })

        # Return normalized output
        return {
            "text": "".join(text_parts),
            "tool_calls": tool_calls or None,
            "raw_content": data["content"],
        }</code></pre></div><div><hr></div><h3><strong>9. Setting Up the Telegram Channel</strong></h3><p>The Telegram channel:</p><ul><li><p>Listens for messages from the user on Telegram chat</p></li><li><p>Passes them through the LLM to get a response</p></li><li><p>Sends the reply back to the user on the chat</p></li></ul><p>Alongside this, it uses the Session manager to track each user&#8217;s conversation history separately.</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:&quot;7fff475c-e4bb-48c2-a1ab-9cfdede93a39&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python"># ./telegram_channel.py

import time
import asyncio
from telegram import Update
from telegram.ext import Application, MessageHandler, filters

# Translates between Telegram Bot API and Tiny-OpenClaw
class TelegramChannel:
    def __init__(self, token, agent, sessions):
        self.token = token   # Telegram bot token from @BotFather
        self.agent = agent   # Agent runtime instance
        self.sessions = sessions # Session manager instance

    # Start polling Telegram for new messages
    async def start(self):
        # Build the Telegram bot app using the bot token
        app = Application.builder().token(self.token).build()

        # Listen for messages and route them to _on_message
        app.add_handler(MessageHandler(filters.TEXT, self._on_message))

        # Initialize the bot and start checking for new messages
        await app.initialize()
        await app.start()
        await app.updater.start_polling()

        # Keep the bot running forever
        await asyncio.Future()

    # Called every time a user sends a message to the bot
    async def _on_message(self, update: Update, context):
        # Get the sender's unique chat ID 
        chat_id = str(update.effective_chat.id)

        # Get the text the user sent
        user_text = update.message.text

        # Ignore empty messages
        if not user_text:
            return

        # Get or create one session per Telegram chat using chat_id as the user identifier
        session_id = self.sessions.get_or_create_session(chat_id, "telegram")

        # Save user message to session history
        self.sessions.add_message(session_id, {
            "role": "user",
            "content": user_text,
            "timestamp": time.time(),
        })

        # Show "typing..." indicator in Telegram chat
        await update.effective_chat.send_action("typing")

        try:
            # Get full conversation history for this user
            history = self.sessions.get_history(session_id)

            full_response = ""

            # Callback that the LLM calls for each word it generates
            async def on_token(token):
                nonlocal full_response
                full_response += token

            # Refresh typing indicator when the agent uses a tool
            async def on_tool_use(name, input):
                await update.effective_chat.send_action("typing")

            # Run the ReAct loop
            await self.agent.run(history, session_id, {
                "on_token": on_token,
                "on_tool_use": on_tool_use,
            })

            # Send reply back to Telegram (split if over 4096 chars due to Telegram's limit)
            if full_response:
                for i in range(0, len(full_response), 4096):
                    await update.message.reply_text(full_response[i:i + 4096])

            # Save LLM response to session history
            self.sessions.add_message(session_id, {
                "role": "assistant",
                "content": full_response,
                "timestamp": time.time(),
            })

        # Send error message if something goes wrong
        except Exception as e:
            await update.message.reply_text(f"Error: {e}")</code></pre></div><p>Before we start using the Telegram channel, we need to take the following steps:</p><ul><li><p>Download Telegram and search for <code>@BotFather</code></p></li><li><p>Send it a new message as <code>/newbot</code> to create a new Telegram bot</p></li><li><p>Choose a name (&#8220;Tiny-OpenClaw&#8221;) and username (ending with &#8216;bot&#8217;)</p></li><li><p>Copy the returned token from the chat and add it to the <code>.env</code> file as:</p></li></ul><blockquote><p><code>TELEGRAM_BOT_TOKEN=&lt;your_telegram_bot_token&gt;</code></p></blockquote><div><hr></div><h3><strong>10. Creating the Main Script</strong></h3><p>This script combines all the components that we previously created and makes everything work together.</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:&quot;a91b947c-d3f2-4826-9153-415c1856e17a&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python"># ./main.py

import asyncio
import os
from dotenv import load_dotenv

from memory_store import Memory
from session_manager import SessionManager
from skill_loader import SkillLoader
from agent_runtime import AgentRuntime
from telegram_channel import TelegramChannel

# Load environment variables
load_dotenv()

async def main():
    print("Tiny OpenClaw starting up...")

    # Create the Memory store
    memory = Memory()

    # Create the Session manager 
    sessions = SessionManager()

    # Load all Skills
    skills = SkillLoader()
    skills.load_from_directory(os.path.join(os.path.dirname(__file__), "skills"))

    # Create the agent runtime 
    agent = AgentRuntime(
        provider = os.getenv("MODEL_PROVIDER"),
        model = os.getenv("MODEL_NAME"),
        api_key = os.getenv("ANTHROPIC_API_KEY"), 
        skills = skills,
        memory = memory,
    )

    # Create the Telegram channel and connect it to the LLM agent and sessions
    telegram = TelegramChannel(
        token = os.getenv("TELEGRAM_BOT_TOKEN"),
        agent = agent,
        sessions = sessions,
    )

    print("\nTiny OpenClaw is running on Telegram.")
    print("\nGO CLAW!!! &#129438;&#129438;&#129438;")

    # Start the Telegram bot 
    await telegram.start()

if __name__ == "__main__":
    asyncio.run(main())</code></pre></div><div><hr></div><h3><strong>11. Adding Environment Variables</strong></h3><p>Finally, the following environment variables are set up in the <code>.env</code> file.</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;plaintext&quot;,&quot;nodeId&quot;:&quot;11028d1b-eb83-4b70-b76f-146295cc774a&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-plaintext">ANTHROPIC_API_KEY=&lt;your-key-here&gt;

MODEL_PROVIDER=anthropic

MODEL_NAME=claude-opus-4-6

TELEGRAM_BOT_TOKEN=&lt;your-telegram-token-here&gt;</code></pre></div><p>This completes our build!</p><div><hr></div><h3><strong>12. Running Tiny-OpenClaw</strong></h3><p>We run Tiny-OpenClaw using the following command in the terminal.</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;bash&quot;,&quot;nodeId&quot;:&quot;78322549-c5f6-42e9-b381-8501a426b0fe&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-bash">uv run main.py</code></pre></div><div><hr></div><h3><strong>Tiny-OpenClaw in Action</strong></h3><p>Here are some screenshots of Tiny-OpenClaw performing different tasks using its Skills.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!8-dR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3461c661-e5b7-4d57-a3e3-6dce30ad6727_1155x507.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!8-dR!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3461c661-e5b7-4d57-a3e3-6dce30ad6727_1155x507.png 424w, https://substackcdn.com/image/fetch/$s_!8-dR!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3461c661-e5b7-4d57-a3e3-6dce30ad6727_1155x507.png 848w, https://substackcdn.com/image/fetch/$s_!8-dR!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3461c661-e5b7-4d57-a3e3-6dce30ad6727_1155x507.png 1272w, https://substackcdn.com/image/fetch/$s_!8-dR!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3461c661-e5b7-4d57-a3e3-6dce30ad6727_1155x507.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!8-dR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3461c661-e5b7-4d57-a3e3-6dce30ad6727_1155x507.png" width="1155" height="507" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3461c661-e5b7-4d57-a3e3-6dce30ad6727_1155x507.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:507,&quot;width&quot;:1155,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:267882,&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/191856057?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3461c661-e5b7-4d57-a3e3-6dce30ad6727_1155x507.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_!8-dR!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3461c661-e5b7-4d57-a3e3-6dce30ad6727_1155x507.png 424w, https://substackcdn.com/image/fetch/$s_!8-dR!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3461c661-e5b7-4d57-a3e3-6dce30ad6727_1155x507.png 848w, https://substackcdn.com/image/fetch/$s_!8-dR!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3461c661-e5b7-4d57-a3e3-6dce30ad6727_1155x507.png 1272w, https://substackcdn.com/image/fetch/$s_!8-dR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3461c661-e5b7-4d57-a3e3-6dce30ad6727_1155x507.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Vr5k!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F590eb4e7-5ff1-4674-9a16-084191dbb523_1356x722.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Vr5k!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F590eb4e7-5ff1-4674-9a16-084191dbb523_1356x722.png 424w, https://substackcdn.com/image/fetch/$s_!Vr5k!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F590eb4e7-5ff1-4674-9a16-084191dbb523_1356x722.png 848w, https://substackcdn.com/image/fetch/$s_!Vr5k!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F590eb4e7-5ff1-4674-9a16-084191dbb523_1356x722.png 1272w, https://substackcdn.com/image/fetch/$s_!Vr5k!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F590eb4e7-5ff1-4674-9a16-084191dbb523_1356x722.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Vr5k!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F590eb4e7-5ff1-4674-9a16-084191dbb523_1356x722.png" width="1356" height="722" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/590eb4e7-5ff1-4674-9a16-084191dbb523_1356x722.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:722,&quot;width&quot;:1356,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:634438,&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/191856057?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F590eb4e7-5ff1-4674-9a16-084191dbb523_1356x722.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_!Vr5k!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F590eb4e7-5ff1-4674-9a16-084191dbb523_1356x722.png 424w, https://substackcdn.com/image/fetch/$s_!Vr5k!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F590eb4e7-5ff1-4674-9a16-084191dbb523_1356x722.png 848w, https://substackcdn.com/image/fetch/$s_!Vr5k!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F590eb4e7-5ff1-4674-9a16-084191dbb523_1356x722.png 1272w, https://substackcdn.com/image/fetch/$s_!Vr5k!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F590eb4e7-5ff1-4674-9a16-084191dbb523_1356x722.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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>Super cool, right?</em></p><p><strong>&#129395; Congratulations on building your own tiny version of OpenClaw from scratch!</strong></p><p>&#128230; Here is the GitHub repository that contains all the code for this project: <a href="https://github.com/ashishbamania/Tiny-OpenClaw">Link</a></p>]]></content:encoded></item><item><title><![CDATA[Launching comprehensive resources to master coding interviews]]></title><description><![CDATA[I&#8217;m excited to launch a comprehensive set of resources on algomaster.io to help you master DSA and prepare for coding interviews:]]></description><link>https://blog.algomaster.io/p/launching-comprehensive-resources</link><guid isPermaLink="false">https://blog.algomaster.io/p/launching-comprehensive-resources</guid><dc:creator><![CDATA[Ashish Pratap Singh]]></dc:creator><pubDate>Sun, 05 Apr 2026 13:30:09 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!XQNw!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0295738-83f5-4991-85e4-807193dacebd_2820x1774.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>I&#8217;m excited to launch a comprehensive set of resources on <strong><a href="https://algomaster.io/">algomaster.io</a></strong> to help you master DSA and prepare for coding interviews:</p><ol><li><p><strong><a href="https://algomaster.io/practice/dsa-patterns?tab=am-600">AlgoMaster 600:</a></strong> Added a new list with 300+ additional frequently asked problems covering most topics and patterns.</p></li><li><p><strong><a href="https://algomaster.io/learn/dsa/">DSA Course:</a> </strong>A complete course to learn DSA from scratch and prepare for coding interviews. It includes explanation to interview topics and a more granular classification of problems by patterns to help you build stronger intuition.</p></li><li><p><strong><a href="https://algomaster.io/practice/company/">Company-wise Practice Page:</a> </strong>A dedicated page to practice questions tailored to specific companies.</p></li><li><p><strong><a href="https://algomaster.io/animations/dsa">600+ DSA Animations</a>:</strong> Visualizations for most problems in the AlgoMaster list and key concepts.</p></li><li><p><strong><a href="https://algomaster.io/interview/coding">AI powered Coding Interview Simulator</a>: </strong>A new feature to practice in a realistic interview environment and receive AI-driven feedback on your approach, code quality, and overall problem-solving process.</p></li></ol><p>I&#8217;ve kept a significant portion (~70%) of these resources as free to help the wider community. Many users have found even the free content to outperform most paid courses in both depth and quality.</p><p>For full access you can <strong><a href="https://algomaster.io/premium">upgrade to premium plan</a></strong> at the current discounted price. The Premium plan includes access to all <strong><a href="http://algomaster.io">algomaster.io</a></strong> courses and features.</p><p>I&#8217;ve put a significant amount of effort in creating these resources and I hope you find them helpful.</p><div><hr></div><h1>What&#8217;s Inside?</h1><h2><a href="https://algomaster.io/practice/dsa-patterns?tab=am-600">AlgoMaster 600</a></h2><p>I&#8217;ve added 300+ new problems to create a well-rounded, high-signal problem set covering all major patterns and difficulty levels. Each problem is carefully selected to give you both the breadth and depth needed to master coding interviews.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Cpfo!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02c2f017-74e9-4b7a-be9e-a4abbd517022_2224x1616.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Cpfo!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02c2f017-74e9-4b7a-be9e-a4abbd517022_2224x1616.png 424w, https://substackcdn.com/image/fetch/$s_!Cpfo!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02c2f017-74e9-4b7a-be9e-a4abbd517022_2224x1616.png 848w, https://substackcdn.com/image/fetch/$s_!Cpfo!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02c2f017-74e9-4b7a-be9e-a4abbd517022_2224x1616.png 1272w, https://substackcdn.com/image/fetch/$s_!Cpfo!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02c2f017-74e9-4b7a-be9e-a4abbd517022_2224x1616.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Cpfo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02c2f017-74e9-4b7a-be9e-a4abbd517022_2224x1616.png" width="1456" height="1058" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/02c2f017-74e9-4b7a-be9e-a4abbd517022_2224x1616.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1058,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:340133,&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://blog.algomaster.io/i/193188051?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02c2f017-74e9-4b7a-be9e-a4abbd517022_2224x1616.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_!Cpfo!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02c2f017-74e9-4b7a-be9e-a4abbd517022_2224x1616.png 424w, https://substackcdn.com/image/fetch/$s_!Cpfo!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02c2f017-74e9-4b7a-be9e-a4abbd517022_2224x1616.png 848w, https://substackcdn.com/image/fetch/$s_!Cpfo!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02c2f017-74e9-4b7a-be9e-a4abbd517022_2224x1616.png 1272w, https://substackcdn.com/image/fetch/$s_!Cpfo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02c2f017-74e9-4b7a-be9e-a4abbd517022_2224x1616.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 introduced a new <strong>frequency column</strong> to help you prioritize smarter by focusing on questions that appear more often in interviews.</p><p>You can now solve problems directly on the platform using the <strong>in-built code editor and judge</strong>. Currently it supports Java, Python, C++, C#, JavaScript, and TypeScript with plans to add more languages over time. If you prefer practicing on LeetCode, the original links are still available.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!fwnq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22290d89-5c3a-4259-ac29-1275252af700_3434x1876.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!fwnq!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22290d89-5c3a-4259-ac29-1275252af700_3434x1876.png 424w, https://substackcdn.com/image/fetch/$s_!fwnq!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22290d89-5c3a-4259-ac29-1275252af700_3434x1876.png 848w, https://substackcdn.com/image/fetch/$s_!fwnq!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22290d89-5c3a-4259-ac29-1275252af700_3434x1876.png 1272w, https://substackcdn.com/image/fetch/$s_!fwnq!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22290d89-5c3a-4259-ac29-1275252af700_3434x1876.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!fwnq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22290d89-5c3a-4259-ac29-1275252af700_3434x1876.png" width="1456" height="795" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/22290d89-5c3a-4259-ac29-1275252af700_3434x1876.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:795,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:409154,&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://blog.algomaster.io/i/193188051?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22290d89-5c3a-4259-ac29-1275252af700_3434x1876.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_!fwnq!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22290d89-5c3a-4259-ac29-1275252af700_3434x1876.png 424w, https://substackcdn.com/image/fetch/$s_!fwnq!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22290d89-5c3a-4259-ac29-1275252af700_3434x1876.png 848w, https://substackcdn.com/image/fetch/$s_!fwnq!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22290d89-5c3a-4259-ac29-1275252af700_3434x1876.png 1272w, https://substackcdn.com/image/fetch/$s_!fwnq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22290d89-5c3a-4259-ac29-1275252af700_3434x1876.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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&#8217;s also an <strong>Evaluate</strong> feature that reviews your solution, grades your code, and provides AI-driven feedback to help you improve.</p><div><hr></div><h2><a href="https://algomaster.io/learn/dsa/course-roadmap">DSA Course</a></h2><p>Launching a complete, structured course designed to take you from fundamentals to interview-ready. The course breaks problems down by <strong>patterns and techniques</strong> so you learn how to recognize patterns easily in interviews.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!XQNw!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0295738-83f5-4991-85e4-807193dacebd_2820x1774.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!XQNw!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0295738-83f5-4991-85e4-807193dacebd_2820x1774.png 424w, https://substackcdn.com/image/fetch/$s_!XQNw!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0295738-83f5-4991-85e4-807193dacebd_2820x1774.png 848w, https://substackcdn.com/image/fetch/$s_!XQNw!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0295738-83f5-4991-85e4-807193dacebd_2820x1774.png 1272w, https://substackcdn.com/image/fetch/$s_!XQNw!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0295738-83f5-4991-85e4-807193dacebd_2820x1774.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!XQNw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0295738-83f5-4991-85e4-807193dacebd_2820x1774.png" width="1456" height="916" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a0295738-83f5-4991-85e4-807193dacebd_2820x1774.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:916,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:568295,&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://blog.algomaster.io/i/193188051?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0295738-83f5-4991-85e4-807193dacebd_2820x1774.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_!XQNw!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0295738-83f5-4991-85e4-807193dacebd_2820x1774.png 424w, https://substackcdn.com/image/fetch/$s_!XQNw!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0295738-83f5-4991-85e4-807193dacebd_2820x1774.png 848w, https://substackcdn.com/image/fetch/$s_!XQNw!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0295738-83f5-4991-85e4-807193dacebd_2820x1774.png 1272w, https://substackcdn.com/image/fetch/$s_!XQNw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0295738-83f5-4991-85e4-807193dacebd_2820x1774.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 topic includes curated practice problems, and every solution covers <strong>multiple approaches</strong> along with <strong>clear intuition</strong>, <strong>step-by-step algorithms</strong>, and <strong>animated walkthroughs</strong> to make concepts easy to understand.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Fjej!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F851c11e1-5170-4990-a5e6-a22bbf4d6cb4_2252x1790.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Fjej!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F851c11e1-5170-4990-a5e6-a22bbf4d6cb4_2252x1790.png 424w, https://substackcdn.com/image/fetch/$s_!Fjej!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F851c11e1-5170-4990-a5e6-a22bbf4d6cb4_2252x1790.png 848w, https://substackcdn.com/image/fetch/$s_!Fjej!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F851c11e1-5170-4990-a5e6-a22bbf4d6cb4_2252x1790.png 1272w, https://substackcdn.com/image/fetch/$s_!Fjej!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F851c11e1-5170-4990-a5e6-a22bbf4d6cb4_2252x1790.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Fjej!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F851c11e1-5170-4990-a5e6-a22bbf4d6cb4_2252x1790.png" width="1456" height="1157" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/851c11e1-5170-4990-a5e6-a22bbf4d6cb4_2252x1790.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1157,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:359667,&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://blog.algomaster.io/i/193188051?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F851c11e1-5170-4990-a5e6-a22bbf4d6cb4_2252x1790.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_!Fjej!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F851c11e1-5170-4990-a5e6-a22bbf4d6cb4_2252x1790.png 424w, https://substackcdn.com/image/fetch/$s_!Fjej!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F851c11e1-5170-4990-a5e6-a22bbf4d6cb4_2252x1790.png 848w, https://substackcdn.com/image/fetch/$s_!Fjej!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F851c11e1-5170-4990-a5e6-a22bbf4d6cb4_2252x1790.png 1272w, https://substackcdn.com/image/fetch/$s_!Fjej!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F851c11e1-5170-4990-a5e6-a22bbf4d6cb4_2252x1790.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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><a href="https://algomaster.io/practice/company/">Company-wise Practice Page</a></h2><p>Introducing the company-wise practice page, where you can solve problems commonly asked by specific companies.</p><p>This helps you tailor your preparation to your target companies and get a clear sense of the types of questions they typically ask.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!k3wL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6313670a-73da-48fe-8223-1c5732b2a71c_2526x1170.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!k3wL!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6313670a-73da-48fe-8223-1c5732b2a71c_2526x1170.png 424w, https://substackcdn.com/image/fetch/$s_!k3wL!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6313670a-73da-48fe-8223-1c5732b2a71c_2526x1170.png 848w, https://substackcdn.com/image/fetch/$s_!k3wL!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6313670a-73da-48fe-8223-1c5732b2a71c_2526x1170.png 1272w, https://substackcdn.com/image/fetch/$s_!k3wL!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6313670a-73da-48fe-8223-1c5732b2a71c_2526x1170.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!k3wL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6313670a-73da-48fe-8223-1c5732b2a71c_2526x1170.png" width="1456" height="674" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6313670a-73da-48fe-8223-1c5732b2a71c_2526x1170.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:674,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:266177,&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://blog.algomaster.io/i/193188051?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6313670a-73da-48fe-8223-1c5732b2a71c_2526x1170.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_!k3wL!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6313670a-73da-48fe-8223-1c5732b2a71c_2526x1170.png 424w, https://substackcdn.com/image/fetch/$s_!k3wL!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6313670a-73da-48fe-8223-1c5732b2a71c_2526x1170.png 848w, https://substackcdn.com/image/fetch/$s_!k3wL!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6313670a-73da-48fe-8223-1c5732b2a71c_2526x1170.png 1272w, https://substackcdn.com/image/fetch/$s_!k3wL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6313670a-73da-48fe-8223-1c5732b2a71c_2526x1170.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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>It&#8217;s especially useful in the final phase of preparation when you want to sharpen your focus. The company list will be updated regularly to stay current.</p><div><hr></div><h2><a href="https://algomaster.io/animations/dsa">600+ DSA Animated Visualizations</a></h2><p>Learning algorithms visually is one of the fastest ways to truly understand and retain them. You can grasp the core idea in minutes instead of watching an hour long video.</p><p>I&#8217;ve created 600+ animations that walk you through how data structures and algorithms work step by step.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!VKry!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fad45cf23-1caf-4d25-9916-ffdd952f0fbb_3326x1926.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!VKry!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fad45cf23-1caf-4d25-9916-ffdd952f0fbb_3326x1926.png 424w, https://substackcdn.com/image/fetch/$s_!VKry!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fad45cf23-1caf-4d25-9916-ffdd952f0fbb_3326x1926.png 848w, https://substackcdn.com/image/fetch/$s_!VKry!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fad45cf23-1caf-4d25-9916-ffdd952f0fbb_3326x1926.png 1272w, https://substackcdn.com/image/fetch/$s_!VKry!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fad45cf23-1caf-4d25-9916-ffdd952f0fbb_3326x1926.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!VKry!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fad45cf23-1caf-4d25-9916-ffdd952f0fbb_3326x1926.png" width="1456" height="843" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ad45cf23-1caf-4d25-9916-ffdd952f0fbb_3326x1926.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:843,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:303441,&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://blog.algomaster.io/i/193188051?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fad45cf23-1caf-4d25-9916-ffdd952f0fbb_3326x1926.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_!VKry!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fad45cf23-1caf-4d25-9916-ffdd952f0fbb_3326x1926.png 424w, https://substackcdn.com/image/fetch/$s_!VKry!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fad45cf23-1caf-4d25-9916-ffdd952f0fbb_3326x1926.png 848w, https://substackcdn.com/image/fetch/$s_!VKry!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fad45cf23-1caf-4d25-9916-ffdd952f0fbb_3326x1926.png 1272w, https://substackcdn.com/image/fetch/$s_!VKry!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fad45cf23-1caf-4d25-9916-ffdd952f0fbb_3326x1926.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 visualizations cover most problems in the AlgoMaster list along with core concepts, helping you build intuition much faster than static explanations.</p><div><hr></div><h2><a href="https://algomaster.io/interview/coding">AI powered Coding Interview Simulator</a></h2><p>I&#8217;m excited to introduce an AI-powered coding interview simulator where you can practice in a realistic interview environment.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!qQib!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6cabaa5-86a0-4728-b312-ba8c379aed72_1786x1566.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!qQib!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6cabaa5-86a0-4728-b312-ba8c379aed72_1786x1566.png 424w, https://substackcdn.com/image/fetch/$s_!qQib!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6cabaa5-86a0-4728-b312-ba8c379aed72_1786x1566.png 848w, https://substackcdn.com/image/fetch/$s_!qQib!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6cabaa5-86a0-4728-b312-ba8c379aed72_1786x1566.png 1272w, https://substackcdn.com/image/fetch/$s_!qQib!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6cabaa5-86a0-4728-b312-ba8c379aed72_1786x1566.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!qQib!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6cabaa5-86a0-4728-b312-ba8c379aed72_1786x1566.png" width="1456" height="1277" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f6cabaa5-86a0-4728-b312-ba8c379aed72_1786x1566.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1277,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:294211,&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://blog.algomaster.io/i/193188051?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6cabaa5-86a0-4728-b312-ba8c379aed72_1786x1566.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_!qQib!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6cabaa5-86a0-4728-b312-ba8c379aed72_1786x1566.png 424w, https://substackcdn.com/image/fetch/$s_!qQib!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6cabaa5-86a0-4728-b312-ba8c379aed72_1786x1566.png 848w, https://substackcdn.com/image/fetch/$s_!qQib!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6cabaa5-86a0-4728-b312-ba8c379aed72_1786x1566.png 1272w, https://substackcdn.com/image/fetch/$s_!qQib!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6cabaa5-86a0-4728-b312-ba8c379aed72_1786x1566.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 create and simulate real interview scenarios, solve problems under time pressure, and receive AI-driven feedback on your approach, code quality, and overall problem-solving process. This helps bridge the gap between practice and actual interviews.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!449R!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F222e7488-633f-4e3b-9cad-103c58c2c90f_3424x1836.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!449R!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F222e7488-633f-4e3b-9cad-103c58c2c90f_3424x1836.png 424w, https://substackcdn.com/image/fetch/$s_!449R!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F222e7488-633f-4e3b-9cad-103c58c2c90f_3424x1836.png 848w, https://substackcdn.com/image/fetch/$s_!449R!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F222e7488-633f-4e3b-9cad-103c58c2c90f_3424x1836.png 1272w, https://substackcdn.com/image/fetch/$s_!449R!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F222e7488-633f-4e3b-9cad-103c58c2c90f_3424x1836.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!449R!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F222e7488-633f-4e3b-9cad-103c58c2c90f_3424x1836.png" width="1456" height="781" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/222e7488-633f-4e3b-9cad-103c58c2c90f_3424x1836.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:781,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:452427,&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://blog.algomaster.io/i/193188051?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F222e7488-633f-4e3b-9cad-103c58c2c90f_3424x1836.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_!449R!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F222e7488-633f-4e3b-9cad-103c58c2c90f_3424x1836.png 424w, https://substackcdn.com/image/fetch/$s_!449R!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F222e7488-633f-4e3b-9cad-103c58c2c90f_3424x1836.png 848w, https://substackcdn.com/image/fetch/$s_!449R!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F222e7488-633f-4e3b-9cad-103c58c2c90f_3424x1836.png 1272w, https://substackcdn.com/image/fetch/$s_!449R!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F222e7488-633f-4e3b-9cad-103c58c2c90f_3424x1836.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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>It also includes a <strong>voice mode</strong> (premium feature), allowing you to explain your approach out loud while the AI interviewer responds in voice, just like a real interview. You can choose from different interviewer personas such as strict, balanced, or coaching.</p><p>If you get stuck, you can ask for hints during the session. After ending the interview, you&#8217;ll receive detailed feedback across multiple dimensions to help you improve.</p><div><hr></div><p>If you have any suggestions or feedback, feel free to share. I&#8217;ll continue improving and expanding these resources over time.</p><p>For any questions related to content or subscription, please reply to this email or reach out at <strong>contact@algomaster.io</strong></p>]]></content:encoded></item><item><title><![CDATA[Tech Stack I used to build my coding platform (algomaster.io)]]></title><description><![CDATA[In September 2024, I started building AlgoMaster.io from scratch after quitting my job at Amazon.]]></description><link>https://blog.algomaster.io/p/algomaster-tech-stack</link><guid isPermaLink="false">https://blog.algomaster.io/p/algomaster-tech-stack</guid><dc:creator><![CDATA[Ashish Pratap Singh]]></dc:creator><pubDate>Sun, 22 Mar 2026 05:01:59 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!BgEN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F080b113a-6427-446d-81ea-6b2232d9a008_1678x1440.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In September 2024, I started building <strong><a href="https://algomaster.io/">AlgoMaster.io</a></strong> from scratch after quitting my job at Amazon. By December, it was live. Today, it serves over <strong>70,000</strong> users and handles roughly <strong>800,000</strong> requests per day. The entire thing runs on about <strong>$900</strong> a month.</p><p>In this article, I&#8217;ll break down every major technology I used and, more importantly, why I chose it. If you&#8217;re planning to build your own platform, SaaS product, or side project, this could save you weeks of research and decision paralysis.</p><div><hr></div><p>AlgoMaster is a Software Engineering interview preparation platform with interactive courses. It includes features like: algorithm visualizations, an in-browser code editor with remote execution, multiple AI-powered capabilities such as AI chatbot, system design interview practice, text-to-speech for lessons, and much more.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!BgEN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F080b113a-6427-446d-81ea-6b2232d9a008_1678x1440.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!BgEN!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F080b113a-6427-446d-81ea-6b2232d9a008_1678x1440.png 424w, https://substackcdn.com/image/fetch/$s_!BgEN!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F080b113a-6427-446d-81ea-6b2232d9a008_1678x1440.png 848w, https://substackcdn.com/image/fetch/$s_!BgEN!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F080b113a-6427-446d-81ea-6b2232d9a008_1678x1440.png 1272w, https://substackcdn.com/image/fetch/$s_!BgEN!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F080b113a-6427-446d-81ea-6b2232d9a008_1678x1440.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!BgEN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F080b113a-6427-446d-81ea-6b2232d9a008_1678x1440.png" width="645" height="553.3001373626373" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/080b113a-6427-446d-81ea-6b2232d9a008_1678x1440.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1249,&quot;width&quot;:1456,&quot;resizeWidth&quot;:645,&quot;bytes&quot;:878862,&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://blog.algomaster.io/i/191725191?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F080b113a-6427-446d-81ea-6b2232d9a008_1678x1440.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_!BgEN!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F080b113a-6427-446d-81ea-6b2232d9a008_1678x1440.png 424w, https://substackcdn.com/image/fetch/$s_!BgEN!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F080b113a-6427-446d-81ea-6b2232d9a008_1678x1440.png 848w, https://substackcdn.com/image/fetch/$s_!BgEN!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F080b113a-6427-446d-81ea-6b2232d9a008_1678x1440.png 1272w, https://substackcdn.com/image/fetch/$s_!BgEN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F080b113a-6427-446d-81ea-6b2232d9a008_1678x1440.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>Building it taught me a lot about choosing the right tools, knowing when &#8220;good enough&#8221; is better than &#8220;perfect,&#8221; and shipping fast without compromising on what truly matters.</p><div><hr></div><h1>High-Level Architecture</h1><p>Before diving into individual tools, here&#8217;s how everything fits together at a high level.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!0bJl!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F121f41db-9d0c-40a7-970f-79ecb5e60576_2930x1048.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!0bJl!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F121f41db-9d0c-40a7-970f-79ecb5e60576_2930x1048.png 424w, https://substackcdn.com/image/fetch/$s_!0bJl!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F121f41db-9d0c-40a7-970f-79ecb5e60576_2930x1048.png 848w, https://substackcdn.com/image/fetch/$s_!0bJl!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F121f41db-9d0c-40a7-970f-79ecb5e60576_2930x1048.png 1272w, https://substackcdn.com/image/fetch/$s_!0bJl!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F121f41db-9d0c-40a7-970f-79ecb5e60576_2930x1048.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!0bJl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F121f41db-9d0c-40a7-970f-79ecb5e60576_2930x1048.png" width="1456" height="521" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/121f41db-9d0c-40a7-970f-79ecb5e60576_2930x1048.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:521,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:183862,&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://blog.algomaster.io/i/191725191?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F121f41db-9d0c-40a7-970f-79ecb5e60576_2930x1048.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_!0bJl!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F121f41db-9d0c-40a7-970f-79ecb5e60576_2930x1048.png 424w, https://substackcdn.com/image/fetch/$s_!0bJl!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F121f41db-9d0c-40a7-970f-79ecb5e60576_2930x1048.png 848w, https://substackcdn.com/image/fetch/$s_!0bJl!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F121f41db-9d0c-40a7-970f-79ecb5e60576_2930x1048.png 1272w, https://substackcdn.com/image/fetch/$s_!0bJl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F121f41db-9d0c-40a7-970f-79ecb5e60576_2930x1048.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 architecture is intentionally simple. A Next.js frontend, deployed on Vercel, handles both the UI and API routes. Supabase powers the database, authentication, and file storage. Payload CMS manages all course content. Stripe handles payments. And a combination of OpenAI, Whisper, Elevanlabs and pgVector powers the AI features.</p><p>Every user request first hits Vercel&#8217;s edge network, where it is routed to the appropriate Next.js serverless function or static page. From there, the application communicates with the relevant backend services as needed.</p><p>Simple, but it works at scale.</p><div><hr></div><h1>Framework and Runtime</h1><h3>Next.js (React) + TypeScript</h3><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!fyoe!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93bfe82f-7518-4019-b30b-22aba063a5dc_574x164.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!fyoe!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93bfe82f-7518-4019-b30b-22aba063a5dc_574x164.png 424w, https://substackcdn.com/image/fetch/$s_!fyoe!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93bfe82f-7518-4019-b30b-22aba063a5dc_574x164.png 848w, https://substackcdn.com/image/fetch/$s_!fyoe!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93bfe82f-7518-4019-b30b-22aba063a5dc_574x164.png 1272w, https://substackcdn.com/image/fetch/$s_!fyoe!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93bfe82f-7518-4019-b30b-22aba063a5dc_574x164.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!fyoe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93bfe82f-7518-4019-b30b-22aba063a5dc_574x164.png" width="574" height="164" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/93bfe82f-7518-4019-b30b-22aba063a5dc_574x164.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:164,&quot;width&quot;:574,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:35882,&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://blog.algomaster.io/i/191725191?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93bfe82f-7518-4019-b30b-22aba063a5dc_574x164.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_!fyoe!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93bfe82f-7518-4019-b30b-22aba063a5dc_574x164.png 424w, https://substackcdn.com/image/fetch/$s_!fyoe!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93bfe82f-7518-4019-b30b-22aba063a5dc_574x164.png 848w, https://substackcdn.com/image/fetch/$s_!fyoe!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93bfe82f-7518-4019-b30b-22aba063a5dc_574x164.png 1272w, https://substackcdn.com/image/fetch/$s_!fyoe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93bfe82f-7518-4019-b30b-22aba063a5dc_574x164.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>The entire platform is built as a Next.js 15 application using the App Router.</p><p>Next.js is an open-source, full-stack React framework that provides a structured approach along with powerful built-in features for building high-performance, scalable web applications.</p><p>I had not used Next.js before this project and had to learn it from scratch. After evaluating multiple options, it became clear that Next.js was the best fit for what I was building, both in terms of capabilities and ecosystem.</p><p>Here is what made Next.js the right choice:</p><ul><li><p><strong>Full Stack Framework: </strong>It allows me to build both the frontend and backend in a single codebase, which simplifies development and reduces context switching.</p></li><li><p><strong>Server-side rendering (SSR) for SEO: </strong>For a content-heavy platform like AlgoMaster, SEO is critical. SSR ensures better indexing and faster initial load times.</p></li><li><p><strong>File-based routing: </strong>Routing is simple and intuitive. The file system directly maps to application routes, which improves developer experience and maintainability.</p></li></ul><p>I use TypeScript across the entire codebase. For a project of this scale (1000+ code files), it is not optional.</p><p>Type safety has prevented countless bugs, especially at API boundaries where mismatches can easily occur. It also improves code readability, refactoring confidence, and long-term maintainability.</p><div><hr></div><h1>UI and Styling</h1><h3>shadcn/ui + Tailwind CSS</h3><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ZKht!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd371fa7c-d993-4670-9f7f-6b06efd5d89c_458x166.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ZKht!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd371fa7c-d993-4670-9f7f-6b06efd5d89c_458x166.png 424w, https://substackcdn.com/image/fetch/$s_!ZKht!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd371fa7c-d993-4670-9f7f-6b06efd5d89c_458x166.png 848w, https://substackcdn.com/image/fetch/$s_!ZKht!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd371fa7c-d993-4670-9f7f-6b06efd5d89c_458x166.png 1272w, https://substackcdn.com/image/fetch/$s_!ZKht!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd371fa7c-d993-4670-9f7f-6b06efd5d89c_458x166.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ZKht!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd371fa7c-d993-4670-9f7f-6b06efd5d89c_458x166.png" width="458" height="166" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d371fa7c-d993-4670-9f7f-6b06efd5d89c_458x166.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:166,&quot;width&quot;:458,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:16143,&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://blog.algomaster.io/i/191725191?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd371fa7c-d993-4670-9f7f-6b06efd5d89c_458x166.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_!ZKht!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd371fa7c-d993-4670-9f7f-6b06efd5d89c_458x166.png 424w, https://substackcdn.com/image/fetch/$s_!ZKht!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd371fa7c-d993-4670-9f7f-6b06efd5d89c_458x166.png 848w, https://substackcdn.com/image/fetch/$s_!ZKht!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd371fa7c-d993-4670-9f7f-6b06efd5d89c_458x166.png 1272w, https://substackcdn.com/image/fetch/$s_!ZKht!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd371fa7c-d993-4670-9f7f-6b06efd5d89c_458x166.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>For the component library, I went with <strong>shadcn/ui</strong>. If you have not used it, shadcn is different from traditional component libraries like Material UI or Chakra. </p><p>Instead of installing a package and importing opaque components, you copy the component source code directly into your project. That means you own it completely. You can customize anything without fighting the library&#8217;s abstractions or overriding styles with hacky CSS specificity tricks.</p><p><strong>Tailwind CSS</strong> handles all the styling. I had used plain CSS, CSS Modules, and styled-components on previous projects, and Tailwind was the clear winner for speed. Your design decisions live right where your markup is, and you&#8217;re never hunting through a separate CSS file.</p><div><hr></div><h1>Database and Authentication</h1><h3>Supabase (PostgreSQL + Auth + Storage)</h3><p>Choosing Supabase was one of the most important decisions I made. As a solo developer, I needed a solution that could handle the database, authentication, and file storage without stitching together multiple services.</p><p>Supabase provides a full <strong>PostgreSQL database</strong> with a clean dashboard, built-in authentication (email, Google, GitHub OAuth), and S3-compatible storage for assets.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!OoaE!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d7babd3-3a72-456a-a58c-92868919480c_1059x654.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!OoaE!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d7babd3-3a72-456a-a58c-92868919480c_1059x654.png 424w, https://substackcdn.com/image/fetch/$s_!OoaE!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d7babd3-3a72-456a-a58c-92868919480c_1059x654.png 848w, https://substackcdn.com/image/fetch/$s_!OoaE!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d7babd3-3a72-456a-a58c-92868919480c_1059x654.png 1272w, https://substackcdn.com/image/fetch/$s_!OoaE!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d7babd3-3a72-456a-a58c-92868919480c_1059x654.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!OoaE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d7babd3-3a72-456a-a58c-92868919480c_1059x654.png" width="1059" height="654" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4d7babd3-3a72-456a-a58c-92868919480c_1059x654.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:654,&quot;width&quot;:1059,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:153962,&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://blog.algomaster.io/i/191725191?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d7babd3-3a72-456a-a58c-92868919480c_1059x654.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_!OoaE!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d7babd3-3a72-456a-a58c-92868919480c_1059x654.png 424w, https://substackcdn.com/image/fetch/$s_!OoaE!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d7babd3-3a72-456a-a58c-92868919480c_1059x654.png 848w, https://substackcdn.com/image/fetch/$s_!OoaE!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d7babd3-3a72-456a-a58c-92868919480c_1059x654.png 1272w, https://substackcdn.com/image/fetch/$s_!OoaE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d7babd3-3a72-456a-a58c-92868919480c_1059x654.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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>It also includes an interactive SQL editor, which makes it easy to run queries, debug issues, and inspect data directly without leaving the dashboard.</p><p>To improve performance for global users, I&#8217;ve configured a <strong>read replica</strong> alongside the primary database. This helps reduce latency for read-heavy operations across different regions.</p><p>One of the biggest advantages is <strong>Row-Level Security (RLS)</strong>. I&#8217;ve configured RLS on sensitive tables so that even if someone attempts to access data via a direct API request, they can only see their own data.</p><p>Supabase makes this straightforward. You define SQL policies once, and they are enforced at the database level, which adds a strong layer of security without additional backend complexity.</p><div><hr></div><h1>Content Management</h1><h3>Payload CMS</h3><p>This was one of the hardest parts to figure out. I spent a significant amount of time exploring different CMS options and even tried building a custom solution from scratch before finally settling on Payload.</p><p>The platform handles a large amount of structured content: courses, chapters, lessons, code examples, quizzes, and diagrams. I needed a CMS that could model complex relationships, remain developer-friendly, and be self-hosted.</p><p>Payload CMS checked all the boxes.</p><p>It is a headless, TypeScript-native, API-first CMS. I define all content schemas directly in TypeScript, and Payload automatically generates the admin panel along with REST and GraphQL APIs.</p><p>The admin panel is where all course content is created and managed, which makes the workflow smooth and centralized. I&#8217;ve defined multiple custom blocks to support different content components such as code snippets, callouts, diagrams, and more.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!xpPH!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F75f9cb4a-a772-4ffa-b0e1-1a27124142f2_1555x934.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!xpPH!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F75f9cb4a-a772-4ffa-b0e1-1a27124142f2_1555x934.png 424w, https://substackcdn.com/image/fetch/$s_!xpPH!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F75f9cb4a-a772-4ffa-b0e1-1a27124142f2_1555x934.png 848w, https://substackcdn.com/image/fetch/$s_!xpPH!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F75f9cb4a-a772-4ffa-b0e1-1a27124142f2_1555x934.png 1272w, https://substackcdn.com/image/fetch/$s_!xpPH!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F75f9cb4a-a772-4ffa-b0e1-1a27124142f2_1555x934.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!xpPH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F75f9cb4a-a772-4ffa-b0e1-1a27124142f2_1555x934.png" width="1456" height="875" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/75f9cb4a-a772-4ffa-b0e1-1a27124142f2_1555x934.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:875,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:198692,&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://blog.algomaster.io/i/191725191?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F75f9cb4a-a772-4ffa-b0e1-1a27124142f2_1555x934.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_!xpPH!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F75f9cb4a-a772-4ffa-b0e1-1a27124142f2_1555x934.png 424w, https://substackcdn.com/image/fetch/$s_!xpPH!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F75f9cb4a-a772-4ffa-b0e1-1a27124142f2_1555x934.png 848w, https://substackcdn.com/image/fetch/$s_!xpPH!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F75f9cb4a-a772-4ffa-b0e1-1a27124142f2_1555x934.png 1272w, https://substackcdn.com/image/fetch/$s_!xpPH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F75f9cb4a-a772-4ffa-b0e1-1a27124142f2_1555x934.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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>All Payload CMS data is stored in PostgreSQL under a separate schema, keeping it isolated from the main application data.</p><p>The Payload application itself is deployed separately on Vercel, allowing it to scale independently from the main platform.</p><div><hr></div><h1>Payments</h1><h3>Stripe</h3><p>All payments are handled through <strong>Stripe</strong>.</p><p>The integration works like this: when a user subscribes, Stripe creates a subscription and sends a webhook to my Next.js API route. The webhook handler then updates the user&#8217;s entitlements in Supabase, granting access to premium features.</p><p>When a subscription is cancelled or expires, another webhook fires, and access is automatically revoked.</p><p>The interesting part was handling multi-currency support. I have users across 50+ countries, so displaying localized pricing was important. For this, I use Vercel&#8217;s geolocation headers to detect the user&#8217;s region and map it to the appropriate currency, enabling a seamless localized pricing experience.</p><div><hr></div><h1>AI Features</h1><p>I&#8217;ve built 5+ AI-powered features into the platform, including:</p><ul><li><p>A lesson chatbot that answers questions based on the current chapter</p></li><li><p>&#8220;Explain with AI&#8221; for content, code blocks, and diagrams</p></li><li><p>An evaluation system for coding and LLD exercises</p></li><li><p>A full system design practice mode with AI-driven feedback</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_!t7oL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ff5aae8-bea8-46a2-b82a-3a08cf641d8e_3392x1840.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!t7oL!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ff5aae8-bea8-46a2-b82a-3a08cf641d8e_3392x1840.png 424w, https://substackcdn.com/image/fetch/$s_!t7oL!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ff5aae8-bea8-46a2-b82a-3a08cf641d8e_3392x1840.png 848w, https://substackcdn.com/image/fetch/$s_!t7oL!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ff5aae8-bea8-46a2-b82a-3a08cf641d8e_3392x1840.png 1272w, https://substackcdn.com/image/fetch/$s_!t7oL!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ff5aae8-bea8-46a2-b82a-3a08cf641d8e_3392x1840.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!t7oL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ff5aae8-bea8-46a2-b82a-3a08cf641d8e_3392x1840.png" width="1456" height="790" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2ff5aae8-bea8-46a2-b82a-3a08cf641d8e_3392x1840.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:790,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:563146,&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://blog.algomaster.io/i/191725191?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ff5aae8-bea8-46a2-b82a-3a08cf641d8e_3392x1840.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_!t7oL!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ff5aae8-bea8-46a2-b82a-3a08cf641d8e_3392x1840.png 424w, https://substackcdn.com/image/fetch/$s_!t7oL!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ff5aae8-bea8-46a2-b82a-3a08cf641d8e_3392x1840.png 848w, https://substackcdn.com/image/fetch/$s_!t7oL!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ff5aae8-bea8-46a2-b82a-3a08cf641d8e_3392x1840.png 1272w, https://substackcdn.com/image/fetch/$s_!t7oL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ff5aae8-bea8-46a2-b82a-3a08cf641d8e_3392x1840.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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>Vercel AI SDK</h3><p>The Vercel AI SDK acts an AI gateway that makes it easy to switch between different models. It also handles streaming responses seamlessly between the model APIs and the client, which improves the overall user experience.</p><h3>OpenAI Models</h3><p>I use OpenAI models such as GPT-5.4-mini and GPT-5.1 to power text-based AI features across the platform.</p><p>I use smaller models for high-frequency, lightweight tasks such as &#8220;Ask AI&#8221; and answer evaluation. For more complex tasks like system design evaluation and judging, I use larger, more capable models to get deeper reasoning and higher-quality outputs.</p><p>Voice input is powered by OpenAI Whisper. Users can speak their answers during interview simulations, and the audio is transcribed server-side.</p><h3>pgVector</h3><p>I use the <strong>pgVector</strong> extension in PostgreSQL to power the RAG-based chatbot experience across the platform.</p><p>At a high level, pgVector allows me to store and query embeddings directly inside my existing Postgres database. This removes the need for a separate vector database and keeps everything in a single, consistent system.</p><p>One important challenge with RAG systems is keeping embeddings up to date. To handle this, I&#8217;ve set up hooks in Payload CMS. Whenever a piece of content is created or updated, it automatically triggers re-generation of embeddings for that content.</p><h3>ElevanLabs</h3><p>Some users prefer listening over reading, especially during commutes. To support this, I use ElevenLabs api to generate audio versions of lessons.</p><p>Each audio file is generated once and then cached in Supabase Storage, so the cost is incurred only a single time per lesson.</p><p>While this feature is relatively expensive, the improvement in user experience makes it well worth it.</p><h3>Claude Code</h3><p>And yes, I use <strong>Claude Code</strong> (Anthropic&#8217;s AI coding tool) extensively for development. It has been one of the biggest productivity multipliers in building this platform.</p><div><hr></div><h2>Code Editor and Execution</h2><p>I&#8217;ve built an in-browser code editor that allows users to write and execute code directly from 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_!AyNv!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff17f2b4f-7bd1-4b21-b12c-3432e32ecf9e_1624x1182.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!AyNv!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff17f2b4f-7bd1-4b21-b12c-3432e32ecf9e_1624x1182.png 424w, https://substackcdn.com/image/fetch/$s_!AyNv!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff17f2b4f-7bd1-4b21-b12c-3432e32ecf9e_1624x1182.png 848w, https://substackcdn.com/image/fetch/$s_!AyNv!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff17f2b4f-7bd1-4b21-b12c-3432e32ecf9e_1624x1182.png 1272w, https://substackcdn.com/image/fetch/$s_!AyNv!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff17f2b4f-7bd1-4b21-b12c-3432e32ecf9e_1624x1182.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!AyNv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff17f2b4f-7bd1-4b21-b12c-3432e32ecf9e_1624x1182.png" width="695" height="505.97527472527474" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f17f2b4f-7bd1-4b21-b12c-3432e32ecf9e_1624x1182.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1060,&quot;width&quot;:1456,&quot;resizeWidth&quot;:695,&quot;bytes&quot;:221137,&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://blog.algomaster.io/i/191725191?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff17f2b4f-7bd1-4b21-b12c-3432e32ecf9e_1624x1182.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_!AyNv!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff17f2b4f-7bd1-4b21-b12c-3432e32ecf9e_1624x1182.png 424w, https://substackcdn.com/image/fetch/$s_!AyNv!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff17f2b4f-7bd1-4b21-b12c-3432e32ecf9e_1624x1182.png 848w, https://substackcdn.com/image/fetch/$s_!AyNv!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff17f2b4f-7bd1-4b21-b12c-3432e32ecf9e_1624x1182.png 1272w, https://substackcdn.com/image/fetch/$s_!AyNv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff17f2b4f-7bd1-4b21-b12c-3432e32ecf9e_1624x1182.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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>Monaco Editor</h3><p>Every coding practice page uses Monaco Editor, the same editor that powers VS Code. It provides syntax highlighting, autocomplete, multi-language support, and a familiar developer experience.</p><p>Users can write and run code seamlessly without leaving the platform.</p><h3>Docker</h3><p>For code execution, I run a self-managed execution service on a <strong>DigitalOcean Droplet </strong>running Docker containers.</p><p>When a user clicks &#8220;Run,&#8221; their code is sent to the server, executed inside an isolated Docker container, and the output is returned. Each execution runs with strict time and memory limits to ensure reliability and fairness.</p><p>These containers are ephemeral. A new container is created for each execution and destroyed immediately afterward.</p><p>This level of isolation is critical because users can submit arbitrary code. It ensures that one user&#8217;s code cannot affect another user&#8217;s execution or access the underlying host system.</p><div><hr></div><h2>Visualizations &amp; Diagrams</h2><p>The platform includes 200+ interactive visualizations and simulations covering key interview topics such as DSA and System Design.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!zHBF!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d42f2e4-f02d-4e9f-b459-e9a642634891_3306x2098.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!zHBF!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d42f2e4-f02d-4e9f-b459-e9a642634891_3306x2098.png 424w, https://substackcdn.com/image/fetch/$s_!zHBF!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d42f2e4-f02d-4e9f-b459-e9a642634891_3306x2098.png 848w, https://substackcdn.com/image/fetch/$s_!zHBF!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d42f2e4-f02d-4e9f-b459-e9a642634891_3306x2098.png 1272w, https://substackcdn.com/image/fetch/$s_!zHBF!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d42f2e4-f02d-4e9f-b459-e9a642634891_3306x2098.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!zHBF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d42f2e4-f02d-4e9f-b459-e9a642634891_3306x2098.png" width="1456" height="924" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9d42f2e4-f02d-4e9f-b459-e9a642634891_3306x2098.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:924,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:417641,&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://blog.algomaster.io/i/191725191?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d42f2e4-f02d-4e9f-b459-e9a642634891_3306x2098.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_!zHBF!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d42f2e4-f02d-4e9f-b459-e9a642634891_3306x2098.png 424w, https://substackcdn.com/image/fetch/$s_!zHBF!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d42f2e4-f02d-4e9f-b459-e9a642634891_3306x2098.png 848w, https://substackcdn.com/image/fetch/$s_!zHBF!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d42f2e4-f02d-4e9f-b459-e9a642634891_3306x2098.png 1272w, https://substackcdn.com/image/fetch/$s_!zHBF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d42f2e4-f02d-4e9f-b459-e9a642634891_3306x2098.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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>D3.js for Algorithm Visualizations</h3><p>One of the core features of the platform is step-by-step algorithm visualization. These are built using D3.js, which provides fine-grained control over SVG elements, making it ideal for animating data structures and algorithms.</p><p>D3 does have a steep learning curve, but it unlocks a level of flexibility and precision that is hard to achieve with higher-level charting libraries.</p><h3>Other Visualization Tools</h3><ul><li><p><strong>Mermaid</strong> for diagrams embedded in course content (architecture diagrams, flowcharts, sequence diagrams)</p></li><li><p><strong>Recharts</strong> for analytics dashboards and progress charts</p></li><li><p><strong>Excalidraw</strong> for the whiteboard feature, where users can sketch out system designs during practice sessions</p></li></ul><div><hr></div><h1>Deployment and Monitoring</h1><h3>Vercel</h3><p>The application is deployed on Vercel. For a Next.js app, this is the path of least resistance.</p><p>Every push to GitHub triggers an automatic build and deployment, and rolling back to a previous version is straightforward if something goes wrong.</p><p>I don&#8217;t manage any servers myself. Vercel handles infrastructure and auto-scaling out of the box. When traffic spikes, serverless functions scale automatically without any manual intervention.</p><p>To control costs and prevent abuse, I&#8217;ve configured rate limits and spending limits.</p><h3>PostHog for Analytics</h3><p>PostHog is used for product analytics, including tracking page views, active users, and overall user behavior.</p><p>It is open-source, self-hostable, and offers a generous free tier, although I currently use their cloud version.</p><p>PostHog also supports feature flags, which I plan to use for gradual rollouts. This will allow me to release new features to a subset of users first, validate them in production, and then roll them out to everyone with confidence.</p><div><hr></div><h1>Other Notable Tools</h1><p>A few more tools that are worth mentioning:</p><h3>Resend</h3><p>Used for transactional emails such as login links and comment reply notifications. It has a clean API, reliable deliverability, and a generous free tier, which makes it a great fit.</p><h4>BlockNote</h4><p>Powers the notes feature. Users can take notes while going through courses, and BlockNote provides a Notion-like block editor that is easy to integrate with React. It supports rich text, code blocks, checklists, and more.</p><h4>Zustand</h4><p>Handles client-side state management. I had used Redux in a previous project and found it too verbose for my needs. Zustand is minimal, requires almost no boilerplate, and just works. It&#8217;s perfect for managing things like editor state, UI preferences, and quiz progress.</p><div><hr></div><h1>Final Thoughts</h1><p>Most of these tools have generous free tiers. You can build something substantial without spending a dollar until you have real users. The barrier to starting is genuinely lower than it&#8217;s ever been.</p><p>What I&#8217;ve learned is this: the hard part is not choosing the perfect tech stack. It is building something people actually want, improving it consistently based on feedback, and showing up every day to make it better. The tech stack is just the vehicle.</p><p>You also don&#8217;t need to know everything before you start. I didn&#8217;t know 90% of the tools I&#8217;ve mentioned in this article when I began. I learned them along the way, one problem at a time.</p><p>I hope you found this useful. Let me know if you have any suggestions or recommendations.</p>]]></content:encoded></item><item><title><![CDATA[300+ Engineering Articles to Level Up Your System Design Skills]]></title><description><![CDATA[I&#8217;m excited to share a new GitHub repository where I&#8217;ve curated 300+ high-quality engineering articles, organized by top tech companies.]]></description><link>https://blog.algomaster.io/p/300-engineering-articles-to-level-up-system-design</link><guid isPermaLink="false">https://blog.algomaster.io/p/300-engineering-articles-to-level-up-system-design</guid><dc:creator><![CDATA[Ashish Pratap Singh]]></dc:creator><pubDate>Sun, 01 Mar 2026 04:41:04 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!7Ld9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fba7552b6-aa48-4fa2-83aa-f01d1c0d27aa_1600x1200.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>I&#8217;m excited to share a <strong><a href="https://github.com/ashishps1/awesome-engineering-articles">new GitHub repository</a></strong> where I&#8217;ve curated 300+ high-quality engineering articles, organized by top tech companies.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!7Ld9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fba7552b6-aa48-4fa2-83aa-f01d1c0d27aa_1600x1200.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!7Ld9!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fba7552b6-aa48-4fa2-83aa-f01d1c0d27aa_1600x1200.png 424w, https://substackcdn.com/image/fetch/$s_!7Ld9!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fba7552b6-aa48-4fa2-83aa-f01d1c0d27aa_1600x1200.png 848w, https://substackcdn.com/image/fetch/$s_!7Ld9!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fba7552b6-aa48-4fa2-83aa-f01d1c0d27aa_1600x1200.png 1272w, https://substackcdn.com/image/fetch/$s_!7Ld9!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fba7552b6-aa48-4fa2-83aa-f01d1c0d27aa_1600x1200.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!7Ld9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fba7552b6-aa48-4fa2-83aa-f01d1c0d27aa_1600x1200.png" width="1456" height="1092" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ba7552b6-aa48-4fa2-83aa-f01d1c0d27aa_1600x1200.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;:195946,&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://blog.algomaster.io/i/189520195?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fba7552b6-aa48-4fa2-83aa-f01d1c0d27aa_1600x1200.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_!7Ld9!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fba7552b6-aa48-4fa2-83aa-f01d1c0d27aa_1600x1200.png 424w, https://substackcdn.com/image/fetch/$s_!7Ld9!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fba7552b6-aa48-4fa2-83aa-f01d1c0d27aa_1600x1200.png 848w, https://substackcdn.com/image/fetch/$s_!7Ld9!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fba7552b6-aa48-4fa2-83aa-f01d1c0d27aa_1600x1200.png 1272w, https://substackcdn.com/image/fetch/$s_!7Ld9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fba7552b6-aa48-4fa2-83aa-f01d1c0d27aa_1600x1200.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 class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://github.com/ashishps1/awesome-engineering-articles&quot;,&quot;text&quot;:&quot;Check it out here&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://github.com/ashishps1/awesome-engineering-articles"><span>Check it out here</span></a></p><p>These articles cover various topics including:</p><ul><li><p>Real-World System Design and Architecture</p></li><li><p>AI/ML and Search</p></li><li><p>Data Engineering</p></li><li><p>Databases and Performance</p></li><li><p>Infrastructure and Security</p></li></ul><div><hr></div><p>A lot of people tell you which engineering blogs to follow. Almost nobody tells you which articles are actually worth your time.</p><p>So I did the hard part: I went through the last 5&#8211;6 years of popular company engineering blogs and pulled out the articles that are genuinely worth reading.</p><p>My goal is to make this repo a one-stop resource for the most interesting engineering writing across the internet.</p><p>If you find it valuable, consider giving it a star (&#11088;&#65039;) and share it with others.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://github.com/ashishps1/awesome-engineering-articles&quot;,&quot;text&quot;:&quot;Give it a Star &#11088;&#65039;&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://github.com/ashishps1/awesome-engineering-articles"><span>Give it a Star &#11088;&#65039;</span></a></p><p>Contributions are welcome too. If you think a company or article is missing, feel free to open a pull request.</p>]]></content:encoded></item><item><title><![CDATA[20 AI Concepts Explained in 20 Minutes]]></title><description><![CDATA[Learning AI can feel overwhelming.]]></description><link>https://blog.algomaster.io/p/20-ai-concepts-explained-simply</link><guid isPermaLink="false">https://blog.algomaster.io/p/20-ai-concepts-explained-simply</guid><dc:creator><![CDATA[Ashish Pratap Singh]]></dc:creator><pubDate>Thu, 26 Feb 2026 13:22:58 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!kpKk!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6903c7ca-215d-4727-be3a-a905bc20c93a_1152x824.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Learning AI can feel overwhelming. If you are not working directly in AI, it can feel like learning an entirely new language.</p><p>But like any technical topic, AI becomes much easier once you understand the fundamentals behind large language models (LLMs) and the modern tools built around them.</p><p>In this article, we will break down <strong>20 of the most important AI concepts</strong> in the simplest way possible, with clear explanations and intuitive examples.</p><div><hr></div><h1><a href="https://getunblocked.com/?utm_source=algomaster&amp;utm_medium=email&amp;utm_campaign=contextengine&amp;utm_content=260226_primary">&#128227; Unblocked: The context layer your AI tools are missing (Sponsor)</a></h1><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!jugg!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94fad4ff-6f9c-4f85-8579-57bf11d46347_1600x800.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!jugg!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94fad4ff-6f9c-4f85-8579-57bf11d46347_1600x800.png 424w, https://substackcdn.com/image/fetch/$s_!jugg!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94fad4ff-6f9c-4f85-8579-57bf11d46347_1600x800.png 848w, https://substackcdn.com/image/fetch/$s_!jugg!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94fad4ff-6f9c-4f85-8579-57bf11d46347_1600x800.png 1272w, https://substackcdn.com/image/fetch/$s_!jugg!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94fad4ff-6f9c-4f85-8579-57bf11d46347_1600x800.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!jugg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94fad4ff-6f9c-4f85-8579-57bf11d46347_1600x800.png" width="1456" height="728" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/94fad4ff-6f9c-4f85-8579-57bf11d46347_1600x800.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:728,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:498594,&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://blog.algomaster.io/i/189045631?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94fad4ff-6f9c-4f85-8579-57bf11d46347_1600x800.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_!jugg!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94fad4ff-6f9c-4f85-8579-57bf11d46347_1600x800.png 424w, https://substackcdn.com/image/fetch/$s_!jugg!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94fad4ff-6f9c-4f85-8579-57bf11d46347_1600x800.png 848w, https://substackcdn.com/image/fetch/$s_!jugg!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94fad4ff-6f9c-4f85-8579-57bf11d46347_1600x800.png 1272w, https://substackcdn.com/image/fetch/$s_!jugg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94fad4ff-6f9c-4f85-8579-57bf11d46347_1600x800.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>Many developer tools promise context-aware AI, but having data access doesn&#8217;t automatically mean agents know when to use it.</p><p>Real context requires understanding. <strong><a href="https://getunblocked.com/?utm_source=algomaster&amp;utm_medium=email&amp;utm_campaign=contextengine&amp;utm_content=260226_primary">Unblocked</a></strong> synthesizes knowledge from your codebase, PRs, discussions, docs, project trackers, and runtime signals. It connects past decisions to current work, resolves conflicts between outdated docs and actual practice, respects data permissions, and surfaces what matters for the task at hand.</p><p>With <strong><a href="https://getunblocked.com/?utm_source=algomaster&amp;utm_medium=email&amp;utm_campaign=contextengine&amp;utm_content=260226_primary">Unblocked</a></strong>:</p><ul><li><p>Coding agents like Cursor, Claude, and Copilot generate output that aligns with your actual architecture and conventions</p></li><li><p>Code review focuses on real bugs rather than stylistic nits</p></li><li><p>You find instant answers without interrupting teammates</p></li></ul><p>See how <strong><a href="https://getunblocked.com/?utm_source=algomaster&amp;utm_medium=email&amp;utm_campaign=contextengine&amp;utm_content=260226_primary">Unblocked</a></strong> works.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://getunblocked.com/?utm_source=algomaster&amp;utm_medium=email&amp;utm_campaign=contextengine&amp;utm_content=260226_primary&quot;,&quot;text&quot;:&quot;Get Started for Free&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://getunblocked.com/?utm_source=algomaster&amp;utm_medium=email&amp;utm_campaign=contextengine&amp;utm_content=260226_primary"><span>Get Started for Free</span></a></p><div><hr></div><h1>Foundations</h1><h2>1. Neural Network</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!kpKk!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6903c7ca-215d-4727-be3a-a905bc20c93a_1152x824.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!kpKk!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6903c7ca-215d-4727-be3a-a905bc20c93a_1152x824.png 424w, https://substackcdn.com/image/fetch/$s_!kpKk!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6903c7ca-215d-4727-be3a-a905bc20c93a_1152x824.png 848w, https://substackcdn.com/image/fetch/$s_!kpKk!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6903c7ca-215d-4727-be3a-a905bc20c93a_1152x824.png 1272w, https://substackcdn.com/image/fetch/$s_!kpKk!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6903c7ca-215d-4727-be3a-a905bc20c93a_1152x824.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!kpKk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6903c7ca-215d-4727-be3a-a905bc20c93a_1152x824.png" width="478" height="341.90277777777777" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6903c7ca-215d-4727-be3a-a905bc20c93a_1152x824.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:824,&quot;width&quot;:1152,&quot;resizeWidth&quot;:478,&quot;bytes&quot;:655388,&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://blog.algomaster.io/i/189045631?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6903c7ca-215d-4727-be3a-a905bc20c93a_1152x824.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_!kpKk!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6903c7ca-215d-4727-be3a-a905bc20c93a_1152x824.png 424w, https://substackcdn.com/image/fetch/$s_!kpKk!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6903c7ca-215d-4727-be3a-a905bc20c93a_1152x824.png 848w, https://substackcdn.com/image/fetch/$s_!kpKk!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6903c7ca-215d-4727-be3a-a905bc20c93a_1152x824.png 1272w, https://substackcdn.com/image/fetch/$s_!kpKk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6903c7ca-215d-4727-be3a-a905bc20c93a_1152x824.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 core, a neural network is a stack of connected layers made up of simple units called neurons. Data enters through the input layer, moves through one or more hidden layers where the model learns useful patterns, and then produces a final prediction at the output layer.</p><p>A helpful way to picture this is as a series of refinement steps. The same input gets transformed again and again, with each layer extracting slightly higher-level features than the one before it. In image models, early layers often pick up simple signals like edges and textures. Deeper layers combine those signals into shapes and parts, and later layers can represent full objects.</p><p>The connections between neurons have weights, numbers that control how strongly one neuron influences another. Training is essentially the process of adjusting these weights so the network&#8217;s outputs become more accurate. </p><p>Modern large language models contain an enormous number of such weights, often in the tens or even hundreds of billions.</p><h2>2. Transfer Learning</h2><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!V_xb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0948584-3704-4eb6-bb7e-7c9a511baf80_1280x488.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!V_xb!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0948584-3704-4eb6-bb7e-7c9a511baf80_1280x488.png 424w, https://substackcdn.com/image/fetch/$s_!V_xb!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0948584-3704-4eb6-bb7e-7c9a511baf80_1280x488.png 848w, https://substackcdn.com/image/fetch/$s_!V_xb!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0948584-3704-4eb6-bb7e-7c9a511baf80_1280x488.png 1272w, https://substackcdn.com/image/fetch/$s_!V_xb!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0948584-3704-4eb6-bb7e-7c9a511baf80_1280x488.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!V_xb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0948584-3704-4eb6-bb7e-7c9a511baf80_1280x488.png" width="450" height="171.5625" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b0948584-3704-4eb6-bb7e-7c9a511baf80_1280x488.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:488,&quot;width&quot;:1280,&quot;resizeWidth&quot;:450,&quot;bytes&quot;:320301,&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://blog.algomaster.io/i/189045631?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0948584-3704-4eb6-bb7e-7c9a511baf80_1280x488.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_!V_xb!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0948584-3704-4eb6-bb7e-7c9a511baf80_1280x488.png 424w, https://substackcdn.com/image/fetch/$s_!V_xb!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0948584-3704-4eb6-bb7e-7c9a511baf80_1280x488.png 848w, https://substackcdn.com/image/fetch/$s_!V_xb!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0948584-3704-4eb6-bb7e-7c9a511baf80_1280x488.png 1272w, https://substackcdn.com/image/fetch/$s_!V_xb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0948584-3704-4eb6-bb7e-7c9a511baf80_1280x488.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Training a neural network from scratch takes a huge amount of data and compute. Transfer learning changes the game. Instead of starting over, you take a model that has already been trained on a broad task and adapt it for a new, more specific one. Most of what the model learned still applies, so you get a strong head start.</p><p>A simple way to think about it is skill reuse. If you have already learned the basics, you can pick up a new variation much faster because the fundamentals do not need to be relearned. In the same way, a pretrained model already understands many general patterns in data, so fine-tuning it for your use case takes far less effort.</p><p>This is actually how most modern AI works. Someone trains a massive general-purpose model (the &#8220;foundation model&#8221;), and then you adapt it for your specific task.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.algomaster.io/p/20-ai-concepts-explained-simply?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://blog.algomaster.io/p/20-ai-concepts-explained-simply?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><div><hr></div><h1>The Transformer Stack</h1><h2>3. Tokenization</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!pG0v!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc983be9a-b185-427d-99cd-b6608f57e79e_768x526.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!pG0v!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc983be9a-b185-427d-99cd-b6608f57e79e_768x526.png 424w, https://substackcdn.com/image/fetch/$s_!pG0v!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc983be9a-b185-427d-99cd-b6608f57e79e_768x526.png 848w, https://substackcdn.com/image/fetch/$s_!pG0v!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc983be9a-b185-427d-99cd-b6608f57e79e_768x526.png 1272w, https://substackcdn.com/image/fetch/$s_!pG0v!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc983be9a-b185-427d-99cd-b6608f57e79e_768x526.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!pG0v!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc983be9a-b185-427d-99cd-b6608f57e79e_768x526.png" width="396" height="271.21875" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c983be9a-b185-427d-99cd-b6608f57e79e_768x526.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:526,&quot;width&quot;:768,&quot;resizeWidth&quot;:396,&quot;bytes&quot;:207661,&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://blog.algomaster.io/i/189045631?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc983be9a-b185-427d-99cd-b6608f57e79e_768x526.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_!pG0v!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc983be9a-b185-427d-99cd-b6608f57e79e_768x526.png 424w, https://substackcdn.com/image/fetch/$s_!pG0v!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc983be9a-b185-427d-99cd-b6608f57e79e_768x526.png 848w, https://substackcdn.com/image/fetch/$s_!pG0v!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc983be9a-b185-427d-99cd-b6608f57e79e_768x526.png 1272w, https://substackcdn.com/image/fetch/$s_!pG0v!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc983be9a-b185-427d-99cd-b6608f57e79e_768x526.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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>Before a model can work with text, it first has to convert that text into smaller units called <strong>tokens</strong>. A token can be a full word, a part of a word, a punctuation mark, or sometimes even a single character. This is the model&#8217;s &#8220;alphabet&#8221; for reading and writing language.</p><p>For example, the word <strong>&#8220;happiness&#8221;</strong> might be split into subword tokens like <strong>&#8220;hap&#8221;</strong>, <strong>&#8220;pi&#8221;</strong>, and <strong>&#8220;ness&#8221;</strong>, while a common word like <strong>&#8220;cat&#8221;</strong> might remain a single token. In general, common words tend to map cleanly to one token, while longer or rarer words get broken into smaller pieces.</p><h4>Why not just use whole words?</h4><p>Because the number of possible words is enormous, and it keeps growing. Proper nouns, slang, typos, domain-specific terms, and words from different languages would explode the vocabulary size. </p><p>Tokenization solves this by using a <strong>fixed vocabulary</strong> (often around <strong>30,000 to 100,000 tokens</strong>) built from common words and reusable subword chunks. That way, even if the model has never seen a word before, it can still represent it by combining familiar pieces.</p><h2>4. Embeddings</h2><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!WVJm!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faeb2338b-278d-4b6e-b353-150aa4797ad9_1212x388.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!WVJm!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faeb2338b-278d-4b6e-b353-150aa4797ad9_1212x388.png 424w, https://substackcdn.com/image/fetch/$s_!WVJm!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faeb2338b-278d-4b6e-b353-150aa4797ad9_1212x388.png 848w, https://substackcdn.com/image/fetch/$s_!WVJm!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faeb2338b-278d-4b6e-b353-150aa4797ad9_1212x388.png 1272w, https://substackcdn.com/image/fetch/$s_!WVJm!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faeb2338b-278d-4b6e-b353-150aa4797ad9_1212x388.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!WVJm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faeb2338b-278d-4b6e-b353-150aa4797ad9_1212x388.png" width="510" height="163.26732673267327" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/aeb2338b-278d-4b6e-b353-150aa4797ad9_1212x388.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:388,&quot;width&quot;:1212,&quot;resizeWidth&quot;:510,&quot;bytes&quot;:225835,&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://blog.algomaster.io/i/189045631?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faeb2338b-278d-4b6e-b353-150aa4797ad9_1212x388.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_!WVJm!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faeb2338b-278d-4b6e-b353-150aa4797ad9_1212x388.png 424w, https://substackcdn.com/image/fetch/$s_!WVJm!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faeb2338b-278d-4b6e-b353-150aa4797ad9_1212x388.png 848w, https://substackcdn.com/image/fetch/$s_!WVJm!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faeb2338b-278d-4b6e-b353-150aa4797ad9_1212x388.png 1272w, https://substackcdn.com/image/fetch/$s_!WVJm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faeb2338b-278d-4b6e-b353-150aa4797ad9_1212x388.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Once text is split into tokens, each token gets converted into an <strong>embedding</strong>, a vector (basically a list of numbers) that captures what the token means.</p><p>You can think of embeddings as coordinates in a high-dimensional map. Words with similar meanings end up close to each other, while unrelated words are far apart. For example, &#8220;king&#8221; and &#8220;queen&#8221; are located near each other in this space, whereas &#8220;king&#8221; and &#8220;refrigerator&#8221; are much farther apart.</p><p>These vectors usually have hundreds or even thousands of dimensions. While that sounds abstract, those dimensions capture meaningful patterns. The difference between &#8220;king&#8221; and &#8220;queen&#8221; is similar to the difference between &#8220;man&#8221; and &#8220;woman.&#8221;</p><p>The model does not understand language symbolically the way humans do. Instead, it learns meaning through geometry, by organizing words in a space where relationships become distances and directions.</p><h2>5. Attention</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Cpa4!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34cbe6f2-07c7-4073-85ce-62aae6ea6927_1022x516.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Cpa4!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34cbe6f2-07c7-4073-85ce-62aae6ea6927_1022x516.png 424w, https://substackcdn.com/image/fetch/$s_!Cpa4!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34cbe6f2-07c7-4073-85ce-62aae6ea6927_1022x516.png 848w, https://substackcdn.com/image/fetch/$s_!Cpa4!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34cbe6f2-07c7-4073-85ce-62aae6ea6927_1022x516.png 1272w, https://substackcdn.com/image/fetch/$s_!Cpa4!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34cbe6f2-07c7-4073-85ce-62aae6ea6927_1022x516.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Cpa4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34cbe6f2-07c7-4073-85ce-62aae6ea6927_1022x516.png" width="500" height="252.44618395303326" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/34cbe6f2-07c7-4073-85ce-62aae6ea6927_1022x516.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:516,&quot;width&quot;:1022,&quot;resizeWidth&quot;:500,&quot;bytes&quot;:247944,&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://blog.algomaster.io/i/189045631?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34cbe6f2-07c7-4073-85ce-62aae6ea6927_1022x516.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_!Cpa4!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34cbe6f2-07c7-4073-85ce-62aae6ea6927_1022x516.png 424w, https://substackcdn.com/image/fetch/$s_!Cpa4!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34cbe6f2-07c7-4073-85ce-62aae6ea6927_1022x516.png 848w, https://substackcdn.com/image/fetch/$s_!Cpa4!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34cbe6f2-07c7-4073-85ce-62aae6ea6927_1022x516.png 1272w, https://substackcdn.com/image/fetch/$s_!Cpa4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34cbe6f2-07c7-4073-85ce-62aae6ea6927_1022x516.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 the problem: the meaning of a word depends on context. &#8220;Bank&#8221; means something different in &#8220;river bank&#8221; versus &#8220;bank account&#8221;. Embeddings alone don&#8217;t solve this because they start as fixed vectors per token.</p><p><strong>Attention</strong> is the mechanism that addresses this. It lets each token look at every other token in the input and decide which ones matter. When processing &#8220;bank&#8221; in &#8220;I sat by the river bank&#8221;, the attention mechanism focuses on &#8220;river&#8221; and adjusts the representation of &#8220;bank&#8221; accordingly.</p><p>This was the key innovation that unlocked modern AI. Before attention, models processed words one at a time, left to right. Attention lets the model see everything at once and figure out what&#8217;s relevant.</p><h2>6. Transformer</h2><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!lprK!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11bff8f2-ca9f-426a-88b2-b303a7c89914_1284x556.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!lprK!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11bff8f2-ca9f-426a-88b2-b303a7c89914_1284x556.png 424w, https://substackcdn.com/image/fetch/$s_!lprK!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11bff8f2-ca9f-426a-88b2-b303a7c89914_1284x556.png 848w, https://substackcdn.com/image/fetch/$s_!lprK!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11bff8f2-ca9f-426a-88b2-b303a7c89914_1284x556.png 1272w, https://substackcdn.com/image/fetch/$s_!lprK!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11bff8f2-ca9f-426a-88b2-b303a7c89914_1284x556.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!lprK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11bff8f2-ca9f-426a-88b2-b303a7c89914_1284x556.png" width="446" height="193.12772585669782" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/11bff8f2-ca9f-426a-88b2-b303a7c89914_1284x556.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:556,&quot;width&quot;:1284,&quot;resizeWidth&quot;:446,&quot;bytes&quot;:246581,&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://blog.algomaster.io/i/189045631?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11bff8f2-ca9f-426a-88b2-b303a7c89914_1284x556.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_!lprK!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11bff8f2-ca9f-426a-88b2-b303a7c89914_1284x556.png 424w, https://substackcdn.com/image/fetch/$s_!lprK!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11bff8f2-ca9f-426a-88b2-b303a7c89914_1284x556.png 848w, https://substackcdn.com/image/fetch/$s_!lprK!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11bff8f2-ca9f-426a-88b2-b303a7c89914_1284x556.png 1272w, https://substackcdn.com/image/fetch/$s_!lprK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11bff8f2-ca9f-426a-88b2-b303a7c89914_1284x556.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>The transformer is the architecture that ties all of this together. It was introduced in a 2017 paper titled <em>&#8220;Attention Is All You Need&#8221;</em> and replaced the strictly sequential, word-by-word processing used in earlier models with attention as the central mechanism.</p><p>A transformer stacks multiple layers of attention and feed-forward networks. Each layer refines the representation of the input. Early layers tend to capture basic grammar. Middle layers pick up relationships between concepts. Later layers handle more complex reasoning.</p><p>One of the biggest advantages of transformers is that they process all tokens in <strong>parallel</strong> instead of one at a time. This makes training far more efficient on modern hardware like GPUs and enables models to scale to massive sizes. GPT, Claude, Gemini, Llama, and most other leading AI systems today are all built on transformer architectures.</p><p>In simple terms, text is converted into tokens, tokens become vectors, and stacked attention layers learn how those vectors relate and interact. That process forms the backbone of modern language models.</p><div><hr></div><h1>Large Language Models</h1><h2>7. LLM (Large Language Model)</h2><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ZN9M!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1fb8541-57b0-4733-999b-8c58b8d7f0e7_1356x412.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ZN9M!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1fb8541-57b0-4733-999b-8c58b8d7f0e7_1356x412.png 424w, https://substackcdn.com/image/fetch/$s_!ZN9M!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1fb8541-57b0-4733-999b-8c58b8d7f0e7_1356x412.png 848w, https://substackcdn.com/image/fetch/$s_!ZN9M!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1fb8541-57b0-4733-999b-8c58b8d7f0e7_1356x412.png 1272w, https://substackcdn.com/image/fetch/$s_!ZN9M!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1fb8541-57b0-4733-999b-8c58b8d7f0e7_1356x412.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ZN9M!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1fb8541-57b0-4733-999b-8c58b8d7f0e7_1356x412.png" width="579" height="175.9203539823009" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d1fb8541-57b0-4733-999b-8c58b8d7f0e7_1356x412.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:412,&quot;width&quot;:1356,&quot;resizeWidth&quot;:579,&quot;bytes&quot;:185832,&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://blog.algomaster.io/i/189045631?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1fb8541-57b0-4733-999b-8c58b8d7f0e7_1356x412.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_!ZN9M!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1fb8541-57b0-4733-999b-8c58b8d7f0e7_1356x412.png 424w, https://substackcdn.com/image/fetch/$s_!ZN9M!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1fb8541-57b0-4733-999b-8c58b8d7f0e7_1356x412.png 848w, https://substackcdn.com/image/fetch/$s_!ZN9M!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1fb8541-57b0-4733-999b-8c58b8d7f0e7_1356x412.png 1272w, https://substackcdn.com/image/fetch/$s_!ZN9M!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1fb8541-57b0-4733-999b-8c58b8d7f0e7_1356x412.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>A large language model (LLM) is essentially a <strong>transformer</strong> trained on an enormous amount of text, often <strong>hundreds of billions to trillions of tokens</strong> pulled from books, websites, code, and many other sources. The training objective sounds almost too simple: <strong>predict the next token</strong>.</p><p>That&#8217;s it. That&#8217;s the whole trick. But by doing this across trillions of examples, the model develops something that looks a lot like understanding, language, facts, reasoning patterns, even a degree of common sense. Most well-known systems today fall into this category, including GPT-style models, Claude, Gemini, and Llama.</p><p>The &#8220;large&#8221; part refers to the parameter count. Frontier models today have hundreds of billions of parameters, and training them costs tens of millions of dollars. But what you get is a model that can write code, answer questions, translate languages, and reason through problems it was never explicitly taught.</p><h2>8. Context Window</h2><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!S8RD!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9e7334f2-f3a6-45c6-8d4b-85633f6f9c70_1382x356.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!S8RD!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9e7334f2-f3a6-45c6-8d4b-85633f6f9c70_1382x356.png 424w, https://substackcdn.com/image/fetch/$s_!S8RD!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9e7334f2-f3a6-45c6-8d4b-85633f6f9c70_1382x356.png 848w, https://substackcdn.com/image/fetch/$s_!S8RD!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9e7334f2-f3a6-45c6-8d4b-85633f6f9c70_1382x356.png 1272w, https://substackcdn.com/image/fetch/$s_!S8RD!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9e7334f2-f3a6-45c6-8d4b-85633f6f9c70_1382x356.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!S8RD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9e7334f2-f3a6-45c6-8d4b-85633f6f9c70_1382x356.png" width="558" height="143.73950795947903" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9e7334f2-f3a6-45c6-8d4b-85633f6f9c70_1382x356.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:356,&quot;width&quot;:1382,&quot;resizeWidth&quot;:558,&quot;bytes&quot;:309454,&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://blog.algomaster.io/i/189045631?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9e7334f2-f3a6-45c6-8d4b-85633f6f9c70_1382x356.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_!S8RD!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9e7334f2-f3a6-45c6-8d4b-85633f6f9c70_1382x356.png 424w, https://substackcdn.com/image/fetch/$s_!S8RD!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9e7334f2-f3a6-45c6-8d4b-85633f6f9c70_1382x356.png 848w, https://substackcdn.com/image/fetch/$s_!S8RD!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9e7334f2-f3a6-45c6-8d4b-85633f6f9c70_1382x356.png 1272w, https://substackcdn.com/image/fetch/$s_!S8RD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9e7334f2-f3a6-45c6-8d4b-85633f6f9c70_1382x356.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>The <strong>context window</strong> is the maximum number of tokens a model can process at once, including both your input and the model&#8217;s generated output. You can think of it as the model&#8217;s working memory.</p><p>Early GPT models had a context window of 4,096 tokens (roughly 3,000 words). That felt limiting fast. Current models have pushed way beyond that. Claude supports 200K tokens. Gemini goes up to 1M. More context means the model can handle longer documents, longer conversations, and more information when forming a response.</p><p>However, there is a trade-off. Bigger context windows require significantly more memory and compute, which increases cost and latency. And even with large windows, models do not treat every part of the input equally. </p><p>Research has shown that performance often drops for information buried in the middle of very long inputs, a phenomenon commonly referred to as &#8220;lost in the middle.&#8221;</p><h2>9. Temperature</h2><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!MMiJ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F566318ef-7d1e-4727-b6c6-36dff5bb983e_1500x302.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!MMiJ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F566318ef-7d1e-4727-b6c6-36dff5bb983e_1500x302.png 424w, https://substackcdn.com/image/fetch/$s_!MMiJ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F566318ef-7d1e-4727-b6c6-36dff5bb983e_1500x302.png 848w, https://substackcdn.com/image/fetch/$s_!MMiJ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F566318ef-7d1e-4727-b6c6-36dff5bb983e_1500x302.png 1272w, https://substackcdn.com/image/fetch/$s_!MMiJ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F566318ef-7d1e-4727-b6c6-36dff5bb983e_1500x302.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!MMiJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F566318ef-7d1e-4727-b6c6-36dff5bb983e_1500x302.png" width="462" height="92.97115384615384" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/566318ef-7d1e-4727-b6c6-36dff5bb983e_1500x302.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:293,&quot;width&quot;:1456,&quot;resizeWidth&quot;:462,&quot;bytes&quot;:201373,&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://blog.algomaster.io/i/189045631?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F566318ef-7d1e-4727-b6c6-36dff5bb983e_1500x302.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_!MMiJ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F566318ef-7d1e-4727-b6c6-36dff5bb983e_1500x302.png 424w, https://substackcdn.com/image/fetch/$s_!MMiJ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F566318ef-7d1e-4727-b6c6-36dff5bb983e_1500x302.png 848w, https://substackcdn.com/image/fetch/$s_!MMiJ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F566318ef-7d1e-4727-b6c6-36dff5bb983e_1500x302.png 1272w, https://substackcdn.com/image/fetch/$s_!MMiJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F566318ef-7d1e-4727-b6c6-36dff5bb983e_1500x302.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>When an LLM generates the next token, it doesn&#8217;t just pick one. It calculates a probability for every token in its vocabulary. Temperature controls how it chooses from those probabilities.</p><p>At temperature 0, it always picks the most probable token. The result is deterministic, focused, and predictable. At temperature 1, it samples proportionally to the probabilities, so you get more variety and surprise. Above 1, things get increasingly random, more creative maybe, but also less coherent.</p><p>In practice, a few simple rules work well:</p><ul><li><p><strong>Low temperature (0 to 0.3):</strong> best for precise tasks like code generation, structured extraction, summaries, and anything where correctness matters more than originality.</p></li><li><p><strong>Medium temperature (0.5 to 0.8):</strong> good for brainstorming, alternative phrasings, marketing copy, and creative writing where variety is useful.</p></li><li><p><strong>High temperature (1+):</strong> can be fun for playful ideation, but it often reduces coherence and can quickly produce nonsense, especially in longer outputs.</p></li></ul><h2>10. Hallucination</h2><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Z7V0!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70289d23-0f30-447c-93cb-8773bb71c36c_1102x348.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Z7V0!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70289d23-0f30-447c-93cb-8773bb71c36c_1102x348.png 424w, https://substackcdn.com/image/fetch/$s_!Z7V0!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70289d23-0f30-447c-93cb-8773bb71c36c_1102x348.png 848w, https://substackcdn.com/image/fetch/$s_!Z7V0!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70289d23-0f30-447c-93cb-8773bb71c36c_1102x348.png 1272w, https://substackcdn.com/image/fetch/$s_!Z7V0!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70289d23-0f30-447c-93cb-8773bb71c36c_1102x348.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Z7V0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70289d23-0f30-447c-93cb-8773bb71c36c_1102x348.png" width="402" height="126.94736842105263" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/70289d23-0f30-447c-93cb-8773bb71c36c_1102x348.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:348,&quot;width&quot;:1102,&quot;resizeWidth&quot;:402,&quot;bytes&quot;:205237,&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://blog.algomaster.io/i/189045631?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70289d23-0f30-447c-93cb-8773bb71c36c_1102x348.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_!Z7V0!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70289d23-0f30-447c-93cb-8773bb71c36c_1102x348.png 424w, https://substackcdn.com/image/fetch/$s_!Z7V0!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70289d23-0f30-447c-93cb-8773bb71c36c_1102x348.png 848w, https://substackcdn.com/image/fetch/$s_!Z7V0!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70289d23-0f30-447c-93cb-8773bb71c36c_1102x348.png 1272w, https://substackcdn.com/image/fetch/$s_!Z7V0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70289d23-0f30-447c-93cb-8773bb71c36c_1102x348.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>This is one of the most common issues people encounter with language models. A <strong>hallucination</strong> happens when an LLM produces something that sounds confident and believable, but is actually incorrect. It might reference a research paper that does not exist, invent a function in a software library, or present a fabricated statistic as if it were widely known.</p><h4>Why does this happen? </h4><p>Because LLMs are pattern completion engines at heart. They&#8217;re optimized to produce fluent, probable text, not to verify whether that text is true. If the most &#8220;natural&#8221; next sentence happens to be false, the model will produce it with the exact same confidence as a true one.</p><p>This makes hallucination one of the biggest practical challenges when using LLMs in real applications. Common ways to reduce it include retrieval-augmented generation (RAG), grounding responses in trusted source documents, and prompting the model to provide citations or acknowledge uncertainty.</p><div><hr></div><h1>Training and Optimization</h1><p>At this point we have a powerful LLM, but it&#8217;s a generalist. How do you make it better at your specific task? And how do you shrink it enough to actually deploy?</p><p>These four techniques cover the spectrum from heavy customization to lightweight compression.</p><h2>11. Fine-tuning</h2><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!QLiy!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d78ba26-5617-42f0-8559-1e6013450e17_1854x606.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!QLiy!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d78ba26-5617-42f0-8559-1e6013450e17_1854x606.png 424w, https://substackcdn.com/image/fetch/$s_!QLiy!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d78ba26-5617-42f0-8559-1e6013450e17_1854x606.png 848w, https://substackcdn.com/image/fetch/$s_!QLiy!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d78ba26-5617-42f0-8559-1e6013450e17_1854x606.png 1272w, https://substackcdn.com/image/fetch/$s_!QLiy!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d78ba26-5617-42f0-8559-1e6013450e17_1854x606.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!QLiy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d78ba26-5617-42f0-8559-1e6013450e17_1854x606.png" width="594" height="194.19230769230768" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4d78ba26-5617-42f0-8559-1e6013450e17_1854x606.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:476,&quot;width&quot;:1456,&quot;resizeWidth&quot;:594,&quot;bytes&quot;:379481,&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://blog.algomaster.io/i/189045631?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d78ba26-5617-42f0-8559-1e6013450e17_1854x606.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_!QLiy!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d78ba26-5617-42f0-8559-1e6013450e17_1854x606.png 424w, https://substackcdn.com/image/fetch/$s_!QLiy!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d78ba26-5617-42f0-8559-1e6013450e17_1854x606.png 848w, https://substackcdn.com/image/fetch/$s_!QLiy!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d78ba26-5617-42f0-8559-1e6013450e17_1854x606.png 1272w, https://substackcdn.com/image/fetch/$s_!QLiy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d78ba26-5617-42f0-8559-1e6013450e17_1854x606.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Fine-tuning starts with a pretrained model and continues training it on a smaller, task-specific dataset. The base model already understands general language patterns. Fine-tuning simply nudges it toward a particular domain, style, or behavior.</p><p>For example, if you want a model that performs well on medical question answering, you might fine-tune a general-purpose LLM on thousands of high-quality medical conversations or clinical explanations.</p><p>The trade-off is cost and infrastructure. Traditional fine-tuning updates most or all of the model&#8217;s parameters. That requires enough GPU memory to load the entire model along with optimizer states and gradients during training. </p><p>For a 70B parameter model, this typically means multiple high-end GPUs and significant compute resources. Fine-tuning can be powerful, but it is not lightweight.</p><h2>12. RLHF (Reinforcement Learning from Human Feedback)</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!cpi6!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc0eed8de-7f88-4dcd-a169-84aa8840725b_1036x714.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!cpi6!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc0eed8de-7f88-4dcd-a169-84aa8840725b_1036x714.png 424w, https://substackcdn.com/image/fetch/$s_!cpi6!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc0eed8de-7f88-4dcd-a169-84aa8840725b_1036x714.png 848w, https://substackcdn.com/image/fetch/$s_!cpi6!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc0eed8de-7f88-4dcd-a169-84aa8840725b_1036x714.png 1272w, https://substackcdn.com/image/fetch/$s_!cpi6!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc0eed8de-7f88-4dcd-a169-84aa8840725b_1036x714.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!cpi6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc0eed8de-7f88-4dcd-a169-84aa8840725b_1036x714.png" width="490" height="337.7027027027027" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c0eed8de-7f88-4dcd-a169-84aa8840725b_1036x714.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:714,&quot;width&quot;:1036,&quot;resizeWidth&quot;:490,&quot;bytes&quot;:261954,&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://blog.algomaster.io/i/189045631?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc0eed8de-7f88-4dcd-a169-84aa8840725b_1036x714.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_!cpi6!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc0eed8de-7f88-4dcd-a169-84aa8840725b_1036x714.png 424w, https://substackcdn.com/image/fetch/$s_!cpi6!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc0eed8de-7f88-4dcd-a169-84aa8840725b_1036x714.png 848w, https://substackcdn.com/image/fetch/$s_!cpi6!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc0eed8de-7f88-4dcd-a169-84aa8840725b_1036x714.png 1272w, https://substackcdn.com/image/fetch/$s_!cpi6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc0eed8de-7f88-4dcd-a169-84aa8840725b_1036x714.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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>RLHF (Reinforcement Learning from Human Feedback) is one of the main techniques that turns &#8220;a model that predicts the next token&#8221; into &#8220;a model that feels helpful, polite, and safe to use.&#8221; It is a big reason modern chatbots feel like they are having a conversation, not just doing high-quality autocomplete.</p><p>At a high level, the process works like this:</p><ol><li><p><strong>Generate candidate answers.</strong> For a given prompt, the model produces multiple possible responses.</p></li><li><p><strong>Humans rank them.</strong> Human reviewers compare those responses and rank them based on qualities like helpfulness, correctness, clarity, and safety.</p></li><li><p><strong>Train a reward model.</strong> A separate model learns to predict which responses humans would prefer, based on those rankings.</p></li><li><p><strong>Tune the LLM using that reward signal.</strong> The LLM is then optimized to produce answers that score higher according to the reward model.</p></li></ol><p>This teaches the model behaviors that plain next-token prediction does not reliably produce: following instructions, refusing unsafe requests, being more balanced, and avoiding harmful or toxic directions. </p><p>Without RLHF (or other alignment methods), an LLM would be far more likely to continue text in whatever direction seems statistically plausible, even when that direction is unhelpful, misleading, or unsafe.</p><h2>13. LoRA (Low-Rank Adaptation)</h2><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!CvJ-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea9ba88d-6b95-4bf6-9d3c-c0b6e9378f88_1542x582.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!CvJ-!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea9ba88d-6b95-4bf6-9d3c-c0b6e9378f88_1542x582.png 424w, https://substackcdn.com/image/fetch/$s_!CvJ-!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea9ba88d-6b95-4bf6-9d3c-c0b6e9378f88_1542x582.png 848w, https://substackcdn.com/image/fetch/$s_!CvJ-!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea9ba88d-6b95-4bf6-9d3c-c0b6e9378f88_1542x582.png 1272w, https://substackcdn.com/image/fetch/$s_!CvJ-!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea9ba88d-6b95-4bf6-9d3c-c0b6e9378f88_1542x582.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!CvJ-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea9ba88d-6b95-4bf6-9d3c-c0b6e9378f88_1542x582.png" width="619" height="233.82554945054946" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ea9ba88d-6b95-4bf6-9d3c-c0b6e9378f88_1542x582.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:550,&quot;width&quot;:1456,&quot;resizeWidth&quot;:619,&quot;bytes&quot;:319982,&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://blog.algomaster.io/i/189045631?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea9ba88d-6b95-4bf6-9d3c-c0b6e9378f88_1542x582.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_!CvJ-!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea9ba88d-6b95-4bf6-9d3c-c0b6e9378f88_1542x582.png 424w, https://substackcdn.com/image/fetch/$s_!CvJ-!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea9ba88d-6b95-4bf6-9d3c-c0b6e9378f88_1542x582.png 848w, https://substackcdn.com/image/fetch/$s_!CvJ-!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea9ba88d-6b95-4bf6-9d3c-c0b6e9378f88_1542x582.png 1272w, https://substackcdn.com/image/fetch/$s_!CvJ-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea9ba88d-6b95-4bf6-9d3c-c0b6e9378f88_1542x582.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Fine-tuning every parameter in a large model, like a 70B parameter LLM, is extremely expensive. <strong>LoRA (Low-Rank Adaptation)</strong> takes a much more efficient approach.</p><p>Instead of updating the model&#8217;s original weights, it <strong>freezes them</strong> and adds small, trainable adapter matrices into selected layers. These adapters usually contain only about <strong>0.1% to 1% of the total parameters</strong>.</p><p>The key insight is that the weight changes during fine-tuning tend to be &#8220;low-rank,&#8221; meaning they can be approximated by much smaller matrices without losing much quality. Instead of updating a 4096x4096 weight matrix, LoRA adds two small matrices (4096x8 and 8x4096) that together approximate the same change.</p><h4>Why does this matter in practice? </h4><p>You can fine-tune on a single GPU what would otherwise require a whole cluster. And you can swap different LoRA adapters in and out of the same base model, so you get multiple specialized versions without storing a full copy of the model for each one.</p><h2>14. Quantization</h2><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!MgxR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc669ce9-0ca6-4f82-8675-3a1a3c84f34e_1348x572.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!MgxR!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc669ce9-0ca6-4f82-8675-3a1a3c84f34e_1348x572.png 424w, https://substackcdn.com/image/fetch/$s_!MgxR!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc669ce9-0ca6-4f82-8675-3a1a3c84f34e_1348x572.png 848w, https://substackcdn.com/image/fetch/$s_!MgxR!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc669ce9-0ca6-4f82-8675-3a1a3c84f34e_1348x572.png 1272w, https://substackcdn.com/image/fetch/$s_!MgxR!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc669ce9-0ca6-4f82-8675-3a1a3c84f34e_1348x572.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!MgxR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc669ce9-0ca6-4f82-8675-3a1a3c84f34e_1348x572.png" width="552" height="234.23145400593472" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cc669ce9-0ca6-4f82-8675-3a1a3c84f34e_1348x572.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:572,&quot;width&quot;:1348,&quot;resizeWidth&quot;:552,&quot;bytes&quot;:170012,&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://blog.algomaster.io/i/189045631?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc669ce9-0ca6-4f82-8675-3a1a3c84f34e_1348x572.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_!MgxR!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc669ce9-0ca6-4f82-8675-3a1a3c84f34e_1348x572.png 424w, https://substackcdn.com/image/fetch/$s_!MgxR!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc669ce9-0ca6-4f82-8675-3a1a3c84f34e_1348x572.png 848w, https://substackcdn.com/image/fetch/$s_!MgxR!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc669ce9-0ca6-4f82-8675-3a1a3c84f34e_1348x572.png 1272w, https://substackcdn.com/image/fetch/$s_!MgxR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc669ce9-0ca6-4f82-8675-3a1a3c84f34e_1348x572.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Quantization is a way to make models smaller and cheaper to run by <strong>storing their weights with fewer bits</strong>. In full precision, weights are often stored as 32-bit floating point values. Quantization reduces that to <strong>16-bit, 8-bit, or even 4-bit</strong>, cutting memory usage dramatically.</p><p>The basic math is straightforward: if you go from <strong>32-bit to 4-bit</strong>, each weight uses 8&#215; less memory, so the whole model becomes roughly <strong>8&#215; smaller</strong>. </p><p>For example, a 70B-parameter model can require well over <strong>100GB of memory</strong> at full precision, but a <strong>4-bit quantized</strong> version can fit into a few dozen GB. The quality drop is often smaller than you would expect, especially with <strong>8-bit quantization</strong>, which tends to preserve performance well for many tasks.</p><p>This is one of the main reasons large models can run on consumer hardware. When you see someone running a 70B model on a desktop GPU or even a laptop, it is almost always a <strong>quantized checkpoint</strong> rather than the full-precision model.</p><div><hr></div><h1>Prompting and Reasoning</h1><p>You&#8217;ve got a trained, optimized model. Now the question is: how do you actually get good output from it?</p><p>Turns out, a lot of it comes down to how you ask.</p><h2>15. Prompt Engineering</h2><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!XA6S!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F05309793-ee58-497f-aa20-1b28eb1ec767_1282x418.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!XA6S!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F05309793-ee58-497f-aa20-1b28eb1ec767_1282x418.png 424w, https://substackcdn.com/image/fetch/$s_!XA6S!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F05309793-ee58-497f-aa20-1b28eb1ec767_1282x418.png 848w, https://substackcdn.com/image/fetch/$s_!XA6S!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F05309793-ee58-497f-aa20-1b28eb1ec767_1282x418.png 1272w, https://substackcdn.com/image/fetch/$s_!XA6S!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F05309793-ee58-497f-aa20-1b28eb1ec767_1282x418.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!XA6S!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F05309793-ee58-497f-aa20-1b28eb1ec767_1282x418.png" width="536" height="174.7644305772231" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/05309793-ee58-497f-aa20-1b28eb1ec767_1282x418.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:418,&quot;width&quot;:1282,&quot;resizeWidth&quot;:536,&quot;bytes&quot;:291025,&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://blog.algomaster.io/i/189045631?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F05309793-ee58-497f-aa20-1b28eb1ec767_1282x418.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_!XA6S!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F05309793-ee58-497f-aa20-1b28eb1ec767_1282x418.png 424w, https://substackcdn.com/image/fetch/$s_!XA6S!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F05309793-ee58-497f-aa20-1b28eb1ec767_1282x418.png 848w, https://substackcdn.com/image/fetch/$s_!XA6S!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F05309793-ee58-497f-aa20-1b28eb1ec767_1282x418.png 1272w, https://substackcdn.com/image/fetch/$s_!XA6S!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F05309793-ee58-497f-aa20-1b28eb1ec767_1282x418.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Prompt engineering is the art of crafting your input to get better output. The same underlying question, phrased differently, can lead to dramatically different responses.</p><p>For example, a vague prompt like &#8220;explain databases&#8221; usually results in a high-level overview. But something more specific like &#8220;explain how B-tree indexes work in PostgreSQL, with a concrete example using a users table&#8221; gives the model clear direction.</p><p>Here are few techniques that consistently improve results:</p><ul><li><p><strong>Role context:</strong> &#8220;You are a senior database engineer.&#8221;</p></li><li><p><strong>Few-shot examples:</strong> Provide sample inputs and outputs to show the format and depth you expect.</p></li><li><p><strong>Step-by-step decomposition:</strong> Break complex tasks into smaller, explicit steps.</p></li><li><p><strong>Constraints:</strong> Limit length, specify structure, or define the desired tone.</p></li></ul><p>Prompt engineering is not a workaround. It is the primary interface for interacting with LLMs. The difference between a vague prompt and a carefully constructed one can mean the difference between shallow, generic output and something that is accurate, structured, and production-ready.</p><h2>16. Chain of Thought (CoT)</h2><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!BRAM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd476a06a-9a5e-433b-86f7-f7e95cf1f45e_1858x180.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!BRAM!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd476a06a-9a5e-433b-86f7-f7e95cf1f45e_1858x180.png 424w, https://substackcdn.com/image/fetch/$s_!BRAM!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd476a06a-9a5e-433b-86f7-f7e95cf1f45e_1858x180.png 848w, https://substackcdn.com/image/fetch/$s_!BRAM!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd476a06a-9a5e-433b-86f7-f7e95cf1f45e_1858x180.png 1272w, https://substackcdn.com/image/fetch/$s_!BRAM!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd476a06a-9a5e-433b-86f7-f7e95cf1f45e_1858x180.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!BRAM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd476a06a-9a5e-433b-86f7-f7e95cf1f45e_1858x180.png" width="608" height="58.879120879120876" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d476a06a-9a5e-433b-86f7-f7e95cf1f45e_1858x180.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:141,&quot;width&quot;:1456,&quot;resizeWidth&quot;:608,&quot;bytes&quot;:206459,&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://blog.algomaster.io/i/189045631?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd476a06a-9a5e-433b-86f7-f7e95cf1f45e_1858x180.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_!BRAM!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd476a06a-9a5e-433b-86f7-f7e95cf1f45e_1858x180.png 424w, https://substackcdn.com/image/fetch/$s_!BRAM!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd476a06a-9a5e-433b-86f7-f7e95cf1f45e_1858x180.png 848w, https://substackcdn.com/image/fetch/$s_!BRAM!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd476a06a-9a5e-433b-86f7-f7e95cf1f45e_1858x180.png 1272w, https://substackcdn.com/image/fetch/$s_!BRAM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd476a06a-9a5e-433b-86f7-f7e95cf1f45e_1858x180.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Chain of thought is a prompting technique where you ask the model to show its reasoning step by step before giving a final answer. Simple idea, but it makes a surprisingly big difference on math, logic, and multi-step reasoning.</p><p>Here&#8217;s a concrete example.</p><p><strong>Direct prompt:</strong> &#8220;What is 47 x 23?&#8221;</p><p>The model might output 1,071 (wrong) because it&#8217;s pattern-matching rather than actually computing.</p><p><strong>Chain of thought prompt:</strong> &#8220;What is 47 x 23? Think step by step.&#8221;</p><p>The model walks through: 47 x 20 = 940, 47 x 3 = 141, 940 + 141 = 1,081 (correct).</p><p>By making the model generate intermediate steps, you&#8217;re giving it &#8220;scratch space&#8221; to work through the problem instead of jumping straight to an answer. Research shows this can improve accuracy on reasoning benchmarks by 20-40%.</p><p>Better answers come from letting the model think out loud, rather than forcing it to jump straight to a conclusion.</p><div><hr></div><h1>Building AI Systems</h1><p>Knowing individual concepts is useful, but real AI products are systems, not solo models. This last section covers the building blocks engineers use to put it all together.</p><h2>17. RAG (Retrieval-Augmented Generation)</h2><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!AvRd!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb06df498-ff54-4816-b24d-f22703f70e6d_1850x642.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!AvRd!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb06df498-ff54-4816-b24d-f22703f70e6d_1850x642.png 424w, https://substackcdn.com/image/fetch/$s_!AvRd!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb06df498-ff54-4816-b24d-f22703f70e6d_1850x642.png 848w, https://substackcdn.com/image/fetch/$s_!AvRd!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb06df498-ff54-4816-b24d-f22703f70e6d_1850x642.png 1272w, https://substackcdn.com/image/fetch/$s_!AvRd!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb06df498-ff54-4816-b24d-f22703f70e6d_1850x642.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!AvRd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb06df498-ff54-4816-b24d-f22703f70e6d_1850x642.png" width="666" height="230.99587912087912" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b06df498-ff54-4816-b24d-f22703f70e6d_1850x642.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:505,&quot;width&quot;:1456,&quot;resizeWidth&quot;:666,&quot;bytes&quot;:338009,&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://blog.algomaster.io/i/189045631?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb06df498-ff54-4816-b24d-f22703f70e6d_1850x642.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_!AvRd!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb06df498-ff54-4816-b24d-f22703f70e6d_1850x642.png 424w, https://substackcdn.com/image/fetch/$s_!AvRd!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb06df498-ff54-4816-b24d-f22703f70e6d_1850x642.png 848w, https://substackcdn.com/image/fetch/$s_!AvRd!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb06df498-ff54-4816-b24d-f22703f70e6d_1850x642.png 1272w, https://substackcdn.com/image/fetch/$s_!AvRd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb06df498-ff54-4816-b24d-f22703f70e6d_1850x642.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Remember the hallucination problem? <strong>RAG (Retrieval-Augmented Generation)</strong> is one of the most effective ways to reduce it.</p><p>The idea is simple. Before the model generates a response, the system first <strong>retrieves relevant documents</strong> from a knowledge base and inserts them into the prompt as context. The model then answers using that information, instead of relying only on what it learned during training.</p><p>For example, imagine a customer support bot. When a user asks about your refund policy, the system first fetches the actual policy document, then the model generates an answer based on what it reads. The response is grounded in real, up-to-date information rather than vague recollection.</p><p>What makes RAG especially powerful is that it <strong>separates knowledge from reasoning</strong>.</p><ul><li><p>The LLM handles understanding and explanation.</p></li><li><p>Your document store provides the facts.</p></li></ul><p>If the information changes, you do not need to retrain the model. You simply update the documents it retrieves. This makes RAG practical, scalable, and far more reliable for real-world applications where accuracy matters.</p><h2>18. Vector Database</h2><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!UNyr!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F502c6166-3d54-48ea-b2d4-03cd1b1ddae6_1828x500.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!UNyr!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F502c6166-3d54-48ea-b2d4-03cd1b1ddae6_1828x500.png 424w, https://substackcdn.com/image/fetch/$s_!UNyr!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F502c6166-3d54-48ea-b2d4-03cd1b1ddae6_1828x500.png 848w, https://substackcdn.com/image/fetch/$s_!UNyr!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F502c6166-3d54-48ea-b2d4-03cd1b1ddae6_1828x500.png 1272w, https://substackcdn.com/image/fetch/$s_!UNyr!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F502c6166-3d54-48ea-b2d4-03cd1b1ddae6_1828x500.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!UNyr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F502c6166-3d54-48ea-b2d4-03cd1b1ddae6_1828x500.png" width="688" height="188.06593406593407" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/502c6166-3d54-48ea-b2d4-03cd1b1ddae6_1828x500.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:398,&quot;width&quot;:1456,&quot;resizeWidth&quot;:688,&quot;bytes&quot;:298628,&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://blog.algomaster.io/i/189045631?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F502c6166-3d54-48ea-b2d4-03cd1b1ddae6_1828x500.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_!UNyr!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F502c6166-3d54-48ea-b2d4-03cd1b1ddae6_1828x500.png 424w, https://substackcdn.com/image/fetch/$s_!UNyr!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F502c6166-3d54-48ea-b2d4-03cd1b1ddae6_1828x500.png 848w, https://substackcdn.com/image/fetch/$s_!UNyr!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F502c6166-3d54-48ea-b2d4-03cd1b1ddae6_1828x500.png 1272w, https://substackcdn.com/image/fetch/$s_!UNyr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F502c6166-3d54-48ea-b2d4-03cd1b1ddae6_1828x500.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>So how does RAG actually find the right documents? That is where <strong>vector databases</strong> come in. They store embeddings, the numerical vectors we discussed earlier, and allow you to search by meaning rather than exact keywords.</p><p>Here is how the flow works. Your documents are first split into smaller chunks. Each chunk is converted into an embedding, and those embeddings are stored in a vector database. </p><p>When a user asks a question, the query is also converted into an embedding. The database then searches for the stored vectors that are closest to the query vector and returns the most relevant chunks.</p><p>This creates a fundamentally different kind of search. A keyword search for &#8220;how to cancel my subscription&#8221; might miss a document titled &#8220;account termination process.&#8221; A vector search can still find it because the underlying meaning is similar, even though the wording is different.</p><p>Some widely used vector databases include Pinecone, Weaviate, Qdrant, and Chroma. PostgreSQL can also support vector search through the <strong>pgvector</strong> extension, which makes it possible to add semantic search capabilities to a familiar relational database.</p><h2>19. AI Agents</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!asWp!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5305d0d-9fdf-4a47-8349-324bcb95bc64_1272x642.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!asWp!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5305d0d-9fdf-4a47-8349-324bcb95bc64_1272x642.png 424w, https://substackcdn.com/image/fetch/$s_!asWp!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5305d0d-9fdf-4a47-8349-324bcb95bc64_1272x642.png 848w, https://substackcdn.com/image/fetch/$s_!asWp!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5305d0d-9fdf-4a47-8349-324bcb95bc64_1272x642.png 1272w, https://substackcdn.com/image/fetch/$s_!asWp!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5305d0d-9fdf-4a47-8349-324bcb95bc64_1272x642.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!asWp!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5305d0d-9fdf-4a47-8349-324bcb95bc64_1272x642.png" width="550" height="277.5943396226415" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c5305d0d-9fdf-4a47-8349-324bcb95bc64_1272x642.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:642,&quot;width&quot;:1272,&quot;resizeWidth&quot;:550,&quot;bytes&quot;:342118,&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://blog.algomaster.io/i/189045631?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5305d0d-9fdf-4a47-8349-324bcb95bc64_1272x642.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_!asWp!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5305d0d-9fdf-4a47-8349-324bcb95bc64_1272x642.png 424w, https://substackcdn.com/image/fetch/$s_!asWp!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5305d0d-9fdf-4a47-8349-324bcb95bc64_1272x642.png 848w, https://substackcdn.com/image/fetch/$s_!asWp!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5305d0d-9fdf-4a47-8349-324bcb95bc64_1272x642.png 1272w, https://substackcdn.com/image/fetch/$s_!asWp!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5305d0d-9fdf-4a47-8349-324bcb95bc64_1272x642.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 <strong>AI agent</strong> is an LLM that does more than generate text. It can <strong>take actions</strong>, make decisions, and interact with external tools to complete tasks. While a chatbot mainly responds with language, an agent can browse the web, run code, query databases, call APIs, and chain these actions together to achieve a goal.</p><p>Most agents follow a simple control loop:</p><ol><li><p><strong>Observe</strong> the current state or new information.</p></li><li><p><strong>Think</strong> about what to do next.</p></li><li><p><strong>Act</strong> by using a tool or taking a step.</p></li><li><p><strong>Repeat</strong> until the task is complete.</p></li></ol><p>The LLM serves as the decision-making engine that drives this loop.</p><p>For example, a coding agent might read a bug report, search the codebase for relevant files, analyze the logic, write a fix, run tests, see failures, revise the fix, and run the tests again until everything passes. Each step involves the model deciding what action to take next based on the latest results.</p><p>The biggest challenge is <strong>reliability</strong>. Every step has some chance of failure, and those risks multiply across long action chains. If a 10-step task has 95% accuracy per step, the chance of everything working perfectly end-to-end drops to about 60%. </p><p>That is why modern agent frameworks invest heavily in planning, validation, retries, and self-correction to keep multi-step workflows on track.</p><h2>20. Diffusion Models</h2><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!rbxz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb24e1423-96f9-442f-905e-ac681f1eb897_1848x562.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!rbxz!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb24e1423-96f9-442f-905e-ac681f1eb897_1848x562.png 424w, https://substackcdn.com/image/fetch/$s_!rbxz!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb24e1423-96f9-442f-905e-ac681f1eb897_1848x562.png 848w, https://substackcdn.com/image/fetch/$s_!rbxz!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb24e1423-96f9-442f-905e-ac681f1eb897_1848x562.png 1272w, https://substackcdn.com/image/fetch/$s_!rbxz!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb24e1423-96f9-442f-905e-ac681f1eb897_1848x562.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!rbxz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb24e1423-96f9-442f-905e-ac681f1eb897_1848x562.png" width="640" height="194.72527472527472" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b24e1423-96f9-442f-905e-ac681f1eb897_1848x562.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:443,&quot;width&quot;:1456,&quot;resizeWidth&quot;:640,&quot;bytes&quot;:533832,&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://blog.algomaster.io/i/189045631?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb24e1423-96f9-442f-905e-ac681f1eb897_1848x562.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_!rbxz!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb24e1423-96f9-442f-905e-ac681f1eb897_1848x562.png 424w, https://substackcdn.com/image/fetch/$s_!rbxz!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb24e1423-96f9-442f-905e-ac681f1eb897_1848x562.png 848w, https://substackcdn.com/image/fetch/$s_!rbxz!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb24e1423-96f9-442f-905e-ac681f1eb897_1848x562.png 1272w, https://substackcdn.com/image/fetch/$s_!rbxz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb24e1423-96f9-442f-905e-ac681f1eb897_1848x562.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Diffusion models are the engine behind many modern image generators, including DALL&#183;E, Midjourney, and Nano Banana (Gemini). The core idea is a bit counterintuitive: they learn to generate images by first learning how to corrupt them.</p><p>During training, you start with real images and gradually add random noise until the image becomes almost pure static. The model is then trained to reverse that process, step by step, learning how to remove a little noise at a time and reconstruct the original image.</p><p>At generation time, you flip the pipeline. You begin with pure noise, and the model iteratively denoises it into a coherent image, guided by your text prompt. Each step makes the image slightly more structured, typically over something like 20&#8211;50 denoising steps.</p><p>The term &#8220;diffusion&#8221; comes from physics, where randomness spreads through a medium like ink dispersing in water. In diffusion models, noise spreads through the image in a similar way, and the model learns the reverse trajectory: how to go from randomness back to signal.</p><p>This same idea now extends beyond images. Diffusion-style approaches are used for video generation, audio, 3D assets, and even scientific domains like molecule and protein structure generation.</p><div><hr></div><p>Thank you for reading!</p><p>If you found it valuable, hit a like &#10084;&#65039; and consider subscribing for more such content every week.</p><p>If you have any questions/suggestions, feel free to leave a comment.</p><div class="captioned-button-wrap" data-attrs="{&quot;url&quot;:&quot;https://blog.algomaster.io/p/20-ai-concepts-explained-simply?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">This post is public so feel free to share it.</p></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.algomaster.io/p/20-ai-concepts-explained-simply?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://blog.algomaster.io/p/20-ai-concepts-explained-simply?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p></div>]]></content:encoded></item><item><title><![CDATA[12 OOP Concepts EVERY Developer Should Know]]></title><description><![CDATA[Key Object-Oriented Programming Concepts]]></description><link>https://blog.algomaster.io/p/12-oop-concepts-every-developer-should-know</link><guid isPermaLink="false">https://blog.algomaster.io/p/12-oop-concepts-every-developer-should-know</guid><dc:creator><![CDATA[Ashish Pratap Singh]]></dc:creator><pubDate>Thu, 12 Feb 2026 04:27:26 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!GcX3!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F069b5b1c-ea4e-4c1e-b77b-640b236b8d83_2638x1320.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><strong>Object-Oriented Programming (OOP)</strong> gives you a practical way to structure software around real-world &#8220;things&#8221; like Users, Orders, Payments, and Notifications.</p><p>Instead of scattering data across variables and wiring behavior through unrelated functions, you <strong>bundle state and behavior</strong> into self-contained units. That makes code easier to reason about, extend, test, and maintain as the project grows.</p><p>But OOP is not just about writing classes. It is about understanding a small set of <strong>core ideas</strong> that help you model complexity, control change, and avoid turning your codebase into a fragile mess.</p><p>In this article, we&#8217;ll cover <strong>12 OOP concepts every developer should know</strong>, with real-world examples and code. These concepts also appear frequently in <strong><a href="https://algomaster.io/learn/lld/course-introduction">low-level design interviews</a></strong>. I&#8217;ve also included links to help you explore each concept in more depth.</p><p>Lets get started.</p><div><hr></div><h1>Building Blocks</h1><h1><a href="https://algomaster.io/learn/lld/classes-and-objects">1. Classes</a></h1><p>A <strong>class</strong> is a blueprint that defines the structure and behavior of objects. It specifies what data something will hold (fields) and what actions it can perform (methods).</p><blockquote><p><strong>Real-World Analogy:</strong> Think of it like an architectural blueprint for a house. The blueprint specifies the number of rooms, doors, and windows. But you can&#8217;t live in a blueprint. You need to build an actual house from it.</p></blockquote><pre><code>public class User {
    private String username;
    private String email;
    private String role;

    public User(String username, String email, String role) {
        this.username = username;
        this.email = email;
        this.role = role;
    }

    public boolean isAdmin() {
        return "ADMIN".equals(role);
    }

    public String getDisplayName() {
        return username + " (" + role + ")";
    }
}</code></pre><p>In the above example, the <code>User</code> class bundles <code>username</code>, <code>email</code>, and <code>role</code> together with the methods that operate on them.</p><p>But a class by itself doesn&#8217;t do anything. It&#8217;s just a template. To actually use it, you need to create objects.</p><div><hr></div><h1><a href="https://algomaster.io/learn/lld/classes-and-objects">2. Objects</a></h1><p>An <strong>object</strong> is a concrete instance of a class. It has actual values for the fields defined in the class.</p><p>If the class is a template, each object is a filled-in copy. You can create many objects from the same class, and each one is independent.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!GcX3!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F069b5b1c-ea4e-4c1e-b77b-640b236b8d83_2638x1320.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!GcX3!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F069b5b1c-ea4e-4c1e-b77b-640b236b8d83_2638x1320.png 424w, https://substackcdn.com/image/fetch/$s_!GcX3!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F069b5b1c-ea4e-4c1e-b77b-640b236b8d83_2638x1320.png 848w, https://substackcdn.com/image/fetch/$s_!GcX3!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F069b5b1c-ea4e-4c1e-b77b-640b236b8d83_2638x1320.png 1272w, https://substackcdn.com/image/fetch/$s_!GcX3!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F069b5b1c-ea4e-4c1e-b77b-640b236b8d83_2638x1320.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!GcX3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F069b5b1c-ea4e-4c1e-b77b-640b236b8d83_2638x1320.png" width="728" height="364.5" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/069b5b1c-ea4e-4c1e-b77b-640b236b8d83_2638x1320.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:729,&quot;width&quot;:1456,&quot;resizeWidth&quot;:728,&quot;bytes&quot;:206375,&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://blog.algomaster.io/i/156430373?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F069b5b1c-ea4e-4c1e-b77b-640b236b8d83_2638x1320.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_!GcX3!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F069b5b1c-ea4e-4c1e-b77b-640b236b8d83_2638x1320.png 424w, https://substackcdn.com/image/fetch/$s_!GcX3!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F069b5b1c-ea4e-4c1e-b77b-640b236b8d83_2638x1320.png 848w, https://substackcdn.com/image/fetch/$s_!GcX3!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F069b5b1c-ea4e-4c1e-b77b-640b236b8d83_2638x1320.png 1272w, https://substackcdn.com/image/fetch/$s_!GcX3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F069b5b1c-ea4e-4c1e-b77b-640b236b8d83_2638x1320.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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><pre><code>// Creating objects from the User class
User alice = new User("alice", "alice@example.com", "ADMIN");
User bob = new User("bob", "bob@example.com", "DEVELOPER");
User carol = new User("carol", "carol@example.com", "DEVELOPER");

alice.isAdmin();          // true
bob.isAdmin();            // false
alice.getDisplayName();   // alice (ADMIN)</code></pre><p>Each object has its own copy of the fields. Changing <code>alice</code>&#8216;s role doesn&#8217;t affect <code>bob</code>. They&#8217;re independent instances built from the same template.</p><p>Classes and objects let you group related data and behavior together. But in larger systems, you often need to define what behaviors must exist without specifying how they work. That&#8217;s where interfaces come in.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.algomaster.io/p/12-oop-concepts-every-developer-should-know?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://blog.algomaster.io/p/12-oop-concepts-every-developer-should-know?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><div><hr></div><h1><a href="https://algomaster.io/learn/lld/interfaces">3. Interfaces</a></h1><p>An <strong>interface</strong> is a contract. It defines a set of methods that a class must implement, without specifying how they should work.</p><p>Think about payment processing in an e-commerce app. You need to charge customers, but you don&#8217;t want to be locked into a single payment provider. So, you define a contract that says &#8220;any payment gateway must support charging and refunding,&#8221; and then Stripe, PayPal, Razorypay or any future provider can plug in.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!n0au!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23d60271-98ca-4bea-8cfd-675deac85692_2642x864.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!n0au!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23d60271-98ca-4bea-8cfd-675deac85692_2642x864.png 424w, https://substackcdn.com/image/fetch/$s_!n0au!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23d60271-98ca-4bea-8cfd-675deac85692_2642x864.png 848w, https://substackcdn.com/image/fetch/$s_!n0au!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23d60271-98ca-4bea-8cfd-675deac85692_2642x864.png 1272w, https://substackcdn.com/image/fetch/$s_!n0au!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23d60271-98ca-4bea-8cfd-675deac85692_2642x864.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!n0au!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23d60271-98ca-4bea-8cfd-675deac85692_2642x864.png" width="1456" height="476" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/23d60271-98ca-4bea-8cfd-675deac85692_2642x864.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:476,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:198247,&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://blog.algomaster.io/i/156430373?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23d60271-98ca-4bea-8cfd-675deac85692_2642x864.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_!n0au!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23d60271-98ca-4bea-8cfd-675deac85692_2642x864.png 424w, https://substackcdn.com/image/fetch/$s_!n0au!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23d60271-98ca-4bea-8cfd-675deac85692_2642x864.png 848w, https://substackcdn.com/image/fetch/$s_!n0au!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23d60271-98ca-4bea-8cfd-675deac85692_2642x864.png 1272w, https://substackcdn.com/image/fetch/$s_!n0au!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23d60271-98ca-4bea-8cfd-675deac85692_2642x864.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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><pre><code>public interface PaymentGateway {
    PaymentResult charge(String customerId, double amount);
    PaymentResult refund(String transactionId);
}

public class StripeGateway implements PaymentGateway {
    private String apiKey;

    public StripeGateway(String apiKey) {
        this.apiKey = apiKey;
    }

    @Override
    public PaymentResult charge(String customerId, double amount) {
        // Stripe-specific API call
        System.out.println("Charging $" + amount + " via Stripe");
        return new PaymentResult(true, "txn_stripe_123");
    }

    @Override
    public PaymentResult refund(String transactionId) {
        System.out.println("Refunding " + transactionId + " via Stripe");
        return new PaymentResult(true, transactionId);
    }
}

public class PayPalGateway implements PaymentGateway {
    @Override
    public PaymentResult charge(String customerId, double amount) {
        // PayPal-specific API call
        System.out.println("Charging $" + amount + " via PayPal");
        return new PaymentResult(true, "txn_paypal_456");
    }

    @Override
    public PaymentResult refund(String transactionId) {
        System.out.println("Refunding " + transactionId + " via PayPal");
        return new PaymentResult(true, transactionId);
    }
}</code></pre><p>The beauty of interfaces is that your checkout service can work with <code>PaymentGateway</code> without knowing whether it&#8217;s talking to Stripe or PayPal. Swapping providers means changing one line of configuration, not rewriting your business logic.</p><p>Interfaces tell you <strong>what</strong> classes must do. The four pillars of OOP tell you <strong>how</strong> to design those classes well.</p><div><hr></div><h1>The Four Pillars</h1><h1><a href="https://algomaster.io/learn/lld/encapsulation">4. Encapsulation</a></h1><p><strong>Encapsulation</strong> is the practice of <strong>bundling data and methods</strong> together in a class while restricting direct access to the internal data. You expose a controlled public interface and hide everything else.</p><p>Consider a rate limiter. Other parts of your system only need to ask &#8220;can this user make another request?&#8221; They shouldn&#8217;t be able to directly mess with the internal counters or reset the time window.</p><p>Here&#8217;s what happens without encapsulation:</p><pre><code>public class RateLimiter {
    public int requestCount;       // Anyone can modify directly
    public long windowStartTime;   // Anyone can reset the window
    public int maxRequests;
}

RateLimiter limiter = new RateLimiter();
limiter.requestCount = -100;       // Invalid state
limiter.windowStartTime = 0;       // Window broken</code></pre><p>And with encapsulation:</p><pre><code>public class RateLimiter {
    private int requestCount;
    private long windowStartTime;
    private final int maxRequests;
    private final long windowSizeMs;

    public RateLimiter(int maxRequests, long windowSizeMs) {
        this.maxRequests = maxRequests;
        this.windowSizeMs = windowSizeMs;
        this.windowStartTime = System.currentTimeMillis();
        this.requestCount = 0;
    }

    public boolean allowRequest() {
        resetWindowIfExpired();
        if (requestCount &lt; maxRequests) {
            requestCount++;
            return true;
        }
        return false;
    }

    public int getRemainingRequests() {
        resetWindowIfExpired();
        return maxRequests - requestCount;
    }

    private void resetWindowIfExpired() {
        long now = System.currentTimeMillis();
        if (now - windowStartTime &gt;= windowSizeMs) {
            requestCount = 0;
            windowStartTime = now;
        }
    }
}</code></pre><p>Now nobody can corrupt the internal state. The only way to interact with the limiter is through <code>allowRequest()</code> and <code>getRemainingRequests()</code>. The window-reset logic is completely internal. If you later switch from a fixed window to a sliding window algorithm, none of the calling code needs to change.</p><p>Encapsulation hides a class&#8217;s internal data. But there&#8217;s a closely related concept that hides complexity at a higher level.</p><div><hr></div><h1><a href="https://algomaster.io/learn/lld/abstraction">5. Abstraction</a></h1><p><strong>Abstraction</strong> is about <strong>hiding unnecessary complexity</strong> and exposing only what the user needs. While encapsulation hides data, abstraction hides implementation details.</p><blockquote><p><strong>Real-World Analogy:</strong> Think about sending a message through Slack. You type a message and hit send. Behind the scenes, there&#8217;s WebSocket management, message serialization, retry logic, delivery confirmation, and push notifications. You don&#8217;t deal with any of that. The complexity is abstracted away behind a simple action.</p></blockquote><p>In code, abstraction typically uses abstract classes or interfaces to define simplified interactions:</p><pre><code>public abstract class CloudStorage {
    // What the caller sees - one simple method
    public String upload(String fileName, byte[] data) {
        validate(fileName, data);
        String path = generatePath(fileName);
        String url = doUpload(path, data);
        logUpload(fileName, url);
        return url;
    }

    // Each provider implements its own upload logic
    protected abstract String doUpload(String path, byte[] data);

    private void validate(String fileName, byte[] data) {
        if (fileName == null || data.length == 0) {
            throw new IllegalArgumentException("Invalid file");
        }
    }

    private String generatePath(String fileName) {
        return "uploads/" + System.currentTimeMillis() + "/" + fileName;
    }

    private void logUpload(String fileName, String url) {
        System.out.println("Uploaded " + fileName + " to " + url);
    }
}

public class S3Storage extends CloudStorage {
    @Override
    protected String doUpload(String path, byte[] data) {
        // AWS SDK calls, multipart upload, encryption...
        return "https://s3.amazonaws.com/bucket/" + path;
    }
}

public class GcsStorage extends CloudStorage {
    @Override
    protected String doUpload(String path, byte[] data) {
        // Google Cloud SDK calls, resumable upload...
        return "https://storage.googleapis.com/bucket/" + path;
    }
}</code></pre><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!zKdS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9dd95a0-a11a-4b91-86d4-63aa061f721f_2634x440.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!zKdS!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9dd95a0-a11a-4b91-86d4-63aa061f721f_2634x440.png 424w, https://substackcdn.com/image/fetch/$s_!zKdS!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9dd95a0-a11a-4b91-86d4-63aa061f721f_2634x440.png 848w, https://substackcdn.com/image/fetch/$s_!zKdS!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9dd95a0-a11a-4b91-86d4-63aa061f721f_2634x440.png 1272w, https://substackcdn.com/image/fetch/$s_!zKdS!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9dd95a0-a11a-4b91-86d4-63aa061f721f_2634x440.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!zKdS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9dd95a0-a11a-4b91-86d4-63aa061f721f_2634x440.png" width="1456" height="243" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b9dd95a0-a11a-4b91-86d4-63aa061f721f_2634x440.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:243,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:93951,&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://blog.algomaster.io/i/156430373?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9dd95a0-a11a-4b91-86d4-63aa061f721f_2634x440.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_!zKdS!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9dd95a0-a11a-4b91-86d4-63aa061f721f_2634x440.png 424w, https://substackcdn.com/image/fetch/$s_!zKdS!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9dd95a0-a11a-4b91-86d4-63aa061f721f_2634x440.png 848w, https://substackcdn.com/image/fetch/$s_!zKdS!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9dd95a0-a11a-4b91-86d4-63aa061f721f_2634x440.png 1272w, https://substackcdn.com/image/fetch/$s_!zKdS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9dd95a0-a11a-4b91-86d4-63aa061f721f_2634x440.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>The caller just invokes <code>upload()</code>. They don&#8217;t need to know about path generation, validation, or provider-specific SDK calls. All that complexity is abstracted away.</p><p>Abstraction simplifies how you interact with objects. But what if multiple classes share the same data and behavior? That&#8217;s where inheritance steps in.</p><div><hr></div><h1><a href="https://algomaster.io/learn/lld/inheritance">6. Inheritance</a></h1><p><strong>Inheritance</strong> lets a new class (child) <strong>derive</strong> from an existing class (parent), inheriting its fields and methods. The child class can reuse the parent&#8217;s code, add new behavior, or override existing behavior.</p><p>In an event-driven system, every event needs a timestamp, an event ID, and a source. But each specific event type carries its own payload. Instead of duplicating the common fields in every event class, you define them once in a base class.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!8NXj!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77f7b2e0-e5c2-48e3-86c2-78704f1d9197_2636x1282.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!8NXj!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77f7b2e0-e5c2-48e3-86c2-78704f1d9197_2636x1282.png 424w, https://substackcdn.com/image/fetch/$s_!8NXj!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77f7b2e0-e5c2-48e3-86c2-78704f1d9197_2636x1282.png 848w, https://substackcdn.com/image/fetch/$s_!8NXj!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77f7b2e0-e5c2-48e3-86c2-78704f1d9197_2636x1282.png 1272w, https://substackcdn.com/image/fetch/$s_!8NXj!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77f7b2e0-e5c2-48e3-86c2-78704f1d9197_2636x1282.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!8NXj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77f7b2e0-e5c2-48e3-86c2-78704f1d9197_2636x1282.png" width="1456" height="708" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/77f7b2e0-e5c2-48e3-86c2-78704f1d9197_2636x1282.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:708,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:244118,&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://blog.algomaster.io/i/156430373?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77f7b2e0-e5c2-48e3-86c2-78704f1d9197_2636x1282.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_!8NXj!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77f7b2e0-e5c2-48e3-86c2-78704f1d9197_2636x1282.png 424w, https://substackcdn.com/image/fetch/$s_!8NXj!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77f7b2e0-e5c2-48e3-86c2-78704f1d9197_2636x1282.png 848w, https://substackcdn.com/image/fetch/$s_!8NXj!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77f7b2e0-e5c2-48e3-86c2-78704f1d9197_2636x1282.png 1272w, https://substackcdn.com/image/fetch/$s_!8NXj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77f7b2e0-e5c2-48e3-86c2-78704f1d9197_2636x1282.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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><pre><code>public class DomainEvent {
    protected String eventId;
    protected String source;
    protected long timestamp;

    public DomainEvent(String source) {
        this.eventId = UUID.randomUUID().toString();
        this.source = source;
        this.timestamp = System.currentTimeMillis();
    }

    public String getEventId() {
        return eventId;
    }

    public long getTimestamp() {
        return timestamp;
    }
}

public class UserRegisteredEvent extends DomainEvent {
    private String userId;
    private String email;

    public UserRegisteredEvent(String userId, String email) {
        super("user-service");
        this.userId = userId;
        this.email = email;
    }

    public String getUserId() {
        return userId;
    }
}

public class OrderPlacedEvent extends DomainEvent {
    private String orderId;
    private double totalAmount;

    public OrderPlacedEvent(String orderId, double totalAmount) {
        super("order-service");
        this.orderId = orderId;
        this.totalAmount = totalAmount;
    }

    public String getOrderId() {
        return orderId;
    }
}</code></pre><p><code>UserRegisteredEvent</code> and <code>OrderPlacedEvent</code> both get <code>eventId</code>, <code>source</code>, <code>timestamp</code>, and <code>getEventId()</code> from <code>DomainEvent</code> without writing that code again. They also add their own unique fields.</p><p>Use inheritance when there&#8217;s a clear <strong>&#8220;is-a&#8221;</strong> relationship. A <code>UserRegisteredEvent</code> <strong>is a</strong> <code>DomainEvent</code>. A <code>StripeGateway</code> <strong>is a</strong> <code>PaymentGateway</code>. Avoid inheriting just to reuse code. If there&#8217;s no natural &#8220;is-a&#8221; relationship, use composition instead.</p><p>Inheritance lets classes share structure and behavior. But what happens when you call the same method on different child classes and get different results? </p><p>That&#8217;s polymorphism.</p><div><hr></div><h1><a href="https://algomaster.io/learn/lld/polymorphism">7. Polymorphism</a></h1><p>Polymorphism means &#8220;many forms.&#8221; It allows objects of different types to be treated through a common interface, with each type providing its own behavior.</p><p>There are two types:</p><ul><li><p><strong>Compile-time</strong> (method overloading): same method name, different parameters</p></li><li><p><strong>Runtime</strong> (method overriding): same method signature, different implementations in child classes</p></li></ul><p>Runtime polymorphism is the more powerful concept. Imagine a notification system that sends alerts through different channels:</p><pre><code>public interface NotificationChannel {
    void send(String recipient, String message);
}

public class EmailChannel implements NotificationChannel {
    @Override
    public void send(String recipient, String message) {
        // SMTP setup, HTML formatting, attachment handling...
        System.out.println("Email to " + recipient + ": " + message);
    }
}

public class SlackChannel implements NotificationChannel {
    @Override
    public void send(String recipient, String message) {
        // Slack API call, channel lookup, markdown formatting...
        System.out.println("Slack to #" + recipient + ": " + message);
    }
}

public class SmsChannel implements NotificationChannel {
    @Override
    public void send(String recipient, String message) {
        // Twilio API, phone number validation, character limits...
        System.out.println("SMS to " + recipient + ": " + message);
    }
}

// Polymorphism in action
List&lt;NotificationChannel&gt; channels = List.of(
    new EmailChannel(), new SlackChannel(), new SmsChannel()
);

for (NotificationChannel channel : channels) {
    channel.send("ops-team", "Server CPU above 90%");
    // Each channel sends the alert its own way
}</code></pre><p>The loop doesn&#8217;t know or care whether it&#8217;s sending an email, a Slack message, or an SMS. It calls <code>send()</code> on each one, and the right implementation runs automatically. If you add a <code>PagerDutyChannel</code> tomorrow, the loop works without any changes.</p><p>This is the real power of polymorphism: you can write code that works with abstractions, and it automatically handles new types as they&#8217;re added.</p><p>Now that we understand how individual classes are structured and designed, let&#8217;s look at how objects relate to each other.</p><div><hr></div><h1>Object Relationships</h1><h1><a href="https://algomaster.io/learn/lld/association">8. Association</a></h1><p><strong>Association</strong> represents a &#8220;knows-about&#8221; relationship between objects. Both objects exist independently. Neither owns or controls the other.</p><p>Think of a developer and a repository on GitHub. A developer contributes to multiple repositories, and a repository has multiple contributors. But if a developer deletes their account, the repository still exists. And if a repository is archived, the developer keeps working on other things.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ixU1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19c0d64e-22e6-4a49-9d3f-d475dd081477_1000x1448.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ixU1!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19c0d64e-22e6-4a49-9d3f-d475dd081477_1000x1448.png 424w, https://substackcdn.com/image/fetch/$s_!ixU1!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19c0d64e-22e6-4a49-9d3f-d475dd081477_1000x1448.png 848w, https://substackcdn.com/image/fetch/$s_!ixU1!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19c0d64e-22e6-4a49-9d3f-d475dd081477_1000x1448.png 1272w, https://substackcdn.com/image/fetch/$s_!ixU1!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19c0d64e-22e6-4a49-9d3f-d475dd081477_1000x1448.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ixU1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19c0d64e-22e6-4a49-9d3f-d475dd081477_1000x1448.png" width="392" height="567.616" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/19c0d64e-22e6-4a49-9d3f-d475dd081477_1000x1448.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1448,&quot;width&quot;:1000,&quot;resizeWidth&quot;:392,&quot;bytes&quot;:134108,&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://blog.algomaster.io/i/156430373?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19c0d64e-22e6-4a49-9d3f-d475dd081477_1000x1448.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_!ixU1!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19c0d64e-22e6-4a49-9d3f-d475dd081477_1000x1448.png 424w, https://substackcdn.com/image/fetch/$s_!ixU1!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19c0d64e-22e6-4a49-9d3f-d475dd081477_1000x1448.png 848w, https://substackcdn.com/image/fetch/$s_!ixU1!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19c0d64e-22e6-4a49-9d3f-d475dd081477_1000x1448.png 1272w, https://substackcdn.com/image/fetch/$s_!ixU1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19c0d64e-22e6-4a49-9d3f-d475dd081477_1000x1448.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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><pre><code>public class Developer {
    private String username;
    private List&lt;Repository&gt; repositories;

    public Developer(String username) {
        this.username = username;
        this.repositories = new ArrayList&lt;&gt;();
    }

    public void contributeTo(Repository repo) {
        repositories.add(repo);
    }
}

public class Repository {
    private String name;
    private List&lt;Developer&gt; contributors;

    public Repository(String name) {
        this.name = name;
        this.contributors = new ArrayList&lt;&gt;();
    }

    public void addContributor(Developer dev) {
        contributors.add(dev);
    }
}

// Both objects are created independently
Developer dev = new Developer("alice");
Repository repo = new Repository("payment-service");

// They reference each other, but neither owns the other
dev.contributeTo(repo);
repo.addContributor(dev);</code></pre><p>The key here is independence. Both <code>Developer</code> and <code>Repository</code> are created outside of each other and just hold references. Deleting one doesn&#8217;t affect the other.</p><p>Association is the most general type of relationship. But sometimes, one object is part of another. That brings us to aggregation.</p><div><hr></div><h1><a href="https://algomaster.io/learn/lld/aggregation">9. Aggregation</a></h1><p><strong>Aggregation</strong> is a specialized form of association that represents a &#8220;has-a&#8221; relationship where the whole contains parts, but the parts can exist independently.</p><p>Think of a team and its microservices. A team owns multiple microservices, but if the team is reorganized, the services don&#8217;t disappear. They get reassigned to a different team.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!9_af!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8e7a9b29-bbfa-444b-8aa1-054e1ab20f2e_1000x1448.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!9_af!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8e7a9b29-bbfa-444b-8aa1-054e1ab20f2e_1000x1448.png 424w, https://substackcdn.com/image/fetch/$s_!9_af!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8e7a9b29-bbfa-444b-8aa1-054e1ab20f2e_1000x1448.png 848w, https://substackcdn.com/image/fetch/$s_!9_af!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8e7a9b29-bbfa-444b-8aa1-054e1ab20f2e_1000x1448.png 1272w, https://substackcdn.com/image/fetch/$s_!9_af!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8e7a9b29-bbfa-444b-8aa1-054e1ab20f2e_1000x1448.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!9_af!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8e7a9b29-bbfa-444b-8aa1-054e1ab20f2e_1000x1448.png" width="384" height="556.032" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8e7a9b29-bbfa-444b-8aa1-054e1ab20f2e_1000x1448.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1448,&quot;width&quot;:1000,&quot;resizeWidth&quot;:384,&quot;bytes&quot;:119624,&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://blog.algomaster.io/i/156430373?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8e7a9b29-bbfa-444b-8aa1-054e1ab20f2e_1000x1448.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_!9_af!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8e7a9b29-bbfa-444b-8aa1-054e1ab20f2e_1000x1448.png 424w, https://substackcdn.com/image/fetch/$s_!9_af!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8e7a9b29-bbfa-444b-8aa1-054e1ab20f2e_1000x1448.png 848w, https://substackcdn.com/image/fetch/$s_!9_af!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8e7a9b29-bbfa-444b-8aa1-054e1ab20f2e_1000x1448.png 1272w, https://substackcdn.com/image/fetch/$s_!9_af!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8e7a9b29-bbfa-444b-8aa1-054e1ab20f2e_1000x1448.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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><pre><code>public class Team {
    private String name;
    private List&lt;Microservice&gt; services;

    public Team(String name) {
        this.name = name;
        this.services = new ArrayList&lt;&gt;();
    }

    // Services are created outside and assigned to the team
    public void addService(Microservice service) {
        services.add(service);
    }

    public void removeService(Microservice service) {
        services.remove(service);
    }
}

public class Microservice {
    private String name;
    private String repoUrl;

    public Microservice(String name, String repoUrl) {
        this.name = name;
        this.repoUrl = repoUrl;
    }
}

// Microservice exists independently
Microservice paymentService = new Microservice("payment-service", "github.com/org/payments");

// Team references the service but doesn't own it
Team platformTeam = new Team("Platform");
platformTeam.addService(paymentService);

// Service can be reassigned to another team
Team checkoutTeam = new Team("Checkout");
checkoutTeam.addService(paymentService);</code></pre><p>The team has services, but services have their own lifecycle. They exist before being assigned to a team and continue to exist after being reassigned.</p><p>In aggregation, parts can survive without the whole. But what if the parts are so tightly coupled to the whole that they shouldn&#8217;t exist independently? </p><p>That&#8217;s composition.</p><div><hr></div><h1><a href="https://algomaster.io/learn/lld/composition">10. Composition</a></h1><p><strong>Composition</strong> is a strong form of &#8220;has-a&#8221; where the whole owns the parts entirely. When the whole is destroyed, the parts are destroyed with it. The parts have no meaning outside of the whole.</p><p>Think of an order and its line items. Each line item (2x T-Shirt, 1x Laptop) only exists as part of that specific order. If the order is cancelled and deleted, the line items go with it. A line item floating around without an order makes no sense.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!9CCE!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65ee825d-3f5b-4b7c-a614-cc474ddddbe7_910x1448.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!9CCE!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65ee825d-3f5b-4b7c-a614-cc474ddddbe7_910x1448.png 424w, https://substackcdn.com/image/fetch/$s_!9CCE!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65ee825d-3f5b-4b7c-a614-cc474ddddbe7_910x1448.png 848w, https://substackcdn.com/image/fetch/$s_!9CCE!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65ee825d-3f5b-4b7c-a614-cc474ddddbe7_910x1448.png 1272w, https://substackcdn.com/image/fetch/$s_!9CCE!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65ee825d-3f5b-4b7c-a614-cc474ddddbe7_910x1448.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!9CCE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65ee825d-3f5b-4b7c-a614-cc474ddddbe7_910x1448.png" width="360" height="572.8351648351648" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/65ee825d-3f5b-4b7c-a614-cc474ddddbe7_910x1448.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1448,&quot;width&quot;:910,&quot;resizeWidth&quot;:360,&quot;bytes&quot;:123665,&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://blog.algomaster.io/i/156430373?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65ee825d-3f5b-4b7c-a614-cc474ddddbe7_910x1448.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_!9CCE!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65ee825d-3f5b-4b7c-a614-cc474ddddbe7_910x1448.png 424w, https://substackcdn.com/image/fetch/$s_!9CCE!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65ee825d-3f5b-4b7c-a614-cc474ddddbe7_910x1448.png 848w, https://substackcdn.com/image/fetch/$s_!9CCE!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65ee825d-3f5b-4b7c-a614-cc474ddddbe7_910x1448.png 1272w, https://substackcdn.com/image/fetch/$s_!9CCE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65ee825d-3f5b-4b7c-a614-cc474ddddbe7_910x1448.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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><pre><code>public class Order {
    private String orderId;
    private List&lt;LineItem&gt; lineItems;  // Order creates and owns line items

    public Order(String orderId) {
        this.orderId = orderId;
        this.lineItems = new ArrayList&lt;&gt;();
    }

    // Order creates the line item internally
    public void addItem(String productId, String productName, int quantity, double price) {
        lineItems.add(new LineItem(productId, productName, quantity, price));
    }

    public double getTotal() {
        return lineItems.stream()
            .mapToDouble(LineItem::getSubtotal)
            .sum();
    }

    public void cancel() {
        lineItems.clear();  // Line items destroyed with the order
        System.out.println("Order " + orderId + " cancelled");
    }
}

public class LineItem {
    private String productId;
    private String productName;
    private int quantity;
    private double unitPrice;

    // Package-private: only Order should create line items
    LineItem(String productId, String productName, int quantity, double unitPrice) {
        this.productId = productId;
        this.productName = productName;
        this.quantity = quantity;
        this.unitPrice = unitPrice;
    }

    double getSubtotal() {
        return quantity * unitPrice;
    }
}

// Order creates line items internally - they don't exist outside
Order order = new Order("ORD-001");
order.addItem("SKU-100", "Mechanical Keyboard", 1, 149.99);
order.addItem("SKU-200", "USB-C Hub", 2, 39.99);
System.out.println(order.getTotal());  // 229.97
order.cancel();  // All line items destroyed</code></pre><p>Notice the difference from aggregation: in composition, the whole creates its parts internally (<code>new LineItem(...)</code> inside <code>addItem</code>). In aggregation, parts are passed in from outside.</p><p>Composition is about ownership and lifecycle control. But not all relationships involve ownership. Sometimes one object just temporarily uses another. </p><p>That&#8217;s dependency.</p><div><hr></div><h1><a href="https://algomaster.io/learn/lld/dependency">11. Dependency</a></h1><p>Dependency is the weakest relationship between classes. It represents a temporary &#8220;uses-a&#8221; connection where one class uses another, typically as a method parameter, local variable, or return type, but doesn&#8217;t hold a long-term reference to it.</p><p>Think of a deployment pipeline. The pipeline uses a logger to record what&#8217;s happening, but it doesn&#8217;t own the logger or keep it around as part of its state. It just uses it during execution and moves on.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!fP-X!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6da387f1-f884-40bd-85ce-5e4ba069037e_1518x1442.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!fP-X!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6da387f1-f884-40bd-85ce-5e4ba069037e_1518x1442.png 424w, https://substackcdn.com/image/fetch/$s_!fP-X!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6da387f1-f884-40bd-85ce-5e4ba069037e_1518x1442.png 848w, https://substackcdn.com/image/fetch/$s_!fP-X!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6da387f1-f884-40bd-85ce-5e4ba069037e_1518x1442.png 1272w, https://substackcdn.com/image/fetch/$s_!fP-X!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6da387f1-f884-40bd-85ce-5e4ba069037e_1518x1442.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!fP-X!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6da387f1-f884-40bd-85ce-5e4ba069037e_1518x1442.png" width="536" height="509.1263736263736" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6da387f1-f884-40bd-85ce-5e4ba069037e_1518x1442.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1383,&quot;width&quot;:1456,&quot;resizeWidth&quot;:536,&quot;bytes&quot;:114661,&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://blog.algomaster.io/i/156430373?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6da387f1-f884-40bd-85ce-5e4ba069037e_1518x1442.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_!fP-X!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6da387f1-f884-40bd-85ce-5e4ba069037e_1518x1442.png 424w, https://substackcdn.com/image/fetch/$s_!fP-X!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6da387f1-f884-40bd-85ce-5e4ba069037e_1518x1442.png 848w, https://substackcdn.com/image/fetch/$s_!fP-X!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6da387f1-f884-40bd-85ce-5e4ba069037e_1518x1442.png 1272w, https://substackcdn.com/image/fetch/$s_!fP-X!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6da387f1-f884-40bd-85ce-5e4ba069037e_1518x1442.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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><pre><code>public class DeploymentService {
    // Dependency: uses HttpClient temporarily, doesn't store it
    public DeploymentResult deploy(String serviceName, String version, HttpClient client) {
        String url = "https://deploy.internal/" + serviceName;
        HttpResponse response = client.post(url, Map.of("version", version));

        if (response.getStatusCode() == 200) {
            return new DeploymentResult(true, "Deployed " + serviceName + " v" + version);
        }
        return new DeploymentResult(false, "Deployment failed: " + response.getBody());
    }
}

public class HttpClient {
    public HttpResponse post(String url, Map&lt;String, String&gt; body) {
        // HTTP connection setup, request serialization, TLS...
        System.out.println("POST " + url);
        return new HttpResponse(200, "OK");
    }
}

// DeploymentService uses HttpClient but doesn't own or store it
DeploymentService deployer = new DeploymentService();
HttpClient client = new HttpClient();
deployer.deploy("payment-service", "2.4.1", client);</code></pre><p><code>DeploymentService</code> depends on <code>HttpClient</code>, but only during the <code>deploy()</code> call. It doesn&#8217;t store the client as a field. Once the method returns, the relationship is gone.</p><p>Dependency is the weakest of the object relationships. The last concept in our list brings us full circle, connecting interfaces back to the classes that implement them.</p><div><hr></div><h1><a href="https://algomaster.io/learn/lld/realization">12. Realization</a></h1><p>Realization is the relationship between an interface and the class that implements it. The class &#8220;realizes&#8221; the contract defined by the interface by providing concrete implementations of all its methods.</p><p>We already saw this with <code>PaymentGateway</code> in the interfaces section. Let&#8217;s look at another example, a cache store:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!fRji!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea85de17-565f-462f-a5a8-a6fbf118dc00_2214x1442.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!fRji!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea85de17-565f-462f-a5a8-a6fbf118dc00_2214x1442.png 424w, https://substackcdn.com/image/fetch/$s_!fRji!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea85de17-565f-462f-a5a8-a6fbf118dc00_2214x1442.png 848w, https://substackcdn.com/image/fetch/$s_!fRji!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea85de17-565f-462f-a5a8-a6fbf118dc00_2214x1442.png 1272w, https://substackcdn.com/image/fetch/$s_!fRji!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea85de17-565f-462f-a5a8-a6fbf118dc00_2214x1442.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!fRji!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea85de17-565f-462f-a5a8-a6fbf118dc00_2214x1442.png" width="1456" height="948" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ea85de17-565f-462f-a5a8-a6fbf118dc00_2214x1442.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:948,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:211721,&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://blog.algomaster.io/i/156430373?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea85de17-565f-462f-a5a8-a6fbf118dc00_2214x1442.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_!fRji!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea85de17-565f-462f-a5a8-a6fbf118dc00_2214x1442.png 424w, https://substackcdn.com/image/fetch/$s_!fRji!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea85de17-565f-462f-a5a8-a6fbf118dc00_2214x1442.png 848w, https://substackcdn.com/image/fetch/$s_!fRji!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea85de17-565f-462f-a5a8-a6fbf118dc00_2214x1442.png 1272w, https://substackcdn.com/image/fetch/$s_!fRji!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea85de17-565f-462f-a5a8-a6fbf118dc00_2214x1442.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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><pre><code>public interface CacheStore {
    void put(String key, String value, int ttlSeconds);
    String get(String key);
    void evict(String key);
}

public class RedisCache implements CacheStore {
    private String connectionUrl;

    public RedisCache(String connectionUrl) {
        this.connectionUrl = connectionUrl;
    }

    @Override
    public void put(String key, String value, int ttlSeconds) {
        // Redis SETEX command with TTL
        System.out.println("Redis SET " + key + " EX " + ttlSeconds);
    }

    @Override
    public String get(String key) {
        // Redis GET command
        System.out.println("Redis GET " + key);
        return null;  // Simplified
    }

    @Override
    public void evict(String key) {
        // Redis DEL command
        System.out.println("Redis DEL " + key);
    }
}</code></pre><p>Each class promises to fulfill the <code>CacheStore</code> contract. Your application code depends on <code>CacheStore</code>, so you can use Redis in production, an in-memory map in tests, and Memcached in a different environment, all without changing a single line of business logic.</p><p>Realization is what makes polymorphism through interfaces possible. It&#8217;s the bridge between abstract contracts and concrete behavior.</p><div><hr></div><h1>The Big Picture</h1><p>Here&#8217;s how all 12 concepts relate to each other:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!UUwt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53ceca09-b929-4302-a816-ecd34f1a946b_2648x982.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!UUwt!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53ceca09-b929-4302-a816-ecd34f1a946b_2648x982.png 424w, https://substackcdn.com/image/fetch/$s_!UUwt!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53ceca09-b929-4302-a816-ecd34f1a946b_2648x982.png 848w, https://substackcdn.com/image/fetch/$s_!UUwt!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53ceca09-b929-4302-a816-ecd34f1a946b_2648x982.png 1272w, https://substackcdn.com/image/fetch/$s_!UUwt!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53ceca09-b929-4302-a816-ecd34f1a946b_2648x982.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!UUwt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53ceca09-b929-4302-a816-ecd34f1a946b_2648x982.png" width="1456" height="540" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/53ceca09-b929-4302-a816-ecd34f1a946b_2648x982.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:540,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:164361,&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://blog.algomaster.io/i/156430373?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53ceca09-b929-4302-a816-ecd34f1a946b_2648x982.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_!UUwt!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53ceca09-b929-4302-a816-ecd34f1a946b_2648x982.png 424w, https://substackcdn.com/image/fetch/$s_!UUwt!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53ceca09-b929-4302-a816-ecd34f1a946b_2648x982.png 848w, https://substackcdn.com/image/fetch/$s_!UUwt!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53ceca09-b929-4302-a816-ecd34f1a946b_2648x982.png 1272w, https://substackcdn.com/image/fetch/$s_!UUwt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53ceca09-b929-4302-a816-ecd34f1a946b_2648x982.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 12 concepts form the foundation of object-oriented design. You don&#8217;t need to use all of them in every project, but understanding each one and knowing when to apply it will make you a better software engineer and help you tackle Low-Level Design interviews with confidence.</p><div><hr></div><p>Thank you for reading!</p><p>If you found it valuable, hit a like &#10084;&#65039; and consider subscribing for more such content every week.</p><p>If you have any questions/suggestions, feel free to leave a comment.</p><div class="captioned-button-wrap" data-attrs="{&quot;url&quot;:&quot;https://blog.algomaster.io/p/12-oop-concepts-every-developer-should-know?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">This post is public so feel free to share it.</p></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.algomaster.io/p/12-oop-concepts-every-developer-should-know?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://blog.algomaster.io/p/12-oop-concepts-every-developer-should-know?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p></div>]]></content:encoded></item><item><title><![CDATA[I created a comprehensive resource to master Concurrency Interviews]]></title><description><![CDATA[I&#8217;m excited to announce the launch of my premium Concurrency Interview resource, built to be the most complete, structured, and high-quality resources for concurrency interview prep available on the internet.]]></description><link>https://blog.algomaster.io/p/concurrency-interview-resource</link><guid isPermaLink="false">https://blog.algomaster.io/p/concurrency-interview-resource</guid><dc:creator><![CDATA[Ashish Pratap Singh]]></dc:creator><pubDate>Thu, 05 Feb 2026 14:06:24 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!QD7M!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c970fb5-a9f2-46c3-bd80-e8408439a6c6_2506x1736.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>I&#8217;m excited to announce the launch of my <strong><a href="https://algomaster.io/learn/concurrency-interview/introduction-to-concurrency">premium Concurrency Interview resource</a></strong>, built to be the most complete, structured, and high-quality resources for concurrency interview prep available on the internet.</p><p>It covers <strong>concurrency and synchronization fundamentals</strong>,<strong> multi-threading patterns</strong>, and <strong>25 commonly asked interview problems</strong> organized by category, each with detailed explanations and implementations. The content supports 5 languages<strong>: Java, Python, C++, C#, and Go</strong>.</p><p>I&#8217;ve kept a meaningful portion of the course (around ~50%) as free. For full access, you can <strong><a href="https://algomaster.io/premium">upgrade to premium plan</a></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_!QD7M!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c970fb5-a9f2-46c3-bd80-e8408439a6c6_2506x1736.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!QD7M!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c970fb5-a9f2-46c3-bd80-e8408439a6c6_2506x1736.png 424w, https://substackcdn.com/image/fetch/$s_!QD7M!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c970fb5-a9f2-46c3-bd80-e8408439a6c6_2506x1736.png 848w, https://substackcdn.com/image/fetch/$s_!QD7M!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c970fb5-a9f2-46c3-bd80-e8408439a6c6_2506x1736.png 1272w, https://substackcdn.com/image/fetch/$s_!QD7M!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c970fb5-a9f2-46c3-bd80-e8408439a6c6_2506x1736.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!QD7M!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c970fb5-a9f2-46c3-bd80-e8408439a6c6_2506x1736.png" width="1456" height="1009" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7c970fb5-a9f2-46c3-bd80-e8408439a6c6_2506x1736.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1009,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:611651,&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://blog.algomaster.io/i/186972392?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c970fb5-a9f2-46c3-bd80-e8408439a6c6_2506x1736.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_!QD7M!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c970fb5-a9f2-46c3-bd80-e8408439a6c6_2506x1736.png 424w, https://substackcdn.com/image/fetch/$s_!QD7M!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c970fb5-a9f2-46c3-bd80-e8408439a6c6_2506x1736.png 848w, https://substackcdn.com/image/fetch/$s_!QD7M!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c970fb5-a9f2-46c3-bd80-e8408439a6c6_2506x1736.png 1272w, https://substackcdn.com/image/fetch/$s_!QD7M!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c970fb5-a9f2-46c3-bd80-e8408439a6c6_2506x1736.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 class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://algomaster.io/learn/concurrency-interview/introduction-to-concurrency&quot;,&quot;text&quot;:&quot;Check it out here&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://algomaster.io/learn/concurrency-interview/introduction-to-concurrency"><span>Check it out here</span></a></p><p>This is in addition to my <strong><a href="https://algomaster.io/learn/lld/course-introduction">Low-Level Design course</a>,</strong> which covers core OOP concepts, design patterns and <strong>40 interview problems</strong>. I also updated my <strong><a href="https://github.com/ashishps1/awesome-low-level-design">LLD github repository</a></strong> with concurrency related topics.</p><div><hr></div><h2>What&#8217;s Inside?</h2><h3>25 Interview Problems (and growing)</h3><p>The course includes <strong>25 concurrency interview problems</strong>, with plans to add more over time.</p><p>For each problem, you get:</p><ul><li><p>The core concurrency challenges</p></li><li><p>Multiple synchronization approaches (so you learn trade-offs, not just one solution)</p></li><li><p>Clean implementations across supported languages</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_!LUJb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd17e152e-21dc-4eaa-89f0-f750ff159bac_3262x1912.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!LUJb!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd17e152e-21dc-4eaa-89f0-f750ff159bac_3262x1912.png 424w, https://substackcdn.com/image/fetch/$s_!LUJb!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd17e152e-21dc-4eaa-89f0-f750ff159bac_3262x1912.png 848w, https://substackcdn.com/image/fetch/$s_!LUJb!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd17e152e-21dc-4eaa-89f0-f750ff159bac_3262x1912.png 1272w, https://substackcdn.com/image/fetch/$s_!LUJb!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd17e152e-21dc-4eaa-89f0-f750ff159bac_3262x1912.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!LUJb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd17e152e-21dc-4eaa-89f0-f750ff159bac_3262x1912.png" width="1456" height="853" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d17e152e-21dc-4eaa-89f0-f750ff159bac_3262x1912.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:853,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:798244,&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://blog.algomaster.io/i/186972392?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd17e152e-21dc-4eaa-89f0-f750ff159bac_3262x1912.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_!LUJb!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd17e152e-21dc-4eaa-89f0-f750ff159bac_3262x1912.png 424w, https://substackcdn.com/image/fetch/$s_!LUJb!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd17e152e-21dc-4eaa-89f0-f750ff159bac_3262x1912.png 848w, https://substackcdn.com/image/fetch/$s_!LUJb!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd17e152e-21dc-4eaa-89f0-f750ff159bac_3262x1912.png 1272w, https://substackcdn.com/image/fetch/$s_!LUJb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd17e152e-21dc-4eaa-89f0-f750ff159bac_3262x1912.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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>Language Specific Deep-Dives</h3><p>Concurrency is deeply language-dependent. Each language has its own primitives, libraries, and best practices.</p><p>That&#8217;s why the course includes dedicated deep-dive chapters for each language, covering the key concurrency primitives and standard libraries.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!KvZR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8e8b34b3-cc02-4e27-a735-a3607b453c0a_2534x1914.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!KvZR!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8e8b34b3-cc02-4e27-a735-a3607b453c0a_2534x1914.png 424w, https://substackcdn.com/image/fetch/$s_!KvZR!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8e8b34b3-cc02-4e27-a735-a3607b453c0a_2534x1914.png 848w, https://substackcdn.com/image/fetch/$s_!KvZR!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8e8b34b3-cc02-4e27-a735-a3607b453c0a_2534x1914.png 1272w, https://substackcdn.com/image/fetch/$s_!KvZR!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8e8b34b3-cc02-4e27-a735-a3607b453c0a_2534x1914.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!KvZR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8e8b34b3-cc02-4e27-a735-a3607b453c0a_2534x1914.png" width="1456" height="1100" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8e8b34b3-cc02-4e27-a735-a3607b453c0a_2534x1914.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1100,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:499982,&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://blog.algomaster.io/i/186972392?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8e8b34b3-cc02-4e27-a735-a3607b453c0a_2534x1914.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_!KvZR!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8e8b34b3-cc02-4e27-a735-a3607b453c0a_2534x1914.png 424w, https://substackcdn.com/image/fetch/$s_!KvZR!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8e8b34b3-cc02-4e27-a735-a3607b453c0a_2534x1914.png 848w, https://substackcdn.com/image/fetch/$s_!KvZR!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8e8b34b3-cc02-4e27-a735-a3607b453c0a_2534x1914.png 1272w, https://substackcdn.com/image/fetch/$s_!KvZR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8e8b34b3-cc02-4e27-a735-a3607b453c0a_2534x1914.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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>400+ Diagrams</h3><p>Concurrency is easier to learn when you can visualize what threads are doing.</p><p>This course includes <strong>400+ diagrams</strong> (flowcharts, sequence diagrams, state diagrams, and more) to make the behavior of threads, locks, and coordination mechanisms feel intuitive.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!95mC!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d267471-e8c3-42e7-a9c3-d1df20ada48c_1592x1238.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!95mC!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d267471-e8c3-42e7-a9c3-d1df20ada48c_1592x1238.png 424w, https://substackcdn.com/image/fetch/$s_!95mC!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d267471-e8c3-42e7-a9c3-d1df20ada48c_1592x1238.png 848w, https://substackcdn.com/image/fetch/$s_!95mC!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d267471-e8c3-42e7-a9c3-d1df20ada48c_1592x1238.png 1272w, https://substackcdn.com/image/fetch/$s_!95mC!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d267471-e8c3-42e7-a9c3-d1df20ada48c_1592x1238.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!95mC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d267471-e8c3-42e7-a9c3-d1df20ada48c_1592x1238.png" width="1456" height="1132" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7d267471-e8c3-42e7-a9c3-d1df20ada48c_1592x1238.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1132,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:111650,&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://blog.algomaster.io/i/186972392?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d267471-e8c3-42e7-a9c3-d1df20ada48c_1592x1238.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_!95mC!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d267471-e8c3-42e7-a9c3-d1df20ada48c_1592x1238.png 424w, https://substackcdn.com/image/fetch/$s_!95mC!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d267471-e8c3-42e7-a9c3-d1df20ada48c_1592x1238.png 848w, https://substackcdn.com/image/fetch/$s_!95mC!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d267471-e8c3-42e7-a9c3-d1df20ada48c_1592x1238.png 1272w, https://substackcdn.com/image/fetch/$s_!95mC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d267471-e8c3-42e7-a9c3-d1df20ada48c_1592x1238.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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>Quizzes and Simulations</h3><p>There are quizzes after chapters to test and reinforce your understanding.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!alc6!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62cb1377-d779-4cde-b57b-5f48f526428f_1626x1350.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!alc6!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62cb1377-d779-4cde-b57b-5f48f526428f_1626x1350.png 424w, https://substackcdn.com/image/fetch/$s_!alc6!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62cb1377-d779-4cde-b57b-5f48f526428f_1626x1350.png 848w, https://substackcdn.com/image/fetch/$s_!alc6!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62cb1377-d779-4cde-b57b-5f48f526428f_1626x1350.png 1272w, https://substackcdn.com/image/fetch/$s_!alc6!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62cb1377-d779-4cde-b57b-5f48f526428f_1626x1350.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!alc6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62cb1377-d779-4cde-b57b-5f48f526428f_1626x1350.png" width="1456" height="1209" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/62cb1377-d779-4cde-b57b-5f48f526428f_1626x1350.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1209,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:185762,&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://blog.algomaster.io/i/186972392?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62cb1377-d779-4cde-b57b-5f48f526428f_1626x1350.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_!alc6!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62cb1377-d779-4cde-b57b-5f48f526428f_1626x1350.png 424w, https://substackcdn.com/image/fetch/$s_!alc6!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62cb1377-d779-4cde-b57b-5f48f526428f_1626x1350.png 848w, https://substackcdn.com/image/fetch/$s_!alc6!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62cb1377-d779-4cde-b57b-5f48f526428f_1626x1350.png 1272w, https://substackcdn.com/image/fetch/$s_!alc6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62cb1377-d779-4cde-b57b-5f48f526428f_1626x1350.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 interactive simulations to help you better understand the multi-threading concepts. I plan to add more simulations in coming weeks.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!cPXJ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd79a877-c04c-4be5-9d42-1c647770e40c_1592x1094.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!cPXJ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd79a877-c04c-4be5-9d42-1c647770e40c_1592x1094.png 424w, https://substackcdn.com/image/fetch/$s_!cPXJ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd79a877-c04c-4be5-9d42-1c647770e40c_1592x1094.png 848w, https://substackcdn.com/image/fetch/$s_!cPXJ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd79a877-c04c-4be5-9d42-1c647770e40c_1592x1094.png 1272w, https://substackcdn.com/image/fetch/$s_!cPXJ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd79a877-c04c-4be5-9d42-1c647770e40c_1592x1094.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!cPXJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd79a877-c04c-4be5-9d42-1c647770e40c_1592x1094.png" width="1456" height="1001" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/dd79a877-c04c-4be5-9d42-1c647770e40c_1592x1094.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1001,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:143160,&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://blog.algomaster.io/i/186972392?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd79a877-c04c-4be5-9d42-1c647770e40c_1592x1094.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_!cPXJ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd79a877-c04c-4be5-9d42-1c647770e40c_1592x1094.png 424w, https://substackcdn.com/image/fetch/$s_!cPXJ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd79a877-c04c-4be5-9d42-1c647770e40c_1592x1094.png 848w, https://substackcdn.com/image/fetch/$s_!cPXJ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd79a877-c04c-4be5-9d42-1c647770e40c_1592x1094.png 1272w, https://substackcdn.com/image/fetch/$s_!cPXJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd79a877-c04c-4be5-9d42-1c647770e40c_1592x1094.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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://algomaster.io/learn/concurrency-interview/introduction-to-concurrency&quot;,&quot;text&quot;:&quot;Check it out here&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://algomaster.io/learn/concurrency-interview/introduction-to-concurrency"><span>Check it out here</span></a></p><p>For any questions related to content or subscription, please reply to this email or reach out at <strong>contact@algomaster.io</strong></p>]]></content:encoded></item><item><title><![CDATA[7 Graph Algorithms You Should Know for Coding Interviews in 2026]]></title><description><![CDATA[This is a guest post by Shayan, an International Grandmaster on Codeforces and a PhD Candidate at the University of Maryland.]]></description><link>https://blog.algomaster.io/p/7-graph-algorithms-you-should-know</link><guid isPermaLink="false">https://blog.algomaster.io/p/7-graph-algorithms-you-should-know</guid><dc:creator><![CDATA[Ashish Pratap Singh]]></dc:creator><pubDate>Wed, 04 Feb 2026 04:03:02 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!1puy!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd166816b-b57e-40e3-ac90-33b31795d92e_1280x926.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>This is a guest post by <strong><a href="https://www.linkedin.com/in/shayan-chashm-jahan-32b4a2216/">Shayan</a></strong>, an <strong><a href="https://codeforces.com/profile/Shayan">International Grandmaster</a></strong> on Codeforces and a PhD Candidate at the University of Maryland.</p><p>In this post Shayan will share <strong>top 7 graph algorithms</strong> to know if you are preparing for coding interviews.</p><div><hr></div><p>Graphs come up in about 35-40% of coding interviews at major tech companies because so many real systems are graphs: social networks, map routing, dependency chains, web crawlers. If you don&#8217;t know core graph patterns, you&#8217;ll struggle in the interview.</p><p>I&#8217;ve seen candidates get stuck on problems like &#8220;Number of Islands&#8221; simply because they hadn&#8217;t practiced basic grid traversal. These problems become straightforward once you know the patterns.</p><p>In this post, I&#8217;ll show you 7 graph algorithms that cover about 85% of graph-related interview questions. For each one, you&#8217;ll learn what it does, when to use it, how it works, and which LeetCode problems to practice.</p><p>This post is based on <a href="https://repovive.com/roadmaps/graph-theory">Repovive's Graph Theory roadmap</a>. Let's get into it.</p><div><hr></div><h1>TL;DR: Algorithm Reference Table</h1><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Z7oD!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e4239b5-28d9-43d4-98d0-55bc9e59a73b_1130x475.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Z7oD!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e4239b5-28d9-43d4-98d0-55bc9e59a73b_1130x475.png 424w, https://substackcdn.com/image/fetch/$s_!Z7oD!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e4239b5-28d9-43d4-98d0-55bc9e59a73b_1130x475.png 848w, https://substackcdn.com/image/fetch/$s_!Z7oD!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e4239b5-28d9-43d4-98d0-55bc9e59a73b_1130x475.png 1272w, https://substackcdn.com/image/fetch/$s_!Z7oD!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e4239b5-28d9-43d4-98d0-55bc9e59a73b_1130x475.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Z7oD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e4239b5-28d9-43d4-98d0-55bc9e59a73b_1130x475.png" width="1130" height="475" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3e4239b5-28d9-43d4-98d0-55bc9e59a73b_1130x475.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:475,&quot;width&quot;:1130,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:102771,&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://blog.algomaster.io/i/186636009?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e4239b5-28d9-43d4-98d0-55bc9e59a73b_1130x475.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_!Z7oD!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e4239b5-28d9-43d4-98d0-55bc9e59a73b_1130x475.png 424w, https://substackcdn.com/image/fetch/$s_!Z7oD!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e4239b5-28d9-43d4-98d0-55bc9e59a73b_1130x475.png 848w, https://substackcdn.com/image/fetch/$s_!Z7oD!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e4239b5-28d9-43d4-98d0-55bc9e59a73b_1130x475.png 1272w, https://substackcdn.com/image/fetch/$s_!Z7oD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e4239b5-28d9-43d4-98d0-55bc9e59a73b_1130x475.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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><h1>1. Breadth-First Search (BFS)</h1><blockquote><p><strong>What it is:</strong> BFS explores a graph <strong>level by level</strong>. It visits every node at distance 1 from the start, then distance 2, then distance 3, and so on.</p></blockquote><h4>When to use it:</h4><p>Use BFS when the problem is naturally about <strong>layers</strong> or <strong>minimum steps</strong>:</p><ul><li><p>Finding the shortest path in an unweighted graph</p></li><li><p>Level-order traversal</p></li><li><p>Finding all nodes within K distance</p></li><li><p>Any problem that asks for &#8220;minimum steps&#8221; or &#8220;shortest path&#8221; without weights</p></li></ul><h4>How it works:</h4><p>BFS uses a <strong>queue</strong>. You start by adding the source node. Then you repeat: remove the front node, process it, and add all its unvisited neighbors to the back of the queue.</p><p>The queue enforces the level-by-level order. By the time you reach a node, you&#8217;ve visited all closer nodes first. This guarantees the first path you find is the shortest.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!WPv8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffadaa359-849f-460d-b6d7-74f1ec9a5a0f_1024x572.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!WPv8!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffadaa359-849f-460d-b6d7-74f1ec9a5a0f_1024x572.jpeg 424w, https://substackcdn.com/image/fetch/$s_!WPv8!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffadaa359-849f-460d-b6d7-74f1ec9a5a0f_1024x572.jpeg 848w, https://substackcdn.com/image/fetch/$s_!WPv8!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffadaa359-849f-460d-b6d7-74f1ec9a5a0f_1024x572.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!WPv8!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffadaa359-849f-460d-b6d7-74f1ec9a5a0f_1024x572.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!WPv8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffadaa359-849f-460d-b6d7-74f1ec9a5a0f_1024x572.jpeg" width="634" height="354.1484375" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fadaa359-849f-460d-b6d7-74f1ec9a5a0f_1024x572.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:572,&quot;width&quot;:1024,&quot;resizeWidth&quot;:634,&quot;bytes&quot;:32699,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/jpeg&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://blog.algomaster.io/i/186636009?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffadaa359-849f-460d-b6d7-74f1ec9a5a0f_1024x572.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_!WPv8!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffadaa359-849f-460d-b6d7-74f1ec9a5a0f_1024x572.jpeg 424w, https://substackcdn.com/image/fetch/$s_!WPv8!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffadaa359-849f-460d-b6d7-74f1ec9a5a0f_1024x572.jpeg 848w, https://substackcdn.com/image/fetch/$s_!WPv8!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffadaa359-849f-460d-b6d7-74f1ec9a5a0f_1024x572.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!WPv8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffadaa359-849f-460d-b6d7-74f1ec9a5a0f_1024x572.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><pre><code>queue = [start]
visited = {start}

while queue is not empty:
    node = queue.pop_front()
    for neighbor in node.neighbors:
        if neighbor not in visited:
            visited.add(neighbor)
            queue.push_back(neighbor)</code></pre><h4>Grid Problems (Flood Fill)</h4><p>BFS works well on 2D grids. </p><p>Think of grids like this:</p><ul><li><p>Each <strong>cell</strong> is a node</p></li><li><p>Its neighbors are usually <strong>up, down, left, right</strong> (sometimes diagonals too)</p></li></ul><p>Problems like &#8220;Number of Islands&#8221; and &#8220;Rotting Oranges&#8221; are grid-based BFS.</p><p>For flood fill, you start at a cell and spread to all connected cells matching a condition. You stop at boundaries or cells that don&#8217;t match. This is the algorithm behind the paint bucket tool in image editors.</p><h4>Practice these LeetCode problems:</h4><ul><li><p><a href="https://leetcode.com/problems/shortest-path-in-binary-matrix/">Shortest Path in Binary Matrix</a> (Medium)</p></li><li><p><a href="https://leetcode.com/problems/rotting-oranges/">Rotting Oranges</a> (Medium)</p></li><li><p><a href="https://leetcode.com/problems/number-of-islands/">Number of Islands</a> (Medium)</p></li><li><p><a href="https://leetcode.com/problems/01-matrix/">01 Matrix</a> (Medium)</p></li><li><p><a href="https://leetcode.com/problems/word-ladder/">Word Ladder</a> (Hard)</p></li></ul><div><hr></div><h1>2. Depth-First Search (DFS)</h1><blockquote><p><strong>What it is:</strong> DFS explores a graph <strong>as deep as possible</strong> before it backtracks. If a node has multiple neighbors, DFS fully explores the first neighbor&#8217;s branch, then returns and tries the next.</p></blockquote><h4>When to use it:</h4><p>DFS is the right tool when you care about <strong>reachability, structure, or exhaustive exploration</strong>, not minimum distance:</p><ul><li><p>Detecting cycles</p></li><li><p>Finding connected components</p></li><li><p>Path finding (when you don&#8217;t need the shortest path)</p></li><li><p>Backtracking problems</p></li><li><p>Tree traversals</p></li></ul><h4>How it works:</h4><p>A good mental model is a maze.</p><p>You choose a path, keep walking, and mark where you&#8217;ve been. When you hit a dead end, you backtrack to the last fork and try a different direction.</p><p>DFS uses a <strong>stack</strong>:</p><ul><li><p>Either an explicit stack you manage yourself</p></li><li><p>Or recursion, which uses the call stack implicitly</p></li></ul><p>Because the &#8220;most recent&#8221; node is processed next, DFS naturally pushes deeper into the graph.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!rCCf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7a65805-5de1-430e-8f90-d296bfec8ede_1113x1280.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!rCCf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7a65805-5de1-430e-8f90-d296bfec8ede_1113x1280.jpeg 424w, https://substackcdn.com/image/fetch/$s_!rCCf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7a65805-5de1-430e-8f90-d296bfec8ede_1113x1280.jpeg 848w, https://substackcdn.com/image/fetch/$s_!rCCf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7a65805-5de1-430e-8f90-d296bfec8ede_1113x1280.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!rCCf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7a65805-5de1-430e-8f90-d296bfec8ede_1113x1280.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!rCCf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7a65805-5de1-430e-8f90-d296bfec8ede_1113x1280.jpeg" width="458" height="526.7205750224618" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b7a65805-5de1-430e-8f90-d296bfec8ede_1113x1280.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1280,&quot;width&quot;:1113,&quot;resizeWidth&quot;:458,&quot;bytes&quot;:72725,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/jpeg&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://blog.algomaster.io/i/186636009?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7a65805-5de1-430e-8f90-d296bfec8ede_1113x1280.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_!rCCf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7a65805-5de1-430e-8f90-d296bfec8ede_1113x1280.jpeg 424w, https://substackcdn.com/image/fetch/$s_!rCCf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7a65805-5de1-430e-8f90-d296bfec8ede_1113x1280.jpeg 848w, https://substackcdn.com/image/fetch/$s_!rCCf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7a65805-5de1-430e-8f90-d296bfec8ede_1113x1280.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!rCCf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7a65805-5de1-430e-8f90-d296bfec8ede_1113x1280.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><pre><code>function dfs(node):
    if node in visited:
        return
    visited.add(node)

    for neighbor in node.neighbors:
        dfs(neighbor)</code></pre><h4>Cycle Detection</h4><p>DFS is one of the most common ways to detect cycles, but the exact rule depends on the graph type (directed vs undirected graphs).</p><p>For undirected graphs: if you reach a visited node that isn&#8217;t your immediate parent, you&#8217;ve found a cycle.</p><p>For directed graphs: you use three states (unvisited, in-progress, completed). If you reach an in-progress node, you&#8217;ve found a back edge, which means a cycle.</p><pre><code>// Directed graph cycle detection
state = [UNVISITED] * n

function hasCycle(node):
    state[node] = IN_PROGRESS

    for neighbor in node.neighbors:
        if state[neighbor] == IN_PROGRESS:
            return true  // cycle found
        if state[neighbor] == UNVISITED:
            if hasCycle(neighbor):
                return true

    state[node] = COMPLETED
    return false</code></pre><p><strong>Practice these LeetCode problems:</strong></p><ul><li><p><a href="https://leetcode.com/problems/clone-graph/">Clone Graph</a> (Medium)</p></li><li><p><a href="https://leetcode.com/problems/number-of-provinces/">Number of Provinces</a> (Medium)</p></li><li><p><a href="https://leetcode.com/problems/max-area-of-island/">Max Area of Island</a> (Medium)</p></li><li><p><a href="https://leetcode.com/problems/course-schedule/">Course Schedule</a> (Medium)</p></li><li><p><a href="https://leetcode.com/problems/all-paths-from-source-to-target/">All Paths From Source to Target</a> (Medium)</p></li></ul><div><hr></div><h1>3. Dijkstra&#8217;s Algorithm</h1><blockquote><p><strong>What it is:</strong> Dijkstra&#8217;s Algorithm finds the <strong>shortest path in a weighted graph</strong> where all edge weights are <strong>non-negative</strong>. Unlike BFS, it works when edges have different costs.</p></blockquote><h4>When to use it:</h4><p>Reach for Dijkstra when you see <strong>weights</strong> and the question is about <strong>minimum cost</strong>:</p><ul><li><p>Shortest path with weighted edges</p></li><li><p>Navigation and routing (Google Maps)</p></li><li><p>Network routing with latency costs</p></li><li><p>Any problem mentioning &#8220;minimum cost path&#8221;</p></li></ul><h4>How it works:</h4><p>BFS doesn&#8217;t work on weighted graphs because one step doesn&#8217;t equal one unit of distance. A direct path might cost 10 while a two-step path costs 2.</p><p>Dijkstra fixes this by always expanding the <strong>currently cheapest known node first</strong>:</p><ul><li><p>Maintain <code>dist[node]</code> = best known distance from the source</p></li><li><p>Use a <strong>min-heap / priority queue</strong> keyed by distance</p></li><li><p>Pop the node with the smallest distance, then relax its edges</p></li></ul><p>If the graph has only non-negative weights, the first time a node is popped with its best distance, that distance is final.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!4MR5!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a364ee5-0256-41be-9856-f1d9c179c5b4_1024x559.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!4MR5!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a364ee5-0256-41be-9856-f1d9c179c5b4_1024x559.jpeg 424w, https://substackcdn.com/image/fetch/$s_!4MR5!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a364ee5-0256-41be-9856-f1d9c179c5b4_1024x559.jpeg 848w, https://substackcdn.com/image/fetch/$s_!4MR5!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a364ee5-0256-41be-9856-f1d9c179c5b4_1024x559.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!4MR5!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a364ee5-0256-41be-9856-f1d9c179c5b4_1024x559.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!4MR5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a364ee5-0256-41be-9856-f1d9c179c5b4_1024x559.jpeg" width="594" height="324.263671875" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0a364ee5-0256-41be-9856-f1d9c179c5b4_1024x559.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:559,&quot;width&quot;:1024,&quot;resizeWidth&quot;:594,&quot;bytes&quot;:27412,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/jpeg&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://blog.algomaster.io/i/186636009?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a364ee5-0256-41be-9856-f1d9c179c5b4_1024x559.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_!4MR5!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a364ee5-0256-41be-9856-f1d9c179c5b4_1024x559.jpeg 424w, https://substackcdn.com/image/fetch/$s_!4MR5!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a364ee5-0256-41be-9856-f1d9c179c5b4_1024x559.jpeg 848w, https://substackcdn.com/image/fetch/$s_!4MR5!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a364ee5-0256-41be-9856-f1d9c179c5b4_1024x559.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!4MR5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a364ee5-0256-41be-9856-f1d9c179c5b4_1024x559.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><pre><code>dist = [infinity] * numNodes
dist[source] = 0
pq = [(0, source)]  // (distance, node)

while pq is not empty:
    d, node = pq.pop_min()

    if d &gt; dist[node]:
        continue  // found a better path already

    for (neighbor, weight) in node.edges:
        newDist = d + weight
        if newDist &lt; dist[neighbor]:
            dist[neighbor] = newDist
            pq.push((newDist, neighbor))</code></pre><h4>Sample Problem: Network Delay Time</h4><p>You have n network nodes. You&#8217;re given travel times as directed edges (u, v, w) where w is the time. You send a signal from node k. How long until all nodes receive it?</p><p>To solve this, you run Dijkstra from node k. Your answer is the maximum distance among all reachable nodes. If any node is unreachable, you return -1.</p><h4>Practice these LeetCode problems:</h4><ul><li><p><a href="https://leetcode.com/problems/network-delay-time/">Network Delay Time</a> (Medium)</p></li><li><p><a href="https://leetcode.com/problems/path-with-minimum-effort/">Path with Minimum Effort</a> (Medium)</p></li><li><p><a href="https://leetcode.com/problems/cheapest-flights-within-k-stops/">Cheapest Flights Within K Stops</a> (Medium)</p></li><li><p><a href="https://leetcode.com/problems/swim-in-rising-water/">Swim in Rising Water</a> (Hard)</p></li></ul><div><hr></div><h1>4. Topological Sort</h1><blockquote><p><strong>What it is:</strong> Topological sort orders nodes in a <strong>Directed Acyclic Graph (DAG)</strong> so that for every edge <code>u &#8594; v</code>, node <code>u</code> appears <strong>before</strong> node <code>v</code>. In plain terms: it gives you an execution order that respects dependencies. That&#8217;s why it shows up so often in scheduling-style problems.</p></blockquote><h4>When to use it:</h4><p>Topological sort is the default pattern when you see dependency language:</p><ul><li><p>Course scheduling with prerequisites</p></li><li><p>Build systems and dependency resolution</p></li><li><p>Task ordering</p></li><li><p>Any problem that mentions &#8220;prerequisites&#8221; or &#8220;dependencies&#8221;</p></li></ul><h4>How it works (Kahn&#8217;s Algorithm):</h4><p>Kahn&#8217;s algorithm is the BFS-style way to do topological sorting.</p><p><strong>Key idea:</strong> A node&#8217;s in-degree is the number of edges pointing to it. If a node has in-degree 0, it has no dependencies and you can process it.</p><p>You start by adding all nodes with in-degree 0 to a queue. You process them one by one. When you process a node, you decrement the in-degree of its neighbors. If a neighbor&#8217;s in-degree drops to 0, you add it to the queue.</p><p>If you process all nodes, you have a valid topological order. If the queue empties before you&#8217;ve processed all nodes, you&#8217;ve found a cycle.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!1puy!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd166816b-b57e-40e3-ac90-33b31795d92e_1280x926.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!1puy!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd166816b-b57e-40e3-ac90-33b31795d92e_1280x926.jpeg 424w, https://substackcdn.com/image/fetch/$s_!1puy!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd166816b-b57e-40e3-ac90-33b31795d92e_1280x926.jpeg 848w, https://substackcdn.com/image/fetch/$s_!1puy!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd166816b-b57e-40e3-ac90-33b31795d92e_1280x926.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!1puy!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd166816b-b57e-40e3-ac90-33b31795d92e_1280x926.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!1puy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd166816b-b57e-40e3-ac90-33b31795d92e_1280x926.jpeg" width="592" height="428.275" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d166816b-b57e-40e3-ac90-33b31795d92e_1280x926.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:926,&quot;width&quot;:1280,&quot;resizeWidth&quot;:592,&quot;bytes&quot;:66020,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/jpeg&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://blog.algomaster.io/i/186636009?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd166816b-b57e-40e3-ac90-33b31795d92e_1280x926.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_!1puy!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd166816b-b57e-40e3-ac90-33b31795d92e_1280x926.jpeg 424w, https://substackcdn.com/image/fetch/$s_!1puy!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd166816b-b57e-40e3-ac90-33b31795d92e_1280x926.jpeg 848w, https://substackcdn.com/image/fetch/$s_!1puy!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd166816b-b57e-40e3-ac90-33b31795d92e_1280x926.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!1puy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd166816b-b57e-40e3-ac90-33b31795d92e_1280x926.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><pre><code>inDegree = count incoming edges for each node
queue = all nodes with inDegree 0
result = []

while queue is not empty:
    node = queue.pop()
    result.append(node)

    for neighbor in node.outgoing:
        inDegree[neighbor] -= 1
        if inDegree[neighbor] == 0:
            queue.push(neighbor)

if len(result) &lt; numNodes:
    return "cycle detected"</code></pre><h4>Sample Problem: Course Schedule II</h4><p>You have numCourses courses. Some have prerequisites: [0, 1] means you take course 1 before course 0. You need to return any valid order to finish all courses, or an empty array if impossible.</p><p>To solve this, you build a directed graph where edge b&#8594;a means &#8220;take b before a&#8221;. Then run Kahn&#8217;s algorithm. If you can&#8217;t process all courses, you&#8217;ve found a cyclic dependency.</p><h4>Practice these LeetCode problems:</h4><ul><li><p><a href="https://leetcode.com/problems/course-schedule/">Course Schedule</a> (Medium)</p></li><li><p><a href="https://leetcode.com/problems/course-schedule-ii/">Course Schedule II</a> (Medium)</p></li><li><p><a href="https://leetcode.com/problems/alien-dictionary/">Alien Dictionary</a> (Hard)</p></li><li><p><a href="https://leetcode.com/problems/parallel-courses/">Parallel Courses</a> (Medium)</p></li></ul><div><hr></div><h1>5. Union-Find (Disjoint Set Union)</h1><blockquote><p><strong>What it is:</strong> Union-Find is a data structure for tracking a collection of elements split into <strong>disjoint (non-overlapping) sets</strong>. It supports two core operations:</p><ul><li><p><strong>find(x):</strong> which set does <code>x</code> belong to?</p></li><li><p><strong>union(x, y):</strong> merge the sets containing <code>x</code> and <code>y</code></p></li></ul><p>Once you have these, you can answer connectivity questions like &#8220;are these two nodes connected?&#8221; efficiently.</p></blockquote><h4>When to use it:</h4><p>Union-Find shines when you&#8217;re adding connections over time and need fast connectivity checks:</p><ul><li><p>Dynamic connectivity queries</p></li><li><p>Detecting cycles in undirected graphs</p></li><li><p>Kruskal&#8217;s MST algorithm</p></li><li><p>Grouping elements as edges are added</p></li></ul><h4>How it works:</h4><p>Each set has a leader (representative). Two elements are in the same set if they have the same leader. You store a parent array where parent[i] points to i&#8217;s parent. The root is the leader (where parent[i] = i).</p><p>To make operations extremely fast in practice, Union-Find uses two standard optimizations:</p><ol><li><p><strong>Path compression</strong>: When you find the leader, you make each node on the path point directly to the leader.</p></li><li><p><strong>Union by rank/size</strong>: When merging two sets, attach the smaller tree under the larger one to keep trees shallow.</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_!3Osr!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb82249de-e250-4e23-8bb8-c0f872b44648_1024x559.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!3Osr!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb82249de-e250-4e23-8bb8-c0f872b44648_1024x559.jpeg 424w, https://substackcdn.com/image/fetch/$s_!3Osr!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb82249de-e250-4e23-8bb8-c0f872b44648_1024x559.jpeg 848w, https://substackcdn.com/image/fetch/$s_!3Osr!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb82249de-e250-4e23-8bb8-c0f872b44648_1024x559.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!3Osr!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb82249de-e250-4e23-8bb8-c0f872b44648_1024x559.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!3Osr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb82249de-e250-4e23-8bb8-c0f872b44648_1024x559.jpeg" width="600" height="327.5390625" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b82249de-e250-4e23-8bb8-c0f872b44648_1024x559.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:559,&quot;width&quot;:1024,&quot;resizeWidth&quot;:600,&quot;bytes&quot;:25987,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/jpeg&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://blog.algomaster.io/i/186636009?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb82249de-e250-4e23-8bb8-c0f872b44648_1024x559.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_!3Osr!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb82249de-e250-4e23-8bb8-c0f872b44648_1024x559.jpeg 424w, https://substackcdn.com/image/fetch/$s_!3Osr!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb82249de-e250-4e23-8bb8-c0f872b44648_1024x559.jpeg 848w, https://substackcdn.com/image/fetch/$s_!3Osr!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb82249de-e250-4e23-8bb8-c0f872b44648_1024x559.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!3Osr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb82249de-e250-4e23-8bb8-c0f872b44648_1024x559.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><pre><code>parent = [0, 1, 2, ..., n-1]  // each node is its own leader
rank = [0] * n

function find(x):
    if parent[x] != x:
        parent[x] = find(parent[x])  // path compression
    return parent[x]

function union(x, y):
    px, py = find(x), find(y)
    if px == py:
        return false  // already connected

    if rank[px] &lt; rank[py]:
        parent[px] = py
    else if rank[px] &gt; rank[py]:
        parent[py] = px
    else:
        parent[py] = px
        rank[px] += 1

    return true</code></pre><h4>Sample Problem: Redundant Connection</h4><p>You have a graph that started as a tree (connected, no cycles), then one edge was added. You need to find the edge that can be removed to restore the tree.</p><p>To solve this using union find, process edges one by one. For each edge (u, v), you check if u and v are already connected using find(). If yes, this edge creates a cycle. If no, you union them. The first edge that connects already-connected nodes is your answer.</p><h4>Practice these LeetCode problems:</h4><ul><li><p><a href="https://leetcode.com/problems/redundant-connection/">Redundant Connection</a> (Medium)</p></li><li><p><a href="https://leetcode.com/problems/number-of-provinces/">Number of Provinces</a> (Medium)</p></li><li><p><a href="https://leetcode.com/problems/accounts-merge/">Accounts Merge</a> (Medium)</p></li><li><p><a href="https://leetcode.com/problems/satisfiability-of-equality-equations/">Satisfiability of Equality Equations</a> (Medium)</p></li></ul><div><hr></div><h1>6. Minimum Spanning Tree (MST)</h1><blockquote><p><strong>What it is:</strong> A spanning tree connects all nodes in a graph using exactly n-1 edges with no cycles. The minimum spanning tree is the one with the smallest total edge weight.</p></blockquote><h4>When to use it:</h4><p>MST comes up whenever you need to connect a set of nodes with minimum total cost:</p><ul><li><p>Connecting all nodes with minimum cost</p></li><li><p>Network design (cables, roads, pipelines)</p></li><li><p>Clustering algorithms</p></li><li><p>Approximation algorithms for NP-hard problems</p></li></ul><h4>How it works (Kruskal&#8217;s Algorithm):</h4><p>Kruskal&#8217;s is the most common MST approach in interviews because it&#8217;s simple and pairs naturally with Union-Find.</p><p>You sort all edges by weight. You process them in order. For each edge, you use Union-Find to check if it connects two different components. If yes, you add it to the MST. If no, you skip it to avoid a cycle.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Q5NN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa8fa90df-b18e-432e-a8b8-a1738d206e1e_1540x682.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Q5NN!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa8fa90df-b18e-432e-a8b8-a1738d206e1e_1540x682.png 424w, https://substackcdn.com/image/fetch/$s_!Q5NN!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa8fa90df-b18e-432e-a8b8-a1738d206e1e_1540x682.png 848w, https://substackcdn.com/image/fetch/$s_!Q5NN!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa8fa90df-b18e-432e-a8b8-a1738d206e1e_1540x682.png 1272w, https://substackcdn.com/image/fetch/$s_!Q5NN!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa8fa90df-b18e-432e-a8b8-a1738d206e1e_1540x682.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Q5NN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa8fa90df-b18e-432e-a8b8-a1738d206e1e_1540x682.png" width="673" height="298.1353021978022" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a8fa90df-b18e-432e-a8b8-a1738d206e1e_1540x682.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:645,&quot;width&quot;:1456,&quot;resizeWidth&quot;:673,&quot;bytes&quot;:34810,&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://blog.algomaster.io/i/186636009?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa8fa90df-b18e-432e-a8b8-a1738d206e1e_1540x682.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_!Q5NN!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa8fa90df-b18e-432e-a8b8-a1738d206e1e_1540x682.png 424w, https://substackcdn.com/image/fetch/$s_!Q5NN!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa8fa90df-b18e-432e-a8b8-a1738d206e1e_1540x682.png 848w, https://substackcdn.com/image/fetch/$s_!Q5NN!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa8fa90df-b18e-432e-a8b8-a1738d206e1e_1540x682.png 1272w, https://substackcdn.com/image/fetch/$s_!Q5NN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa8fa90df-b18e-432e-a8b8-a1738d206e1e_1540x682.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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><pre><code>edges.sort(by weight)
mst = []
uf = UnionFind(n)

for edge in edges:
    u, v, weight = edge
    if uf.find(u) != uf.find(v):
        uf.union(u, v)
        mst.append(edge)

    if len(mst) == n - 1:
        break

return mst</code></pre><h4>Sample Problem: Min Cost to Connect All Points</h4><p>You&#8217;re given points on a 2D plane. The cost to connect two points is their Manhattan distance. You return the minimum cost to connect all points.</p><p>To solve this, you treat each pair of points as a potential edge. Generate all edges, sort by weight, and run Kruskal&#8217;s. The MST gives you the minimum total cost.</p><h4>Practice these LeetCode problems:</h4><ul><li><p><a href="https://leetcode.com/problems/min-cost-to-connect-all-points/">Min Cost to Connect All Points</a> (Medium)</p></li><li><p><a href="https://leetcode.com/problems/connecting-cities-with-minimum-cost/">Connecting Cities With Minimum Cost</a> (Medium)</p></li><li><p><a href="https://leetcode.com/problems/find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree/">Find Critical and Pseudo-Critical Edges in MST</a> (Hard)</p></li></ul><div><hr></div><h1>7. Bipartite Graph Check</h1><blockquote><p><strong>What it is:</strong> A graph is <strong>bipartite</strong> if you can split its nodes into two groups such that <strong>every edge connects nodes from different groups</strong>. No edge is allowed within the same group.</p><p>A simple way to remember it: Can you <strong>2-color</strong> the graph so that no two adjacent nodes share the same color?</p></blockquote><h4>When to use it:</h4><p>Bipartite checks appear whenever the problem is about dividing things into two compatible sets:</p><ul><li><p>Team or group assignments</p></li><li><p>Matching problems</p></li><li><p>Checking for odd-length cycles (a graph is bipartite if and only if it has no odd-length cycles)</p></li><li><p>Scheduling with conflicts</p></li></ul><h4>How it works:</h4><p>You can use <strong>BFS or DFS</strong> to try 2-coloring the graph.</p><p>Pick a start node and assign it color 0. Assign all its neighbors color 1. Assign their neighbors color 0. Continue alternating.</p><p>If you ever find an edge where both endpoints have the <strong>same color</strong>, the graph is <strong>not</strong> bipartite.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!h9CR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb729cce8-027e-45b1-881c-f1e3e572101b_1230x478.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!h9CR!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb729cce8-027e-45b1-881c-f1e3e572101b_1230x478.png 424w, https://substackcdn.com/image/fetch/$s_!h9CR!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb729cce8-027e-45b1-881c-f1e3e572101b_1230x478.png 848w, https://substackcdn.com/image/fetch/$s_!h9CR!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb729cce8-027e-45b1-881c-f1e3e572101b_1230x478.png 1272w, https://substackcdn.com/image/fetch/$s_!h9CR!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb729cce8-027e-45b1-881c-f1e3e572101b_1230x478.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!h9CR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb729cce8-027e-45b1-881c-f1e3e572101b_1230x478.png" width="644" height="250.269918699187" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b729cce8-027e-45b1-881c-f1e3e572101b_1230x478.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:478,&quot;width&quot;:1230,&quot;resizeWidth&quot;:644,&quot;bytes&quot;:21041,&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://blog.algomaster.io/i/186636009?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb729cce8-027e-45b1-881c-f1e3e572101b_1230x478.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_!h9CR!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb729cce8-027e-45b1-881c-f1e3e572101b_1230x478.png 424w, https://substackcdn.com/image/fetch/$s_!h9CR!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb729cce8-027e-45b1-881c-f1e3e572101b_1230x478.png 848w, https://substackcdn.com/image/fetch/$s_!h9CR!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb729cce8-027e-45b1-881c-f1e3e572101b_1230x478.png 1272w, https://substackcdn.com/image/fetch/$s_!h9CR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb729cce8-027e-45b1-881c-f1e3e572101b_1230x478.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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><pre><code>color = [-1] * n  // uncolored

function isBipartite(start):
    queue = [start]
    color[start] = 0

    while queue is not empty:
        node = queue.pop()
        for neighbor in node.neighbors:
            if color[neighbor] == -1:
                color[neighbor] = 1 - color[node]
                queue.push(neighbor)
            else if color[neighbor] == color[node]:
                return false

    return true</code></pre><h4>Sample Problem: Is Graph Bipartite?</h4><p>You&#8217;re given an undirected graph. You return true if it&#8217;s bipartite.</p><p>Because the graph may be disconnected, run BFS/DFS from <strong>every uncolored node</strong>:</p><ul><li><p>Start a new traversal, try to 2-color that component</p></li><li><p>If any component fails, return <code>false</code></p></li><li><p>If all components succeed, the graph is bipartite</p></li></ul><h4>Practice these LeetCode problems:</h4><ul><li><p><a href="https://leetcode.com/problems/is-graph-bipartite/">Is Graph Bipartite?</a> (Medium)</p></li><li><p><a href="https://leetcode.com/problems/possible-bipartition/">Possible Bipartition</a> (Medium)</p></li></ul><div><hr></div><h1>What to Do Next</h1><p>You now have 7 algorithms that cover most graph problems in coding interviews. Here&#8217;s how to retain them:</p><ol><li><p><strong>Practice in order.</strong> Start with BFS and DFS. They&#8217;re the foundation the others build on.</p></li><li><p><strong>Match patterns to algorithms.</strong> &#8220;Shortest path&#8221; without weights &#8594; BFS. &#8220;Prerequisites&#8221; or &#8220;dependencies&#8221; &#8594; topological sort. &#8220;Minimum cost to connect&#8221; &#8594; MST.</p></li><li><p><strong>Implement from scratch.</strong> Don&#8217;t just read the code. Write it yourself. Debug it. That&#8217;s how you learn.</p></li><li><p><strong>Practice with time limits.</strong> In interviews, you have 20-30 minutes per problem. Get comfortable working under that constraint.</p></li></ol><p>For a structured approach to learn, feel free to take a look at our roadmaps. It covers these algorithms plus topics like Strongly Connected Components, Lowest Common Ancestor, and Network Flow.</p>]]></content:encoded></item><item><title><![CDATA[Polling vs. Long Polling vs. SSE vs. WebSockets vs. Webhooks]]></title><description><![CDATA[How do you keep clients updated with server changes?]]></description><link>https://blog.algomaster.io/p/polling-vs-long-polling-vs-sse-vs-websockets-webhooks</link><guid isPermaLink="false">https://blog.algomaster.io/p/polling-vs-long-polling-vs-sse-vs-websockets-webhooks</guid><dc:creator><![CDATA[Ashish Pratap Singh]]></dc:creator><pubDate>Tue, 03 Feb 2026 04:02:53 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!DkxM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf447e18-ccb7-4f9c-8e09-2a4d51989ac8_2068x1366.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Whether you are chatting with a friend or playing an online game, updates show up in real time without hitting <strong>&#8220;refresh&#8221;</strong>.</p><p>Behind these seamless experiences lies a key engineering decision: <strong>how does the server notify the client (or another system) when new data is available?</strong></p><p>The traditional HTTP was built around a simple request-response flow: <strong>the client asks, the server answers</strong>. But in real-time systems, the server often needs to push updates proactively, sometimes continuously.</p><p>That&#8217;s where communication models like <strong>Long Polling, Server-Sent Events (SSE), WebSockets, and Webhooks</strong> come in.</p><p>In this article, we&#8217;ll break down how each one works, it&#8217;s pros and cons, where it fits best, and how to choose the right approach for a <strong>production system</strong> or a <strong>system design interview</strong>.</p><p>Let's start with the most straightforward approach.</p><div><hr></div><h1>1. Polling</h1><p><strong>Polling</strong> is the simplest approach to getting updates from a server. The client sends requests to the server at regular intervals, checking if anything has changed.</p><p>Think of it like refreshing your email inbox every few minutes to check for new messages.</p><h3>How It Works</h3><ol><li><p>Client sends an HTTP request to the server</p></li><li><p>Server responds immediately with current data (or empty response)</p></li><li><p>Client waits for a fixed interval (e.g., 5 seconds)</p></li><li><p>Client sends another request</p></li><li><p>Repeat indefinitely</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_!WjQ1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6cd9ef44-0e1d-45f6-ae64-83466f648175_1268x1536.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!WjQ1!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6cd9ef44-0e1d-45f6-ae64-83466f648175_1268x1536.png 424w, https://substackcdn.com/image/fetch/$s_!WjQ1!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6cd9ef44-0e1d-45f6-ae64-83466f648175_1268x1536.png 848w, https://substackcdn.com/image/fetch/$s_!WjQ1!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6cd9ef44-0e1d-45f6-ae64-83466f648175_1268x1536.png 1272w, https://substackcdn.com/image/fetch/$s_!WjQ1!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6cd9ef44-0e1d-45f6-ae64-83466f648175_1268x1536.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!WjQ1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6cd9ef44-0e1d-45f6-ae64-83466f648175_1268x1536.png" width="554" height="671.0914826498423" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6cd9ef44-0e1d-45f6-ae64-83466f648175_1268x1536.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1536,&quot;width&quot;:1268,&quot;resizeWidth&quot;:554,&quot;bytes&quot;:135207,&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://blog.algomaster.io/i/173211909?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6cd9ef44-0e1d-45f6-ae64-83466f648175_1268x1536.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_!WjQ1!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6cd9ef44-0e1d-45f6-ae64-83466f648175_1268x1536.png 424w, https://substackcdn.com/image/fetch/$s_!WjQ1!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6cd9ef44-0e1d-45f6-ae64-83466f648175_1268x1536.png 848w, https://substackcdn.com/image/fetch/$s_!WjQ1!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6cd9ef44-0e1d-45f6-ae64-83466f648175_1268x1536.png 1272w, https://substackcdn.com/image/fetch/$s_!WjQ1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6cd9ef44-0e1d-45f6-ae64-83466f648175_1268x1536.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 something wasteful here? The client keeps asking even when nothing has changed. Three out of four requests in this diagram returned empty responses. </p><p>In real applications, this ratio is often much worse. You might make 100 requests before getting a single meaningful update.</p><h3>Example: Weather Dashboard</h3><p>Imagine you&#8217;re building a weather dashboard. Weather data doesn&#8217;t change that frequently, maybe every 15-30 minutes at most. </p><p>Polling makes sense here:</p><pre><code>setInterval(async () =&gt; {
    const response = await fetch('/api/weather?city=london');
    const weather = await response.json();
    updateDashboard(weather);
}, 60000); // Poll every minute</code></pre><p>Every minute, your client asks for the current weather. The server responds with temperature, humidity, conditions, and so on.</p><h3>Pros</h3><ul><li><p><strong>Simple to implement:</strong> Just a regular HTTP request in a loop. No special protocols or libraries needed.</p></li><li><p><strong>Works everywhere:</strong> Any HTTP client can do polling. No firewall or proxy issues.</p></li><li><p><strong>Stateless:</strong> Each request is independent. The server doesn&#8217;t need to maintain any connection state.</p></li><li><p><strong>Easy to debug:</strong> Standard HTTP requests that show up in network logs and dev tools.</p></li></ul><h3>Cons</h3><ul><li><p><strong>Wasted requests:</strong> Most requests return empty responses when nothing has changed. This wastes bandwidth and server resources.</p></li><li><p><strong>High latency:</strong> Updates are delayed by the polling interval. If you poll every 10 seconds, updates can take up to 10 seconds to reach the client.</p></li><li><p><strong>Doesn&#8217;t scale:</strong> 10,000 clients polling every second means 10,000 requests per second, even when nothing is happening.</p></li><li><p><strong>Trade-off between latency and efficiency:</strong> Shorter intervals mean faster updates but more wasted requests. Longer intervals mean fewer requests but slower updates.</p></li></ul><h3>When to Use</h3><ul><li><p><strong>Low-frequency updates:</strong> Weather data, daily reports, or anything that changes infrequently</p></li><li><p><strong>Simple systems:</strong> MVPs, internal tools, or situations where simplicity matters more than efficiency</p></li><li><p><strong>Legacy compatibility:</strong> When you need to support older clients or environments that can&#8217;t use modern techniques</p></li><li><p><strong>Acceptable latency:</strong> When delays of several seconds (or minutes) are acceptable</p></li></ul><p>Polling is a reasonable starting point, but you&#8217;ll quickly feel its limitations as your application grows. If you need faster updates without drowning your server in requests, that&#8217;s where long polling comes in.</p><div><hr></div><h1>2. Long Polling</h1><p><strong>Long polling</strong> improves on regular polling by having the server hold the request open until new data is available (or a timeout occurs). Instead of the client repeatedly asking &#8220;anything new?&#8221;, the server waits and responds only when there&#8217;s something to report.</p><p>This was the technique that powered early real-time applications like Facebook Messenger before WebSockets became widely supported.</p><h3>How It Works</h3><ol><li><p>Client sends an HTTP request to the server</p></li><li><p>Server holds the connection open (doesn&#8217;t respond immediately)</p></li><li><p>When new data arrives, server sends the response</p></li><li><p>Client immediately sends another request</p></li><li><p>If no data arrives within the timeout period, server sends an empty response and client reconnects</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_!1YRT!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9949bc36-7f67-4fea-b348-2fbf6557f857_1356x1674.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!1YRT!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9949bc36-7f67-4fea-b348-2fbf6557f857_1356x1674.png 424w, https://substackcdn.com/image/fetch/$s_!1YRT!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9949bc36-7f67-4fea-b348-2fbf6557f857_1356x1674.png 848w, https://substackcdn.com/image/fetch/$s_!1YRT!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9949bc36-7f67-4fea-b348-2fbf6557f857_1356x1674.png 1272w, https://substackcdn.com/image/fetch/$s_!1YRT!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9949bc36-7f67-4fea-b348-2fbf6557f857_1356x1674.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!1YRT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9949bc36-7f67-4fea-b348-2fbf6557f857_1356x1674.png" width="578" height="713.5486725663717" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9949bc36-7f67-4fea-b348-2fbf6557f857_1356x1674.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1674,&quot;width&quot;:1356,&quot;resizeWidth&quot;:578,&quot;bytes&quot;:186235,&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://blog.algomaster.io/i/173211909?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9949bc36-7f67-4fea-b348-2fbf6557f857_1356x1674.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_!1YRT!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9949bc36-7f67-4fea-b348-2fbf6557f857_1356x1674.png 424w, https://substackcdn.com/image/fetch/$s_!1YRT!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9949bc36-7f67-4fea-b348-2fbf6557f857_1356x1674.png 848w, https://substackcdn.com/image/fetch/$s_!1YRT!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9949bc36-7f67-4fea-b348-2fbf6557f857_1356x1674.png 1272w, https://substackcdn.com/image/fetch/$s_!1YRT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9949bc36-7f67-4fea-b348-2fbf6557f857_1356x1674.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 insight is that the server only responds when it has something meaningful to say. This eliminates the wasted &#8220;nothing new&#8221; responses of regular polling.</p><h3>Example: Chat Application</h3><p>Consider a chat app built with long polling. When you open a conversation, your browser sends a request like:</p><pre><code>GET /api/messages?conversation=123&amp;after=msg_999</code></pre><p>The server checks if there are any messages newer than <code>msg_999</code>. If not, instead of returning an empty response, it holds the connection and waits. </p><p>When someone sends a new message to that conversation, the server immediately responds with the new message. Your client receives it, renders it in the chat window, and immediately opens a new connection to wait for the next message.</p><p>There&#8217;s an important detail here: the <strong>timeout</strong>. HTTP connections can&#8217;t stay open forever. Proxies, load balancers, and browsers all have limits. So the server needs to respond eventually, even if nothing happened.</p><p>A typical timeout is 30 seconds. If 30 seconds pass with no new data, the server sends an empty response, the client immediately reconnects, and the wait continues.</p><h3>Pros</h3><ul><li><p><strong>Near real-time:</strong> Updates arrive almost instantly when they happen, without waiting for a polling interval.</p></li><li><p><strong>Fewer wasted requests:</strong> Responses almost always contain useful data, not empty &#8220;nothing new&#8221; responses.</p></li><li><p><strong>Works through proxies and firewalls:</strong> Uses standard HTTP, so it works in restrictive network environments where WebSockets might be blocked.</p></li><li><p><strong>Simpler than WebSockets:</strong> No protocol upgrade, no special handling for connection state.</p></li></ul><h3>Cons</h3><ul><li><p><strong>Resource intensive:</strong> Each waiting client holds a connection open on the server. With 10,000 clients, you need 10,000 open connections.</p></li><li><p><strong>Timeout handling complexity:</strong> You need to handle timeouts, reconnection logic, and edge cases like the client receiving data just as the timeout expires.</p></li><li><p><strong>Head-of-line blocking:</strong> If multiple events happen quickly, they may get batched together or delivered out of order.</p></li><li><p><strong>HTTP overhead:</strong> Every response requires a new request, and each request carries HTTP headers. This overhead adds up.</p></li></ul><h3>When to Use</h3><ul><li><p><strong>Chat applications (historically):</strong> Before WebSocket support was universal, long polling powered most chat systems</p></li><li><p><strong>Fallback mechanism:</strong> When WebSockets aren&#8217;t available due to proxy or firewall restrictions</p></li><li><p><strong>Server-initiated updates:</strong> When clients mostly receive data rather than send it</p></li><li><p><strong>Moderate scale:</strong> Works well for hundreds or thousands of concurrent connections, but gets expensive at massive scale</p></li></ul><p>Long polling feels like &#8220;almost real-time,&#8221; but it&#8217;s still request-response at heart. The client still initiates every exchange. What if the server could just push data to clients whenever it wants? That&#8217;s exactly what Server-Sent Events enable.</p><div><hr></div><h1>3. Server-Sent Events (SSE)</h1>
      <p>
          <a href="https://blog.algomaster.io/p/polling-vs-long-polling-vs-sse-vs-websockets-webhooks">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[How to Scale a System from 0 to 10 million+ Users]]></title><description><![CDATA[Scaling is a complex topic, but after working at big tech on services handling millions of requests and scaling my own startup (AlgoMaster.io) from scratch, I&#8217;ve realized that most systems evolve through a surprisingly similar set of stages as they grow.]]></description><link>https://blog.algomaster.io/p/scaling-a-system-from-0-to-10-million-users</link><guid isPermaLink="false">https://blog.algomaster.io/p/scaling-a-system-from-0-to-10-million-users</guid><dc:creator><![CDATA[Ashish Pratap Singh]]></dc:creator><pubDate>Thu, 29 Jan 2026 04:18:00 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!2Tb9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F329f47dd-6c66-4c66-b973-487ef28e77de_725x511.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Scaling is a complex topic, but after working at <strong>big tech</strong> on services handling millions of requests and scaling my own <strong>startup (<a href="https://algomaster.io/">AlgoMaster.io</a>)</strong> from scratch, I&#8217;ve realized that most systems evolve through a surprisingly similar set of stages as they grow.</p><p>The key insight is that <strong>you should not over-engineer from the start</strong>. Start simple, identify bottlenecks, and scale incrementally.</p><p>In this article, I&#8217;ll walk you through <strong>7 stages of scaling a system</strong> from zero to 10 million users and beyond. Each stage addresses the specific bottlenecks that show up at different growth points. You&#8217;ll learn what to add, when to add it, why it helps, and the trade-offs involved.</p><p>Whether you&#8217;re building an app or website, preparing for system design interviews, or just curious about how large-scale systems work, understanding this progression will sharpen they way you think about architecture.</p><blockquote><p><strong>Disclaimer: </strong>The user ranges and numbers mentioned in this article are approximate and intended to illustrate a scaling journey. Actual thresholds will vary depending on your product, workload characteristics, and traffic patterns.</p></blockquote><div><hr></div><h1>Stage 1: Single Server (0-100 Users)</h1><p>When you&#8217;re just starting out, your first priority is simple: <strong>ship something and validate your idea</strong>. Optimizing too early at this stage wastes time and money on problems you may never face.</p><p>The simplest architecture puts everything on a <strong>single server</strong>: your web application, database, and any background jobs all running on the same machine.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Xhwe!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F996b8082-9df2-4e4f-82b2-b1c7d87d7894_1276x760.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Xhwe!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F996b8082-9df2-4e4f-82b2-b1c7d87d7894_1276x760.png 424w, https://substackcdn.com/image/fetch/$s_!Xhwe!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F996b8082-9df2-4e4f-82b2-b1c7d87d7894_1276x760.png 848w, https://substackcdn.com/image/fetch/$s_!Xhwe!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F996b8082-9df2-4e4f-82b2-b1c7d87d7894_1276x760.png 1272w, https://substackcdn.com/image/fetch/$s_!Xhwe!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F996b8082-9df2-4e4f-82b2-b1c7d87d7894_1276x760.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Xhwe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F996b8082-9df2-4e4f-82b2-b1c7d87d7894_1276x760.png" width="656" height="390.72100313479626" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/996b8082-9df2-4e4f-82b2-b1c7d87d7894_1276x760.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:760,&quot;width&quot;:1276,&quot;resizeWidth&quot;:656,&quot;bytes&quot;:64447,&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://blog.algomaster.io/i/173209644?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F996b8082-9df2-4e4f-82b2-b1c7d87d7894_1276x760.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_!Xhwe!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F996b8082-9df2-4e4f-82b2-b1c7d87d7894_1276x760.png 424w, https://substackcdn.com/image/fetch/$s_!Xhwe!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F996b8082-9df2-4e4f-82b2-b1c7d87d7894_1276x760.png 848w, https://substackcdn.com/image/fetch/$s_!Xhwe!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F996b8082-9df2-4e4f-82b2-b1c7d87d7894_1276x760.png 1272w, https://substackcdn.com/image/fetch/$s_!Xhwe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F996b8082-9df2-4e4f-82b2-b1c7d87d7894_1276x760.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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>This is how Instagram started. When Kevin Systrom and Mike Krieger launched the first version in 2010, 25,000 people signed up on day one.</p><p>They didn&#8217;t over-engineer upfront. With a small team and a simple setup, they scaled in response to real demand, adding capacity as usage grew, rather than building for hypothetical future traffic.</p></blockquote><h3>What This Architecture Looks Like</h3><p>In practice, a single-server setup means:</p><ul><li><p>A web framework (Django, Rails, Express, Spring Boot) handling HTTP requests</p></li><li><p>A database (PostgreSQL, MySQL) storing your data</p></li><li><p>Background job processing (Sidekiq, Celery) for async tasks</p></li><li><p>Maybe a reverse proxy (Nginx) in front for SSL termination</p></li></ul><p>All of these run on one virtual machine. Your cloud provider bill might be $20-50/month for a basic VPS (DigitalOcean Droplet, AWS Lightsail, Linode).</p><h3>Why This Works for Early Stage</h3><p>At this stage, simplicity is your biggest advantage:</p><ul><li><p><strong>Fast deployment</strong>: One server means one place to deploy, monitor, and debug.</p></li><li><p><strong>Low cost</strong>: A single $20-50/month Virtual Private Server (VPS) can comfortably handle your first 100 users.</p></li><li><p><strong>Faster iteration</strong>: No distributed systems complexity to slow down development.</p></li><li><p><strong>Easier debugging</strong>: All logs are in one place, and there are no network issues between components.</p></li><li><p><strong>Full-stack visibility</strong>: You can trace every request end to end because there&#8217;s only one execution path.</p></li></ul><h3>The Trade-offs You&#8217;re Making</h3><p>This simplicity comes with trade-offs you accept knowingly:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!_20S!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6910b4a2-9e2d-4e75-85aa-0c9c84863481_711x221.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!_20S!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6910b4a2-9e2d-4e75-85aa-0c9c84863481_711x221.png 424w, https://substackcdn.com/image/fetch/$s_!_20S!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6910b4a2-9e2d-4e75-85aa-0c9c84863481_711x221.png 848w, https://substackcdn.com/image/fetch/$s_!_20S!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6910b4a2-9e2d-4e75-85aa-0c9c84863481_711x221.png 1272w, https://substackcdn.com/image/fetch/$s_!_20S!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6910b4a2-9e2d-4e75-85aa-0c9c84863481_711x221.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!_20S!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6910b4a2-9e2d-4e75-85aa-0c9c84863481_711x221.png" width="711" height="221" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6910b4a2-9e2d-4e75-85aa-0c9c84863481_711x221.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:221,&quot;width&quot;:711,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:39074,&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://blog.algomaster.io/i/173209644?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6910b4a2-9e2d-4e75-85aa-0c9c84863481_711x221.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_!_20S!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6910b4a2-9e2d-4e75-85aa-0c9c84863481_711x221.png 424w, https://substackcdn.com/image/fetch/$s_!_20S!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6910b4a2-9e2d-4e75-85aa-0c9c84863481_711x221.png 848w, https://substackcdn.com/image/fetch/$s_!_20S!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6910b4a2-9e2d-4e75-85aa-0c9c84863481_711x221.png 1272w, https://substackcdn.com/image/fetch/$s_!_20S!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6910b4a2-9e2d-4e75-85aa-0c9c84863481_711x221.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><h3>When to Move On</h3><p>You&#8217;ll know it&#8217;s time to evolve when you notice these signs:</p><ul><li><p><strong>Database queries slow down during peak traffic</strong>: The app and database compete for the same CPU and memory. One heavy query can drag down API latency for everyone.</p></li><li><p><strong>Server CPU or memory consistently exceeds 70-80%</strong>: You&#8217;re approaching the limits of what a single machine can reliably handle.</p></li><li><p><strong>Deployments require restarts and cause downtime</strong>: Even short interruptions become noticeable, and users start to complain.</p></li><li><p><strong>A background job crash takes down the web server</strong>: Without isolation, non-user-facing work can impact the user experience.</p></li><li><p><strong>You can&#8217;t afford even brief downtime</strong>: Your product has become critical enough that even maintenance windows stop being acceptable.</p></li></ul><p>At some point, the server starts to struggle under the weight of doing everything. That&#8217;s when it&#8217;s time for your first architectural split.</p><div><hr></div><h1>Stage 2: Separate Database (100-1K Users)</h1><p>As traffic grows, your single server starts struggling. The web application and database compete for the same CPU, memory, and disk I/O. A single heavy query can spike latency and slow down every API response.</p><p>The first scaling step is simple: <strong>separate the database from the application server</strong>.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!3Atu!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefc4c8c3-9f3a-4233-8564-26bb9ce8c3a0_670x192.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!3Atu!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefc4c8c3-9f3a-4233-8564-26bb9ce8c3a0_670x192.png 424w, https://substackcdn.com/image/fetch/$s_!3Atu!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefc4c8c3-9f3a-4233-8564-26bb9ce8c3a0_670x192.png 848w, https://substackcdn.com/image/fetch/$s_!3Atu!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefc4c8c3-9f3a-4233-8564-26bb9ce8c3a0_670x192.png 1272w, https://substackcdn.com/image/fetch/$s_!3Atu!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefc4c8c3-9f3a-4233-8564-26bb9ce8c3a0_670x192.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!3Atu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefc4c8c3-9f3a-4233-8564-26bb9ce8c3a0_670x192.png" width="670" height="192" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/efc4c8c3-9f3a-4233-8564-26bb9ce8c3a0_670x192.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:192,&quot;width&quot;:670,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:21631,&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://blog.algomaster.io/i/173209644?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefc4c8c3-9f3a-4233-8564-26bb9ce8c3a0_670x192.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_!3Atu!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefc4c8c3-9f3a-4233-8564-26bb9ce8c3a0_670x192.png 424w, https://substackcdn.com/image/fetch/$s_!3Atu!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefc4c8c3-9f3a-4233-8564-26bb9ce8c3a0_670x192.png 848w, https://substackcdn.com/image/fetch/$s_!3Atu!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefc4c8c3-9f3a-4233-8564-26bb9ce8c3a0_670x192.png 1272w, https://substackcdn.com/image/fetch/$s_!3Atu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefc4c8c3-9f3a-4233-8564-26bb9ce8c3a0_670x192.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>This two-tier architecture gives you several immediate benefits:</p><ul><li><p><strong>Resource Isolation: </strong>Application and database no longer compete for CPU/memory. Each can use 100% of their allocated resources.</p></li><li><p><strong>Independent Scaling: </strong>Upgrade the database (more RAM, faster storage) without touching the app server.</p></li><li><p><strong>Better Security: </strong>Database server can sit in a private network, not exposed to the internet.</p></li><li><p><strong>Specialized Optimization: </strong>Tune each server for its specific workload. High CPU for app server, high I/O for database.</p></li><li><p><strong>Backup Simplicity: </strong>Database backups don&#8217;t affect application performance since they run on a different machine.</p></li></ul><h3>Managed Database Services</h3><p>At this stage, most teams use a managed database like <strong>Amazon RDS</strong>, <strong>Google Cloud SQL</strong>, <strong>Azure Database</strong>, or <strong>Supabase</strong> (I use Supabase at <strong><a href="https://algomaster.io/">algomaster.io</a></strong>).</p><p>Managed services typically handle:</p><ul><li><p>Automated backups (daily snapshots, point-in-time recovery)</p></li><li><p>Security patches and updates</p></li><li><p>Basic monitoring and alerts</p></li><li><p>Optional read replicas (we&#8217;ll cover these later)</p></li><li><p>Failover to standby instances</p></li></ul><p>The cost difference between self-hosting and managed is usually small once you factor in engineering time. A managed PostgreSQL instance might cost <strong>$50&#8211;$100/month more</strong> than a raw VM, but it can save hours of maintenance every week. Those hours are better spent shipping features.</p><p>The main reasons to self-manage a database are:</p><ul><li><p>Cost optimization at very large scale</p></li><li><p>Specific configurations that managed services don&#8217;t support</p></li><li><p>Compliance requirements that prohibit managed services</p></li><li><p>You&#8217;re building a database product</p></li></ul><p>For most teams, managed services are the right choice until your database bill grows into the <strong>thousands of dollars per month</strong>.</p><h3>Connection Pooling</h3><p>One often-overlooked improvement at this stage is connection pooling. Each database connection consumes resources:</p><ul><li><p>Memory for the connection state (typically 5-10MB per connection in PostgreSQL)</p></li><li><p>File descriptors on both app and database servers</p></li><li><p>CPU overhead for connection management</p></li></ul><p>Opening a new connection is expensive too. Between the TCP handshake, SSL negotiation, and database authentication, you can add <strong>50&#8211;100 ms</strong> of overhead per request.</p><p>A connection pooler like <strong>PgBouncer</strong> (for PostgreSQL) keeps a small set of database connections open and reuses them across requests.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!r_Je!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F889d79be-870e-4147-8bf5-da46855a4641_609x317.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!r_Je!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F889d79be-870e-4147-8bf5-da46855a4641_609x317.png 424w, https://substackcdn.com/image/fetch/$s_!r_Je!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F889d79be-870e-4147-8bf5-da46855a4641_609x317.png 848w, https://substackcdn.com/image/fetch/$s_!r_Je!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F889d79be-870e-4147-8bf5-da46855a4641_609x317.png 1272w, https://substackcdn.com/image/fetch/$s_!r_Je!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F889d79be-870e-4147-8bf5-da46855a4641_609x317.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!r_Je!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F889d79be-870e-4147-8bf5-da46855a4641_609x317.png" width="609" height="317" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/889d79be-870e-4147-8bf5-da46855a4641_609x317.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:317,&quot;width&quot;:609,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:30249,&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://blog.algomaster.io/i/173209644?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F889d79be-870e-4147-8bf5-da46855a4641_609x317.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_!r_Je!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F889d79be-870e-4147-8bf5-da46855a4641_609x317.png 424w, https://substackcdn.com/image/fetch/$s_!r_Je!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F889d79be-870e-4147-8bf5-da46855a4641_609x317.png 848w, https://substackcdn.com/image/fetch/$s_!r_Je!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F889d79be-870e-4147-8bf5-da46855a4641_609x317.png 1272w, https://substackcdn.com/image/fetch/$s_!r_Je!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F889d79be-870e-4147-8bf5-da46855a4641_609x317.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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>With 1,000 users, you might have 100 concurrent connections hitting your API. Without pooling, that&#8217;s 100 database connections consuming resources. With pooling, 20-30 actual database connections can efficiently serve those 100 application connections through connection reuse.</p><p><strong>Connection pooling modes:</strong></p><ul><li><p><strong>Session pooling</strong>: One pool connection per client connection (most compatible, least efficient)</p></li><li><p><strong>Transaction pooling</strong>: Connection returned to the pool after each transaction (best balance for most apps)</p></li><li><p><strong>Statement pooling</strong>: Connection returned after each statement (most efficient, but can break features)</p></li></ul><p>Most applications work best with <strong>transaction pooling</strong>, which often improves connection efficiency by <strong>3&#8211;5x</strong>.</p><h3>Network Latency Considerations</h3><p>Separating the database introduces network latency. When app and database were on the same machine, &#8220;network&#8221; latency was essentially zero (loopback interface). Now every query adds 0.1-1ms of network round-trip time.</p><p>For most applications, this is negligible. But if your code makes hundreds of database queries per request (an anti-pattern, but common), this latency adds up. The solution isn&#8217;t to put them back on the same machine, but to optimize your query patterns:</p><ul><li><p>Batch queries where possible</p></li><li><p>Use JOINs instead of N+1 query patterns</p></li><li><p>Cache frequently accessed data</p></li><li><p>Use connection pooling to avoid repeated connection setup overhead</p></li></ul><p>With the database on its own server, you&#8217;ve bought yourself room to grow. But you&#8217;ve also created a new single point of failure: the application server is now the weak link. What happens when it goes down, or when it simply can&#8217;t keep up with demand?</p><div><hr></div><h1>Stage 3: Load Balancer + Horizontal Scaling (1K-10K Users)</h1>
      <p>
          <a href="https://blog.algomaster.io/p/scaling-a-system-from-0-to-10-million-users">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[DSA was HARD until I Learned these 20 Patterns]]></title><description><![CDATA[Templates included]]></description><link>https://blog.algomaster.io/p/20-dsa-patterns</link><guid isPermaLink="false">https://blog.algomaster.io/p/20-dsa-patterns</guid><dc:creator><![CDATA[Ashish Pratap Singh]]></dc:creator><pubDate>Tue, 20 Jan 2026 04:54:49 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!Zq5_!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce7ede95-93fd-4e84-bca9-2500d9d5f518_783x955.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>I&#8217;ve solved over 2,000 coding problems across<strong> </strong>LeetCode<strong> </strong>and other platforms<strong>, </strong>and<strong> </strong>if there&#8217;s one thing I&#8217;ve learned, it&#8217;s this:</p><blockquote><p>Getting good at DSA is <strong>less</strong> about how many problems you solve and <strong>more</strong> about how many <strong>patterns</strong> you truly understand.</p></blockquote><p>Patterns help you solve a wide range of problems in less time because they train you to recognize the right approach, even for questions you have never seen before.</p><p>In this article, I&#8217;ll walk you through the <strong>20 most important patterns</strong> that made learning DSA and preparing for coding interviews far less painful for me.</p><p>Even better, these are the same patterns that showed up again and again in my interviews, including at companies like <strong>Amazon</strong> and <strong>Google</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_!Zq5_!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce7ede95-93fd-4e84-bca9-2500d9d5f518_783x955.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Zq5_!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce7ede95-93fd-4e84-bca9-2500d9d5f518_783x955.png 424w, https://substackcdn.com/image/fetch/$s_!Zq5_!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce7ede95-93fd-4e84-bca9-2500d9d5f518_783x955.png 848w, https://substackcdn.com/image/fetch/$s_!Zq5_!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce7ede95-93fd-4e84-bca9-2500d9d5f518_783x955.png 1272w, https://substackcdn.com/image/fetch/$s_!Zq5_!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce7ede95-93fd-4e84-bca9-2500d9d5f518_783x955.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Zq5_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce7ede95-93fd-4e84-bca9-2500d9d5f518_783x955.png" width="627" height="764.7318007662835" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ce7ede95-93fd-4e84-bca9-2500d9d5f518_783x955.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:955,&quot;width&quot;:783,&quot;resizeWidth&quot;:627,&quot;bytes&quot;:157785,&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://blog.algomaster.io/i/184854210?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce7ede95-93fd-4e84-bca9-2500d9d5f518_783x955.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_!Zq5_!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce7ede95-93fd-4e84-bca9-2500d9d5f518_783x955.png 424w, https://substackcdn.com/image/fetch/$s_!Zq5_!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce7ede95-93fd-4e84-bca9-2500d9d5f518_783x955.png 848w, https://substackcdn.com/image/fetch/$s_!Zq5_!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce7ede95-93fd-4e84-bca9-2500d9d5f518_783x955.png 1272w, https://substackcdn.com/image/fetch/$s_!Zq5_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce7ede95-93fd-4e84-bca9-2500d9d5f518_783x955.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>For each pattern, I&#8217;ll share:</p><ul><li><p>When to use it</p></li><li><p>A reusable template</p></li><li><p>A sample problem walkthrough</p></li><li><p>Practice links to related LeetCode problems</p></li></ul><p>This article is the essence of everything I have learned about DSA and LeetCode, distilled into one guide. I&#8217;ve also added links for each pattern so you can dive deeper when you&#8217;re ready.</p><p>If you want to explore more patterns and resources, check out: <a href="https://algomaster.io/">algomaster.io</a></p><p>Let&#8217;s get started.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.algomaster.io/p/20-dsa-patterns?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://blog.algomaster.io/p/20-dsa-patterns?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><div><hr></div><h1>1. <a href="https://algomaster.io/learn/dsa/prefix-sum-introduction">Prefix Sum</a></h1><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!mhMA!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34681b04-c8c1-489e-bb28-5a7bac0e8748_395x212.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!mhMA!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34681b04-c8c1-489e-bb28-5a7bac0e8748_395x212.png 424w, https://substackcdn.com/image/fetch/$s_!mhMA!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34681b04-c8c1-489e-bb28-5a7bac0e8748_395x212.png 848w, https://substackcdn.com/image/fetch/$s_!mhMA!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34681b04-c8c1-489e-bb28-5a7bac0e8748_395x212.png 1272w, https://substackcdn.com/image/fetch/$s_!mhMA!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34681b04-c8c1-489e-bb28-5a7bac0e8748_395x212.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!mhMA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34681b04-c8c1-489e-bb28-5a7bac0e8748_395x212.png" width="395" height="212" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/34681b04-c8c1-489e-bb28-5a7bac0e8748_395x212.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:212,&quot;width&quot;:395,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:13267,&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://blog.algomaster.io/i/184854210?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34681b04-c8c1-489e-bb28-5a7bac0e8748_395x212.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_!mhMA!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34681b04-c8c1-489e-bb28-5a7bac0e8748_395x212.png 424w, https://substackcdn.com/image/fetch/$s_!mhMA!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34681b04-c8c1-489e-bb28-5a7bac0e8748_395x212.png 848w, https://substackcdn.com/image/fetch/$s_!mhMA!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34681b04-c8c1-489e-bb28-5a7bac0e8748_395x212.png 1272w, https://substackcdn.com/image/fetch/$s_!mhMA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34681b04-c8c1-489e-bb28-5a7bac0e8748_395x212.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>The Prefix Sum pattern involves <strong>preprocessing</strong> an array to create a new array where each element at index <code>i</code> represents the sum of all elements from the start up to <code>i</code>. This allows for <strong>O(1) sum queries</strong> on any subarray.</p><h3>When to use</h3><ul><li><p>Multiple sum queries on subarrays</p></li><li><p>Finding subarrays with a target sum</p></li><li><p>Calculating cumulative totals</p></li></ul><h3>Template</h3><pre><code>// Build prefix sum array
int[] prefix = new int[n + 1];
for (int i = 0; i &lt; n; i++) {
    prefix[i + 1] = prefix[i] + nums[i];
}

// Query sum of range [left, right]
int rangeSum = prefix[right + 1] - prefix[left];</code></pre><h3>Sample Problem</h3><p><strong>Range Sum Query</strong>: Given an array <code>nums</code>, answer multiple queries about the sum of elements within a specific range <code>[i, j]</code>.</p><h4>Example:</h4><ul><li><p><strong>Input:</strong> <code>nums = [1, 2, 3, 4, 5, 6]</code>, <code>i = 1</code>, <code>j = 3</code></p></li><li><p><strong>Output:</strong> <code>9</code></p></li></ul><h4>Step-by-Step Walkthrough:</h4><pre><code>nums = [1, 2, 3, 4, 5, 6]

Step 1: Build prefix sum array
  prefix[0] = 0
  prefix[1] = 0 + 1 = 1
  prefix[2] = 1 + 2 = 3
  prefix[3] = 3 + 3 = 6
  prefix[4] = 6 + 4 = 10
  prefix[5] = 10 + 5 = 15
  prefix[6] = 15 + 6 = 21

  prefix = [0, 1, 3, 6, 10, 15, 21]

Step 2: Query sum for range [1, 3]
  sum = prefix[3 + 1] - prefix[1]
  sum = prefix[4] - prefix[1]
  sum = 10 - 1 = 9</code></pre><h3>Practice Problems</h3><ol><li><p><a href="https://leetcode.com/problems/range-sum-query-immutable/">Range Sum Query - Immutable (LeetCode #303)</a></p></li><li><p><a href="https://leetcode.com/problems/contiguous-array/">Contiguous Array (LeetCode #525)</a></p></li><li><p><a href="https://leetcode.com/problems/subarray-sum-equals-k/">Subarray Sum Equals K (LeetCode #560)</a></p></li><li><p><a href="https://leetcode.com/problems/product-of-array-except-self/">Product of Array Except Self (LeetCode #238)</a></p></li></ol><div><hr></div><h1>2. <a href="https://algomaster.io/learn/dsa/two-pointers-introduction">Two Pointers</a></h1><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!c0Qf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2bc6864-ae2a-4634-bfea-c270a62a05c3_427x213.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!c0Qf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2bc6864-ae2a-4634-bfea-c270a62a05c3_427x213.png 424w, https://substackcdn.com/image/fetch/$s_!c0Qf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2bc6864-ae2a-4634-bfea-c270a62a05c3_427x213.png 848w, https://substackcdn.com/image/fetch/$s_!c0Qf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2bc6864-ae2a-4634-bfea-c270a62a05c3_427x213.png 1272w, https://substackcdn.com/image/fetch/$s_!c0Qf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2bc6864-ae2a-4634-bfea-c270a62a05c3_427x213.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!c0Qf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2bc6864-ae2a-4634-bfea-c270a62a05c3_427x213.png" width="427" height="213" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e2bc6864-ae2a-4634-bfea-c270a62a05c3_427x213.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:213,&quot;width&quot;:427,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:12671,&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://blog.algomaster.io/i/184854210?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2bc6864-ae2a-4634-bfea-c270a62a05c3_427x213.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_!c0Qf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2bc6864-ae2a-4634-bfea-c270a62a05c3_427x213.png 424w, https://substackcdn.com/image/fetch/$s_!c0Qf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2bc6864-ae2a-4634-bfea-c270a62a05c3_427x213.png 848w, https://substackcdn.com/image/fetch/$s_!c0Qf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2bc6864-ae2a-4634-bfea-c270a62a05c3_427x213.png 1272w, https://substackcdn.com/image/fetch/$s_!c0Qf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2bc6864-ae2a-4634-bfea-c270a62a05c3_427x213.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>The Two Pointers pattern uses two pointers to traverse an array or list, typically from opposite ends or both moving in the same direction. It reduces time complexity from <strong>O(n^2) to O(n)</strong> for many problems.</p><h3>When to use</h3><ul><li><p>Finding pairs in sorted arrays</p></li><li><p>Comparing elements from both ends</p></li><li><p>Partitioning arrays</p></li><li><p>Palindrome checks</p></li></ul><h3>Template</h3><pre><code>// Opposite direction (converging)
int left = 0, right = n - 1;
while (left &lt; right) {
    if (condition_met) {
        // found answer
    } else if (need_larger_sum) {
        left++;
    } else {
        right--;
    }
}

// Same direction
int slow = 0;
for (int fast = 0; fast &lt; n; fast++) {
    if (condition) {
        // process and move slow
        slow++;
    }
}</code></pre><h3>Sample Problem</h3><p><strong>Two Sum II</strong>: Find two numbers in a sorted array that add up to a target value. Return their indices.</p><h4>Example:</h4><ul><li><p><strong>Input:</strong> <code>nums = [1, 2, 3, 4, 6]</code>, <code>target = 6</code></p></li><li><p><strong>Output:</strong> <code>[1, 3]</code> (indices of 2 and 4)</p></li></ul><h4>Step-by-Step Walkthrough:</h4><pre><code>nums = [1, 2, 3, 4, 6], target = 6

Step 1: left = 0, right = 4
  sum = nums[0] + nums[4] = 1 + 6 = 7 &gt; 6
  Move right pointer left: right = 3

Step 2: left = 0, right = 3
  sum = nums[0] + nums[3] = 1 + 4 = 5 &lt; 6
  Move left pointer right: left = 1

Step 3: left = 1, right = 3
  sum = nums[1] + nums[3] = 2 + 4 = 6 == target
  Found! Return [1, 3]</code></pre><h3>Practice Problems</h3><ol><li><p><a href="https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/">Two Sum II - Input Array is Sorted (LeetCode #167)</a></p></li><li><p><a href="https://leetcode.com/problems/3sum/">3Sum (LeetCode #15)</a></p></li><li><p><a href="https://leetcode.com/problems/container-with-most-water/">Container With Most Water (LeetCode #11)</a></p></li><li><p><a href="https://leetcode.com/problems/trapping-rain-water/">Trapping Rain Water (LeetCode #42)</a></p></li><li><p><a href="https://leetcode.com/problems/valid-palindrome/">Valid Palindrome (LeetCode #125)</a></p></li></ol><div><hr></div><h1>3. <a href="https://algomaster.io/learn/dsa/sliding-window-introduction">Sliding Window</a></h1><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!85XO!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13fce108-3936-4ab5-aea7-e7ea7dc9982f_456x272.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!85XO!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13fce108-3936-4ab5-aea7-e7ea7dc9982f_456x272.png 424w, https://substackcdn.com/image/fetch/$s_!85XO!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13fce108-3936-4ab5-aea7-e7ea7dc9982f_456x272.png 848w, https://substackcdn.com/image/fetch/$s_!85XO!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13fce108-3936-4ab5-aea7-e7ea7dc9982f_456x272.png 1272w, https://substackcdn.com/image/fetch/$s_!85XO!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13fce108-3936-4ab5-aea7-e7ea7dc9982f_456x272.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!85XO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13fce108-3936-4ab5-aea7-e7ea7dc9982f_456x272.png" width="456" height="272" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/13fce108-3936-4ab5-aea7-e7ea7dc9982f_456x272.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:272,&quot;width&quot;:456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:15969,&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://blog.algomaster.io/i/184854210?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13fce108-3936-4ab5-aea7-e7ea7dc9982f_456x272.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_!85XO!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13fce108-3936-4ab5-aea7-e7ea7dc9982f_456x272.png 424w, https://substackcdn.com/image/fetch/$s_!85XO!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13fce108-3936-4ab5-aea7-e7ea7dc9982f_456x272.png 848w, https://substackcdn.com/image/fetch/$s_!85XO!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13fce108-3936-4ab5-aea7-e7ea7dc9982f_456x272.png 1272w, https://substackcdn.com/image/fetch/$s_!85XO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13fce108-3936-4ab5-aea7-e7ea7dc9982f_456x272.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 Sliding Window pattern maintains a window of elements and slides it across the array to find subarrays or substrings that satisfy certain conditions. It avoids recalculating overlapping parts of consecutive windows.</p><h3>When to use</h3><ul><li><p>Contiguous subarray/substring problems</p></li><li><p>Finding maximum/minimum in window of size k</p></li><li><p>Longest/shortest substring with certain properties</p></li><li><p>Problems involving consecutive elements</p></li></ul><h3>Template</h3><pre><code>// Fixed-size window
int windowSum = 0;
for (int i = 0; i &lt; n; i++) {
    windowSum += nums[i];
    if (i &gt;= k - 1) {
        // process window
        result = Math.max(result, windowSum);
        windowSum -= nums[i - k + 1];
    }
}

// Variable-size window
int left = 0;
for (int right = 0; right &lt; n; right++) {
    // expand window by including nums[right]

    while (window_condition_violated) {
        // shrink window from left
        left++;
    }

    // update result
}</code></pre><h3>Sample Problem</h3><p><strong>Maximum Sum Subarray of Size K</strong>: Find the maximum sum of any contiguous subarray of size <code>k</code>.</p><h4>Example:</h4><ul><li><p><strong>Input:</strong> <code>nums = [2, 1, 5, 1, 3, 2]</code>, <code>k = 3</code></p></li><li><p><strong>Output:</strong> <code>9</code></p></li></ul><h4>Step-by-Step Walkthrough:</h4><pre><code>nums = [2, 1, 5, 1, 3, 2], k = 3

Step 1: Build initial window [2, 1, 5]
  windowSum = 2 + 1 + 5 = 8
  maxSum = 8

Step 2: Slide window to [1, 5, 1]
  windowSum = 8 - 2 + 1 = 7
  maxSum = max(8, 7) = 8

Step 3: Slide window to [5, 1, 3]
  windowSum = 7 - 1 + 3 = 9
  maxSum = max(8, 9) = 9

Step 4: Slide window to [1, 3, 2]
  windowSum = 9 - 5 + 2 = 6
  maxSum = max(9, 6) = 9

Result: 9</code></pre><h3>Practice Problems</h3><ol><li><p><a href="https://leetcode.com/problems/maximum-average-subarray-i/">Maximum Average Subarray I (LeetCode #643)</a></p></li><li><p><a href="https://leetcode.com/problems/longest-substring-without-repeating-characters/">Longest Substring Without Repeating Characters (LeetCode #3)</a></p></li><li><p><a href="https://leetcode.com/problems/minimum-window-substring/">Minimum Window Substring (LeetCode #76)</a></p></li><li><p><a href="https://leetcode.com/problems/permutation-in-string/">Permutation in String (LeetCode #567)</a></p></li><li><p><a href="https://leetcode.com/problems/sliding-window-maximum/">Sliding Window Maximum (LeetCode #239)</a></p></li></ol><div><hr></div><h1>4. <a href="https://algomaster.io/learn/dsa/fast-slow-pointers-introduction">Fast &amp; Slow Pointers</a></h1><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!dGnL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35244893-2102-4209-a164-1709d042b95f_553x164.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!dGnL!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35244893-2102-4209-a164-1709d042b95f_553x164.png 424w, https://substackcdn.com/image/fetch/$s_!dGnL!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35244893-2102-4209-a164-1709d042b95f_553x164.png 848w, https://substackcdn.com/image/fetch/$s_!dGnL!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35244893-2102-4209-a164-1709d042b95f_553x164.png 1272w, https://substackcdn.com/image/fetch/$s_!dGnL!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35244893-2102-4209-a164-1709d042b95f_553x164.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!dGnL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35244893-2102-4209-a164-1709d042b95f_553x164.png" width="553" height="164" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/35244893-2102-4209-a164-1709d042b95f_553x164.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:164,&quot;width&quot;:553,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:12039,&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://blog.algomaster.io/i/184854210?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35244893-2102-4209-a164-1709d042b95f_553x164.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_!dGnL!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35244893-2102-4209-a164-1709d042b95f_553x164.png 424w, https://substackcdn.com/image/fetch/$s_!dGnL!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35244893-2102-4209-a164-1709d042b95f_553x164.png 848w, https://substackcdn.com/image/fetch/$s_!dGnL!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35244893-2102-4209-a164-1709d042b95f_553x164.png 1272w, https://substackcdn.com/image/fetch/$s_!dGnL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35244893-2102-4209-a164-1709d042b95f_553x164.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>The Fast &amp; Slow Pointers pattern (also called Tortoise and Hare) uses two pointers moving at different speeds. When there is a cycle, the fast pointer will eventually meet the slow pointer.</p><h3>When to use</h3><ul><li><p>Detecting cycles in linked lists or arrays</p></li><li><p>Finding the middle of a linked list</p></li><li><p>Finding the start of a cycle</p></li></ul><h3>Template</h3><pre><code><code>// Find middle
while (fast != null &amp;&amp; fast.next != null) {
    slow = slow.next;
    fast = fast.next.next;
}
return slow; // middle node

// Cycle detection
ListNode slow = head, fast = head;
while (fast != null &amp;&amp; fast.next != null) {
    slow = slow.next;
    fast = fast.next.next;

    if (slow == fast) {
        // cycle detected
        return true;
    }
}
return false; // no cycle</code></code></pre><h3>Sample Problem</h3><p><strong>Linked List Cycle</strong>: Detect if a linked list has a cycle.</p><h4>Example:</h4><ul><li><p><strong>Input:</strong> <code>head = [3, 2, 0, -4]</code>, tail connects to node index 1</p></li><li><p><strong>Output:</strong> <code>true</code></p></li></ul><h4>Step-by-Step Walkthrough:</h4><pre><code><code>List: 3 -&gt; 2 -&gt; 0 -&gt; -4 -&gt; (back to 2)

Step 1: slow = 3, fast = 3
Step 2: slow = 2, fast = 0
Step 3: slow = 0, fast = 2 (wrapped around)
Step 4: slow = -4, fast = -4

slow == fast, cycle detected!</code></code></pre><h3>Practice Problems</h3><ol><li><p><a href="https://leetcode.com/problems/linked-list-cycle/">Linked List Cycle (LeetCode #141)</a></p></li><li><p><a href="https://leetcode.com/problems/linked-list-cycle-ii/">Linked List Cycle II (LeetCode #142)</a></p></li><li><p><a href="https://leetcode.com/problems/happy-number/">Happy Number (LeetCode #202)</a></p></li><li><p><a href="https://leetcode.com/problems/find-the-duplicate-number/">Find the Duplicate Number (LeetCode #287)</a></p></li><li><p><a href="https://leetcode.com/problems/middle-of-the-linked-list/">Middle of the Linked List (LeetCode #876)</a></p></li></ol><div><hr></div><h1>5. <a href="https://algomaster.io/learn/dsa/linked-list-in-place-reversal-introduction">LinkedList In-place Reversal</a></h1><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!4C0C!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0cd68630-9c56-41d4-a686-5de4f135138f_530x179.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!4C0C!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0cd68630-9c56-41d4-a686-5de4f135138f_530x179.png 424w, https://substackcdn.com/image/fetch/$s_!4C0C!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0cd68630-9c56-41d4-a686-5de4f135138f_530x179.png 848w, https://substackcdn.com/image/fetch/$s_!4C0C!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0cd68630-9c56-41d4-a686-5de4f135138f_530x179.png 1272w, https://substackcdn.com/image/fetch/$s_!4C0C!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0cd68630-9c56-41d4-a686-5de4f135138f_530x179.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!4C0C!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0cd68630-9c56-41d4-a686-5de4f135138f_530x179.png" width="530" height="179" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0cd68630-9c56-41d4-a686-5de4f135138f_530x179.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:179,&quot;width&quot;:530,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:12893,&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://blog.algomaster.io/i/184854210?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0cd68630-9c56-41d4-a686-5de4f135138f_530x179.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_!4C0C!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0cd68630-9c56-41d4-a686-5de4f135138f_530x179.png 424w, https://substackcdn.com/image/fetch/$s_!4C0C!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0cd68630-9c56-41d4-a686-5de4f135138f_530x179.png 848w, https://substackcdn.com/image/fetch/$s_!4C0C!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0cd68630-9c56-41d4-a686-5de4f135138f_530x179.png 1272w, https://substackcdn.com/image/fetch/$s_!4C0C!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0cd68630-9c56-41d4-a686-5de4f135138f_530x179.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>This pattern reverses parts of a linked list without using extra space. It manipulates pointers to reverse the direction of links.</p><h3>When to use</h3><ul><li><p>Reversing a linked list or portion of it</p></li><li><p>Reversing nodes in groups</p></li><li><p>Checking for palindromes in linked lists</p></li></ul><h3>Template</h3><pre><code>// Reverse entire list
ListNode prev = null, curr = head;
while (curr != null) {
    ListNode next = curr.next;
    curr.next = prev;
    prev = curr;
    curr = next;
}
return prev; // new head</code></pre><h3>Sample Problem</h3><p><strong>Reverse Linked List II</strong>: Reverse the nodes of a linked list from position <code>m</code> to <code>n</code>.</p><h4>Example:</h4><ul><li><p><strong>Input:</strong> <code>head = [1, 2, 3, 4, 5]</code>, <code>m = 2</code>, <code>n = 4</code></p></li><li><p><strong>Output:</strong> <code>[1, 4, 3, 2, 5]</code></p></li></ul><h4>Step-by-Step Walkthrough:</h4><pre><code>Original: 1 -&gt; 2 -&gt; 3 -&gt; 4 -&gt; 5
Reverse positions 2 to 4

Step 1: Position prev before node 2
  prev = 1, curr = 2

Step 2: Move 3 after 1
  1 -&gt; 3 -&gt; 2 -&gt; 4 -&gt; 5

Step 3: Move 4 after 1
  1 -&gt; 4 -&gt; 3 -&gt; 2 -&gt; 5

Result: [1, 4, 3, 2, 5]</code></pre><h3>Practice Problems</h3><ol><li><p><a href="https://leetcode.com/problems/reverse-linked-list/">Reverse Linked List (LeetCode #206)</a></p></li><li><p><a href="https://leetcode.com/problems/reverse-linked-list-ii/">Reverse Linked List II (LeetCode #92)</a></p></li><li><p><a href="https://leetcode.com/problems/swap-nodes-in-pairs/">Swap Nodes in Pairs (LeetCode #24)</a></p></li><li><p><a href="https://leetcode.com/problems/reverse-nodes-in-k-group/">Reverse Nodes in k-Group (LeetCode #25)</a></p></li><li><p><a href="https://leetcode.com/problems/palindrome-linked-list/">Palindrome Linked List (LeetCode #234)</a></p></li></ol><div><hr></div><h1>6. <a href="https://algomaster.io/learn/dsa/frequency-counting-introduction">Frequency Counting</a></h1><p>The Frequency Counting pattern uses hash maps or arrays to count occurrences of elements. It transforms O(n^2) lookup problems into O(n) by trading space for time.</p><h3>When to use</h3><ul><li><p>Finding duplicates or unique elements</p></li><li><p>Checking if two collections have same elements</p></li><li><p>Finding elements that appear k times</p></li><li><p>Anagram problems</p></li></ul><h3>Template</h3><pre><code><code>// Using HashMap
Map&lt;Integer, Integer&gt; freq = new HashMap&lt;&gt;();
for (int num : nums) {
    freq.put(num, freq.getOrDefault(num, 0) + 1);
}

// Using array (when range is known)
int[] freq = new int[26]; // for lowercase letters
for (char c : str.toCharArray()) {
    freq[c - 'a']++;
}

// Finding element with specific frequency
for (Map.Entry&lt;Integer, Integer&gt; entry : freq.entrySet()) {
    if (entry.getValue() == target) {
        return entry.getKey();
    }
}</code></code></pre><h3>Sample Problem</h3><p><strong>Valid Anagram</strong>: Given two strings <code>s</code> and <code>t</code>, return true if <code>t</code> is an anagram of <code>s</code>.</p><h4>Example:</h4><ul><li><p><strong>Input:</strong> <code>s = "anagram"</code>, <code>t = "nagaram"</code></p></li><li><p><strong>Output:</strong> <code>true</code></p></li></ul><h4>Step-by-Step Walkthrough:</h4><pre><code><code>s = "anagram", t = "nagaram"

Step 1: Count frequencies in s
  freq = {a: 3, n: 1, g: 1, r: 1, m: 1}

Step 2: Decrement frequencies using t
  't' -&gt; n: freq[n] = 1 - 1 = 0
  't' -&gt; a: freq[a] = 3 - 1 = 2
  't' -&gt; g: freq[g] = 1 - 1 = 0
  't' -&gt; a: freq[a] = 2 - 1 = 1
  't' -&gt; r: freq[r] = 1 - 1 = 0
  't' -&gt; a: freq[a] = 1 - 1 = 0
  't' -&gt; m: freq[m] = 1 - 1 = 0

Step 3: Check all frequencies are 0
  freq = {a: 0, n: 0, g: 0, r: 0, m: 0}
  All zero -&gt; Return true</code></code></pre><h3>Practice Problems</h3><ol><li><p><a href="https://leetcode.com/problems/valid-anagram/">Valid Anagram (LeetCode #242)</a></p></li><li><p><a href="https://leetcode.com/problems/group-anagrams/">Group Anagrams (LeetCode #49)</a></p></li><li><p><a href="https://leetcode.com/problems/top-k-frequent-elements/">Top K Frequent Elements (LeetCode #347)</a></p></li><li><p><a href="https://leetcode.com/problems/first-unique-character-in-a-string/">First Unique Character in a String (LeetCode #387)</a></p></li></ol><div><hr></div><h1>7. <a href="https://algomaster.io/learn/dsa/monotonic-stack-introduction">Monotonic Stack</a></h1><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Bho7!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa38b30f3-981b-48a5-badd-80ea36dae834_533x211.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Bho7!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa38b30f3-981b-48a5-badd-80ea36dae834_533x211.png 424w, https://substackcdn.com/image/fetch/$s_!Bho7!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa38b30f3-981b-48a5-badd-80ea36dae834_533x211.png 848w, https://substackcdn.com/image/fetch/$s_!Bho7!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa38b30f3-981b-48a5-badd-80ea36dae834_533x211.png 1272w, https://substackcdn.com/image/fetch/$s_!Bho7!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa38b30f3-981b-48a5-badd-80ea36dae834_533x211.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Bho7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa38b30f3-981b-48a5-badd-80ea36dae834_533x211.png" width="533" height="211" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a38b30f3-981b-48a5-badd-80ea36dae834_533x211.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:211,&quot;width&quot;:533,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:13402,&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://blog.algomaster.io/i/184854210?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa38b30f3-981b-48a5-badd-80ea36dae834_533x211.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_!Bho7!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa38b30f3-981b-48a5-badd-80ea36dae834_533x211.png 424w, https://substackcdn.com/image/fetch/$s_!Bho7!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa38b30f3-981b-48a5-badd-80ea36dae834_533x211.png 848w, https://substackcdn.com/image/fetch/$s_!Bho7!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa38b30f3-981b-48a5-badd-80ea36dae834_533x211.png 1272w, https://substackcdn.com/image/fetch/$s_!Bho7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa38b30f3-981b-48a5-badd-80ea36dae834_533x211.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>A Monotonic Stack maintains elements in either increasing or decreasing order. As you iterate, you pop elements that violate the order, which reveals relationships between elements.</p><h3>When to use</h3><ul><li><p>Finding the next greater/smaller element</p></li><li><p>Finding previous greater/smaller element</p></li><li><p>Problems involving spans or ranges</p></li><li><p>Histogram problems</p></li></ul><h3>Template</h3><pre><code>/// Next Greater Element (decreasing stack)
int[] result = new int[n];
Arrays.fill(result, -1);
Stack&lt;Integer&gt; stack = new Stack&lt;&gt;(); // stores indices

for (int i = 0; i &lt; n; i++) {
    while (!stack.isEmpty() &amp;&amp; nums[i] &gt; nums[stack.peek()]) {
        int idx = stack.pop();
        result[idx] = nums[i];
    }
    stack.push(i);
}</code></pre><h3>Sample Problem</h3><p><strong>Next Greater Element</strong>: For each element in an array, find the next greater element. Output -1 if none exists.</p><h4>Example:</h4><ul><li><p><strong>Input:</strong> <code>nums = [2, 1, 2, 4, 3]</code></p></li><li><p><strong>Output:</strong> <code>[4, 2, 4, -1, -1]</code></p></li></ul><h4>Step-by-Step Walkthrough:</h4><pre><code>nums = [2, 1, 2, 4, 3]
result = [-1, -1, -1, -1, -1]
stack = []

Step 1: i = 0, nums[0] = 2
  stack is empty, push 0
  stack = [0]

Step 2: i = 1, nums[1] = 1
  1 &lt; nums[0]=2, push 1
  stack = [0, 1]

Step 3: i = 2, nums[2] = 2
  2 &gt; nums[1]=1, pop 1, result[1] = 2
  2 &lt;= nums[0]=2, push 2
  stack = [0, 2], result = [-1, 2, -1, -1, -1]

Step 4: i = 3, nums[3] = 4
  4 &gt; nums[2]=2, pop 2, result[2] = 4
  4 &gt; nums[0]=2, pop 0, result[0] = 4
  push 3
  stack = [3], result = [4, 2, 4, -1, -1]

Step 5: i = 4, nums[4] = 3
  3 &lt; nums[3]=4, push 4
  stack = [3, 4]

Result: [4, 2, 4, -1, -1]</code></pre><h3>Practice Problems</h3><ol><li><p><a href="https://leetcode.com/problems/next-greater-element-i/">Next Greater Element I (LeetCode #496)</a></p></li><li><p><a href="https://leetcode.com/problems/daily-temperatures/">Daily Temperatures (LeetCode #739)</a></p></li><li><p><a href="https://leetcode.com/problems/largest-rectangle-in-histogram/">Largest Rectangle in Histogram (LeetCode #84)</a></p></li><li><p><a href="https://leetcode.com/problems/trapping-rain-water/">Trapping Rain Water (LeetCode #42)</a></p></li><li><p><a href="https://leetcode.com/problems/online-stock-span/">Online Stock Span (LeetCode #901)</a></p></li></ol><div><hr></div><h1>8. <a href="https://algomaster.io/learn/dsa/bit-manipulation-introduction">Bit Manipulation</a></h1><p>Bit manipulation uses binary operations (AND, OR, XOR, NOT, shifts) to solve problems efficiently. XOR is particularly useful since a ^ a = 0 and a ^ 0 = a.</p><h3>When to use</h3><ul><li><p>Finding unique numbers (XOR)</p></li><li><p>Checking power of 2</p></li><li><p>Counting bits</p></li><li><p>Generating subsets using bit masks</p></li><li><p>Space optimization</p></li></ul><h3>Template</h3><pre><code>// Basic operations
int and = a &amp; b;        // both bits 1
int or = a | b;         // either bit 1
int xor = a ^ b;        // bits different
int not = ~a;           // flip bits
int leftShift = a &lt;&lt; n; // multiply by 2^n
int rightShift = a &gt;&gt; n;// divide by 2^n

// Check if bit i is set
boolean isSet = (n &amp; (1 &lt;&lt; i)) != 0;

// Set bit i
n = n | (1 &lt;&lt; i);

// Clear bit i
n = n &amp; ~(1 &lt;&lt; i);

// Toggle bit i
n = n ^ (1 &lt;&lt; i);

// Check if power of 2
boolean isPowerOf2 = (n &gt; 0) &amp;&amp; ((n &amp; (n - 1)) == 0);

// Count set bits
int count = 0;
while (n &gt; 0) {
    count += n &amp; 1;
    n &gt;&gt;= 1;
}
// Or: Integer.bitCount(n);

// Find single number (XOR all elements)
int single = 0;
for (int num : nums) {
    single ^= num;
}</code></pre><h2>Practice Problems</h2><ol><li><p><a href="https://leetcode.com/problems/single-number/">Single Number (LeetCode #136)</a></p></li><li><p><a href="https://leetcode.com/problems/number-of-1-bits/">Number of 1 Bits (LeetCode #191)</a></p></li><li><p><a href="https://leetcode.com/problems/counting-bits/">Counting Bits (LeetCode #338)</a></p></li><li><p><a href="https://leetcode.com/problems/power-of-two/">Power of Two (LeetCode #231)</a></p></li><li><p><a href="https://leetcode.com/problems/missing-number/">Missing Number (LeetCode #268)</a></p></li></ol><div><hr></div><h1>9. <a href="https://algomaster.io/learn/dsa/top-k-elements-introduction">Top &#8216;K&#8217; Elements</a></h1><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!yX7t!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2546e104-3d19-49ec-b7bb-1652786a4a79_597x240.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!yX7t!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2546e104-3d19-49ec-b7bb-1652786a4a79_597x240.png 424w, https://substackcdn.com/image/fetch/$s_!yX7t!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2546e104-3d19-49ec-b7bb-1652786a4a79_597x240.png 848w, https://substackcdn.com/image/fetch/$s_!yX7t!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2546e104-3d19-49ec-b7bb-1652786a4a79_597x240.png 1272w, https://substackcdn.com/image/fetch/$s_!yX7t!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2546e104-3d19-49ec-b7bb-1652786a4a79_597x240.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!yX7t!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2546e104-3d19-49ec-b7bb-1652786a4a79_597x240.png" width="597" height="240" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2546e104-3d19-49ec-b7bb-1652786a4a79_597x240.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:240,&quot;width&quot;:597,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:19420,&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://blog.algomaster.io/i/184854210?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2546e104-3d19-49ec-b7bb-1652786a4a79_597x240.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_!yX7t!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2546e104-3d19-49ec-b7bb-1652786a4a79_597x240.png 424w, https://substackcdn.com/image/fetch/$s_!yX7t!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2546e104-3d19-49ec-b7bb-1652786a4a79_597x240.png 848w, https://substackcdn.com/image/fetch/$s_!yX7t!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2546e104-3d19-49ec-b7bb-1652786a4a79_597x240.png 1272w, https://substackcdn.com/image/fetch/$s_!yX7t!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2546e104-3d19-49ec-b7bb-1652786a4a79_597x240.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>This pattern finds the k largest or smallest elements using heaps (priority queues). A min-heap of size k keeps track of k largest elements, and a max-heap keeps k smallest.</p><h3>When to use</h3><ul><li><p>Finding k largest/smallest elements</p></li><li><p>Finding kth largest/smallest element</p></li><li><p>Finding k most/least frequent elements</p></li><li><p>Merging k sorted lists</p></li></ul><h3>Template</h3><pre><code>// K largest elements using min-heap
PriorityQueue&lt;Integer&gt; minHeap = new PriorityQueue&lt;&gt;();

for (int num : nums) {
    minHeap.offer(num);
    if (minHeap.size() &gt; k) {
        minHeap.poll(); // remove smallest
    }
}
// minHeap now contains k largest elements
// minHeap.peek() is the kth largest</code></pre><h3>Sample Problem</h3><p><strong>Kth Largest Element</strong>: Find the kth largest element in an unsorted array.</p><h4>Example:</h4><ul><li><p><strong>Input:</strong> <code>nums = [3, 2, 1, 5, 6, 4]</code>, <code>k = 2</code></p></li><li><p><strong>Output:</strong> <code>5</code></p></li></ul><h4>Step-by-Step Walkthrough:</h4><pre><code>nums = [3, 2, 1, 5, 6, 4], k = 2
Using min-heap of size k

Step 1: num = 3
  heap = [3]

Step 2: num = 2
  heap = [2, 3]

Step 3: num = 1
  heap = [1, 3, 2], size &gt; k
  poll smallest: heap = [2, 3]

Step 4: num = 5
  heap = [2, 3, 5], size &gt; k
  poll smallest: heap = [3, 5]

Step 5: num = 6
  heap = [3, 5, 6], size &gt; k
  poll smallest: heap = [5, 6]

Step 6: num = 4
  heap = [4, 6, 5], size &gt; k
  poll smallest: heap = [5, 6]

heap.peek() = 5 (kth largest)</code></pre><h3>Practice Problems</h3><ol><li><p><a href="https://leetcode.com/problems/kth-largest-element-in-an-array/">Kth Largest Element in an Array (LeetCode #215)</a></p></li><li><p><a href="https://leetcode.com/problems/top-k-frequent-elements/">Top K Frequent Elements (LeetCode #347)</a></p></li><li><p><a href="https://leetcode.com/problems/k-closest-points-to-origin/">K Closest Points to Origin (LeetCode #973)</a></p></li><li><p><a href="https://leetcode.com/problems/find-k-pairs-with-smallest-sums/">Find K Pairs with Smallest Sums (LeetCode #373)</a></p></li><li><p><a href="https://leetcode.com/problems/kth-largest-element-in-a-stream/">Kth Largest Element in a Stream (LeetCode #703)</a></p></li></ol><div><hr></div><h1>10. <a href="https://algomaster.io/learn/dsa/intervals-introduction">Overlapping Intervals</a></h1><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!bOBx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f63f8b5-db64-4d4c-a3e0-6370c56c7d9e_491x121.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!bOBx!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f63f8b5-db64-4d4c-a3e0-6370c56c7d9e_491x121.png 424w, https://substackcdn.com/image/fetch/$s_!bOBx!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f63f8b5-db64-4d4c-a3e0-6370c56c7d9e_491x121.png 848w, https://substackcdn.com/image/fetch/$s_!bOBx!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f63f8b5-db64-4d4c-a3e0-6370c56c7d9e_491x121.png 1272w, https://substackcdn.com/image/fetch/$s_!bOBx!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f63f8b5-db64-4d4c-a3e0-6370c56c7d9e_491x121.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!bOBx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f63f8b5-db64-4d4c-a3e0-6370c56c7d9e_491x121.png" width="491" height="121" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8f63f8b5-db64-4d4c-a3e0-6370c56c7d9e_491x121.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:121,&quot;width&quot;:491,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:3115,&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://blog.algomaster.io/i/184854210?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f63f8b5-db64-4d4c-a3e0-6370c56c7d9e_491x121.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_!bOBx!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f63f8b5-db64-4d4c-a3e0-6370c56c7d9e_491x121.png 424w, https://substackcdn.com/image/fetch/$s_!bOBx!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f63f8b5-db64-4d4c-a3e0-6370c56c7d9e_491x121.png 848w, https://substackcdn.com/image/fetch/$s_!bOBx!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f63f8b5-db64-4d4c-a3e0-6370c56c7d9e_491x121.png 1272w, https://substackcdn.com/image/fetch/$s_!bOBx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f63f8b5-db64-4d4c-a3e0-6370c56c7d9e_491x121.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>This pattern handles problems involving intervals that may overlap. The key insight is that after sorting by start time, two intervals <code>[a, b]</code> and <code>[c, d]</code> overlap if <code>b &gt;= c</code>.</p><h3>When to use</h3><ul><li><p>Merging overlapping intervals</p></li><li><p>Finding interval intersections</p></li><li><p>Scheduling problems (meeting rooms)</p></li><li><p>Inserting into sorted intervals</p></li></ul><h3>Template</h3><pre><code>// Sort by start time
Arrays.sort(intervals, (a, b) -&gt; a[0] - b[0]);

// Merge overlapping intervals
List&lt;int[]&gt; merged = new ArrayList&lt;&gt;();
for (int[] interval : intervals) {
    if (merged.isEmpty() || merged.get(merged.size() - 1)[1] &lt; interval[0]) {
        // no overlap, add new interval
        merged.add(interval);
    } else {
        // overlap, merge by extending end time
        merged.get(merged.size() - 1)[1] =
            Math.max(merged.get(merged.size() - 1)[1], interval[1]);
    }
}</code></pre><h3>Sample Problem</h3><p><strong>Merge Intervals</strong>: Given a collection of intervals, merge all overlapping intervals.</p><h4>Example:</h4><ul><li><p><strong>Input:</strong> <code>intervals = [[1,3], [2,6], [8,10], [15,18]]</code></p></li><li><p><strong>Output:</strong> <code>[[1,6], [8,10], [15,18]]</code></p></li></ul><h4>Step-by-Step Walkthrough:</h4><pre><code>intervals = [[1,3], [2,6], [8,10], [15,18]]
(Already sorted by start time)

Step 1: interval = [1,3]
  merged is empty, add [1,3]
  merged = [[1,3]]

Step 2: interval = [2,6]
  last = [1,3], start = 2 &lt;= end = 3
  Overlap! Merge: end = max(3, 6) = 6
  merged = [[1,6]]

Step 3: interval = [8,10]
  last = [1,6], start = 8 &gt; end = 6
  No overlap, add [8,10]
  merged = [[1,6], [8,10]]

Step 4: interval = [15,18]
  last = [8,10], start = 15 &gt; end = 10
  No overlap, add [15,18]
  merged = [[1,6], [8,10], [15,18]]</code></pre><h3>Practice Problems</h3><ol><li><p><a href="https://leetcode.com/problems/merge-intervals/">Merge Intervals (LeetCode #56)</a></p></li><li><p><a href="https://leetcode.com/problems/insert-interval/">Insert Interval (LeetCode #57)</a></p></li><li><p><a href="https://leetcode.com/problems/non-overlapping-intervals/">Non-overlapping Intervals (LeetCode #435)</a></p></li><li><p><a href="https://leetcode.com/problems/meeting-rooms/">Meeting Rooms (LeetCode #252)</a></p></li><li><p><a href="https://leetcode.com/problems/meeting-rooms-ii/">Meeting Rooms II (LeetCode #253)</a></p></li></ol><div><hr></div><h1>11. <a href="https://algomaster.io/learn/dsa/binary-search-introduction">Modified Binary Search</a></h1><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!KXQf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1aea1488-9842-43ac-b4fc-214c5db22d04_632x184.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!KXQf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1aea1488-9842-43ac-b4fc-214c5db22d04_632x184.png 424w, https://substackcdn.com/image/fetch/$s_!KXQf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1aea1488-9842-43ac-b4fc-214c5db22d04_632x184.png 848w, https://substackcdn.com/image/fetch/$s_!KXQf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1aea1488-9842-43ac-b4fc-214c5db22d04_632x184.png 1272w, https://substackcdn.com/image/fetch/$s_!KXQf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1aea1488-9842-43ac-b4fc-214c5db22d04_632x184.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!KXQf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1aea1488-9842-43ac-b4fc-214c5db22d04_632x184.png" width="632" height="184" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1aea1488-9842-43ac-b4fc-214c5db22d04_632x184.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:184,&quot;width&quot;:632,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:15121,&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://blog.algomaster.io/i/184854210?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1aea1488-9842-43ac-b4fc-214c5db22d04_632x184.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_!KXQf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1aea1488-9842-43ac-b4fc-214c5db22d04_632x184.png 424w, https://substackcdn.com/image/fetch/$s_!KXQf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1aea1488-9842-43ac-b4fc-214c5db22d04_632x184.png 848w, https://substackcdn.com/image/fetch/$s_!KXQf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1aea1488-9842-43ac-b4fc-214c5db22d04_632x184.png 1272w, https://substackcdn.com/image/fetch/$s_!KXQf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1aea1488-9842-43ac-b4fc-214c5db22d04_632x184.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>This pattern adapts binary search to handle rotated arrays, finding boundaries, or searching for conditions rather than exact values.</p><h3>When to use</h3><ul><li><p>Searching in rotated sorted arrays</p></li><li><p>Finding first/last occurrence of element</p></li><li><p>Finding minimum/maximum satisfying a condition</p></li><li><p>Peak finding problems</p></li></ul><h3>Template</h3><pre><code>// Standard binary search
int left = 0, right = n - 1;
while (left &lt;= right) {
    int mid = left + (right - left) / 2;
    if (nums[mid] == target) return mid;
    else if (nums[mid] &lt; target) left = mid + 1;
    else right = mid - 1;
}

// Find first occurrence
while (left &lt; right) {
    int mid = left + (right - left) / 2;
    if (condition(mid)) right = mid;
    else left = mid + 1;
}</code></pre><h3>Sample Problem</h3><p><strong>Search in Rotated Sorted Array</strong>: Search for a target in a rotated sorted array.</p><h4>Example:</h4><ul><li><p><strong>Input:</strong> <code>nums = [4, 5, 6, 7, 0, 1, 2]</code>, <code>target = 0</code></p></li><li><p><strong>Output:</strong> <code>4</code></p></li></ul><h4>Step-by-Step Walkthrough:</h4><pre><code>nums = [4, 5, 6, 7, 0, 1, 2], target = 0

Step 1: left = 0, right = 6, mid = 3
  nums[mid] = 7 != 0
  nums[left] = 4 &lt;= nums[mid] = 7 (left half sorted)
  target = 0 not in [4, 7), search right
  left = 4

Step 2: left = 4, right = 6, mid = 5
  nums[mid] = 1 != 0
  nums[left] = 0 &lt;= nums[mid] = 1 (left half sorted)
  target = 0 in [0, 1), search left
  right = 4

Step 3: left = 4, right = 4, mid = 4
  nums[mid] = 0 == target
  Found at index 4!</code></pre><h3>Practice Problems</h3><ol><li><p><a href="https://leetcode.com/problems/search-in-rotated-sorted-array/">Search in Rotated Sorted Array (LeetCode #33)</a></p></li><li><p><a href="https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/">Find Minimum in Rotated Sorted Array (LeetCode #153)</a></p></li><li><p><a href="https://leetcode.com/problems/search-a-2d-matrix/">Search a 2D Matrix (LeetCode #74)</a></p></li><li><p><a href="https://leetcode.com/problems/find-peak-element/">Find Peak Element (LeetCode #162)</a></p></li><li><p><a href="https://leetcode.com/problems/first-bad-version/">First Bad Version (LeetCode #278)</a></p></li></ol><div><hr></div><h1>12. <a href="https://algomaster.io/learn/dsa/binary-tree-introduction">Binary Tree Traversal</a></h1><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!_qae!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7927d4e-fcac-45c3-8c3a-307ec13b8a6b_486x286.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!_qae!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7927d4e-fcac-45c3-8c3a-307ec13b8a6b_486x286.png 424w, https://substackcdn.com/image/fetch/$s_!_qae!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7927d4e-fcac-45c3-8c3a-307ec13b8a6b_486x286.png 848w, https://substackcdn.com/image/fetch/$s_!_qae!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7927d4e-fcac-45c3-8c3a-307ec13b8a6b_486x286.png 1272w, https://substackcdn.com/image/fetch/$s_!_qae!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7927d4e-fcac-45c3-8c3a-307ec13b8a6b_486x286.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!_qae!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7927d4e-fcac-45c3-8c3a-307ec13b8a6b_486x286.png" width="486" height="286" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c7927d4e-fcac-45c3-8c3a-307ec13b8a6b_486x286.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:286,&quot;width&quot;:486,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:23436,&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://blog.algomaster.io/i/184854210?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7927d4e-fcac-45c3-8c3a-307ec13b8a6b_486x286.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_!_qae!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7927d4e-fcac-45c3-8c3a-307ec13b8a6b_486x286.png 424w, https://substackcdn.com/image/fetch/$s_!_qae!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7927d4e-fcac-45c3-8c3a-307ec13b8a6b_486x286.png 848w, https://substackcdn.com/image/fetch/$s_!_qae!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7927d4e-fcac-45c3-8c3a-307ec13b8a6b_486x286.png 1272w, https://substackcdn.com/image/fetch/$s_!_qae!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7927d4e-fcac-45c3-8c3a-307ec13b8a6b_486x286.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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>Binary Tree Traversal visits all nodes in a specific order. The three main orders are preorder (root-left-right), inorder (left-root-right), and postorder (left-right-root).</p><h3>When to use</h3><ul><li><p>Processing tree nodes in specific order</p></li><li><p>Building trees from traversals</p></li><li><p>BST operations (inorder gives sorted order)</p></li><li><p>Tree serialization/deserialization</p></li></ul><h3>Template</h3><pre><code>// Preorder (Root -&gt; Left -&gt; Right)
void preorder(TreeNode node) {
    if (node == null) return;
    process(node);        // visit root
    preorder(node.left);  // left subtree
    preorder(node.right); // right subtree
}

// Inorder (Left -&gt; Root -&gt; Right)
void inorder(TreeNode node) {
    if (node == null) return;
    inorder(node.left);   // left subtree
    process(node);        // visit root
    inorder(node.right);  // right subtree
}

// Postorder (Left -&gt; Right -&gt; Root)
void postorder(TreeNode node) {
    if (node == null) return;
    postorder(node.left);  // left subtree
    postorder(node.right); // right subtree
    process(node);         // visit root
}</code></pre><h3>Sample Problem</h3><p><strong>Inorder Traversal</strong>: Return the inorder traversal of a binary tree.</p><h4>Example:</h4><ul><li><p><strong>Input:</strong> Tree with root = <code>[1, null, 2, 3]</code></p></li><li><p><strong>Output:</strong> <code>[1, 3, 2]</code></p></li></ul><h4>Step-by-Step Walkthrough:</h4><pre><code>Tree:
    1
     \
      2
     /
    3

Inorder: Left -&gt; Root -&gt; Right

Step 1: Start at 1
  No left child, visit 1
  result = [1]

Step 2: Go to right child 2
  Has left child 3, go left

Step 3: At node 3
  No left child, visit 3
  result = [1, 3]
  No right child, backtrack

Step 4: Back at node 2
  Left done, visit 2
  result = [1, 3, 2]
  No right child

Done: [1, 3, 2]</code></pre><h3>Practice Problems</h3><ol><li><p><a href="https://leetcode.com/problems/binary-tree-inorder-traversal/">Binary Tree Inorder Traversal (LeetCode #94)</a></p></li><li><p><a href="https://leetcode.com/problems/binary-tree-preorder-traversal/">Binary Tree Preorder Traversal (LeetCode #144)</a></p></li><li><p><a href="https://leetcode.com/problems/binary-tree-postorder-traversal/">Binary Tree Postorder Traversal (LeetCode #145)</a></p></li><li><p><a href="https://leetcode.com/problems/kth-smallest-element-in-a-bst/">Kth Smallest Element in a BST (LeetCode #230)</a></p></li><li><p><a href="https://leetcode.com/problems/validate-binary-search-tree/">Validate Binary Search Tree (LeetCode #98)</a></p></li></ol><div><hr></div><h1>13. <a href="https://algomaster.io/learn/dsa/dfs-introduction">Depth-First Search (DFS)</a></h1><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!FxC4!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5add8c70-dc33-4e4c-9602-af8ecdc9da23_571x261.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!FxC4!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5add8c70-dc33-4e4c-9602-af8ecdc9da23_571x261.png 424w, https://substackcdn.com/image/fetch/$s_!FxC4!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5add8c70-dc33-4e4c-9602-af8ecdc9da23_571x261.png 848w, https://substackcdn.com/image/fetch/$s_!FxC4!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5add8c70-dc33-4e4c-9602-af8ecdc9da23_571x261.png 1272w, https://substackcdn.com/image/fetch/$s_!FxC4!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5add8c70-dc33-4e4c-9602-af8ecdc9da23_571x261.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!FxC4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5add8c70-dc33-4e4c-9602-af8ecdc9da23_571x261.png" width="571" height="261" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5add8c70-dc33-4e4c-9602-af8ecdc9da23_571x261.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:261,&quot;width&quot;:571,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:24287,&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://blog.algomaster.io/i/184854210?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5add8c70-dc33-4e4c-9602-af8ecdc9da23_571x261.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_!FxC4!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5add8c70-dc33-4e4c-9602-af8ecdc9da23_571x261.png 424w, https://substackcdn.com/image/fetch/$s_!FxC4!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5add8c70-dc33-4e4c-9602-af8ecdc9da23_571x261.png 848w, https://substackcdn.com/image/fetch/$s_!FxC4!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5add8c70-dc33-4e4c-9602-af8ecdc9da23_571x261.png 1272w, https://substackcdn.com/image/fetch/$s_!FxC4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5add8c70-dc33-4e4c-9602-af8ecdc9da23_571x261.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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>DFS explores as deep as possible along each branch before backtracking. It uses a stack (or recursion) to remember which nodes to visit next.</p><h3>When to use</h3><ul><li><p>Exploring all paths in a tree/graph</p></li><li><p>Finding connected components</p></li><li><p>Detecting cycles</p></li><li><p>Topological sorting</p></li><li><p>Path finding when all paths matter</p></li></ul><h3>Template</h3><pre><code>// DFS on a graph - visited tracking required
void dfs(int node, boolean[] visited, List&lt;List&lt;Integer&gt;&gt; graph) {
    visited[node] = true;

    // Process current node
    process(node);

    // Explore unvisited neighbors
    for (int neighbor : graph.get(node)) {
        if (!visited[neighbor]) {
            dfs(neighbor, visited, graph);
        }
    }
}</code></pre><h3>Sample Problem</h3><p><strong>Path Sum</strong>: Determine if the tree has a root-to-leaf path where values sum to a target.</p><h4>Example:</h4><ul><li><p><strong>Input:</strong> <code>root = [5, 4, 8, 11, null, 13, 4, 7, 2]</code>, <code>targetSum = 22</code></p></li><li><p><strong>Output:</strong> <code>true</code> (path: 5 -&gt; 4 -&gt; 11 -&gt; 2)</p></li></ul><h4>Step-by-Step Walkthrough:</h4><pre><code>Tree:
        5
       / \
      4   8
     /   / \
    11  13  4
   /  \      \
  7    2      1

Target = 22

DFS Path 1: 5 -&gt; 4 -&gt; 11 -&gt; 7
  Sum = 5 + 4 + 11 + 7 = 27 != 22

DFS Path 2: 5 -&gt; 4 -&gt; 11 -&gt; 2
  Sum = 5 + 4 + 11 + 2 = 22 == target
  Found! Return true</code></pre><h3>Practice Problems</h3><ol><li><p><a href="https://leetcode.com/problems/path-sum/">Path Sum (LeetCode #112)</a></p></li><li><p><a href="https://leetcode.com/problems/path-sum-ii/">Path Sum II (LeetCode #113)</a></p></li><li><p><a href="https://leetcode.com/problems/clone-graph/">Clone Graph (LeetCode #133)</a></p></li><li><p><a href="https://leetcode.com/problems/course-schedule-ii/">Course Schedule II (LeetCode #210)</a></p></li><li><p><a href="https://leetcode.com/problems/number-of-islands/">Number of Islands (LeetCode #200)</a></p></li></ol><div><hr></div><h1>14. <a href="https://algomaster.io/learn/dsa/bfs-introduction">Breadth-First Search (BFS)</a></h1><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!_Cko!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69138cfe-fa0e-4ec2-89fd-267b379ee583_517x220.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!_Cko!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69138cfe-fa0e-4ec2-89fd-267b379ee583_517x220.png 424w, https://substackcdn.com/image/fetch/$s_!_Cko!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69138cfe-fa0e-4ec2-89fd-267b379ee583_517x220.png 848w, https://substackcdn.com/image/fetch/$s_!_Cko!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69138cfe-fa0e-4ec2-89fd-267b379ee583_517x220.png 1272w, https://substackcdn.com/image/fetch/$s_!_Cko!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69138cfe-fa0e-4ec2-89fd-267b379ee583_517x220.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!_Cko!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69138cfe-fa0e-4ec2-89fd-267b379ee583_517x220.png" width="517" height="220" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/69138cfe-fa0e-4ec2-89fd-267b379ee583_517x220.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:220,&quot;width&quot;:517,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:18298,&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://blog.algomaster.io/i/184854210?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69138cfe-fa0e-4ec2-89fd-267b379ee583_517x220.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_!_Cko!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69138cfe-fa0e-4ec2-89fd-267b379ee583_517x220.png 424w, https://substackcdn.com/image/fetch/$s_!_Cko!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69138cfe-fa0e-4ec2-89fd-267b379ee583_517x220.png 848w, https://substackcdn.com/image/fetch/$s_!_Cko!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69138cfe-fa0e-4ec2-89fd-267b379ee583_517x220.png 1272w, https://substackcdn.com/image/fetch/$s_!_Cko!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69138cfe-fa0e-4ec2-89fd-267b379ee583_517x220.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>BFS explores nodes level by level, visiting all neighbors before moving deeper. It uses a queue and guarantees the shortest path in unweighted graphs.</p><h3>When to use</h3><ul><li><p>Finding shortest path (unweighted)</p></li><li><p>Level-order traversal</p></li><li><p>Finding all nodes at distance k</p></li><li><p>Spreading problems (rotting oranges, walls and gates)</p></li></ul><h3>Template</h3><pre><code>public void bfs(Node start) {
    // Handle edge case
    if (start == null) return;

    // Initialize queue and visited set
    Queue&lt;Node&gt; queue = new LinkedList&lt;&gt;();
    Set&lt;Node&gt; visited = new HashSet&lt;&gt;();

    // Add starting node
    queue.offer(start);
    visited.add(start);

    // Process nodes level by level
    while (!queue.isEmpty()) {
        Node current = queue.poll();

        // Process the current node
        process(current);

        // Add unvisited neighbors to queue
        for (Node neighbor : current.getNeighbors()) {
            if (!visited.contains(neighbor)) {
                visited.add(neighbor);
                queue.offer(neighbor);
            }
        }
    }
}</code></pre><h3>Sample Problem</h3><p><strong>Level Order Traversal</strong>: Return the level order traversal of a binary tree.</p><h4>Example:</h4><ul><li><p><strong>Input:</strong> <code>root = [3, 9, 20, null, null, 15, 7]</code></p></li><li><p><strong>Output:</strong> <code>[[3], [9, 20], [15, 7]]</code></p></li></ul><h4>Step-by-Step Walkthrough:</h4><pre><code>Tree:
    3
   / \
  9  20
    /  \
   15   7

Step 1: Level 0
  queue = [3]
  Process 3, add children 9, 20
  result = [[3]]

Step 2: Level 1
  queue = [9, 20]
  Process 9 (no children)
  Process 20, add children 15, 7
  result = [[3], [9, 20]]

Step 3: Level 2
  queue = [15, 7]
  Process 15 (no children)
  Process 7 (no children)
  result = [[3], [9, 20], [15, 7]]</code></pre><h3>Practice Problems</h3><ol><li><p><a href="https://leetcode.com/problems/binary-tree-level-order-traversal/">Binary Tree Level Order Traversal (LeetCode #102)</a></p></li><li><p><a href="https://leetcode.com/problems/rotting-oranges/">Rotting Oranges (LeetCode #994)</a></p></li><li><p><a href="https://leetcode.com/problems/word-ladder/">Word Ladder (LeetCode #127)</a></p></li><li><p><a href="https://leetcode.com/problems/minimum-depth-of-binary-tree/">Minimum Depth of Binary Tree (LeetCode #111)</a></p></li><li><p><a href="https://leetcode.com/problems/walls-and-gates/">Walls and Gates (LeetCode #286)</a></p></li></ol><div><hr></div><h1>15. <a href="https://algomaster.io/learn/dsa/shortest-path-introduction">Shortest Path</a></h1><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!KkhG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bd0bf6c-627d-4962-b946-d008527e4e85_554x242.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!KkhG!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bd0bf6c-627d-4962-b946-d008527e4e85_554x242.png 424w, https://substackcdn.com/image/fetch/$s_!KkhG!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bd0bf6c-627d-4962-b946-d008527e4e85_554x242.png 848w, https://substackcdn.com/image/fetch/$s_!KkhG!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bd0bf6c-627d-4962-b946-d008527e4e85_554x242.png 1272w, https://substackcdn.com/image/fetch/$s_!KkhG!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bd0bf6c-627d-4962-b946-d008527e4e85_554x242.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!KkhG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bd0bf6c-627d-4962-b946-d008527e4e85_554x242.png" width="554" height="242" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7bd0bf6c-627d-4962-b946-d008527e4e85_554x242.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:242,&quot;width&quot;:554,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:22883,&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://blog.algomaster.io/i/184854210?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bd0bf6c-627d-4962-b946-d008527e4e85_554x242.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_!KkhG!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bd0bf6c-627d-4962-b946-d008527e4e85_554x242.png 424w, https://substackcdn.com/image/fetch/$s_!KkhG!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bd0bf6c-627d-4962-b946-d008527e4e85_554x242.png 848w, https://substackcdn.com/image/fetch/$s_!KkhG!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bd0bf6c-627d-4962-b946-d008527e4e85_554x242.png 1272w, https://substackcdn.com/image/fetch/$s_!KkhG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bd0bf6c-627d-4962-b946-d008527e4e85_554x242.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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>Shortest path algorithms find the minimum distance between nodes. Dijkstra&#8217;s works for weighted graphs with non-negative weights, while Bellman-Ford handles negative weights.</p><h3>When to use</h3><ul><li><p>Finding minimum cost/distance paths</p></li><li><p>Network routing problems</p></li><li><p>Weighted graph traversal</p></li><li><p>Problems with varying edge costs</p></li></ul><h3>Template</h3><pre><code>// Dijkstra's Algorithm using Priority Queue
int[] dist = new int[n];
Arrays.fill(dist, Integer.MAX_VALUE);
dist[source] = 0;

// PQ: (distance, node)
PriorityQueue&lt;int[]&gt; pq = new PriorityQueue&lt;&gt;((a, b) -&gt; a[0] - b[0]);
pq.offer(new int[]{0, source});

while (!pq.isEmpty()) {
    int[] curr = pq.poll();
    int d = curr[0], node = curr[1];

    if (d &gt; dist[node]) continue; // already processed

    for (int[] edge : graph.get(node)) {
        int neighbor = edge[0], weight = edge[1];
        int newDist = dist[node] + weight;

        if (newDist &lt; dist[neighbor]) {
            dist[neighbor] = newDist;
            pq.offer(new int[]{newDist, neighbor});
        }
    }
}</code></pre><h3>Sample Problem</h3><p><strong>Network Delay Time</strong>: Find the time it takes for a signal to reach all nodes from a source node.</p><h4>Example:</h4><ul><li><p><strong>Input:</strong> <code>times = [[2,1,1], [2,3,1], [3,4,1]]</code>, <code>n = 4</code>, <code>k = 2</code></p></li><li><p><strong>Output:</strong> <code>2</code></p></li></ul><h4>Step-by-Step Walkthrough:</h4><pre><code>Graph: 2 --(1)--&gt; 1
       2 --(1)--&gt; 3 --(1)--&gt; 4
Source: node 2

Initial: dist = [INF, INF, 0, INF, INF] (1-indexed)
         pq = [(0, 2)]

Step 1: Process (0, 2)
  Neighbor 1: dist[1] = 0 + 1 = 1
  Neighbor 3: dist[3] = 0 + 1 = 1
  pq = [(1, 1), (1, 3)]

Step 2: Process (1, 1)
  No outgoing edges
  pq = [(1, 3)]

Step 3: Process (1, 3)
  Neighbor 4: dist[4] = 1 + 1 = 2
  pq = [(2, 4)]

Step 4: Process (2, 4)
  No outgoing edges

dist = [INF, 1, 0, 1, 2]
Max distance = 2</code></pre><h3>Practice Problems</h3><ol><li><p><a href="https://leetcode.com/problems/network-delay-time/">Network Delay Time (LeetCode #743)</a></p></li><li><p><a href="https://leetcode.com/problems/cheapest-flights-within-k-stops/">Cheapest Flights Within K Stops (LeetCode #787)</a></p></li><li><p><a href="https://leetcode.com/problems/path-with-maximum-probability/">Path with Maximum Probability (LeetCode #1514)</a></p></li><li><p><a href="https://leetcode.com/problems/swim-in-rising-water/">Swim in Rising Water (LeetCode #778)</a></p></li><li><p><a href="https://leetcode.com/problems/path-with-minimum-effort/">Path with Minimum Effort (LeetCode #1631)</a></p></li></ol><div><hr></div><h2>16. <a href="https://algomaster.io/learn/dsa/matrix-traversal-introduction">Matrix Traversal</a></h2><p>Matrix traversal uses DFS or BFS to explore 2D grids. The key is handling 4-directional (or 8-directional) movement and boundary checks.</p><h3>When to use</h3><ul><li><p>Grid-based problems (islands, regions)</p></li><li><p>Flood fill algorithms</p></li><li><p>Finding connected components in 2D</p></li><li><p>Path finding in mazes</p></li></ul><h3>Template</h3><pre><code>// Direction arrays for 4 directions
int[] dx = {0, 0, 1, -1};
int[] dy = {1, -1, 0, 0};

// DFS on matrix
void dfs(int[][] grid, int i, int j, boolean[][] visited) {
    int m = grid.length, n = grid[0].length;

    // boundary and validity check
    if (i &lt; 0 || i &gt;= m || j &lt; 0 || j &gt;= n) return;
    if (visited[i][j] || grid[i][j] == 0) return;

    visited[i][j] = true;
    // process cell

    // explore 4 directions
    for (int d = 0; d &lt; 4; d++) {
        dfs(grid, i + dx[d], j + dy[d], visited);
    }
}

// BFS on matrix
Queue&lt;int[]&gt; queue = new LinkedList&lt;&gt;();
queue.offer(new int[]{startRow, startCol});
visited[startRow][startCol] = true;

while (!queue.isEmpty()) {
    int[] cell = queue.poll();
    int i = cell[0], j = cell[1];

    for (int d = 0; d &lt; 4; d++) {
        int ni = i + dx[d], nj = j + dy[d];
        if (ni &gt;= 0 &amp;&amp; ni &lt; m &amp;&amp; nj &gt;= 0 &amp;&amp; nj &lt; n
            &amp;&amp; !visited[ni][nj] &amp;&amp; grid[ni][nj] == 1) {
            visited[ni][nj] = true;
            queue.offer(new int[]{ni, nj});
        }
    }
}</code></pre><h3>Sample Problem</h3><p><strong>Number of Islands</strong>: Count the number of islands (connected 1s) in a 2D grid.</p><h4>Example:</h4><ul><li><p><strong>Input:</strong></p></li></ul><pre><code>grid = [
  ["1","1","0","0","0"],
  ["1","1","0","0","0"],
  ["0","0","1","0","0"],
  ["0","0","0","1","1"]
]</code></pre><ul><li><p><strong>Output:</strong> 3</p></li></ul><h4>Step-by-Step Walkthrough:</h4><pre><code>Grid:
1 1 0 0 0
1 1 0 0 0
0 0 1 0 0
0 0 0 1 1

Step 1: Find '1' at (0,0)
  DFS marks connected cells: (0,0), (0,1), (1,0), (1,1)
  islands = 1

Step 2: Find '1' at (2,2)
  DFS marks: (2,2)
  islands = 2

Step 3: Find '1' at (3,3)
  DFS marks connected cells: (3,3), (3,4)
  islands = 3

Result: 3 islands</code></pre><h3>Practice Problems</h3><ol><li><p><a href="https://leetcode.com/problems/number-of-islands/">Number of Islands (LeetCode #200)</a></p></li><li><p><a href="https://leetcode.com/problems/flood-fill/">Flood Fill (LeetCode #733)</a></p></li><li><p><a href="https://leetcode.com/problems/surrounded-regions/">Surrounded Regions (LeetCode #130)</a></p></li><li><p><a href="https://leetcode.com/problems/max-area-of-island/">Max Area of Island (LeetCode #695)</a></p></li><li><p><a href="https://leetcode.com/problems/pacific-atlantic-water-flow/">Pacific Atlantic Water Flow (LeetCode #417)</a></p></li></ol><div><hr></div><h1>17. <a href="https://algomaster.io/learn/dsa/backtracking-introduction">Backtracking</a></h1><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!-6zJ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fd3635f-16e8-4c98-b72f-b94a38cddc67_490x382.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!-6zJ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fd3635f-16e8-4c98-b72f-b94a38cddc67_490x382.png 424w, https://substackcdn.com/image/fetch/$s_!-6zJ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fd3635f-16e8-4c98-b72f-b94a38cddc67_490x382.png 848w, https://substackcdn.com/image/fetch/$s_!-6zJ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fd3635f-16e8-4c98-b72f-b94a38cddc67_490x382.png 1272w, https://substackcdn.com/image/fetch/$s_!-6zJ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fd3635f-16e8-4c98-b72f-b94a38cddc67_490x382.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!-6zJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fd3635f-16e8-4c98-b72f-b94a38cddc67_490x382.png" width="490" height="382" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6fd3635f-16e8-4c98-b72f-b94a38cddc67_490x382.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:382,&quot;width&quot;:490,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:24943,&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://blog.algomaster.io/i/184854210?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fd3635f-16e8-4c98-b72f-b94a38cddc67_490x382.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_!-6zJ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fd3635f-16e8-4c98-b72f-b94a38cddc67_490x382.png 424w, https://substackcdn.com/image/fetch/$s_!-6zJ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fd3635f-16e8-4c98-b72f-b94a38cddc67_490x382.png 848w, https://substackcdn.com/image/fetch/$s_!-6zJ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fd3635f-16e8-4c98-b72f-b94a38cddc67_490x382.png 1272w, https://substackcdn.com/image/fetch/$s_!-6zJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fd3635f-16e8-4c98-b72f-b94a38cddc67_490x382.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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>Backtracking explores all possible solutions by making choices, and undoes (backtracks) when a path leads to an invalid solution. It builds solutions incrementally.</p><h3>When to use</h3><ul><li><p>Generating all permutations/combinations/subsets</p></li><li><p>Solving constraint satisfaction problems (N-Queens, Sudoku)</p></li><li><p>Finding all paths meeting certain criteria</p></li><li><p>String partitioning problems</p></li></ul><h3>Template</h3><pre><code>public void backtrack(State state, Choices choices, Results results) {
    // Base case: Is this a complete solution?
    if (isComplete(state)) {
        results.add(copy(state));  // Store the solution
        return;
    }

    // Recursive case: Try each available choice
    for (Choice choice : getAvailableChoices(state, choices)) {
        // 1. CHOOSE: Make the choice
        makeChoice(state, choice);

        // 2. EXPLORE: Recursively explore with this choice
        backtrack(state, choices, results);

        // 3. UNCHOOSE: Undo the choice (backtrack)
        undoChoice(state, choice);
    }
}</code></pre><h3>Sample Problem</h3><p><strong>Subsets</strong>: Generate all possible subsets of an array.</p><h4>Example:</h4><ul><li><p><strong>Input:</strong> nums = [1, 2, 3]</p></li><li><p><strong>Output:</strong> [[], [1], [1,2], [1,2,3], [1,3], [2], [2,3], [3]]</p></li></ul><h4>Step-by-Step Walkthrough:</h4><pre><code>nums = [1, 2, 3]

backtrack([], start=0)
  add [] to result

  i=0: choose 1 -&gt; [1]
    backtrack([1], start=1)
      add [1] to result

      i=1: choose 2 -&gt; [1,2]
        backtrack([1,2], start=2)
          add [1,2] to result

          i=2: choose 3 -&gt; [1,2,3]
            backtrack([1,2,3], start=3)
              add [1,2,3] to result
            unchoose 3 -&gt; [1,2]
        unchoose 2 -&gt; [1]

      i=2: choose 3 -&gt; [1,3]
        backtrack([1,3], start=3)
          add [1,3] to result
        unchoose 3 -&gt; [1]
    unchoose 1 -&gt; []

  i=1: choose 2 -&gt; [2]
    ...similar process

Result: [[], [1], [1,2], [1,2,3], [1,3], [2], [2,3], [3]]</code></pre><h3>Practice Problems</h3><ol><li><p><a href="https://leetcode.com/problems/subsets/">Subsets (LeetCode #78)</a></p></li><li><p><a href="https://leetcode.com/problems/permutations/">Permutations (LeetCode #46)</a></p></li><li><p><a href="https://leetcode.com/problems/combination-sum/">Combination Sum (LeetCode #39)</a></p></li><li><p><a href="https://leetcode.com/problems/n-queens/">N-Queens (LeetCode #51)</a></p></li><li><p><a href="https://leetcode.com/problems/word-search/">Word Search (LeetCode #79)</a></p></li></ol><div><hr></div><h1>18. <a href="https://algomaster.io/learn/dsa/tries-introduction">Prefix Search (Trie)</a></h1><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!lhl0!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbdefbf9-7457-4203-bd82-a5e876c4e9fd_431x341.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!lhl0!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbdefbf9-7457-4203-bd82-a5e876c4e9fd_431x341.png 424w, https://substackcdn.com/image/fetch/$s_!lhl0!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbdefbf9-7457-4203-bd82-a5e876c4e9fd_431x341.png 848w, https://substackcdn.com/image/fetch/$s_!lhl0!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbdefbf9-7457-4203-bd82-a5e876c4e9fd_431x341.png 1272w, https://substackcdn.com/image/fetch/$s_!lhl0!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbdefbf9-7457-4203-bd82-a5e876c4e9fd_431x341.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!lhl0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbdefbf9-7457-4203-bd82-a5e876c4e9fd_431x341.png" width="431" height="341" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bbdefbf9-7457-4203-bd82-a5e876c4e9fd_431x341.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:341,&quot;width&quot;:431,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:28661,&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://blog.algomaster.io/i/184854210?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbdefbf9-7457-4203-bd82-a5e876c4e9fd_431x341.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_!lhl0!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbdefbf9-7457-4203-bd82-a5e876c4e9fd_431x341.png 424w, https://substackcdn.com/image/fetch/$s_!lhl0!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbdefbf9-7457-4203-bd82-a5e876c4e9fd_431x341.png 848w, https://substackcdn.com/image/fetch/$s_!lhl0!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbdefbf9-7457-4203-bd82-a5e876c4e9fd_431x341.png 1272w, https://substackcdn.com/image/fetch/$s_!lhl0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbdefbf9-7457-4203-bd82-a5e876c4e9fd_431x341.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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 Trie (prefix tree) stores strings character by character, allowing efficient prefix lookups. Each node represents a character, and paths from root to nodes represent prefixes.</p><h3>When to use</h3><ul><li><p>Autocomplete and search suggestions</p></li><li><p>Spell checking</p></li><li><p>IP routing (longest prefix match)</p></li><li><p>Word games (finding valid words)</p></li></ul><h3>Template</h3><pre><code>class TrieNode {
    TrieNode[] children = new TrieNode[26];
    boolean isEndOfWord = false;
}

class Trie {
    TrieNode root = new TrieNode();

    void insert(String word) {
        TrieNode node = root;
        for (char c : word.toCharArray()) {
            int idx = c - 'a';
            if (node.children[idx] == null) {
                node.children[idx] = new TrieNode();
            }
            node = node.children[idx];
        }
        node.isEndOfWord = true;
    }

    boolean search(String word) {
        TrieNode node = searchPrefix(word);
        return node != null &amp;&amp; node.isEndOfWord;
    }

    boolean startsWith(String prefix) {
        return searchPrefix(prefix) != null;
    }

    private TrieNode searchPrefix(String prefix) {
        TrieNode node = root;
        for (char c : prefix.toCharArray()) {
            int idx = c - 'a';
            if (node.children[idx] == null) return null;
            node = node.children[idx];
        }
        return node;
    }
}</code></pre><h3>Sample Problem</h3><p><strong>Implement Trie</strong>: Implement a trie with insert, search, and startsWith methods.</p><h4>Example:</h4><pre><code>Trie trie = new Trie();
trie.insert("apple");
trie.search("apple");   // returns true
trie.search("app");     // returns false
trie.startsWith("app"); // returns true</code></pre><h4>Step-by-Step Walkthrough:</h4><pre><code>Insert "apple":

  root
   |
   a (idx=0)
   |
   p (idx=15)
   |
   p (idx=15)
   |
   l (idx=11)
   |
   e (idx=4, isEndOfWord=true)

Search "apple":
  Traverse: a -&gt; p -&gt; p -&gt; l -&gt; e
  Node exists and isEndOfWord = true
  Return true

Search "app":
  Traverse: a -&gt; p -&gt; p
  Node exists but isEndOfWord = false
  Return false

StartsWith "app":
  Traverse: a -&gt; p -&gt; p
  Node exists (prefix found)
  Return true</code></pre><h3>Practice Problems</h3><ol><li><p><a href="https://leetcode.com/problems/implement-trie-prefix-tree/">Implement Trie (LeetCode #208)</a></p></li><li><p><a href="https://leetcode.com/problems/word-search-ii/">Word Search II (LeetCode #212)</a></p></li><li><p><a href="https://leetcode.com/problems/design-add-and-search-words-data-structure/">Design Add and Search Words Data Structure (LeetCode #211)</a></p></li><li><p><a href="https://leetcode.com/problems/replace-words/">Replace Words (LeetCode #648)</a></p></li><li><p><a href="https://leetcode.com/problems/longest-word-in-dictionary/">Longest Word in Dictionary (LeetCode #720)</a></p></li></ol><div><hr></div><h1>19. <a href="https://algomaster.io/learn/dsa/greedy-introduction">Greedy</a></h1><p>Greedy algorithms make locally optimal choices at each step, hoping to find a global optimum. They work when local optimal choices lead to global optimal solutions.</p><h3>When to use</h3><ul><li><p>Optimization problems with greedy choice property</p></li><li><p>Interval scheduling</p></li><li><p>Huffman coding</p></li><li><p>Activity selection</p></li><li><p>When proof by exchange argument works</p></li></ul><h3>Template</h3><pre><code>public Result solveGreedy(Input input) {
    // Step 1: Sort or organize input (if needed)
    sort(input, byGreedyCriterion);

    // Step 2: Initialize result and tracking variables
    Result result = initialResult();
    State state = initialState();

    // Step 3: Iterate and make greedy choices
    for (Element element : input) {
        if (canInclude(element, state)) {
            // Make the greedy choice
            result = update(result, element);
            state = updateState(state, element);
        }
    }

    return result;
}</code></pre><h3>Sample Problem</h3><p><strong>Jump Game</strong>: Determine if you can reach the last index starting from index 0.</p><h4>Example:</h4><ul><li><p><strong>Input:</strong> nums = [2, 3, 1, 1, 4]</p></li><li><p><strong>Output:</strong> true</p></li></ul><h4>Step-by-Step Walkthrough:</h4><pre><code>nums = [2, 3, 1, 1, 4]

Track maxReach (farthest index we can reach)

Step 1: i = 0, nums[0] = 2
  maxReach = max(0, 0 + 2) = 2

Step 2: i = 1, nums[1] = 3
  i &lt;= maxReach (1 &lt;= 2)
  maxReach = max(2, 1 + 3) = 4

Step 3: i = 2, nums[2] = 1
  i &lt;= maxReach (2 &lt;= 4)
  maxReach = max(4, 2 + 1) = 4

Step 4: i = 3, nums[3] = 1
  i &lt;= maxReach (3 &lt;= 4)
  maxReach = max(4, 3 + 1) = 4

maxReach = 4 &gt;= last index (4)
Return true</code></pre><h3>Practice Problems</h3><ol><li><p><a href="https://leetcode.com/problems/jump-game/">Jump Game (LeetCode #55)</a></p></li><li><p><a href="https://leetcode.com/problems/jump-game-ii/">Jump Game II (LeetCode #45)</a></p></li><li><p><a href="https://leetcode.com/problems/gas-station/">Gas Station (LeetCode #134)</a></p></li><li><p><a href="https://leetcode.com/problems/task-scheduler/">Task Scheduler (LeetCode #621)</a></p></li><li><p><a href="https://leetcode.com/problems/partition-labels/">Partition Labels (LeetCode #763)</a></p></li></ol><div><hr></div><h1>20. <a href="https://blog.algomaster.io/p/20-patterns-to-master-dynamic-programming">Dynamic Programming Patterns</a></h1><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!he5Z!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72238d31-04bf-4e98-9c8f-fe05a663ecf6_430x315.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!he5Z!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72238d31-04bf-4e98-9c8f-fe05a663ecf6_430x315.png 424w, https://substackcdn.com/image/fetch/$s_!he5Z!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72238d31-04bf-4e98-9c8f-fe05a663ecf6_430x315.png 848w, https://substackcdn.com/image/fetch/$s_!he5Z!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72238d31-04bf-4e98-9c8f-fe05a663ecf6_430x315.png 1272w, https://substackcdn.com/image/fetch/$s_!he5Z!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72238d31-04bf-4e98-9c8f-fe05a663ecf6_430x315.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!he5Z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72238d31-04bf-4e98-9c8f-fe05a663ecf6_430x315.png" width="430" height="315" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/72238d31-04bf-4e98-9c8f-fe05a663ecf6_430x315.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:315,&quot;width&quot;:430,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:17841,&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://blog.algomaster.io/i/184854210?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72238d31-04bf-4e98-9c8f-fe05a663ecf6_430x315.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_!he5Z!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72238d31-04bf-4e98-9c8f-fe05a663ecf6_430x315.png 424w, https://substackcdn.com/image/fetch/$s_!he5Z!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72238d31-04bf-4e98-9c8f-fe05a663ecf6_430x315.png 848w, https://substackcdn.com/image/fetch/$s_!he5Z!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72238d31-04bf-4e98-9c8f-fe05a663ecf6_430x315.png 1272w, https://substackcdn.com/image/fetch/$s_!he5Z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72238d31-04bf-4e98-9c8f-fe05a663ecf6_430x315.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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>Dynamic Programming (DP) solves problems by breaking them into overlapping subproblems and storing results to avoid recomputation. It works when problems have optimal substructure.</p><h3>When to use</h3><ul><li><p>Problems with overlapping subproblems</p></li><li><p>Optimization (min/max) problems</p></li><li><p>Counting problems (number of ways)</p></li><li><p>Decision problems (can we achieve X?)</p></li></ul><h3>Common DP Patterns</h3><ol><li><p><strong>Fibonacci Pattern</strong> (1D DP with previous states)</p></li><li><p><strong>0/1 Knapsack</strong> (include or exclude each item)</p></li><li><p><strong>Longest Common Subsequence</strong> (2D DP on two sequences)</p></li><li><p><strong>Longest Increasing Subsequence</strong></p></li></ol><p>You can find more DP patterns and how to approach them in <a href="https://blog.algomaster.io/p/20-patterns-to-master-dynamic-programming">this article</a>.</p><h3>Sample Problem</h3><p><strong>Climbing Stairs</strong>: Find the number of ways to climb n stairs, taking 1 or 2 steps at a time.</p><h4>Example:</h4><ul><li><p><strong>Input:</strong> n = 4</p></li><li><p><strong>Output:</strong> 5</p></li></ul><h4>Step-by-Step Walkthrough:</h4><pre><code>n = 4

dp[i] = number of ways to reach step i
dp[i] = dp[i-1] + dp[i-2]
(we can reach step i from step i-1 or step i-2)

Base cases:
  dp[0] = 1 (one way to stay at ground)
  dp[1] = 1 (one way: take 1 step)

Step 2: dp[2] = dp[1] + dp[0] = 1 + 1 = 2
  Ways: [1,1], [2]

Step 3: dp[3] = dp[2] + dp[1] = 2 + 1 = 3
  Ways: [1,1,1], [1,2], [2,1]

Step 4: dp[4] = dp[3] + dp[2] = 3 + 2 = 5
  Ways: [1,1,1,1], [1,1,2], [1,2,1], [2,1,1], [2,2]

Result: 5 ways</code></pre><h3>Practice Problems</h3><ol><li><p><a href="https://leetcode.com/problems/climbing-stairs/">Climbing Stairs (LeetCode #70)</a></p></li><li><p><a href="https://leetcode.com/problems/house-robber/">House Robber (LeetCode #198)</a></p></li><li><p><a href="https://leetcode.com/problems/coin-change/">Coin Change (LeetCode #322)</a></p></li><li><p><a href="https://leetcode.com/problems/longest-common-subsequence/">Longest Common Subsequence (LeetCode #1143)</a></p></li><li><p><a href="https://leetcode.com/problems/longest-increasing-subsequence/">Longest Increasing Subsequence (LeetCode #300)</a></p></li><li><p><a href="https://leetcode.com/problems/partition-equal-subset-sum/">Partition Equal Subset Sum (LeetCode #416)</a></p></li><li><p><a href="https://leetcode.com/problems/edit-distance/">Edit Distance (LeetCode #72)</a></p></li></ol><div><hr></div><p>That&#8217;s it. Thanks for reading!</p><p>I&#8217;ve put together many more patterns and problems on my website. You can explore them here: <a href="https://algomaster.io/">algomaster.io</a></p><p>If this article helped you, give it a like and share it with others.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.algomaster.io/p/20-dsa-patterns?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://blog.algomaster.io/p/20-dsa-patterns?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p>]]></content:encoded></item></channel></rss>