<?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[Algorythm]]></title><description><![CDATA[Technical Insights from the Algorythm Community]]></description><link>https://news.algorythm.org</link><image><url>https://substackcdn.com/image/fetch/$s_!ZHce!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc189bab-46c7-4025-a701-4a0aee3c4e47_200x200.png</url><title>Algorythm</title><link>https://news.algorythm.org</link></image><generator>Substack</generator><lastBuildDate>Fri, 10 Apr 2026 13:57:46 GMT</lastBuildDate><atom:link href="https://news.algorythm.org/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[Algorythm, Inc]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[algorythmorg@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[algorythmorg@substack.com]]></itunes:email><itunes:name><![CDATA[Esco Obong]]></itunes:name></itunes:owner><itunes:author><![CDATA[Esco Obong]]></itunes:author><googleplay:owner><![CDATA[algorythmorg@substack.com]]></googleplay:owner><googleplay:email><![CDATA[algorythmorg@substack.com]]></googleplay:email><googleplay:author><![CDATA[Esco Obong]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[How to Build Your Own LLM Benchmark]]></title><description><![CDATA[Using real-world exams and task-specific evaluations to test what public benchmarks miss]]></description><link>https://news.algorythm.org/p/how-to-build-your-own-llm-benchmark</link><guid isPermaLink="false">https://news.algorythm.org/p/how-to-build-your-own-llm-benchmark</guid><dc:creator><![CDATA[Emmanuel Acheampong]]></dc:creator><pubDate>Thu, 09 Apr 2026 15:01:24 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/8d6e09a2-b2b7-4863-bc45-aa095d98599e_1024x755.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>This publication is by members of the <strong><a href="https://algorythm.org/">Algorythm</a></strong> Community. A network of 20k+ black software engineers sharing technical insights across all fields of software development. Join us on <a href="https://www.linkedin.com/groups/8873861/">LinkedIn</a>, <a href="https://www.facebook.com/groups/algorythm">Facebook</a> and <a href="https://algorythmorg.substack.com/subscribe">Subscribe</a> for more insights.</em></p><div><hr></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!zfkV!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08ccdb52-28ff-4601-9b31-111209760184_1024x538.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!zfkV!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08ccdb52-28ff-4601-9b31-111209760184_1024x538.jpeg 424w, https://substackcdn.com/image/fetch/$s_!zfkV!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08ccdb52-28ff-4601-9b31-111209760184_1024x538.jpeg 848w, https://substackcdn.com/image/fetch/$s_!zfkV!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08ccdb52-28ff-4601-9b31-111209760184_1024x538.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!zfkV!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08ccdb52-28ff-4601-9b31-111209760184_1024x538.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!zfkV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08ccdb52-28ff-4601-9b31-111209760184_1024x538.jpeg" width="1024" height="538" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/08ccdb52-28ff-4601-9b31-111209760184_1024x538.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:538,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:218110,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/jpeg&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://algorythmorg.substack.com/i/193668243?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08ccdb52-28ff-4601-9b31-111209760184_1024x538.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_!zfkV!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08ccdb52-28ff-4601-9b31-111209760184_1024x538.jpeg 424w, https://substackcdn.com/image/fetch/$s_!zfkV!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08ccdb52-28ff-4601-9b31-111209760184_1024x538.jpeg 848w, https://substackcdn.com/image/fetch/$s_!zfkV!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08ccdb52-28ff-4601-9b31-111209760184_1024x538.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!zfkV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08ccdb52-28ff-4601-9b31-111209760184_1024x538.jpeg 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Most LLM benchmarks are broken not because the questions are bad, but because the industry treats them as proof of capability when they&#8217;re actually proof of optimization. A model that scores 90% on MMLU has demonstrated one thing: it&#8217;s good at MMLU. That number tells you almost nothing about whether it can handle your task, your users, or your domain.</p><p>It gets worse. Labs actively tune against public benchmarks. Training data gets curated to maximize leaderboard positions. The scores go up. The real-world performance stays flat. Benchmarks aren&#8217;t failing because they&#8217;re poorly designed. They&#8217;re failing because they&#8217;ve become marketing artifacts.</p><p>The fix is straightforward: stop relying on someone else&#8217;s eval and build your own. The performance that matters is performance on your task, in your context, for your users. Everything else is noise.</p><p>In this article, I walk through the full process from choosing an evaluation source to structuring a dataset, selecting models, and designing a scoring framework. I use the West African Senior School Certificate Examination (WASSCE) as the case study: a high-stakes regional exam taken by over 2 million students every year, many of whom already turn to AI tools for help. It&#8217;s a useful example for anyone who wants to evaluate models against real-world knowledge rather than relying solely on public benchmarks.</p><p>But the framework applies to any domain. Medical licensing exams. Legal bar questions. Industry-specific certifications. Internal company assessments. If you have a corpus of questions with known correct answers that represent your use case, you can build an eval.</p><div><hr></div><h3>Why Public Benchmarks Are Misleading You</h3><p>MMLU, GPQA, HumanEval, GSM8K;  these have become the standard scorecards for every LLM release. They&#8217;re treated as definitive. They&#8217;re not.</p><p><strong>They&#8217;re being overfit.</strong> When every model release is tuned to maximize performance on the same benchmarks, the scores stop meaning what you think they mean. Labs don&#8217;t just train models, they train models to win leaderboards. High MMLU increasingly tells you how well a lab optimizes for MMLU, not how capable the model is on novel tasks.</p><p><strong>They over-represent one slice of the world.</strong> AP exams, college-level science, competition math. All drawn from American and European academic traditions. If your users aren&#8217;t in that distribution, you&#8217;re evaluating against someone else&#8217;s reality.</p><p><strong>They don&#8217;t test what you actually need.</strong> If you&#8217;re building an education platform for West African students, a legal research tool for Brazilian attorneys, or a diagnostic assistant for rural healthcare workers, the questions that matter aren&#8217;t in any public benchmark. Full stop.</p><p>Relying on public benchmarks to make product decisions is like hiring someone based on their SAT score. It tells you something. It doesn&#8217;t tell you enough. Here&#8217;s how to build the eval that does.</p><div><hr></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!pXRu!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbea0cc47-d5c8-4220-825f-d5e0b58de4ae_1024x579.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!pXRu!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbea0cc47-d5c8-4220-825f-d5e0b58de4ae_1024x579.jpeg 424w, https://substackcdn.com/image/fetch/$s_!pXRu!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbea0cc47-d5c8-4220-825f-d5e0b58de4ae_1024x579.jpeg 848w, https://substackcdn.com/image/fetch/$s_!pXRu!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbea0cc47-d5c8-4220-825f-d5e0b58de4ae_1024x579.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!pXRu!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbea0cc47-d5c8-4220-825f-d5e0b58de4ae_1024x579.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!pXRu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbea0cc47-d5c8-4220-825f-d5e0b58de4ae_1024x579.jpeg" width="1024" height="579" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bea0cc47-d5c8-4220-825f-d5e0b58de4ae_1024x579.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:579,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:165590,&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://algorythmorg.substack.com/i/193668243?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbea0cc47-d5c8-4220-825f-d5e0b58de4ae_1024x579.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_!pXRu!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbea0cc47-d5c8-4220-825f-d5e0b58de4ae_1024x579.jpeg 424w, https://substackcdn.com/image/fetch/$s_!pXRu!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbea0cc47-d5c8-4220-825f-d5e0b58de4ae_1024x579.jpeg 848w, https://substackcdn.com/image/fetch/$s_!pXRu!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbea0cc47-d5c8-4220-825f-d5e0b58de4ae_1024x579.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!pXRu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbea0cc47-d5c8-4220-825f-d5e0b58de4ae_1024x579.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><h3>Step 1: Choose Your Evaluation Source</h3><p>The foundation of any custom benchmark is a structured corpus of questions with verified correct answers. The best sources share three properties: they&#8217;re high-stakes (so the questions are well-vetted), they have clear right answers (so scoring is unambiguous), and they represent the knowledge domain you actually care about.</p><p>Good candidates: standardized exams (national or regional), professional certification tests, internal company assessments, and university-level subject exams.</p><p><strong>What to avoid:</strong> Do not use scraped question banks without verified answer keys you&#8217;ll be measuring noise. Avoid subjective or free-response questions unless you have a reliable grading pipeline (human or model-based). And stay away from question sets smaller than 200 questions per subject. Below that threshold, your results will be too noisy to draw real conclusions.</p><p><strong>The WASSCE example:</strong> Every year, over 2 million candidates across five West African countries; Ghana, Nigeria, Sierra Leone, The Gambia, and Liberia sit for the West African Senior School Certificate Examination. It covers a standardized curriculum, has published marking schemes, and is the single most consequential exam in the region, gating university admission for an entire generation.</p><p>I took this exam at Presbyterian Boys&#8217; Secondary School (Presec Legon) in Accra, Ghana. I know the content, I know the stakes, and I know that nobody in the AI evaluation space is testing models against it. That gap is exactly the opportunity.</p><p>WASSCE also offers something most benchmarks can&#8217;t: a natural gradient between universal knowledge and regionally situated knowledge. Some subjects test the same physics and algebra you&#8217;d find anywhere. Others require knowledge of ECOWAS trade policy, the 1992 Ghanaian constitution, or the ecological zones of the Sahel. That gradient lets you measure not just whether a model is capable, but where its knowledge actually comes from.</p><div><hr></div><h3>Step 2: Select and Structure Your Subjects (The Situated Evaluation Framework)</h3><p>This is the most important design decision in your benchmark, and most people get it wrong by testing only one type of knowledge.</p><p>I call this the <strong>Situated Evaluation Framework</strong>: every custom benchmark should include both <strong>universal</strong> subjects (where you&#8217;d expect models to perform well regardless of training distribution) and <strong>situated</strong> subjects (where performance depends on how well the training data represents your specific domain).</p><p>The universal subjects are your control group. They establish a baseline: &#8220;this model is generally capable.&#8221; The situated subjects are your stress test. They answer the question that actually matters: &#8220;is this model capable <em>for my users</em>?&#8221;</p><p>The spread between them is the signal. A model that scores 85% on your universal subjects and 45% on your situated ones doesn&#8217;t have a general capability problem. It has a training data problem. That distinction changes everything about how you respond &#8212; you don&#8217;t need a bigger model, you need better data or fine-tuning.</p><p><strong>The WASSCE example &#8212; four core subjects:</strong></p><h4>Core Mathematics (Universal Control)</h4><p>50 multiple-choice questions covering algebra, geometry, trigonometry, statistics, and number theory. This is the control group; the content is largely universal. If a model can handle GSM8K or MATH, it should perform well here. If it doesn&#8217;t, that tells us something about question formatting or curriculum-specific conventions rather than knowledge gaps.</p><h4>English Language (Cultural Fluency Test)</h4><p>Comprehension passages, vocabulary in context, grammar, sentence construction, and an oral English section tested via written proxies like stress and intonation patterns. The comprehension passages are often drawn from West African literary or cultural contexts. A model trained predominantly on American or British English corpora might parse the grammar fine but miss the contextual cues. This subject tests cultural fluency, not just linguistic competence.</p><h4>Integrated Science (Applied Regional Knowledge)</h4><p>Biology, chemistry, physics, and earth science; but with an applied, West African lens. Questions reference local agricultural practices, tropical diseases, regional ecosystems, and public health issues relevant to the subregion. This is where you start to see whether a model&#8217;s &#8220;science knowledge&#8221; is truly general or just Western-general.</p><h4>Social Studies (Maximum Regional Specificity)</h4><p>This is the subject most likely to break models. Social Studies on WASSCE covers governance structures in West Africa, the role of ECOWAS, environmental sustainability in the Ghanaian context, youth and national development, and cultural practices across the subregion. A model might ace AP US Government and have no idea what the Directive Principles of State Policy are in the 1992 Constitution of Ghana.</p><p>This is the real test of whether training data represents the world or just part of it.</p><p><strong>How to apply this to your domain:</strong> Pick 3-5 subjects or topic areas. At least one universal control, at least one situated stress test. If every subject in your benchmark is situated, you have no baseline. If every subject is universal, you&#8217;re rebuilding MMLU. You need the gradient.</p><div><hr></div><h3>Step 3: Build the Dataset</h3><p>This is the most labor-intensive step, and the one that produces the most lasting value. Your goal is a clean, machine-readable, structured dataset that can be run through any eval harness.</p><p><strong>The sourcing pipeline:</strong></p><ol><li><p><strong>Collect source material</strong> &#8212; past papers, question banks, or assessment archives in whatever format they exist (PDF, image, print)</p></li><li><p><strong>Extract and digitize</strong> &#8212; OCR, manual transcription, or a combination</p></li><li><p><strong>Verify against answer keys</strong> &#8212; cross-check with official marking schemes or expert review</p></li><li><p><strong>Structure into a standard format</strong> &#8212; JSON is the most common for eval frameworks</p></li></ol><p><strong>A single question entry might look like:</strong></p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;json&quot;,&quot;nodeId&quot;:&quot;5e302b18-185d-4e7d-a8f8-2879c5219ef6&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-json">{

  &#8220;subject&#8221;: &#8220;Social Studies&#8221;,

  &#8220;year&#8221;: 2023,

  &#8220;question_number&#8221;: 15,

  &#8220;question&#8221;: &#8220;The main objective of ECOWAS is to promote&#8221;,

  &#8220;options&#8221;: {

    &#8220;A&#8221;: &#8220;military cooperation among member states&#8221;,

    &#8220;B&#8221;: &#8220;economic integration among member states&#8221;,

    &#8220;C&#8221;: &#8220;cultural exchange programs in West Africa&#8221;,

    &#8220;D&#8221;: &#8220;political unification of West African states&#8221;

  },

  &#8220;correct_answer&#8221;: &#8220;B&#8221;

}</code></pre></div><p><strong>A note on data availability:</strong> If you&#8217;re working with educational data from regions outside the US or Europe, structured, machine-readable datasets are rare. Part of the value of projects like this is building that artifact. The dataset itself becomes a contribution.</p><p>For well-resourced domains (US medical licensing, bar exams, etc.), you may find existing structured datasets. But even then, building your own gives you control over quality, scope, and format.</p><div><hr></div><h3>Step 4: Design the Prompt Format</h3><p>Keep it simple. For multiple-choice evaluations, zero-shot prompting with a clear instruction format is the cleanest baseline:</p><p>The following is a multiple choice question from [Exam Name] in [Subject].</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;plaintext&quot;,&quot;nodeId&quot;:&quot;a459fb60-bd38-4924-8a91-87cfcb151f28&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-plaintext">Question: [question text]

A. [option A]

B. [option B]

C. [option C]

D. [option D]

Answer with just the letter of the correct option.</code></pre></div><p>Zero-shot measures the model&#8217;s baseline knowledge without in-context learning crutches. This is what you want for an initial benchmark. Few-shot variants (providing example questions and answers before the test question) are worth exploring in follow-up work to measure how quickly models can adapt.</p><p><strong>Why this matters:</strong> The prompt format directly affects results. If your prompt is ambiguous, you&#8217;re benchmarking prompt sensitivity, not knowledge. Keep it clean, keep it consistent across all subjects and models.</p><div><hr></div><h3>Step 5: Select Your Models</h3><p>Don&#8217;t just run the biggest model available. The goal is to test hypotheses, not collect trophies.</p><p>Pick one model from each of four archetypes:</p><p><strong>The Dense Baseline</strong> &#8212; a standard, well-understood model with strong general capability. This is your reference point. (e.g., DeepSeek-V3-0324, Llama-3.3-70B-Instruct, GPT-OSS-120B)</p><p><strong>The Reasoning Specialist</strong> &#8212; a model optimized for chain-of-thought or extended thinking. Does explicit reasoning help on your situated content, or only on math and logic? (e.g., DeepSeek-R1-0528, Kimi-K2-Thinking)</p><p><strong>The Efficient Model</strong> &#8212; a smaller or mixture-of-experts (MoE) architecture. MoE models activate only a subset of their parameters per token, trading total size for speed and cost. This tests whether you can get comparable results at lower compute. (e.g., Nemotron-3-Nano-30B, Gemma-3-12b-it)</p><p><strong>The Multilingual/Large-Scale Entry</strong> &#8212; a model with broader training data or massive scale. Tests whether more data or more parameters close the gap on situated knowledge. (e.g., Qwen3-235B-A22B-Instruct, Nemotron-3-Super-120B)</p><p><strong>The WASSCE example:</strong> I&#8217;m running all nine models listed above across the four core subjects. The specific hypotheses: Does Qwen3&#8217;s multilingual pretraining give it an edge on West African Social Studies? Does DeepSeek-R1&#8217;s reasoning help on situated content, or only on Maths? Does Gemma at 12B hold up against models 10x its size on universal subjects?</p><p>All of these models are available on <strong>Crusoe Intelligence Foundry</strong> via managed inference &#8212; one API, no GPU management. Run the full eval without provisioning a single machine.</p><div><hr></div><h3>Step 6: Score and Analyze</h3><p>For multiple-choice: accuracy (correct / total) per subject, per model. But raw accuracy is just the starting point. The interesting analysis comes from the comparisons.</p><p><strong>Cross-subject analysis:</strong> Do models uniformly degrade across your situated subjects, or is the drop concentrated in specific areas? If every model tanks on Social Studies but handles Maths fine, that&#8217;s a training data gap. If some models handle the transition better than others, that&#8217;s an architecture or training insight.</p><p><strong>Question-type analysis:</strong> Within a subject, which topics trip models up? Constitutional history vs. arithmetic? Tropical agriculture vs. basic chemistry? This granularity tells you exactly where models need improvement for your use case.</p><p><strong>Architecture effects:</strong> Do MoE models with fewer active parameters perform differently than dense models of comparable total size? This matters if you&#8217;re choosing models for deployment on constrained infrastructure.</p><p><strong>Reasoning vs. baseline:</strong> Does explicit chain-of-thought (DeepSeek-R1, Kimi-K2-Thinking) actually help on culturally situated questions, or does it only improve performance on math and logic? If reasoning tokens don&#8217;t help on Social Studies, that tells us the gap is in knowledge, not in reasoning ability.</p><div><hr></div><h3>Common Mistakes That Will Wreck Your Benchmark</h3><p>I&#8217;ve seen enough eval projects go sideways to know where the landmines are. Avoid these.</p><p><strong>Dataset leakage.</strong> If your eval questions appeared in the model&#8217;s training data, your benchmark is measuring memorization, not capability. This is the single most common failure mode. Use questions from recent exam years, check for contamination, and if in doubt, hold back a subset of questions that you never publish.</p><p><strong>Prompt inconsistency.</strong> If you change the prompt format between subjects or models, you&#8217;re benchmarking prompt sensitivity, not knowledge. Lock the format. Use the exact same template for every question, every model, every run.</p><p><strong>Treating accuracy as ground truth.</strong> A model scoring 72% on one run and 68% on the next isn&#8217;t necessarily different. Run multiple passes, report variance, and don&#8217;t draw conclusions from single-digit accuracy differences. If your dataset is small (under 200 questions per subject), confidence intervals matter more than point estimates.</p><p><strong>Ignoring the failure mode.</strong> Accuracy tells you how often the model is right. It doesn&#8217;t tell you how it&#8217;s wrong. A model that consistently picks the same wrong answer on constitutional questions has a knowledge gap. A model that picks randomly has a comprehension problem. The fix is different. Look at the errors, not just the score.</p><p><strong>Overfitting your own eval.</strong> If you keep iterating on prompts until a specific model scores well on your benchmark, congratulations!! you&#8217;ve done the same thing you criticized the labs for. Set the format once. Run it. Report what you find.</p><div><hr></div><h3>What I Expect to Find (WASSCE Predictions)</h3><p>I&#8217;ll be upfront about my priors. These are testable hypotheses, not conclusions.</p><p><strong>Core Maths:</strong> Models will perform reasonably well &#8212; 70-85% for the larger ones. The content is universal enough that existing training data should cover it.</p><p><strong>English:</strong> Mid-range performance. Grammar and vocabulary will be fine. Comprehension passages with West African cultural context will cause noticeable drops.</p><p><strong>Integrated Science:</strong> Slightly below Maths. Universal science questions will be handled. Locally contextualized ones, tropical agriculture, regional health issues will be weaker.</p><p><strong>Social Studies:</strong> The biggest gap. I&#8217;d be surprised if any open model breaks 60% without specific fine-tuning on West African content.</p><p>If these priors hold, the implication is straightforward: open models have a regional knowledge gap, and it&#8217;s measurable. That matters for anyone building AI-powered education tools, tutoring systems, or information services for West Africa or any region underrepresented in English-language training data.</p><div><hr></div><h3>Why This Matters</h3><p>The Situated Evaluation Framework is general. Any domain where public benchmarks don&#8217;t cover your use case and that&#8217;s most domains benefits from building custom evals. The methodology in this post works for medical licensing in Southeast Asia, legal reasoning in Latin America, or internal compliance assessments at your company.</p><p>But the WASSCE case study highlights something that needs to be said directly.</p><p>West Africa has one of the youngest populations on Earth. Millions of students prepare for WASSCE every year, and they&#8217;re increasingly turning to AI-powered tools for study help. If the open models behind those tools have systematic blind spots on the very content these students need to learn, that&#8217;s not a minor gap. That&#8217;s a failure mode with consequences measured in denied university admissions and misdirected study time.</p><p>MMLU told us models were getting good at Western academic knowledge. That was useful. But it was never the whole picture. The question this benchmark answers is whether progress is truly global or whether we&#8217;re building intelligence that only knows half the world.</p><p>The rule is simple: <strong>if it&#8217;s not in your eval, it doesn&#8217;t exist to your model.</strong></p><p>Build the benchmark. Run the numbers. Make the gaps impossible to ignore.</p><div><hr></div><p><em>The WASSCE benchmark dataset and eval pipeline are open source at <a href="https://github.com/acheamponge/wassce-benchmark">https://github.com/acheamponge/wassce-benchmark</a> . If you found this useful, share it with someone building AI for underrepresented communities.</em></p><h3><strong>About The Author</strong></h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!i3E2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f3c6e0c-aef6-4bfe-b410-4e26dc9ced88_1056x1280.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!i3E2!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f3c6e0c-aef6-4bfe-b410-4e26dc9ced88_1056x1280.jpeg 424w, https://substackcdn.com/image/fetch/$s_!i3E2!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f3c6e0c-aef6-4bfe-b410-4e26dc9ced88_1056x1280.jpeg 848w, https://substackcdn.com/image/fetch/$s_!i3E2!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f3c6e0c-aef6-4bfe-b410-4e26dc9ced88_1056x1280.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!i3E2!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f3c6e0c-aef6-4bfe-b410-4e26dc9ced88_1056x1280.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!i3E2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f3c6e0c-aef6-4bfe-b410-4e26dc9ced88_1056x1280.jpeg" width="728" height="882.4242424242424" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1f3c6e0c-aef6-4bfe-b410-4e26dc9ced88_1056x1280.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:1280,&quot;width&quot;:1056,&quot;resizeWidth&quot;:728,&quot;bytes&quot;:160595,&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://algorythmorg.substack.com/i/193668243?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f3c6e0c-aef6-4bfe-b410-4e26dc9ced88_1056x1280.jpeg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:&quot;center&quot;,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!i3E2!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f3c6e0c-aef6-4bfe-b410-4e26dc9ced88_1056x1280.jpeg 424w, https://substackcdn.com/image/fetch/$s_!i3E2!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f3c6e0c-aef6-4bfe-b410-4e26dc9ced88_1056x1280.jpeg 848w, https://substackcdn.com/image/fetch/$s_!i3E2!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f3c6e0c-aef6-4bfe-b410-4e26dc9ced88_1056x1280.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!i3E2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f3c6e0c-aef6-4bfe-b410-4e26dc9ced88_1056x1280.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><a href="https://www.linkedin.com/in/emmanuel-acheampong/">Emmanuel Acheampong</a> is a Senior Manager at Crusoe AI and previously co-founded and led AI at yshade.ai. He took the WASSCE at Presec Legon in Accra, Ghana.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://acheamponge.substack.com/subscribe&quot;,&quot;text&quot;:&quot;Subscribe to Emmanuel&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://acheamponge.substack.com/subscribe"><span>Subscribe to Emmanuel</span></a></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://news.algorythm.org/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Algorythm! Subscribe for free to receive more technical insights from the community and support our work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p>]]></content:encoded></item><item><title><![CDATA[Building Agentic Applications With LangGraph]]></title><description><![CDATA[A hands-on introduction to LangGraph fundamentals and case study for customer support agents]]></description><link>https://news.algorythm.org/p/building-an-agentic-ai-customer-support</link><guid isPermaLink="false">https://news.algorythm.org/p/building-an-agentic-ai-customer-support</guid><dc:creator><![CDATA[koakande]]></dc:creator><pubDate>Fri, 03 Apr 2026 15:10:44 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!OMHn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F479fb2a6-6cd6-478f-a899-7d14becd7c29_1536x1024.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>This publication is by members of the <strong><a href="https://algorythm.org/">Algorythm</a></strong> Community. A network of 20k+ black software engineers sharing technical insights across all fields of software development. Join us on <a href="https://www.linkedin.com/groups/8873861/">LinkedIn</a>, <a href="https://www.facebook.com/groups/algorythm">Facebook</a> and <a href="https://algorythmorg.substack.com/subscribe">Subscribe</a> for more insights.</em></p><div><hr></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!OMHn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F479fb2a6-6cd6-478f-a899-7d14becd7c29_1536x1024.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!OMHn!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F479fb2a6-6cd6-478f-a899-7d14becd7c29_1536x1024.jpeg 424w, https://substackcdn.com/image/fetch/$s_!OMHn!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F479fb2a6-6cd6-478f-a899-7d14becd7c29_1536x1024.jpeg 848w, https://substackcdn.com/image/fetch/$s_!OMHn!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F479fb2a6-6cd6-478f-a899-7d14becd7c29_1536x1024.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!OMHn!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F479fb2a6-6cd6-478f-a899-7d14becd7c29_1536x1024.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!OMHn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F479fb2a6-6cd6-478f-a899-7d14becd7c29_1536x1024.jpeg" width="1456" height="971" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/479fb2a6-6cd6-478f-a899-7d14becd7c29_1536x1024.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:971,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:320238,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/jpeg&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://algorythmorg.substack.com/i/193068110?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F479fb2a6-6cd6-478f-a899-7d14becd7c29_1536x1024.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_!OMHn!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F479fb2a6-6cd6-478f-a899-7d14becd7c29_1536x1024.jpeg 424w, https://substackcdn.com/image/fetch/$s_!OMHn!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F479fb2a6-6cd6-478f-a899-7d14becd7c29_1536x1024.jpeg 848w, https://substackcdn.com/image/fetch/$s_!OMHn!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F479fb2a6-6cd6-478f-a899-7d14becd7c29_1536x1024.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!OMHn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F479fb2a6-6cd6-478f-a899-7d14becd7c29_1536x1024.jpeg 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3>Introduction</h3><p>Agentic AI is a powerful new paradigm that enables a new class of high-value applications. One of the first use cases to show immediate returns is customer support. We&#8217;ll explore how to build these systems using customer support agents as a case study, but the same core principles apply broadly across many domains.</p><p>Traditionally, customer agents read emails from customers, prioritised them, and followed up with required actions. Agentic AI can now support this initial triaging by summarising the email and preparing a draft response for human review to ensure customers receive rapid feedback. This saves time that would have been spent reading the original email, understanding it, and composing the response.</p><p>Furthermore, since there&#8217;s a human in the loop, the bot output is not customer-facing and is safe enough for quick deployment without the strict guardrails required for fully autonomous customer-facing applications.</p><p>This was the first Agentic AI application we deployed in my company, and it has proven popular among the agents it supports. In this tutorial, we&#8217;ll build a skeletal version of this application. We&#8217;ll start with a simple bot, add tool-calling capabilities, and finally add human review and feedback features.</p><h3>LangGraph Overview</h3><p>In order to build the application, one could code it from the ground up, but that would take a lot of time. Fortunately, there are several frameworks that handle much of the heavy lifting, allowing us to focus on the application development. The one employed in this tutorial is <strong>LangGraph</strong>, which provides a powerful framework for working with LLMs and building stateful, agentic AI applications.</p><p>The fundamental challenge solved by agentic AI frameworks is how to describe the various interactions within AI applications in a way that is both <strong>evolvable</strong> and <strong>scalable</strong>. <strong>LangGraph</strong> tackles this challenge using a <strong>graph-based workflow</strong>.<br>The practical application of graphs is ubiquitous &#8212; they are used in knowledge representation, social networks, recommendation systems, and more.</p><p>Technical interviews on data structures and algorithms (DSA) are rarely complete without questions involving graphs. In the context of <strong>agentic AI</strong>, graphs enable the execution of <strong>flowcharts with memory</strong>. They allow for modular implementation of agentic architectures and provide a structured framework for the flow of associated data.</p><p><strong>LangGraph</strong> leverages graphs to develop an orchestration framework for the <strong>development, deployment, and management of stateful agents</strong>. It provides functionalities that enable efficient implementation of <strong>production-grade, stateful, and multi-agent workflows</strong>.</p><p>This tutorial will explore the different aspects of <strong>LangGraph</strong> with increasing levels of complexity, allowing the application to evolve gradually as new functionalities are added. This step-by-step progression will enhance comprehension and demonstrate the application&#8217;s growth through different stages of sophistication.</p><h3>1. Building Munah: The Basic Agent</h3><h4>StateGraph</h4><p>This is the fundamental structure that underpins stateful agent development within LangGraph. It models stateful agents as a graph of states and the transitions between them. It defines the flow of executions with proceedings depending on output or conditions. The structure enables the ease of developing debuggable stateful agents that can maintain context and memory.</p><h4>State</h4><p>The <strong>State</strong> serves as the working database of the graph. It is a temporary memory that holds all the context or data relevant to a graph execution. As the workflow progresses, the state dynamically updates to include inputs, conversation history, decisions, variables, and other intermediate information. This data is accessible to all nodes within the graph and ensures each component operates with the proper context. In essence, the <strong>State </strong>enables the graph to perform coherent and context-aware execution of its logic.</p><h4>Nodes</h4><p>This is the point at which the logic of the graph is executed. It serves as an action centre, enabling operations such as model invocation, function execution, database querying, and more. Each node receives the current <strong>State</strong>, modifies it, and passes the updated state to downstream operations.</p><h4>Edges</h4><p>Edges serve as the flow paths for information between nodes. They act as conduits through which the State moves across the graph. Edges can also be conditional, meaning the state of the workflow determines which path to follow. For example, if an LLM determines that a tool is needed to fulfill a request, the flow transitions to the <strong>ToolNode</strong>; otherwise, it proceeds to the next node.</p><p>With these components in place, the stage is now set to build our basic component for Munah.</p><h4>Coding the Basic Workflow</h4><blockquote><p><strong>Imports and Declaration</strong></p></blockquote><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:&quot;9355ce8a-1062-48c3-80a9-ff2c94545f4a&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python"># import libraries
import logging
from dotenv import load_dotenv
from typing import TypedDict, Annotated
from langchain_groq import ChatGroq
from langgraph.graph import StateGraph, START, END
from langgraph.graph.message import add_messages
from langchain_core.messages import HumanMessage

