<?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>Thu, 23 Apr 2026 07:33:44 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[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>300,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><item><title><![CDATA[How Git Works Internally]]></title><description><![CDATA[We run git add, git commit, and git push without thinking twice.]]></description><link>https://blog.algomaster.io/p/how-git-works-internally</link><guid isPermaLink="false">https://blog.algomaster.io/p/how-git-works-internally</guid><dc:creator><![CDATA[Ashish Pratap Singh]]></dc:creator><pubDate>Thu, 15 Jan 2026 10:03:30 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!LSMI!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8363fed-dc7e-4f8b-bf3f-756841964c63_685x532.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Most of us treat Git like a black box: memorize a few commands like <strong>git add</strong>, <strong>git commit</strong>, and <strong>git push</strong>, copy-paste the rest, and hope nothing breaks.</p><p>But what actually happens when you run these commands? Where do your files go?How does Git track every change you have ever made without consuming gigabytes of storage?</p><p>Understanding Git&#8217;s internals helps you reason about your changes, debug issues faster, and use Git as the powerful tool it was designed to be.</p><p>In this article, we will explore:</p><ul><li><p>What Git really is under the hood</p></li><li><p>Git&#8217;s object model: blobs, trees, and commits</p></li><li><p>How Git uses SHA-1 hashes to store and address data</p></li><li><p>The three areas: working directory, staging area, and repository</p></li><li><p>How commits, branches, merges and rebases actually work</p></li><li><p>How Git keeps repositories small</p></li></ul><div><hr></div><h1>1. Distributed Version Control</h1><p>Git is a <strong>distributed version control system</strong> created by Linus Torvalds in 2005 for Linux kernel development.</p><p>Older tools like <strong>CVS</strong> and <strong>SVN</strong> use a <strong>centralized</strong> model: one server holds the source of truth, and developers pull from and push to that central 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_!LOgf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62d3037e-264f-4e38-b5b9-9734977409fa_1288x496.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!LOgf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62d3037e-264f-4e38-b5b9-9734977409fa_1288x496.png 424w, https://substackcdn.com/image/fetch/$s_!LOgf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62d3037e-264f-4e38-b5b9-9734977409fa_1288x496.png 848w, https://substackcdn.com/image/fetch/$s_!LOgf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62d3037e-264f-4e38-b5b9-9734977409fa_1288x496.png 1272w, https://substackcdn.com/image/fetch/$s_!LOgf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62d3037e-264f-4e38-b5b9-9734977409fa_1288x496.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!LOgf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62d3037e-264f-4e38-b5b9-9734977409fa_1288x496.png" width="646" height="248.77018633540374" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/62d3037e-264f-4e38-b5b9-9734977409fa_1288x496.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:496,&quot;width&quot;:1288,&quot;resizeWidth&quot;:646,&quot;bytes&quot;:31640,&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/184584683?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62d3037e-264f-4e38-b5b9-9734977409fa_1288x496.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_!LOgf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62d3037e-264f-4e38-b5b9-9734977409fa_1288x496.png 424w, https://substackcdn.com/image/fetch/$s_!LOgf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62d3037e-264f-4e38-b5b9-9734977409fa_1288x496.png 848w, https://substackcdn.com/image/fetch/$s_!LOgf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62d3037e-264f-4e38-b5b9-9734977409fa_1288x496.png 1272w, https://substackcdn.com/image/fetch/$s_!LOgf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62d3037e-264f-4e38-b5b9-9734977409fa_1288x496.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="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>Git flips this model. In Git, <strong>every developer has a full copy of the repository</strong>, including the entire history.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!hrz2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdaeb638-5530-40e5-a8a5-ba7333615c38_1272x808.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!hrz2!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdaeb638-5530-40e5-a8a5-ba7333615c38_1272x808.png 424w, https://substackcdn.com/image/fetch/$s_!hrz2!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdaeb638-5530-40e5-a8a5-ba7333615c38_1272x808.png 848w, https://substackcdn.com/image/fetch/$s_!hrz2!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdaeb638-5530-40e5-a8a5-ba7333615c38_1272x808.png 1272w, https://substackcdn.com/image/fetch/$s_!hrz2!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdaeb638-5530-40e5-a8a5-ba7333615c38_1272x808.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!hrz2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdaeb638-5530-40e5-a8a5-ba7333615c38_1272x808.png" width="614" height="390.02515723270443" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bdaeb638-5530-40e5-a8a5-ba7333615c38_1272x808.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:808,&quot;width&quot;:1272,&quot;resizeWidth&quot;:614,&quot;bytes&quot;:55583,&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/184584683?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdaeb638-5530-40e5-a8a5-ba7333615c38_1272x808.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_!hrz2!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdaeb638-5530-40e5-a8a5-ba7333615c38_1272x808.png 424w, https://substackcdn.com/image/fetch/$s_!hrz2!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdaeb638-5530-40e5-a8a5-ba7333615c38_1272x808.png 848w, https://substackcdn.com/image/fetch/$s_!hrz2!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdaeb638-5530-40e5-a8a5-ba7333615c38_1272x808.png 1272w, https://substackcdn.com/image/fetch/$s_!hrz2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdaeb638-5530-40e5-a8a5-ba7333615c38_1272x808.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="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 distributed setup gives Git a few key advantages:</p><ul><li><p>Work offline with full history</p></li><li><p>No single point of failure</p></li><li><p>Faster operations because most work happens locally</p></li><li><p>Flexible workflows for teams and individuals</p></li></ul><p>But how does Git store the full history without the repo becoming huge? To answer that, you need to understand the <strong>Git&#8217;s data model</strong>.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.algomaster.io/p/how-git-works-internally?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-git-works-internally?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><div><hr></div><h1>2. Git&#8217;s Data Model</h1><p>At its core, Git is a <strong>content-addressable filesystem</strong>. It stores data as <strong>objects</strong>, and each object is identified by a <strong>SHA-1 hash</strong> of its contents.</p><p>When you add a file to Git, it computes a 40-character hexadecimal SHA-1 hash of the file&#8217;s contents. This hash becomes the file&#8217;s unique address in Git&#8217;s database.</p><pre><code><code>File contents: "Hello, World!"
SHA-1 hash:    5dd01c177f5d7d1be5346a5bc18a569a7410c2ef</code></code></pre><p>Same content always produces the same hash. So two files with identical contents (even if they have different names) share the same hash. </p><p>Git stores the content <strong>once</strong> and references it <strong>multiple times</strong>, which helps repositories stay compact even across thousands of commits.</p><p>Git organizes everything into <strong>objects</strong> stored in its database. There are four types of objects, but three are essential for understanding how Git works: <strong>blobs, trees, and commits</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_!oPmT!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab6671e3-08ed-4090-9ea8-ef979856d07f_1662x1594.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!oPmT!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab6671e3-08ed-4090-9ea8-ef979856d07f_1662x1594.png 424w, https://substackcdn.com/image/fetch/$s_!oPmT!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab6671e3-08ed-4090-9ea8-ef979856d07f_1662x1594.png 848w, https://substackcdn.com/image/fetch/$s_!oPmT!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab6671e3-08ed-4090-9ea8-ef979856d07f_1662x1594.png 1272w, https://substackcdn.com/image/fetch/$s_!oPmT!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab6671e3-08ed-4090-9ea8-ef979856d07f_1662x1594.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!oPmT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab6671e3-08ed-4090-9ea8-ef979856d07f_1662x1594.png" width="622" height="596.3681318681319" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ab6671e3-08ed-4090-9ea8-ef979856d07f_1662x1594.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1396,&quot;width&quot;:1456,&quot;resizeWidth&quot;:622,&quot;bytes&quot;:108013,&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/184584683?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab6671e3-08ed-4090-9ea8-ef979856d07f_1662x1594.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_!oPmT!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab6671e3-08ed-4090-9ea8-ef979856d07f_1662x1594.png 424w, https://substackcdn.com/image/fetch/$s_!oPmT!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab6671e3-08ed-4090-9ea8-ef979856d07f_1662x1594.png 848w, https://substackcdn.com/image/fetch/$s_!oPmT!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab6671e3-08ed-4090-9ea8-ef979856d07f_1662x1594.png 1272w, https://substackcdn.com/image/fetch/$s_!oPmT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab6671e3-08ed-4090-9ea8-ef979856d07f_1662x1594.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="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>Blobs: Storing File Contents</h3><p>A <strong>blob</strong> (binary large object) stores the raw contents of a file. Just the contents. No filename, no permissions, no timestamps, no metadata of any kind.</p><p>When you add <code>README.md</code> to Git, it creates a blob containing the file&#8217;s text. That blob has no idea it came from a file called <code>README.md</code>. It is simply a chunk of bytes with a SHA-1 hash computed from those bytes.</p><p><strong>Why separate content from filename?</strong></p><p>If the same config file is copied to three locations, a naive system stores three copies. Git stores <strong>one blob</strong> and references it <strong>three times</strong>, and these storage savings compound across the project&#8217;s history.</p><p>Of course, if blobs do not store filenames, Git still needs a way to represent folder structure. That is the job of <strong>trees</strong>.</p><h3>Trees: Mapping Directory Structure</h3><p>A <strong>tree</strong> represents a <strong>directory</strong>. It contains pointers to blobs (files) and other trees (subdirectories), along with filenames and permissions.</p><pre><code>Tree: 4c5f8a2b9d3e7f1a6b0c8d5e2f9a4b7c3d6e0f1a
&#9500;&#9472;&#9472; README.md      -&gt; blob 5dd01c17...  (100644)
&#9500;&#9472;&#9472; src/           -&gt; tree 8a3b2c1d...
&#9492;&#9472;&#9472; package.json   -&gt; blob 7f2e3d4c...  (100644)</code></pre><p>The tree acts as a directory listing. It says &#8220;there is a file called README.md, and its contents are stored in blob 5dd01c17.&#8221; The blob stores the data; the tree gives it a name and location.</p><p>If you rename a file without changing its contents, Git creates a new tree (with the new filename) pointing to the same blob. The actual file data is not duplicated.</p><p>Now we have blobs for content and trees for structure. But version control needs more: who made changes, when, and why. That is what <strong>commits</strong> provide.</p><h3>Commits: Recording History</h3><p>A <strong>commit</strong> captures a complete snapshot of your project at a specific moment in time. Every commit contains:</p><ul><li><p>A pointer to a tree (the root directory at that moment)</p></li><li><p>Pointers to parent commits (the history leading to this point)</p></li><li><p>Author information (who wrote the changes)</p></li><li><p>Committer information (who applied the changes)</p></li><li><p>Timestamps</p></li><li><p>A commit message explaining the changes</p></li></ul><pre><code>Commit: abc123def456...
  tree:      def456...
  parent:    789012...
  author:    John &lt;john@example.com&gt; 1699900000 +0000
  committer: John &lt;john@example.com&gt; 1699900000 +0000

  Add login feature</code></pre><p>When you run <strong>git commit</strong>, Git creates a new commit object. This commit points to a tree representing your project&#8217;s current state. The parent pointer links back to the previous commit, forming a chain. This chain is your project&#8217;s history.</p><blockquote><p>The <strong>parent pointer</strong> is what makes Git a version control system rather than just a filesystem. By following parent pointers backward, Git can reconstruct any previous state of your project.</p></blockquote><p>The following diagram shows how a complete snapshot looks in Git&#8217;s object model:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!jBfw!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73d2e59f-e15d-4e64-bbdf-c882993c92e5_634x551.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!jBfw!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73d2e59f-e15d-4e64-bbdf-c882993c92e5_634x551.png 424w, https://substackcdn.com/image/fetch/$s_!jBfw!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73d2e59f-e15d-4e64-bbdf-c882993c92e5_634x551.png 848w, https://substackcdn.com/image/fetch/$s_!jBfw!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73d2e59f-e15d-4e64-bbdf-c882993c92e5_634x551.png 1272w, https://substackcdn.com/image/fetch/$s_!jBfw!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73d2e59f-e15d-4e64-bbdf-c882993c92e5_634x551.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!jBfw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73d2e59f-e15d-4e64-bbdf-c882993c92e5_634x551.png" width="606" height="526.6656151419559" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/73d2e59f-e15d-4e64-bbdf-c882993c92e5_634x551.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:551,&quot;width&quot;:634,&quot;resizeWidth&quot;:606,&quot;bytes&quot;:42165,&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/184584683?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73d2e59f-e15d-4e64-bbdf-c882993c92e5_634x551.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_!jBfw!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73d2e59f-e15d-4e64-bbdf-c882993c92e5_634x551.png 424w, https://substackcdn.com/image/fetch/$s_!jBfw!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73d2e59f-e15d-4e64-bbdf-c882993c92e5_634x551.png 848w, https://substackcdn.com/image/fetch/$s_!jBfw!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73d2e59f-e15d-4e64-bbdf-c882993c92e5_634x551.png 1272w, https://substackcdn.com/image/fetch/$s_!jBfw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73d2e59f-e15d-4e64-bbdf-c882993c92e5_634x551.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="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 blobs, trees, and commits, Git has everything it needs to store and track your project. But where do these objects actually live?</p><div><hr></div><h1>3. How Git Stores Objects</h1><p>When you run <strong>git init</strong>, Git creates the <code>.git</code> directory with this structure:</p><pre><code><code>.git/
&#9500;&#9472;&#9472; HEAD              (contains: ref: refs/heads/main)
&#9500;&#9472;&#9472; config            (repository configuration)
&#9500;&#9472;&#9472; description       (used by GitWeb, rarely relevant)
&#9500;&#9472;&#9472; hooks/            (scripts triggered by Git events)
&#9500;&#9472;&#9472; info/             (exclude patterns, other info)
&#9500;&#9472;&#9472; objects/          (the object database, initially empty)
&#9474;   &#9500;&#9472;&#9472; info/
&#9474;   &#9492;&#9472;&#9472; pack/
&#9492;&#9472;&#9472; refs/             (references to commits)
    &#9500;&#9472;&#9472; heads/        (branch pointers, initially empty)
    &#9492;&#9472;&#9472; tags/         (tag pointers)</code></code></pre><p>All Git objects live inside your repository&#8217;s <code>.git/objects</code> directory.</p><p>Git uses a simple organization scheme: the first two characters of an object&#8217;s hash become a subdirectory name, and the remaining 38 characters become the filename.</p><pre><code>.git/objects/
&#9500;&#9472;&#9472; 5d/
&#9474;   &#9492;&#9472;&#9472; d01c177f5d7d1be5346a5bc18a569a7410c2ef  (blob)
&#9500;&#9472;&#9472; 4c/
&#9474;   &#9492;&#9472;&#9472; 5f8a2b9d3e7f1a6b0c8d5e2f9a4b7c3d6e0f1a  (tree)
&#9500;&#9472;&#9472; a1/
&#9474;   &#9492;&#9472;&#9472; b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0  (commit)
&#9492;&#9472;&#9472; ...</code></pre><p>This two-character prefix prevents any single directory from containing too many files, which could slow down filesystem operations.</p><p>Before writing an object to disk, Git also <strong>compresses it with zlib</strong>. A 1MB source file might shrink to ~100KB or less. Combine that with content-addressable deduplication (identical content stored once), and Git repositories stay surprisingly small even with long histories.</p><h3>Inspecting Objects Directly</h3><p>Git provides low-level commands to examine objects. These &#8220;plumbing&#8221; commands reveal what is happening under the hood:</p><pre><code># Determine an object's type (blob, tree, commit, or tag)
git cat-file -t 5dd01c17

# Display an object's contents
git cat-file -p 5dd01c17

# Examine what a commit contains
git cat-file -p HEAD</code></pre><p>Try running <code>git cat-file -p HEAD</code> in a repository. You will see the tree pointer, parent pointer, author information, and commit message. Then run <code>git cat-file -p</code> on that tree hash to see the directory listing.</p><p>Objects explain how Git stores data, but they do not yet explain the day-to-day workflow. When you edit a file, stage it, and commit, you move data through three distinct areas. </p><p>Let&#8217;s look at those next.</p><div><hr></div><h1>4. The Three Areas</h1><p>Git organizes your work into three separate areas. Understanding these areas is the key to understanding why Git commands behave the way they do.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!y_cr!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87fa292d-f91f-4e83-917d-beec9fee1851_668x155.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!y_cr!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87fa292d-f91f-4e83-917d-beec9fee1851_668x155.png 424w, https://substackcdn.com/image/fetch/$s_!y_cr!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87fa292d-f91f-4e83-917d-beec9fee1851_668x155.png 848w, https://substackcdn.com/image/fetch/$s_!y_cr!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87fa292d-f91f-4e83-917d-beec9fee1851_668x155.png 1272w, https://substackcdn.com/image/fetch/$s_!y_cr!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87fa292d-f91f-4e83-917d-beec9fee1851_668x155.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!y_cr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87fa292d-f91f-4e83-917d-beec9fee1851_668x155.png" width="668" height="155" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/87fa292d-f91f-4e83-917d-beec9fee1851_668x155.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:155,&quot;width&quot;:668,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:18748,&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/184584683?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87fa292d-f91f-4e83-917d-beec9fee1851_668x155.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_!y_cr!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87fa292d-f91f-4e83-917d-beec9fee1851_668x155.png 424w, https://substackcdn.com/image/fetch/$s_!y_cr!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87fa292d-f91f-4e83-917d-beec9fee1851_668x155.png 848w, https://substackcdn.com/image/fetch/$s_!y_cr!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87fa292d-f91f-4e83-917d-beec9fee1851_668x155.png 1272w, https://substackcdn.com/image/fetch/$s_!y_cr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87fa292d-f91f-4e83-917d-beec9fee1851_668x155.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><h3>Working Directory: Your Workspace</h3><p>The <strong>working directory</strong> is what you see in your file explorer. These are actual files on your filesystem that you open in your editor, modify, and save.</p><p>The working directory is not Git. It is simply a checkout of one particular version of your project. Git can delete it and recreate it from any commit in seconds.</p><p>This is why you can switch branches instantly, even in large projects. Git is not moving files around; it is regenerating the working directory from its object database.</p><h3>Staging Area: Your Draft</h3><p>The <strong>staging area</strong> (also called the <strong>index</strong>) lives in a single file at <code>.git/index</code>. It represents the exact snapshot of what your <strong>next commit</strong> will contain.</p><p>When you run <code>git add README.md</code>, Git does two things:</p><ol><li><p>Creates a blob object from the file&#8217;s current contents (or reuses an existing blob if the contents match)</p></li><li><p>Updates the index to associate the filename with that blob&#8217;s hash</p></li></ol><p>Think of the staging area as a draft of your next commit. You can add files to it incrementally, remove files from it, and review exactly what is staged before committing. </p><p>This gives you precise control over what goes into each commit.</p><pre><code># See what is staged versus what is modified
git status

# See the actual diff of staged changes
git diff --staged

# Remove a file from staging (keep the working directory change)
git restore --staged README.md</code></pre><h4>Why have a staging area at all?</h4><p>Imagine you changed five files. Three are part of a bug fix, and two are unrelated cleanup. </p><p>Without staging, you either commit everything together or do awkward manual juggling. With staging, you commit the bug fix first, then commit the cleanup separately. Your history stays clean and easy to follow.</p><h3>Repository: The Source of Truth</h3><p>The <strong>repository</strong> is the <code>.git</code> directory. It contains everything: the object database (all blobs, trees, commits), references (branches, tags), configuration, hooks, and more.</p><p>When you run <strong>git commit</strong>, Git:</p><ol><li><p>Creates a tree object from the current index</p></li><li><p>Creates a commit object pointing to that tree, with the current HEAD as parent</p></li><li><p>Updates the current branch to point to this new commit</p></li></ol><p>The repository is the source of truth for your project. The working directory and staging area are just convenient views into it. If you delete your working directory but keep <code>.git</code>, you can restore everything. If you delete <code>.git</code>, your history is gone.</p><p>Now that we understand where data lives, let&#8217;s understand what actually happens when you commit files.</p><div><hr></div><h1>5. How Commits Work</h1><p>A Git commit is not a &#8220;bundle of changes.&#8221; It is a <strong>snapshot</strong> of your project at a moment in time, plus a pointer to its parent commit(s).</p><p>Let&#8217;s trace what Git creates as you commit.</p><h3>Creating Your First Commit</h3><pre><code>echo "Hello" &gt; hello.txt
git add hello.txt
git commit -m "Initial commit"</code></pre><p>At this point, Git writes <strong>three objects</strong>:</p><ol><li><p><strong>Blob</strong>: the contents of <code>hello.txt</code> (<code>"Hello\n"</code>)</p></li><li><p><strong>Tree</strong>: a directory listing that maps <code>hello.txt</code> to that blob (and stores file mode like <code>100644</code>)</p></li><li><p><strong>Commit</strong>: points to the tree and stores metadata (author, timestamp, message)</p></li></ol><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!EKHj!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19d8b88d-d1b2-4d66-a2cf-ba1862161504_498x125.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!EKHj!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19d8b88d-d1b2-4d66-a2cf-ba1862161504_498x125.png 424w, https://substackcdn.com/image/fetch/$s_!EKHj!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19d8b88d-d1b2-4d66-a2cf-ba1862161504_498x125.png 848w, https://substackcdn.com/image/fetch/$s_!EKHj!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19d8b88d-d1b2-4d66-a2cf-ba1862161504_498x125.png 1272w, https://substackcdn.com/image/fetch/$s_!EKHj!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19d8b88d-d1b2-4d66-a2cf-ba1862161504_498x125.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!EKHj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19d8b88d-d1b2-4d66-a2cf-ba1862161504_498x125.png" width="498" height="125" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/19d8b88d-d1b2-4d66-a2cf-ba1862161504_498x125.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:125,&quot;width&quot;:498,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:10346,&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/184584683?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19d8b88d-d1b2-4d66-a2cf-ba1862161504_498x125.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_!EKHj!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19d8b88d-d1b2-4d66-a2cf-ba1862161504_498x125.png 424w, https://substackcdn.com/image/fetch/$s_!EKHj!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19d8b88d-d1b2-4d66-a2cf-ba1862161504_498x125.png 848w, https://substackcdn.com/image/fetch/$s_!EKHj!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19d8b88d-d1b2-4d66-a2cf-ba1862161504_498x125.png 1272w, https://substackcdn.com/image/fetch/$s_!EKHj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19d8b88d-d1b2-4d66-a2cf-ba1862161504_498x125.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>The commit does not contain file contents directly. It contains a pointer to the root tree, and the tree points to blobs.</p><h3>Creating a Second Commit</h3><p>Now change the file and commit again:</p><pre><code>echo "World" &gt;&gt; hello.txt
git commit -am "Add world"</code></pre><p>What changes inside Git?</p><ul><li><p><code>hello.txt</code> has new content, so Git creates a <strong>new blob</strong> for the new contents.</p></li><li><p>Because the file now points to a different blob, Git creates a <strong>new tree</strong>.</p></li><li><p>Git creates a <strong>new commit</strong> pointing to that new tree, and sets its <strong>parent</strong> to the previous commit.</p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!sbzs!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe80dd8a2-d935-41ef-9869-9b876324a596_799x213.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!sbzs!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe80dd8a2-d935-41ef-9869-9b876324a596_799x213.png 424w, https://substackcdn.com/image/fetch/$s_!sbzs!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe80dd8a2-d935-41ef-9869-9b876324a596_799x213.png 848w, https://substackcdn.com/image/fetch/$s_!sbzs!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe80dd8a2-d935-41ef-9869-9b876324a596_799x213.png 1272w, https://substackcdn.com/image/fetch/$s_!sbzs!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe80dd8a2-d935-41ef-9869-9b876324a596_799x213.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!sbzs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe80dd8a2-d935-41ef-9869-9b876324a596_799x213.png" width="799" height="213" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e80dd8a2-d935-41ef-9869-9b876324a596_799x213.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:213,&quot;width&quot;:799,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:21045,&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/184584683?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe80dd8a2-d935-41ef-9869-9b876324a596_799x213.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_!sbzs!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe80dd8a2-d935-41ef-9869-9b876324a596_799x213.png 424w, https://substackcdn.com/image/fetch/$s_!sbzs!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe80dd8a2-d935-41ef-9869-9b876324a596_799x213.png 848w, https://substackcdn.com/image/fetch/$s_!sbzs!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe80dd8a2-d935-41ef-9869-9b876324a596_799x213.png 1272w, https://substackcdn.com/image/fetch/$s_!sbzs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe80dd8a2-d935-41ef-9869-9b876324a596_799x213.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Notice what did not happen:</p><ul><li><p>Git did not modify Blob A.</p></li><li><p>Git did not overwrite Tree A.</p></li><li><p>Git did not &#8220;update&#8221; Commit A.</p></li></ul><p>Git objects are effectively immutable. New state means new objects, while unchanged objects are reused.</p><p>Also notice the storage efficiency: even though commits are &#8220;snapshots,&#8221; Git is not duplicating everything each time. Only objects that changed are new. Everything else is referenced again.</p><h3>Snapshots, Not Diffs</h3><p>A common misconception is that Git stores <strong>diffs</strong> between commits, like:</p><pre><code>Commit 1 + Diff -&gt; Commit 2 + Diff -&gt; Commit 3 ...</code></pre><p>That is not how Git works.</p><p>Git stores <strong>snapshots</strong>:</p><ul><li><p>Each commit points to a tree</p></li><li><p>That tree represents the full directory state at that moment</p></li><li><p>Git computes diffs only when you ask for them (for example <code>git diff</code>, <code>git show</code>, PR views)</p></li></ul><p>So the internal model is closer to this:</p><pre><code>Snapshot (Tree) A  -&gt; Commit A
Snapshot (Tree) B  -&gt; Commit B
Snapshot (Tree) C  -&gt; Commit C</code></pre><p>This is why operations like <code>checkout</code> are fast. Git does not replay every change from the beginning of time. It simply reads the tree for the commit you want and regenerates the working directory from that snapshot.</p><div><hr></div><h1>6. How Branches Work</h1><p>Here is the fact that changes how you think about Git: <strong>a branch is just a pointer to a commit</strong>.</p><p>That is the entire implementation. A branch is a small file containing a 40-character commit hash. The file for your <code>main</code> branch lives at <code>.git/refs/heads/main</code>.</p><pre><code>.git/refs/heads/main:    a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0
.git/refs/heads/feature: x9y8z7w6v5u4t3s2r1q0p9o8n7m6l5k4j3i2h1g0</code></pre><p>Creating a branch is nearly instantaneous because Git only creates a tiny file. There is no copying of files, no duplicating history. Just a 41-byte file (40 characters plus a newline) pointing to an existing commit.</p><h3>HEAD: Tracking Your Current Position</h3><p><strong>HEAD</strong> is a special reference that tells Git where you are. In most cases, HEAD points to a branch name rather than directly to a commit:</p><pre><code>.git/HEAD: ref: refs/heads/main</code></pre><p>This means: &#8220;you are on <code>main</code>.&#8221; Git resolves your current commit by following pointers: <code>HEAD</code> &#8594; <code>main</code> &#8594; commit &#8594; tree &#8594; files</p><p>When you create a new branch using <strong>git branch feature</strong>, Git creates <code>.git/refs/heads/feature</code> containing the current commit hash. No new commits, no copying.</p><p>When you switch branches with <strong>git checkout feature</strong>, Git updates HEAD to point to <code>refs/heads/feature</code>, then regenerates your working directory and index to match that branch&#8217;s commit.</p><p>Sometimes HEAD points directly to a commit hash instead of a branch name. This is called <strong>detached HEAD</strong> state. It happens when you checkout a specific commit by its hash or checkout a tag. </p><p>In this state, any new commits you create are not attached to a branch and can become &#8220;lost&#8221; if you switch away without creating a branch to preserve them.</p><h3>How Commits Advance Branches</h3><p>When you create a new commit while on a branch, Git advances that branch pointer.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!LSMI!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8363fed-dc7e-4f8b-bf3f-756841964c63_685x532.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!LSMI!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8363fed-dc7e-4f8b-bf3f-756841964c63_685x532.png 424w, https://substackcdn.com/image/fetch/$s_!LSMI!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8363fed-dc7e-4f8b-bf3f-756841964c63_685x532.png 848w, https://substackcdn.com/image/fetch/$s_!LSMI!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8363fed-dc7e-4f8b-bf3f-756841964c63_685x532.png 1272w, https://substackcdn.com/image/fetch/$s_!LSMI!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8363fed-dc7e-4f8b-bf3f-756841964c63_685x532.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!LSMI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8363fed-dc7e-4f8b-bf3f-756841964c63_685x532.png" width="685" height="532" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b8363fed-dc7e-4f8b-bf3f-756841964c63_685x532.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:532,&quot;width&quot;:685,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:25049,&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/184584683?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8363fed-dc7e-4f8b-bf3f-756841964c63_685x532.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_!LSMI!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8363fed-dc7e-4f8b-bf3f-756841964c63_685x532.png 424w, https://substackcdn.com/image/fetch/$s_!LSMI!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8363fed-dc7e-4f8b-bf3f-756841964c63_685x532.png 848w, https://substackcdn.com/image/fetch/$s_!LSMI!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8363fed-dc7e-4f8b-bf3f-756841964c63_685x532.png 1272w, https://substackcdn.com/image/fetch/$s_!LSMI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8363fed-dc7e-4f8b-bf3f-756841964c63_685x532.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="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 new commit (C4) has C3 as its parent. Then Git updates <code>.git/refs/heads/main</code> to contain C4&#8217;s hash. HEAD still points to main, but main now points to the new commit.</p><p>This pointer-based design explains why Git branching is so fast and cheap. There is no copying involved. Creating ten branches from the same commit means creating ten 41-byte files, all pointing to the same commit hash.</p><p>But branches diverge. Different developers make different changes on different branches. Eventually, those branches need to come back together. Let&#8217;s see how merging works.</p><div><hr></div><h1>7. How Merging Works</h1><p>Merging combines the work from two branches into one. Git handles merging differently depending on how the branches have diverged.</p><h3>Fast-Forward Merge: The Simple Case</h3><p>The simplest merge happens when the target branch has not moved since the source branch was created. In this case, Git performs a <strong>fast-forward merge</strong>: it simply moves the target branch pointer forward to match the source branch.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!M5uj!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23d5859c-8a35-408c-bb0e-a57d832f74d0_540x687.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!M5uj!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23d5859c-8a35-408c-bb0e-a57d832f74d0_540x687.png 424w, https://substackcdn.com/image/fetch/$s_!M5uj!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23d5859c-8a35-408c-bb0e-a57d832f74d0_540x687.png 848w, https://substackcdn.com/image/fetch/$s_!M5uj!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23d5859c-8a35-408c-bb0e-a57d832f74d0_540x687.png 1272w, https://substackcdn.com/image/fetch/$s_!M5uj!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23d5859c-8a35-408c-bb0e-a57d832f74d0_540x687.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!M5uj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23d5859c-8a35-408c-bb0e-a57d832f74d0_540x687.png" width="540" height="687" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/23d5859c-8a35-408c-bb0e-a57d832f74d0_540x687.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:687,&quot;width&quot;:540,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:30336,&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/184584683?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23d5859c-8a35-408c-bb0e-a57d832f74d0_540x687.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_!M5uj!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23d5859c-8a35-408c-bb0e-a57d832f74d0_540x687.png 424w, https://substackcdn.com/image/fetch/$s_!M5uj!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23d5859c-8a35-408c-bb0e-a57d832f74d0_540x687.png 848w, https://substackcdn.com/image/fetch/$s_!M5uj!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23d5859c-8a35-408c-bb0e-a57d832f74d0_540x687.png 1272w, https://substackcdn.com/image/fetch/$s_!M5uj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23d5859c-8a35-408c-bb0e-a57d832f74d0_540x687.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="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>No new commit is created. Git just updates the main branch pointer from C2 to C3. Fast-forward merges are instant and create a linear history.</p><h3>Three-Way Merge: When Branches Diverge</h3><p>When both branches have new commits since they diverged, Git performs a <strong>three-way merge</strong>. It needs three pieces of information:</p><ol><li><p>The <strong>merge base</strong>: the common ancestor where the branches diverged</p></li><li><p>The <strong>current branch tip</strong>: where your branch is now (ours)</p></li><li><p>The <strong>other branch tip</strong>: what you are merging in (theirs)</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_!3nlx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6426b4f2-b7df-4be3-bc12-28884577d7df_505x356.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!3nlx!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6426b4f2-b7df-4be3-bc12-28884577d7df_505x356.png 424w, https://substackcdn.com/image/fetch/$s_!3nlx!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6426b4f2-b7df-4be3-bc12-28884577d7df_505x356.png 848w, https://substackcdn.com/image/fetch/$s_!3nlx!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6426b4f2-b7df-4be3-bc12-28884577d7df_505x356.png 1272w, https://substackcdn.com/image/fetch/$s_!3nlx!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6426b4f2-b7df-4be3-bc12-28884577d7df_505x356.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!3nlx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6426b4f2-b7df-4be3-bc12-28884577d7df_505x356.png" width="505" height="356" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6426b4f2-b7df-4be3-bc12-28884577d7df_505x356.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:356,&quot;width&quot;:505,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:20964,&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/184584683?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6426b4f2-b7df-4be3-bc12-28884577d7df_505x356.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_!3nlx!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6426b4f2-b7df-4be3-bc12-28884577d7df_505x356.png 424w, https://substackcdn.com/image/fetch/$s_!3nlx!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6426b4f2-b7df-4be3-bc12-28884577d7df_505x356.png 848w, https://substackcdn.com/image/fetch/$s_!3nlx!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6426b4f2-b7df-4be3-bc12-28884577d7df_505x356.png 1272w, https://substackcdn.com/image/fetch/$s_!3nlx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6426b4f2-b7df-4be3-bc12-28884577d7df_505x356.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="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>Git compares both branch tips against the merge base to determine what changed on each side. Changes that only appear on one side are applied automatically. Changes that conflict (both sides modified the same lines) require manual resolution.</p><p>The resulting merge commit (C4) has two parents: C2 from main and C3 from feature. This preserves the complete history of both branches. You can trace back through either parent to see exactly what work happened on each branch.</p><h3>Handling Conflicts</h3><p>When Git cannot automatically merge (the same lines were changed differently on both sides), it marks the conflicts in your files:</p><pre><code>&lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD
const timeout = 5000;
=======
const timeout = 10000;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; feature</code></pre><p>Everything between <code>&lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD</code> and <code>=======</code> is from your current branch. Everything between <code>=======</code> and <code>&gt;&gt;&gt;&gt;&gt;&gt;&gt; feature</code> is from the branch being merged. </p><p>You resolve the conflict by editing the file to contain what you actually want, removing the conflict markers, then staging and committing.</p><p>Merging preserves the complete history of both branches, but it creates merge commits that can clutter the history. There is another way to integrate changes that results in a cleaner, linear history.</p><div><hr></div><h1>8. How Rebase Works</h1><p>Rebasing is an alternative to merging that rewrites history to create a linear sequence of commits. </p><p>Instead of creating a merge commit that ties two branches together, rebase moves your commits to appear as if they were created on top of the target branch.</p><p>When you run <strong>git rebase main</strong> while on a feature branch, Git:</p><ol><li><p>Finds the common ancestor of both branches</p></li><li><p>Saves the commits that are unique to your feature branch</p></li><li><p>Resets your branch to the tip of main</p></li><li><p>Replays your saved commits one by one on top</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_!nfIc!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53756bfe-dc06-4769-bb78-5fb14265ea2d_849x715.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!nfIc!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53756bfe-dc06-4769-bb78-5fb14265ea2d_849x715.png 424w, https://substackcdn.com/image/fetch/$s_!nfIc!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53756bfe-dc06-4769-bb78-5fb14265ea2d_849x715.png 848w, https://substackcdn.com/image/fetch/$s_!nfIc!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53756bfe-dc06-4769-bb78-5fb14265ea2d_849x715.png 1272w, https://substackcdn.com/image/fetch/$s_!nfIc!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53756bfe-dc06-4769-bb78-5fb14265ea2d_849x715.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!nfIc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53756bfe-dc06-4769-bb78-5fb14265ea2d_849x715.png" width="711" height="598.7809187279152" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/53756bfe-dc06-4769-bb78-5fb14265ea2d_849x715.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:715,&quot;width&quot;:849,&quot;resizeWidth&quot;:711,&quot;bytes&quot;:37335,&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/184584683?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53756bfe-dc06-4769-bb78-5fb14265ea2d_849x715.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_!nfIc!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53756bfe-dc06-4769-bb78-5fb14265ea2d_849x715.png 424w, https://substackcdn.com/image/fetch/$s_!nfIc!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53756bfe-dc06-4769-bb78-5fb14265ea2d_849x715.png 848w, https://substackcdn.com/image/fetch/$s_!nfIc!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53756bfe-dc06-4769-bb78-5fb14265ea2d_849x715.png 1272w, https://substackcdn.com/image/fetch/$s_!nfIc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53756bfe-dc06-4769-bb78-5fb14265ea2d_849x715.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Notice that F1 and F2 become F1' and F2' after rebasing. The prime marks indicate these are new commits with different hashes. Even though the changes are identical, the commits have different parent pointers, which means different SHA-1 hashes. </p><p>The original commits still exist in the object database (and are recoverable via reflog) but are no longer reachable from any branch.</p><div><hr></div><h1>9. How Git Optimizes Storage</h1><p>So far, we have discussed &#8220;loose objects&#8221;: individual files in <code>.git/objects/</code> named by their hash. This is simple and fast for writing new objects, but it does not scale perfectly.</p><p>Two issues show up as a repo grows:</p><ul><li><p><strong>Filesystem overhead:</strong> thousands (or millions) of tiny files can slow down filesystems.</p></li><li><p><strong>Wasted space across versions:</strong> even though Git stores snapshots, many snapshots differ only slightly.</p></li></ul><p>Git solves both problems with <strong>pack files</strong>.</p><h3>Pack Files</h3><p>Instead of keeping every object as a separate file, Git periodically (during <strong>git gc</strong>, <strong>push</strong>, <strong>fetch</strong>, or <strong>clone</strong>) bundles many objects together into a pack:</p><pre><code><code>.git/objects/pack/
&#9500;&#9472;&#9472; pack-abc123def456.idx   (index for fast lookup)
&#9492;&#9472;&#9472; pack-abc123def456.pack  (compressed objects with deltas)</code></code></pre><ul><li><p>The <code>.pack</code> file holds the actual compressed, delta-encoded data.</p></li><li><p>The <code>.idx</code> file is an index that lets Git locate any object inside the pack quickly.</p></li></ul><p>This reduces file count dramatically and makes large repositories more efficient to store and transfer.</p><h3>How packing saves space</h3><p>When Git creates a pack, it applies three main optimizations:</p><ol><li><p><strong>Grouping: </strong>Git clusters related objects (for example, multiple versions of the same file) so it can compress them effectively.</p></li><li><p><strong>Delta compression: </strong>Instead of storing every version in full, Git stores one full version and then stores <strong>deltas</strong> (differences) for the others. Older versions can be reconstructed by applying deltas.</p></li><li><p><strong>Compression: </strong>The packed data is compressed (zlib), just like loose objects, but now Git can often compress even better because it is working with a larger, more structured dataset.</p></li></ol><h3>The Impact on Repository Size</h3><p>Imagine a 1MB configuration file modified 100 times.</p><ul><li><p>Without packing, Git would store many full versions (each compressed, but still substantial). You might end up with something on the order of <strong>tens of megabytes</strong> or more across history.</p></li><li><p>With packing, Git can store one full version plus small deltas for the other 99 versions. If each change touches only a few lines, each delta could be only a few kilobytes, so the total might be closer to <strong>a couple of megabytes</strong>.</p></li></ul><p>This is why repositories with years of history and thousands of commits can still clone in a reasonable size. Git is not shipping every full file version. It is shipping a compact representation built from packed objects and deltas.</p><h3>When Packing Happens</h3><p>You usually do not need to trigger packing manually. Git does it for you:</p><ul><li><p><code>git gc</code> explicitly runs garbage collection and repacking</p></li><li><p><code>git push</code> / <code>git fetch</code> / <code>git clone</code> often involve packing or repacking for efficient transfer</p></li><li><p>Git can also run GC automatically when loose objects grow past certain thresholds</p></li></ul><p>You rarely think about pack files day to day, but they are a big reason Git scales so well and why repository sizes are manageable despite storing complete history.</p><div><hr></div><h1>Key Takeaways</h1><p><strong>Git is a content-addressable filesystem.</strong> Every piece of data is stored by its SHA-1 hash. Same content, same hash, stored once.</p><p><strong>Three object types matter.</strong> Blobs store file contents. Trees store directory structure. Commits store snapshots with history links.</p><p><strong>The three areas structure your workflow.</strong> Working directory for editing, staging area for drafting commits, repository for permanent storage.</p><p><strong>Branches are just pointers.</strong> A branch is a 41-byte file containing a commit hash. Creating branches is instant. Switching branches regenerates the working directory.</p><p><strong>Merging connects histories.</strong> Fast-forward when possible, three-way merge when branches diverge. Conflicts happen when the same lines change differently.</p><p><strong>Pack files keep Git efficient.</strong> Delta compression and grouping allow Git to store extensive history in surprisingly little space.</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>]]></content:encoded></item><item><title><![CDATA[How Load Balancers Actually Work]]></title><description><![CDATA[A Deep Dive]]></description><link>https://blog.algomaster.io/p/how-load-balancers-actually-work</link><guid isPermaLink="false">https://blog.algomaster.io/p/how-load-balancers-actually-work</guid><dc:creator><![CDATA[Ashish Pratap Singh]]></dc:creator><pubDate>Thu, 08 Jan 2026 12:30:35 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!D0s8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84d04287-a773-401e-9011-87f9c15533f1_483x333.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>A <strong>load balancer</strong> is one of the most foundational building blocks in distributed systems. It sits between clients and your backend servers and <strong>spreads incoming traffic across a pool of machines</strong>, so no single server becomes the bottleneck (or the single point of failure).</p><p>But the interesting questions start after the definition:</p><ul><li><p>How does the load balancer decide which server should handle a request?</p></li><li><p>What&#8217;s the difference between L4 and L7 Load Balancers?</p></li><li><p>What happens when a server slows down or goes offline mid-traffic?</p></li><li><p>How can the load balancer ensure that request from the same client always go to the same server?</p></li><li><p>And what happens if the load balancer itself goes down?</p></li></ul><p>In this article, we&#8217;ll answer these questions and build an intuitive understanding of how load balancers work in real systems.</p><p>Let&#8217;s start with the basics: <strong>why we need load balancers in the first place.</strong></p><div><hr></div><h1>1. Why Do We Need Load Balancers?</h1><p>Imagine a web app with just one server. Every user request hits the same machine.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!iVgQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4fb6ba4d-93ed-4ad4-ae43-ba982907aebd_460x175.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!iVgQ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4fb6ba4d-93ed-4ad4-ae43-ba982907aebd_460x175.png 424w, https://substackcdn.com/image/fetch/$s_!iVgQ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4fb6ba4d-93ed-4ad4-ae43-ba982907aebd_460x175.png 848w, https://substackcdn.com/image/fetch/$s_!iVgQ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4fb6ba4d-93ed-4ad4-ae43-ba982907aebd_460x175.png 1272w, https://substackcdn.com/image/fetch/$s_!iVgQ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4fb6ba4d-93ed-4ad4-ae43-ba982907aebd_460x175.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!iVgQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4fb6ba4d-93ed-4ad4-ae43-ba982907aebd_460x175.png" width="506" height="192.5" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4fb6ba4d-93ed-4ad4-ae43-ba982907aebd_460x175.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:175,&quot;width&quot;:460,&quot;resizeWidth&quot;:506,&quot;bytes&quot;:9297,&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/183867133?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4fb6ba4d-93ed-4ad4-ae43-ba982907aebd_460x175.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_!iVgQ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4fb6ba4d-93ed-4ad4-ae43-ba982907aebd_460x175.png 424w, https://substackcdn.com/image/fetch/$s_!iVgQ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4fb6ba4d-93ed-4ad4-ae43-ba982907aebd_460x175.png 848w, https://substackcdn.com/image/fetch/$s_!iVgQ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4fb6ba4d-93ed-4ad4-ae43-ba982907aebd_460x175.png 1272w, https://substackcdn.com/image/fetch/$s_!iVgQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4fb6ba4d-93ed-4ad4-ae43-ba982907aebd_460x175.png 1456w" sizes="100vw" fetchpriority="high"></picture><div></div></div></a></figure></div><p>It works&#8230; until it doesn&#8217;t. This &#8220;single-server&#8221; setup has a few fundamental problems:</p><ol><li><p><strong>Single Point of Failure:</strong> If the server crashes, your entire application goes down.</p></li><li><p><strong>Limited Scalability:</strong> A single server can only handle so many requests before it becomes overloaded.</p></li><li><p><strong>Poor Performance:</strong> As traffic increases, response times degrade for all users.</p></li><li><p><strong>No Redundancy:</strong> Hardware failures, software bugs, or maintenance windows cause complete outages.</p></li></ol><p>A <strong>load balancer</strong> solves these problems by distributing traffic across multiple servers.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!iJQc!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2bce6202-ec2a-4435-a1fe-ca9119015eda_476x284.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!iJQc!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2bce6202-ec2a-4435-a1fe-ca9119015eda_476x284.png 424w, https://substackcdn.com/image/fetch/$s_!iJQc!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2bce6202-ec2a-4435-a1fe-ca9119015eda_476x284.png 848w, https://substackcdn.com/image/fetch/$s_!iJQc!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2bce6202-ec2a-4435-a1fe-ca9119015eda_476x284.png 1272w, https://substackcdn.com/image/fetch/$s_!iJQc!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2bce6202-ec2a-4435-a1fe-ca9119015eda_476x284.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!iJQc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2bce6202-ec2a-4435-a1fe-ca9119015eda_476x284.png" width="476" height="284" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2bce6202-ec2a-4435-a1fe-ca9119015eda_476x284.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:284,&quot;width&quot;:476,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:16259,&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/183867133?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2bce6202-ec2a-4435-a1fe-ca9119015eda_476x284.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_!iJQc!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2bce6202-ec2a-4435-a1fe-ca9119015eda_476x284.png 424w, https://substackcdn.com/image/fetch/$s_!iJQc!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2bce6202-ec2a-4435-a1fe-ca9119015eda_476x284.png 848w, https://substackcdn.com/image/fetch/$s_!iJQc!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2bce6202-ec2a-4435-a1fe-ca9119015eda_476x284.png 1272w, https://substackcdn.com/image/fetch/$s_!iJQc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2bce6202-ec2a-4435-a1fe-ca9119015eda_476x284.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="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 this setup, you get:</p><ul><li><p><strong>High Availability:</strong> If one server fails, traffic is automatically routed to healthy servers.</p></li><li><p><strong>Horizontal Scalability:</strong> You can add more servers to handle increased load.</p></li><li><p><strong>Better Performance:</strong> Requests are distributed, so no single server is overwhelmed.</p></li><li><p><strong>Zero-Downtime Deployments:</strong> You can take servers out of rotation for maintenance without affecting users.</p></li></ul><p><em><strong>But how does the load balancer decide which server should handle each request?</strong></em></p><div><hr></div><h1>2. Load Balancing Algorithms</h1><p>The load balancer uses algorithms to distribute incoming requests. Each algorithm has different characteristics and is suited for different scenarios.</p><p>Below are the most common ones you&#8217;ll see in real systems.</p><h2>2.1 Round Robin</h2><p>The simplest algorithm. Requests are distributed to servers in sequential order.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Bc7a!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70cff03e-f5ac-4ce3-8ddf-158dc7530cc3_493x203.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Bc7a!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70cff03e-f5ac-4ce3-8ddf-158dc7530cc3_493x203.png 424w, https://substackcdn.com/image/fetch/$s_!Bc7a!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70cff03e-f5ac-4ce3-8ddf-158dc7530cc3_493x203.png 848w, https://substackcdn.com/image/fetch/$s_!Bc7a!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70cff03e-f5ac-4ce3-8ddf-158dc7530cc3_493x203.png 1272w, https://substackcdn.com/image/fetch/$s_!Bc7a!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70cff03e-f5ac-4ce3-8ddf-158dc7530cc3_493x203.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Bc7a!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70cff03e-f5ac-4ce3-8ddf-158dc7530cc3_493x203.png" width="493" height="203" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/70cff03e-f5ac-4ce3-8ddf-158dc7530cc3_493x203.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:203,&quot;width&quot;:493,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:15866,&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/183867133?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70cff03e-f5ac-4ce3-8ddf-158dc7530cc3_493x203.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_!Bc7a!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70cff03e-f5ac-4ce3-8ddf-158dc7530cc3_493x203.png 424w, https://substackcdn.com/image/fetch/$s_!Bc7a!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70cff03e-f5ac-4ce3-8ddf-158dc7530cc3_493x203.png 848w, https://substackcdn.com/image/fetch/$s_!Bc7a!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70cff03e-f5ac-4ce3-8ddf-158dc7530cc3_493x203.png 1272w, https://substackcdn.com/image/fetch/$s_!Bc7a!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70cff03e-f5ac-4ce3-8ddf-158dc7530cc3_493x203.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><pre><code>Request 1 &#8594; Server A
Request 2 &#8594; Server B
Request 3 &#8594; Server C
Request 4 &#8594; Server A  (cycle repeats)
Request 5 &#8594; Server B
...</code></pre><h4>Pros:</h4><ul><li><p>Simple to implement</p></li><li><p>Works well when all servers have equal capacity</p></li><li><p>Predictable distribution</p></li></ul><h4>Cons:</h4><ul><li><p>Does not account for server load or capacity differences</p></li><li><p>A slow request on one server does not affect the distribution</p></li></ul><p><strong>Best for:</strong> Homogeneous server environments where all servers have similar specs and requests have similar processing times.</p><h2>2.2 Weighted Round Robin</h2><p>An extension of Round Robin where servers are assigned weights based on their capacity.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!uczx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8327b027-1d8f-4589-9037-52428f3447ac_504x223.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!uczx!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8327b027-1d8f-4589-9037-52428f3447ac_504x223.png 424w, https://substackcdn.com/image/fetch/$s_!uczx!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8327b027-1d8f-4589-9037-52428f3447ac_504x223.png 848w, https://substackcdn.com/image/fetch/$s_!uczx!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8327b027-1d8f-4589-9037-52428f3447ac_504x223.png 1272w, https://substackcdn.com/image/fetch/$s_!uczx!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8327b027-1d8f-4589-9037-52428f3447ac_504x223.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!uczx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8327b027-1d8f-4589-9037-52428f3447ac_504x223.png" width="504" height="223" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8327b027-1d8f-4589-9037-52428f3447ac_504x223.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:223,&quot;width&quot;:504,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:20400,&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/183867133?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8327b027-1d8f-4589-9037-52428f3447ac_504x223.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_!uczx!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8327b027-1d8f-4589-9037-52428f3447ac_504x223.png 424w, https://substackcdn.com/image/fetch/$s_!uczx!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8327b027-1d8f-4589-9037-52428f3447ac_504x223.png 848w, https://substackcdn.com/image/fetch/$s_!uczx!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8327b027-1d8f-4589-9037-52428f3447ac_504x223.png 1272w, https://substackcdn.com/image/fetch/$s_!uczx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8327b027-1d8f-4589-9037-52428f3447ac_504x223.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><pre><code>Server A (weight=3): Handles 3 out of every 6 requests
Server B (weight=2): Handles 2 out of every 6 requests
Server C (weight=1): Handles 1 out of every 6 requests</code></pre><h4>Pros:</h4><ul><li><p>Still simple</p></li><li><p>Better for mixed instance sizes (e.g., 2 vCPU + 4 vCPU + 8 vCPU)</p></li></ul><h4>Cons:</h4><ul><li><p>Still not load-aware in real time</p></li><li><p>If one server becomes slow (GC pause, noisy neighbor, warm cache vs cold cache), it will still get its scheduled share</p></li></ul><p><strong>Best for:</strong> Heterogeneous environments where servers have different capacities (e.g., different CPU, memory, or network bandwidth).</p><h2>2.3 Least Connections</h2><p>Routes requests to the server with the fewest active connections.</p><p>This algorithm is <strong>dynamic</strong>, it considers the current state of each server rather than using a fixed rotation.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!D0s8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84d04287-a773-401e-9011-87f9c15533f1_483x333.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!D0s8!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84d04287-a773-401e-9011-87f9c15533f1_483x333.png 424w, https://substackcdn.com/image/fetch/$s_!D0s8!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84d04287-a773-401e-9011-87f9c15533f1_483x333.png 848w, https://substackcdn.com/image/fetch/$s_!D0s8!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84d04287-a773-401e-9011-87f9c15533f1_483x333.png 1272w, https://substackcdn.com/image/fetch/$s_!D0s8!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84d04287-a773-401e-9011-87f9c15533f1_483x333.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!D0s8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84d04287-a773-401e-9011-87f9c15533f1_483x333.png" width="483" height="333" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/84d04287-a773-401e-9011-87f9c15533f1_483x333.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:333,&quot;width&quot;:483,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:22015,&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/183867133?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84d04287-a773-401e-9011-87f9c15533f1_483x333.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_!D0s8!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84d04287-a773-401e-9011-87f9c15533f1_483x333.png 424w, https://substackcdn.com/image/fetch/$s_!D0s8!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84d04287-a773-401e-9011-87f9c15533f1_483x333.png 848w, https://substackcdn.com/image/fetch/$s_!D0s8!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84d04287-a773-401e-9011-87f9c15533f1_483x333.png 1272w, https://substackcdn.com/image/fetch/$s_!D0s8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84d04287-a773-401e-9011-87f9c15533f1_483x333.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="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>Server A: 10 active connections
Server B: 5 active connections  &#8592; Next request goes here
Server C: 8 active connections</code></pre><h4>Pros:</h4><ul><li><p>Adapts to varying request processing times</p></li><li><p>Naturally balances load when some requests take longer than others</p></li></ul><h4>Cons:</h4><ul><li><p>Requires tracking connection counts for each server</p></li><li><p>Slightly more overhead than Round Robin</p></li></ul><p><strong>Best for:</strong> Applications where request processing times vary significantly (e.g., database queries, file uploads).</p><h2>2.4 Weighted Least Connections</h2><p>Combines Least Connections with server weights. The algorithm considers both the number of active connections and the server&#8217;s capacity.</p><pre><code>Score = Active Connections / Weight

Server A: 10 connections, weight 5 &#8594; Score = 2.0
Server B: 6 connections, weight 2  &#8594; Score = 3.0
Server C: 4 connections, weight 1  &#8594; Score = 4.0

Next request goes to Server A (lowest score)</code></pre><h4>Pros:</h4><ul><li><p>Works well for mixed instance sizes <em>and</em> mixed request durations</p></li><li><p>More robust than either &#8220;weighted&#8221; or &#8220;least connections&#8221; alone</p></li></ul><h4>Cons:</h4><ul><li><p>Needs reliable tracking + weight tuning</p></li><li><p>Still uses connections as a proxy for load (not always perfect)</p></li></ul><p><strong>Best for:</strong> Heterogeneous environments with varying request processing times.</p><h2>2.5 IP Hash</h2><p>The client&#8217;s IP address is hashed to determine which server handles the request. The same client IP always goes to the same server.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!D4NK!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffabb590c-7c5e-45b0-a598-f35d9e5b66d0_488x332.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!D4NK!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffabb590c-7c5e-45b0-a598-f35d9e5b66d0_488x332.png 424w, https://substackcdn.com/image/fetch/$s_!D4NK!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffabb590c-7c5e-45b0-a598-f35d9e5b66d0_488x332.png 848w, https://substackcdn.com/image/fetch/$s_!D4NK!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffabb590c-7c5e-45b0-a598-f35d9e5b66d0_488x332.png 1272w, https://substackcdn.com/image/fetch/$s_!D4NK!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffabb590c-7c5e-45b0-a598-f35d9e5b66d0_488x332.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!D4NK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffabb590c-7c5e-45b0-a598-f35d9e5b66d0_488x332.png" width="488" height="332" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fabb590c-7c5e-45b0-a598-f35d9e5b66d0_488x332.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:332,&quot;width&quot;:488,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:19921,&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/183867133?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffabb590c-7c5e-45b0-a598-f35d9e5b66d0_488x332.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_!D4NK!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffabb590c-7c5e-45b0-a598-f35d9e5b66d0_488x332.png 424w, https://substackcdn.com/image/fetch/$s_!D4NK!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffabb590c-7c5e-45b0-a598-f35d9e5b66d0_488x332.png 848w, https://substackcdn.com/image/fetch/$s_!D4NK!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffabb590c-7c5e-45b0-a598-f35d9e5b66d0_488x332.png 1272w, https://substackcdn.com/image/fetch/$s_!D4NK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffabb590c-7c5e-45b0-a598-f35d9e5b66d0_488x332.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="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>hash(192.168.1.10) % 3 = 1 &#8594; Server B
hash(192.168.1.20) % 3 = 0 &#8594; Server A
hash(192.168.1.30) % 3 = 2 &#8594; Server C</code></pre><h4>Pros:</h4><ul><li><p>Simple session persistence without cookies</p></li><li><p>No additional state to track</p></li></ul><h4>Cons:</h4><ul><li><p>Uneven distribution if IP addresses are not uniformly distributed</p></li><li><p>Server additions/removals cause redistribution of clients</p></li></ul><p><strong>Best for:</strong> Applications requiring basic session persistence without cookie support.</p><h2>2.6 Least Response Time</h2><p>Routes requests to the server with the fastest response time and fewest active connections.</p><p>The load balancer continuously measures:</p><ul><li><p>Average response time for each server</p></li><li><p>Number of active connections</p></li></ul><h4>Pros</h4><ul><li><p>Optimizes for perceived performance</p></li><li><p>Can avoid slow/unhealthy servers before they fully fail</p></li></ul><h4>Cons</h4><ul><li><p>Highest operational complexity (needs continuous measurement and smoothing)</p></li><li><p>Can &#8220;overreact&#8221; to noise without careful tuning (feedback loops)</p></li><li><p>Requires good metrics and stable observation windows</p></li></ul><p><strong>Best for:</strong> Latency-sensitive applications where response time is critical.</p><div><hr></div><h1>3. Layer 4 vs Layer 7 Load Balancing</h1>
      <p>
          <a href="https://blog.algomaster.io/p/how-load-balancers-actually-work">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[The Hidden Cost of Database Indexes]]></title><description><![CDATA[&#8220;Just add an index&#8221;. This is the most common advice when a query runs slow.]]></description><link>https://blog.algomaster.io/p/the-hidden-cost-of-database-indexes</link><guid isPermaLink="false">https://blog.algomaster.io/p/the-hidden-cost-of-database-indexes</guid><dc:creator><![CDATA[Ashish Pratap Singh]]></dc:creator><pubDate>Tue, 06 Jan 2026 04:19:07 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!2BPe!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e61e5aa-302e-4ede-891d-1b185a1a12e4_963x353.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><strong>&#8220;Just add an index.&#8221;</strong></p><p>This is the most common advice when a query runs slow. And it works. Indexes can turn a 30-second query into a 30-millisecond one.</p><p>But <strong>indexes aren&#8217;t free</strong>. Every index you create comes with costs that are easy to overlook until they become a problem.</p><p>In this article, we&#8217;ll explore the <strong>hidden costs of database indexes</strong> that every developer should understand before reaching for `CREATE INDEX`.</p><div><hr></div><h1>1. The Write Performance Penalty</h1><p>When you think about indexes, you probably think about <strong>SELECT</strong> queries. But every index also affects <strong>INSERT</strong>, <strong>UPDATE</strong>, and <strong>DELETE</strong> operations.</p><p><strong>Here&#8217;s why:</strong> an index is a separate data structure (usually a B-Tree) that maintains a sorted copy of the indexed column(s) along with pointers to the actual rows. When you modify data in the table, the database must also update every index on that table.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!2BPe!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e61e5aa-302e-4ede-891d-1b185a1a12e4_963x353.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!2BPe!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e61e5aa-302e-4ede-891d-1b185a1a12e4_963x353.png 424w, https://substackcdn.com/image/fetch/$s_!2BPe!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e61e5aa-302e-4ede-891d-1b185a1a12e4_963x353.png 848w, https://substackcdn.com/image/fetch/$s_!2BPe!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e61e5aa-302e-4ede-891d-1b185a1a12e4_963x353.png 1272w, https://substackcdn.com/image/fetch/$s_!2BPe!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e61e5aa-302e-4ede-891d-1b185a1a12e4_963x353.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!2BPe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e61e5aa-302e-4ede-891d-1b185a1a12e4_963x353.png" width="963" height="353" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7e61e5aa-302e-4ede-891d-1b185a1a12e4_963x353.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:353,&quot;width&quot;:963,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:26155,&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/173211298?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e61e5aa-302e-4ede-891d-1b185a1a12e4_963x353.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_!2BPe!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e61e5aa-302e-4ede-891d-1b185a1a12e4_963x353.png 424w, https://substackcdn.com/image/fetch/$s_!2BPe!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e61e5aa-302e-4ede-891d-1b185a1a12e4_963x353.png 848w, https://substackcdn.com/image/fetch/$s_!2BPe!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e61e5aa-302e-4ede-891d-1b185a1a12e4_963x353.png 1272w, https://substackcdn.com/image/fetch/$s_!2BPe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e61e5aa-302e-4ede-891d-1b185a1a12e4_963x353.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><h3>How Each Operation is Affected</h3><p><strong>INSERT:</strong> For every new row, the database must:</p><ol><li><p>Write the row to the table</p></li><li><p>Find the correct position in each B-Tree index</p></li><li><p>Insert a new entry in each index</p></li><li><p>Potentially rebalance the B-Tree if nodes split</p></li></ol><p><strong>UPDATE:</strong> When you update an indexed column, the database must:</p><ol><li><p>Update the row in the table</p></li><li><p>Remove the old entry from the index</p></li><li><p>Insert a new entry at the correct position</p></li><li><p>This is essentially a DELETE + INSERT on the index</p></li></ol><p><strong>DELETE:</strong> For every deleted row, the database must:</p><ol><li><p>Remove the row from the table</p></li><li><p>Find and remove the corresponding entry in each index</p></li><li><p>Potentially rebalance the B-Tree</p></li></ol><h3>Real-World Impact</h3><p>Consider a table with 5 indexes. Every INSERT now requires 6 write operations instead of 1. The overhead compounds quickly:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!cOue!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60a2705d-224c-49ed-a7f4-fe6ce4623dc7_1390x676.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!cOue!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60a2705d-224c-49ed-a7f4-fe6ce4623dc7_1390x676.png 424w, https://substackcdn.com/image/fetch/$s_!cOue!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60a2705d-224c-49ed-a7f4-fe6ce4623dc7_1390x676.png 848w, https://substackcdn.com/image/fetch/$s_!cOue!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60a2705d-224c-49ed-a7f4-fe6ce4623dc7_1390x676.png 1272w, https://substackcdn.com/image/fetch/$s_!cOue!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60a2705d-224c-49ed-a7f4-fe6ce4623dc7_1390x676.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!cOue!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60a2705d-224c-49ed-a7f4-fe6ce4623dc7_1390x676.png" width="640" height="311.2517985611511" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/60a2705d-224c-49ed-a7f4-fe6ce4623dc7_1390x676.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:676,&quot;width&quot;:1390,&quot;resizeWidth&quot;:640,&quot;bytes&quot;:69243,&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/173211298?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60a2705d-224c-49ed-a7f4-fe6ce4623dc7_1390x676.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_!cOue!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60a2705d-224c-49ed-a7f4-fe6ce4623dc7_1390x676.png 424w, https://substackcdn.com/image/fetch/$s_!cOue!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60a2705d-224c-49ed-a7f4-fe6ce4623dc7_1390x676.png 848w, https://substackcdn.com/image/fetch/$s_!cOue!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60a2705d-224c-49ed-a7f4-fe6ce4623dc7_1390x676.png 1272w, https://substackcdn.com/image/fetch/$s_!cOue!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60a2705d-224c-49ed-a7f4-fe6ce4623dc7_1390x676.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="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 numbers are approximate and depend on many factors (index type, column size, tree depth), but the trend is clear: <strong>more indexes = slower writes</strong>.</p><p>For write-heavy workloads like logging systems, event tracking, or IoT data ingestion, this overhead can become a serious bottleneck.</p><div><hr></div><h1>2. Storage Overhead</h1>
      <p>
          <a href="https://blog.algomaster.io/p/the-hidden-cost-of-database-indexes">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[I Created the Most Comprehensive System Design Interview Resource]]></title><description><![CDATA[I&#8217;m excited to launch my premium pattern-focused System Design interview resource.]]></description><link>https://blog.algomaster.io/p/system-design-course</link><guid isPermaLink="false">https://blog.algomaster.io/p/system-design-course</guid><dc:creator><![CDATA[Ashish Pratap Singh]]></dc:creator><pubDate>Thu, 25 Dec 2025 14:30:25 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!AeNy!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0030996-9d6d-4200-9e3b-3c5a3e735763_2518x1728.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>I&#8217;m excited to launch my <strong><a href="https://algomaster.io/learn/system-design-interviews/introduction">premium pattern-focused System Design interview resource</a></strong>.</p><p>This is the most comprehensive course I&#8217;ve built, covering <strong>55 interview problems</strong>, <strong>20 technology deep dives</strong>, and <strong>20 reusable patterns</strong> that appear across multiple problems.</p><p>Many chapters are <strong>free to explore</strong>. To unlock full access, you need to become a <strong><a href="https://blog.algomaster.io/subscribe">paid subscriber</a></strong> to the newsletter.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!AeNy!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0030996-9d6d-4200-9e3b-3c5a3e735763_2518x1728.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!AeNy!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0030996-9d6d-4200-9e3b-3c5a3e735763_2518x1728.png 424w, https://substackcdn.com/image/fetch/$s_!AeNy!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0030996-9d6d-4200-9e3b-3c5a3e735763_2518x1728.png 848w, https://substackcdn.com/image/fetch/$s_!AeNy!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0030996-9d6d-4200-9e3b-3c5a3e735763_2518x1728.png 1272w, https://substackcdn.com/image/fetch/$s_!AeNy!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0030996-9d6d-4200-9e3b-3c5a3e735763_2518x1728.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!AeNy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0030996-9d6d-4200-9e3b-3c5a3e735763_2518x1728.png" width="1456" height="999" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b0030996-9d6d-4200-9e3b-3c5a3e735763_2518x1728.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:999,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:497869,&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/182567412?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0030996-9d6d-4200-9e3b-3c5a3e735763_2518x1728.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_!AeNy!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0030996-9d6d-4200-9e3b-3c5a3e735763_2518x1728.png 424w, https://substackcdn.com/image/fetch/$s_!AeNy!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0030996-9d6d-4200-9e3b-3c5a3e735763_2518x1728.png 848w, https://substackcdn.com/image/fetch/$s_!AeNy!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0030996-9d6d-4200-9e3b-3c5a3e735763_2518x1728.png 1272w, https://substackcdn.com/image/fetch/$s_!AeNy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0030996-9d6d-4200-9e3b-3c5a3e735763_2518x1728.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/system-design-interviews/introduction&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/system-design-interviews/introduction"><span>Check it out here</span></a></p><p>This is in addition to my <strong><a href="https://algomaster.io/learn/system-design/what-is-system-design">System Design Fundamentals</a></strong> and <strong><a href="https://algomaster.io/learn/lld/what-is-lld">Low-Level Design</a></strong> Courses. I also updated my popular <strong><a href="https://github.com/ashishps1/awesome-system-design-resources">system design github repository</a></strong> with more free resources.</p><div><hr></div><h3>What&#8217;s Inside?</h3><h4>55 interview problems categorized into buckets</h4><p>Organized into 12 practical categories including:</p><ul><li><p><strong>Real-Time Communication:</strong> WhatsApp, Slack, Zoom, Google Docs</p></li><li><p><strong>Social Media:</strong> Instagram, TikTok, Reddit, FB News Feed, Tinder</p></li><li><p><strong>Media Streaming:</strong> Spotify, YouTube, Netflix, Twitch, Google Drive</p></li><li><p><strong>Location-Based: </strong>Airbnb, Food Delivery, Uber, Google Maps</p></li><li><p><strong>Search &amp; Aggregation:</strong> Autocomplete, Web Crawler, Google Search, Ad Click Aggregator</p></li><li><p><strong>E-commerce &amp; Marketplace:</strong> Amazon, Shopify, Flash Sale, Movie Booking, Auction System</p></li><li><p><strong>Financial System: </strong>Payment Systems (Stripe), Digital Wallet, Stock Exchange</p></li><li><p><strong>Distributed Infrastructure:</strong> Key-Value Store, Distributed Cache, CDN, Rate Limiter, Message Queue</p></li><li><p><strong>Counting &amp; Ranking:</strong> Likes Counter, Top K, Real-Time Leaderboard</p></li><li><p><strong>Asynchronous Systems:</strong> Notification Service, Job Scheduler, CI/CD Pipeline</p></li></ul><div><hr></div><h4>20 Technical Deep Dives</h4><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!by0R!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fada89b-e14f-4a7a-9b2d-3b85c8615b16_2536x1772.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!by0R!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fada89b-e14f-4a7a-9b2d-3b85c8615b16_2536x1772.png 424w, https://substackcdn.com/image/fetch/$s_!by0R!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fada89b-e14f-4a7a-9b2d-3b85c8615b16_2536x1772.png 848w, https://substackcdn.com/image/fetch/$s_!by0R!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fada89b-e14f-4a7a-9b2d-3b85c8615b16_2536x1772.png 1272w, https://substackcdn.com/image/fetch/$s_!by0R!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fada89b-e14f-4a7a-9b2d-3b85c8615b16_2536x1772.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!by0R!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fada89b-e14f-4a7a-9b2d-3b85c8615b16_2536x1772.png" width="1456" height="1017" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6fada89b-e14f-4a7a-9b2d-3b85c8615b16_2536x1772.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1017,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:483965,&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/182567412?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fada89b-e14f-4a7a-9b2d-3b85c8615b16_2536x1772.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_!by0R!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fada89b-e14f-4a7a-9b2d-3b85c8615b16_2536x1772.png 424w, https://substackcdn.com/image/fetch/$s_!by0R!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fada89b-e14f-4a7a-9b2d-3b85c8615b16_2536x1772.png 848w, https://substackcdn.com/image/fetch/$s_!by0R!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fada89b-e14f-4a7a-9b2d-3b85c8615b16_2536x1772.png 1272w, https://substackcdn.com/image/fetch/$s_!by0R!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fada89b-e14f-4a7a-9b2d-3b85c8615b16_2536x1772.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="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>Learn how popular technologies work under the hood and when to use them in interviews:</p><ul><li><p><strong>Databases:</strong> PostgreSQL, MySQL, MongoDB, Cassandra, DynamoDB</p></li><li><p><strong>Caching:</strong> Redis, Memcached</p></li><li><p><strong>Search:</strong> Elasticsearch</p></li><li><p><strong>Messaging:</strong> Kafka, RabbitMQ, SQS</p></li><li><p><strong>Stream Processing:</strong> Flink, Spark</p></li><li><p><strong>Cloud &amp; Infra:</strong> S3, Lambda, Nginx, Docker, Kubernetes</p></li><li><p><strong>Coordination:</strong> Zookeeper, Prometheus</p></li></ul><div><hr></div><h4>20 High-Level Patterns</h4><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!riMz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8126c4c8-b65d-4bbd-af05-1e606aa40e13_2536x1772.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!riMz!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8126c4c8-b65d-4bbd-af05-1e606aa40e13_2536x1772.png 424w, https://substackcdn.com/image/fetch/$s_!riMz!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8126c4c8-b65d-4bbd-af05-1e606aa40e13_2536x1772.png 848w, https://substackcdn.com/image/fetch/$s_!riMz!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8126c4c8-b65d-4bbd-af05-1e606aa40e13_2536x1772.png 1272w, https://substackcdn.com/image/fetch/$s_!riMz!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8126c4c8-b65d-4bbd-af05-1e606aa40e13_2536x1772.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!riMz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8126c4c8-b65d-4bbd-af05-1e606aa40e13_2536x1772.png" width="1456" height="1017" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8126c4c8-b65d-4bbd-af05-1e606aa40e13_2536x1772.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1017,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:497174,&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/182567412?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8126c4c8-b65d-4bbd-af05-1e606aa40e13_2536x1772.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_!riMz!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8126c4c8-b65d-4bbd-af05-1e606aa40e13_2536x1772.png 424w, https://substackcdn.com/image/fetch/$s_!riMz!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8126c4c8-b65d-4bbd-af05-1e606aa40e13_2536x1772.png 848w, https://substackcdn.com/image/fetch/$s_!riMz!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8126c4c8-b65d-4bbd-af05-1e606aa40e13_2536x1772.png 1272w, https://substackcdn.com/image/fetch/$s_!riMz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8126c4c8-b65d-4bbd-af05-1e606aa40e13_2536x1772.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="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 patterns repeat across problems. Learn them once, apply them everywhere:</p><ul><li><p>Realtime Updates</p></li><li><p>Fanout Pattern</p></li><li><p>High Read/Write Traffic</p></li><li><p>Hot Keys</p></li><li><p>Traffic Spikes</p></li><li><p>Handling Large Files</p></li><li><p>Media Streaming</p></li><li><p>Location Data</p></li><li><p>Generating Unique IDs</p></li><li><p>Distributed Counting</p></li><li><p>Leader Election</p></li><li><p>Failure Detection and Handling</p></li><li><p>Recommendations</p></li><li><p>Multi-Tenancy</p></li><li><p>Multi-Region Architecture</p></li><li><p>Deduplicating Data</p></li><li><p>Distributed Transactions</p></li><li><p>Removing Single Points of Failure</p></li></ul><div><hr></div><h4>Interactive Simulations</h4><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!VN3A!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82d47e6f-adbc-4ef8-a10b-590e0206c826_2516x1674.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!VN3A!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82d47e6f-adbc-4ef8-a10b-590e0206c826_2516x1674.png 424w, https://substackcdn.com/image/fetch/$s_!VN3A!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82d47e6f-adbc-4ef8-a10b-590e0206c826_2516x1674.png 848w, https://substackcdn.com/image/fetch/$s_!VN3A!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82d47e6f-adbc-4ef8-a10b-590e0206c826_2516x1674.png 1272w, https://substackcdn.com/image/fetch/$s_!VN3A!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82d47e6f-adbc-4ef8-a10b-590e0206c826_2516x1674.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!VN3A!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82d47e6f-adbc-4ef8-a10b-590e0206c826_2516x1674.png" width="1456" height="969" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/82d47e6f-adbc-4ef8-a10b-590e0206c826_2516x1674.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:969,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:550675,&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/182567412?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82d47e6f-adbc-4ef8-a10b-590e0206c826_2516x1674.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_!VN3A!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82d47e6f-adbc-4ef8-a10b-590e0206c826_2516x1674.png 424w, https://substackcdn.com/image/fetch/$s_!VN3A!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82d47e6f-adbc-4ef8-a10b-590e0206c826_2516x1674.png 848w, https://substackcdn.com/image/fetch/$s_!VN3A!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82d47e6f-adbc-4ef8-a10b-590e0206c826_2516x1674.png 1272w, https://substackcdn.com/image/fetch/$s_!VN3A!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82d47e6f-adbc-4ef8-a10b-590e0206c826_2516x1674.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="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 is interactive simulations for problems to help you better understand the system and functional requirements before diving into the solution.</p><div><hr></div><h3>Quizzes After Each Chapter</h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Kodj!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdcb0d67a-7465-47ce-bf5c-796c32959e0f_1644x1486.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Kodj!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdcb0d67a-7465-47ce-bf5c-796c32959e0f_1644x1486.png 424w, https://substackcdn.com/image/fetch/$s_!Kodj!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdcb0d67a-7465-47ce-bf5c-796c32959e0f_1644x1486.png 848w, https://substackcdn.com/image/fetch/$s_!Kodj!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdcb0d67a-7465-47ce-bf5c-796c32959e0f_1644x1486.png 1272w, https://substackcdn.com/image/fetch/$s_!Kodj!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdcb0d67a-7465-47ce-bf5c-796c32959e0f_1644x1486.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Kodj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdcb0d67a-7465-47ce-bf5c-796c32959e0f_1644x1486.png" width="1456" height="1316" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/dcb0d67a-7465-47ce-bf5c-796c32959e0f_1644x1486.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1316,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:230237,&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/182567412?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdcb0d67a-7465-47ce-bf5c-796c32959e0f_1644x1486.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_!Kodj!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdcb0d67a-7465-47ce-bf5c-796c32959e0f_1644x1486.png 424w, https://substackcdn.com/image/fetch/$s_!Kodj!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdcb0d67a-7465-47ce-bf5c-796c32959e0f_1644x1486.png 848w, https://substackcdn.com/image/fetch/$s_!Kodj!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdcb0d67a-7465-47ce-bf5c-796c32959e0f_1644x1486.png 1272w, https://substackcdn.com/image/fetch/$s_!Kodj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdcb0d67a-7465-47ce-bf5c-796c32959e0f_1644x1486.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="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>Every chapter ends with a quiz to test your understanding. These quizzes help reinforce the concepts and ensure you&#8217;re retaining what you learn before moving to the next topic.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://algomaster.io/learn/system-design-interviews/introduction&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/system-design-interviews/introduction"><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[How to Use AI Effectively in Large Codebases]]></title><description><![CDATA[AI coding assistants are everywhere now.]]></description><link>https://blog.algomaster.io/p/using-ai-effectively-in-large-codebases</link><guid isPermaLink="false">https://blog.algomaster.io/p/using-ai-effectively-in-large-codebases</guid><dc:creator><![CDATA[Ashish Pratap Singh]]></dc:creator><pubDate>Fri, 12 Dec 2025 10:38:06 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!ge-Z!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2313b162-231f-4a2a-8115-888344721b64_1642x1378.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>AI coding assistants are everywhere now.</p><p>GitHub Copilot, Cursor, Claude, ChatGPT. Every developer has tried at least one.</p><p>And for small projects, they work great. But something breaks when you try to use these tools in a <strong>large, production codebase</strong>.</p><p>The suggestions become generic. The AI hallucinates function names that don&#8217;t exist. It confidently tells you to import a module that isn&#8217;t in your project.</p><p>This isn&#8217;t a flaw in the AI models themselves. It&#8217;s a context problem.</p><p>And understanding this problem is the key to actually getting value from AI in professional software development.</p><p>In this article, I&#8217;ll share <strong>why AI struggles</strong> with large codebases and share <strong>practical tips</strong> for using it effectively at that scale.</p><div><hr></div><h1><a href="https://www.augmentcode.com/product/code-review?utm_source=algomaster&amp;utm_medium=newsletter&amp;utm_campaign=influencer">&#128227; Better Context. Better Agent. Better Code. Better Code Review</a>.</h1><p><strong><a href="https://www.augmentcode.com/product/code-review?utm_source=algomaster&amp;utm_medium=newsletter&amp;utm_campaign=influencer">Augment Code</a></strong> is an AI coding assistant built for real-world engineering teams shipping millions of lines of 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_!vFyp!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbaaf0e6-cf98-43eb-9b6a-ce30a47df0f1_1920x1080.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!vFyp!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbaaf0e6-cf98-43eb-9b6a-ce30a47df0f1_1920x1080.png 424w, https://substackcdn.com/image/fetch/$s_!vFyp!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbaaf0e6-cf98-43eb-9b6a-ce30a47df0f1_1920x1080.png 848w, https://substackcdn.com/image/fetch/$s_!vFyp!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbaaf0e6-cf98-43eb-9b6a-ce30a47df0f1_1920x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!vFyp!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbaaf0e6-cf98-43eb-9b6a-ce30a47df0f1_1920x1080.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!vFyp!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbaaf0e6-cf98-43eb-9b6a-ce30a47df0f1_1920x1080.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bbaaf0e6-cf98-43eb-9b6a-ce30a47df0f1_1920x1080.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:691533,&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/181162436?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbaaf0e6-cf98-43eb-9b6a-ce30a47df0f1_1920x1080.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_!vFyp!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbaaf0e6-cf98-43eb-9b6a-ce30a47df0f1_1920x1080.png 424w, https://substackcdn.com/image/fetch/$s_!vFyp!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbaaf0e6-cf98-43eb-9b6a-ce30a47df0f1_1920x1080.png 848w, https://substackcdn.com/image/fetch/$s_!vFyp!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbaaf0e6-cf98-43eb-9b6a-ce30a47df0f1_1920x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!vFyp!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbaaf0e6-cf98-43eb-9b6a-ce30a47df0f1_1920x1080.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="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>They recently launched an industry-leading <strong><a href="https://www.augmentcode.com/product/code-review?utm_source=algomaster&amp;utm_medium=newsletter&amp;utm_campaign=influencer">code review</a> </strong>tool that actually understands context, not just diffs.</p><p>Instead of blindly reacting to changed lines, <strong><a href="https://www.augmentcode.com/product/code-review?utm_source=algomaster&amp;utm_medium=newsletter&amp;utm_campaign=influencer">Augment</a></strong> loads the full picture &#8211; the files your PR touches, the dependencies around them, and the architecture three layers deep.</p><p>What does that look like in practice?</p><ul><li><p>Code reviews with full-codebase awareness, not just the diff you pushed.</p></li><li><p>Inline comments, right in GitHub: no extra dashboards or tools to check.</p></li><li><p>One-click fixes from your IDE or terminal with Augment Code</p></li><li><p>High-signal comments developers actually read</p></li></ul><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.augmentcode.com/product/code-review?utm_source=algomaster&amp;utm_medium=newsletter&amp;utm_campaign=influencer&quot;,&quot;text&quot;:&quot;Try Code Review&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.augmentcode.com/product/code-review?utm_source=algomaster&amp;utm_medium=newsletter&amp;utm_campaign=influencer"><span>Try Code Review</span></a></p><div><hr></div><h1>Why AI Struggles with Large Codebases</h1><p>To understand why AI coding tools struggle at scale, you need to understand how they work.</p><p>When you ask an AI assistant a question about your code, it needs context. Without context, it&#8217;s just guessing based on patterns it learned during training.</p><p>Here&#8217;s the problem: most AI tools have a very limited view of your codebase.</p><h4>What AI sees:</h4><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!d81z!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F10accdec-6b74-4811-a8b8-7be241734e89_662x119.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!d81z!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F10accdec-6b74-4811-a8b8-7be241734e89_662x119.png 424w, https://substackcdn.com/image/fetch/$s_!d81z!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F10accdec-6b74-4811-a8b8-7be241734e89_662x119.png 848w, https://substackcdn.com/image/fetch/$s_!d81z!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F10accdec-6b74-4811-a8b8-7be241734e89_662x119.png 1272w, https://substackcdn.com/image/fetch/$s_!d81z!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F10accdec-6b74-4811-a8b8-7be241734e89_662x119.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!d81z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F10accdec-6b74-4811-a8b8-7be241734e89_662x119.png" width="662" height="119" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/10accdec-6b74-4811-a8b8-7be241734e89_662x119.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:119,&quot;width&quot;:662,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:13289,&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/181162436?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F10accdec-6b74-4811-a8b8-7be241734e89_662x119.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_!d81z!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F10accdec-6b74-4811-a8b8-7be241734e89_662x119.png 424w, https://substackcdn.com/image/fetch/$s_!d81z!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F10accdec-6b74-4811-a8b8-7be241734e89_662x119.png 848w, https://substackcdn.com/image/fetch/$s_!d81z!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F10accdec-6b74-4811-a8b8-7be241734e89_662x119.png 1272w, https://substackcdn.com/image/fetch/$s_!d81z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F10accdec-6b74-4811-a8b8-7be241734e89_662x119.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><h4>What it needs to see:</h4><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ge-Z!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2313b162-231f-4a2a-8115-888344721b64_1642x1378.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ge-Z!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2313b162-231f-4a2a-8115-888344721b64_1642x1378.png 424w, https://substackcdn.com/image/fetch/$s_!ge-Z!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2313b162-231f-4a2a-8115-888344721b64_1642x1378.png 848w, https://substackcdn.com/image/fetch/$s_!ge-Z!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2313b162-231f-4a2a-8115-888344721b64_1642x1378.png 1272w, https://substackcdn.com/image/fetch/$s_!ge-Z!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2313b162-231f-4a2a-8115-888344721b64_1642x1378.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ge-Z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2313b162-231f-4a2a-8115-888344721b64_1642x1378.png" width="608" height="510.2857142857143" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2313b162-231f-4a2a-8115-888344721b64_1642x1378.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1222,&quot;width&quot;:1456,&quot;resizeWidth&quot;:608,&quot;bytes&quot;:167547,&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/181162436?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2313b162-231f-4a2a-8115-888344721b64_1642x1378.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_!ge-Z!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2313b162-231f-4a2a-8115-888344721b64_1642x1378.png 424w, https://substackcdn.com/image/fetch/$s_!ge-Z!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2313b162-231f-4a2a-8115-888344721b64_1642x1378.png 848w, https://substackcdn.com/image/fetch/$s_!ge-Z!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2313b162-231f-4a2a-8115-888344721b64_1642x1378.png 1272w, https://substackcdn.com/image/fetch/$s_!ge-Z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2313b162-231f-4a2a-8115-888344721b64_1642x1378.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="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>The Context Window Problem</h3><p>Every LLM has a context window, the maximum amount of text it can consider at once. Even with context windows of 100K+ tokens, you can&#8217;t just dump your entire codebase into a prompt.</p><p>A typical production codebase might have:</p><ul><li><p>10,000+ source files</p></li><li><p>1 million+ lines of code</p></li><li><p>Hundreds of internal APIs</p></li><li><p>Years of accumulated conventions and patterns</p></li></ul><p>You can&#8217;t fit that into any context window. So AI tools have to be selective about what they include.</p><p>Most tools solve this by looking at:</p><ul><li><p>The file you&#8217;re currently editing</p></li><li><p>Maybe a few open tabs</p></li><li><p>Sometimes files you&#8217;ve recently viewed</p></li></ul><p>That&#8217;s it. The AI has no idea about your authentication service three directories over, the utility functions your team uses constantly, or the database schema that defines your data model.</p><h3>The Stale Context Problem</h3><p>Here&#8217;s another issue that gets overlooked: your codebase changes constantly.</p><p>You switch branches multiple times a day. Your teammates merge PRs. You run search-and-replace across dozens of files. The code that existed five minutes ago might not exist now.</p><p>Most AI indexing systems update on a schedule, often every 10 minutes or longer. In that time, you might have:</p><ul><li><p>Switched to a feature branch</p></li><li><p>Renamed a key function</p></li><li><p>Added new type definitions</p></li><li><p>Merged in your colleague&#8217;s changes</p></li></ul><p>If the AI&#8217;s understanding of your codebase is 10 minutes old, it&#8217;s working with outdated information. It might suggest importing a module that was just renamed, or recommend a function signature that no longer exists.</p><p>This is especially painful when you&#8217;re doing <a href="https://www.augmentcode.com/product/code-review?utm_source=algomaster&amp;utm_medium=newsletter&amp;utm_campaign=influencer">code review</a>. You check out a PR branch, ask the AI about the changes, and it responds based on the main branch because its index hasn&#8217;t caught up yet.</p><div><hr></div><h1>The Retrieval Problem (And Why It Matters)</h1><p>At its core, making AI useful in large codebases is a retrieval problem.</p><p>The AI model itself is powerful. GPT-4, Claude, and others can understand and generate code remarkably well. The bottleneck is getting the right context into the model&#8217;s prompt before it generates a response.</p><p>This is conceptually similar to RAG (Retrieval Augmented Generation) for documents, but with code-specific challenges:</p><h4>Code relationships are complex</h4><p>Unlike documents, code has rich structural relationships. A function definition isn&#8217;t just similar to its call sites textually, it&#8217;s semantically connected. Documentation isn&#8217;t necessarily similar to the code it describes.</p><p>Generic embedding models trained on text don&#8217;t capture these relationships well.</p><h4>Context relevance isn&#8217;t just about similarity</h4><p>When you&#8217;re writing code, the most &#8220;relevant&#8221; context isn&#8217;t always the most similar text. If you&#8217;re implementing a new API endpoint, you probably need:</p><ul><li><p>Similar endpoints for pattern matching</p></li><li><p>The authentication middleware</p></li><li><p>Data validation utilities</p></li><li><p>Database query helpers</p></li><li><p>Error handling conventions</p></li></ul><p>These aren&#8217;t necessarily textually similar to what you&#8217;re writing, but they&#8217;re essential context.</p><h4>Some &#8220;relevant&#8221; context is actually useless</h4><p>Here&#8217;s a counterintuitive point: sometimes the most semantically similar code is the least helpful.</p><p>If you&#8217;re using PyTorch and the AI retrieves PyTorch source code, that&#8217;s probably not useful. The model already knows how PyTorch works. It was trained on that. What it doesn&#8217;t know is your specific project structure, your team&#8217;s conventions, your custom utilities.</p><p>The ideal retrieval system prioritizes helpfulness over raw relevance.</p><div><hr></div><h1>What Actually Works</h1><p>After years of trying to make AI useful in professional development, here&#8217;s what I&#8217;ve learned actually matters:</p><h3>1. Deep Codebase Indexing</h3><p>The AI needs to understand your entire codebase, not just open files.</p><p>This means:</p><ul><li><p>Indexing all source files, not just recent ones</p></li><li><p>Understanding relationships between files (imports, dependencies, call graphs)</p></li><li><p>Capturing type definitions, interfaces, and schemas</p></li><li><p>Learning your project structure and conventions</p></li></ul><p>The index also needs to stay current. If you switch branches, the AI should immediately understand the new state of the code. If you rename a function, it should know about that within seconds, not minutes.</p><h3>2. Context-Aware Retrieval</h3><p>When you ask a question or request a code change, the AI needs to pull in relevant context intelligently.</p><p>Good retrieval considers:</p><ul><li><p><strong>Direct relationships</strong>: What files import this one? What does this file import?</p></li><li><p><strong>Semantic relationships</strong>: What other code does similar things?</p></li><li><p><strong>Structural context</strong>: What&#8217;s the project structure around this file?</p></li><li><p><strong>Historical patterns</strong>: How has your team solved similar problems before?</p></li></ul><h3>3. Branch-Aware Understanding</h3><p>Your AI assistant needs to understand that you work on branches.</p><p>When you switch from <code>main</code> to <code>feature/new-auth</code>, everything changes. The AI should:</p><ul><li><p>Immediately understand the new branch state</p></li><li><p>Not mix up code from different branches</p></li><li><p>Handle rebases and merges gracefully</p></li><li><p>Provide suggestions based on the current branch, not a stale main</p></li></ul><h3>4. Security-Conscious Architecture</h3><p>For production codebases, security isn&#8217;t optional.</p><p>The AI system should:</p><ul><li><p>Respect access controls (don&#8217;t retrieve code the user can&#8217;t access)</p></li><li><p>Not send sensitive code to third-party APIs unnecessarily</p></li><li><p>Maintain audit trails of what was accessed</p></li><li><p>Comply with your organization&#8217;s security requirements</p></li></ul><div><hr></div><h1>How <a href="https://www.augmentcode.com/product/code-review?utm_source=algomaster&amp;utm_medium=newsletter&amp;utm_campaign=influencer">Augment Code</a> Approaches This</h1><p>This is where I want to talk about <strong><a href="https://www.augmentcode.com/product/code-review?utm_source=algomaster&amp;utm_medium=newsletter&amp;utm_campaign=influencer">Augment Code</a></strong>, our sponsor for this post.</p><p>I&#8217;ve been using Augment for the past few weeks, and it solves many of the problems I described above in ways that other tools don&#8217;t.</p><h3>Real-Time Indexing</h3><p>Augment maintains a personal search index for each developer that updates within seconds of code changes.</p><p>When you switch branches in git, when you do a search-and-replace across 100 files, when your colleague&#8217;s PR gets merged, Augment&#8217;s index reflects those changes almost immediately.</p><p>I tested it.</p><p>I downloaded the Kafka source code from GitHub (around 7,000 files, 300+ MB). Augment indexed it in under a minute. I asked questions about Kafka&#8217;s internals, like &#8220;show me the code path for storing messages to log files&#8221;, and it found the relevant code paths accurately.</p><p>On my own project (1,000+ files), the index updated in about 10 seconds.</p><h3>Custom Embedding Models</h3><p>Augment doesn&#8217;t use generic embedding models like most tools.</p><p>They&#8217;ve trained custom models specifically for code retrieval. These models understand that:</p><ul><li><p>A function call site is related to its definition (even though they look different)</p></li><li><p>Documentation is related to the code it describes</p></li><li><p>Code in different languages can be semantically related</p></li><li><p>Common library code (like PyTorch internals) doesn&#8217;t need to be retrieved since the model already knows it</p></li></ul><p>This matters because generic embeddings optimized for text similarity often miss the connections that matter in code.</p><h3>The Prompt Enhancer</h3><p>This is something Augment users consistently mention as their favorite feature.</p><p>You don&#8217;t have to be a prompt engineer to get good results. The system takes your simple request and automatically enriches it with relevant context from your codebase.</p><p>I tested this on my website project. I gave it a minimal prompt: &#8220;Update comment component to allow users to edit their comments.&#8221;</p><p>No additional context. No file paths. No architecture explanation.</p><p>Augment built the complete feature in one prompt: UI components, database calls, edge case handling, everything. It understood my project&#8217;s patterns, my component structure, my database schema, and generated code that fit naturally.</p><p>That&#8217;s what good retrieval enables. The model has all the context it needs to make intelligent decisions.</p><h3>Security By Design</h3><p>Augment self-hosts their embedding search and doesn&#8217;t use third-party APIs for retrieval. This matters because research has shown that embeddings can be reverse-engineered back to source code.</p><p>They also implement proof-of-possession for file access. The IDE has to prove it knows a file&#8217;s content before the backend will return information about that file. This prevents retrieving code you&#8217;re not authorized to access.</p><div><hr></div><h1>Practical Tips for Using AI in Large Codebases</h1><p>Whether you&#8217;re using <strong><a href="https://www.augmentcode.com/product/code-review?utm_source=algomaster&amp;utm_medium=newsletter&amp;utm_campaign=influencer">Augment</a></strong> or another tool, here are strategies that help:</p><h3>1. Provide Explicit Context</h3><p>Don&#8217;t assume the AI knows your codebase structure.</p><p><strong>Instead of:</strong></p><pre><code>Fix the bug in the user service</code></pre><p><strong>Try:</strong></p><pre><code>In src/services/user/authentication.ts, the validateToken
function is not checking token expiration correctly.
It should use the exp claim from the JWT payload.</code></pre><p>Explicit file paths and specific details help the AI focus on the right area.</p><h3>2. Reference Related Files</h3><p>If you know what files are relevant, mention them.</p><pre><code>Update the UserProfile component (src/components/UserProfile.tsx)
to display the user&#8217;s subscription status.

The subscription data comes from the useSubscription hook
(src/hooks/useSubscription.ts) and follows the same pattern
as the useAccount hook.</code></pre><h3>3. Explain Your Conventions</h3><p>AI tools don&#8217;t automatically know your team&#8217;s patterns.</p><pre><code>Create a new API endpoint for updating user preferences.

Follow the same pattern as the existing endpoints in
src/api/routes/:
- Use the validateRequest middleware
- Return responses using the ApiResponse wrapper
- Log errors to the auditLogger</code></pre><h3>4. Work Iteratively</h3><p>Don&#8217;t expect perfect results on the first try.</p><p>Start with a simple request, review what the AI generates, and provide corrections. Each iteration helps narrow in on what you actually need.</p><h3>5. Use AI for Exploration</h3><p>Large codebases are hard to navigate. AI tools excel at questions like:</p><ul><li><p>&#8220;How does authentication work in this codebase?&#8221;</p></li><li><p>&#8220;What&#8217;s the flow when a user places an order?&#8221;</p></li><li><p>&#8220;Where is the database connection configured?&#8221;</p></li></ul><p>These exploration queries help you get oriented quickly, even in unfamiliar code.</p><div><hr></div><h2>The Future of AI in Professional Development</h2><p>The tools we have today are just the beginning.</p><p>As retrieval systems get better, as context windows expand, and as models become more capable, AI assistants will become genuinely useful for complex professional work.</p><p>The key insight is that model capability isn&#8217;t the bottleneck anymore. Context is. The teams building the best code understanding, the best retrieval systems, and the best context management will build the most useful tools.</p><p>This is why I&#8217;m excited about tools like <strong><a href="https://www.augmentcode.com/product/code-review?utm_source=algomaster&amp;utm_medium=newsletter&amp;utm_campaign=influencer">Augment</a></strong> that focus specifically on professional development in large codebases. They&#8217;re solving the hard problems that make AI actually useful, not just impressive in demos.</p><div><hr></div><h2><a href="https://www.augmentcode.com/product/code-review?utm_source=algomaster&amp;utm_medium=newsletter&amp;utm_campaign=influencer">Try Augment Code</a></h2><p>If you work with large codebases and want to see what proper context awareness looks like, <strong><a href="https://www.augmentcode.com/product/code-review?utm_source=algomaster&amp;utm_medium=newsletter&amp;utm_campaign=influencer">try Augment Code</a></strong>.</p><p>They have:</p><ul><li><p>VS Code and JetBrains extensions</p></li><li><p>A CLI tool for terminal users</p></li><li><p>SOC 2 Type II compliance for enterprise requirements</p></li><li><p>A free trial to test it on your own codebase</p></li><li><p>A newly launched industry leading code review tool</p></li></ul><p>The best way to evaluate any AI tool is to try it on your actual work. See if it understands your codebase, your conventions, your patterns.</p>]]></content:encoded></item><item><title><![CDATA[Pub-Sub vs Message Queue vs Message Broker]]></title><description><![CDATA[What&#8217;s the difference?]]></description><link>https://blog.algomaster.io/p/pub-sub-vs-message-queue-vs-message-broker</link><guid isPermaLink="false">https://blog.algomaster.io/p/pub-sub-vs-message-queue-vs-message-broker</guid><dc:creator><![CDATA[Ashish Pratap Singh]]></dc:creator><pubDate>Wed, 10 Dec 2025 04:57:26 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!kC8x!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48800e6c-b0e5-4fe0-a9e4-7f667b1e66a7_1830x1388.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When you&#8217;re working on a distributed system and need components to <strong>communicate asynchronously</strong>, you&#8217;ll hear terms like: <strong>&#8220;pub-sub&#8221;, &#8220;message queue&#8221;</strong>, and <strong>&#8220;message broker&#8221;</strong>.</p><p>Although they are used interchangeably sometimes, they&#8217;re not the same thing.</p><p><strong>Simply put:</strong></p><blockquote><p>A message broker is the <strong>infrastructure</strong>. Message queues and pub-sub are <strong>messaging patterns</strong> that brokers implement.</p></blockquote><p>In this article, we&#8217;ll explore:</p><ul><li><p>What each term means</p></li><li><p>How they differ architecturally</p></li><li><p>When to use each pattern</p></li><li><p>Real-world examples and use cases</p></li><li><p>How modern systems like Kafka, RabbitMQ, and Redis fit in</p></li></ul><div><hr></div><h1>1. The Core Concepts</h1><p>Before diving into comparisons, let&#8217;s define each term clearly.</p><h2>1.1 Message Broker</h2><p>A <strong>message broker</strong> is the middleware infrastructure that receives, stores, and routes messages between producers and consumers. It&#8217;s the &#8220;thing&#8221; that sits in the middle.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!VjPv!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F174a1db8-0687-48b2-b2f7-e9e37a3ec1c6_1962x548.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!VjPv!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F174a1db8-0687-48b2-b2f7-e9e37a3ec1c6_1962x548.png 424w, https://substackcdn.com/image/fetch/$s_!VjPv!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F174a1db8-0687-48b2-b2f7-e9e37a3ec1c6_1962x548.png 848w, https://substackcdn.com/image/fetch/$s_!VjPv!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F174a1db8-0687-48b2-b2f7-e9e37a3ec1c6_1962x548.png 1272w, https://substackcdn.com/image/fetch/$s_!VjPv!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F174a1db8-0687-48b2-b2f7-e9e37a3ec1c6_1962x548.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!VjPv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F174a1db8-0687-48b2-b2f7-e9e37a3ec1c6_1962x548.png" width="694" height="193.99587912087912" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/174a1db8-0687-48b2-b2f7-e9e37a3ec1c6_1962x548.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:407,&quot;width&quot;:1456,&quot;resizeWidth&quot;:694,&quot;bytes&quot;:60173,&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/173210098?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F174a1db8-0687-48b2-b2f7-e9e37a3ec1c6_1962x548.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_!VjPv!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F174a1db8-0687-48b2-b2f7-e9e37a3ec1c6_1962x548.png 424w, https://substackcdn.com/image/fetch/$s_!VjPv!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F174a1db8-0687-48b2-b2f7-e9e37a3ec1c6_1962x548.png 848w, https://substackcdn.com/image/fetch/$s_!VjPv!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F174a1db8-0687-48b2-b2f7-e9e37a3ec1c6_1962x548.png 1272w, https://substackcdn.com/image/fetch/$s_!VjPv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F174a1db8-0687-48b2-b2f7-e9e37a3ec1c6_1962x548.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Think of a message broker like a post office. It receives mail (messages), stores it temporarily, and delivers it to the right recipients based on addresses (routing rules).</p><p><strong>Examples:</strong> RabbitMQ, Apache Kafka, ActiveMQ</p><h4>Key responsibilities:</h4><ul><li><p>Accept messages from producers</p></li><li><p>Store messages durably or transiently</p></li><li><p>Route messages to appropriate consumers</p></li><li><p>Handle delivery guarantees (at-least-once, exactly-once)</p></li><li><p>Manage consumer acknowledgments</p></li></ul><h2>1.2 Message Queue</h2><p>A <strong>message queue</strong> is a messaging pattern where messages are sent to a queue and consumed by exactly one consumer. Messages are typically processed in order and removed from the queue after consumption.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!SGXq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2726eea3-4c83-4894-8c3e-f1788fc9841e_1902x588.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!SGXq!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2726eea3-4c83-4894-8c3e-f1788fc9841e_1902x588.png 424w, https://substackcdn.com/image/fetch/$s_!SGXq!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2726eea3-4c83-4894-8c3e-f1788fc9841e_1902x588.png 848w, https://substackcdn.com/image/fetch/$s_!SGXq!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2726eea3-4c83-4894-8c3e-f1788fc9841e_1902x588.png 1272w, https://substackcdn.com/image/fetch/$s_!SGXq!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2726eea3-4c83-4894-8c3e-f1788fc9841e_1902x588.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!SGXq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2726eea3-4c83-4894-8c3e-f1788fc9841e_1902x588.png" width="1456" height="450" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2726eea3-4c83-4894-8c3e-f1788fc9841e_1902x588.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:450,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:67815,&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/173210098?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2726eea3-4c83-4894-8c3e-f1788fc9841e_1902x588.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_!SGXq!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2726eea3-4c83-4894-8c3e-f1788fc9841e_1902x588.png 424w, https://substackcdn.com/image/fetch/$s_!SGXq!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2726eea3-4c83-4894-8c3e-f1788fc9841e_1902x588.png 848w, https://substackcdn.com/image/fetch/$s_!SGXq!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2726eea3-4c83-4894-8c3e-f1788fc9841e_1902x588.png 1272w, https://substackcdn.com/image/fetch/$s_!SGXq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2726eea3-4c83-4894-8c3e-f1788fc9841e_1902x588.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="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>Message queues enable <strong>asynchronous service-to-service communication</strong>, especially in serverless and microservices architectures. They allow you to build reliable background processing, work distribution, and decoupled systems.</p><p><strong>Examples: </strong>SQS queues, RabbitMQ queues</p><p>When multiple consumers connect to the same queue, they compete for messages. Each message goes to exactly one consumer.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!QzR0!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fed34852e-2684-4403-b2b7-7270f92065ca_1810x904.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!QzR0!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fed34852e-2684-4403-b2b7-7270f92065ca_1810x904.png 424w, https://substackcdn.com/image/fetch/$s_!QzR0!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fed34852e-2684-4403-b2b7-7270f92065ca_1810x904.png 848w, https://substackcdn.com/image/fetch/$s_!QzR0!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fed34852e-2684-4403-b2b7-7270f92065ca_1810x904.png 1272w, https://substackcdn.com/image/fetch/$s_!QzR0!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fed34852e-2684-4403-b2b7-7270f92065ca_1810x904.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!QzR0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fed34852e-2684-4403-b2b7-7270f92065ca_1810x904.png" width="656" height="327.54945054945057" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ed34852e-2684-4403-b2b7-7270f92065ca_1810x904.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:727,&quot;width&quot;:1456,&quot;resizeWidth&quot;:656,&quot;bytes&quot;:80821,&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/173210098?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fed34852e-2684-4403-b2b7-7270f92065ca_1810x904.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_!QzR0!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fed34852e-2684-4403-b2b7-7270f92065ca_1810x904.png 424w, https://substackcdn.com/image/fetch/$s_!QzR0!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fed34852e-2684-4403-b2b7-7270f92065ca_1810x904.png 848w, https://substackcdn.com/image/fetch/$s_!QzR0!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fed34852e-2684-4403-b2b7-7270f92065ca_1810x904.png 1272w, https://substackcdn.com/image/fetch/$s_!QzR0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fed34852e-2684-4403-b2b7-7270f92065ca_1810x904.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h4>Key Characteristics:</h4><ul><li><p><strong>Delivery: </strong>Exactly one consumer receives each message</p></li><li><p><strong>Ordering: </strong>First-In-First-Out (FIFO) ordering within a single queue</p></li><li><p><strong>Persistence: </strong>Messages stored until consumed and acknowledged</p></li><li><p><strong>Acknowledgment: </strong>Consumer must confirm successful processing</p></li><li><p><strong>Retry: </strong>Failed messages can be retried or dead-lettered</p></li></ul><h2>1.3 Pub-Sub (Publish-Subscribe)</h2><p><strong>Pub-Sub</strong> is a messaging pattern where publishers send messages to topics, and all subscribers to that topic receive a copy of the message. Messages are broadcast, not consumed exclusively.</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ZveM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ef3ab1f-d1a7-4cfc-909b-5869cadc3265_1988x836.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ZveM!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ef3ab1f-d1a7-4cfc-909b-5869cadc3265_1988x836.png 424w, https://substackcdn.com/image/fetch/$s_!ZveM!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ef3ab1f-d1a7-4cfc-909b-5869cadc3265_1988x836.png 848w, https://substackcdn.com/image/fetch/$s_!ZveM!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ef3ab1f-d1a7-4cfc-909b-5869cadc3265_1988x836.png 1272w, https://substackcdn.com/image/fetch/$s_!ZveM!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ef3ab1f-d1a7-4cfc-909b-5869cadc3265_1988x836.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ZveM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ef3ab1f-d1a7-4cfc-909b-5869cadc3265_1988x836.png" width="710" height="298.4340659340659" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9ef3ab1f-d1a7-4cfc-909b-5869cadc3265_1988x836.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:612,&quot;width&quot;:1456,&quot;resizeWidth&quot;:710,&quot;bytes&quot;:86340,&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/173210098?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ef3ab1f-d1a7-4cfc-909b-5869cadc3265_1988x836.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_!ZveM!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ef3ab1f-d1a7-4cfc-909b-5869cadc3265_1988x836.png 424w, https://substackcdn.com/image/fetch/$s_!ZveM!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ef3ab1f-d1a7-4cfc-909b-5869cadc3265_1988x836.png 848w, https://substackcdn.com/image/fetch/$s_!ZveM!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ef3ab1f-d1a7-4cfc-909b-5869cadc3265_1988x836.png 1272w, https://substackcdn.com/image/fetch/$s_!ZveM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ef3ab1f-d1a7-4cfc-909b-5869cadc3265_1988x836.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="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>Think of it like a radio broadcast. The station (publisher) broadcasts a signal (message), and everyone tuned to that frequency (subscribers) receives it simultaneously.</p><p>It&#8217;s an <strong>asynchronous communication</strong> model that decouples services, making it easier to build <strong>scalable, event-driven systems</strong>. Pub/Sub is widely used in modern cloud architectures to deliver instant event notifications and enable reliable communication between independent components.</p><p><strong>Examples: </strong>Redis Pub/Sub, SNS</p><p>Pub-sub naturally implements fan-out in event-drive architectures, where one event triggers multiple actions:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ZdUz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2056c392-d7ce-4dec-9945-3dcc47baf27f_1852x758.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ZdUz!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2056c392-d7ce-4dec-9945-3dcc47baf27f_1852x758.png 424w, https://substackcdn.com/image/fetch/$s_!ZdUz!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2056c392-d7ce-4dec-9945-3dcc47baf27f_1852x758.png 848w, https://substackcdn.com/image/fetch/$s_!ZdUz!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2056c392-d7ce-4dec-9945-3dcc47baf27f_1852x758.png 1272w, https://substackcdn.com/image/fetch/$s_!ZdUz!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2056c392-d7ce-4dec-9945-3dcc47baf27f_1852x758.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ZdUz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2056c392-d7ce-4dec-9945-3dcc47baf27f_1852x758.png" width="672" height="275.0769230769231" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2056c392-d7ce-4dec-9945-3dcc47baf27f_1852x758.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:596,&quot;width&quot;:1456,&quot;resizeWidth&quot;:672,&quot;bytes&quot;:67750,&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/173210098?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2056c392-d7ce-4dec-9945-3dcc47baf27f_1852x758.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_!ZdUz!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2056c392-d7ce-4dec-9945-3dcc47baf27f_1852x758.png 424w, https://substackcdn.com/image/fetch/$s_!ZdUz!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2056c392-d7ce-4dec-9945-3dcc47baf27f_1852x758.png 848w, https://substackcdn.com/image/fetch/$s_!ZdUz!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2056c392-d7ce-4dec-9945-3dcc47baf27f_1852x758.png 1272w, https://substackcdn.com/image/fetch/$s_!ZdUz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2056c392-d7ce-4dec-9945-3dcc47baf27f_1852x758.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h4>Key Characteristics:</h4><ul><li><p><strong>Delivery: </strong>One-to-many. Each message delivered to all subscribers.</p></li><li><p><strong>Decoupling: </strong>Publishers and subscribers are decoupled</p></li><li><p><strong>Scalability: </strong>Easy to add new subscribers</p></li><li><p><strong>Persistence: </strong>Messages may or may not be removed after delivery (depends on implementation)</p></li></ul><div><hr></div><h1>2. How Brokers Implement Both</h1>
      <p>
          <a href="https://blog.algomaster.io/p/pub-sub-vs-message-queue-vs-message-broker">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Why You Should NEVER Start With Microservices]]></title><description><![CDATA[The hidden cost of premature optimization]]></description><link>https://blog.algomaster.io/p/why-you-should-never-start-with-microservices</link><guid isPermaLink="false">https://blog.algomaster.io/p/why-you-should-never-start-with-microservices</guid><dc:creator><![CDATA[Ashish Pratap Singh]]></dc:creator><pubDate>Mon, 08 Dec 2025 03:40:18 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!kPsl!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9891d75a-3c7f-4b21-b600-aadd10428032_1412x1038.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>You&#8217;re starting a new project. You&#8217;ve read about how <strong>Netflix</strong>, <strong>Amazon</strong>, and <strong>Uber</strong> use microservices to handle millions of requests.</p><p>You want to build something scalable from day one.</p><p>So you begin designing your system with separate services for users, orders, payments, notifications, and inventory. Each with its own database, its own deployment pipeline, its own monitoring setup.</p><p>Six months later, you have 15 services, a team of 3 developers, and you&#8217;re spending 80% of your time debugging distributed system issues instead of building features.</p><p>This is the <strong>microservices trap</strong>, and it catches more teams than you might think.</p><p>In this article, I&#8217;ll explain:</p><ul><li><p>Why microservices are exciting but dangerous for new projects</p></li><li><p>The hidden costs that nobody talks about</p></li><li><p>When microservices actually make sense</p></li><li><p>The &#8220;Monolith First&#8221; approach and why it works</p></li><li><p>Why microservices are important in System Design Interviews</p></li></ul><div><hr></div><h1>The Microservices Hype</h1><p>Microservices sound exciting and they always look impressive in system design interviews.</p><p>The idea of having small, independent services that can be developed, deployed, and scaled independently sounds like engineering nirvana.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!8MUF!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06ea7e94-ef62-40fe-8c49-432b054aee04_1410x758.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!8MUF!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06ea7e94-ef62-40fe-8c49-432b054aee04_1410x758.png 424w, https://substackcdn.com/image/fetch/$s_!8MUF!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06ea7e94-ef62-40fe-8c49-432b054aee04_1410x758.png 848w, https://substackcdn.com/image/fetch/$s_!8MUF!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06ea7e94-ef62-40fe-8c49-432b054aee04_1410x758.png 1272w, https://substackcdn.com/image/fetch/$s_!8MUF!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06ea7e94-ef62-40fe-8c49-432b054aee04_1410x758.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!8MUF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06ea7e94-ef62-40fe-8c49-432b054aee04_1410x758.png" width="692" height="372.0113475177305" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/06ea7e94-ef62-40fe-8c49-432b054aee04_1410x758.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:758,&quot;width&quot;:1410,&quot;resizeWidth&quot;:692,&quot;bytes&quot;:65365,&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/177345058?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06ea7e94-ef62-40fe-8c49-432b054aee04_1410x758.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_!8MUF!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06ea7e94-ef62-40fe-8c49-432b054aee04_1410x758.png 424w, https://substackcdn.com/image/fetch/$s_!8MUF!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06ea7e94-ef62-40fe-8c49-432b054aee04_1410x758.png 848w, https://substackcdn.com/image/fetch/$s_!8MUF!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06ea7e94-ef62-40fe-8c49-432b054aee04_1410x758.png 1272w, https://substackcdn.com/image/fetch/$s_!8MUF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06ea7e94-ef62-40fe-8c49-432b054aee04_1410x758.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>When you read about microservices, you hear about:</p><ul><li><p><strong>Independent deployments</strong>: Deploy one service without affecting others</p></li><li><p><strong>Technology flexibility</strong>: Use the best language/framework for each service</p></li><li><p><strong>Team autonomy</strong>: Small teams own their services end-to-end</p></li><li><p><strong>Scalability</strong>: Scale only the services that need it</p></li><li><p><strong>Fault isolation</strong>: One service failure doesn&#8217;t bring down the system</p></li></ul><p>These benefits are real. But they come with a catch.</p><blockquote><p><strong>These benefits only materialize at scale, both in terms of traffic AND team size.</strong></p></blockquote><p>For a startup or small team, microservices don&#8217;t just fail to provide these benefits. They actively work against you.</p><p>Let me show you why.</p><div><hr></div><h1>The Hidden Costs of Microservices</h1><h2>1. Distributed Systems Complexity</h2><p>The moment you split your application into multiple services, you&#8217;ve created a distributed system. And distributed systems are <strong>hard</strong>.</p><p>Problems that didn&#8217;t exist in a monolith suddenly become your daily reality:</p><ul><li><p><strong>Network failures</strong> - Service A can&#8217;t reach Service B. Now what?</p></li><li><p><strong>Latency</strong> - A function call that took microseconds is now a network call taking milliseconds</p></li><li><p><strong>Data consistency</strong> - How do you maintain consistency across multiple databases?</p></li><li><p><strong>Debugging nightmares</strong> - A single request might touch 10 services. Good luck tracing that error.</p></li></ul><p>In a monolith, calling a function is guaranteed to either work or throw an exception.</p><p>In microservices, a service call can:</p><ul><li><p>Succeed</p></li><li><p>Fail with an error</p></li><li><p>Timeout (but did it actually succeed?)</p></li><li><p>Succeed but return stale data</p></li><li><p>Succeed on retry but cause duplicate operations</p></li></ul><p>Each of these scenarios requires different handling. Multiply this by every service-to-service call in your system.</p><h3>What about debugging?</h3><p>In a monolith you get a stack trace.</p><p>In a microservices architecture, a single user request might touch 10 different services. When something goes wrong, you need to trace through logs across all of them, correlate timestamps, and figure out which service caused the failure.</p><p>But distributed complexity is just the beginning. How do you even manage all these services?</p><h2>2. Operational Overhead</h2><p>A monolith means one thing to deploy, monitor, and maintain.</p><p>With microservices, everything multiplies:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Ufsm!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F45e14638-771a-4ffc-a1c8-82bee1aa4c83_1584x880.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Ufsm!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F45e14638-771a-4ffc-a1c8-82bee1aa4c83_1584x880.png 424w, https://substackcdn.com/image/fetch/$s_!Ufsm!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F45e14638-771a-4ffc-a1c8-82bee1aa4c83_1584x880.png 848w, https://substackcdn.com/image/fetch/$s_!Ufsm!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F45e14638-771a-4ffc-a1c8-82bee1aa4c83_1584x880.png 1272w, https://substackcdn.com/image/fetch/$s_!Ufsm!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F45e14638-771a-4ffc-a1c8-82bee1aa4c83_1584x880.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Ufsm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F45e14638-771a-4ffc-a1c8-82bee1aa4c83_1584x880.png" width="632" height="351.15934065934067" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/45e14638-771a-4ffc-a1c8-82bee1aa4c83_1584x880.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:809,&quot;width&quot;:1456,&quot;resizeWidth&quot;:632,&quot;bytes&quot;:104649,&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/177345058?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F45e14638-771a-4ffc-a1c8-82bee1aa4c83_1584x880.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_!Ufsm!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F45e14638-771a-4ffc-a1c8-82bee1aa4c83_1584x880.png 424w, https://substackcdn.com/image/fetch/$s_!Ufsm!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F45e14638-771a-4ffc-a1c8-82bee1aa4c83_1584x880.png 848w, https://substackcdn.com/image/fetch/$s_!Ufsm!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F45e14638-771a-4ffc-a1c8-82bee1aa4c83_1584x880.png 1272w, https://substackcdn.com/image/fetch/$s_!Ufsm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F45e14638-771a-4ffc-a1c8-82bee1aa4c83_1584x880.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="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&#8217;ll also need additional infrastructure that a monolith simply doesn&#8217;t require:</p><ul><li><p><strong>Service discovery</strong>: How do services find each other?</p></li><li><p><strong>API Gateway</strong>: How do external clients reach your services?</p></li><li><p><strong>Distributed tracing</strong>: How do you debug across services?</p></li><li><p><strong>Circuit breakers</strong>: How do you handle cascading failures?</p></li><li><p><strong>Message queues</strong>: How do services communicate asynchronously?</p></li></ul><p>Each of these adds complexity, cost, and potential failure points. A small team can easily spend more time managing infrastructure than building features.</p><p>Speaking of performance costs, let&#8217;s look at what happens to your application&#8217;s speed.</p><h2>3. Network Is Now Your Bottleneck</h2><p>In a monolith, data access is fast <code>(~1 microsecond)</code>. Objects are in memory or a single database call away.</p><p>In microservices, what was once a method call is now:</p><pre><code><code>1. Serialize request to JSON           ~0.5ms
2. DNS lookup                          ~1-10ms
3. TCP connection                      ~1-5ms
4. TLS handshake                       ~5-30ms
5. Send HTTP request                   ~1-5ms
6. Service B processes                 ~varies
7. Serialize response                  ~0.5ms
8. Network transfer back               ~1-5ms
9. Deserialize response                ~0.5ms

Time: 10-50+ milliseconds (10,000x slower!)       </code></code></pre><p>This overhead adds up quickly. A page that required 5 internal method calls in a monolith might now require 5 network calls, each adding 10-50ms of latency. </p><h2>4. Data Management Becomes a Nightmare</h2><p>One of the &#8220;benefits&#8221; of microservices is that each service owns its data. But this creates serious challenges.</p><h3>The Join Problem</h3><p>In a monolith, you can easily join users with orders with products in a single SQL query:</p><pre><code>SELECT u.name, o.total, p.title
FROM users u
JOIN orders o ON u.id = o.user_id
JOIN order_items oi ON o.id = oi.order_id
JOIN products p ON oi.product_id = p.id
WHERE u.id = 123;</code></pre><p>In microservices, the same data lives in different databases:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!kPsl!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9891d75a-3c7f-4b21-b600-aadd10428032_1412x1038.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!kPsl!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9891d75a-3c7f-4b21-b600-aadd10428032_1412x1038.png 424w, https://substackcdn.com/image/fetch/$s_!kPsl!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9891d75a-3c7f-4b21-b600-aadd10428032_1412x1038.png 848w, https://substackcdn.com/image/fetch/$s_!kPsl!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9891d75a-3c7f-4b21-b600-aadd10428032_1412x1038.png 1272w, https://substackcdn.com/image/fetch/$s_!kPsl!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9891d75a-3c7f-4b21-b600-aadd10428032_1412x1038.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!kPsl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9891d75a-3c7f-4b21-b600-aadd10428032_1412x1038.png" width="662" height="486.6543909348442" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9891d75a-3c7f-4b21-b600-aadd10428032_1412x1038.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1038,&quot;width&quot;:1412,&quot;resizeWidth&quot;:662,&quot;bytes&quot;:64312,&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/177345058?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9891d75a-3c7f-4b21-b600-aadd10428032_1412x1038.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_!kPsl!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9891d75a-3c7f-4b21-b600-aadd10428032_1412x1038.png 424w, https://substackcdn.com/image/fetch/$s_!kPsl!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9891d75a-3c7f-4b21-b600-aadd10428032_1412x1038.png 848w, https://substackcdn.com/image/fetch/$s_!kPsl!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9891d75a-3c7f-4b21-b600-aadd10428032_1412x1038.png 1272w, https://substackcdn.com/image/fetch/$s_!kPsl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9891d75a-3c7f-4b21-b600-aadd10428032_1412x1038.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="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>To get user + orders + products, you need to: </p><ol><li><p>Call the Users service</p></li><li><p>Call the Orders service</p></li><li><p>Call the Products service</p></li><li><p>Join the data in your application code</p></li></ol><h3>The Transaction Problem</h3><p>In a monolith, you can wrap multiple operations in a database transaction:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!fV-z!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feaed61f1-41dd-434b-bcb2-f191664002e3_485x209.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!fV-z!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feaed61f1-41dd-434b-bcb2-f191664002e3_485x209.png 424w, https://substackcdn.com/image/fetch/$s_!fV-z!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feaed61f1-41dd-434b-bcb2-f191664002e3_485x209.png 848w, https://substackcdn.com/image/fetch/$s_!fV-z!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feaed61f1-41dd-434b-bcb2-f191664002e3_485x209.png 1272w, https://substackcdn.com/image/fetch/$s_!fV-z!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feaed61f1-41dd-434b-bcb2-f191664002e3_485x209.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!fV-z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feaed61f1-41dd-434b-bcb2-f191664002e3_485x209.png" width="587" height="252.95463917525774" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/eaed61f1-41dd-434b-bcb2-f191664002e3_485x209.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:209,&quot;width&quot;:485,&quot;resizeWidth&quot;:587,&quot;bytes&quot;:29238,&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/177345058?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feaed61f1-41dd-434b-bcb2-f191664002e3_485x209.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_!fV-z!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feaed61f1-41dd-434b-bcb2-f191664002e3_485x209.png 424w, https://substackcdn.com/image/fetch/$s_!fV-z!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feaed61f1-41dd-434b-bcb2-f191664002e3_485x209.png 848w, https://substackcdn.com/image/fetch/$s_!fV-z!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feaed61f1-41dd-434b-bcb2-f191664002e3_485x209.png 1272w, https://substackcdn.com/image/fetch/$s_!fV-z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feaed61f1-41dd-434b-bcb2-f191664002e3_485x209.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>In microservices, each service has its own database. You can&#8217;t have a transaction span multiple services. Instead, you need <strong>distributed transactions</strong> or <strong>saga pattern</strong> - both are complex and error-prone.</p><h2>5. Testing Is Exponentially Harder</h2><p>Testing a monolith is straightforward: spin up the application, run your tests.</p><p>Testing microservices requires multiple layers:</p><ul><li><p><strong>Contract testing</strong> between services</p></li><li><p><strong>Integration tests</strong> that spin up multiple services</p></li><li><p><strong>End-to-end tests</strong> across the entire system</p></li><li><p><strong>Chaos engineering</strong> to verify fault tolerance</p></li></ul><p>Your CI/CD pipeline becomes a complex orchestration of building, deploying, and testing multiple services in the correct order. A change to a shared API requires updating and testing all dependent services.</p><h2>6. You Don&#8217;t Know Your Domain Yet</h2><p>This might be the most important point.</p><p>When you&#8217;re starting a new project, <strong>you don&#8217;t fully understand your domain</strong>.</p><p>Requirements will change. You&#8217;ll discover that what you thought were separate concerns are actually deeply intertwined.</p><blockquote><p>In a monolith, refactoring is moving code between packages. In microservices, refactoring is redesigning APIs, migrating data, and coordinating deployments across teams.</p></blockquote><p>Martin Fowler calls this the <strong><a href="https://martinfowler.com/bliki/MonolithFirst.html">Monolith First</a></strong> approach:</p><blockquote><p>&#8220;Almost all the successful microservice stories have started with a monolith that got too big and was broken up.&#8221;</p><p>&#8212; Martin Fowler</p></blockquote><p>Starting with microservices means you&#8217;re drawing service boundaries before you understand where they should be. And wrong boundaries are incredibly expensive to fix.</p><p>So when do microservices actually make sense?</p><div><hr></div><h1>When Microservices Actually Make Sense</h1>
      <p>
          <a href="https://blog.algomaster.io/p/why-you-should-never-start-with-microservices">
              Read more
          </a>
      </p>
   ]]></content:encoded></item></channel></rss>