# Setup logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(&#8221;customer_complaint_bot&#8221;)

# Load environment variables (for Groq API key)
load_dotenv()

# Initialize LLM (using Groq&#8217;s Llama 3.1)
llm = ChatGroq(model=&#8221;llama-3.1-8b-instant&#8221;, temperature=0)</code></pre></div><blockquote><p><strong>Defining the State</strong></p></blockquote><p>The State is declared with variables we would need to hold the workflow data. The state inherits from <code>TypedDict</code> meaning we expect it to contain the declared keys.</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:&quot;5285d274-d042-4995-8070-a40242711866&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python">class AgentState(TypedDict):
    &#8220;&#8221;&#8220;
    The state of our customer complaint agent.
    &#8220;&#8221;&#8220;
    # &#8216;add_messages&#8217; is a special modifier that appends
    # new messages to the list, rather than overwriting it.
    messages: Annotated[list, add_messages]
    
    # The original customer email
    original_email: str
    
    # The final summary
    summary: str</code></pre></div><h4>Nodes declaration</h4><p>The <code>summarise_complaint</code> node receives the email, sends it to an LLM and returns the summarised version.</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:&quot;34fb1a7a-7a31-42c9-8507-bd94fadae14f&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python">def summarise_complaint(state: AgentState):
    &#8220;&#8221;&#8220;
    A node that takes the customer input from the state
    and generates a summary.
    &#8220;&#8221;&#8220;

    email = state[&#8221;messages&#8221;][-1].content
    logger.info(f&#8221;Summarising customer email: {email}&#8221;)

    prompt = f&#8221;&#8220;&#8221;
    You are an expert customer service agent. Please summarise the following
    customer complaint email concisely. Extract the core issue. 
    Do not add any formatting.
    
    Email:
    {email}
    
    Summary:
    &#8220;&#8221;&#8220;
    
    response = llm.invoke(prompt)
    summary = response.content
    logger.info(&#8221;Summary generated successfully.&#8221;)
    
    # Return a dictionary to update the state
    return {&#8221;original_email&#8221;: email, &#8220;summary&#8221;: summary}</code></pre></div><blockquote><p><strong>Note:</strong> This is an example prompt for instructional purposes. Prompt engineering and evaluation are out of scope for this article, but they are crucial for ensuring the accuracy and relevance of summarisations for your specific product and user base.</p></blockquote><h4><strong>Graph definition</strong></h4><p>The components are now ready for building the bot. It will be done in four main steps. First the graph is declared, then nodes are added to the graph. This is followed by connecting the nodes with edges and finally, the graph is complied.</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:&quot;7f306df0-3af7-4b6d-ad0c-0416ff721400&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python"># Initialize the graph
customer_complaint_bot = StateGraph(AgentState)

# Add the nodes
customer_complaint_bot.add_node(&#8221;summarise&#8221;, summarise_complaint)

# Define the edges
customer_complaint_bot.add_edge(START, &#8220;summarise&#8221;)
customer_complaint_bot.add_edge(&#8221;summarise&#8221;, END)

# Compile the graph
app_stage1 = customer_complaint_bot.compile()</code></pre></div><h4><strong>Graph Visualisation</strong></h4><p>It is instructive to visualise the current state of the graph. We will use <a href="https://pygraphviz.github.io/documentation/stable/install.html">pygraphviz</a> with the script below:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:&quot;c1422760-e35e-4633-b78a-3c54702b3048&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python">from IPython.display import Image, display

# Get the graph object
graph = app_stage1.get_graph()

# Draw it as a PNG (returns raw bytes)
png_bytes = graph.draw_png()

# Display the PNG in the notebook
display(Image(png_bytes))</code></pre></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!_olS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff06f5272-869c-4d11-8f76-6a6a589082c2_196x367.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!_olS!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff06f5272-869c-4d11-8f76-6a6a589082c2_196x367.png 424w, https://substackcdn.com/image/fetch/$s_!_olS!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff06f5272-869c-4d11-8f76-6a6a589082c2_196x367.png 848w, https://substackcdn.com/image/fetch/$s_!_olS!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff06f5272-869c-4d11-8f76-6a6a589082c2_196x367.png 1272w, https://substackcdn.com/image/fetch/$s_!_olS!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff06f5272-869c-4d11-8f76-6a6a589082c2_196x367.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!_olS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff06f5272-869c-4d11-8f76-6a6a589082c2_196x367.png" width="196" height="367" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f06f5272-869c-4d11-8f76-6a6a589082c2_196x367.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:367,&quot;width&quot;:196,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:40287,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://algorythmorg.substack.com/i/193068110?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff06f5272-869c-4d11-8f76-6a6a589082c2_196x367.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!_olS!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff06f5272-869c-4d11-8f76-6a6a589082c2_196x367.png 424w, https://substackcdn.com/image/fetch/$s_!_olS!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff06f5272-869c-4d11-8f76-6a6a589082c2_196x367.png 848w, https://substackcdn.com/image/fetch/$s_!_olS!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff06f5272-869c-4d11-8f76-6a6a589082c2_196x367.png 1272w, https://substackcdn.com/image/fetch/$s_!_olS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff06f5272-869c-4d11-8f76-6a6a589082c2_196x367.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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">Fig 2: Basic Agentic Customer Support AI Bot</figcaption></figure></div><h4><strong>Running the Bot</strong></h4><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:&quot;8e633bc9-f706-447b-ba7f-a36d9c9162d9&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python"># Define a sample complaint
complaint_email = (
    &#8220;Hi, I bought the &#8216;SuperWidget 5000&#8217; (Order #A-12345) last week and &#8220;
    &#8220;it arrived broken. The screen is cracked. I tried calling support &#8220;
    &#8220;but was on hold for 45 minutes. This is unacceptable. I want a &#8220;
    &#8220;full refund and a return label.&#8221;
)

# Invoke the graph
# We pass the input as the &#8216;messages&#8217; list
inputs = {&#8221;messages&#8221;: [HumanMessage(content=complaint_email)]}
result = app_stage1.invoke(inputs)

print(f&#8221;Summary: {result[&#8217;summary&#8217;]}&#8221;)</code></pre></div><h4><strong>Final Output</strong></h4><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;bash&quot;,&quot;nodeId&quot;:&quot;98fd6e0e-8f94-4329-b245-b19ef5e8d2e5&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-bash">Summary: The customer received a broken &#8216;SuperWidget 5000&#8217; with a 
cracked screen, was unable to get through to support after waiting 45 minutes,
 and is requesting a full refund and a return label.</code></pre></div><h4><strong>Walkthrough</strong></h4><p>As a summary of the workflow above, let&#8217;s take a quick walkthrough of the sequence of events:</p><ol><li><p>The graph is invoked with customer input</p></li><li><p><code>summarise</code> node takes in the <code>State</code> , extracts the input, interpolates it on the prompt, calls the llm with the prompt, gets a response and returns both the llm summary and the customer input</p></li><li><p>The graph captures the <code>summarise</code> node output, merges it to the <code>State</code> and returns the <code>State</code> object</p></li></ol><p>We grab the <code>State</code> object, extract the summary from it and print it out. It is instructive to know that after each node returns, the graph updates the <code>State</code> object with the node output.</p><p><strong>The main achievement of this first stage is that we learnt the fundamentals of LangGraph which are State, Nodes and Edges with a simple LLM interaction.</strong></p><p></p><h3>2. Adding Tool Calling and Conditional Flow</h3><p>Having familiarised ourselves with the fundamentals, let&#8217;s move on to more advanced capabilities of the <strong>LangGraph</strong> framework.<br></p><p>When customer input requires the LLM to fetch additional context in order to generate a more relevant response, it needs to <strong>leverage a tool call</strong>. Fundamentally, tools are functions or APIs that allow the LLM to perform actions beyond text generation &#8212; such as database lookups, calculations, or external API interactions.<br>We&#8217;ll now evolve Munah by equipping her with <strong>tool-calling ability</strong>.</p><p>The main steps to implement this are:</p><ol><li><p>Define the logic for the tool in terms of a function or API call.</p></li><li><p>Wrap the defined logic inside a <strong>ToolNode</strong>, which serves as the execution component in LangGraph.</p></li><li><p>Bind the tools to the LLM so that it is aware of them and can call them when needed.</p></li><li><p>Modify the prompt and workflow to instruct the LLM to use the tools when necessary.</p></li></ol><p>In this tutorial, our imaginary customer will be asking questions about their order. The LLM will read the message, determine that it needs the order details, and call the appropriate tool to interact with the database. After retrieving the order details, it will summarise the email and prepare a draft response.</p><p>Both the summary and the response will then be passed to the customer support agent for review before making the final decision.</p><p>Let&#8217;s dive into the details.</p><h4>Define the Tool</h4><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:&quot;8c1ffcf0-f7e5-4914-a1d8-fc34b264bfa4&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python">from langgraph.prebuilt import ToolNode, tools_condition
from langchain.tools import tool
from langchain_core.messages import SystemMessage, ToolMessage

# Define the logics (tool) to get order details
def get_order_details(order_id: str) -&gt; dict:
    &#8220;&#8221;&#8220;Retrieve order details by order ID from mock database.
     &#65039;Args:
        order_id (str): The order ID to look up.
    Returns:
        dict: A dictionary with order details.
    &#8220;&#8221;&#8220;
    logger.info(f&#8221;Retrieving details for order ID: {order_id}&#8221;)

    # Mock database
    mock_db = {
        &#8220;A-12345&#8221;: {&#8221;product&#8221;: &#8220;SuperWidget 5000&#8221;, &#8220;status&#8221;: &#8220;Delivered&#8221;, &#8220;price&#8221;: &#8220;&#163;299&#8221;},
        &#8220;B-54321&#8221;: {&#8221;product&#8221;: &#8220;MegaWidget 2000&#8221;, &#8220;status&#8221;: &#8220;Shipped&#8221;, &#8220;price&#8221;: &#8220;&#163;149&#8221;},
    }

    order = mock_db.get(order_id, {&#8221;error&#8221;: &#8220;Order not found&#8221;})
    return order

# Define the tool node
tools = [get_order_details] # More tools can be added as required
tool_node = ToolNode(tools=tools)

# Bind the tools to the LLM - ensuring LLM can call them
llm_with_tools = llm.bind_tools(tools)

# Redefine the summarise_complaint function to include tool usage
def tooled_summarise_complaint(state: AgentState):
    original_email = state.get(&#8221;original_email&#8221;) or state[&#8221;messages&#8221;][-1].content
    messages = state.get(&#8221;messages&#8221;, [])

    # Extract any tool responses so far
    tool_messages = [m.content for m in messages if isinstance(m, ToolMessage)]

    # Build the new LLM input
    llm_input = [
        SystemMessage(content=(
            &#8220;You are an expert customer service agent. &#8220;
            &#8220;Summarise the customer&#8217;s complaint and interpret any tool results below. &#8220;
            &#8220;Use the tool outputs to answer questions accurately. &#8220;
            &#8220;Always keep the original email context.&#8221;
        )),
        HumanMessage(content=original_email),
    ] + tool_messages  # &lt;-- add all tool results here
    
    response = llm_with_tools.invoke(llm_input)
    print(f&#8221;LLM Response: {response}&#8221;)
    summary = response.content
    logger.info(&#8221;Summary generated successfully.&#8221;)

    # Return a dictionary to update the state
    return {&#8221;messages&#8221;: response, &#8220;original_email&#8221;: original_email, &#8220;summary&#8221;: summary}</code></pre></div><h4>Structure the graph</h4><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:&quot;146f8180-7297-4d55-a3ad-db0e99b8c4b9&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python"># build a new graph incorporating the tool node
customer_complaint_bot_with_tools = StateGraph(AgentState)
customer_complaint_bot_with_tools.add_node(&#8221;summarise_with_tools&#8221;, tooled_summarise_complaint)
customer_complaint_bot_with_tools.add_node(&#8221;tools&#8221;, tool_node)

# Define the edges with tool condition
customer_complaint_bot_with_tools.add_edge(START, &#8220;summarise_with_tools&#8221;)
customer_complaint_bot_with_tools.add_conditional_edges(
    &#8220;summarise_with_tools&#8221;,
    tools_condition,   # built-in condition to check for tool calls
)
customer_complaint_bot_with_tools.add_edge(&#8221;tools&#8221;, END)

#  Compile the new graph
app_stage2 = customer_complaint_bot_with_tools.compile()

# display the new graph
graph = app_stage2.get_graph()
png_bytes = graph.draw_png()
display(Image(png_bytes))</code></pre></div><h4>Run the Bot</h4><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:&quot;4a9c11b4-8155-46ea-89c2-a95544b284a9&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python"># call the new graph with a new input that requires tool use
new_complaint_email = (
    &#8220;Hello, I ordered the &#8216;MegaWidget 2000&#8217; with order ID B-54321 two days ago, &#8220;
    &#8220;but I haven&#8217;t received any shipping updates. Can you check the status of my order? &#8220;
    &#8220;Also, I want to confirm the price I was charged.&#8221;
)
new_inputs = {&#8221;messages&#8221;: [HumanMessage(content=new_complaint_email)]}
new_result = app_stage2.invoke(new_inputs)
print(f&#8221;New Summary with tools: {new_result[&#8217;summary&#8217;]}&#8221;)</code></pre></div><h4>Output</h4><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;bash&quot;,&quot;nodeId&quot;:&quot;9e2798cf-1cbb-4060-a9bd-ca33efd09717&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-bash">New Summary with tools: </code></pre></div><h4>Understanding Why It Fails</h4><p>The implementation above does not produce any output, and a quick look at the graph visualisation explains why. <strong>Figure 3</strong> shows that the <code>summarise_with_tools</code> node either calls the tool or moves directly to the end node. When the tool is called, its output <strong>is not passed back to the LLM</strong>, which prevents the workflow from generating a final response.</p><p><br>We could print the tool output for inspection, but that would be of little use. The core issue is that the LLM never receives the tool&#8217;s result to complete the workflow.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!4lC7!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17b1f0e5-3b07-4eb2-9fca-004bc3323a21_311x446.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!4lC7!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17b1f0e5-3b07-4eb2-9fca-004bc3323a21_311x446.png 424w, https://substackcdn.com/image/fetch/$s_!4lC7!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17b1f0e5-3b07-4eb2-9fca-004bc3323a21_311x446.png 848w, https://substackcdn.com/image/fetch/$s_!4lC7!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17b1f0e5-3b07-4eb2-9fca-004bc3323a21_311x446.png 1272w, https://substackcdn.com/image/fetch/$s_!4lC7!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17b1f0e5-3b07-4eb2-9fca-004bc3323a21_311x446.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!4lC7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17b1f0e5-3b07-4eb2-9fca-004bc3323a21_311x446.png" width="311" height="446" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/17b1f0e5-3b07-4eb2-9fca-004bc3323a21_311x446.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:446,&quot;width&quot;:311,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:57038,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://algorythmorg.substack.com/i/193068110?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17b1f0e5-3b07-4eb2-9fca-004bc3323a21_311x446.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!4lC7!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17b1f0e5-3b07-4eb2-9fca-004bc3323a21_311x446.png 424w, https://substackcdn.com/image/fetch/$s_!4lC7!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17b1f0e5-3b07-4eb2-9fca-004bc3323a21_311x446.png 848w, https://substackcdn.com/image/fetch/$s_!4lC7!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17b1f0e5-3b07-4eb2-9fca-004bc3323a21_311x446.png 1272w, https://substackcdn.com/image/fetch/$s_!4lC7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17b1f0e5-3b07-4eb2-9fca-004bc3323a21_311x446.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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">Fig 3: Agentic Customer Support AI Bot with Tools</figcaption></figure></div><p></p><h4>ReAct Pattern</h4><p>The <strong><a href="https://arxiv.org/abs/2210.03629">ReAct</a></strong> (Reason + Act) pattern enables the LLM to <strong>reason</strong> about its query and then <strong>act</strong> based on that reasoning. In the previous implementation, when the LLM decided to call a tool, the action was taken but the tool&#8217;s output was <strong>not passed back</strong> to the LLM. As a result, the model could not combine the <strong>user query</strong> and the <strong>tool response</strong> to generate a context-aware answer. To fix this, we need to modify the graph by <strong>adding an edge from the tool node back to the LLM node</strong>, allowing the LLM to continue reasoning with the new information and produce a more relevant response.</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:&quot;06985ba4-3882-4606-8fe2-c1073a7fb619&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python">#  Add edge from tool node back to summarise node
customer_complaint_bot_with_tools.add_edge(&#8221;tools&#8221;, &#8220;summarise_with_tools&#8221;)

#  Compile the new graph
app_stage2 = customer_complaint_bot_with_tools.compile()

# Display the new graph
graph = app_stage2.get_graph()
png_bytes = graph.draw_png()
display(Image(png_bytes))</code></pre></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ob3C!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e2c887c-6481-4485-8539-a03c4b20d607_436x332.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ob3C!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e2c887c-6481-4485-8539-a03c4b20d607_436x332.png 424w, https://substackcdn.com/image/fetch/$s_!ob3C!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e2c887c-6481-4485-8539-a03c4b20d607_436x332.png 848w, https://substackcdn.com/image/fetch/$s_!ob3C!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e2c887c-6481-4485-8539-a03c4b20d607_436x332.png 1272w, https://substackcdn.com/image/fetch/$s_!ob3C!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e2c887c-6481-4485-8539-a03c4b20d607_436x332.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ob3C!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e2c887c-6481-4485-8539-a03c4b20d607_436x332.png" width="436" height="332" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4e2c887c-6481-4485-8539-a03c4b20d607_436x332.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:332,&quot;width&quot;:436,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:67259,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://algorythmorg.substack.com/i/193068110?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e2c887c-6481-4485-8539-a03c4b20d607_436x332.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ob3C!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e2c887c-6481-4485-8539-a03c4b20d607_436x332.png 424w, https://substackcdn.com/image/fetch/$s_!ob3C!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e2c887c-6481-4485-8539-a03c4b20d607_436x332.png 848w, https://substackcdn.com/image/fetch/$s_!ob3C!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e2c887c-6481-4485-8539-a03c4b20d607_436x332.png 1272w, https://substackcdn.com/image/fetch/$s_!ob3C!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4e2c887c-6481-4485-8539-a03c4b20d607_436x332.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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">Fig 4: Agentic Customer Support AI Bot with ReAct Architecture</figcaption></figure></div><p>Let&#8217;s now try passing in our customer email and observe the output.</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:&quot;8f5011f8-1113-4856-b6a2-48b129a1ac00&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python"># call the new graph with a new input that requires tool use
new_complaint_email = (
    &#8220;Hello, I ordered the &#8216;MegaWidget 2000&#8217; with order ID B-54321 two days ago, &#8220;
    &#8220;but I haven&#8217;t received any shipping updates. Can you check the status of my order? &#8220;
    &#8220;Also, I want to confirm the price I was charged.&#8221;
)
new_inputs = {&#8221;messages&#8221;: [HumanMessage(content=new_complaint_email)]}
new_result = app_stage2.invoke(new_inputs)


# Run the graph
new_result = app_stage2.invoke(new_inputs)

# Extract key parts 
original_email = new_result.get(&#8221;original_email&#8221;)
summary = new_result.get(&#8221;summary&#8221;)

# Extract the latest AI message (final model output)
final_ai_msg = None
for msg in reversed(new_result.get(&#8221;messages&#8221;, [])):
    if msg.__class__.__name__ == &#8220;AIMessage&#8221; and msg.content.strip():
        final_ai_msg = msg.content
        break

# Extract tool results (if any)
tool_outputs = [
    msg.content
    for msg in new_result.get(&#8221;messages&#8221;, [])
    if msg.__class__.__name__ == &#8220;ToolMessage&#8221;
]

# Print formatted output
print(&#8221;\nOriginal Customer Email:&#8221;)
print(f&#8221;{original_email}\n&#8221;)

if tool_outputs:
    print(&#8221;Tool Output(s):&#8221;)
    for t in tool_outputs:
        print(f&#8221;  &#8594; {t}&#8221;)
    print()

if final_ai_msg:
    print(&#8221;Final AI Response:&#8221;)
    print(final_ai_msg)
else:
    print(&#8221;No final AI message found in result.&#8221;)</code></pre></div><p>The formatted output is</p><pre><code>Original Customer Email:
Hello, I ordered the &#8216;MegaWidget 2000&#8217; with order ID B-54321 two days ago, but I haven&#8217;t received any shipping updates. Can you check the status of my order? Also, I want to confirm the price I was charged.

Tool Output(s):
  &#8594; {&#8221;product&#8221;: &#8220;MegaWidget 2000&#8221;, &#8220;status&#8221;: &#8220;Shipped&#8221;, &#8220;price&#8221;: &#8220;&#163;149&#8221;}

Final AI Response:
Customer&#8217;s concern
The customer ordered the MegaWidget 2000 (Order ID B-54321) two days ago and has not yet received any shipping updates. They would like to know the current status of the shipment and confirm the amount that was charged.

Tool output interpretation
- Product: MegaWidget 2000
- Order status: Shipped
- Price charged: &#163;149

Response
Hi there! I&#8217;ve pulled up the details for your order B-54321. Your MegaWidget 2000 has already been shipped, and the amount charged was &#163;149.  

If you&#8217;d like a tracking number or more detailed shipping information, just let me know and I&#8217;ll forward it to you right away. Otherwise, you should expect delivery shortly.  

Thanks for reaching out, and feel free to ask if there&#8217;s anything else I can help with!</code></pre><h3>3. Human-in-the-Loop (HITL) and Persistence</h3><p>Currently, Munah can understand customer correspondence and leverage available tools to provide contextual summaries and draft responses. To achieve full automation with human oversight, we can utilize two key LangGraph features: <strong>Interrupts</strong> and <strong>Persistence</strong>.</p><h4>Human-in-the-Loop via Interrupt</h4><p>The <strong>Interrupt</strong> feature allows pausing graph execution to enable human oversight, such as reviewing or editing Munah&#8217;s draft response. When an interruption occurs, the current graph state is stored and presented to a human for review. After the review, execution resumes from exactly where it stopped, incorporating any feedback provided.</p><h4>State Persistence</h4><p>By default, the graph state persists only during execution. LangGraph provides long-term persistence through the <code>MemorySaver</code> class, which allows the graph to preserve workflow context and resume without data loss.</p><p>We have added a node that implements the human review process, as shown below:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:&quot;a9c0d5da-d935-4027-bedb-7bd1c368252a&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python"># Import
from langgraph.checkpoint.memory import MemorySaver

# Initialize the graph
customer_complaint_bot_with_tools = StateGraph(AgentState)

# Add the nodes
customer_complaint_bot_with_tools.add_node(&#8221;summarise_with_tools&#8221;, tooled_summarise_complaint)
customer_complaint_bot_with_tools.add_node(&#8221;tools&#8221;, tool_node)
customer_complaint_bot_with_tools.add_node(&#8221;human_review&#8221;, human_in_the_loop_review)

# Redirect flow:
# After summarising (with tools), send to human review before ending.
# Conditional: if the LLM requests a tool, go to tools; otherwise go to human review
customer_complaint_bot_with_tools.add_edge(START, &#8220;summarise_with_tools&#8221;)
customer_complaint_bot_with_tools.add_conditional_edges(
    &#8220;summarise_with_tools&#8221;,
    tools_condition,   # built-in LangGraph function that checks for tool calls
    {
        &#8220;tools&#8221;: &#8220;tools&#8221;,           # if tool call detected
        &#8220;__end__&#8221;: &#8220;human_review&#8221;,    # if no tool call, go straight to human review
    }
)
customer_complaint_bot_with_tools.add_edge(&#8221;tools&#8221;, &#8220;summarise_with_tools&#8221;)
customer_complaint_bot_with_tools.add_edge(&#8221;human_review&#8221;, END)

# Add a MemorySaver for Persistent State 
memory = MemorySaver()

# Compile the new graph with MemorySaver as checkpointer
app_stage3 = customer_complaint_bot_with_tools.compile(checkpointer=memory)


# Visualize the Graph
graph = app_stage3.get_graph()
png_bytes = graph.draw_png()
display(Image(png_bytes))</code></pre></div><h4>Visualisation</h4><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!TU8P!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89310ee0-b917-45b6-8edd-b84c97f15f8e_485x458.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!TU8P!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89310ee0-b917-45b6-8edd-b84c97f15f8e_485x458.png 424w, https://substackcdn.com/image/fetch/$s_!TU8P!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89310ee0-b917-45b6-8edd-b84c97f15f8e_485x458.png 848w, https://substackcdn.com/image/fetch/$s_!TU8P!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89310ee0-b917-45b6-8edd-b84c97f15f8e_485x458.png 1272w, https://substackcdn.com/image/fetch/$s_!TU8P!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89310ee0-b917-45b6-8edd-b84c97f15f8e_485x458.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!TU8P!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89310ee0-b917-45b6-8edd-b84c97f15f8e_485x458.png" width="485" height="458" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/89310ee0-b917-45b6-8edd-b84c97f15f8e_485x458.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:458,&quot;width&quot;:485,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:90284,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://algorythmorg.substack.com/i/193068110?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89310ee0-b917-45b6-8edd-b84c97f15f8e_485x458.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!TU8P!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89310ee0-b917-45b6-8edd-b84c97f15f8e_485x458.png 424w, https://substackcdn.com/image/fetch/$s_!TU8P!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89310ee0-b917-45b6-8edd-b84c97f15f8e_485x458.png 848w, https://substackcdn.com/image/fetch/$s_!TU8P!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89310ee0-b917-45b6-8edd-b84c97f15f8e_485x458.png 1272w, https://substackcdn.com/image/fetch/$s_!TU8P!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89310ee0-b917-45b6-8edd-b84c97f15f8e_485x458.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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">Fig 5: Agentic Customer Support AI Bot with Human-in-the-Loop</figcaption></figure></div><h4>Running the workflow</h4><p>When the workflow is run, it will interrupt the flow and send the LLM output to a human. This can be implemented through a dashboard, web/app UI, API gateway or some other CRM platform. The human can choose to approve the draft response based on the original email and tool call output or they can modify the draft response.</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:&quot;de086acd-75bb-45bd-b608-d6f9f7adec5f&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python"># Run the graph with human-in-the-loop

# Use the same thread_id for continuity
config = {&#8221;configurable&#8221;: {&#8221;thread_id&#8221;: thread_id}}
new_inputs = {&#8221;messages&#8221;: [HumanMessage(content=new_complaint_email)]}

logger.info(&#8221;--- Starting workflow... ---&#8221;)
# This call will PAUSE at &#8216;human_review&#8217; and return the current state
interrupted_state = app_stage3.invoke(new_inputs, config=config)

logger.info(&#8221;--- WORKFLOW PAUSED FOR HUMAN REVIEW ---&#8221;)

# --- Step 2: Show the human (you) what to review ---
# Get the AI&#8217;s draft response from the interrupted state
ai_draft = &#8220;&#8221;
for msg in reversed(interrupted_state.get(&#8221;messages&#8221;, [])):
    if msg.__class__.__name__ == &#8220;AIMessage&#8221; and msg.content.strip():
        ai_draft = msg.content
        break

logger.info(f&#8221;\n Original Email:\n{interrupted_state[&#8217;original_email&#8217;]}\n&#8221;)
logger.info(f&#8221; AI-Generated Draft:\n{ai_draft}\n&#8221;)

# --- Step 3: Get REAL feedback from the user via input() ---
logger.info(&#8221;---  WAITING FOR YOUR INPUT ---&#8221;)
logger.info(&#8221;Provide feedback/edits (or just press Enter to approve the draft as-is):&#8221;)
feedback_comment = input()

human_feedback = {}
if feedback_comment:
    # If you provided feedback, you must also provide the *new* summary
    print(&#8221;\nPlease provide the new, approved summary:&#8221;)
    approved_summary = input()
    human_feedback = {
        &#8220;approved_summary&#8221;: approved_summary,
        &#8220;comment&#8221;: feedback_comment
    }
else:
    # If you just pressed Enter, approve the original draft
    print(&#8221;---  No feedback provided. Approving original draft... ---&#8221;)
    human_feedback = {
        &#8220;approved_summary&#8221;: ai_draft, # Approve the original draft
        &#8220;comment&#8221;: &#8220;Approved as-is.&#8221;
    }

print(&#8221;--- Resuming workflow... ---&#8221;)
# We use invoke() again with the same thread_id to resume after human feedback
final_result = app_stage3.invoke(human_feedback, config=config)

# Display Final Results
logger.info(&#8221;\n Workflow Completed with Human Review\n&#8221;)
print(&#8221;Final Summary:&#8221;, final_result.get(&#8221;summary&#8221;), &#8220;\n&#8221;)

logger.info(&#8221;Conversation Messages:&#8221;)
for msg in final_result.get(&#8221;messages&#8221;, []):
    print(f&#8221;- {msg.__class__.__name__}: {msg.content}\n&#8221;)</code></pre></div><h4>Output</h4><p>The output below shows that it is straightforward to modify the output from the LLM and this application greatly improve the customer support workflow.</p><pre><code>## Final Summary: <strong>**Customer&#8217;s Complaint (summarised)**</strong>

The customer ordered the <em>*MegaWidget 2000*</em> (Order ID <strong>**B-54321**</strong>) two days ago and has not yet received any shipping updates. They would like to know the current status of the shipment and confirm the amount that was charged.

---

### <strong>**Interpretation of the Tool Output**</strong>
- <strong>**Product:**</strong> MegaWidget 2000  
- <strong>**Order status:**</strong> <strong>**Shipped**</strong>  
- <strong>**Price charged:**</strong> <strong>**&#163;149**</strong>

---

### <strong>**Response**</strong>

Hi there,

Thank you for reaching out. I&#8217;ve pulled up your order details:

| Item | Detail |
|------|---------|
| <strong>**Product**</strong> | MegaWidget 2000 |
| <strong>**Order ID**</strong> | <strong>**B-54321**</strong> |
| <strong>**Current status**</strong> | <strong>**Shipped**</strong> |
| <strong>**Amount charged**</strong> | <strong>**&#163;149**</strong> |

Your package has already left our warehouse and is on its way to you. You should receive a tracking number and further shipping updates within the next 24 hours. If you&#8217;d like me to send the tracking details right away, just let me know.

Please feel free to ask if you have any other questions or need further assistance.

Best regards,  
<strong>**[Your Name]**</strong>  
Customer Support Team</code></pre><h3>Conclusion</h3><p>We have built a complete agentic bot, starting from a simple LLM call, then adding tool-call capability, and eventually including a human-in-the-loop. These are the fundamentals of modern agentic applications, and the agentic customer support AI bot we have built is a highly practical bot, suitable for adoption due to its quick wins and minimal risk of errors.</p><p></p><h3>Gotchas</h3><ul><li><p>The <code>tools_condition</code> function is a routing mechanism. It takes the current state, inspects the last message in <code>messages</code> for a tool-call request, and returns the appropriate tools and <code>_end_</code> if none are found. It will error if it encounters an unexpected structure. Without a routing map, <code>tools_condition</code> cannot reliably decide which node to route to in cases of noisy or ambiguous input. It is therefore recommended to provide a routing map that explicitly instructs <code>tools_condition</code> on the correct path when no tool call is detected.</p></li><li><p>The <code>state</code> object serves as the main database during graph execution. Ensure that any data required by downstream nodes is returned to the state as soon as it is generated.</p></li></ul><p></p><h3>Next Steps</h3><p>Phew! That was quite a journey through the basics of LangGraph, and it should get easier from here onward. I&#8217;ll keep this brief, but there are many possible extensions: for example, human feedback could be fed back into the LLM to refine its output, or tool calls could be implemented using <a href="https://medium.com/@nimritakoul01/the-model-context-protocol-mcp-a-complete-tutorial-a3abe8a7f4ef">MCP</a>.</p><p><br>Before concluding, here are a few points often overlooked in tutorial applications: while learning is a key goal, one should also consider the ultimate aim &#8212; deriving real value from the application. Achieving this requires putting the application into production, which involves additional considerations such as safety, security, compliance, scalability, evaluation, cost, and more. For now, let&#8217;s enjoy exploring the new agentic capabilities provided by LangGraph.</p><p></p><h3><strong>About The Author</strong></h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!xWgA!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcab4e6f5-4859-4c74-8fa0-b48ee02273b9_1024x1024.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!xWgA!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcab4e6f5-4859-4c74-8fa0-b48ee02273b9_1024x1024.jpeg 424w, https://substackcdn.com/image/fetch/$s_!xWgA!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcab4e6f5-4859-4c74-8fa0-b48ee02273b9_1024x1024.jpeg 848w, https://substackcdn.com/image/fetch/$s_!xWgA!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcab4e6f5-4859-4c74-8fa0-b48ee02273b9_1024x1024.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!xWgA!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcab4e6f5-4859-4c74-8fa0-b48ee02273b9_1024x1024.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!xWgA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcab4e6f5-4859-4c74-8fa0-b48ee02273b9_1024x1024.jpeg" width="1024" height="1024" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cab4e6f5-4859-4c74-8fa0-b48ee02273b9_1024x1024.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:175100,&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://algorythmorg.substack.com/i/193068110?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcab4e6f5-4859-4c74-8fa0-b48ee02273b9_1024x1024.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_!xWgA!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcab4e6f5-4859-4c74-8fa0-b48ee02273b9_1024x1024.jpeg 424w, https://substackcdn.com/image/fetch/$s_!xWgA!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcab4e6f5-4859-4c74-8fa0-b48ee02273b9_1024x1024.jpeg 848w, https://substackcdn.com/image/fetch/$s_!xWgA!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcab4e6f5-4859-4c74-8fa0-b48ee02273b9_1024x1024.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!xWgA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcab4e6f5-4859-4c74-8fa0-b48ee02273b9_1024x1024.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><a href="https://www.linkedin.com/in/koakande/">Kabiru Akande, PhD</a> is an AI Engineering Manager with over a decade of experience leading the design and deployment of secure, scalable enterprise AI systems, with deep expertise in security, safety, infrastructure, and operations. </p><p>He holds a PhD in Signal Processing and Digital Communications from The University of Edinburgh and is an inventor with multiple granted U.S. patents in signal processing and communications. He is also a speaker and presenter on topics including AI engineering, wireless communications and academic career pathways. (<a href="https://kbakande.github.io/">full bio</a>)</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://koakande.substack.com/subscribe&quot;,&quot;text&quot;:&quot;Subscribe to Kabiru&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://koakande.substack.com/subscribe"><span>Subscribe to Kabiru</span></a></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://news.algorythm.org/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Algorythm! Subscribe for free to receive more technical insights from the community and support our work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p>]]></content:encoded></item><item><title><![CDATA[Multi-Agent Coding, Without the Chaos]]></title><description><![CDATA[Practical patterns for splitting work, coordinating execution, and reviewing results in real codebases]]></description><link>https://news.algorythm.org/p/multi-agent-coding-without-the-chaos</link><guid isPermaLink="false">https://news.algorythm.org/p/multi-agent-coding-without-the-chaos</guid><dc:creator><![CDATA[Andrew Orobator]]></dc:creator><pubDate>Fri, 27 Mar 2026 15:30:54 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!klIT!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d109096-4a5c-4636-81b4-c292afc2c429_2760x1504.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>This publication is by members of the <strong><a href="https://algorythm.org/">Algorythm</a></strong> Community. A network of 20k+ black software engineers sharing technical insights across all fields of software development. Join us on <a href="https://www.linkedin.com/groups/8873861/">LinkedIn</a>, <a href="https://www.facebook.com/groups/algorythm">Facebook</a> and <a href="https://algorythmorg.substack.com/subscribe">Subscribe</a> for more insights.</em></p><div><hr></div><p><em>This is Part 9 of a 10-part series on AI-assisted development workflows. Find the series <a href="https://medium.com/@andreworobator/vibe-engineering-from-random-code-to-deterministic-systems-06e2bf87c144">here</a></em></p><div><hr></div><p>I had six agents running in parallel across six git worktrees &#8212; separate working copies of the repo, each on its own branch, sharing the same git history but with their own files on disk. A large migration, broken into independent pieces &#8212; each agent with its own <a href="https://medium.com/@andreworobator/vibe-engineering-from-random-code-to-deterministic-systems-part-4-0155b79d1fcc">worklog</a>, its own branch, its own PR. The editing portion went fine. Diffs were clean. Plans were being followed.</p><p>Then they all started running tests at the same time.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!RpN1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F162eeb86-b3f8-4ee1-a2fb-29a4f42f08bc_1110x1256.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!RpN1!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F162eeb86-b3f8-4ee1-a2fb-29a4f42f08bc_1110x1256.png 424w, https://substackcdn.com/image/fetch/$s_!RpN1!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F162eeb86-b3f8-4ee1-a2fb-29a4f42f08bc_1110x1256.png 848w, https://substackcdn.com/image/fetch/$s_!RpN1!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F162eeb86-b3f8-4ee1-a2fb-29a4f42f08bc_1110x1256.png 1272w, https://substackcdn.com/image/fetch/$s_!RpN1!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F162eeb86-b3f8-4ee1-a2fb-29a4f42f08bc_1110x1256.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!RpN1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F162eeb86-b3f8-4ee1-a2fb-29a4f42f08bc_1110x1256.png" width="1110" height="1256" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/162eeb86-b3f8-4ee1-a2fb-29a4f42f08bc_1110x1256.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1256,&quot;width&quot;:1110,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Force Quit showing Cursor at 193 GB&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Force Quit showing Cursor at 193 GB" title="Force Quit showing Cursor at 193 GB" srcset="https://substackcdn.com/image/fetch/$s_!RpN1!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F162eeb86-b3f8-4ee1-a2fb-29a4f42f08bc_1110x1256.png 424w, https://substackcdn.com/image/fetch/$s_!RpN1!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F162eeb86-b3f8-4ee1-a2fb-29a4f42f08bc_1110x1256.png 848w, https://substackcdn.com/image/fetch/$s_!RpN1!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F162eeb86-b3f8-4ee1-a2fb-29a4f42f08bc_1110x1256.png 1272w, https://substackcdn.com/image/fetch/$s_!RpN1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F162eeb86-b3f8-4ee1-a2fb-29a4f42f08bc_1110x1256.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>193 GB of memory. On a 64 GB machine. The system was swap-thrashing so hard I couldn&#8217;t even open Activity Monitor. I had to force-reboot.</p><p><strong>Editing is cheap. Execution is the bottleneck.</strong> A swarm doesn&#8217;t become powerful when more agents start writing. It becomes powerful when coordination, verification, and review scale faster than code generation. Six agents writing code in parallel barely registers on the CPU. Six agents each spinning up Gradle daemons, compiling Kotlin, and running test suites? That&#8217;s six independent build systems fighting over the same physical resources.</p><p>And memory isn&#8217;t even the only wall. Kotlin&#8217;s build cache hardcodes absolute file paths. Every worktree I spin up does a full cache invalidation &#8212; 40+ minute initial builds on Reddit&#8217;s codebase. Another developer on an M2 Pro Mac reported thermal throttling running a <em>single </em>agent loop on a complex Android app. Two instances? Physically impossible.</p><p>For web developers with fast builds and no compilation cache, multi-agent localhost might work fine. For compiled languages with heavy build systems, it&#8217;s currently impractical. The fix is cloud agents, and that&#8217;s where this is all heading. </p><h3>The Multi-Agent Spectrum</h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!klIT!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d109096-4a5c-4636-81b4-c292afc2c429_2760x1504.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!klIT!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d109096-4a5c-4636-81b4-c292afc2c429_2760x1504.jpeg 424w, https://substackcdn.com/image/fetch/$s_!klIT!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d109096-4a5c-4636-81b4-c292afc2c429_2760x1504.jpeg 848w, https://substackcdn.com/image/fetch/$s_!klIT!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d109096-4a5c-4636-81b4-c292afc2c429_2760x1504.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!klIT!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d109096-4a5c-4636-81b4-c292afc2c429_2760x1504.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!klIT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d109096-4a5c-4636-81b4-c292afc2c429_2760x1504.jpeg" width="1456" height="793" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1d109096-4a5c-4636-81b4-c292afc2c429_2760x1504.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:793,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:301899,&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://algorythmorg.substack.com/i/192304846?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d109096-4a5c-4636-81b4-c292afc2c429_2760x1504.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_!klIT!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d109096-4a5c-4636-81b4-c292afc2c429_2760x1504.jpeg 424w, https://substackcdn.com/image/fetch/$s_!klIT!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d109096-4a5c-4636-81b4-c292afc2c429_2760x1504.jpeg 848w, https://substackcdn.com/image/fetch/$s_!klIT!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d109096-4a5c-4636-81b4-c292afc2c429_2760x1504.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!klIT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d109096-4a5c-4636-81b4-c292afc2c429_2760x1504.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>There are three ways to run multiple agents, and which one you reach for depends on what you&#8217;re doing and what your system can handle.</p><p><strong>Subagents</strong> run inside a parent agent&#8217;s session, each with its own context window and prompt. The parent only receives the summary, not the full search trail &#8212; subagents actually <em>save</em> context by doing deep work in their own windows. Subagents save context, but they can&#8217;t coordinate laterally. They only talk to the parent.</p><p>I learned the limits of this the hard way. On Sparkpass, a Next.js ticketing app, the product spec had drifted from the codebase. I planned a 7-domain parallel audit &#8212; Auth, Events, Payments, Wallets, Dashboard, Attendee, Admin &#8212; each subagent with its own slice of the spec and code locations to examine. The plan was clean. The machine couldn&#8217;t handle it. </p><p>Too many subagents running simultaneously hit local resource limits, and the whole thing ground to a halt. I had to fall back to running the domains serially, one agent at a time. That&#8217;s where the <code>NEXT_AGENT_PROMPT</code> pattern came from &#8212; each agent wrote a structured handoff of what it found, what was left, and what the next agent should be aware of. The serial version found 23 gaps across the codebase. The parallel plan was better in theory. The serial fallback actually shipped.</p><p><strong>Independent sessions</strong> are separate editor or terminal windows, each in its own git worktree, with its own agent. No shared context at all. The key is to design the work so agents don&#8217;t <em>need</em> to coordinate &#8212; choose tasks that are genuinely independent. Separate features, documentation, isolated modules. If two agents touch the same file, you&#8217;ve picked the wrong tasks to parallelize. On platforms with fast builds, independent sessions will usually beat serial execution on wall-clock time.</p><p><strong>Serial handoffs</strong> are what the Sparkpass audit fell back to &#8212; and they worked. No compaction loss because nothing carries over in-context; the handoff file <em>is</em> the context. Steve Yegge&#8217;s <a href="https://github.com/steveyegge/beads">Beads</a> system takes this further with an issue tracker as shared working memory, <code>bd ready</code>surfacing unblocked tasks, and a dependency graph enforcing ordering. Serial makes sense when a task is genuinely unparallelizable or when you&#8217;re up against device constraints like the Gradle and memory walls from earlier.</p><p>The decision rule is simple: <strong>subagents for parallel research, independent sessions for isolated implementation, serial handoffs for dependency-heavy or long-lived work. </strong>Most real workflows mix all three.</p><p><strong>When do you actually need parallel agents?</strong> Sergio Sastre Florez, an Android GDE, pushed back on this: if agents are running long enough to parallelize, the output is probably too large to review carefully. Large parallel outputs hide duplication and unnecessary code.</p><p>He&#8217;s right. Most tasks don&#8217;t need parallelism. A task too simple for parallel execution wastes more time on setup than it saves.</p><p>And there&#8217;s a hidden cost beyond compute: every agent you spawn makes you a manager. You&#8217;re context-switching between worktrees, checking progress, unsticking blocked agents, reviewing diffs across multiple PRs. Engineers are used to a maker schedule, not a manager schedule. Three parallel agents can drain you faster than one focused session if you&#8217;re not careful.</p><p><strong>When parallel actually helps:</strong> large migrations with battle-tested skills, epics with independent tickets, features with parts that don&#8217;t depend on each other. And you shouldn&#8217;t decide this yourself. Ask the agent: &#8220;Can this work be parallelized?&#8221; Then verify the proposed split against file overlap, dependency chains, and review burden. It might say no. That&#8217;s a valid answer.</p><h3>Specialists Beat Generalists</h3><p>Marvin Minsky&#8217;s <em><a href="https://en.wikipedia.org/wiki/Society_of_Mind">Society of Mind</a></em> argues that intelligence emerges from many simple agents operating at different abstraction levels. High-level agents coordinate strategy. Mid-level agents execute specialized tasks. Low-level agents handle mechanical operations.</p><p>I learned the difference between horizontal and vertical partitioning building <a href="https://medium.com/@andreworobator/eagle-eye-turning-screenshot-review-into-deterministic-qa-5f8ff97ebb56">Eagle Eye</a>, a screenshot review system. The first version used 3 generalist subagents &#8212; each one reviewed a batch of screenshots for <em>everything</em>: contrast, clipping, layout, touch targets. Fifteen things to check per screenshot. Low contrast text on the settings screen shipped because all three generalists checked for contrast and none of them owned it. When everybody&#8217;s responsible, nobody&#8217;s accountable.</p><p>The fix was vertical partitioning. Instead of 3 generalists reviewing batches, I proposed 4 specialists reviewing all screenshots for one concern each:</p><ul><li><p><strong>Text Contrast Agent</strong> &#8212; WCAG violations across all screenshots</p></li><li><p><strong>UI Clipping Agent</strong> &#8212; content overflow across all screenshots</p></li><li><p><strong>Layout Agent</strong> &#8212; design system spacing violations</p></li><li><p><strong>Touch Target Agent</strong> &#8212; interactive elements below 48dp</p></li></ul><p>A coordinator aggregates their findings into a unified report. Each specialist has one mandate. Narrower prompts mean lower token costs. And because each agent owns exactly one concern, things are less likely to fall through.</p><p>The same pattern showed up in Reddit&#8217;s Flag Lifecycle Agent &#8212; an autonomous system that discovers stale feature flags in the codebase, validates them against production experiment data, and generates cleanup PRs. Three abstraction layers:</p><ul><li><p><strong>Orchestration</strong> &#8212; discovery, validation, complexity scoring, spec generation</p></li><li><p><strong>Specialists</strong> &#8212; Planner, Coder, Reviewer (a 3-agent loop inside a cloud sandbox)</p></li><li><p><strong>Platform</strong> &#8212; sandboxed execution, git operations, PR creation, experiment data APIs</p></li></ul><p>Each layer communicates via structured data. The orchestrator doesn&#8217;t write Kotlin. The coder doesn&#8217;t know how to query experiment data. The platform doesn&#8217;t know what a flag cleanup is. Clear boundaries, clear responsibilities. In Phase 1 testing, this architecture cleaned up 7 flags in a single day at $8.79 total &#8212; all 7 PRs passed CI.</p><p><strong>The pattern generalizes across stacks.</strong> I used the same layered architecture in AutonomyOS, a Next.js/TypeScript agent platform. Events trigger proposals, proposals decompose into missions, missions break into concurrent steps &#8212; each step executed independently, results aggregated by a coordinator. Different language, different domain, same shape: coordinator at the top, specialists in the middle, platform at the bottom.</p><h3>The Conductor Pattern</h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!N-jH!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0032d8ec-a62d-42b1-89c6-cd15dcfb6e99_1024x558.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!N-jH!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0032d8ec-a62d-42b1-89c6-cd15dcfb6e99_1024x558.png 424w, https://substackcdn.com/image/fetch/$s_!N-jH!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0032d8ec-a62d-42b1-89c6-cd15dcfb6e99_1024x558.png 848w, https://substackcdn.com/image/fetch/$s_!N-jH!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0032d8ec-a62d-42b1-89c6-cd15dcfb6e99_1024x558.png 1272w, https://substackcdn.com/image/fetch/$s_!N-jH!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0032d8ec-a62d-42b1-89c6-cd15dcfb6e99_1024x558.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!N-jH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0032d8ec-a62d-42b1-89c6-cd15dcfb6e99_1024x558.png" width="1024" height="558" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0032d8ec-a62d-42b1-89c6-cd15dcfb6e99_1024x558.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:558,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:237596,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://algorythmorg.substack.com/i/192304846?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0032d8ec-a62d-42b1-89c6-cd15dcfb6e99_1024x558.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!N-jH!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0032d8ec-a62d-42b1-89c6-cd15dcfb6e99_1024x558.png 424w, https://substackcdn.com/image/fetch/$s_!N-jH!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0032d8ec-a62d-42b1-89c6-cd15dcfb6e99_1024x558.png 848w, https://substackcdn.com/image/fetch/$s_!N-jH!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0032d8ec-a62d-42b1-89c6-cd15dcfb6e99_1024x558.png 1272w, https://substackcdn.com/image/fetch/$s_!N-jH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0032d8ec-a62d-42b1-89c6-cd15dcfb6e99_1024x558.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" 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 orchestrating parallel agents like a CPU scheduler. Independent tasks get parallelized. Dependent tasks stay serial. You set the goals and constraints. The AI proposes the schedule.</p><p>In practice, this means one main editor window stays on <code>develop</code> and orchestrates. It creates git worktrees, writes <a href="https://medium.com/@andreworobator/vibe-engineering-from-random-code-to-deterministic-systems-part-4-0155b79d1fcc">worklogs</a>, and delegates. Each execution window opens in its own worktree, follows its assigned worklog, commits, pushes, and opens a PR. The main window never implements. It plans and coordinates.</p><p>The migration from the opening used this pattern. Each worktree got a dedicated worklog (TDD plan, verification plan, invariants, a checklist of surprises and notes) and a separate PR &#8212; independent, not stacked.</p><p><strong>The orchestrator agent is the key upgrade.</strong> Instead of manually deciding what to parallelize, the orchestrator looks at all in-progress worktrees and picks up the next task with minimal conflicts. Ask the agent: &#8220;Look at the work remaining and the worktrees already running. What should the next agent pick up?&#8221; It considers file overlap, module boundaries, and dependency chains. It might tell you everything remaining is serial. That&#8217;s fine.</p><p><strong>Verification makes this trustworthy.</strong> Without closing the loop (TDD, red-green commits, a verification plan), the AI will push slop. Every agent following a worklog has a contract: write the test, watch it fail, write the implementation, watch it pass, commit at each transition. The worklog structure is what separates parallel execution from parallel chaos.</p><p>And the worklog survives compaction. When a long-running agent hits context limits and the conversation gets compressed, the worklog on disk is still intact. The agent can re-read it and restore full context. This is what makes parallel agents viable for complex PRs, not just trivial ones.</p><p>This is still pre-background-agent territory. You&#8217;re manually triggering each agent. You&#8217;re reviewing each PR. But you&#8217;ve separated orchestration from execution. Skills and worklogs are now executable artifacts.</p><p>More agents writing code means more code to review. That review layer is its own multi-agent problem.</p><h3>Who Reviews the Agents?</h3><p>As execution parallelizes, review must also become layered and partially automated, or the human becomes the bottleneck again. In <a href="https://medium.com/@andreworobator/vibe-engineering-from-random-code-to-deterministic-systems-part-2-d2ddd50109e7">Part 2</a>, a second model caught an issue the first one missed entirely. Different models have different blind spots, which is exactly why you want AI handling the mechanical review layer &#8212; missing imports, type inconsistencies, test coverage gaps &#8212; before a human ever sees the PR.</p><p>The principle: <strong>review must decompose into fast mechanical checks and slow human judgment.</strong> AI handles the first layer. Humans handle the second. Neither works alone at scale.</p><p>The specific tools matter less than the pattern. For my personal projects, I use Greptile for confidence scoring (a 2/5 score has consistently flagged real problems) and CodeRabbit for deep static analysis and auto-generated sequence diagrams. But any tool that gates the mechanical layer works.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!uCxi!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf3cd826-75e0-4042-a789-70c25c8bd820_1400x1743.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!uCxi!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf3cd826-75e0-4042-a789-70c25c8bd820_1400x1743.png 424w, https://substackcdn.com/image/fetch/$s_!uCxi!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf3cd826-75e0-4042-a789-70c25c8bd820_1400x1743.png 848w, https://substackcdn.com/image/fetch/$s_!uCxi!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf3cd826-75e0-4042-a789-70c25c8bd820_1400x1743.png 1272w, https://substackcdn.com/image/fetch/$s_!uCxi!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf3cd826-75e0-4042-a789-70c25c8bd820_1400x1743.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!uCxi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf3cd826-75e0-4042-a789-70c25c8bd820_1400x1743.png" width="1400" height="1743" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/df3cd826-75e0-4042-a789-70c25c8bd820_1400x1743.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1743,&quot;width&quot;:1400,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!uCxi!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf3cd826-75e0-4042-a789-70c25c8bd820_1400x1743.png 424w, https://substackcdn.com/image/fetch/$s_!uCxi!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf3cd826-75e0-4042-a789-70c25c8bd820_1400x1743.png 848w, https://substackcdn.com/image/fetch/$s_!uCxi!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf3cd826-75e0-4042-a789-70c25c8bd820_1400x1743.png 1272w, https://substackcdn.com/image/fetch/$s_!uCxi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf3cd826-75e0-4042-a789-70c25c8bd820_1400x1743.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Greptile&#8217;s confidence score flagging a critical issue &#8212; 2/5, with a clear explanation of why</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!KBbt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b7dd7d0-6953-4d10-ac16-f0803218bdcf_1400x989.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!KBbt!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b7dd7d0-6953-4d10-ac16-f0803218bdcf_1400x989.png 424w, https://substackcdn.com/image/fetch/$s_!KBbt!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b7dd7d0-6953-4d10-ac16-f0803218bdcf_1400x989.png 848w, https://substackcdn.com/image/fetch/$s_!KBbt!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b7dd7d0-6953-4d10-ac16-f0803218bdcf_1400x989.png 1272w, https://substackcdn.com/image/fetch/$s_!KBbt!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b7dd7d0-6953-4d10-ac16-f0803218bdcf_1400x989.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!KBbt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b7dd7d0-6953-4d10-ac16-f0803218bdcf_1400x989.png" width="1400" height="989" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1b7dd7d0-6953-4d10-ac16-f0803218bdcf_1400x989.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:989,&quot;width&quot;:1400,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!KBbt!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b7dd7d0-6953-4d10-ac16-f0803218bdcf_1400x989.png 424w, https://substackcdn.com/image/fetch/$s_!KBbt!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b7dd7d0-6953-4d10-ac16-f0803218bdcf_1400x989.png 848w, https://substackcdn.com/image/fetch/$s_!KBbt!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b7dd7d0-6953-4d10-ac16-f0803218bdcf_1400x989.png 1272w, https://substackcdn.com/image/fetch/$s_!KBbt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b7dd7d0-6953-4d10-ac16-f0803218bdcf_1400x989.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>CodeRabbit catching test gaps and accessibility issues with suggested fixes</p><p><strong>The workflow:</strong></p><ol><li><p>Agent writes code and tests</p></li><li><p>Push to branch, open PR</p></li><li><p>AI reviewer scores confidence and flags mechanical issues</p></li><li><p>CI passes (tests, lint, build)</p></li><li><p>Human reviews with mechanical analysis already done &#8212; primarily architecture and product decisions</p></li></ol><p>But you&#8217;re still in the loop. Still triggering every agent. Still reviewing every PR. And flag cleanup is just one use case. Unused dependency removal, lint upgrades, library migrations, dead code cleanup &#8212; every piece of tedious maintenance work that devs do on a regular basis is a candidate for the same pattern: discover, verify, ship.</p><p>A self-driving codebase doesn&#8217;t begin with autonomy. It begins when work becomes structured enough to delegate safely.</p><p><em>Follow <a href="https://www.linkedin.com/in/andrew-orobator/">Andrew</a> to catch the release of Part 10 for where this is heading: cloud agents, autonomous maintenance loops, executable worklogs, and the full Redit Flag Lifecycle case study that shows how multi-agent systems can safely discover, verify, and ship real code changes.</em></p><h3>About The Author</h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!YJ_W!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabc6dde9-2eb6-4acb-8d77-1d61450901f6_1024x1024.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!YJ_W!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabc6dde9-2eb6-4acb-8d77-1d61450901f6_1024x1024.jpeg 424w, https://substackcdn.com/image/fetch/$s_!YJ_W!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabc6dde9-2eb6-4acb-8d77-1d61450901f6_1024x1024.jpeg 848w, https://substackcdn.com/image/fetch/$s_!YJ_W!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabc6dde9-2eb6-4acb-8d77-1d61450901f6_1024x1024.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!YJ_W!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabc6dde9-2eb6-4acb-8d77-1d61450901f6_1024x1024.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!YJ_W!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabc6dde9-2eb6-4acb-8d77-1d61450901f6_1024x1024.jpeg" width="1024" height="1024" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/abc6dde9-2eb6-4acb-8d77-1d61450901f6_1024x1024.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:174496,&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://algorythmorg.substack.com/i/192304846?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabc6dde9-2eb6-4acb-8d77-1d61450901f6_1024x1024.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_!YJ_W!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabc6dde9-2eb6-4acb-8d77-1d61450901f6_1024x1024.jpeg 424w, https://substackcdn.com/image/fetch/$s_!YJ_W!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabc6dde9-2eb6-4acb-8d77-1d61450901f6_1024x1024.jpeg 848w, https://substackcdn.com/image/fetch/$s_!YJ_W!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabc6dde9-2eb6-4acb-8d77-1d61450901f6_1024x1024.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!YJ_W!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabc6dde9-2eb6-4acb-8d77-1d61450901f6_1024x1024.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><a href="https://www.linkedin.com/in/andrew-orobator/">Andrew Orobator</a> is a Senior Android Engineer @ Reddit, Musician and Public Speaker.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://andreworobator.substack.com/subscribe&quot;,&quot;text&quot;:&quot;Subscribe to Andrew&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://andreworobator.substack.com/subscribe"><span>Subscribe to Andrew</span></a></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://news.algorythm.org/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Algorythm! Subscribe for free to receive more technical insights from the community and support our work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p><p></p><p></p><p></p>]]></content:encoded></item><item><title><![CDATA[Building a Distributed Database From Scratch With Rust]]></title><description><![CDATA[A practical deep dive into modern storage engines]]></description><link>https://news.algorythm.org/p/building-a-distributed-database-from</link><guid isPermaLink="false">https://news.algorythm.org/p/building-a-distributed-database-from</guid><dc:creator><![CDATA[Youdahe Asfaw]]></dc:creator><pubDate>Thu, 19 Mar 2026 15:41:52 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!ssgY!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ee5f23f-5a7d-4e67-a6c4-3d6c50ea2d3c_1536x1024.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>This publication is by members of the <strong><a href="https://algorythm.org/">Algorythm</a></strong> Community. A network of 20k+ black software engineers sharing technical insights across all fields of software development. Join us on <a href="https://www.linkedin.com/groups/8873861/">LinkedIn</a>, <a href="https://www.facebook.com/groups/algorythm">Facebook</a> and <a href="https://algorythmorg.substack.com/subscribe">Subscribe</a> for more insights.</em></p><div><hr></div><p>Many engineers use databases every day. Few ever look inside one. I wanted to change that for myself, so I built <strong><a href="https://github.com/Youdahe123/youdaheDB">youdaheDB</a></strong> a distributed key-value database engine written from scratch in Rust, using only the standard library. No external crates. No frameworks. Just raw bytes, files, and the Rust compiler yelling at me.</p><h3>What is youdaheDB?</h3><p>It&#8217;s a working key-value storage engine built on the same architecture that powers databases like RocksDB and LevelDB: the <strong>LSM-Tree (Log-Structured Merge Tree)</strong>.</p><p>You can put keys, get keys, delete keys, and scan everything in sorted order &#8212; all through an interactive REPL. Kill the process mid-write, restart it, and your data is still there.</p><pre><code><code>$ cargo run

Distributed DB Engine v0.2 (with SSTables)

db&gt; put user:1 youdahe
OK

db&gt; put user:2 alice
OK

db&gt; get user:1
youdahe
</code></code></pre><p>Kill it. Restart it.</p><pre><code><code>$ cargo run

[engine] Recovered 2 entries from WAL

db&gt; get user:1
youdahe
</code></code></pre><p>Everything survived.</p><div><hr></div><h3>The Architecture</h3><p>youdaheDB has four core components, each built from scratch:</p><div><hr></div><h4><strong>1. Write-Ahead Log (WAL)</strong></h4><p>Before your database can do anything else reliably, it needs to be honest about what happened &#8212; even if the power goes out.</p><p>That&#8217;s what a <strong>Write-Ahead Log</strong> is. It&#8217;s a simple append-only log file on disk where every write gets recorded <em>before</em> it gets committed to the db in memory.</p><p>Think of it like a receipt printer: before your order is prepared, the kitchen gets the ticket. If something crashes, you replay the tickets from the beginning to reconstruct exactly where you left off.</p><p>Even though it hits disk first which is slower than memory, it doesn&#8217;t need to do any file seeks since it&#8217;s &#8220;append-only&#8221;. This is what makes it fast from a latency perspective because appending to the end of a file is an O(1) operation like adding to a Linked List.</p><p>When the db client sends a write, it can get a response back as soon as the new value is appended to the end of the log without needing to wait for it to be fully processed into the actual database. Evening updating the value for an existing key or deleting a key are operations that get appended to the end of the WAL.</p><p>You might be wondering how can a log be used to represent key value pairs? You&#8217;d expect something like a Hash Map not a Linked List. And how could adding another entry to the log change a value or delete anything?</p><p>The format of the log file is simple: length-prefixed key-value pairs in little-endian binary. The length shows where the entry begins and helps the log reader know where the current record ends so it can parse the next record. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Czkp!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F54e21507-8cd8-4bc9-bfda-3dce8b06c179_1600x461.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Czkp!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F54e21507-8cd8-4bc9-bfda-3dce8b06c179_1600x461.jpeg 424w, https://substackcdn.com/image/fetch/$s_!Czkp!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F54e21507-8cd8-4bc9-bfda-3dce8b06c179_1600x461.jpeg 848w, https://substackcdn.com/image/fetch/$s_!Czkp!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F54e21507-8cd8-4bc9-bfda-3dce8b06c179_1600x461.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!Czkp!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F54e21507-8cd8-4bc9-bfda-3dce8b06c179_1600x461.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Czkp!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F54e21507-8cd8-4bc9-bfda-3dce8b06c179_1600x461.jpeg" width="1456" height="420" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/54e21507-8cd8-4bc9-bfda-3dce8b06c179_1600x461.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:420,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:113734,&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://algorythmorg.substack.com/i/191468866?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F54e21507-8cd8-4bc9-bfda-3dce8b06c179_1600x461.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_!Czkp!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F54e21507-8cd8-4bc9-bfda-3dce8b06c179_1600x461.jpeg 424w, https://substackcdn.com/image/fetch/$s_!Czkp!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F54e21507-8cd8-4bc9-bfda-3dce8b06c179_1600x461.jpeg 848w, https://substackcdn.com/image/fetch/$s_!Czkp!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F54e21507-8cd8-4bc9-bfda-3dce8b06c179_1600x461.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!Czkp!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F54e21507-8cd8-4bc9-bfda-3dce8b06c179_1600x461.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>On restart, you replay the WAL from the beginning and rebuild your state in memory, which includes processing delete commands. If a key shows up twice, it just overwrites the value it saw before with the latest value.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ry-c!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb944d743-fc9b-4aef-9e2f-ef3bc7c3f234_1295x832.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ry-c!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb944d743-fc9b-4aef-9e2f-ef3bc7c3f234_1295x832.jpeg 424w, https://substackcdn.com/image/fetch/$s_!ry-c!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb944d743-fc9b-4aef-9e2f-ef3bc7c3f234_1295x832.jpeg 848w, https://substackcdn.com/image/fetch/$s_!ry-c!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb944d743-fc9b-4aef-9e2f-ef3bc7c3f234_1295x832.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!ry-c!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb944d743-fc9b-4aef-9e2f-ef3bc7c3f234_1295x832.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ry-c!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb944d743-fc9b-4aef-9e2f-ef3bc7c3f234_1295x832.jpeg" width="1295" height="832" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b944d743-fc9b-4aef-9e2f-ef3bc7c3f234_1295x832.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:832,&quot;width&quot;:1295,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:172493,&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://algorythmorg.substack.com/i/191468866?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb944d743-fc9b-4aef-9e2f-ef3bc7c3f234_1295x832.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_!ry-c!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb944d743-fc9b-4aef-9e2f-ef3bc7c3f234_1295x832.jpeg 424w, https://substackcdn.com/image/fetch/$s_!ry-c!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb944d743-fc9b-4aef-9e2f-ef3bc7c3f234_1295x832.jpeg 848w, https://substackcdn.com/image/fetch/$s_!ry-c!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb944d743-fc9b-4aef-9e2f-ef3bc7c3f234_1295x832.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!ry-c!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb944d743-fc9b-4aef-9e2f-ef3bc7c3f234_1295x832.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><div><hr></div><h4><strong>2. MemTable</strong></h4><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!wWke!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d989877-4451-471f-857b-10132ead6963_997x682.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!wWke!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d989877-4451-471f-857b-10132ead6963_997x682.jpeg 424w, https://substackcdn.com/image/fetch/$s_!wWke!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d989877-4451-471f-857b-10132ead6963_997x682.jpeg 848w, https://substackcdn.com/image/fetch/$s_!wWke!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d989877-4451-471f-857b-10132ead6963_997x682.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!wWke!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d989877-4451-471f-857b-10132ead6963_997x682.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!wWke!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d989877-4451-471f-857b-10132ead6963_997x682.jpeg" width="997" height="682" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4d989877-4451-471f-857b-10132ead6963_997x682.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:682,&quot;width&quot;:997,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:292419,&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://algorythmorg.substack.com/i/191468866?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d989877-4451-471f-857b-10132ead6963_997x682.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_!wWke!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d989877-4451-471f-857b-10132ead6963_997x682.jpeg 424w, https://substackcdn.com/image/fetch/$s_!wWke!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d989877-4451-471f-857b-10132ead6963_997x682.jpeg 848w, https://substackcdn.com/image/fetch/$s_!wWke!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d989877-4451-471f-857b-10132ead6963_997x682.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!wWke!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d989877-4451-471f-857b-10132ead6963_997x682.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>A <strong>MemTable</strong> (memory table) is the database&#8217;s active in-memory view of the latest data. After each write is appended to the WAL for durability, it&#8217;s also inserted into the MemTable so reads can see the newest value immediately without going to disk first.</p><p>In youdaheDB, the MemTable is backed by Rust&#8217;s <code>BTreeMap</code>, which keeps keys sorted automatically. That sorted order matters for two reasons: it makes range scans efficient (searching by a prefix of a key), and it makes flushing to disk simpler because the data is already in the right order for an SSTable (sorted on-disk file format described in the next section). </p><p>Updates overwrite older in-memory values for the same key, but deletes are still only marked for deletion rather than removing the key entirely, so older copies on disk do not come back later.</p><div><hr></div><h4><strong>3. SSTables (Sorted String Tables)</strong></h4><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!aNm6!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff36553a4-a25d-4232-b71b-d7667dfd3012_1240x848.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!aNm6!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff36553a4-a25d-4232-b71b-d7667dfd3012_1240x848.jpeg 424w, https://substackcdn.com/image/fetch/$s_!aNm6!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff36553a4-a25d-4232-b71b-d7667dfd3012_1240x848.jpeg 848w, https://substackcdn.com/image/fetch/$s_!aNm6!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff36553a4-a25d-4232-b71b-d7667dfd3012_1240x848.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!aNm6!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff36553a4-a25d-4232-b71b-d7667dfd3012_1240x848.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!aNm6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff36553a4-a25d-4232-b71b-d7667dfd3012_1240x848.jpeg" width="1240" height="848" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f36553a4-a25d-4232-b71b-d7667dfd3012_1240x848.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:848,&quot;width&quot;:1240,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:283615,&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://algorythmorg.substack.com/i/191468866?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff36553a4-a25d-4232-b71b-d7667dfd3012_1240x848.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_!aNm6!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff36553a4-a25d-4232-b71b-d7667dfd3012_1240x848.jpeg 424w, https://substackcdn.com/image/fetch/$s_!aNm6!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff36553a4-a25d-4232-b71b-d7667dfd3012_1240x848.jpeg 848w, https://substackcdn.com/image/fetch/$s_!aNm6!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff36553a4-a25d-4232-b71b-d7667dfd3012_1240x848.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!aNm6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff36553a4-a25d-4232-b71b-d7667dfd3012_1240x848.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>RAM is fast, but it&#8217;s limited in size. Once the MemTable grows past a certain threshold, youdaheDB flushes it to disk as an <strong>SSTable</strong> &#8212; a Sorted String Table and the MemTable is emptied.</p><p>An SSTable is an immutable, sorted file. &#8220;Sorted&#8221; means the keys are written in alphabetical order, which makes lookups efficient: once you scan past the key you&#8217;re looking for, you know it isn&#8217;t in this file. &#8220;Immutable&#8221; means once it&#8217;s written, it&#8217;s never modified &#8212; no partial updates, no corruption risk.</p><p>Over time, multiple SSTables accumulate on disk. Reads search them newest-to-oldest, and the first match wins.</p><div><hr></div><h4><strong>4. Tombstones</strong></h4><p>When you delete a key, you can&#8217;t just erase it from the MemTable and call it a day. Older copies of that key may still exist in files on disk. If you silently removed the entry from memory, those older values would &#8220;reappear&#8221; the next time you went looking on disk.</p><p>The solution is a <strong>tombstone</strong> &#8212; a special marker that says &#8220;this key was deleted.&#8221; This is the missing piece to expalain how deletion is happening as described in the WAL, MemTable and SSTable.</p><p>Instead of removing the entry, youdaheDB inserts a <code>None</code> value for that key. When a read finds a tombstone, it knows to stop looking further and return &#8220;not found,&#8221; even if older copies exist on disk.</p><p>Tombstones are eventually cleaned up during <strong>compaction</strong> (more on that below).</p><div><hr></div><h4><strong>5. The Storage Engine</strong></h4><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ssgY!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ee5f23f-5a7d-4e67-a6c4-3d6c50ea2d3c_1536x1024.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ssgY!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ee5f23f-5a7d-4e67-a6c4-3d6c50ea2d3c_1536x1024.jpeg 424w, https://substackcdn.com/image/fetch/$s_!ssgY!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ee5f23f-5a7d-4e67-a6c4-3d6c50ea2d3c_1536x1024.jpeg 848w, https://substackcdn.com/image/fetch/$s_!ssgY!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ee5f23f-5a7d-4e67-a6c4-3d6c50ea2d3c_1536x1024.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!ssgY!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ee5f23f-5a7d-4e67-a6c4-3d6c50ea2d3c_1536x1024.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ssgY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ee5f23f-5a7d-4e67-a6c4-3d6c50ea2d3c_1536x1024.jpeg" width="1456" height="971" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2ee5f23f-5a7d-4e67-a6c4-3d6c50ea2d3c_1536x1024.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:971,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:809714,&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://algorythmorg.substack.com/i/191468866?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ee5f23f-5a7d-4e67-a6c4-3d6c50ea2d3c_1536x1024.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_!ssgY!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ee5f23f-5a7d-4e67-a6c4-3d6c50ea2d3c_1536x1024.jpeg 424w, https://substackcdn.com/image/fetch/$s_!ssgY!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ee5f23f-5a7d-4e67-a6c4-3d6c50ea2d3c_1536x1024.jpeg 848w, https://substackcdn.com/image/fetch/$s_!ssgY!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ee5f23f-5a7d-4e67-a6c4-3d6c50ea2d3c_1536x1024.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!ssgY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2ee5f23f-5a7d-4e67-a6c4-3d6c50ea2d3c_1536x1024.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The coordinator that ties everything together. It owns the WAL, MemTable, and all SSTables.</p><blockquote><p><strong>Write path:</strong> WAL (durability) &#8594; MemTable (speed) &#8594; SSTable flush when full.</p></blockquote><p></p><blockquote><p><strong>Read path:</strong> MemTable (newest) &#8594; SSTables newest-to-oldest &#8594; not found.</p></blockquote><p>On startup, it discovers existing SSTable files on disk, replays the WAL to rebuild the MemTable, and you&#8217;re back in business.</p><div><hr></div><h3><strong>The Roadmap</strong></h3><p>I&#8217;m building in public, youdaheDB is still early-stage. This article is part I in a series where I&#8217;ll explain from start to end how to build a production ready distributed database.<br><br>There&#8217;s a list of missing pieces waiting to be tackled:</p><p><strong>Compaction</strong> is the big one. As SSTables accumulate, reads get expensive &#8212; the engine has to search more and more files. Compaction merges multiple SSTables into one: it sorts and combines all the entries, applies tombstones (permanently removing deleted keys), and discards superseded versions of the same key. Without compaction, the engine gets slower over time and wastes disk space on stale and deleted data.</p><p>Beyond compaction, what&#8217;s missing includes:</p><ul><li><p><strong>Bloom filters</strong> &#8212; probabilistic data structures that let the engine quickly rule out SSTables that definitely don&#8217;t contain a key, avoiding unnecessary disk reads</p></li><li><p><strong>Indexes</strong> &#8212; structures that enable faster lookups without scanning files linearly</p></li><li><p><strong>Checksums</strong> &#8212; to detect file corruption on disk</p></li><li><p><strong>Manifests</strong> &#8212; a durable record of which SSTable files are current, so the engine doesn&#8217;t have to re-discover them on startup</p></li><li><p><strong>WAL rotation</strong> &#8212; periodically replacing the WAL with a fresh file after old entries are safely flushed to SSTables</p></li></ul><div><hr></div><h3>The Next Phase: Raft Consensus</h3><p>A single-node database is useful, but what happens when that machine dies?</p><p>youdaheDB&#8217;s next phase is implementing the <strong>Raft consensus protocol</strong> to replicate data across multiple nodes. Consensus protocols exist to solve a hard problem: how do you get multiple machines to agree on the state of shared data, even when some of them crash or go offline?</p><p>The core idea in Raft: one node is elected <strong>leader</strong>, and all writes go through it. A write is only considered committed once a <strong>quorum</strong> &#8212; a majority of nodes &#8212; confirms they&#8217;ve stored it. If the leader dies, the remaining nodes hold an election and choose a new one. Because commit quorums and election quorums always overlap, any newly elected leader is guaranteed to have seen all previously committed data.</p><p>Each node maintains its <strong>own local persistent log</strong> that it uses to track and replay committed entries &#8212; similar in purpose to the single-node WAL. The Raft protocol coordinates these logs across the cluster: the leader sends log entries to followers, and once a majority acknowledges them, the entry is committed on all nodes. It&#8217;s not a single shared log &#8212; it&#8217;s a distributed agreement protocol that keeps independent local logs in sync.</p><div><hr></div><h3>Why Rust?</h3><p>Rust&#8217;s ownership model is well-suited for database engineering. The borrow checker enforces memory safety at compile time &#8212; it eliminates whole classes of bugs like use-after-free and data races that are common in systems code written in C or C++.</p><p>That said, Rust doesn&#8217;t fully solve the reader-writer coordination problem on its own. For example: if one thread is serving reads while another is flushing the MemTable to an SSTable, Rust doesn&#8217;t automatically figure out how to coordinate that handoff. You still need to choose the right synchronization primitive &#8212; a <code>Mutex</code>, an <code>RwLock</code>, a channel &#8212; and reason carefully about the access pattern.</p><p>What Rust <em>does</em> do is make it much harder to accidentally create undefined behavior while doing that. In Java or Python, you might use locks incorrectly and not find out until a crash in production. In Rust, many of those mistakes won&#8217;t compile. It does not automatically prove that your concurrency design is correct though.</p><p>No garbage collector also means predictable latency. When you&#8217;re flushing a MemTable to disk or replaying a WAL, you don&#8217;t want a GC pause in the middle of it.</p><div><hr></div><h3>What I Took Away</h3><p>Building a database from scratch teaches you things that no amount of <code>SELECT * FROM</code> ever will:</p><ul><li><p><strong>Why databases use WALs</strong> &#8212; sequential disk appends are fast; random writes are not</p></li><li><p><strong>Why tombstones exist</strong> &#8212; you can&#8217;t just &#8220;delete&#8221; something when older copies live on disk</p></li><li><p><strong>Why LSM-trees flush and compact</strong> &#8212; memory is fast but finite; disk is slow but abundant, and compaction keeps reads from getting too expensive over time</p></li><li><p><strong>Why consensus is hard</strong> &#8212; getting 3 machines to agree on anything, while handling failures and network partitions, is a genuinely difficult problem</p></li></ul><p>The entire thing is built with zero external dependencies. Just Rust&#8217;s standard library, a <code>Cargo.toml</code>, and a lot of binary serialization code.</p><p>youdaheDB isn&#8217;t production-ready. But it taught me more about how data actually lives and moves through a system than any tutorial ever could.</p><p>Check out the work in progress here on Github &#8594;  <a href="https://github.com/Youdahe123/youdaheDB">youdaheDB</a></p><h3>About The Author</h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!BjG8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7cc34566-011d-46a6-b6da-daff0d2bf714_400x400.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!BjG8!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7cc34566-011d-46a6-b6da-daff0d2bf714_400x400.png 424w, https://substackcdn.com/image/fetch/$s_!BjG8!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7cc34566-011d-46a6-b6da-daff0d2bf714_400x400.png 848w, https://substackcdn.com/image/fetch/$s_!BjG8!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7cc34566-011d-46a6-b6da-daff0d2bf714_400x400.png 1272w, https://substackcdn.com/image/fetch/$s_!BjG8!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7cc34566-011d-46a6-b6da-daff0d2bf714_400x400.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!BjG8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7cc34566-011d-46a6-b6da-daff0d2bf714_400x400.png" width="400" height="400" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7cc34566-011d-46a6-b6da-daff0d2bf714_400x400.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:400,&quot;width&quot;:400,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:122989,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://algorythmorg.substack.com/i/191468866?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7cc34566-011d-46a6-b6da-daff0d2bf714_400x400.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!BjG8!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7cc34566-011d-46a6-b6da-daff0d2bf714_400x400.png 424w, https://substackcdn.com/image/fetch/$s_!BjG8!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7cc34566-011d-46a6-b6da-daff0d2bf714_400x400.png 848w, https://substackcdn.com/image/fetch/$s_!BjG8!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7cc34566-011d-46a6-b6da-daff0d2bf714_400x400.png 1272w, https://substackcdn.com/image/fetch/$s_!BjG8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7cc34566-011d-46a6-b6da-daff0d2bf714_400x400.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" 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 href="https://www.linkedin.com/in/youdaheasfaw/">Youdahe Asfaw</a> is a Sophomore studying CS @ Gustavus Adolphus College, founder of an edtech platform called <a href="https://docere.app/">Docere</a>, and an ML researcher. He specializes in infrastructure, building replicas of tools like Docker and Kubernetes from scratch.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://youdahe.substack.com/subscribe&quot;,&quot;text&quot;:&quot;Subscribe to Youdahe&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://youdahe.substack.com/subscribe"><span>Subscribe to Youdahe</span></a></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://news.algorythm.org/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Algorythm! Subscribe for free to receive more technical insights from the community and support our work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p>]]></content:encoded></item><item><title><![CDATA[Your Java Singleton Choice Could Make Your App 871x Slower]]></title><description><![CDATA[Benchmarking synchronized, double-checked locking, and holder singletons in Java]]></description><link>https://news.algorythm.org/p/your-java-singleton-choice-could</link><guid isPermaLink="false">https://news.algorythm.org/p/your-java-singleton-choice-could</guid><dc:creator><![CDATA[Adewale Adeleye]]></dc:creator><pubDate>Thu, 12 Mar 2026 15:01:49 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!LLhW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0902cd5c-8247-4aee-84e3-872887762b08_800x533.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>This publication is by members of the <strong><a href="https://algorythm.org/">Algorythm</a></strong> Community. A network of 20k+ black software engineers sharing technical insights across all fields of software development. Join us on <a href="https://www.linkedin.com/groups/8873861/">LinkedIn</a>, <a href="https://www.facebook.com/groups/algorythm">Facebook</a> and <a href="https://algorythmorg.substack.com/subscribe">Subscribe</a> for more insights.</em></p><div><hr></div><p>What if I told you that your singleton implementation choice could make your Java application 871 times slower? That&#8217;s not a typo. In a billion-operation benchmark across different singleton patterns, I discovered performance differences so dramatic they&#8217;ll make you question everything you know about &#8220;optimized&#8221; 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_!LLhW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0902cd5c-8247-4aee-84e3-872887762b08_800x533.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!LLhW!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0902cd5c-8247-4aee-84e3-872887762b08_800x533.png 424w, https://substackcdn.com/image/fetch/$s_!LLhW!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0902cd5c-8247-4aee-84e3-872887762b08_800x533.png 848w, https://substackcdn.com/image/fetch/$s_!LLhW!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0902cd5c-8247-4aee-84e3-872887762b08_800x533.png 1272w, https://substackcdn.com/image/fetch/$s_!LLhW!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0902cd5c-8247-4aee-84e3-872887762b08_800x533.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!LLhW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0902cd5c-8247-4aee-84e3-872887762b08_800x533.png" width="800" height="533" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0902cd5c-8247-4aee-84e3-872887762b08_800x533.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:533,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Article content&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Article content" title="Article content" srcset="https://substackcdn.com/image/fetch/$s_!LLhW!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0902cd5c-8247-4aee-84e3-872887762b08_800x533.png 424w, https://substackcdn.com/image/fetch/$s_!LLhW!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0902cd5c-8247-4aee-84e3-872887762b08_800x533.png 848w, https://substackcdn.com/image/fetch/$s_!LLhW!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0902cd5c-8247-4aee-84e3-872887762b08_800x533.png 1272w, https://substackcdn.com/image/fetch/$s_!LLhW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0902cd5c-8247-4aee-84e3-872887762b08_800x533.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Benchmark results: 1 billion operations, single-threaded performance</figcaption></figure></div><p>While the singleton pattern seems simple enough to ensure only one instance of a class exists in an application, in high-concurrent Java environments, the implementation details determine whether your application scales or dies under load in a low-latency environment.</p><p>By the end of this article, you&#8217;ll understand the performance characteristics of different singleton patterns, their real-world impact on high-throughput applications, and the benchmark data that reveals these dramatic differences. Whether you&#8217;re building REST clients, connection pools, configuration managers, or metrics and logging systems, the use cases are enormous&#8202;&#8212;&#8202;and choosing the right singleton pattern could be the difference between an application that scales gracefully and one that collapses under load.</p><h3>The Traditional Approach: Synchronized Singleton</h3><p>This is the most common implementation of the Singleton pattern that is usually the go-to approach for many developers because it&#8217;s simple, thread-safe, and works correctly in every scenario. Unfortunately, it &#8220;works correctly&#8221; and &#8220;perform well&#8221; are two very different things which is why despite seeming bulletproof, it hides a performance time bomb.</p><pre><code><code>public class Logger {
    private static Logger instance;
    private Logger() {
        System.out.println("Logger initialized");
    }
    
    public static synchronized Logger getInstance() {
        if (instance == null) {
            instance = new Logger();
        }
        return instance;
    }
    public void log(String message) {
        System.out.println("[LOG] " + message);
    }
}</code></code></pre><p>Here&#8217;s where the performance disaster lurks: at runtime, every single call to getInstance() acquires a synchronized lock, even after the instance has been created. Your logger, connection pool, or configuration manager could be accessed millions of times daily, and each access must wait for the same lock.</p><p>In low-traffic applications, this overhead might seem negligible. But as concurrent users increase, the situation deteriorates rapidly. Threads queue up for the lock, creating artificial serialization in what should be parallel operations. Instead of working simultaneously, threads are forced to wait in line, each blocking the others.</p><p>The impact? In our billion-operation benchmark, the synchronized singleton took 3.5 seconds for single-threaded access. Add just 10 concurrent threads, and that time jumps to 13 seconds, which is far from the expected instant operation. This performance gap can be the difference between a responsive application and one that users abandon in frustration.</p><h3>The &#8220;Optimized&#8221; Solution: Double-Checked Locking</h3><p>The Double-Checked Locking (DCL) approach is designed to solve the synchronized singleton&#8217;s lock contention nightmare. It checks if an instance exists before acquiring any lock, and only synchronize during the rare moment of creation.</p><pre><code><code>public class Logger {
    private static volatile Logger instance;
    
    private Logger() {
        System.out.println("Logger initialized");
    }

    public static Logger getInstance() {
    // First check - no lock needed
        if (instance == null) {          
&#9;&#9;        // Lock only when necessary          
            synchronized (Logger.class) {    
&#9;&#9;            // Second check - prevent race condition      
                if (instance == null) {            
                    instance = new Logger();
                }
            }
        }
        return instance;
    }
    ...
}</code></code></pre><p>This transforms the performance landscape and ensures that after the instances is created, threads can access getInstance() without any synchronization overhead. The first check happens outside the synchronized block, meaning 99.9% of calls avoid locking entirely.</p><p>The performance improvement based on our benchmark is dramatic. DCL reduced single-threaded access time from 4.5seconds to 460milliseconds, a 7.6x improvement. With 10 concurrent threads, the gains are even more striking from 13 seconds to just 128 milliseconds, making DCL over 100x faster than the synchronized approach.</p><p>However, DCL requires the volatile keyword to ensure proper memory visibility across threads. Without thevolatile, you risk seeing partially initialized instances, which can be a dangerous bug if omitted. The pattern is intricate enough that experts like Joshua Bloch and Doug Lea have warned against it, considering it an anti-pattern due to its error-prone nature and the memory model issues that plagued Java versions before Java 5.</p><h3>The Modern Approach: Initialization-on-Demand Holder</h3><p>The Holder pattern, also known as &#8220;Initialization-on-Demand Holder,&#8221; addresses the problems of DCL by leveraging Java&#8217;s classloader behavior without the need for the volatile keyword. It ensures thread safety, removes synchronization overhead, and provides simplicity and correctness across all Java versions. Since the volatile keyword isn&#8217;t used, it relies on the JVM&#8217;s guarantees about <strong>class loading</strong> and <strong>static initializers</strong>.</p><pre><code><code>public class Logger {
    private Logger() {
        System.out.println("Logger initialized");
    }

    // Static inner class is not loaded until getInstance() is called
    private static class Holder {
        private static final Logger INSTANCE = new Logger();
    }

    public static Logger getInstance() {
        return Holder.INSTANCE;
    }
    ...
}</code></code></pre><p>The performance results are remarkable. In our benchmark, the Holder pattern reduced single-threaded access time to just <strong>4 milliseconds</strong>, which is <strong>115x faster</strong> than DCL and an astounding <strong>871x faster</strong> than the synchronized approach. The JIT compiler optimizes this pattern to near-zero cost, essentially turning singleton access into a simple field read.</p><h3>Benchmark Deep Dive: Numbers Don&#8217;t Lie</h3><p>To compare the performance impact of the three patterns, I tested different scenarios in a single-threaded environment, scaling from two million to one billion operations. The tests ran on a multi-core system with JVM warmup and multiple measurement runs for accuracy.</p><p>Below is the progressive performance scaling showing how the different options perform under different operations.</p><pre><code><code>| Operations | Synchronized | DCL   | Holder | Holder Advantage |
|------------|--------------|-------|--------|------------------|
| 2M         | 11ms         | 6ms   | 4ms    | 2.75x            |
| 400M       | 1,374ms      | 192ms | 3ms    | 458x             |
| 1B         | 3,487ms      | 460ms | 4ms    | 871.75x          |</code></code></pre><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!T_CG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe41804af-1f0e-49f3-aa99-12c59e696197_800x529.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!T_CG!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe41804af-1f0e-49f3-aa99-12c59e696197_800x529.png 424w, https://substackcdn.com/image/fetch/$s_!T_CG!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe41804af-1f0e-49f3-aa99-12c59e696197_800x529.png 848w, https://substackcdn.com/image/fetch/$s_!T_CG!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe41804af-1f0e-49f3-aa99-12c59e696197_800x529.png 1272w, https://substackcdn.com/image/fetch/$s_!T_CG!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe41804af-1f0e-49f3-aa99-12c59e696197_800x529.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!T_CG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe41804af-1f0e-49f3-aa99-12c59e696197_800x529.png" width="800" height="529" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e41804af-1f0e-49f3-aa99-12c59e696197_800x529.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:529,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Article content&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Article content" title="Article content" srcset="https://substackcdn.com/image/fetch/$s_!T_CG!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe41804af-1f0e-49f3-aa99-12c59e696197_800x529.png 424w, https://substackcdn.com/image/fetch/$s_!T_CG!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe41804af-1f0e-49f3-aa99-12c59e696197_800x529.png 848w, https://substackcdn.com/image/fetch/$s_!T_CG!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe41804af-1f0e-49f3-aa99-12c59e696197_800x529.png 1272w, https://substackcdn.com/image/fetch/$s_!T_CG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe41804af-1f0e-49f3-aa99-12c59e696197_800x529.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Performance comparison results: Synchronized. (3,487ms), DCL (460ms), Holder(4ms) - demonstrating exponential performance differences</figcaption></figure></div><p>For small-scale operations, the synchronized approach doesn&#8217;t look bad and seems to perform acceptably. As we scale to medium-level operations, the performance degradation gradually becomes noticeable. However, large-scale operations expose a performance gap that increases exponentially with scale.</p><h3>Real-World Impact</h3><p>For some high-traffic web applications and enterprise systems highlighted below, these performance differences translate into tangible business consequences:</p><p><strong>High-Traffic Web Applications:</strong></p><ul><li><p>Social media platforms with millions of daily active users could see response times degrade from milliseconds to seconds during peak traffic</p></li><li><p>API gateways handling configuration or logging requests would become bottlenecks, which could cause cascade failures across microservices</p></li></ul><p><strong>Enterprise Systems:</strong></p><ul><li><p>In real-time trading systems where microseconds matter, synchronized singletons would be completely unusable</p></li><li><p>Banking applications process millions of transactions daily across different payment channels and would accumulate hours of unnecessary overhead if a poor singleton pattern is chosen for their operations</p></li></ul><p>In production environments processing billions of operations, choosing the wrong singleton pattern can mean the difference between a system that scales gracefully and one that collapses under load. The 871x performance difference isn&#8217;t just a benchmark curiosity, it&#8217;s the difference between meeting SLA requirements and facing system outages.</p><h3>When Pattern Choice Matters Most</h3><p>Not every application needs to worry about singleton performance, but certain scenarios make pattern choice crucial. Consider the following instances:</p><p><strong>High-Frequency Access Patterns:</strong> Connection pools managing database or HTTP connections, logging systems called thousands of times per second, and configuration managers accessed on every request all require optimal singleton performance.</p><p><strong>Concurrent Environments:</strong> Real-time systems processing continuous data streams that ingest big data and multi-threaded batch processing applications handling large operations demand efficient singleton access under load.</p><p><strong>Performance-Critical Systems:</strong> High-throughput applications processing millions of operations and low-latency systems where every millisecond counts are scenarios where pattern choice becomes make-or-break.</p><p><strong>The Hidden Performance Trap:</strong> During development and testing with low load, singleton performance issues often remain invisible and seem perfectly adequate when handling dozens of requests per minute. However, production environments reveal the truth as the system scales. What works well for 10 concurrent users becomes a nightmare with 1,000, and by the time the problem surfaces, changing the pattern might require significant refactoring across multiple system components.</p><h3>Practical Implementation Guidelines</h3><h4>Default Recommendation: Use Holder Pattern</h4><p>For 99% of production singleton implementations, the Holder pattern should be your first choice:</p><pre><code><code>public class Logger {
    private Logger() {
        System.out.println("Logger initialized");
    }

    // Static inner class is not loaded until getInstance() is called
    private static class Holder {
        private static final Logger INSTANCE = new Logger();
    }

    public static Logger getInstance() {
        return Holder.INSTANCE;
    }
   // Business methods...
}</code></code></pre><h3>Why Holder Pattern Wins:</h3><ul><li><p><strong>Best performance</strong>: 871x faster than synchronized, 115x faster than DCL</p></li><li><p><strong>Simplest code</strong>: No synchronization complexity or volatile keywords</p></li><li><p><strong>Thread-safe by design</strong>: Leverages JVM class loading guarantees</p></li><li><p><strong>Maintainable</strong>: Easy to understand and modify</p></li><li><p><strong>Future-proof</strong>: Performance characteristics remain excellent as load increases</p></li></ul><h3>Migration Strategy</h3><p><strong>For New Development:</strong> Start with the Holder pattern as your default choice. It provides the best combination of performance, simplicity, and maintainability.</p><p><strong>For Existing Systems:</strong> Begin by identifying high-traffic singleton access points using profiling tools, then measure current performance to establish baseline metrics. Prioritize migration of singletons accessed most frequently, and test thoroughly in staging environments with realistic load. Finally, monitor production performance after migration to validate improvements.</p><p><strong>Code Quality Benefits:</strong> The Holder pattern delivers fewer bugs since simpler code means fewer opportunities for threading errors. It enables easier testing without synchronization complexity to mock or test around. Future developers benefit from better maintainability as they can understand and modify the code easily. Additionally, you gain performance predictability with consistent behavior across different load levels.</p><h3>Conclusion</h3><p>Our billion-operation benchmark revealed a stark truth on how the choice of Singleton pattern can create an 871x performance difference between responsive applications and ones that users abandon. Even though the initial pattern seems like a simple design decision, it becomes a critical architectural choice that determines the scalability of an application.</p><p>We discovered that the synchronized singleton, while appearing &#8220;safe,&#8221; creates performance disasters under load. DCL offers a significant improvement, reducing the overhead by 7.6x, but the Holder pattern seems to be the clear winner, delivering 871x better performance with simpler code.</p><p>Performance differences are exponential at scale, with small loads hiding massive performance gaps that only surface in production under real load scenarios. In enterprise environments processing billions of operations, the Holder pattern should be your default singleton implementation because it combines the best performance traits with the simplest and most maintainable code.</p><p>You can check out the code for the benchmark <strong><a href="https://github.com/Adewagold/java-high-performance/tree/main/src/main/java/singleton">here</a></strong>.</p><h3>Coming Up in Part 2</h3><p>If you enjoyed reading this article, don&#8217;t refactor all your singletons to use the Holder pattern just yet&#8202;&#8212;&#8202;there&#8217;s something crucial you need to know about multi-threading. In Part 2, we will discover why DCL can outperform the Holder pattern in high-concurrency scenarios, and when the highlighted choice might not be optimal after all. The results will challenge everything we&#8217;ve learned about singleton performance.</p><p></p><h3><strong>About The Author</strong></h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!wQou!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d6ea6fb-ff68-4212-8f5a-a302b1d5c3ef_1972x1820.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!wQou!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d6ea6fb-ff68-4212-8f5a-a302b1d5c3ef_1972x1820.png 424w, https://substackcdn.com/image/fetch/$s_!wQou!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d6ea6fb-ff68-4212-8f5a-a302b1d5c3ef_1972x1820.png 848w, https://substackcdn.com/image/fetch/$s_!wQou!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d6ea6fb-ff68-4212-8f5a-a302b1d5c3ef_1972x1820.png 1272w, https://substackcdn.com/image/fetch/$s_!wQou!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d6ea6fb-ff68-4212-8f5a-a302b1d5c3ef_1972x1820.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!wQou!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d6ea6fb-ff68-4212-8f5a-a302b1d5c3ef_1972x1820.png" width="1456" height="1344" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7d6ea6fb-ff68-4212-8f5a-a302b1d5c3ef_1972x1820.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1344,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:3680304,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://algorythmorg.substack.com/i/190720219?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d6ea6fb-ff68-4212-8f5a-a302b1d5c3ef_1972x1820.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!wQou!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d6ea6fb-ff68-4212-8f5a-a302b1d5c3ef_1972x1820.png 424w, https://substackcdn.com/image/fetch/$s_!wQou!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d6ea6fb-ff68-4212-8f5a-a302b1d5c3ef_1972x1820.png 848w, https://substackcdn.com/image/fetch/$s_!wQou!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d6ea6fb-ff68-4212-8f5a-a302b1d5c3ef_1972x1820.png 1272w, https://substackcdn.com/image/fetch/$s_!wQou!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d6ea6fb-ff68-4212-8f5a-a302b1d5c3ef_1972x1820.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" 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 href="https://www.linkedin.com/in/adewaledr/">Adewale Adeleye</a> is a software engineer with a background in fintech, blockchain, and scalable backend systems. His work spans enterprise software, payment infrastructure, and emerging technologies, and he writes about innovation, business, and the digital systems shaping the future. Outside of work, he loves adventure, travel, and exploring new places and ideas.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://adewagold.substack.com/subscribe&quot;,&quot;text&quot;:&quot;Subscribe to Adeleye&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://adewagold.substack.com/subscribe"><span>Subscribe to Adeleye</span></a></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://news.algorythm.org/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Algorythm! Subscribe for free to receive more technical insights from the community and support our work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[How to Build a “Find Nearby” Feature That Actually Scales]]></title><description><![CDATA[How R-trees make nearby-location queries fast in PostgreSQL and other database systems]]></description><link>https://news.algorythm.org/p/how-to-build-a-find-nearby-feature</link><guid isPermaLink="false">https://news.algorythm.org/p/how-to-build-a-find-nearby-feature</guid><dc:creator><![CDATA[Wilfred Chetat Yeku]]></dc:creator><pubDate>Fri, 06 Mar 2026 16:02:48 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!Zq5f!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c223f80-82d9-442c-b67c-dad7c6e869cc_1542x1186.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>This publication is by members of the <strong><a href="https://algorythm.org/">Algorythm</a></strong> Community. A network of 20k+ black software engineers sharing technical insights across all fields of software development. Join us on <a href="https://www.linkedin.com/groups/8873861/">LinkedIn</a>, <a href="https://www.facebook.com/groups/algorythm">Facebook</a> and <a href="https://algorythmorg.substack.com/subscribe">Subscribe</a> for more insights.</em></p><div><hr></div><p>I recently worked on a project that required querying data by geographical coordinates, which was my first experience with a production-grade app that needed this feature. I started by trying to use a <strong>WHERE</strong> clause to query data within specific geographic coordinates (latitude, longitude). This worked but was painfully slow and impractical for a production environment.</p><p> So I did some research on ways to make this work efficiently with minimal latency in response.  I found a working solution using the PostgreSQL extension PostGIS, and I then decided to dig deeper into the topic to better understand what was actually happening under the hood.</p><h3>Why Traditional Indexes Fail</h3><p>While B-trees can index multiple columns at a time (composite indexes), they fundamentally sort data linearly. Because of this, when you need to query data using true multi-dimensional criteria&#8212;such as searching within a bounding box using latitude and longitude&#8212;B-trees become inadequate and inefficient.</p><p>Imagine you have a table with 1 million store locations, each defined by latitude and longitude. You want to quickly find all stores within a 5 km radius of a customer&#8217;s location. With standard B-tree indexes, you&#8217;d create:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;sql&quot;,&quot;nodeId&quot;:&quot;382d95f3-cea1-4a67-bd32-60f5bd1f8f78&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-sql">CREATE INDEX idx_latitude ON stores(latitude);

CREATE INDEX idx_longitude ON stores(longitude);</code></pre></div><p>Your initial bounding-box query might look like:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;sql&quot;,&quot;nodeId&quot;:&quot;2af1979a-383d-4e06-9e8b-1dfe48e06431&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-sql">SELECT *

FROM stores

WHERE latitude BETWEEN 40.7 AND 40.8

  AND longitude BETWEEN -74.1 AND -73.9;</code></pre></div><p>However, this approach:</p><ul><li><p>Requires two separate scans (latitude and longitude).</p></li><li><p>Forces an expensive intersection operation in your application code.</p></li><li><p>Requires further filtering to verify distances precisely.</p></li><li><p>Quickly degrades performance as the dataset grows because B-trees can&#8217;t inherently manage multi-dimensional searches efficiently.</p></li></ul><h3>Why Geospatial Indexes Exist</h3><p>Imagine typing &#8220;Bus stops near me&#8221; into Google and instantly getting the five closest stops around you with no lag or missed results. That&#8217;s geospatial indexing at work. Geospatial indexing is a method for efficiently querying location-based data by latitude and longitude (2D) and sometimes by altitude (3D). Many popular applications today use geospatial indexing to deliver quick, efficient results to their users, leveraging latitude and longitude pairs.</p><p>Unlike traditional indexes such as B-trees, geospatial indexes are designed to handle multidimensional spatial data. A spatial index typically organizes data in a hierarchical structure composed of:</p><blockquote><p> <strong>Leaf Nodes: </strong>The leaf nodes contain bounding rectangles and references to the stored geometries.</p></blockquote><p></p><blockquote><p> <strong>Interior Nodes:</strong> The interior nodes store larger bounding regions that encompass their child nodes.</p></blockquote><p>During a query, the database traverses only the branches whose bounding regions intersect the search area. This allows the system to quickly eliminate large portions of irrelevant data. The most widely used structure for achieving this is the R-Tree.</p><h3>R-Trees</h3><p>An R-Tree is a tree-based data structure used to efficiently store and retrieve spatial (location-based) data. It follows the same idea as a B-Tree, but instead of indexing scalar values, it indexes spatial objects such as points, lines, and polygons.</p><p>The key idea behind an R-Tree is the use of Minimum Bounding Rectangles (MBRs).</p><p> An MBR is the smallest rectangle that fully contains a spatial object. These rectangles allow the index to group nearby spatial objects together, making spatial queries much faster. Most spatial databases, such as PostGIS, implement R-Tree behavior through GiST indexes, which generalize the R-Tree structure for multiple data types. In PostgreSQL, creating one is as simple as: </p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;sql&quot;,&quot;nodeId&quot;:&quot;da4acc8f-5b33-4c38-84a5-d1a946653b51&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-sql">CREATE INDEX ... USING GIST (location)</code></pre></div><p>and PostGIS handles the rest.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Zq5f!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c223f80-82d9-442c-b67c-dad7c6e869cc_1542x1186.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Zq5f!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c223f80-82d9-442c-b67c-dad7c6e869cc_1542x1186.png 424w, https://substackcdn.com/image/fetch/$s_!Zq5f!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c223f80-82d9-442c-b67c-dad7c6e869cc_1542x1186.png 848w, https://substackcdn.com/image/fetch/$s_!Zq5f!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c223f80-82d9-442c-b67c-dad7c6e869cc_1542x1186.png 1272w, https://substackcdn.com/image/fetch/$s_!Zq5f!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c223f80-82d9-442c-b67c-dad7c6e869cc_1542x1186.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Zq5f!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c223f80-82d9-442c-b67c-dad7c6e869cc_1542x1186.png" width="1456" height="1120" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3c223f80-82d9-442c-b67c-dad7c6e869cc_1542x1186.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1120,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Zq5f!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c223f80-82d9-442c-b67c-dad7c6e869cc_1542x1186.png 424w, https://substackcdn.com/image/fetch/$s_!Zq5f!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c223f80-82d9-442c-b67c-dad7c6e869cc_1542x1186.png 848w, https://substackcdn.com/image/fetch/$s_!Zq5f!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c223f80-82d9-442c-b67c-dad7c6e869cc_1542x1186.png 1272w, https://substackcdn.com/image/fetch/$s_!Zq5f!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c223f80-82d9-442c-b67c-dad7c6e869cc_1542x1186.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="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>Inserting Data</h3><p>When geographical data is inserted into a database, the spatial object is stored in the table, and the spatial index then computes the object&#8217;s Minimum Bounding Rectangle based on its coordinates (latitude, longitude) or (latitude, longitude, and altitude). This rectangle is inserted into the R-Tree structure.</p><p>Each node in the tree stores bounding rectangles that cover all spatial objects contained within that node. As more data is inserted, nearby objects tend to be grouped under the same nodes. If a node exceeds its capacity, it is split into multiple nodes, and the tree structure adjusts accordingly. The node capacity for an R-Tree, like a B-Tree, depends on the page size (generally 8 kilobytes).</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!dqLa!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcdcaecea-dbb2-4418-bdef-ec3326b177f8_1600x1003.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!dqLa!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcdcaecea-dbb2-4418-bdef-ec3326b177f8_1600x1003.png 424w, https://substackcdn.com/image/fetch/$s_!dqLa!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcdcaecea-dbb2-4418-bdef-ec3326b177f8_1600x1003.png 848w, https://substackcdn.com/image/fetch/$s_!dqLa!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcdcaecea-dbb2-4418-bdef-ec3326b177f8_1600x1003.png 1272w, https://substackcdn.com/image/fetch/$s_!dqLa!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcdcaecea-dbb2-4418-bdef-ec3326b177f8_1600x1003.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!dqLa!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcdcaecea-dbb2-4418-bdef-ec3326b177f8_1600x1003.png" width="1456" height="913" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cdcaecea-dbb2-4418-bdef-ec3326b177f8_1600x1003.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:913,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!dqLa!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcdcaecea-dbb2-4418-bdef-ec3326b177f8_1600x1003.png 424w, https://substackcdn.com/image/fetch/$s_!dqLa!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcdcaecea-dbb2-4418-bdef-ec3326b177f8_1600x1003.png 848w, https://substackcdn.com/image/fetch/$s_!dqLa!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcdcaecea-dbb2-4418-bdef-ec3326b177f8_1600x1003.png 1272w, https://substackcdn.com/image/fetch/$s_!dqLa!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcdcaecea-dbb2-4418-bdef-ec3326b177f8_1600x1003.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="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>Querying Data</h3><p>During queries, the R-Tree quickly eliminates regions that cannot contain relevant results by checking whether their bounding rectangles intersect the search area. Only candidate geometries that pass this initial filter are then evaluated with precise spatial operations.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!yCES!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3fe3bae5-80ad-4caa-babe-92bb58168b55_1600x1170.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!yCES!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3fe3bae5-80ad-4caa-babe-92bb58168b55_1600x1170.png 424w, https://substackcdn.com/image/fetch/$s_!yCES!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3fe3bae5-80ad-4caa-babe-92bb58168b55_1600x1170.png 848w, https://substackcdn.com/image/fetch/$s_!yCES!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3fe3bae5-80ad-4caa-babe-92bb58168b55_1600x1170.png 1272w, https://substackcdn.com/image/fetch/$s_!yCES!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3fe3bae5-80ad-4caa-babe-92bb58168b55_1600x1170.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!yCES!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3fe3bae5-80ad-4caa-babe-92bb58168b55_1600x1170.png" width="1456" height="1065" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3fe3bae5-80ad-4caa-babe-92bb58168b55_1600x1170.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1065,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!yCES!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3fe3bae5-80ad-4caa-babe-92bb58168b55_1600x1170.png 424w, https://substackcdn.com/image/fetch/$s_!yCES!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3fe3bae5-80ad-4caa-babe-92bb58168b55_1600x1170.png 848w, https://substackcdn.com/image/fetch/$s_!yCES!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3fe3bae5-80ad-4caa-babe-92bb58168b55_1600x1170.png 1272w, https://substackcdn.com/image/fetch/$s_!yCES!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3fe3bae5-80ad-4caa-babe-92bb58168b55_1600x1170.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" 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 simple latitude/longitude <strong>WHERE</strong> clause feels like it should be enough until your dataset grows, and queries that took milliseconds start taking seconds. The problem isn&#8217;t the query, it&#8217;s the index behind it.</p><p>Geospatial indexing solves this by organizing spatial data into structures like R-trees, which group nearby objects using Minimum Bounding Rectangles and traverse only the relevant parts of the dataset, skipping entire geographic regions that can&#8217;t match and running precise calculations only on a small set of candidates.</p><p>Tools like PostGIS bring these capabilities directly to PostgreSQL, enabling developers to build fast, location-aware systems, from mapping services and logistics platforms to ride-sharing and food delivery apps.</p><p></p><h3>About The Author</h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!WBEg!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf919f3c-b2c6-4798-a3c6-56bc3fe9c034_1280x1173.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!WBEg!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf919f3c-b2c6-4798-a3c6-56bc3fe9c034_1280x1173.jpeg 424w, https://substackcdn.com/image/fetch/$s_!WBEg!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf919f3c-b2c6-4798-a3c6-56bc3fe9c034_1280x1173.jpeg 848w, https://substackcdn.com/image/fetch/$s_!WBEg!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf919f3c-b2c6-4798-a3c6-56bc3fe9c034_1280x1173.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!WBEg!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf919f3c-b2c6-4798-a3c6-56bc3fe9c034_1280x1173.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!WBEg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf919f3c-b2c6-4798-a3c6-56bc3fe9c034_1280x1173.jpeg" width="1280" height="1173" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/af919f3c-b2c6-4798-a3c6-56bc3fe9c034_1280x1173.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1173,&quot;width&quot;:1280,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:110140,&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://algorythmorg.substack.com/i/190099454?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf919f3c-b2c6-4798-a3c6-56bc3fe9c034_1280x1173.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_!WBEg!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf919f3c-b2c6-4798-a3c6-56bc3fe9c034_1280x1173.jpeg 424w, https://substackcdn.com/image/fetch/$s_!WBEg!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf919f3c-b2c6-4798-a3c6-56bc3fe9c034_1280x1173.jpeg 848w, https://substackcdn.com/image/fetch/$s_!WBEg!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf919f3c-b2c6-4798-a3c6-56bc3fe9c034_1280x1173.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!WBEg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf919f3c-b2c6-4798-a3c6-56bc3fe9c034_1280x1173.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><a href="https://www.linkedin.com/in/wilfred-chetat/">Wilfred Chetat</a> is a Senior Backend Engineer at UXE Security Solutions in Dubai, where he builds and scales high-throughput distributed systems for real-time video analytics. With over 6 years of Python development experience, he works across the full backend stack, from API design and message queues to databases and container orchestration.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://wilfredchetat485157.substack.com/subscribe&quot;,&quot;text&quot;:&quot;Subscribe to Wilfred&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://wilfredchetat485157.substack.com/subscribe"><span>Subscribe to Wilfred</span></a></p><p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://news.algorythm.org/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Algorythm! Subscribe for free to receive more technical insights from the community and support our work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Using LLMs to Build A Recommendation Engine]]></title><description><![CDATA[GraphRAG for constraint-aware, explainable recommendations]]></description><link>https://news.algorythm.org/p/using-llms-to-build-a-recommendation</link><guid isPermaLink="false">https://news.algorythm.org/p/using-llms-to-build-a-recommendation</guid><dc:creator><![CDATA[Bryan Ofuokwu]]></dc:creator><pubDate>Wed, 25 Feb 2026 16:16:34 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!WF9j!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34e573c4-7e6f-4c00-953f-06da63a9ad74_1536x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>This publication is by members of the <strong><a href="https://algorythm.org/">Algorythm</a></strong> Community. A network of 20k+ black software engineers sharing technical insights across all fields of software development. Join us on <a href="https://www.linkedin.com/groups/8873861/">LinkedIn</a>, <a href="https://www.facebook.com/groups/algorythm">Facebook</a> and <a href="https://algorythmorg.substack.com/subscribe">Subscribe</a> for more insights.</em></p><div><hr></div><p>Recommendation engines are incredibly powerful tools that drive the core experiences of social networks, e-commerce, and media platforms. Today, we can create complex recommendation systems much more easily using modern technology, without needing to be machine learning experts.</p><p>At a high level, traditional Retrieval-Augmented Generation (RAG) retrieves information based on text similarity, but it struggles with complex, multi-layered constraints. GraphRAG solves this by retrieving structured networks of relationships, giving the LLM precise, deterministic facts to reason over.</p><p>To illustrate this, let&#8217;s look at real estate as a prime example where recommendations are notoriously challenging and a graph model helps immensely. I&#8217;ve had this crazy idea: what if we could utilize <strong>GraphRAG</strong> and <strong>relationships</strong> for better recommendations&#8230;.</p><p>Not just &#8220;homes similar to what you clicked,&#8221; but recommendations that actually understand the <em>web of constraints</em> behind real decisions:</p><ul><li><p>&#8220;Like this neighborhood, but quieter.&#8221;</p></li><li><p>&#8220;Within 25 minutes of work <em>and</em> close to my partner&#8217;s job.&#8221;</p></li><li><p>&#8220;Rental-friendly HOA only.&#8221;</p></li><li><p>&#8220;Good schools, but still walkable to coffee + gym.&#8221;</p></li><li><p>&#8220;Don&#8217;t show me places with sketchy parking or bad street noise.&#8221;</p></li></ul><p>This moves beyond simple similarity, combining relational structure, strict constraints, and transparent explanations. And that&#8217;s exactly where GraphRAG starts to look&#8230; weirdly reasonable.</p><p>This post is a deep dive into:</p><ul><li><p>What GraphRAG means for recommendation engines,</p></li><li><p><strong>Why it&#8217;s powerful for recommendations involving complex relationships,</strong></p></li><li><p>What a sane architecture looks like, and</p></li><li><p>When this is a <strong>terrible</strong> idea and you should not build it.</p></li></ul><h3>The problem with traditional recommendation systems?</h3><p>Most recommendation systems work well when the goal is straightforward:</p><ul><li><p>&#8220;People who viewed X also viewed Y&#8221; (collaborative filtering)</p></li><li><p>&#8220;This listing is similar to your tastes&#8221; (content-based / embeddings)</p></li><li><p>&#8220;Rank what you&#8217;re most likely to click&#8221; (learning-to-rank)</p></li></ul><p><strong>But recommendations get messy when you have to weigh dozens of subjective, competing factors. For example in real estate,</strong> a user isn&#8217;t just selecting a product. They&#8217;re making a life impacting decision:</p><ul><li><p>commute time</p></li><li><p>school district</p></li><li><p>safety + noise</p></li><li><p>lifestyle (walkability, parks, gym, groceries)</p></li><li><p>deal-breakers (HOA rules, pets, rental bans)</p></li><li><p>social constraints (close to family, near friends)</p></li><li><p>financial constraints (budget, taxes, insurance)</p></li><li><p>investment constraints (cap rate, STR legality)</p></li></ul><p>If your system only knows &#8220;similar listing text,&#8221; it will repeatedly violate user intent in subtle ways. And subtle violations kill trust fast.</p><h3>So what is GraphRAG in recommendation terms?</h3><p><strong>GraphRAG</strong> = <strong>Graph retrieval</strong> + <strong>LLM reasoning</strong></p><p>Instead of retrieving &#8220;similar items,&#8221; we retrieve a <strong>relevant subgraph</strong> of facts and relationships that explain <em>why</em> something is a good match.</p><p>A simple mental model:</p><ul><li><p><strong>Traditional retrieval:</strong> &#8220;Give me listings similar to what this user liked.&#8221;</p></li><li><p><strong>GraphRAG retrieval:</strong> &#8220;Give me listings similar to what this user liked, <em>and also pull the network of constraints and relationships that make those listings relevant.</em>&#8221;</p></li></ul><p>Then the LLM uses that retrieved context to:</p><ul><li><p>apply nuanced preferences (&#8220;quiet street is more important than granite countertops&#8221;),</p></li><li><p>reason over multi-hop relationships (&#8220;this neighborhood is similar to yours because&#8230;&#8221;),</p></li><li><p>generate explanations grounded in facts,</p></li><li><p>ask clarifying questions when constraints conflict.</p></li></ul><p>GraphRAG is not &#8220;LLM decides everything.&#8221; It&#8217;s &#8220;retrieve structured context <strong>deterministically</strong>, then let the LLM reason on top.&#8221;</p><h3>Why real estate here (and where else it applies)?</h3><p>GraphRAG shines when recommendations require <strong>multi-hop reasoning</strong> and <strong>constraint satisfaction</strong>. Real estate is full of that, but <strong>this approach easily applies to other datasets that can be modeled as a graph</strong>, such as:</p><ul><li><p><strong>Expert matching:</strong> weighing required skills, company culture, salary expectations, and remote flexibility.</p></li><li><p><strong>Travel itineraries:</strong> balancing travel dates, group size, interests, and proximity to lodging/transit.</p></li></ul><p><strong>Example of a recommendation that is NOT just similarity:</strong> User says: <em>&#8220;Show me 3-bed homes similar to what I saved, but I need rental-friendly HOA rules, and my commute must be under 30 minutes.&#8221;</em></p><p>A pure embedding search might nail &#8220;similar style&#8221; but miss HOA rental restrictions, commute constraints, and neighborhood nuances. A graph, though? This is literally graph-shaped.</p><h3>What does the graph look like?</h3><p>Let&#8217;s model a real estate recommendation graph with a few core node types:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!WF9j!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34e573c4-7e6f-4c00-953f-06da63a9ad74_1536x1024.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!WF9j!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34e573c4-7e6f-4c00-953f-06da63a9ad74_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!WF9j!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34e573c4-7e6f-4c00-953f-06da63a9ad74_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!WF9j!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34e573c4-7e6f-4c00-953f-06da63a9ad74_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!WF9j!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34e573c4-7e6f-4c00-953f-06da63a9ad74_1536x1024.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!WF9j!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34e573c4-7e6f-4c00-953f-06da63a9ad74_1536x1024.png" width="1456" height="971" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/34e573c4-7e6f-4c00-953f-06da63a9ad74_1536x1024.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:971,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:740375,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://algorythmorg.substack.com/i/189141651?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34e573c4-7e6f-4c00-953f-06da63a9ad74_1536x1024.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!WF9j!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34e573c4-7e6f-4c00-953f-06da63a9ad74_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!WF9j!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34e573c4-7e6f-4c00-953f-06da63a9ad74_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!WF9j!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34e573c4-7e6f-4c00-953f-06da63a9ad74_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!WF9j!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34e573c4-7e6f-4c00-953f-06da63a9ad74_1536x1024.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>This graph encodes the real question: <em>&#8220;What is this user actually optimizing for, and what rules must never be violated?&#8221;</em></p><h3>What does the workflow look like?</h3><p>If you&#8217;re building this seriously, you typically do it in <strong>two stages</strong>. To set up your architecture, you need to rely on specific technology choices, balancing trade-offs between speed, cost, and reasoning power.</p><h4><strong>Architecture &amp; Technology Stack</strong> </h4><p>To build a solid GraphRAG framework, you need to select tools for both generation and reasoning:</p><p><em><strong>Embedding Model</strong></em></p><p>Use a smaller, fine-tuned embedding model (e.g. text-embedding-3-small). </p><p>These models are fast, scalable, and highly cost-effective for generating candidate vectors during the initial retrieval phase.</p><p><em><strong>Vector Database</strong></em></p><p>Store and query these embeddings in a robust vector database (e.g. Pinecone). </p><p>You need ultra-low latency vector retrieval to execute the first pass of similarity matching efficiently.</p><p><em><strong>Graph Database &amp; Framework</strong></em></p><p>Utilize a graph database (like Neo4j) paired with a framework (like LlamaIndex or Microsoft&#8217;s GraphRAG). </p><p>This is essential for efficiently mapping and querying the multi-hop relationships required to pull bounded subgraphs without dumping the entire graph into a prompt.</p><p><em><strong>Reasoning LLM</strong></em></p><p>For the final retrieval and ranking, deploy a powerful LLM  (like GPT-5 or Claude 4.5 Sonnet).</p><p>The second stage requires heavy cognitive lifting to evaluate complex constraints, detect conflicts, and generate grounded explanations. While these models have higher latency and cost tradeoffs, their reasoning capabilities are mandatory for accurate GraphRAG. You can configure the reasoning effort / thinking budget to achieve desired latency.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!X9dE!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93c6911c-cb82-4159-b1dd-717142324a47_1536x1024.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!X9dE!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93c6911c-cb82-4159-b1dd-717142324a47_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!X9dE!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93c6911c-cb82-4159-b1dd-717142324a47_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!X9dE!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93c6911c-cb82-4159-b1dd-717142324a47_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!X9dE!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93c6911c-cb82-4159-b1dd-717142324a47_1536x1024.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!X9dE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93c6911c-cb82-4159-b1dd-717142324a47_1536x1024.png" width="1456" height="971" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/93c6911c-cb82-4159-b1dd-717142324a47_1536x1024.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:971,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:924689,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://algorythmorg.substack.com/i/189141651?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93c6911c-cb82-4159-b1dd-717142324a47_1536x1024.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!X9dE!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93c6911c-cb82-4159-b1dd-717142324a47_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!X9dE!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93c6911c-cb82-4159-b1dd-717142324a47_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!X9dE!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93c6911c-cb82-4159-b1dd-717142324a47_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!X9dE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93c6911c-cb82-4159-b1dd-717142324a47_1536x1024.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h4><strong>Stage 1: Candidate generation (fast + scalable)</strong> </h4><p>Use a hybrid approach to rapidly narrow down the universe of options:</p><ul><li><p><strong>Hard filters:</strong> price, beds/baths, location bounds.</p></li><li><p><strong>Vector retrieval:</strong> utilizing your fine-tuned embedding model and vector DB for listing &#8220;vibe/style similarity&#8221;.</p></li><li><p><strong>Graph expansion:</strong> neighborhoods the user tends to like, HOA constraints, POIs, commute feasibility.</p></li></ul><p>This stage returns maybe <strong>200&#8211;500 candidates</strong>.</p><h4><strong>Stage 2: GraphRAG reasoning + rerank (smart + explainable)</strong> </h4><p>For each candidate (or the top 50), retrieve a <strong>bounded subgraph</strong>: neighborhood stats, HOA rules, commute time estimate, nearby POIs, similarity link to prior saved listings/neighborhoods.</p><p>Now your powerful LLM can do something useful:</p><ul><li><p><strong>rerank based on soft preferences</strong></p></li><li><p><strong>produce explanations</strong></p></li><li><p><strong>detect conflicts</strong> (e.g., &#8220;you want STR but this HOA bans STR&#8221;)</p></li><li><p><strong>ask clarifying questions</strong> when needed</p></li></ul><p>You end with top <strong>10&#8211;20 recommendations</strong> that are constraint-compliant, explainable, and personalized beyond text similarity.</p><h3>What &#8220;bounded subgraph retrieval&#8221; looks like?</h3><p>This is the part people mess up. You do <strong>not</strong> dump your whole graph into the prompt. You retrieve a compact &#8220;fact pack,&#8221; like:</p><p><strong>Listing A</strong></p><ul><li><p>$820k, 3bd/2ba, 1,750 sqft</p></li><li><p>Neighborhood: Greenlake</p></li><li><p>Commute: 28 minutes (typical traffic)</p></li><li><p>HOA: rentals allowed, STR not allowed</p></li><li><p>Nearby: gym (0.4 mi), grocery (0.3 mi), park (0.2 mi)</p></li><li><p>Similar to: 3 saved listings in Ravenna (neighborhood similarity edge)</p></li></ul><p>That&#8217;s the &#8220;RAG context,&#8221; except it&#8217;s <strong>graph-derived</strong>. Now the LLM isn&#8217;t guessing; it&#8217;s reasoning over facts.</p><h3>Why GraphRAG can produce better recommendations?</h3><p>GraphRAG improves recommendations in a few specific ways:</p><ol><li><p><strong>It handles multi-hop constraints:</strong> &#8220;Close to my sister&#8221; &#8594; sister&#8217;s location &#8594; commute edges &#8594; neighborhood candidates.</p></li><li><p><strong>It makes preferences explicit:</strong> If a user repeatedly saves homes in quiet neighborhoods, that preference becomes a graph signal &#8212; not a vague embedding.</p></li><li><p><strong>It supports cold-start:</strong> New listing? New user? Graph connections still provide signal: neighborhood, HOA, POIs, school district, comps.</p></li><li><p><strong>It enables real explanations:</strong> You can finally answer <em>&#8220;Why did you recommend this?&#8221;</em> &#8230;and not with fluffy nonsense.</p></li></ol><h3>When is GraphRAG a terrible idea?</h3><p>GraphRAG is <strong>not</strong> the default architecture for recommendations. Avoid it when:</p><ol><li><p><strong>Similarity already solves your problem:</strong> If embeddings + LTR gets you 90% of the value, GraphRAG might be expensive &#8220;coolness&#8221;.</p></li><li><p><strong>Your graph relationships are weak or noisy:</strong> If your edges are mostly heuristics and guesses, you&#8217;ll add complexity without real lift.</p></li><li><p><strong>You need ultra-low latency at massive scale:</strong> Graph queries + LLM inference = not cheap, not fast.</p></li><li><p><strong>Your entity resolution is messy:</strong> Graphs break when the same HOA appears under multiple names, addresses aren&#8217;t normalized, or entities aren&#8217;t deduped cleanly.</p></li><li><p><strong>You can&#8217;t measure lift:</strong> GraphRAG feels smart, but you still need constraint satisfaction rates, save rates, lead conversion, and &#8220;good match&#8221; feedback. If you can&#8217;t evaluate, then what are we doing?</p></li></ol><h3>A realistic MVP</h3><p><strong>MVP graph scope</strong> - Keep it tight: User &#8596; Listing &#8596; Neighborhood &#8596; HOA &#8596; POI</p><p><strong>MVP capabilities</strong>: hard filters | embedding similarity | HOA rule filtering | neighborhood context + explanation | commute estimation</p><p><strong>Use GraphRAG only where it matters</strong>: Don&#8217;t run GraphRAG on infinite scroll. Run it on <strong>high-intent flows</strong> like search results refinement, &#8220;recommended for you&#8221; after saves, or investment mode toggles.</p><p>GraphRAG for recommendation engines sounds crazy until you realize that some recommendation problems aren&#8217;t primarily similarity problems. They&#8217;re <strong>relationship + constraint + trust</strong> problems.</p><p>So if your users care about constraints that must never be violated, multi-hop relationships, grounded explanations, and personalization beyond text similarity&#8230; GraphRAG is a serious tool &#8212; <em>when used with discipline</em>. Ultimately, this approach extends far beyond real estate; it is a vital framework for unlocking value in any dataset with complex relationships that can be modeled as a graph.</p><h3>About The Author</h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!VUqY!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62a33d27-3c4d-44db-abde-4a115b7941b3_800x800.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!VUqY!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62a33d27-3c4d-44db-abde-4a115b7941b3_800x800.jpeg 424w, https://substackcdn.com/image/fetch/$s_!VUqY!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62a33d27-3c4d-44db-abde-4a115b7941b3_800x800.jpeg 848w, https://substackcdn.com/image/fetch/$s_!VUqY!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62a33d27-3c4d-44db-abde-4a115b7941b3_800x800.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!VUqY!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62a33d27-3c4d-44db-abde-4a115b7941b3_800x800.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!VUqY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62a33d27-3c4d-44db-abde-4a115b7941b3_800x800.jpeg" width="564" height="564" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/62a33d27-3c4d-44db-abde-4a115b7941b3_800x800.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:800,&quot;width&quot;:800,&quot;resizeWidth&quot;:564,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Profile image&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Profile image" title="Profile image" srcset="https://substackcdn.com/image/fetch/$s_!VUqY!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62a33d27-3c4d-44db-abde-4a115b7941b3_800x800.jpeg 424w, https://substackcdn.com/image/fetch/$s_!VUqY!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62a33d27-3c4d-44db-abde-4a115b7941b3_800x800.jpeg 848w, https://substackcdn.com/image/fetch/$s_!VUqY!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62a33d27-3c4d-44db-abde-4a115b7941b3_800x800.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!VUqY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62a33d27-3c4d-44db-abde-4a115b7941b3_800x800.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><a href="https://www.linkedin.com/in/bryan-ofuokwu/">Bryan Ofuokwu</a> is an Applied AI Engineer at Salesforce building production AI systems at scale. He explores LLMs, RAG, ML pipelines, and the intersection of software engineering and machine learning.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://bryan248569.substack.com/subscribe&quot;,&quot;text&quot;:&quot;Subscribe to Bryan&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://bryan248569.substack.com/subscribe"><span>Subscribe to Bryan</span></a></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://news.algorythm.org/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Algorythm! Subscribe for free to receive more technical insights from the community and support our work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Quantum Computing for Fun and Profit]]></title><description><![CDATA[How can I maximize my payout when playing Plinko?]]></description><link>https://news.algorythm.org/p/quantum-mechanics-for-fun-and-profit</link><guid isPermaLink="false">https://news.algorythm.org/p/quantum-mechanics-for-fun-and-profit</guid><dc:creator><![CDATA[Krystal Maughan]]></dc:creator><pubDate>Fri, 20 Feb 2026 16:11:58 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!rmwi!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d3c8616-5cae-4750-b7d7-20c846a8e359_994x636.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>This publication is by members of the <strong><a href="https://algorythm.org/">Algorythm</a></strong> Community. A network of 20k+ black software engineers sharing technical insights across all fields of software development. Join us on <a href="https://www.linkedin.com/groups/8873861/">LinkedIn</a>, <a href="https://www.facebook.com/groups/algorythm">Facebook</a> and <a href="https://algorythmorg.substack.com/subscribe">Subscribe</a> for more insights.</em></p><div><hr></div><p>My current interests are many things involving quantum information, as I work on quantum-safe cryptography. For this article, I&#8217;d like to present a classical problem that was asked by a trader when I participated in a PhD symposium hosted by a prop trading firm on Wall Street many years ago. It stuck with me because of the <em>elegance of its solution</em>.</p><p>Today, finance departments in quantitative research are still <a href="https://arxiv.org/pdf/2009.06601">fascinated by derivations of this problem</a>. </p><p>Last summer (2025), I worked with two researchers, <em>Otene Sunday ThankGod and Jibril Abdullahi</em>, on an efficient quantum implementation as a <em>Womanium &amp; Wiser Quantum Program Scholar</em>. The Goal: &#8220;How can I maximize my payout when playing Plinko?&#8221;</p><h3><strong>Plinko is essentially the Galton-Box Problem</strong></h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!rmwi!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d3c8616-5cae-4750-b7d7-20c846a8e359_994x636.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!rmwi!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d3c8616-5cae-4750-b7d7-20c846a8e359_994x636.jpeg 424w, https://substackcdn.com/image/fetch/$s_!rmwi!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d3c8616-5cae-4750-b7d7-20c846a8e359_994x636.jpeg 848w, https://substackcdn.com/image/fetch/$s_!rmwi!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d3c8616-5cae-4750-b7d7-20c846a8e359_994x636.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!rmwi!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d3c8616-5cae-4750-b7d7-20c846a8e359_994x636.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!rmwi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d3c8616-5cae-4750-b7d7-20c846a8e359_994x636.jpeg" width="994" height="636" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9d3c8616-5cae-4750-b7d7-20c846a8e359_994x636.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:636,&quot;width&quot;:994,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:312715,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/jpeg&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://algorythmorg.substack.com/i/188608484?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d3c8616-5cae-4750-b7d7-20c846a8e359_994x636.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_!rmwi!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d3c8616-5cae-4750-b7d7-20c846a8e359_994x636.jpeg 424w, https://substackcdn.com/image/fetch/$s_!rmwi!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d3c8616-5cae-4750-b7d7-20c846a8e359_994x636.jpeg 848w, https://substackcdn.com/image/fetch/$s_!rmwi!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d3c8616-5cae-4750-b7d7-20c846a8e359_994x636.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!rmwi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d3c8616-5cae-4750-b7d7-20c846a8e359_994x636.jpeg 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><em>&#8220;Plinko: The Price is Right Wiki&#8221;,</em> https://priceisright.fandom.com/wiki/Plinko</figcaption></figure></div><p>It&#8217;s time to play &#8220;The Price is Right!&#8221; But what does this have to do with Quantum Computing? </p><p>Let&#8217;s say you were chosen as a contestant on &#8220;The Price is Right&#8221; and have a chance to win a big payout by playing the game &#8220;Plinko&#8221;. Plinko is a game in which a contestant stands at the top of the stairs looking down at a board with varying levels of cash prizes. </p><p>The goal as a contestant is to drop the ball from a starting position to maximize your payout (we want to end up in the slot with the <em>most cash value</em>).</p><h3><strong>Modelling a Game with Maths</strong></h3><p>Statisticians have been fascinated with this problem because we can model the problem as a statistical likelihood problem with some degree of uncertainty. Additionally, it&#8217;s a great example to visualize the <a href="https://en.wikipedia.org/wiki/Central_limit_theorem">Central Limit Theorem</a> as we find our solution converges to <a href="https://en.wikipedia.org/wiki/Binomial_distribution">Binomial Distribution</a>. Solutions that demonstrate this often contain some sort of <a href="https://en.wikipedia.org/wiki/Monte_Carlo_method">Monte Carlo simulation</a>.</p><p>Many papers and blog posts have been written about the Galton-Box or Galton Board problem, where our <strong>Galton-Box is our Plinko board</strong> and we have a series of pegs laid out with a depth for our box,<em> n</em>. For this post, we can ignore the term and its definition, so every time &#8220;Galton-Box&#8221; is mentioned, replace it with &#8220;Plinko board&#8221;. <a href="https://en.wikipedia.org/wiki/Francis_Galton">Galton</a> himself is a problematic contributor to the field of statistics, but I digress, because our focus is <em>Winner winner chicken dinner!</em></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!n-9q!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F40db6524-2135-47b9-a121-e1f2d62f5cf0_1356x1044.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!n-9q!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F40db6524-2135-47b9-a121-e1f2d62f5cf0_1356x1044.png 424w, https://substackcdn.com/image/fetch/$s_!n-9q!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F40db6524-2135-47b9-a121-e1f2d62f5cf0_1356x1044.png 848w, https://substackcdn.com/image/fetch/$s_!n-9q!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F40db6524-2135-47b9-a121-e1f2d62f5cf0_1356x1044.png 1272w, https://substackcdn.com/image/fetch/$s_!n-9q!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F40db6524-2135-47b9-a121-e1f2d62f5cf0_1356x1044.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!n-9q!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F40db6524-2135-47b9-a121-e1f2d62f5cf0_1356x1044.png" width="1356" height="1044" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/40db6524-2135-47b9-a121-e1f2d62f5cf0_1356x1044.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1044,&quot;width&quot;:1356,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!n-9q!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F40db6524-2135-47b9-a121-e1f2d62f5cf0_1356x1044.png 424w, https://substackcdn.com/image/fetch/$s_!n-9q!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F40db6524-2135-47b9-a121-e1f2d62f5cf0_1356x1044.png 848w, https://substackcdn.com/image/fetch/$s_!n-9q!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F40db6524-2135-47b9-a121-e1f2d62f5cf0_1356x1044.png 1272w, https://substackcdn.com/image/fetch/$s_!n-9q!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F40db6524-2135-47b9-a121-e1f2d62f5cf0_1356x1044.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="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">&#8220;Glow: The Event Store&#8221; https://glowparties.ca/product/plinko/</figcaption></figure></div><p>So what are the odds that if I stand at the extreme left side of the board, my ball will land at the top cash prize by the time it makes its way to the bottom of the board? We can imagine ourselves standing at the top of the stairs, dropping the ball and calculating for each peg on the board what the probability of the ball going down a certain path might be. As we try each starting position, we note which are more successful than others, but doing this over and over for each iteration is tiring!</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!YIBb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17199317-f7ee-4079-ba53-e6a85624bf30_1170x398.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!YIBb!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17199317-f7ee-4079-ba53-e6a85624bf30_1170x398.png 424w, https://substackcdn.com/image/fetch/$s_!YIBb!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17199317-f7ee-4079-ba53-e6a85624bf30_1170x398.png 848w, https://substackcdn.com/image/fetch/$s_!YIBb!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17199317-f7ee-4079-ba53-e6a85624bf30_1170x398.png 1272w, https://substackcdn.com/image/fetch/$s_!YIBb!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17199317-f7ee-4079-ba53-e6a85624bf30_1170x398.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!YIBb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17199317-f7ee-4079-ba53-e6a85624bf30_1170x398.png" width="1170" height="398" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/17199317-f7ee-4079-ba53-e6a85624bf30_1170x398.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:398,&quot;width&quot;:1170,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!YIBb!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17199317-f7ee-4079-ba53-e6a85624bf30_1170x398.png 424w, https://substackcdn.com/image/fetch/$s_!YIBb!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17199317-f7ee-4079-ba53-e6a85624bf30_1170x398.png 848w, https://substackcdn.com/image/fetch/$s_!YIBb!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17199317-f7ee-4079-ba53-e6a85624bf30_1170x398.png 1272w, https://substackcdn.com/image/fetch/$s_!YIBb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17199317-f7ee-4079-ba53-e6a85624bf30_1170x398.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3><strong>Marked Trees and Random Walks</strong></h3><p>If you noticed that each path resembles a tree, you would be right, as our path is essentially a discrete random walk with a number of steps over a time <strong>t</strong>, where with some probability the ball drops left or right as it hits a peg. </p><p>In traditional computing, when we want to solve a problem that may have many solutions, we might use backtracking to traverse every possible solution. Think about using a classical computer to solve Sudoku or the <a href="https://en.wikipedia.org/wiki/Eight_queens_puzzle">N-Queens Problem</a>.</p><h4>How would we solve this Quantumly?</h4><p>In Quantum Computing, we can use <a href="https://en.wikipedia.org/wiki/Quantum_walk">Quantum Walks</a>, a type of Quantum Algorithm (that is the quantum version of a <a href="https://en.wikipedia.org/wiki/Random_walk">classical random walk</a>) to find paths that are &#8220;marked&#8221;, meaning that they will lead to some solution (this solution may be wrong or correct, but this is distinct from a partial solution where we are not certain whether one exists after running the algorithm). </p><p>We can then use a subroutine of this algorithm, called a <a href="https://en.wikipedia.org/wiki/Quantum_Fourier_transform">Quantum Fourier Transform</a> (QFT), to make our solution &#8220;faster&#8221; by using some sort of <a href="https://en.wikipedia.org/wiki/Hamiltonian_(quantum_mechanics)#Schr%C3%B6dinger_equation">evolution operator</a>. QFTs are the cornerstone of many of our current Quantum algorithms such as <a href="https://en.wikipedia.org/wiki/Shor's_algorithm">Shor&#8217;s Algorithm</a>, which was developed in 1994 to find prime factors of an integer.</p><h4>What do you Mean by Faster?</h4><p>Since QFTs use <a href="https://en.wikipedia.org/wiki/Quantum_superposition">superposition</a> (meaning that they can traverse a number of possibilities <em>simultaneously</em>), a concept intrinsic to quantum mechanics, they can provide what we call a &#8220;quantum advantage&#8221;; a speedup in the land of quantum solutions <em>relative</em> to a classical solution (where a classical solution means a world where we do not have access to a quantum computer).</p><h3><strong>TLDR</strong></h3><p>As it turns out, Plinko is a real-world abstraction for the (<em>Quantum) Galton-Box problem</em>. With a quantum solution, we would model each peg as a &#8220;quantum peg&#8221;, which is composed of a number of quantum gates which we need to set, swap and reset for each round.</p><p>However, one of the challenges of implementation for finding a solution that may provide a <em>quantum advantage</em> is that our current quantum computers are noisy and therefore error-prone, meaning that finding a solution as we increase the depth of n becomes challenging. </p><p>Perhaps in the future, as quantum computers become fault-tolerant (meaning that they are less error-prone), these problems and their implementations will become more tractable. <a href="https://theskepticalstatistician.blogspot.com/2012/09/games-of-price-is-right-plinko.html">Bonus: Statistically, the middle slot is the best spot to maximize a payout</a>.</p><h3><strong>About The Author</strong></h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!0i6o!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfcc8852-3387-4c00-ad0c-3c9ec3fdfa80_1140x1242.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!0i6o!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfcc8852-3387-4c00-ad0c-3c9ec3fdfa80_1140x1242.jpeg 424w, https://substackcdn.com/image/fetch/$s_!0i6o!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfcc8852-3387-4c00-ad0c-3c9ec3fdfa80_1140x1242.jpeg 848w, https://substackcdn.com/image/fetch/$s_!0i6o!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfcc8852-3387-4c00-ad0c-3c9ec3fdfa80_1140x1242.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!0i6o!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfcc8852-3387-4c00-ad0c-3c9ec3fdfa80_1140x1242.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!0i6o!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfcc8852-3387-4c00-ad0c-3c9ec3fdfa80_1140x1242.jpeg" width="1140" height="1242" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/dfcc8852-3387-4c00-ad0c-3c9ec3fdfa80_1140x1242.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1242,&quot;width&quot;:1140,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:194435,&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://algorythmorg.substack.com/i/188608484?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfcc8852-3387-4c00-ad0c-3c9ec3fdfa80_1140x1242.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_!0i6o!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfcc8852-3387-4c00-ad0c-3c9ec3fdfa80_1140x1242.jpeg 424w, https://substackcdn.com/image/fetch/$s_!0i6o!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfcc8852-3387-4c00-ad0c-3c9ec3fdfa80_1140x1242.jpeg 848w, https://substackcdn.com/image/fetch/$s_!0i6o!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfcc8852-3387-4c00-ad0c-3c9ec3fdfa80_1140x1242.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!0i6o!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdfcc8852-3387-4c00-ad0c-3c9ec3fdfa80_1140x1242.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><figcaption class="image-caption">Krystal in front of a Quantum Computer</figcaption></figure></div><p><strong>Krystal Maughan</strong> is a PhD student currently working on Quantum-Safe Cryptography.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://kammitama.substack.com/subscribe&quot;,&quot;text&quot;:&quot;Subscribe To Krystal&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://kammitama.substack.com/subscribe"><span>Subscribe To Krystal</span></a></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://news.algorythm.org/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Algorythm! Subscribe for free to receive more technical insights and support our work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h3><strong>More reading:</strong></h3><ul><li><p>Binomial Distribution: <a href="https://en.wikipedia.org/wiki/Binomial_distribution">https://en.wikipedia.org/wiki/Binomial_distribution</a></p></li><li><p>The Central Limit Theorem: <a href="https://en.wikipedia.org/wiki/Central_limit_theorem">https://en.wikipedia.org/wiki/Central_limit_theorem</a></p></li><li><p>&#8220;The Skeptical Statistician: Games of the Price is Right: Plinko&#8221;, <a href="https://theskepticalstatistician.blogspot.com/2012/09/games-of-price-is-right-plinko.html">https://theskepticalstatistician.blogspot.com/2012/09/games-of-price-is-right-plinko.html</a></p></li><li><p>Marked Vertices: &#8220;Quadratic speedup for finding marked vertices by quantum walks&#8221;, <a href="https://arxiv.org/pdf/1903.07493">https://arxiv.org/pdf/1903.07493</a></p></li><li><p>Monte Carlo Simulation: <a href="https://en.wikipedia.org/wiki/Monte_Carlo_method">https://en.wikipedia.org/wiki/Monte_Carlo_method</a></p></li><li><p>N-Queens Problem: <a href="https://en.wikipedia.org/wiki/Eight_queens_puzzle">https://en.wikipedia.org/wiki/Eight_queens_puzzle</a></p></li><li><p>Sir Francis Galton: <a href="https://en.wikipedia.org/wiki/Francis_Galton">https://en.wikipedia.org/wiki/Francis_Galton</a></p></li><li><p>Quantum Walks, Notes by Andrew Childs on Quantum Algorithms: &#8203;&#8203;<a href="https://www.cs.umd.edu/~amchilds/qa/qa.pdf">https://www.cs.umd.edu/~amchilds/qa/qa.pdf</a></p></li><li><p>Quantum Galton Box: &#8220;Universal Statistical Simulator&#8221;, &#8220;Universal Statistical Simulator&#8221; Carney M., and Varcoe B., 2022, <a href="https://arxiv.org/abs/2202.01735">https://arxiv.org/abs/2202.01735</a></p></li><li><p>Quantum Fourier Transform, <a href="https://en.wikipedia.org/wiki/Quantum_Fourier_transform">https://en.wikipedia.org/wiki/Quantum_Fourier_transform</a></p></li><li><p>Quantum Walk: <a href="https://en.wikipedia.org/wiki/Quantum_walk">https://en.wikipedia.org/wiki/Quantum_walk</a></p></li><li><p>Random Walks: <a href="https://en.wikipedia.org/wiki/Random_walk">https://en.wikipedia.org/wiki/Random_walk</a></p></li><li><p>Shor&#8217;s Algorithm: <a href="https://en.wikipedia.org/wiki/Shor's_algorithm">https://en.wikipedia.org/wiki/Shor&#8217;s_algorithm</a></p></li><li><p>Quantum superposition: <a href="https://en.wikipedia.org/wiki/Quantum_superposition">https://en.wikipedia.org/wiki/Quantum_superposition</a></p></li><li><p>Time Evolution Operators: <a href="https://en.wikipedia.org/wiki/Hamiltonian_(quantum_mechanics)#Schr%C3%B6dinger_equation">https://en.wikipedia.org/wiki/Hamiltonian_(quantum_mechanics)#Schr%C3%B6dinger_equation</a></p></li></ul>]]></content:encoded></item><item><title><![CDATA[How ChatGPT Understands What You Mean]]></title><description><![CDATA[Attention: The simple idea that kicked off the LLM era]]></description><link>https://news.algorythm.org/p/the-attention-mechanism</link><guid isPermaLink="false">https://news.algorythm.org/p/the-attention-mechanism</guid><dc:creator><![CDATA[Ayda Sultan]]></dc:creator><pubDate>Wed, 11 Feb 2026 16:02:39 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!hoAh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28c69f03-a6e9-4c5f-b2d8-df60ea8029e5_1244x582.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>This publication is by members of the <strong><a href="https://algorythm.org/">Algorythm</a></strong> Community. A network of 20k+ black software engineers sharing technical insights across all fields of software development. Join us on <a href="https://www.linkedin.com/groups/8873861/">LinkedIn</a>, <a href="https://www.facebook.com/groups/algorythm">Facebook</a> and <a href="https://algorythmorg.substack.com/subscribe">Subscribe</a> for more insights.</em></p><div><hr></div><p>Models like Gemini, ChatGPT, and Claude are all built on the same core idea: The Attention Mechanism. This idea enables models to reason over long chats and understand entire codebases. Without this algorithm, we would have likely never entered the large language model (LLM) era.</p><p>To better understand the algorithm, we first need to investigate what previous problem it was designed to solve. This requires turning a few pages back and revisiting an older generation of models called recurrent neural networks (RNNs).</p><h3>RNNs</h3><p>Recurrent neural networks (which are now archaic on the machine learning timeline) are networks trained on sequential data, like language, where the current element depends on previous elements in the sequence. They allow us to operate over sequences of data. This means that models develop context dynamically as they&#8217;re exposed to more sequence positions. Why does the context matter, you ask? Let&#8217;s look at an example.</p><blockquote><p>I wrote it in python and ran the script</p></blockquote><p>Without additional context, it&#8217;s unclear whether &#8216;python&#8217; refers to the programming language or the snake. The intended meaning can only be understood by looking at surrounding words.</p><p>To explain this more formally (skip this paragraph if you&#8217;re allergic to equations), the context (h) is continuously updated as the model sees more tokens (x). At any timestep (t), an RNN has access to the current token (xt) and a context that summarizes all previous tokens (ht-1). This brings us to the core equation for updating a context at any timestep (ht):</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;h_t = \\phi(W_x x_t + W_h h_{t-1} + b)&quot;,&quot;id&quot;:&quot;CJYYCHWTAT&quot;}" data-component-name="LatexBlockToDOM"></div><p>where Wx and Wh are learned weight matrices, and b is a bias vector</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!hoAh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28c69f03-a6e9-4c5f-b2d8-df60ea8029e5_1244x582.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!hoAh!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28c69f03-a6e9-4c5f-b2d8-df60ea8029e5_1244x582.png 424w, https://substackcdn.com/image/fetch/$s_!hoAh!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28c69f03-a6e9-4c5f-b2d8-df60ea8029e5_1244x582.png 848w, https://substackcdn.com/image/fetch/$s_!hoAh!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28c69f03-a6e9-4c5f-b2d8-df60ea8029e5_1244x582.png 1272w, https://substackcdn.com/image/fetch/$s_!hoAh!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28c69f03-a6e9-4c5f-b2d8-df60ea8029e5_1244x582.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!hoAh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28c69f03-a6e9-4c5f-b2d8-df60ea8029e5_1244x582.png" width="1244" height="582" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/28c69f03-a6e9-4c5f-b2d8-df60ea8029e5_1244x582.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:582,&quot;width&quot;:1244,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!hoAh!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28c69f03-a6e9-4c5f-b2d8-df60ea8029e5_1244x582.png 424w, https://substackcdn.com/image/fetch/$s_!hoAh!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28c69f03-a6e9-4c5f-b2d8-df60ea8029e5_1244x582.png 848w, https://substackcdn.com/image/fetch/$s_!hoAh!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28c69f03-a6e9-4c5f-b2d8-df60ea8029e5_1244x582.png 1272w, https://substackcdn.com/image/fetch/$s_!hoAh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28c69f03-a6e9-4c5f-b2d8-df60ea8029e5_1244x582.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>One visible problem here is the packing of all past information into a single vector (ht). As the sequence grows longer, the model is forced to forget some of this information to make room for new information. Can we somehow keep updating the context without sacrificing earlier information? Yes! And that&#8217;s where attention comes in. </p><h3>Attention</h3><p>Attention allows a model to focus directly on previous tokens and selectively pull important information instead of compressing all past information into a single fixed-size vector. It lets each token decide which other token it needs to focus on and how much information to pull in. How? By projecting the same token representation into three distinct subspaces: query, key and value vectors.</p><p>The query and key vectors dictate how much information is transferred between any two tokens. The query vector asks &#8216;which token is relevant to me?&#8217; while the key vector represents what each token has to offer. By taking the dot product between these two vectors, we can measure their compatibility score. Here is an example.</p><blockquote><p>The cat sat on a mat</p></blockquote><p>The query for &#8216;sat&#8217; represents the kind of information the token is looking for. It computes a compatibility score with every other token in the sentence by taking the dot product between its query vector and other token&#8217;s key vector. Remember, each token has three corresponding vectors: key, query, and value. A high score between the query vector of &#8216;sat&#8217; and the key vector of &#8216;cat&#8217; indicates that &#8216;sat&#8217; should rely heavily on the token &#8216;cat&#8217; for its downstream tasks (whether next word prediction or machine translation).</p><p><strong>Note: </strong>Queries as questions and keys as information holders are purely pedagogical metaphors. These are just vectors learned to increase the predictive power of the model.</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{score}(q, k) = \\frac{q \\cdot k}{\\sqrt{d_k}}&quot;,&quot;id&quot;:&quot;CJKZJYUVRV&quot;}" data-component-name="LatexBlockToDOM"></div><p>The above score represents the relevance of the key to the query and determines how much information from the corresponding token&#8217;s value vector is incorporated into the querying token&#8217;s final representation. Each token&#8217;s representation is the weighted sum of all value vectors. For a given token i, the output representation is</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;h_i = \\sum_j a_{ij} v_j&quot;,&quot;id&quot;:&quot;HRVYAXPCOB&quot;}" data-component-name="LatexBlockToDOM"></div><p>where aij is the attention score between tokens i and j and vj is the value vector for token j</p><p>But can&#8217;t we just have a value vector? If we did, each token&#8217;s context would be all previous tokens regardless of how relevant these tokens are to the current token. In other words, every token would contribute equally, forcing the model to treat all past information as equally important. As the sequence grows longer, important information that appeared earlier in the sequence becomes diluted. Attention scores prevent this by ensuring connection is determined by relevance and not distance from the current token.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!6kiT!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb45cd2a7-89d2-4ed8-bb0e-3253691515b9_937x414.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!6kiT!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb45cd2a7-89d2-4ed8-bb0e-3253691515b9_937x414.png 424w, https://substackcdn.com/image/fetch/$s_!6kiT!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb45cd2a7-89d2-4ed8-bb0e-3253691515b9_937x414.png 848w, https://substackcdn.com/image/fetch/$s_!6kiT!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb45cd2a7-89d2-4ed8-bb0e-3253691515b9_937x414.png 1272w, https://substackcdn.com/image/fetch/$s_!6kiT!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb45cd2a7-89d2-4ed8-bb0e-3253691515b9_937x414.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!6kiT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb45cd2a7-89d2-4ed8-bb0e-3253691515b9_937x414.png" width="937" height="414" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b45cd2a7-89d2-4ed8-bb0e-3253691515b9_937x414.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:414,&quot;width&quot;:937,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!6kiT!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb45cd2a7-89d2-4ed8-bb0e-3253691515b9_937x414.png 424w, https://substackcdn.com/image/fetch/$s_!6kiT!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb45cd2a7-89d2-4ed8-bb0e-3253691515b9_937x414.png 848w, https://substackcdn.com/image/fetch/$s_!6kiT!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb45cd2a7-89d2-4ed8-bb0e-3253691515b9_937x414.png 1272w, https://substackcdn.com/image/fetch/$s_!6kiT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb45cd2a7-89d2-4ed8-bb0e-3253691515b9_937x414.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Hope you now understand why we need three separate vectors derived from the same representation for the attention mechanism to work.</p><h3>Self-attention vs multi-head attention</h3><p>So far, we&#8217;ve described self-attention, where each token computes a single attention score with each token it&#8217;s looking at. In multi-head attention, the model computes multiple attention heads in parallel. Each head has its own query, key, and value projections. This is equivalent to the current token looking at the same other token from different perspectives, inquiring different information (like semantics or syntax) with each head. The output of all heads is then concatenated to form the final representation.</p><p>To explain this better, imagine you&#8217;re trying to hire a candidate for a position. You&#8217;ll likely evaluate them from multiple angles before you make a decision. This can include technical proficiency, teamwork, past experience, and so on. There&#8217;s no single metric that can fully capture a candidate&#8217;s fit. This is similar to a token considering multiple &#8216;criteria&#8217; before deciding how much influence other tokens should have over its representation.</p><h3>Parallelization advantage</h3><p>The attention mechanism has another advantage, which is particularly attractive for companies building large models (and NVIDIA): parallelization. Sequential data requires sequential processing. But models using attention can compute attention scores between tokens independently of each other. No token depends on the output of another token in the sequence, making the computation highly parallelizable.</p><h3>Research questions</h3><p>In this post, we&#8217;ve discussed the attention mechanism in depth through formal mathematical definitions and analogies. This might lead you to think that the attention&#8217;s role in a model is thoroughly understood. However, understanding how a mechanism computes does not explain why it behaves that way. Despite our current understanding, there are still open questions in the research community as to how exactly each token allocates attention scores to other tokens. In addition, strong attention scores don&#8217;t correspond to higher importance or causality. This highlights that much remains to be investigated about this mechanism and its role in creating highly performant and efficient architectures.</p><div><hr></div><p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://news.algorythm.org/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Algorythm! Subscribe for free to receive more technical insights and support our work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p><h2><strong>About the Author</strong></h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!vgRE!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b6c1b94-b621-4852-9cfa-175d03084c45_800x800.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!vgRE!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b6c1b94-b621-4852-9cfa-175d03084c45_800x800.jpeg 424w, https://substackcdn.com/image/fetch/$s_!vgRE!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b6c1b94-b621-4852-9cfa-175d03084c45_800x800.jpeg 848w, https://substackcdn.com/image/fetch/$s_!vgRE!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b6c1b94-b621-4852-9cfa-175d03084c45_800x800.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!vgRE!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b6c1b94-b621-4852-9cfa-175d03084c45_800x800.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!vgRE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b6c1b94-b621-4852-9cfa-175d03084c45_800x800.jpeg" width="800" height="800" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3b6c1b94-b621-4852-9cfa-175d03084c45_800x800.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:800,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Profile image&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Profile image" title="Profile image" srcset="https://substackcdn.com/image/fetch/$s_!vgRE!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b6c1b94-b621-4852-9cfa-175d03084c45_800x800.jpeg 424w, https://substackcdn.com/image/fetch/$s_!vgRE!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b6c1b94-b621-4852-9cfa-175d03084c45_800x800.jpeg 848w, https://substackcdn.com/image/fetch/$s_!vgRE!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b6c1b94-b621-4852-9cfa-175d03084c45_800x800.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!vgRE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b6c1b94-b621-4852-9cfa-175d03084c45_800x800.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><a href="https://www.linkedin.com/in/ayda-sultan/">Ayda Sultan</a> is a machine learning researcher focused on interpreting the internals of large models. Her work centers around understanding how neural networks work internally. She&#8217;s an advocate of careful deployment of AI systems and believes AI models can be fully understood and surgically controlled.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://aydasultan.substack.com/subscribe&quot;,&quot;text&quot;:&quot;Subscribe to Ayda&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://aydasultan.substack.com/subscribe"><span>Subscribe to Ayda</span></a></p>]]></content:encoded></item><item><title><![CDATA[Building A Game Boy Color Emulator in Rust]]></title><description><![CDATA[The Project That Changed How I Think About Computers]]></description><link>https://news.algorythm.org/p/building-a-game-boy-color-emulator</link><guid isPermaLink="false">https://news.algorythm.org/p/building-a-game-boy-color-emulator</guid><dc:creator><![CDATA[Aza Walker]]></dc:creator><pubDate>Tue, 03 Feb 2026 16:02:17 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/45f36d49-c678-4d8d-9137-08c474ae69d4_1024x687.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>This publication is by members of the <strong><a href="https://algorythm.org/">Algorythm</a></strong> Community. A network of 20k+ black software engineers sharing technical insights across all fields of software development. Join us on <a href="https://www.linkedin.com/groups/8873861/">LinkedIn</a>, <a href="https://www.facebook.com/groups/algorythm">Facebook</a> and <a href="https://algorythmorg.substack.com/subscribe">Subscribe</a> for more insights.</em></p><div><hr></div><p>Building an emulator made me a better engineer&#8230;</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!lcw1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4a7be29-1d02-4ac3-b070-2b97c6db459c_1456x1362.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!lcw1!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4a7be29-1d02-4ac3-b070-2b97c6db459c_1456x1362.webp 424w, https://substackcdn.com/image/fetch/$s_!lcw1!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4a7be29-1d02-4ac3-b070-2b97c6db459c_1456x1362.webp 848w, https://substackcdn.com/image/fetch/$s_!lcw1!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4a7be29-1d02-4ac3-b070-2b97c6db459c_1456x1362.webp 1272w, https://substackcdn.com/image/fetch/$s_!lcw1!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4a7be29-1d02-4ac3-b070-2b97c6db459c_1456x1362.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!lcw1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4a7be29-1d02-4ac3-b070-2b97c6db459c_1456x1362.webp" width="1456" height="1362" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e4a7be29-1d02-4ac3-b070-2b97c6db459c_1456x1362.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1362,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:38878,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/webp&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://azawalker.substack.com/i/186584142?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4a7be29-1d02-4ac3-b070-2b97c6db459c_1456x1362.webp&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!lcw1!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4a7be29-1d02-4ac3-b070-2b97c6db459c_1456x1362.webp 424w, https://substackcdn.com/image/fetch/$s_!lcw1!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4a7be29-1d02-4ac3-b070-2b97c6db459c_1456x1362.webp 848w, https://substackcdn.com/image/fetch/$s_!lcw1!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4a7be29-1d02-4ac3-b070-2b97c6db459c_1456x1362.webp 1272w, https://substackcdn.com/image/fetch/$s_!lcw1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4a7be29-1d02-4ac3-b070-2b97c6db459c_1456x1362.webp 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Wild Pidgey appeared!</figcaption></figure></div><div><hr></div><p>I&#8217;m a self-taught software engineer. Most of what I know about computers came from reading books and articles, watching YouTube videos, taking online courses, and, most importantly, building software.</p><p>That approach gave me momentum. It taught me how to learn quickly and how to get unstuck. But it didn&#8217;t always give me satisfying answers to <em>why</em> or <em>how</em> things worked the way they did.</p><p>A lot of my learning was reactionary. I learned what I needed when I needed it. If a concept came up at work, I&#8217;d dive in just far enough to solve the problem in front of me. That&#8217;s often the most practical way to learn, but it also meant there were entire areas of computer science I could avoid as long as things kept working.</p><p>Over time, I started to notice that some parts of my understanding felt vague. I could write correct code, but I wasn&#8217;t always confident I understood what was happening underneath it. I began to suspect that being more proactive and actively seeking out what I didn&#8217;t fully understand, would make me a better engineer, especially in harder situations or when writing more intentional, efficient systems.</p><p>So one day I went hunting for a challenging project, and I decided to build a <a href="https://github.com/areklaw2/iron-boy">Game Boy / Game Boy Color</a> emulator&#8230; in Rust &#129408;&#8230;</p><div class="native-video-embed" data-component-name="VideoPlaceholder" data-attrs="{&quot;mediaUploadId&quot;:&quot;87cd5599-2f4d-44b0-886e-6cbdbfe6fb34&quot;,&quot;duration&quot;:null}"></div><p>An emulator is hardware or software that enables one computer system to behave like another computer system; it&#8217;s a computer inside a computer. I wrote a software emulator.</p><p>I wrote about it in this <a href="https://www.linkedin.com/posts/aza-walker_emulators-systemsprogramming-rust-activity-7354172429285351424-Jg6-?utm_source=share&amp;utm_medium=member_desktop&amp;rcm=ACoAABqJNAkBfI7k-M4FSnS2Ag2xFQoFTjei1Fs">post</a> I made on LinkedIn. The gist of the post was that building an emulator was a challenging and fun project where I learned some of the following topics:</p><ul><li><p>Endianness</p></li><li><p>Bit manipulations</p></li><li><p>CPU instruction sets &amp; assembly</p></li><li><p>CPU instruction execution pipelines &amp; interrupts</p></li><li><p>Disassembling bytes into assembly</p></li><li><p>Pixel Processing</p></li><li><p>Buses</p></li><li><p>RAM and ROM</p></li><li><p>I/O handling</p></li><li><p>Timing (polling vs scheduling)</p></li></ul><p>What I didn&#8217;t fully explain in the LinkedIn post was why building an emulator mattered so much to me. That project forced me to slow down. It made gaps in my understanding of computer architecture impossible to ignore. It gave me a concrete way to push into other computer science topics like operating systems and database. </p><h3>What Emulation Requires of You</h3><p>Emulation gave me a way to ask the question <em>What don&#8217;t I actually understand yet? </em>by forcing me to model a system&#8217;s behavior directly.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!WztD!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F224585fe-4fc0-4379-b08b-caeb17a74459_828x972.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!WztD!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F224585fe-4fc0-4379-b08b-caeb17a74459_828x972.jpeg 424w, https://substackcdn.com/image/fetch/$s_!WztD!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F224585fe-4fc0-4379-b08b-caeb17a74459_828x972.jpeg 848w, https://substackcdn.com/image/fetch/$s_!WztD!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F224585fe-4fc0-4379-b08b-caeb17a74459_828x972.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!WztD!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F224585fe-4fc0-4379-b08b-caeb17a74459_828x972.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!WztD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F224585fe-4fc0-4379-b08b-caeb17a74459_828x972.jpeg" width="560" height="657.3913043478261" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/224585fe-4fc0-4379-b08b-caeb17a74459_828x972.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:972,&quot;width&quot;:828,&quot;resizeWidth&quot;:560,&quot;bytes&quot;:61959,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:&quot;image/jpeg&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://azawalker.substack.com/i/186584142?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F224585fe-4fc0-4379-b08b-caeb17a74459_828x972.jpeg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!WztD!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F224585fe-4fc0-4379-b08b-caeb17a74459_828x972.jpeg 424w, https://substackcdn.com/image/fetch/$s_!WztD!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F224585fe-4fc0-4379-b08b-caeb17a74459_828x972.jpeg 848w, https://substackcdn.com/image/fetch/$s_!WztD!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F224585fe-4fc0-4379-b08b-caeb17a74459_828x972.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!WztD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F224585fe-4fc0-4379-b08b-caeb17a74459_828x972.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>When you write a web application, the rules of the machine are already in place. The hardware exists. Code execution is handled for you. You&#8217;re working inside a system whose behavior is defined ahead of time. The computer becomes a black box. You don&#8217;t care how it works internally, you care about the interface it exposes and whether it behaves as expected.</p><p>When you build an emulator, you don&#8217;t get that luxury. You have to build the black box itself.</p><p>The system you&#8217;re emulating has a fixed, real behavior. Your task is to reproduce that behavior accurately. Very quickly, vague ideas about computers turn into concrete questions:</p><ul><li><p>How does the CPU execute instructions, and in what order?</p></li><li><p>Where does state live, and when does it change?</p></li><li><p>How does data move between components?</p></li></ul><p>At a basic level, something has to fetch and execute instructions. Something has to hold memory. Something has to represent I/O components (timers, graphics, sound, input). Something has to move data between all of them.</p><p>An emulator is a system where every step depends on the last one. It&#8217;s a state machine. The next state depends on the current state, and the current state depends on the previous one. There&#8217;s no room to reinterpret mistakes as design choices. If one part of your model is wrong, the effects propagate.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!zylb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfa811f9-ade3-44d2-a882-fe93f8898df5_1600x729.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!zylb!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfa811f9-ade3-44d2-a882-fe93f8898df5_1600x729.png 424w, https://substackcdn.com/image/fetch/$s_!zylb!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfa811f9-ade3-44d2-a882-fe93f8898df5_1600x729.png 848w, https://substackcdn.com/image/fetch/$s_!zylb!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfa811f9-ade3-44d2-a882-fe93f8898df5_1600x729.png 1272w, https://substackcdn.com/image/fetch/$s_!zylb!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfa811f9-ade3-44d2-a882-fe93f8898df5_1600x729.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!zylb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfa811f9-ade3-44d2-a882-fe93f8898df5_1600x729.png" width="1456" height="663" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cfa811f9-ade3-44d2-a882-fe93f8898df5_1600x729.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:663,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:100773,&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://azawalker.substack.com/i/186584142?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfa811f9-ade3-44d2-a882-fe93f8898df5_1600x729.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_!zylb!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfa811f9-ade3-44d2-a882-fe93f8898df5_1600x729.png 424w, https://substackcdn.com/image/fetch/$s_!zylb!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfa811f9-ade3-44d2-a882-fe93f8898df5_1600x729.png 848w, https://substackcdn.com/image/fetch/$s_!zylb!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfa811f9-ade3-44d2-a882-fe93f8898df5_1600x729.png 1272w, https://substackcdn.com/image/fetch/$s_!zylb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfa811f9-ade3-44d2-a882-fe93f8898df5_1600x729.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">An example of a bug in how the pixels are rendered</figcaption></figure></div><p>Bugs show up in subtle but unforgiving ways. A misunderstood instruction can alter control flow. A small timing error can change observable behavior. A mistake in how memory is modeled can corrupt state long before anything crashes. Often, nothing fails loudly. Things just stop behaving like the machine you&#8217;re trying to emulate.</p><p>Building an emulator forces me to engage directly with structure, causality, and behavior, the fundamentals that drive both hardware and software systems.</p><h3><strong>Modeling The Structure</strong></h3><p>Let&#8217;s take a peek at some code and ideas to get a taste of the structure, causality, and behavior I mentioned.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!jmJb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9059211-dbcd-4b48-8736-b696bd1378a1_1000x455.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!jmJb!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9059211-dbcd-4b48-8736-b696bd1378a1_1000x455.webp 424w, https://substackcdn.com/image/fetch/$s_!jmJb!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9059211-dbcd-4b48-8736-b696bd1378a1_1000x455.webp 848w, https://substackcdn.com/image/fetch/$s_!jmJb!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9059211-dbcd-4b48-8736-b696bd1378a1_1000x455.webp 1272w, https://substackcdn.com/image/fetch/$s_!jmJb!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9059211-dbcd-4b48-8736-b696bd1378a1_1000x455.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!jmJb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9059211-dbcd-4b48-8736-b696bd1378a1_1000x455.webp" width="1000" height="455" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b9059211-dbcd-4b48-8736-b696bd1378a1_1000x455.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:455,&quot;width&quot;:1000,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:17066,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/webp&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://azawalker.substack.com/i/186584142?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9059211-dbcd-4b48-8736-b696bd1378a1_1000x455.webp&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!jmJb!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9059211-dbcd-4b48-8736-b696bd1378a1_1000x455.webp 424w, https://substackcdn.com/image/fetch/$s_!jmJb!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9059211-dbcd-4b48-8736-b696bd1378a1_1000x455.webp 848w, https://substackcdn.com/image/fetch/$s_!jmJb!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9059211-dbcd-4b48-8736-b696bd1378a1_1000x455.webp 1272w, https://substackcdn.com/image/fetch/$s_!jmJb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9059211-dbcd-4b48-8736-b696bd1378a1_1000x455.webp 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Basic Architecture of a Computer illustrating components.</figcaption></figure></div><h3>CPU</h3><p>At the center of a computer, and by extension, an emulator, is the Central Processing Unit (CPU). The CPU has access to the bus and registers. Registers are quick data storage that the CPU uses to know what it wants to do next. The cpu uses a special register called the program counter to retrieve the next instruction; the program counter is like an index into the memory that tells the CPU where it is in the executing program.</p><p>The CPU&#8217;s main goal is to fetch, decode, and execute instructions continuously and every time it does those actions; it completes a cycle.</p><pre><code><code>struct Cpu {
    bus: Bus,
    registers: [u8; 5],
    program_counter: u8,
}

impl Cpu {
    //...

    fn cycle(&amp;mut self) {
        // Fetch
        let instruction = self.fetch_instruction(self.program_counter);
        // Decode
        let instruction_type = self.decode_instruction(instruction);
        // Execute
        match instruction_type {
            Add =&gt; self.add_instruction(instruction),
        }
    }

    //...
}

fn main() {
    //...
    loop {
        // something signaled to interrupt the cpu
        if bus.interrupt_pending() {
            bus.handle_interupt() // clear interrup and unblock CPU
        }

        cpu.cycle()
    }
}</code></code></pre><p>The cpu cycles until the program ends, something halts it, or until an interrupt is triggered.  An interrupt is an external signal that tells the CPU something needs attention before continuing.</p><h3>Memory</h3><p>Memory is where state lives. It&#8217;s where programs live, data lives, and results are stored. The CPU relies on memory to keep track of instructions, data, and previous computations. Every read and write goes through memory. Without it, there is no persistent state for the system to operate on. We treat memory like an array of bytes</p><p>Usually when speaking about memory we are talking about, Random Access Memory (RAM). However, there is also Read Only Memory (ROM), usually from external memory devices like CDs or Cartridges.</p><h3>Bus</h3><p>The bus is how everything communicates. Instruction fetches, data reads and writes, addresses, and interrupt signals all move across it. It&#8217;s not glamorous, but it&#8217;s what allows the CPU, memory, and devices to coordinate with each other.</p><pre><code><code>struct Bus {
    ppu: Ppu,
    cartridge: Cartridge,
    interrupts: Interrupts,
}

impl Bus {
    fn read_8(&amp;self, address: u16) -&gt; u8 {
        match address {
            // Other components
            0x8000..=0x9FFF =&gt; self.ppu.read_8(address),
            0xC000..=0xFDFF =&gt; self.memory.read_8(address),
            // Other components
            0xFFFF =&gt; self.interrupts.read_8(address),
            _ =&gt; 0xFF,
        }
    }

    fn write_8(&amp;mut self, address: u16, value: u8) {
        match address {
            // Other components
            0x8000..=0x9FFF =&gt; self.ppu.write_8(address, value),
            0xC000..=0xFDFF =&gt; self.memory.write_8(address, value),
            // Other components
            0xFFFF =&gt; self.interrupts.write_8(value),
            _ =&gt; {}
        }
    }
}</code></code></pre><p>We can represent the Bus as a match that routes to different components based on the read and write address.</p><h3>I/O Devices</h3><p>Devices are everything that isn&#8217;t the CPU. Timers, graphics hardware, sound hardware, controllers, and input devices are how time passes, pixels appear, and user actions matter. Devices are also how the outside world signals the CPU through interrupts that something has happened and needs to be handled.</p><div><hr></div><p>I&#8217;m leaving out quite a bit here, intentionally. The goal isn&#8217;t completeness. It&#8217;s clarity. If you understand these pieces, you have enough of a mental model to start learning about emulators and computer architecture. Everything else builds on this foundation.</p><h2>What&#8217;s to Come</h2><p>This post is the first in a series about computer architecture concepts, using emulation as the guide. This won&#8217;t be a formal tutorial on how to write an emulator, but I will explore some of the topics that go into building one. </p><p>Next time we&#8217;ll start with the CPU and go into depth on instruction execution, then move to time, then memory, then devices like pixel processors. Finally, we&#8217;ll look at how all of these pieces interact to produce the systems we recognize.</p><p>You don&#8217;t need to understand everything at once. Each article will introduce one piece and we&#8217;ll drive it home.</p><p>By the end of this series, you won&#8217;t magically know everything. But you will have gained trust in your understanding. Debugging should feel less mysterious. Low-level systems should feel less intimidating. And the abstractions you use every day should start to make more sense.</p><p>If that sounds useful, let&#8217;s keep going! Thanks for reading! </p><div><hr></div><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://news.algorythm.org/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Algorythm! Subscribe for free to receive more technical insights and support our work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h2><strong>About the Author</strong></h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!AsKk!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d0df6e9-0e25-4f92-9ac5-6b87c6164253_1656x1945.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!AsKk!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d0df6e9-0e25-4f92-9ac5-6b87c6164253_1656x1945.jpeg 424w, https://substackcdn.com/image/fetch/$s_!AsKk!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d0df6e9-0e25-4f92-9ac5-6b87c6164253_1656x1945.jpeg 848w, https://substackcdn.com/image/fetch/$s_!AsKk!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d0df6e9-0e25-4f92-9ac5-6b87c6164253_1656x1945.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!AsKk!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d0df6e9-0e25-4f92-9ac5-6b87c6164253_1656x1945.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!AsKk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d0df6e9-0e25-4f92-9ac5-6b87c6164253_1656x1945.jpeg" width="728" height="855" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1d0df6e9-0e25-4f92-9ac5-6b87c6164253_1656x1945.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:1710,&quot;width&quot;:1456,&quot;resizeWidth&quot;:728,&quot;bytes&quot;:1443186,&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://algorythmorg.substack.com/i/186722425?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d0df6e9-0e25-4f92-9ac5-6b87c6164253_1656x1945.jpeg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:&quot;center&quot;,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!AsKk!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d0df6e9-0e25-4f92-9ac5-6b87c6164253_1656x1945.jpeg 424w, https://substackcdn.com/image/fetch/$s_!AsKk!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d0df6e9-0e25-4f92-9ac5-6b87c6164253_1656x1945.jpeg 848w, https://substackcdn.com/image/fetch/$s_!AsKk!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d0df6e9-0e25-4f92-9ac5-6b87c6164253_1656x1945.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!AsKk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d0df6e9-0e25-4f92-9ac5-6b87c6164253_1656x1945.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><figcaption class="image-caption"></figcaption></figure></div><p><a href="https://www.linkedin.com/in/aza-walker/">Aza Walker</a> is a Software Engineer, fascinated with the systems that make modern computing possible. If he&#8217;s not coding he&#8217;s listening to music, playing video games, or watching anime. Aza currently works at ShipBob as a Senior Software Engineer, where he focuses on developing scalable microservices.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://azawalker.substack.com/subscribe&quot;,&quot;text&quot;:&quot;Subscribe to Aza&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://azawalker.substack.com/subscribe"><span>Subscribe to Aza</span></a></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://github.com/areklaw2&quot;,&quot;text&quot;:&quot;Aza's Github&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://github.com/areklaw2"><span>Aza's Github</span></a></p><p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://news.algorythm.org/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Algorythm! Subscribe for free to receive more technical insights from the community and support our work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p>]]></content:encoded></item></channel></rss>