<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Derek mwale</title>
    <description>The latest articles on DEV Community by Derek mwale (@derekmwale).</description>
    <link>https://dev.to/derekmwale</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4042380%2F32f29659-b869-4e9b-914c-1584bd72f208.png</url>
      <title>DEV Community: Derek mwale</title>
      <link>https://dev.to/derekmwale</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/derekmwale"/>
    <language>en</language>
    <item>
      <title>The 5 Code Reviews That Changed How I Think About Engineering</title>
      <dc:creator>Derek mwale</dc:creator>
      <pubDate>Fri, 07 Aug 2026 06:06:33 +0000</pubDate>
      <link>https://dev.to/derekmwale/the-5-code-reviews-that-changed-how-i-think-about-engineering-56kg</link>
      <guid>https://dev.to/derekmwale/the-5-code-reviews-that-changed-how-i-think-about-engineering-56kg</guid>
      <description>&lt;p&gt;There are code reviews you forget five minutes after approving them.&lt;/p&gt;

&lt;p&gt;Then there are code reviews that permanently change how you think about software.&lt;/p&gt;

&lt;p&gt;I've had both.&lt;/p&gt;

&lt;p&gt;Early in my career, I thought code review was mostly about catching bugs.&lt;/p&gt;

&lt;p&gt;Someone writes code.&lt;/p&gt;

&lt;p&gt;Someone else reads it.&lt;/p&gt;

&lt;p&gt;They find something wrong.&lt;/p&gt;

&lt;p&gt;They leave a comment.&lt;/p&gt;

&lt;p&gt;The developer fixes it.&lt;/p&gt;

&lt;p&gt;Pull request gets merged.&lt;/p&gt;

&lt;p&gt;Done.&lt;/p&gt;

&lt;p&gt;That mental model is incomplete.&lt;/p&gt;

&lt;p&gt;The best code reviews I've experienced weren't really about syntax, formatting, or whether a function was ten lines too long.&lt;/p&gt;

&lt;p&gt;They were about &lt;strong&gt;how to think&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;A good review can expose an architectural assumption you didn't realize you were making.&lt;/p&gt;

&lt;p&gt;It can reveal that your data model doesn't represent reality.&lt;/p&gt;

&lt;p&gt;It can show you that an apparently harmless abstraction will become a nightmare six months later.&lt;/p&gt;

&lt;p&gt;It can demonstrate why an API should be designed around behavior rather than implementation.&lt;/p&gt;

&lt;p&gt;And sometimes, the most valuable review comment is only one sentence long.&lt;/p&gt;

&lt;p&gt;Over time, I started realizing that experienced engineers don't necessarily write better code because they know more syntax.&lt;/p&gt;

&lt;p&gt;They write better code because they have developed better instincts about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;boundaries&lt;/li&gt;
&lt;li&gt;failure&lt;/li&gt;
&lt;li&gt;data&lt;/li&gt;
&lt;li&gt;complexity&lt;/li&gt;
&lt;li&gt;ownership&lt;/li&gt;
&lt;li&gt;change&lt;/li&gt;
&lt;li&gt;observability&lt;/li&gt;
&lt;li&gt;trade-offs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These instincts are difficult to learn from tutorials.&lt;/p&gt;

&lt;p&gt;You usually learn them by getting burned.&lt;/p&gt;

&lt;p&gt;This article is about five hypothetical-but-realistic code reviews based on the kinds of engineering lessons that changed how I approach software.&lt;/p&gt;

&lt;p&gt;Each review taught me something different.&lt;/p&gt;

&lt;p&gt;And together they changed my definition of what "good code" actually means.&lt;/p&gt;




&lt;h1&gt;
  
  
  1. The Code Review That Taught Me That Correctness Comes Before Cleverness
&lt;/h1&gt;

&lt;p&gt;The first lesson was simple:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code that looks intelligent is not necessarily code that is correct.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I remember working on logic that involved processing a collection of records.&lt;/p&gt;

&lt;p&gt;The implementation was compact.&lt;/p&gt;

&lt;p&gt;It used a clever combination of filtering, mapping and reduction.&lt;/p&gt;

&lt;p&gt;Something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;quantity&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;active&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At first glance, this looks great.&lt;/p&gt;

&lt;p&gt;It's short.&lt;/p&gt;

&lt;p&gt;It's readable.&lt;/p&gt;

&lt;p&gt;It's idiomatic Python.&lt;/p&gt;

&lt;p&gt;But the review wasn't about the syntax.&lt;/p&gt;

&lt;p&gt;The reviewer asked:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Why are inactive products excluded from the calculation?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That question stopped me.&lt;/p&gt;

&lt;p&gt;I had assumed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;inactive product
      ↓
don't include it
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But the business requirement was actually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Product becomes inactive
      ↓
New purchases cannot use it
      ↓
Existing orders must preserve it
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The calculation wasn't supposed to ask whether the product was currently active.&lt;/p&gt;

&lt;p&gt;It was supposed to use the historical state captured when the order was created.&lt;/p&gt;

&lt;p&gt;The bug wasn't in the loop.&lt;/p&gt;

&lt;p&gt;The bug was in my mental model.&lt;/p&gt;




&lt;h1&gt;
  
  
  Code Can Be Locally Correct and Globally Wrong
&lt;/h1&gt;

&lt;p&gt;This is one of the most important engineering lessons I've learned.&lt;/p&gt;

&lt;p&gt;Consider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;calculate_total&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;quantity&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The function itself may be perfectly correct.&lt;/p&gt;

&lt;p&gt;But what if:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;item.price
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;is mutable?&lt;/p&gt;

&lt;p&gt;Suppose:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Monday:
Laptop = $1000

Tuesday:
Laptop = $1200
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A customer bought it Monday.&lt;/p&gt;

&lt;p&gt;If we calculate their historical order using the current product price:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Order total = $1200
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;we have created a logical bug.&lt;/p&gt;

&lt;p&gt;The arithmetic is correct.&lt;/p&gt;

&lt;p&gt;The system is wrong.&lt;/p&gt;

&lt;p&gt;This is the difference between &lt;strong&gt;local correctness&lt;/strong&gt; and &lt;strong&gt;system correctness&lt;/strong&gt;.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Fix Was a Data Modeling Decision
&lt;/h1&gt;

&lt;p&gt;Instead of relying on the current product:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;OrderItem
    │
    └── Product
           │
           └── current price
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;we capture the price at purchase time:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Order
 │
 └── OrderItem
       ├── product_id
       ├── quantity
       └── price_at_purchase
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;order_items&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="n"&gt;BIGSERIAL&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="n"&gt;order_id&lt;/span&gt; &lt;span class="nb"&gt;BIGINT&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;
        &lt;span class="k"&gt;REFERENCES&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;

    &lt;span class="n"&gt;product_id&lt;/span&gt; &lt;span class="nb"&gt;BIGINT&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;
        &lt;span class="k"&gt;REFERENCES&lt;/span&gt; &lt;span class="n"&gt;products&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;

    &lt;span class="n"&gt;quantity&lt;/span&gt; &lt;span class="nb"&gt;INTEGER&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;
        &lt;span class="k"&gt;CHECK&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;quantity&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;

    &lt;span class="n"&gt;price_cents&lt;/span&gt; &lt;span class="nb"&gt;INTEGER&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;
        &lt;span class="k"&gt;CHECK&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;price_cents&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Product.price
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;represents the current catalog price.&lt;/p&gt;

&lt;p&gt;While:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;OrderItem.price_cents
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;represents historical truth.&lt;/p&gt;

&lt;p&gt;That tiny modeling decision has enormous consequences.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Diagram
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;             PRODUCT
        ┌────────────────┐
        │ id             │
        │ name           │
        │ current_price  │
        └───────┬────────┘
                │
                │ reference
                ▼
          ORDER_ITEM
        ┌────────────────┐
        │ product_id     │
        │ quantity       │
        │ price_cents    │
        └────────────────┘
                │
                ▼
             ORDER
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The review taught me something bigger than "store historical prices."&lt;/p&gt;

&lt;p&gt;It taught me:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Before optimizing code, make sure the code represents the correct model of reality.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h1&gt;
  
  
  The Engineering Lesson
&lt;/h1&gt;

&lt;p&gt;A lot of bad software starts with developers asking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"How do I implement this?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;before asking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"What is actually true?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That's backwards.&lt;/p&gt;

&lt;p&gt;I now try to ask:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;What does this data mean?
        ↓
What must always be true?
        ↓
What changes over time?
        ↓
What is historical?
        ↓
What is current?
        ↓
Then:
How should I implement it?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is one reason I became much more interested in data modeling and system design.&lt;/p&gt;

&lt;p&gt;The code is downstream from the model.&lt;/p&gt;

&lt;p&gt;If the model is wrong, elegant code simply produces the wrong answer faster.&lt;/p&gt;




&lt;h1&gt;
  
  
  Implementation Principle: Make Invariants Explicit
&lt;/h1&gt;

&lt;p&gt;Suppose an order quantity must always be positive.&lt;/p&gt;

&lt;p&gt;Don't rely only on:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also enforce it at the database level:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CHECK&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;quantity&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Application validation
        +
Database constraint
        =
Defense in depth
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The system becomes harder to corrupt.&lt;/p&gt;

&lt;p&gt;That review changed how I see constraints.&lt;/p&gt;

&lt;p&gt;Constraints aren't obstacles.&lt;/p&gt;

&lt;p&gt;They're executable statements about reality.&lt;/p&gt;




&lt;h1&gt;
  
  
  2. The Code Review That Taught Me That Abstractions Have a Cost
&lt;/h1&gt;

&lt;p&gt;The second review taught me something even more painful:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Not every abstraction makes software better.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I once encountered the temptation to create a generic repository layer.&lt;/p&gt;

&lt;p&gt;It looked sophisticated.&lt;/p&gt;

&lt;p&gt;Something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;BaseRepository&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;filters&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="bp"&gt;...&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="bp"&gt;...&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="bp"&gt;...&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="bp"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserRepository&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BaseRepository&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;pass&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ProductRepository&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BaseRepository&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;pass&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;OrderRepository&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BaseRepository&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;pass&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At first:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Less duplication!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Beautiful.&lt;/p&gt;

&lt;p&gt;Then requirements changed.&lt;/p&gt;

&lt;p&gt;Orders needed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;transactional operations
state transitions
locking
historical records
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Users needed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;email uniqueness
authentication
soft deletion
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Products needed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;inventory
pricing
availability
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The generic abstraction started becoming:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;BaseRepository
       │
       ├── if User
       ├── if Product
       ├── if Order
       ├── if special case
       └── if another special case
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Eventually the abstraction was more complicated than the duplication it was supposed to eliminate.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Review Comment
&lt;/h1&gt;

&lt;p&gt;The reviewer essentially asked:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Are these things actually the same, or do they just look similar right now?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That changed how I think about abstraction.&lt;/p&gt;

&lt;p&gt;Two pieces of code being structurally similar does not mean they share the same concept.&lt;/p&gt;

&lt;p&gt;This distinction is enormous.&lt;/p&gt;




&lt;h1&gt;
  
  
  Similarity Is Not Identity
&lt;/h1&gt;

&lt;p&gt;Imagine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(...)&lt;/span&gt;
&lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(...)&lt;/span&gt;
&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(...)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;They all technically update something.&lt;/p&gt;

&lt;p&gt;But semantically:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User update
     ≠
Product update
     ≠
Order update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The abstraction:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;update(entity)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;may hide meaningful differences.&lt;/p&gt;

&lt;p&gt;A better design might be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;user_service&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update_profile&lt;/span&gt;&lt;span class="p"&gt;(...)&lt;/span&gt;
&lt;span class="n"&gt;product_service&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;change_price&lt;/span&gt;&lt;span class="p"&gt;(...)&lt;/span&gt;
&lt;span class="n"&gt;order_service&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cancel&lt;/span&gt;&lt;span class="p"&gt;(...)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the operations describe domain behavior.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Diagram
&lt;/h1&gt;

&lt;p&gt;Bad abstraction:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;             BaseRepository
                  │
        ┌─────────┼─────────┐
        ▼         ▼         ▼
      User     Product     Order
        │         │         │
        └───── shared ──────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Eventually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;             BaseRepository
                  │
       ┌──────────┼──────────┐
       ▼          ▼          ▼
     User       Product     Order
       │          │           │
    hacks       hacks       hacks
       │          │           │
       └──────────┼───────────┘
                  ▼
            abstraction hell
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Better:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;UserService
ProductService
OrderService
      │
      ▼
Shared infrastructure
      │
      ▼
Database
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Share infrastructure where it is genuinely shared.&lt;/p&gt;

&lt;p&gt;Don't force domain concepts into the same shape.&lt;/p&gt;




&lt;h1&gt;
  
  
  Abstraction Should Follow Understanding
&lt;/h1&gt;

&lt;p&gt;This became one of my favorite engineering principles.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Don't abstract what you haven't understood.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Early in a project, duplication can be useful.&lt;/p&gt;

&lt;p&gt;It gives you information.&lt;/p&gt;

&lt;p&gt;Suppose you have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;send_user_email&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nf"&gt;send_order_email&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nf"&gt;send_payment_email&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;They look similar.&lt;/p&gt;

&lt;p&gt;You could immediately create:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;send_email&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;template&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;recipient&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Maybe that's correct.&lt;/p&gt;

&lt;p&gt;But perhaps six months later you discover:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User email
→ transactional

Order email
→ retryable

Payment email
→ audit-sensitive
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the generic abstraction becomes restrictive.&lt;/p&gt;

&lt;p&gt;Sometimes three similar implementations are telling you:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"We don't yet know whether these things are actually the same."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That's valuable information.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Rule I Use Now
&lt;/h1&gt;

&lt;p&gt;I don't ask:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Can I remove duplication?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I ask:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Does the duplication represent the same concept?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If yes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Abstract.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If no:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Keep them separate.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If uncertain:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Wait.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Waiting is sometimes the better engineering decision.&lt;/p&gt;




&lt;h1&gt;
  
  
  3. The Code Review That Taught Me to Design for Failure
&lt;/h1&gt;

&lt;p&gt;The third review changed my relationship with error handling.&lt;/p&gt;

&lt;p&gt;I had written code around an external API.&lt;/p&gt;

&lt;p&gt;The happy path looked something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;payment_provider&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;charge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;amount&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;success&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;mark_order_paid&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Simple.&lt;/p&gt;

&lt;p&gt;The reviewer asked:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"What happens if the payment succeeds but this process crashes before &lt;code&gt;mark_order_paid()&lt;/code&gt;?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That question opened an entire world.&lt;/p&gt;




&lt;h1&gt;
  
  
  Distributed Systems Exist Even in Small Applications
&lt;/h1&gt;

&lt;p&gt;The system looked like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Your API
   │
   ▼
Payment Provider
   │
   ▼
Payment
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But now there are two independent systems.&lt;/p&gt;

&lt;p&gt;Your database might say:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PENDING
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;while the payment provider says:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PAID
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The network can fail.&lt;/p&gt;

&lt;p&gt;The process can crash.&lt;/p&gt;

&lt;p&gt;The response can disappear.&lt;/p&gt;

&lt;p&gt;The user can retry.&lt;/p&gt;

&lt;p&gt;The payment provider can timeout.&lt;/p&gt;

&lt;p&gt;You don't control any of these.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Naive Implementation
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;pay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;

    &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;payment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;charge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;total&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;success&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;PAID&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
        &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Potential sequence:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. Request payment
2. Provider charges customer
3. Provider returns success
4. Application crashes
5. Database still says PENDING
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now what?&lt;/p&gt;




&lt;h1&gt;
  
  
  The Better Design
&lt;/h1&gt;

&lt;p&gt;Introduce explicit payment states:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PENDING
AUTHORIZED
PAID
FAILED
REFUNDED
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And idempotency:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Client
  │
  │ Idempotency-Key: abc123
  ▼
Backend
  │
  ▼
Payment Provider
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Store:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;abc123 → payment result
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the request arrives again:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;abc123
  │
  ▼
Already processed
  │
  ▼
Return existing result
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Implementation
&lt;/h1&gt;

&lt;p&gt;A simplified schema:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;payments&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="n"&gt;BIGSERIAL&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="n"&gt;order_id&lt;/span&gt; &lt;span class="nb"&gt;BIGINT&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;
        &lt;span class="k"&gt;REFERENCES&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;

    &lt;span class="n"&gt;idempotency_key&lt;/span&gt; &lt;span class="nb"&gt;TEXT&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt; &lt;span class="k"&gt;UNIQUE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="nb"&gt;TEXT&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="n"&gt;amount_cents&lt;/span&gt; &lt;span class="nb"&gt;INTEGER&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;
        &lt;span class="k"&gt;CHECK&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;amount_cents&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;

    &lt;span class="n"&gt;created_at&lt;/span&gt; &lt;span class="n"&gt;TIMESTAMPTZ&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create_payment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;

    &lt;span class="n"&gt;existing&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;payment_repo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find_by_key&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;existing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;existing&lt;/span&gt;

    &lt;span class="n"&gt;payment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;payment_repo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;order_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;idempotency_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;PENDING&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;amount_cents&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;total&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;payment&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The unique constraint protects against duplicates.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Deeper Lesson
&lt;/h1&gt;

&lt;p&gt;The review wasn't really about payments.&lt;/p&gt;

&lt;p&gt;It taught me:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Assume the world can interrupt your program at any moment.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A process can die.&lt;/p&gt;

&lt;p&gt;A machine can restart.&lt;/p&gt;

&lt;p&gt;A database can timeout.&lt;/p&gt;

&lt;p&gt;A network packet can disappear.&lt;/p&gt;

&lt;p&gt;A user can click twice.&lt;/p&gt;

&lt;p&gt;A worker can execute the same job twice.&lt;/p&gt;

&lt;p&gt;An external API can return success after you timeout.&lt;/p&gt;

&lt;p&gt;Once you think this way, software design changes.&lt;/p&gt;

&lt;p&gt;You stop asking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Does this work?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;and start asking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"What happens when this works halfway?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That is a much more important question.&lt;/p&gt;




&lt;h1&gt;
  
  
  Design Around Failure States
&lt;/h1&gt;

&lt;p&gt;A robust system doesn't pretend failure doesn't happen.&lt;/p&gt;

&lt;p&gt;It models failure.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;             Operation
                 │
        ┌────────┼────────┐
        ▼        ▼        ▼
     Success   Timeout   Failure
        │        │        │
        ▼        ▼        ▼
      Commit    Retry    Recover
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And sometimes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Unknown outcome
      │
      ▼
Reconcile
      │
      ▼
Determine truth
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is especially important for:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Payments
Orders
Messaging
Distributed jobs
File uploads
External APIs
Inventory
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  4. The Code Review That Taught Me That Complexity Is a Budget
&lt;/h1&gt;

&lt;p&gt;The fourth review was about performance.&lt;/p&gt;

&lt;p&gt;I had optimized something before it needed optimization.&lt;/p&gt;

&lt;p&gt;The code was relatively straightforward.&lt;/p&gt;

&lt;p&gt;But I thought:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"This will eventually be slow."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So I introduced caching.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;API
 │
 ▼
Redis
 │
 ▼
PostgreSQL
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The reviewer asked:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"What evidence tells us the database is the bottleneck?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I didn't have any.&lt;/p&gt;

&lt;p&gt;I had optimized a problem that didn't exist.&lt;/p&gt;




&lt;h1&gt;
  
  
  Premature Optimization Is Really Premature Complexity
&lt;/h1&gt;

&lt;p&gt;People often quote:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Premature optimization is the root of all evil."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I think the more practical version is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Premature complexity is expensive even when the optimization is technically correct.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Caching introduces:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Cache keys
TTL
Invalidation
Stale data
Memory usage
Failure modes
Monitoring
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now instead of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Request
 ↓
Database
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Request
 ↓
Cache
 ├── HIT
 │    ↓
 │   Response
 │
 └── MISS
      ↓
    Database
      ↓
    Cache
      ↓
   Response
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's not free.&lt;/p&gt;




&lt;h1&gt;
  
  
  Measure First
&lt;/h1&gt;

&lt;p&gt;Suppose we have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;products&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;category_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before caching, measure.&lt;/p&gt;

&lt;p&gt;Maybe the query takes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;4ms
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Maybe there are:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2,000 requests/day
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Caching this might provide almost no value.&lt;/p&gt;

&lt;p&gt;Instead, suppose the query takes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1.8 seconds
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and receives:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;50,000 requests/minute
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we have evidence.&lt;/p&gt;

&lt;p&gt;Optimization becomes engineering instead of speculation.&lt;/p&gt;




&lt;h1&gt;
  
  
  A Better Optimization Loop
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Observe
  ↓
Measure
  ↓
Identify bottleneck
  ↓
Hypothesize
  ↓
Change
  ↓
Measure
  ↓
Keep or revert
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is very different from:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Guess
 ↓
Add technology
 ↓
Hope
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Example: Database Index
&lt;/h1&gt;

&lt;p&gt;Suppose:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;user_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;123&lt;/span&gt;
&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;created_at&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The table grows.&lt;/p&gt;

&lt;p&gt;Instead of immediately introducing a caching layer, check the query plan.&lt;/p&gt;

&lt;p&gt;You might discover that an index solves the problem:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;INDEX&lt;/span&gt; &lt;span class="n"&gt;idx_orders_user_created&lt;/span&gt;
&lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;created_at&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Before:

Query
 ↓
Scan huge table
 ↓
Sort
 ↓
Response

After:

Query
 ↓
Index
 ↓
Relevant rows
 ↓
Response
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A one-line index may be better than another distributed component.&lt;/p&gt;




&lt;h1&gt;
  
  
  Complexity Has Carrying Costs
&lt;/h1&gt;

&lt;p&gt;Every new component introduces:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Operational cost
Debugging cost
Deployment cost
Security cost
Learning cost
Failure modes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Think of architecture as having a complexity budget.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Database
        1 unit

Redis
        +1

Queue
        +1

Search cluster
        +1

Microservice
        +2

Event bus
        +2

Multi-region
        +3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The numbers aren't literal.&lt;/p&gt;

&lt;p&gt;The idea is.&lt;/p&gt;

&lt;p&gt;Complexity compounds.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Diagram
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Simple:

Application
    │
    ▼
Database


More complex:

Application
 ├── Redis
 ├── Queue
 ├── Search
 ├── Service A
 ├── Service B
 └── Event Bus
        │
        ▼
     Database
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second architecture may eventually be necessary.&lt;/p&gt;

&lt;p&gt;But it should earn its complexity.&lt;/p&gt;




&lt;h1&gt;
  
  
  Complexity Should Buy You Something
&lt;/h1&gt;

&lt;p&gt;This became a rule I use often:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Every architectural component should solve a measurable problem.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Redis should solve:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Latency
Database load
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A queue should solve:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Asynchronous processing
Traffic smoothing
Retryability
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A search engine should solve:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Search requirements
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Microservices should solve problems like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Independent deployment
Team ownership
Isolation
Scaling boundaries
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Not:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"Big companies use microservices."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  5. The Code Review That Taught Me That Readability Is a Performance Feature
&lt;/h1&gt;

&lt;p&gt;The fifth review might have been the most subtle.&lt;/p&gt;

&lt;p&gt;The code worked.&lt;/p&gt;

&lt;p&gt;It was reasonably fast.&lt;/p&gt;

&lt;p&gt;It passed tests.&lt;/p&gt;

&lt;p&gt;But the reviewer said something like:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"I understand what this code does, but I don't understand why it does it."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That sentence changed my view of readability.&lt;/p&gt;

&lt;p&gt;I had previously thought readability meant:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Good variable names
Short functions
Formatting
Comments
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Those things matter.&lt;/p&gt;

&lt;p&gt;But deeper readability is about &lt;strong&gt;preserving intent&lt;/strong&gt;.&lt;/p&gt;




&lt;h1&gt;
  
  
  Code Should Explain the System's Decisions
&lt;/h1&gt;

&lt;p&gt;Consider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ACTIVE&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;process&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Easy to read.&lt;/p&gt;

&lt;p&gt;But why?&lt;/p&gt;

&lt;p&gt;Maybe inactive users shouldn't be processed.&lt;/p&gt;

&lt;p&gt;Or maybe only verified users should.&lt;/p&gt;

&lt;p&gt;Or perhaps:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;ACTIVE&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;means something very specific in the domain.&lt;/p&gt;

&lt;p&gt;A better design can make the intent explicit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;can_receive_notifications&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="nf"&gt;notify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the code communicates behavior.&lt;/p&gt;




&lt;h1&gt;
  
  
  Business Logic Should Read Like Business Logic
&lt;/h1&gt;

&lt;p&gt;Instead of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;PAID&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;created_at&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;cutoff&lt;/span&gt;
    &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;refunded&lt;/span&gt;
&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="bp"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you might encapsulate the concept:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;is_eligible_for_archive&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="bp"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Order&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;is_eligible_for_archive&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nf"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;PAID&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
            &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;created_at&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;cutoff&lt;/span&gt;
            &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;refunded&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The complexity didn't disappear.&lt;/p&gt;

&lt;p&gt;It moved to a place where it can be named.&lt;/p&gt;

&lt;p&gt;That's valuable.&lt;/p&gt;




&lt;h1&gt;
  
  
  Names Are Compression
&lt;/h1&gt;

&lt;p&gt;A good function name compresses a lot of knowledge.&lt;/p&gt;

&lt;p&gt;Consider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;calculate_total&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;versus:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;calculate_refundable_amount&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second name tells me more.&lt;/p&gt;

&lt;p&gt;Or:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;transition_to_paid&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;instead of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;update_status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;PAID&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second is a generic mutation.&lt;/p&gt;

&lt;p&gt;The first communicates a domain transition.&lt;/p&gt;




&lt;h1&gt;
  
  
  APIs Should Express Intent
&lt;/h1&gt;

&lt;p&gt;Compare:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;PATCH /orders/123
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;POST /orders/123/cancel
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first exposes implementation.&lt;/p&gt;

&lt;p&gt;The second expresses behavior.&lt;/p&gt;

&lt;p&gt;This doesn't mean action-oriented endpoints are always better.&lt;/p&gt;

&lt;p&gt;The larger lesson is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Interfaces should communicate the domain's concepts, not merely expose its database.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h1&gt;
  
  
  Implementation: State Transitions
&lt;/h1&gt;

&lt;p&gt;Instead of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;CANCELLED&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cancel&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Order&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;cancel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;PENDING&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;PAID&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}:&lt;/span&gt;
            &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;InvalidTransition&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;CANCELLED&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the domain rule lives with the behavior.&lt;/p&gt;

&lt;p&gt;You can test it directly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;test_paid_order_can_be_cancelled&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;

    &lt;span class="n"&gt;order&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Order&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;PAID&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cancel&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;CANCELLED&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Readability Reduces Future Bugs
&lt;/h1&gt;

&lt;p&gt;This is why I increasingly see readability as a reliability feature.&lt;/p&gt;

&lt;p&gt;Suppose an engineer joins the project six months later.&lt;/p&gt;

&lt;p&gt;They see:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;CANCELLED&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;They might assume:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Any order can be cancelled.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But if they see:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cancel&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;they know:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;There is probably domain logic here.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code guides the engineer toward the correct behavior.&lt;/p&gt;

&lt;p&gt;That's powerful.&lt;/p&gt;




&lt;h1&gt;
  
  
  Comments Should Explain Why
&lt;/h1&gt;

&lt;p&gt;Bad comment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Increment counter
&lt;/span&gt;&lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code already explains that.&lt;/p&gt;

&lt;p&gt;Better:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Keep this counter monotonic because downstream
# reconciliation uses it to detect missing events.
&lt;/span&gt;&lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the comment preserves context.&lt;/p&gt;

&lt;p&gt;The best comments explain:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Why this exists
Why this approach was chosen
What constraint must not be violated
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Not:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;What the next line does
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  The Deeper Pattern Behind All Five Reviews
&lt;/h1&gt;

&lt;p&gt;Looking back, these five reviews seem different.&lt;/p&gt;

&lt;p&gt;One was about data modeling.&lt;/p&gt;

&lt;p&gt;One was about abstraction.&lt;/p&gt;

&lt;p&gt;One was about failure.&lt;/p&gt;

&lt;p&gt;One was about complexity.&lt;/p&gt;

&lt;p&gt;One was about readability.&lt;/p&gt;

&lt;p&gt;But they all point to the same thing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Engineering is mostly about managing change and uncertainty.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's put them together.&lt;/p&gt;




&lt;h1&gt;
  
  
  Lesson 1: Model Reality Correctly
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Reality
  ↓
Domain model
  ↓
Data model
  ↓
Code
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the model is wrong:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Wrong model
  ↓
Correct implementation
  ↓
Correctly implemented mistake
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Lesson 2: Don't Abstract Before Understanding
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Similarity
    ↓
Observation
    ↓
Understanding
    ↓
Abstraction
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Not:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Similarity
    ↓
Generic framework
    ↓
Pain
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Lesson 3: Design for Failure
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Operation
    ↓
Success
    OR
Failure
    OR
Timeout
    OR
Partial completion
    OR
Unknown state
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Good systems account for these.&lt;/p&gt;




&lt;h1&gt;
  
  
  Lesson 4: Spend Complexity Carefully
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Problem
  ↓
Measurement
  ↓
Solution
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Not:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Technology
  ↓
Find a problem for it
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Lesson 5: Preserve Intent
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Code
 ↓
Meaning
 ↓
Future engineer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The goal isn't merely for today's developer to understand the code.&lt;/p&gt;

&lt;p&gt;The goal is for someone six months from now to understand it without needing to reconstruct your entire thought process.&lt;/p&gt;




&lt;h1&gt;
  
  
  Code Review Is Architecture Review
&lt;/h1&gt;

&lt;p&gt;This changed my attitude toward pull requests.&lt;/p&gt;

&lt;p&gt;A pull request is not just:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Does this compile?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's also:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Does this model the domain correctly?

Does this introduce unnecessary coupling?

What happens when it fails?

Will this still make sense in six months?

Does this add complexity we actually need?

Can another engineer understand the intent?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These questions are much more valuable than arguing about tabs versus spaces.&lt;/p&gt;




&lt;h1&gt;
  
  
  A Practical Code Review Framework
&lt;/h1&gt;

&lt;p&gt;Today, when reviewing code, I like thinking in layers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Layer 1: Correctness
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Does it work?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Happy path
Edge cases
Invalid input
Failure states
Concurrency
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Layer 2: Data
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Does the model represent reality?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ask:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;What does this field mean?
What happens when it changes?
What history needs preserving?
What constraints exist?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Layer 3: Architecture
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Where does this responsibility belong?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ask:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Does this create coupling?
Does this violate boundaries?
Is this abstraction justified?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Layer 4: Operations
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;What happens in production?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ask:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;How do we debug it?
How do we monitor it?
What happens when a dependency fails?
Can we recover?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Layer 5: Future Change
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;What happens when requirements change?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ask:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Can this evolve?
Will this force a rewrite?
Does this lock us into a decision too early?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is where code review starts becoming engineering review.&lt;/p&gt;




&lt;h1&gt;
  
  
  What I Don't Care About as Much Anymore
&lt;/h1&gt;

&lt;p&gt;Experience changed what I consider important.&lt;/p&gt;

&lt;p&gt;I care less about:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;One-line functions
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and more about:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Correct boundaries
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I care less about:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Perfect abstractions
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and more about:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Useful abstractions
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I care less about:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Maximum performance
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and more about:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Measured performance
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I care less about:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;How clever the implementation looks
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and more about:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Whether another engineer can reason about it
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And I care much more about:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Failure
Data integrity
Operational visibility
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  The Best Code Is Often Boring
&lt;/h1&gt;

&lt;p&gt;This is probably one of the biggest changes in my engineering philosophy.&lt;/p&gt;

&lt;p&gt;When I was younger, interesting code meant:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Complex algorithm
Clever abstraction
Advanced architecture
New technology
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, interesting engineering often looks boring.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create_order&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;

    &lt;span class="nf"&gt;validate_items&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nf"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;

        &lt;span class="n"&gt;order&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;create_order_record&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="nf"&gt;create_order_items&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is nothing flashy here.&lt;/p&gt;

&lt;p&gt;But if:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;validation
transactionality
constraints
authorization
idempotency
observability
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;are all correctly handled around it, this boring code can be extremely valuable.&lt;/p&gt;




&lt;h1&gt;
  
  
  Engineering Is Not About Impressing the Compiler
&lt;/h1&gt;

&lt;p&gt;The compiler doesn't care about your architecture.&lt;/p&gt;

&lt;p&gt;The database doesn't care about your design philosophy.&lt;/p&gt;

&lt;p&gt;The user doesn't care how elegant your dependency injection system is.&lt;/p&gt;

&lt;p&gt;Production cares about:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Correctness
Reliability
Performance
Security
Recoverability
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And future developers care about:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Clarity
Boundaries
Intent
Changeability
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Good engineering balances both.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Difference Between Code and Software
&lt;/h1&gt;

&lt;p&gt;This distinction became much clearer to me.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code&lt;/strong&gt; is what you write.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Software&lt;/strong&gt; is what happens after you write it.&lt;/p&gt;

&lt;p&gt;Software includes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Code
+
Data
+
Users
+
Infrastructure
+
Failures
+
Deployments
+
Operations
+
Future changes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A code review that only looks at the code is incomplete.&lt;/p&gt;

&lt;p&gt;You have to think about the system around it.&lt;/p&gt;




&lt;h1&gt;
  
  
  A Pull Request Is a Prediction
&lt;/h1&gt;

&lt;p&gt;This is another mental model I like.&lt;/p&gt;

&lt;p&gt;Every pull request is a prediction about the future.&lt;/p&gt;

&lt;p&gt;When you merge:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;This code will behave correctly.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But you're also saying:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;This data model will remain useful.

This boundary will make sense.

This complexity is worth it.

These failure modes are acceptable.

Future developers will understand this.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's a much bigger claim.&lt;/p&gt;

&lt;p&gt;Code review is the process of challenging that prediction.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Five Questions I Ask Now
&lt;/h1&gt;

&lt;p&gt;If I had to reduce everything I've learned into five questions, they would be:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. What reality is this code modeling?
&lt;/h3&gt;

&lt;p&gt;If I don't understand the underlying concept, I shouldn't approve the implementation yet.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. What happens when this fails halfway?
&lt;/h3&gt;

&lt;p&gt;Timeouts, retries, crashes and duplicate requests are normal parts of production.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Is this abstraction actually earned?
&lt;/h3&gt;

&lt;p&gt;Similarity isn't enough.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. What complexity am I introducing?
&lt;/h3&gt;

&lt;p&gt;Every abstraction, dependency and service has a maintenance cost.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Will the next engineer understand why?
&lt;/h3&gt;

&lt;p&gt;Because eventually, someone else will have to change it.&lt;/p&gt;

&lt;p&gt;And that person might be me six months later.&lt;/p&gt;




&lt;h1&gt;
  
  
  A Complete Review Example
&lt;/h1&gt;

&lt;p&gt;Imagine this pull request:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;process_payment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;

    &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;provider&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;charge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;success&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;PAID&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
        &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A shallow review says:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Looks good.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A deeper review asks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. What if provider succeeds and db.save() fails?

2. Can this function be called twice?

3. Is provider.charge() idempotent?

4. Where is the payment ID stored?

5. What if the provider times out?

6. How do we reconcile unknown states?

7. Is order.status allowed to change directly?

8. Is payment amount derived from trusted data?

9. How do we observe failures?

10. How do we test duplicate requests?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we're reviewing a system.&lt;/p&gt;




&lt;h1&gt;
  
  
  A More Robust Version
&lt;/h1&gt;

&lt;p&gt;Conceptually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;process_payment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;idempotency_key&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;

    &lt;span class="n"&gt;payment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;payment_repo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find_by_key&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;idempotency_key&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;payment&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;payment&lt;/span&gt;

    &lt;span class="n"&gt;payment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;payment_repo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;order_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;amount_cents&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;idempotency_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;idempotency_key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;PENDING&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

        &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;provider&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;charge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;payment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;amount_cents&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;idempotency_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;idempotency_key&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;success&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;payment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mark_paid&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="n"&gt;provider_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;
            &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;payment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mark_failed&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

        &lt;span class="n"&gt;payment_repo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;payment&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;payment&lt;/span&gt;

    &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;TimeoutError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

        &lt;span class="n"&gt;payment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mark_unknown&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

        &lt;span class="n"&gt;payment_repo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;payment&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="k"&gt;raise&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This still isn't a complete payment system.&lt;/p&gt;

&lt;p&gt;Real systems need reconciliation, webhooks, retries, provider-specific behavior and more.&lt;/p&gt;

&lt;p&gt;But notice how different the mental model is.&lt;/p&gt;

&lt;p&gt;We're explicitly modeling:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Identity
State
Failure
Retries
External systems
Historical records
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's engineering.&lt;/p&gt;




&lt;h1&gt;
  
  
  Code Review Should Teach, Not Just Judge
&lt;/h1&gt;

&lt;p&gt;Another lesson I learned is that the best code reviews don't simply say:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Wrong."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;They explain:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Here's the risk."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For example, instead of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Don't do this.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;say:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;This couples order state directly to the payment provider response.
If the provider succeeds but this transaction fails, our local state
can remain PENDING. Consider modeling the payment state separately and
using an idempotency key so retries don't create duplicate charges.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That teaches a principle.&lt;/p&gt;

&lt;p&gt;The developer can use it elsewhere.&lt;/p&gt;

&lt;p&gt;That's a much better review.&lt;/p&gt;




&lt;h1&gt;
  
  
  From Reviewer to Better Engineer
&lt;/h1&gt;

&lt;p&gt;Eventually, code review stops being something you do to other people's code.&lt;/p&gt;

&lt;p&gt;You start reviewing your own code mentally before opening the pull request.&lt;/p&gt;

&lt;p&gt;You start thinking:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Will someone question this abstraction?
What happens if this times out?
Is this data historical?
Do I need this dependency?
Can I explain why this exists?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's when code review has done its job.&lt;/p&gt;

&lt;p&gt;It has changed how you think.&lt;/p&gt;




&lt;h1&gt;
  
  
  Final Thoughts
&lt;/h1&gt;

&lt;p&gt;The five code reviews I remember most weren't necessarily the ones that caught the biggest bugs.&lt;/p&gt;

&lt;p&gt;They were the ones that changed the questions I asked.&lt;/p&gt;

&lt;p&gt;The first taught me:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Correctness starts with modeling reality.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The second taught me:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Abstraction is a tool, not a virtue.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The third taught me:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Failure is not an edge case. It is part of the normal execution environment.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The fourth taught me:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Complexity is a budget. Spend it where the problem demands it.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The fifth taught me:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Readable code preserves intent for people you haven't met yet.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Together, these lessons changed my definition of engineering.&lt;/p&gt;

&lt;p&gt;I used to think engineering was mostly about making software work.&lt;/p&gt;

&lt;p&gt;Now I think it's about making software &lt;strong&gt;continue to work as reality changes&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Users change.&lt;/p&gt;

&lt;p&gt;Requirements change.&lt;/p&gt;

&lt;p&gt;Traffic changes.&lt;/p&gt;

&lt;p&gt;Databases grow.&lt;/p&gt;

&lt;p&gt;Dependencies fail.&lt;/p&gt;

&lt;p&gt;Teams change.&lt;/p&gt;

&lt;p&gt;Business models change.&lt;/p&gt;

&lt;p&gt;The original developer leaves.&lt;/p&gt;

&lt;p&gt;And eventually, somebody opens the code six months later and asks:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Why did they build it this way?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The quality of your engineering is partly determined by how easily that person can answer that question.&lt;/p&gt;

&lt;p&gt;That's why I don't think the best code is necessarily the shortest code.&lt;/p&gt;

&lt;p&gt;Or the cleverest code.&lt;/p&gt;

&lt;p&gt;Or the most abstract code.&lt;/p&gt;

&lt;p&gt;Or even the fastest code.&lt;/p&gt;

&lt;p&gt;The best code is code that makes the system's important truths visible.&lt;/p&gt;

&lt;p&gt;It tells you:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;What the system believes.
What the system guarantees.
What can fail.
Where responsibility lives.
Why a decision was made.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And when those things are clear, something interesting happens.&lt;/p&gt;

&lt;p&gt;The code becomes easier to change.&lt;/p&gt;

&lt;p&gt;The architecture becomes easier to reason about.&lt;/p&gt;

&lt;p&gt;The bugs become easier to diagnose.&lt;/p&gt;

&lt;p&gt;The reviews become more meaningful.&lt;/p&gt;

&lt;p&gt;And the system starts feeling less like a pile of instructions and more like an engineered machine.&lt;/p&gt;

&lt;p&gt;That's probably the biggest thing code reviews have taught me.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Good engineering isn't about writing code that looks impressive.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It's about building systems that remain understandable when the original assumptions start breaking.&lt;/p&gt;

&lt;p&gt;And eventually, they always do.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>softwaredevelopment</category>
      <category>api</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>The "Minimum Viable System": How to Ship Early Without Shipping Junk</title>
      <dc:creator>Derek mwale</dc:creator>
      <pubDate>Fri, 07 Aug 2026 05:57:56 +0000</pubDate>
      <link>https://dev.to/derekmwale/the-minimum-viable-system-how-to-ship-early-without-shipping-junk-5d40</link>
      <guid>https://dev.to/derekmwale/the-minimum-viable-system-how-to-ship-early-without-shipping-junk-5d40</guid>
      <description>&lt;p&gt;There is a dangerous piece of advice in software development:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Just build an MVP."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It sounds reasonable.&lt;/p&gt;

&lt;p&gt;Build the smallest possible version.&lt;/p&gt;

&lt;p&gt;Launch quickly.&lt;/p&gt;

&lt;p&gt;Get feedback.&lt;/p&gt;

&lt;p&gt;Improve later.&lt;/p&gt;

&lt;p&gt;The problem is that many developers interpret "minimum viable product" as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Remove everything.
Skip architecture.
Ignore security.
Ignore testing.
Hardcode everything.
Ship it.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then six months later, the product is technically alive but practically dead.&lt;/p&gt;

&lt;p&gt;Every new feature breaks something.&lt;/p&gt;

&lt;p&gt;Every database migration is terrifying.&lt;/p&gt;

&lt;p&gt;Every customer request requires a workaround.&lt;/p&gt;

&lt;p&gt;The codebase has become a collection of decisions that made sense individually but make no sense together.&lt;/p&gt;

&lt;p&gt;The team spends more time fighting the system than improving the product.&lt;/p&gt;

&lt;p&gt;This is where I think the idea of a &lt;strong&gt;Minimum Viable System&lt;/strong&gt; becomes much more useful.&lt;/p&gt;

&lt;p&gt;The goal isn't to build the smallest amount of software possible.&lt;/p&gt;

&lt;p&gt;The goal is to build the &lt;strong&gt;smallest system that can safely support learning&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;That distinction matters.&lt;/p&gt;

&lt;p&gt;A Minimum Viable System is not junk software.&lt;/p&gt;

&lt;p&gt;It is intentionally incomplete software with enough engineering discipline to survive contact with reality.&lt;/p&gt;

&lt;p&gt;The system doesn't need every feature.&lt;/p&gt;

&lt;p&gt;It doesn't need perfect scalability.&lt;/p&gt;

&lt;p&gt;It doesn't need a distributed architecture.&lt;/p&gt;

&lt;p&gt;It doesn't need Kubernetes.&lt;/p&gt;

&lt;p&gt;It doesn't need twelve microservices.&lt;/p&gt;

&lt;p&gt;But it does need a few things to be fundamentally correct.&lt;/p&gt;

&lt;p&gt;It needs a coherent data model.&lt;/p&gt;

&lt;p&gt;It needs clear boundaries.&lt;/p&gt;

&lt;p&gt;It needs basic observability.&lt;/p&gt;

&lt;p&gt;It needs reasonable security.&lt;/p&gt;

&lt;p&gt;It needs a deployment process.&lt;/p&gt;

&lt;p&gt;It needs tests around important behavior.&lt;/p&gt;

&lt;p&gt;And most importantly, it needs to be designed so that the next version doesn't require throwing away the first one.&lt;/p&gt;

&lt;p&gt;That is the difference between &lt;strong&gt;shipping early&lt;/strong&gt; and &lt;strong&gt;shipping junk&lt;/strong&gt;.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Problem With "Move Fast"
&lt;/h1&gt;

&lt;p&gt;Software engineers often imagine speed as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Idea
 ↓
Code
 ↓
Deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But real software doesn't work that way.&lt;/p&gt;

&lt;p&gt;The moment users arrive, the system becomes a living thing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                USERS
                  │
                  ▼
              PRODUCT
                  │
       ┌──────────┼──────────┐
       ▼          ▼          ▼
    Traffic     Data       Feedback
       │          │          │
       └──────────┼──────────┘
                  ▼
              ENGINEERING
                  │
                  ▼
               CHANGE
                  │
                  ▼
               PRODUCT
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every deployment creates new constraints.&lt;/p&gt;

&lt;p&gt;Every customer creates new data.&lt;/p&gt;

&lt;p&gt;Every integration creates another dependency.&lt;/p&gt;

&lt;p&gt;Every feature creates another behavior.&lt;/p&gt;

&lt;p&gt;The software becomes increasingly difficult to change.&lt;/p&gt;

&lt;p&gt;So the real objective of early development should not be:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"How quickly can I write the first version?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It should be:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"How quickly can I create a system that teaches me what I need to know without creating unnecessary future problems?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That is a much better question.&lt;/p&gt;




&lt;h1&gt;
  
  
  MVP vs Minimum Viable System
&lt;/h1&gt;

&lt;p&gt;Let's make the distinction explicit.&lt;/p&gt;

&lt;p&gt;A traditional MVP often gets described as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Minimum
+
Viable
+
Product
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I would describe a Minimum Viable System as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Minimum
+
Useful
+
Safe
+
Observable
+
Changeable
+
Deployable
+
System
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The product is what users experience.&lt;/p&gt;

&lt;p&gt;The system is everything required to make that experience reliable.&lt;/p&gt;

&lt;p&gt;For example, suppose you're building a simple marketplace.&lt;/p&gt;

&lt;p&gt;The MVP might be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User
 ↓
Browse Products
 ↓
Add to Cart
 ↓
Checkout
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But the Minimum Viable System is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                   Marketplace
                       │
       ┌───────────────┼───────────────┐
       ▼               ▼               ▼
   Frontend         Backend         Database
                       │
             ┌─────────┼─────────┐
             ▼         ▼         ▼
          Auth       Orders    Payments
                       │
                       ▼
                  Observability
                       │
                       ▼
                   Deployment
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You don't need everything.&lt;/p&gt;

&lt;p&gt;But the things you do build need to form a coherent system.&lt;/p&gt;




&lt;h1&gt;
  
  
  The First Principle: Remove Features, Not Engineering
&lt;/h1&gt;

&lt;p&gt;This is probably the most important idea in the entire article.&lt;/p&gt;

&lt;p&gt;When you're trying to ship early, remove &lt;strong&gt;scope&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Don't automatically remove &lt;strong&gt;engineering discipline&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;For example, you might decide:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;No social login.
No mobile application.
No recommendation engine.
No advanced analytics.
No multi-language support.
No marketplace messaging.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Good.&lt;/p&gt;

&lt;p&gt;That's scope reduction.&lt;/p&gt;

&lt;p&gt;But don't decide:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;No authentication.
No validation.
No database constraints.
No backups.
No error handling.
No logs.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's not scope reduction.&lt;/p&gt;

&lt;p&gt;That's risk accumulation.&lt;/p&gt;

&lt;p&gt;A useful way to think about it is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                 PRODUCT SCOPE
                       │
             ┌─────────┴─────────┐
             ▼                   ▼
          Remove               Keep
          Features             Foundations
             │                   │
             ▼                   ▼
        Faster Launch        Safer System
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The trick is knowing which is which.&lt;/p&gt;




&lt;h1&gt;
  
  
  What Can Be Cheap?
&lt;/h1&gt;

&lt;p&gt;Almost everything visible to the user can be simplified.&lt;/p&gt;

&lt;p&gt;Suppose you're building a dashboard.&lt;/p&gt;

&lt;p&gt;You don't need:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;100 chart types
Real-time WebSockets
Custom themes
AI analytics
Advanced filtering
Drag-and-drop layouts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You might only need:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Three metrics
One table
One chart
One filter
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's perfectly reasonable.&lt;/p&gt;

&lt;p&gt;But your backend should still have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input validation
Authentication
Authorization
Database constraints
Error handling
Logging
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The interface can be primitive.&lt;/p&gt;

&lt;p&gt;The foundations should be intentional.&lt;/p&gt;




&lt;h1&gt;
  
  
  Think in System Invariants
&lt;/h1&gt;

&lt;p&gt;One of the best ways to build a small system without building a fragile system is to define &lt;strong&gt;invariants&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;An invariant is something that should always be true.&lt;/p&gt;

&lt;p&gt;For an e-commerce system:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;An order must belong to a user.

An order must contain at least one item.

An order item must reference a valid product.

A paid order cannot become unpaid accidentally.

A product price must not be negative.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These rules are more important than whether the interface has a beautiful animation.&lt;/p&gt;




&lt;h1&gt;
  
  
  Example: Database Invariants
&lt;/h1&gt;

&lt;p&gt;Suppose we have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;products&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="n"&gt;BIGSERIAL&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="nb"&gt;TEXT&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;price_cents&lt;/span&gt; &lt;span class="nb"&gt;INTEGER&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can strengthen the system:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;products&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="n"&gt;BIGSERIAL&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="nb"&gt;TEXT&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;price_cents&lt;/span&gt; &lt;span class="nb"&gt;INTEGER&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;
        &lt;span class="k"&gt;CHECK&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;price_cents&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the database itself protects an invariant.&lt;/p&gt;

&lt;p&gt;This is important because your application code isn't the only thing touching your data forever.&lt;/p&gt;

&lt;p&gt;Eventually you'll have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Backend
Admin panel
Scripts
Workers
Imports
Migrations
Analytics jobs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Database constraints are a final line of defense.&lt;/p&gt;




&lt;h1&gt;
  
  
  Don't Build a Cathedral
&lt;/h1&gt;

&lt;p&gt;One of the biggest mistakes I've seen in early software development is architecture designed for imaginary scale.&lt;/p&gt;

&lt;p&gt;The developer thinks:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"What if we get ten million users?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So they build:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;API Gateway
 ↓
Auth Service
 ↓
User Service
 ↓
Product Service
 ↓
Order Service
 ↓
Event Bus
 ↓
Kafka
 ↓
Multiple databases
 ↓
Redis cluster
 ↓
Kubernetes
 ↓
Service mesh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The product has:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;12 users.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is architecture fiction.&lt;/p&gt;

&lt;p&gt;The architecture should reflect the problem you actually have.&lt;/p&gt;




&lt;h1&gt;
  
  
  Start With the Boring Architecture
&lt;/h1&gt;

&lt;p&gt;For many products, I would start with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                 Internet
                    │
                    ▼
                 Nginx
                    │
                    ▼
              Application
                    │
              ┌─────┴─────┐
              ▼           ▼
           Database      Redis
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Maybe you don't even need Redis.&lt;/p&gt;

&lt;p&gt;Maybe:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Internet
   ↓
Application
   ↓
PostgreSQL
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;is enough.&lt;/p&gt;

&lt;p&gt;There is nothing embarrassing about this.&lt;/p&gt;

&lt;p&gt;A well-designed monolith can take you surprisingly far.&lt;/p&gt;

&lt;p&gt;The goal is not architectural complexity.&lt;/p&gt;

&lt;p&gt;The goal is &lt;strong&gt;architectural clarity&lt;/strong&gt;.&lt;/p&gt;




&lt;h1&gt;
  
  
  A Good Monolith Has Boundaries
&lt;/h1&gt;

&lt;p&gt;A monolith doesn't mean:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Everything everywhere.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It can still have internal modules.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app/
├── users/
├── products/
├── orders/
├── payments/
├── notifications/
└── shared/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The application is one deployable unit.&lt;/p&gt;

&lt;p&gt;But the concepts are separated.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;             Application
                  │
     ┌────────────┼────────────┐
     ▼            ▼            ▼
   Users       Products      Orders
                                │
                                ▼
                            Payments
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a very powerful starting point.&lt;/p&gt;

&lt;p&gt;If one day the order subsystem genuinely needs to become independent, you already have a conceptual boundary.&lt;/p&gt;




&lt;h1&gt;
  
  
  Implementation: A Small Modular Backend
&lt;/h1&gt;

&lt;p&gt;Here's a simplified Python-style structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserService&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create_user&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="bp"&gt;...&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ProductService&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create_product&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="bp"&gt;...&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;OrderService&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create_order&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="bp"&gt;...&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PaymentService&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;charge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;order_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="bp"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The services can live inside one application.&lt;/p&gt;

&lt;p&gt;You don't need a network boundary between them yet.&lt;/p&gt;

&lt;p&gt;That is an important distinction:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Logical boundary
≠
Network boundary
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create the logical boundary first.&lt;/p&gt;

&lt;p&gt;Introduce distributed infrastructure only when the problem demands it.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Minimum Viable Data Model
&lt;/h1&gt;

&lt;p&gt;Early developers sometimes focus heavily on screens.&lt;/p&gt;

&lt;p&gt;I usually think about the data first.&lt;/p&gt;

&lt;p&gt;Ask:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;What entities exist?

What relationships exist?

What must always be true?

What changes over time?

What needs history?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For a marketplace:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User
 │
 └────&amp;lt; Order
           │
           └────&amp;lt; OrderItem &amp;gt;──── Product
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A simple relational model might be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="n"&gt;BIGSERIAL&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;email&lt;/span&gt; &lt;span class="nb"&gt;TEXT&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt; &lt;span class="k"&gt;UNIQUE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;created_at&lt;/span&gt; &lt;span class="n"&gt;TIMESTAMPTZ&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;products&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="n"&gt;BIGSERIAL&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="nb"&gt;TEXT&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;price_cents&lt;/span&gt; &lt;span class="nb"&gt;INTEGER&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;
        &lt;span class="k"&gt;CHECK&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;price_cents&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;created_at&lt;/span&gt; &lt;span class="n"&gt;TIMESTAMPTZ&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="n"&gt;BIGSERIAL&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;user_id&lt;/span&gt; &lt;span class="nb"&gt;BIGINT&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;
        &lt;span class="k"&gt;REFERENCES&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="nb"&gt;TEXT&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;created_at&lt;/span&gt; &lt;span class="n"&gt;TIMESTAMPTZ&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;order_items&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="n"&gt;BIGSERIAL&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;order_id&lt;/span&gt; &lt;span class="nb"&gt;BIGINT&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;
        &lt;span class="k"&gt;REFERENCES&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;product_id&lt;/span&gt; &lt;span class="nb"&gt;BIGINT&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;
        &lt;span class="k"&gt;REFERENCES&lt;/span&gt; &lt;span class="n"&gt;products&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;quantity&lt;/span&gt; &lt;span class="nb"&gt;INTEGER&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;
        &lt;span class="k"&gt;CHECK&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;quantity&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;price_cents&lt;/span&gt; &lt;span class="nb"&gt;INTEGER&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;
        &lt;span class="k"&gt;CHECK&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;price_cents&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice something important.&lt;/p&gt;

&lt;p&gt;This is not over-engineered.&lt;/p&gt;

&lt;p&gt;It's just explicit.&lt;/p&gt;




&lt;h1&gt;
  
  
  Why Store the Price on Order Items?
&lt;/h1&gt;

&lt;p&gt;Someone might ask:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Why not always read the current product price?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Because historical data matters.&lt;/p&gt;

&lt;p&gt;Suppose:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Product today: $20
Product yesterday: $15
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A customer bought it yesterday.&lt;/p&gt;

&lt;p&gt;The order should still represent:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$15
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;not:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Current product price = $20
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a small modeling decision.&lt;/p&gt;

&lt;p&gt;But these are the kinds of decisions that separate durable software from fragile software.&lt;/p&gt;




&lt;h1&gt;
  
  
  Build the Smallest Correct Workflow
&lt;/h1&gt;

&lt;p&gt;Let's say we need checkout.&lt;/p&gt;

&lt;p&gt;Don't build:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Coupons
Gift cards
Subscriptions
Loyalty points
Multiple currencies
Installments
Wallets
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Start with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Cart
 ↓
Create Order
 ↓
Calculate Total
 ↓
Payment
 ↓
Mark Paid
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The workflow should be correct.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                 Checkout
                    │
                    ▼
              Validate Cart
                    │
                    ▼
              Create Order
                    │
                    ▼
             Calculate Total
                    │
                    ▼
              Process Payment
                    │
             ┌──────┴──────┐
             ▼             ▼
          Success        Failure
             │             │
             ▼             ▼
        Mark Paid       Mark Failed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is enough to learn.&lt;/p&gt;




&lt;h1&gt;
  
  
  Transactions Matter Early
&lt;/h1&gt;

&lt;p&gt;Imagine this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Create order
   ↓
Payment succeeds
   ↓
Server crashes
   ↓
Order isn't marked paid
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the external payment provider says:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PAID
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your database says:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PENDING
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You have created an inconsistency.&lt;/p&gt;

&lt;p&gt;You don't need microservices to encounter distributed systems problems.&lt;/p&gt;

&lt;p&gt;They arrive naturally.&lt;/p&gt;




&lt;h1&gt;
  
  
  Use Transactions Where They Make Sense
&lt;/h1&gt;

&lt;p&gt;For local database operations:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;

    &lt;span class="n"&gt;order&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;create_order&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;create_order_item&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="nf"&gt;update_order_total&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If something fails:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Operation
   ↓
Failure
   ↓
Rollback
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;instead of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Order created
Order item 1 created
Order item 2 created
Order item 3 failed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Partial state is one of the easiest ways to create early technical debt.&lt;/p&gt;




&lt;h1&gt;
  
  
  But Don't Pretend External APIs Are Transactional
&lt;/h1&gt;

&lt;p&gt;A payment provider isn't your database.&lt;/p&gt;

&lt;p&gt;This won't magically work:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;

    &lt;span class="n"&gt;order&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;create_order&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="n"&gt;payment_provider&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;charge&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="nf"&gt;mark_paid&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the payment succeeds and your transaction rolls back, the payment still happened.&lt;/p&gt;

&lt;p&gt;This is where idempotency and state machines become important.&lt;/p&gt;




&lt;h1&gt;
  
  
  Build Explicit State Machines
&lt;/h1&gt;

&lt;p&gt;Instead of random booleans:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;is_paid
is_cancelled
is_refunded
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;use a clear state:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PENDING
PAID
FAILED
CANCELLED
REFUNDED
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And define valid transitions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;              ┌─────────┐
              │ PENDING │
              └────┬────┘
             ┌─────┴─────┐
             ▼           ▼
           PAID        FAILED
             │
             ▼
          REFUNDED
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then implementation becomes explicit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;VALID_TRANSITIONS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;PENDING&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;PAID&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;FAILED&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;CANCELLED&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;PAID&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;REFUNDED&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;FAILED&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;CANCELLED&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;REFUNDED&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now your system has a model of reality.&lt;/p&gt;




&lt;h1&gt;
  
  
  Idempotency: One of the Cheapest High-Value Investments
&lt;/h1&gt;

&lt;p&gt;Imagine the user clicks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Pay
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The request reaches the server.&lt;/p&gt;

&lt;p&gt;The payment succeeds.&lt;/p&gt;

&lt;p&gt;The response gets lost.&lt;/p&gt;

&lt;p&gt;The client retries.&lt;/p&gt;

&lt;p&gt;Now you might charge them twice.&lt;/p&gt;

&lt;p&gt;This is why idempotency matters.&lt;/p&gt;

&lt;p&gt;A request can include:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;Idempotency-Key: 7b1a-92f4
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The backend stores the result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;7b1a-92f4
     ↓
Payment #9281
     ↓
SUCCESS
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the request arrives again:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Same key
   ↓
Existing result
   ↓
Return previous result
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No duplicate payment.&lt;/p&gt;

&lt;p&gt;This is not premature optimization.&lt;/p&gt;

&lt;p&gt;It's correctness.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Minimum Viable API
&lt;/h1&gt;

&lt;p&gt;Don't build 100 endpoints.&lt;/p&gt;

&lt;p&gt;Start with the smallest workflow.&lt;/p&gt;

&lt;p&gt;For a marketplace:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;POST /auth/register
POST /auth/login

GET /products
GET /products/:id

POST /orders
GET /orders/:id

POST /payments
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's enough to launch a surprisingly functional system.&lt;/p&gt;

&lt;p&gt;But each endpoint should have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Validation
Authentication
Authorization
Consistent errors
Logging
Tests
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  API Error Design
&lt;/h1&gt;

&lt;p&gt;Avoid this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Something went wrong"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Prefer structured errors:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"code"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"INVALID_ORDER"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Order contains no items"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"request_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"req_82a91"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the client can understand what happened.&lt;/p&gt;

&lt;p&gt;The request ID also helps debugging.&lt;/p&gt;




&lt;h1&gt;
  
  
  Implementation: Request IDs
&lt;/h1&gt;

&lt;p&gt;A simple middleware pattern:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;uuid&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;request_id_middleware&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;next_handler&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;

    &lt;span class="n"&gt;request_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;X-Request-ID&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;uuid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;uuid4&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;

    &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;next_handler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;X-Request-ID&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;request_id&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then logs can contain:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;request_id=req_82a91
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now one customer issue can be traced across the system.&lt;/p&gt;




&lt;h1&gt;
  
  
  Observability Is Not a Luxury
&lt;/h1&gt;

&lt;p&gt;You don't need a massive observability platform on day one.&lt;/p&gt;

&lt;p&gt;But you need to know:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;What happened?
When?
To whom?
Where?
Why?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At minimum:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Logs
Errors
Request IDs
Basic metrics
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A simple log:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;info&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;order_created&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;extra&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;order_id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;user_id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;request_id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;request_id&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you have a trail.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Minimum Viable Metrics
&lt;/h1&gt;

&lt;p&gt;I would start with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Requests
Errors
Latency
Active users
Successful transactions
Failed transactions
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's enough to answer many early questions.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Requests:       12,430
Errors:             83
Error rate:       0.67%
P95 latency:       420ms
Orders:             218
Payments failed:     11
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is far more useful than a dashboard containing 200 meaningless metrics.&lt;/p&gt;




&lt;h1&gt;
  
  
  Testing: Don't Test Everything
&lt;/h1&gt;

&lt;p&gt;Another misunderstanding of MVP development is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"We don't have time for tests."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You don't have time for &lt;strong&gt;the wrong tests&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;You don't need hundreds of tests for every CSS component.&lt;/p&gt;

&lt;p&gt;Test the business invariants.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;test_order_requires_items&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;pytest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;raises&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nf"&gt;create_order&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Test:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;test_negative_price_is_rejected&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;pytest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;raises&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nf"&gt;create_product&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Laptop&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;price_cents&lt;/span&gt;&lt;span class="o"&gt;=-&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Test state transitions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;test_paid_order_can_be_refunded&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;

    &lt;span class="n"&gt;order&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Order&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;PAID&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;REFUNDED&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;REFUNDED&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And invalid transitions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;test_pending_order_cannot_be_refunded&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;

    &lt;span class="n"&gt;order&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Order&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;PENDING&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;pytest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;raises&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;REFUNDED&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These tests protect the system's meaning.&lt;/p&gt;




&lt;h1&gt;
  
  
  Test the Expensive-to-Fix Things
&lt;/h1&gt;

&lt;p&gt;A useful rule:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Test behavior that would be expensive or embarrassing to break.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Examples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Authentication
Payments
Permissions
Data integrity
Orders
Billing
State transitions
Important calculations
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Don't obsess over achieving:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;100% code coverage
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;while missing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;100% correctness of money movement
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Coverage is a metric.&lt;/p&gt;

&lt;p&gt;Correctness is the goal.&lt;/p&gt;




&lt;h1&gt;
  
  
  Security Must Exist Before Users
&lt;/h1&gt;

&lt;p&gt;One of the worst MVP philosophies is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"We'll add security after we validate the idea."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Users don't care whether you're validating an idea.&lt;/p&gt;

&lt;p&gt;If their passwords are leaked, they're still leaked.&lt;/p&gt;

&lt;p&gt;The minimum system should include:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HTTPS
Password hashing
Authentication
Authorization
Input validation
Secure secrets
Database access controls
Rate limiting where necessary
Dependency updates
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You don't need a giant security department.&lt;/p&gt;

&lt;p&gt;You do need basic security hygiene.&lt;/p&gt;




&lt;h1&gt;
  
  
  Never Store Plaintext Passwords
&lt;/h1&gt;

&lt;p&gt;This should be non-negotiable.&lt;/p&gt;

&lt;p&gt;Don't:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;password&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use a password hashing algorithm through a reputable library.&lt;/p&gt;

&lt;p&gt;Conceptually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;password_hash&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;hash_password&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;verify_password&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;password_hash&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The database should never contain the original password.&lt;/p&gt;




&lt;h1&gt;
  
  
  Authorization Is Different From Authentication
&lt;/h1&gt;

&lt;p&gt;Authentication asks:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Who are you?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Authorization asks:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;What are you allowed to do?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User A
 ↓
GET /orders/123
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The system shouldn't simply check:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Is User A logged in?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It should check:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Does Order 123 belong to User A?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A simple rule:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;current_user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;Forbidden&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Many security vulnerabilities are simply authorization mistakes.&lt;/p&gt;




&lt;h1&gt;
  
  
  Don't Build Your Own Cryptography
&lt;/h1&gt;

&lt;p&gt;This is another place where "minimum viable" can become dangerous.&lt;/p&gt;

&lt;p&gt;Don't implement:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Your own password hashing
Your own encryption algorithm
Your own JWT implementation
Your own TLS
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use established libraries.&lt;/p&gt;

&lt;p&gt;Build your product.&lt;/p&gt;

&lt;p&gt;Not your own cryptographic primitive.&lt;/p&gt;




&lt;h1&gt;
  
  
  Deployment Is Part of the Product
&lt;/h1&gt;

&lt;p&gt;A system that works on your laptop isn't a product.&lt;/p&gt;

&lt;p&gt;This:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Works on my machine
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;is not deployment.&lt;/p&gt;

&lt;p&gt;A minimum viable system needs a repeatable path:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Git
 ↓
Build
 ↓
Test
 ↓
Deploy
 ↓
Health Check
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Even if you're the only developer.&lt;/p&gt;




&lt;h1&gt;
  
  
  A Minimal Deployment Pipeline
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                 Git Push
                    │
                    ▼
                  CI
                    │
          ┌─────────┴─────────┐
          ▼                   ▼
       Tests              Build
          │                   │
          └─────────┬─────────┘
                    ▼
                 Deploy
                    │
                    ▼
               Health Check
                    │
              ┌─────┴─────┐
              ▼           ▼
           Healthy      Failed
              │           │
              ▼           ▼
            Live       Rollback
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is enough.&lt;/p&gt;

&lt;p&gt;You don't need an elaborate platform team.&lt;/p&gt;




&lt;h1&gt;
  
  
  Health Checks
&lt;/h1&gt;

&lt;p&gt;A simple endpoint:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;GET /health
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Response:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ok"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But a deeper readiness check might verify:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Database
Redis
Critical dependencies
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ready"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"database"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ok"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This becomes extremely useful during deployments.&lt;/p&gt;




&lt;h1&gt;
  
  
  Feature Flags Are Extremely Powerful
&lt;/h1&gt;

&lt;p&gt;You don't always have to choose:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Build feature
OR
Don't build feature
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can build:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Feature
 ↓
Disabled
 ↓
Deploy
 ↓
Enable for developers
 ↓
Enable for 5%
 ↓
Enable for 50%
 ↓
Enable for everyone
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;feature_flags&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;enabled&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;new_checkout&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;user_id&lt;/span&gt;
&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;new_checkout&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;old_checkout&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now deployment and release become separate concepts.&lt;/p&gt;

&lt;p&gt;This gives you much more control.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Minimum Viable System Should Be Observable Before It Is Scaled
&lt;/h1&gt;

&lt;p&gt;This is a principle I strongly believe in.&lt;/p&gt;

&lt;p&gt;Don't scale something you can't understand.&lt;/p&gt;

&lt;p&gt;Suppose your application gets slow.&lt;/p&gt;

&lt;p&gt;If you have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;No logs
No metrics
No tracing
No profiling
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you don't know why.&lt;/p&gt;

&lt;p&gt;You start guessing.&lt;/p&gt;

&lt;p&gt;Then you add:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Redis
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It doesn't fix the problem.&lt;/p&gt;

&lt;p&gt;Then:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;More servers
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Still doesn't fix it.&lt;/p&gt;

&lt;p&gt;Then:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Database replica
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Still broken.&lt;/p&gt;

&lt;p&gt;You are scaling blind.&lt;/p&gt;




&lt;h1&gt;
  
  
  Measure Before Optimizing
&lt;/h1&gt;

&lt;p&gt;A simple workflow:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Problem
  ↓
Measure
  ↓
Identify bottleneck
  ↓
Change
  ↓
Measure again
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Not:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Problem
 ↓
Add technology
 ↓
Hope
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  The Database Is Often Your First Scaling Problem
&lt;/h1&gt;

&lt;p&gt;Suppose your query is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;user_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;
&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;created_at&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the table grows, indexing matters.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;INDEX&lt;/span&gt; &lt;span class="n"&gt;idx_orders_user_created&lt;/span&gt;
&lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;created_at&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is often more valuable than introducing another service.&lt;/p&gt;

&lt;p&gt;A good database design can eliminate entire categories of infrastructure complexity.&lt;/p&gt;




&lt;h1&gt;
  
  
  Don't Prematurely Cache Everything
&lt;/h1&gt;

&lt;p&gt;Caching is useful.&lt;/p&gt;

&lt;p&gt;But it introduces invalidation problems.&lt;/p&gt;

&lt;p&gt;Start with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Database
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Measure.&lt;/p&gt;

&lt;p&gt;If a query becomes expensive:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Optimize query
 ↓
Add index
 ↓
Measure
 ↓
Cache if necessary
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Not:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Everything → Redis
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  The Minimum Viable System Has a Debt Budget
&lt;/h1&gt;

&lt;p&gt;Technical debt isn't automatically bad.&lt;/p&gt;

&lt;p&gt;Sometimes debt is intentional.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;We use a simple email implementation now.
We'll build a notification service later.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's reasonable.&lt;/p&gt;

&lt;p&gt;But record the debt.&lt;/p&gt;

&lt;p&gt;Create a simple document:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TECHNICAL DEBT

1. Replace temporary email provider
2. Add stronger rate limiting
3. Refactor reporting query
4. Improve background job retries
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now debt is visible.&lt;/p&gt;

&lt;p&gt;Invisible debt is much more dangerous than documented debt.&lt;/p&gt;




&lt;h1&gt;
  
  
  Distinguish Good Debt From Bad Debt
&lt;/h1&gt;

&lt;h3&gt;
  
  
  Good debt
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Simple architecture
Temporary UI
Manual admin process
Limited feature set
Basic deployment
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These can be improved later.&lt;/p&gt;

&lt;h3&gt;
  
  
  Bad debt
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Security vulnerability
Corruptible data
Unclear ownership
No backups
No migration strategy
Duplicated business logic everywhere
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These become exponentially more expensive.&lt;/p&gt;




&lt;h1&gt;
  
  
  A Useful Equation
&lt;/h1&gt;

&lt;p&gt;I think about early software roughly like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Future Change Cost
≈
Complexity
×
Coupling
×
Uncertainty
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can't eliminate uncertainty.&lt;/p&gt;

&lt;p&gt;You're building something new.&lt;/p&gt;

&lt;p&gt;But you can reduce:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Complexity
Coupling
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's what good MVP architecture does.&lt;/p&gt;




&lt;h1&gt;
  
  
  Build for Change, Not for Scale
&lt;/h1&gt;

&lt;p&gt;This distinction is extremely important.&lt;/p&gt;

&lt;p&gt;Early products usually don't need:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;10 million requests/second
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;They need:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The ability to change direction quickly.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You might discover that users don't want feature A.&lt;/p&gt;

&lt;p&gt;They want feature B.&lt;/p&gt;

&lt;p&gt;If your architecture is easy to change:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;A → B
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;is manageable.&lt;/p&gt;

&lt;p&gt;If your architecture is tightly coupled:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;A
 ↓
Service 1
 ↓
Service 2
 ↓
Service 3
 ↓
Database
 ↓
Event bus
 ↓
Service 4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;changing A can become a project of its own.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Real Enemy Is Coupling
&lt;/h1&gt;

&lt;p&gt;Consider this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create_order&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="nf"&gt;send_email&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="nf"&gt;charge_payment&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="nf"&gt;update_inventory&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="nf"&gt;create_analytics_event&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="nf"&gt;notify_admin&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One function now knows everything.&lt;/p&gt;

&lt;p&gt;That's coupling.&lt;/p&gt;

&lt;p&gt;A cleaner approach:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create_order&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;order&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;order_service&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;events&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;publish&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nc"&gt;OrderCreated&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then other systems can react.&lt;/p&gt;

&lt;p&gt;Even inside a monolith, this creates cleaner boundaries.&lt;/p&gt;




&lt;h1&gt;
  
  
  But Don't Turn Everything Into Events
&lt;/h1&gt;

&lt;p&gt;Again, balance.&lt;/p&gt;

&lt;p&gt;This:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;create order
 ↓
event
 ↓
handler
 ↓
event
 ↓
handler
 ↓
event
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;can become difficult to reason about.&lt;/p&gt;

&lt;p&gt;Use events where asynchronous behavior genuinely helps.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;OrderCreated
 ↓
Send email
 ↓
Update analytics
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Those operations don't necessarily need to block checkout.&lt;/p&gt;

&lt;p&gt;But:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Calculate order total
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;should probably remain part of the immediate transaction.&lt;/p&gt;




&lt;h1&gt;
  
  
  Synchronous vs Asynchronous
&lt;/h1&gt;

&lt;p&gt;A useful early rule:&lt;/p&gt;

&lt;h3&gt;
  
  
  Synchronous
&lt;/h3&gt;

&lt;p&gt;Use when the user needs the result immediately.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Create order
Calculate total
Validate permissions
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Asynchronous
&lt;/h3&gt;

&lt;p&gt;Use when the work can happen later.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Send email
Generate report
Resize image
Process analytics
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This keeps the core workflow simple.&lt;/p&gt;




&lt;h1&gt;
  
  
  Background Jobs Without Overengineering
&lt;/h1&gt;

&lt;p&gt;You might start with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Application
 ↓
Database
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then introduce a simple queue when needed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Application
 ↓
Queue
 ↓
Worker
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;jobs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;enqueue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;send_order_confirmation&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The worker handles:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;send_order_confirmation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order_id&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;

    &lt;span class="n"&gt;order&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;get_order&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;template&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;order_confirmation&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the checkout request doesn't wait for email delivery.&lt;/p&gt;




&lt;h1&gt;
  
  
  Retry Carefully
&lt;/h1&gt;

&lt;p&gt;Background jobs can fail.&lt;/p&gt;

&lt;p&gt;Use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Attempt 1
 ↓
Failure
 ↓
Attempt 2
 ↓
Failure
 ↓
Attempt 3
 ↓
Dead Letter Queue
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But make the job idempotent.&lt;/p&gt;

&lt;p&gt;Otherwise:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Retry
 ↓
Duplicate action
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;can become a serious problem.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Minimum Viable Admin System
&lt;/h1&gt;

&lt;p&gt;This is something developers often overlook.&lt;/p&gt;

&lt;p&gt;You need a way to operate your own product.&lt;/p&gt;

&lt;p&gt;At minimum:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;View users
View orders
View errors
View important records
Disable problematic accounts
Retry failed jobs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You don't need a beautiful admin dashboard.&lt;/p&gt;

&lt;p&gt;A basic internal interface can save enormous amounts of time.&lt;/p&gt;




&lt;h1&gt;
  
  
  Build Manual Processes Before Automating Them
&lt;/h1&gt;

&lt;p&gt;Suppose you're unsure whether refunds should be automatic.&lt;/p&gt;

&lt;p&gt;Don't spend two weeks building refund automation.&lt;/p&gt;

&lt;p&gt;Start with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Customer requests refund
 ↓
Admin reviews
 ↓
Admin clicks refund
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you have enough volume:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Automated Refund
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The manual process teaches you the rules.&lt;/p&gt;

&lt;p&gt;This is one of the most powerful forms of product discovery.&lt;/p&gt;




&lt;h1&gt;
  
  
  Automation Should Follow Understanding
&lt;/h1&gt;

&lt;p&gt;The sequence should often be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Manual
 ↓
Understand
 ↓
Standardize
 ↓
Automate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Not:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Unknown Process
 ↓
Automate
 ↓
Discover Problems
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Automation amplifies understanding.&lt;/p&gt;

&lt;p&gt;It also amplifies confusion.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Minimum Viable System Is a Learning Machine
&lt;/h1&gt;

&lt;p&gt;This is the deeper idea.&lt;/p&gt;

&lt;p&gt;You're not merely building:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Product
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You're building:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Product
+
Feedback Loop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The system should teach you.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                    USERS
                      │
                      ▼
                   PRODUCT
                      │
             ┌────────┼────────┐
             ▼        ▼        ▼
          Metrics   Feedback   Errors
             │        │        │
             └────────┼────────┘
                      ▼
                  INSIGHTS
                      │
                      ▼
                    CHANGE
                      │
                      ▼
                   PRODUCT
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is why observability, analytics and customer feedback matter so much.&lt;/p&gt;

&lt;p&gt;They aren't side projects.&lt;/p&gt;

&lt;p&gt;They are part of the learning system.&lt;/p&gt;




&lt;h1&gt;
  
  
  What I Would Build in the First Two Weeks
&lt;/h1&gt;

&lt;p&gt;If I were building a new backend-heavy product, my initial system might look like this.&lt;/p&gt;

&lt;h2&gt;
  
  
  Day 1–2: Domain
&lt;/h2&gt;

&lt;p&gt;Define:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Users
Core entities
Relationships
Important states
Business rules
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Draw the data model.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User
 │
 ├── Orders
 │     │
 │     └── Items
 │
 └── Profile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Day 3–4: Database
&lt;/h2&gt;

&lt;p&gt;Implement:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Tables
Primary keys
Foreign keys
Constraints
Indexes
Migrations
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Don't obsess over optimization.&lt;/p&gt;

&lt;p&gt;Make the model correct.&lt;/p&gt;




&lt;h2&gt;
  
  
  Day 5–6: Core API
&lt;/h2&gt;

&lt;p&gt;Implement only:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Authentication
Core resource creation
Core resource retrieval
Primary workflow
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No 50-endpoint REST API.&lt;/p&gt;




&lt;h2&gt;
  
  
  Day 7: Tests
&lt;/h2&gt;

&lt;p&gt;Test:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Core business rules
Important failure cases
Authorization
Data invariants
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Day 8: Deployment
&lt;/h2&gt;

&lt;p&gt;Create:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CI
Production environment
Environment variables
Database migrations
Health check
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Day 9: Observability
&lt;/h2&gt;

&lt;p&gt;Add:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Structured logs
Request IDs
Error tracking
Basic metrics
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Day 10: Launch
&lt;/h2&gt;

&lt;p&gt;Give it to real users.&lt;/p&gt;

&lt;p&gt;Not after six months.&lt;/p&gt;

&lt;p&gt;Now.&lt;/p&gt;




&lt;h1&gt;
  
  
  Then Let Reality Drive Development
&lt;/h1&gt;

&lt;p&gt;After launch, don't immediately build 30 more features.&lt;/p&gt;

&lt;p&gt;Watch.&lt;/p&gt;

&lt;p&gt;Ask:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Where do users struggle?

What do they actually use?

Where do they abandon the workflow?

What breaks?

What do they request repeatedly?

What are they willing to pay for?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then build.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Product Roadmap Should Come From Evidence
&lt;/h1&gt;

&lt;p&gt;A bad roadmap:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;AI
Blockchain
Mobile app
Social feed
NFTs
Recommendations
Gamification
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A better roadmap:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Users cannot complete checkout
 ↓
Fix checkout

Users repeatedly search for invoices
 ↓
Add invoices

Customers ask for export
 ↓
Add CSV export
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The system tells you where to go.&lt;/p&gt;




&lt;h1&gt;
  
  
  Don't Confuse "Small" With "Cheap"
&lt;/h1&gt;

&lt;p&gt;A small system can still be high quality.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;One backend
One database
One frontend
One deployment
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;can be extremely well engineered.&lt;/p&gt;

&lt;p&gt;And:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;12 services
Kubernetes
Kafka
Redis
GraphQL
Service mesh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;can be terrible.&lt;/p&gt;

&lt;p&gt;Architecture quality is not proportional to architecture size.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Smallest Good System
&lt;/h1&gt;

&lt;p&gt;If I had to reduce the idea of a Minimum Viable System to one architecture, it would be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                 USERS
                   │
                   ▼
                FRONTEND
                   │
                   ▼
                API
                   │
          ┌────────┼────────┐
          ▼        ▼        ▼
       Domain    Auth     Validation
       Logic
          │
          ▼
       Database
          │
          ▼
        Migrations

Supporting:
    Logs
    Metrics
    Tests
    Backups
    CI/CD
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it.&lt;/p&gt;

&lt;p&gt;No Kubernetes.&lt;/p&gt;

&lt;p&gt;No microservices.&lt;/p&gt;

&lt;p&gt;No event streaming platform.&lt;/p&gt;

&lt;p&gt;No AI agent swarm.&lt;/p&gt;

&lt;p&gt;No infrastructure theater.&lt;/p&gt;

&lt;p&gt;Just a coherent system.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Minimum Viable System Checklist
&lt;/h1&gt;

&lt;p&gt;Before launching, I would ask:&lt;/p&gt;

&lt;h2&gt;
  
  
  Product
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[ ] Is the core user problem clear?
[ ] Can a user complete the main workflow?
[ ] Is there a measurable outcome?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Data
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[ ] Are relationships modeled correctly?
[ ] Are important constraints enforced?
[ ] Are migrations versioned?
[ ] Are backups configured?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Backend
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[ ] Are APIs validated?
[ ] Are errors structured?
[ ] Are permissions enforced?
[ ] Are important operations transactional?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Security
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[ ] Are passwords hashed?
[ ] Is HTTPS enabled?
[ ] Are secrets outside source control?
[ ] Is authorization checked?
[ ] Are dangerous inputs validated?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Reliability
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[ ] Are errors logged?
[ ] Are request IDs available?
[ ] Is there a health endpoint?
[ ] Can failed jobs be retried?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Deployment
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[ ] Can the system be deployed repeatably?
[ ] Can database migrations run safely?
[ ] Is rollback possible?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Product Learning
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[ ] Can we measure usage?
[ ] Can users give feedback?
[ ] Can we identify failures?
[ ] Can we understand why users leave?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If these answers are mostly yes, you probably have something much more valuable than a typical MVP.&lt;/p&gt;

&lt;p&gt;You have a Minimum Viable System.&lt;/p&gt;




&lt;h1&gt;
  
  
  What I Would Not Build
&lt;/h1&gt;

&lt;p&gt;At the beginning, I would probably avoid:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Microservices
Kubernetes
Custom authentication protocol
Custom payment infrastructure
Complex event-driven architecture
Premature caching
Multi-region deployment
Multiple databases
Distributed tracing infrastructure
AI agents
Complex recommendation engines
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Unless the actual problem requires them.&lt;/p&gt;

&lt;p&gt;Not because these technologies are bad.&lt;/p&gt;

&lt;p&gt;They're excellent technologies.&lt;/p&gt;

&lt;p&gt;But technology should answer a problem.&lt;/p&gt;

&lt;p&gt;It shouldn't become the problem.&lt;/p&gt;




&lt;h1&gt;
  
  
  The "Future Scale" Test
&lt;/h1&gt;

&lt;p&gt;Before adding infrastructure, ask three questions:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. What problem am I solving?
&lt;/h3&gt;

&lt;p&gt;Not:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Would Redis be cool?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Which measured bottleneck requires Redis?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  2. Do I actually have the problem?
&lt;/h3&gt;

&lt;p&gt;Not:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"What if we have millions of users?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Do our current measurements indicate that the database is the bottleneck?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  3. What's the simplest solution?
&lt;/h3&gt;

&lt;p&gt;Maybe the answer is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Add an index.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Not:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Create another distributed service.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This discipline can save months.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Most Valuable Feature Is Sometimes "Nothing"
&lt;/h1&gt;

&lt;p&gt;This is something I learned to appreciate more with experience.&lt;/p&gt;

&lt;p&gt;A developer sees an empty space in the product and thinks:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"We should build something here."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But sometimes the best decision is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Don't build it.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every feature adds:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Code
Tests
Documentation
UI
Data
Support
Security
Maintenance
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The cost isn't just development.&lt;/p&gt;

&lt;p&gt;It's permanent ownership.&lt;/p&gt;




&lt;h1&gt;
  
  
  Every Feature Becomes a Contract
&lt;/h1&gt;

&lt;p&gt;Once users depend on something, removing it becomes difficult.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Feature
 ↓
Users depend on it
 ↓
Data accumulates
 ↓
Documentation exists
 ↓
Integrations appear
 ↓
Support depends on it
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the feature is part of the system.&lt;/p&gt;

&lt;p&gt;This is why early product development should be ruthless about scope.&lt;/p&gt;

&lt;p&gt;You're not just choosing what to build.&lt;/p&gt;

&lt;p&gt;You're choosing what you will have to maintain.&lt;/p&gt;




&lt;h1&gt;
  
  
  Software Is a Long-Term Commitment
&lt;/h1&gt;

&lt;p&gt;Writing code is easy compared with maintaining code.&lt;/p&gt;

&lt;p&gt;A hundred lines today might become:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;100 lines
 ↓
500 lines
 ↓
3 developers
 ↓
10 integrations
 ↓
100 customers
 ↓
Production dependency
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is why I care about the first architecture.&lt;/p&gt;

&lt;p&gt;Not because it needs to be perfect.&lt;/p&gt;

&lt;p&gt;But because it establishes the direction.&lt;/p&gt;




&lt;h1&gt;
  
  
  The First Version Is a Seed
&lt;/h1&gt;

&lt;p&gt;I like thinking about software like a seed.&lt;/p&gt;

&lt;p&gt;You don't need to build the entire tree.&lt;/p&gt;

&lt;p&gt;But you shouldn't plant something that is fundamentally malformed.&lt;/p&gt;

&lt;p&gt;A good seed has:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Clear structure
Healthy boundaries
Correct foundations
Room to grow
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first version of your product should work the same way.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;               VERSION 1
                   │
          ┌────────┼────────┐
          ▼        ▼        ▼
       Users      Data     Logic
          │        │        │
          └────────┼────────┘
                   ▼
                Feedback
                   │
                   ▼
               VERSION 2
                   │
                   ▼
               VERSION 3
                   │
                   ▼
              REAL SYSTEM
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You don't know what version 10 will look like.&lt;/p&gt;

&lt;p&gt;That's okay.&lt;/p&gt;

&lt;p&gt;Your job is to make version 1 good enough to discover version 2.&lt;/p&gt;




&lt;h1&gt;
  
  
  Shipping Early Is About Managing Uncertainty
&lt;/h1&gt;

&lt;p&gt;This is the part of MVP thinking that I think gets lost.&lt;/p&gt;

&lt;p&gt;You're not shipping early because you don't care about quality.&lt;/p&gt;

&lt;p&gt;You're shipping early because you don't yet know enough to justify building everything.&lt;/p&gt;

&lt;p&gt;That's a completely different philosophy.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;High uncertainty
      +
Small system
      ↓
Fast feedback
      ↓
More knowledge
      ↓
Better architecture
      ↓
Better product
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The mistake is thinking:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;High uncertainty
      +
Huge system
      ↓
Success
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Usually you just get an expensive guess.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Best Early Architecture Is a Feedback Architecture
&lt;/h1&gt;

&lt;p&gt;This is ultimately what I mean by Minimum Viable System.&lt;/p&gt;

&lt;p&gt;Build enough to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Create value
Collect data
Observe behavior
Protect users
Change quickly
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Everything else can wait.&lt;/p&gt;

&lt;p&gt;Your architecture should make the feedback loop fast.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                  IDEA
                   │
                   ▼
                BUILD
                   │
                   ▼
                SHIP
                   │
                   ▼
                USERS
                   │
                   ▼
                MEASURE
                   │
                   ▼
                LEARN
                   │
                   ▼
                CHANGE
                   │
                   └───────────────► BUILD
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's the real engine of an early-stage product.&lt;/p&gt;




&lt;h1&gt;
  
  
  Final Thoughts
&lt;/h1&gt;

&lt;p&gt;I no longer think the goal of early software development should be to build an MVP.&lt;/p&gt;

&lt;p&gt;The phrase has become too easy to misunderstand.&lt;/p&gt;

&lt;p&gt;The goal should be to build a &lt;strong&gt;Minimum Viable System&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;A system that is small enough to build quickly.&lt;/p&gt;

&lt;p&gt;Simple enough to understand.&lt;/p&gt;

&lt;p&gt;Reliable enough to trust.&lt;/p&gt;

&lt;p&gt;Secure enough to expose to users.&lt;/p&gt;

&lt;p&gt;Observable enough to debug.&lt;/p&gt;

&lt;p&gt;Flexible enough to change.&lt;/p&gt;

&lt;p&gt;And incomplete enough to leave room for discovery.&lt;/p&gt;

&lt;p&gt;The philosophy is simple:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Reduce Scope
     ↓
Keep Foundations
     ↓
Ship
     ↓
Observe
     ↓
Learn
     ↓
Improve
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Don't remove engineering just because the product is young.&lt;/p&gt;

&lt;p&gt;Remove unnecessary product complexity.&lt;/p&gt;

&lt;p&gt;Don't build for imaginary millions of users.&lt;/p&gt;

&lt;p&gt;Build for the users you actually have.&lt;/p&gt;

&lt;p&gt;Don't build ten services because you might need them someday.&lt;/p&gt;

&lt;p&gt;Build one good system with boundaries.&lt;/p&gt;

&lt;p&gt;Don't automate processes you don't understand.&lt;/p&gt;

&lt;p&gt;Do them manually until the pattern becomes obvious.&lt;/p&gt;

&lt;p&gt;Don't test every line of code.&lt;/p&gt;

&lt;p&gt;Test the rules that define whether your product is correct.&lt;/p&gt;

&lt;p&gt;Don't optimize everything.&lt;/p&gt;

&lt;p&gt;Measure first.&lt;/p&gt;

&lt;p&gt;Don't aim for perfect architecture.&lt;/p&gt;

&lt;p&gt;Aim for architecture that can evolve.&lt;/p&gt;

&lt;p&gt;And most importantly:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Don't confuse shipping early with shipping carelessly.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A Minimum Viable System is not an excuse for bad engineering.&lt;/p&gt;

&lt;p&gt;It is a strategy for &lt;strong&gt;focused engineering&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;You are deliberately saying:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"We don't know everything yet, so we won't build everything yet."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But you're also saying:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"The things we do build will have foundations strong enough to survive what we learn."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That is the balance.&lt;/p&gt;

&lt;p&gt;Because the real goal of version one isn't to prove that you can write software.&lt;/p&gt;

&lt;p&gt;It's to create enough reality that the software can teach you what to build next.&lt;/p&gt;

&lt;p&gt;And that's the difference between a prototype that gets thrown away...&lt;/p&gt;

&lt;p&gt;and a small system that eventually becomes a real product.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>softwaredevelopment</category>
      <category>api</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>5 Emerging Tech Trends Quietly Reshaping the Enterprise</title>
      <dc:creator>Derek mwale</dc:creator>
      <pubDate>Fri, 07 Aug 2026 05:49:00 +0000</pubDate>
      <link>https://dev.to/derekmwale/5-emerging-tech-trends-quietly-reshaping-the-enterprise-2jep</link>
      <guid>https://dev.to/derekmwale/5-emerging-tech-trends-quietly-reshaping-the-enterprise-2jep</guid>
      <description>&lt;p&gt;Technology doesn't always change the enterprise with a dramatic announcement.&lt;/p&gt;

&lt;p&gt;Sometimes the biggest transformation happens quietly.&lt;/p&gt;

&lt;p&gt;A few engineers start experimenting with something.&lt;/p&gt;

&lt;p&gt;A small team deploys it internally.&lt;/p&gt;

&lt;p&gt;A developer builds a prototype over a weekend.&lt;/p&gt;

&lt;p&gt;A security team begins writing policies around it.&lt;/p&gt;

&lt;p&gt;Then suddenly, three years later, the architecture of the company looks completely different.&lt;/p&gt;

&lt;p&gt;I think we are entering one of those periods.&lt;/p&gt;

&lt;p&gt;The obvious story is artificial intelligence.&lt;/p&gt;

&lt;p&gt;But "AI" is too broad to describe what is actually happening.&lt;/p&gt;

&lt;p&gt;The deeper transformation is architectural.&lt;/p&gt;

&lt;p&gt;AI is moving from chat interfaces into workflows.&lt;/p&gt;

&lt;p&gt;Software is becoming increasingly autonomous.&lt;/p&gt;

&lt;p&gt;Compute is moving closer to where data is generated.&lt;/p&gt;

&lt;p&gt;Sensitive workloads are being redesigned around new trust models.&lt;/p&gt;

&lt;p&gt;Enterprise infrastructure is being rebuilt around AI-native applications rather than traditional web applications.&lt;/p&gt;

&lt;p&gt;And physical machines are beginning to inherit capabilities that previously existed only in software.&lt;/p&gt;

&lt;p&gt;Several major technology research organizations are pointing toward the same general direction. Gartner's 2026 technology trends include multiagent systems, domain-specific language models, physical AI, confidential computing, AI-native development platforms and AI security platforms. Deloitte similarly describes a shift toward agentic workforces, physical AI, new AI infrastructure and security architectures.&lt;/p&gt;

&lt;p&gt;What interests me isn't the hype.&lt;/p&gt;

&lt;p&gt;It's the engineering underneath it.&lt;/p&gt;

&lt;p&gt;Because the enterprise of the future isn't simply going to have "more AI."&lt;/p&gt;

&lt;p&gt;It is going to have a fundamentally different architecture.&lt;/p&gt;

&lt;p&gt;In this article, I'll explore five technologies that I believe are quietly pushing enterprise software in that direction:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Agentic AI and autonomous software&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;AI-native infrastructure and the new compute stack&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Confidential computing and trust-by-design&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Edge AI and physical intelligence&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Domain-specific AI and smaller intelligent systems&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The important part is not merely understanding what these technologies are.&lt;/p&gt;

&lt;p&gt;It's understanding what they do to the way we build software.&lt;/p&gt;




&lt;h1&gt;
  
  
  1. Agentic AI: Software That Doesn't Just Respond
&lt;/h1&gt;

&lt;p&gt;For decades, enterprise software followed a relatively predictable pattern.&lt;/p&gt;

&lt;p&gt;A human performs an action.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User
  ↓
Application
  ↓
Database
  ↓
Response
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A user opens an application.&lt;/p&gt;

&lt;p&gt;They click a button.&lt;/p&gt;

&lt;p&gt;The application executes a predetermined operation.&lt;/p&gt;

&lt;p&gt;The database changes.&lt;/p&gt;

&lt;p&gt;The result appears.&lt;/p&gt;

&lt;p&gt;This architecture has powered everything from banking systems to ERP platforms.&lt;/p&gt;

&lt;p&gt;But AI agents introduce something different.&lt;/p&gt;

&lt;p&gt;Instead of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Human → Software → Result
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;we can increasingly build:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Human
  ↓
AI Agent
  ↓
Reason
  ↓
Plan
  ↓
Tools
  ↓
Systems
  ↓
Actions
  ↓
Result
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The software isn't simply responding.&lt;/p&gt;

&lt;p&gt;It is deciding which operations need to happen.&lt;/p&gt;

&lt;p&gt;That is a major architectural shift.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Difference Between a Chatbot and an Agent
&lt;/h1&gt;

&lt;p&gt;Consider a customer asking:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"Why hasn't my order arrived?"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A chatbot might answer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"Your order is currently in transit."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An agent could potentially:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Identify the customer.&lt;/li&gt;
&lt;li&gt;Query the order database.&lt;/li&gt;
&lt;li&gt;Retrieve the shipping record.&lt;/li&gt;
&lt;li&gt;Query the logistics provider.&lt;/li&gt;
&lt;li&gt;Determine whether the package is delayed.&lt;/li&gt;
&lt;li&gt;Check company policy.&lt;/li&gt;
&lt;li&gt;Create a support ticket.&lt;/li&gt;
&lt;li&gt;Notify the customer.&lt;/li&gt;
&lt;li&gt;Escalate the issue if necessary.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The difference is not intelligence alone.&lt;/p&gt;

&lt;p&gt;It is &lt;strong&gt;agency&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The agent has access to tools.&lt;/p&gt;




&lt;h1&gt;
  
  
  A Simple Agent Architecture
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                    User Request
                         │
                         ▼
                  ┌─────────────┐
                  │ AI Agent    │
                  │             │
                  │ Reason      │
                  │ Plan        │
                  │ Decide      │
                  └──────┬──────┘
                         │
             ┌───────────┼───────────┐
             ▼           ▼           ▼
          Database      API        Search
             │           │           │
             └───────────┼───────────┘
                         ▼
                       Action
                         │
                         ▼
                       Result
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This looks simple.&lt;/p&gt;

&lt;p&gt;It isn't.&lt;/p&gt;

&lt;p&gt;The moment an AI system can take actions, we have to answer questions traditional software didn't have to answer in quite the same way.&lt;/p&gt;




&lt;h1&gt;
  
  
  What Is the Agent Allowed to Do?
&lt;/h1&gt;

&lt;p&gt;Imagine an AI employee with access to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Customer database
Payment system
Email
CRM
Internal documents
Cloud infrastructure
Source code
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the model makes a mistake, the consequences aren't just a bad sentence.&lt;/p&gt;

&lt;p&gt;It could:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Delete data
Send an email
Approve a payment
Modify infrastructure
Expose private information
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is why agentic AI creates a new security problem.&lt;/p&gt;

&lt;p&gt;Recent enterprise security activity reflects this concern. Reuters reported in August 2026 that Obsidian Security raised funding at a $1.1 billion valuation amid demand for security around AI agents accessing sensitive enterprise data; the company said nearly 70% of its clients allowed AI agents to interact with business data.&lt;/p&gt;

&lt;p&gt;The interesting thing isn't the funding.&lt;/p&gt;

&lt;p&gt;It's the architectural implication.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AI agents need permissions.&lt;/strong&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  Building a Permissioned Agent
&lt;/h1&gt;

&lt;p&gt;Instead of giving an agent unrestricted access:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;agent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Agent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;database&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;admin&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;full&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;payments&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;full&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;we should define capabilities.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;permissions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;read_orders&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;read_customer&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;send_support_email&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;refund_payment&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;delete_customer&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then tools become controlled interfaces.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get_order&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order_id&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;permissions&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;read_orders&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;PermissionError&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;database&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_order&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This resembles traditional security engineering.&lt;/p&gt;

&lt;p&gt;The difference is that the caller is now probabilistic.&lt;/p&gt;

&lt;p&gt;That makes least privilege even more important.&lt;/p&gt;




&lt;h1&gt;
  
  
  Agents Need Deterministic Boundaries
&lt;/h1&gt;

&lt;p&gt;I wouldn't want an AI agent deciding everything.&lt;/p&gt;

&lt;p&gt;I'd give it deterministic boundaries.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                    AI
                     │
              "I want to refund"
                     │
                     ▼
              Policy Engine
                     │
           ┌─────────┴─────────┐
           ▼                   ▼
       Allowed               Denied
           │
           ▼
        Payment API
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The model proposes.&lt;/p&gt;

&lt;p&gt;The policy system decides.&lt;/p&gt;

&lt;p&gt;This separation is going to become extremely important.&lt;/p&gt;




&lt;h1&gt;
  
  
  Agentic Systems Will Change Backend Architecture
&lt;/h1&gt;

&lt;p&gt;Traditional backend:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HTTP Request
      ↓
Controller
      ↓
Service
      ↓
Database
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Agentic backend:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User
 ↓
Agent
 ↓
Planner
 ↓
Tool Selection
 ↓
Policy Engine
 ↓
Services
 ↓
External APIs
 ↓
Verification
 ↓
Response
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we need new infrastructure for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tool registries&lt;/li&gt;
&lt;li&gt;Agent identity&lt;/li&gt;
&lt;li&gt;Permissions&lt;/li&gt;
&lt;li&gt;Execution traces&lt;/li&gt;
&lt;li&gt;Memory&lt;/li&gt;
&lt;li&gt;Policy enforcement&lt;/li&gt;
&lt;li&gt;Human approval&lt;/li&gt;
&lt;li&gt;Audit logs&lt;/li&gt;
&lt;li&gt;Cost tracking&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In other words:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The enterprise backend is acquiring an operating system for AI workers.&lt;/strong&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  The Hidden Problem: Token Economics
&lt;/h1&gt;

&lt;p&gt;There is another problem people don't talk about enough.&lt;/p&gt;

&lt;p&gt;Agents can become expensive.&lt;/p&gt;

&lt;p&gt;An ordinary API request might require:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 request
1 database query
1 response
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An agent might perform:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Request
 ↓
Reason
 ↓
Tool selection
 ↓
Tool call
 ↓
Observe result
 ↓
Reason again
 ↓
Another tool
 ↓
Reason again
 ↓
Final response
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each reasoning cycle can consume model inference.&lt;/p&gt;

&lt;p&gt;Recent analysis has highlighted this emerging "token tax": agentic systems can consume large numbers of tokens internally for planning, tool selection and iterative reasoning even when the user-facing output is short.&lt;/p&gt;

&lt;p&gt;So enterprises will increasingly optimize:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;AI Quality
+
Latency
+
Token Usage
+
Tool Calls
+
Infrastructure Cost
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a new kind of systems engineering.&lt;/p&gt;




&lt;h1&gt;
  
  
  2. AI-Native Infrastructure: The Computer Is Changing Again
&lt;/h1&gt;

&lt;p&gt;The second quiet transformation is happening below the application layer.&lt;/p&gt;

&lt;p&gt;AI has changed what we expect infrastructure to do.&lt;/p&gt;

&lt;p&gt;Traditional cloud applications were mostly CPU-oriented.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Application
    ↓
CPU
    ↓
Memory
    ↓
Storage
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Modern AI systems increasingly require:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Application
    ↓
Model
    ↓
GPU / Accelerator
    ↓
High-Speed Memory
    ↓
High-Speed Network
    ↓
Storage
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This changes the economics and architecture of enterprise computing.&lt;/p&gt;

&lt;p&gt;Gartner identifies AI supercomputing platforms and AI-native development platforms among its major 2026 strategic trends.&lt;/p&gt;




&lt;h1&gt;
  
  
  The New Enterprise Compute Stack
&lt;/h1&gt;

&lt;p&gt;A simplified AI infrastructure stack looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;┌──────────────────────────────┐
│ Enterprise Applications      │
├──────────────────────────────┤
│ AI Agents / Models           │
├──────────────────────────────┤
│ Inference Runtime            │
├──────────────────────────────┤
│ GPU / AI Accelerators        │
├──────────────────────────────┤
│ High-Speed Networking        │
├──────────────────────────────┤
│ Storage                      │
├──────────────────────────────┤
│ Compute / Virtualization     │
└──────────────────────────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important shift is that AI is becoming an infrastructure concern.&lt;/p&gt;

&lt;p&gt;It isn't just an application feature.&lt;/p&gt;




&lt;h1&gt;
  
  
  Why This Matters to Software Engineers
&lt;/h1&gt;

&lt;p&gt;Imagine you're building an application that processes millions of documents.&lt;/p&gt;

&lt;p&gt;A traditional architecture might look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;API
 ↓
CPU workers
 ↓
Database
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An AI architecture might look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;API
 ↓
Queue
 ↓
GPU Workers
 ↓
Model Inference
 ↓
Vector Database
 ↓
Results
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now your architecture needs to understand:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;GPU utilization&lt;/li&gt;
&lt;li&gt;Model loading&lt;/li&gt;
&lt;li&gt;Batch inference&lt;/li&gt;
&lt;li&gt;Memory bandwidth&lt;/li&gt;
&lt;li&gt;Quantization&lt;/li&gt;
&lt;li&gt;Model caching&lt;/li&gt;
&lt;li&gt;Inference latency&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is a very different world.&lt;/p&gt;




&lt;h1&gt;
  
  
  AI-Native Development
&lt;/h1&gt;

&lt;p&gt;There is also a change happening in how software itself is produced.&lt;/p&gt;

&lt;p&gt;AI-native development isn't simply:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Developer + Copilot
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It increasingly looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Developer
   ↓
AI coding system
   ↓
Planning
   ↓
Code generation
   ↓
Tests
   ↓
Static analysis
   ↓
Review
   ↓
Deployment
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The developer increasingly becomes an architect and verifier.&lt;/p&gt;

&lt;p&gt;The machine generates more of the implementation.&lt;/p&gt;




&lt;h1&gt;
  
  
  A Simple AI Development Pipeline
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                  Requirement
                       │
                       ▼
                 AI Planner
                       │
                       ▼
                 Code Generator
                       │
                       ▼
                    Tests
                       │
                       ▼
                Static Analysis
                       │
                       ▼
                 Human Review
                       │
                       ▼
                   Deployment
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This changes what "productivity" means.&lt;/p&gt;

&lt;p&gt;The bottleneck may move from writing code to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Architecture
Specification
Testing
Verification
Security
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's why I think strong software engineering fundamentals become more valuable, not less.&lt;/p&gt;




&lt;h1&gt;
  
  
  AI Doesn't Remove Architecture
&lt;/h1&gt;

&lt;p&gt;If anything, it makes architecture more important.&lt;/p&gt;

&lt;p&gt;AI can generate:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create_user&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="bp"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But it doesn't automatically know:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Whether the API should be synchronous.&lt;/li&gt;
&lt;li&gt;Whether the database needs transactions.&lt;/li&gt;
&lt;li&gt;Whether the operation should be idempotent.&lt;/li&gt;
&lt;li&gt;Whether a queue is required.&lt;/li&gt;
&lt;li&gt;Whether the endpoint should be public.&lt;/li&gt;
&lt;li&gt;Whether the data is sensitive.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The hard part of engineering has never been typing.&lt;/p&gt;

&lt;p&gt;It has been deciding what should exist.&lt;/p&gt;




&lt;h1&gt;
  
  
  3. Confidential Computing: Trusting the Machine Less
&lt;/h1&gt;

&lt;p&gt;This is one of the technologies I find particularly interesting.&lt;/p&gt;

&lt;p&gt;For decades, security focused heavily on:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Data at rest
Data in transit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We encrypt databases.&lt;/p&gt;

&lt;p&gt;We use TLS.&lt;/p&gt;

&lt;p&gt;We encrypt backups.&lt;/p&gt;

&lt;p&gt;But what happens while data is being processed?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Encrypted Data
     ↓
Application
     ↓
CPU Memory
     ↓
Processing
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At some point, the data has to become usable.&lt;/p&gt;

&lt;p&gt;Confidential computing attempts to protect workloads and data while they are in use using hardware-backed trusted execution environments.&lt;/p&gt;

&lt;p&gt;The Confidential Computing Consortium describes trusted execution environments as a way to isolate memory so that even privileged infrastructure layers such as the host OS or hypervisor can be outside the trust boundary.&lt;/p&gt;

&lt;p&gt;This becomes particularly interesting for AI.&lt;/p&gt;




&lt;h1&gt;
  
  
  Why AI Makes Confidential Computing More Important
&lt;/h1&gt;

&lt;p&gt;Imagine a hospital wants to use an AI model on sensitive medical data.&lt;/p&gt;

&lt;p&gt;Traditional architecture:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hospital Data
      ↓
Cloud
      ↓
AI Model
      ↓
Results
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The organization has to trust the infrastructure handling that data.&lt;/p&gt;

&lt;p&gt;With confidential computing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;             Cloud Infrastructure
                     │
          ┌──────────┴──────────┐
          │ Trusted Environment │
          │                     │
          │ Data                │
          │ Model               │
          │ Computation         │
          └─────────────────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The goal is to reduce the amount of infrastructure that must be trusted.&lt;/p&gt;




&lt;h1&gt;
  
  
  Attestation
&lt;/h1&gt;

&lt;p&gt;One of the powerful ideas here is remote attestation.&lt;/p&gt;

&lt;p&gt;Instead of simply saying:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Trust me, I'm running the correct software."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;a system can provide cryptographic evidence about the environment it is running in.&lt;/p&gt;

&lt;p&gt;Conceptually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Workload
   ↓
Trusted Environment
   ↓
Measurement
   ↓
Cryptographic Attestation
   ↓
Verifier
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then a service can make decisions based on the attested environment.&lt;/p&gt;

&lt;p&gt;This is a fundamentally different trust model.&lt;/p&gt;




&lt;h1&gt;
  
  
  A Simple Conceptual Attestation Flow
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;authorize_workload&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;attestation&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="nf"&gt;verify_signature&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;attestation&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;attestation&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;measurement&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt;
       &lt;span class="n"&gt;APPROVED_MEASUREMENTS&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Obviously, production attestation is much more complex.&lt;/p&gt;

&lt;p&gt;But the principle is simple:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Don't trust the environment merely because it says it is trustworthy. Verify it.&lt;/strong&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  Confidential Computing + AI Agents
&lt;/h1&gt;

&lt;p&gt;Now combine the first trend with the third.&lt;/p&gt;

&lt;p&gt;An AI agent can:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Read sensitive data
Reason over it
Call tools
Make decisions
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates a massive trust problem.&lt;/p&gt;

&lt;p&gt;Confidential computing can become part of the security architecture:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                 AI Agent
                    │
                    ▼
             Policy Layer
                    │
                    ▼
           Confidential Runtime
                    │
          ┌─────────┴─────────┐
          ▼                   ▼
       Secrets              Data
          │                   │
          └─────────┬─────────┘
                    ▼
                Model
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This doesn't magically make AI secure.&lt;/p&gt;

&lt;p&gt;But it can strengthen the hardware foundation beneath the system.&lt;/p&gt;

&lt;p&gt;Research in 2026 has specifically explored confidential computing as a security substrate for agentic AI because autonomous agents can hold credentials, process sensitive context and interact with multiple systems.&lt;/p&gt;




&lt;h1&gt;
  
  
  4. Edge AI: Intelligence Is Moving Toward the Data
&lt;/h1&gt;

&lt;p&gt;The cloud centralized computing.&lt;/p&gt;

&lt;p&gt;The edge is decentralizing it again.&lt;/p&gt;

&lt;p&gt;For many years, the architecture looked like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Device
  ↓
Internet
  ↓
Cloud
  ↓
Compute
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But latency-sensitive applications increasingly look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Device
  ↓
Edge Compute
  ↓
Cloud
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is especially important for AI.&lt;/p&gt;




&lt;h1&gt;
  
  
  Why Send Everything to the Cloud?
&lt;/h1&gt;

&lt;p&gt;Imagine a factory camera generating:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;30 frames / second
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Across:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;500 cameras
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's an enormous amount of data.&lt;/p&gt;

&lt;p&gt;Sending every raw frame to a distant cloud isn't necessarily efficient.&lt;/p&gt;

&lt;p&gt;Instead:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Camera
 ↓
Edge AI
 ↓
"Anomaly detected"
 ↓
Cloud
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The edge device processes the raw information.&lt;/p&gt;

&lt;p&gt;The cloud receives the important event.&lt;/p&gt;




&lt;h1&gt;
  
  
  Edge Architecture
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;              CLOUD
                │
        Global Coordination
                │
       ┌────────┼────────┐
       │        │        │
       ▼        ▼        ▼
     Edge A   Edge B   Edge C
       │        │        │
      IoT      IoT      IoT
    Devices   Devices   Devices
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This changes the architecture of enterprise software.&lt;/p&gt;

&lt;p&gt;Instead of one centralized application, we get a distributed computing continuum.&lt;/p&gt;




&lt;h1&gt;
  
  
  Edge AI Implementation
&lt;/h1&gt;

&lt;p&gt;Suppose we have a camera and an object-detection model.&lt;/p&gt;

&lt;p&gt;Conceptually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

    &lt;span class="n"&gt;frame&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;camera&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="n"&gt;prediction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;predict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;frame&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;prediction&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;confidence&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mf"&gt;0.9&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

        &lt;span class="nf"&gt;send_event&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;type&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;anomaly&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;confidence&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;prediction&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;confidence&lt;/span&gt;
        &lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important design choice is:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The raw frame doesn't necessarily need to leave the edge device.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Only the useful information does.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Benefits
&lt;/h1&gt;

&lt;p&gt;Edge AI can provide:&lt;/p&gt;

&lt;h3&gt;
  
  
  Lower latency
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Device → Edge
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;is usually faster than:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Device → Internet → Cloud
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Lower bandwidth
&lt;/h3&gt;

&lt;p&gt;Send:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"Anomaly detected"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;instead of thousands of images.&lt;/p&gt;

&lt;h3&gt;
  
  
  Better resilience
&lt;/h3&gt;

&lt;p&gt;The edge system can continue operating even when cloud connectivity disappears.&lt;/p&gt;

&lt;h3&gt;
  
  
  Privacy
&lt;/h3&gt;

&lt;p&gt;Sensitive data can sometimes remain local.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Problem With Edge
&lt;/h1&gt;

&lt;p&gt;Edge computing creates a new operational nightmare.&lt;/p&gt;

&lt;p&gt;Instead of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;10 servers
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you might have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;10,000 edge devices
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Remote updates&lt;/li&gt;
&lt;li&gt;Device identity&lt;/li&gt;
&lt;li&gt;Monitoring&lt;/li&gt;
&lt;li&gt;Secure boot&lt;/li&gt;
&lt;li&gt;Model deployment&lt;/li&gt;
&lt;li&gt;Hardware health monitoring&lt;/li&gt;
&lt;li&gt;Offline operation&lt;/li&gt;
&lt;li&gt;Configuration management&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is why edge computing isn't simply "put AI on a Raspberry Pi."&lt;/p&gt;

&lt;p&gt;It's distributed systems at physical scale.&lt;/p&gt;




&lt;h1&gt;
  
  
  Edge Model Deployment
&lt;/h1&gt;

&lt;p&gt;A simple model lifecycle might look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Model v1
   ↓
Train
   ↓
Validate
   ↓
Package
   ↓
Sign
   ↓
Deploy to 1%
   ↓
Monitor
   ↓
Deploy to 10%
   ↓
Deploy to 100%
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is essentially CI/CD for intelligence.&lt;/p&gt;




&lt;h1&gt;
  
  
  Edge + Cloud
&lt;/h1&gt;

&lt;p&gt;The strongest architecture probably isn't:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Edge OR Cloud
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Edge
 +
Regional Compute
 +
Cloud
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Sensor
  ↓
Edge inference
  ↓
Regional aggregation
  ↓
Cloud analytics
  ↓
Global model training
  ↓
Updated model
  ↓
Edge deployment
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates a feedback loop.&lt;/p&gt;




&lt;h1&gt;
  
  
  5. Domain-Specific AI: Smaller Models, Better Systems
&lt;/h1&gt;

&lt;p&gt;The fifth trend I think deserves more attention is specialization.&lt;/p&gt;

&lt;p&gt;The AI conversation has focused heavily on giant general-purpose models.&lt;/p&gt;

&lt;p&gt;But enterprises often don't need an AI that knows everything.&lt;/p&gt;

&lt;p&gt;They need an AI that understands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Insurance
Banking
Agriculture
Manufacturing
Law
Healthcare
Logistics
Telecommunications
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is where domain-specific AI becomes interesting.&lt;/p&gt;

&lt;p&gt;Gartner lists domain-specific language models among its major 2026 strategic technology trends.&lt;/p&gt;




&lt;h1&gt;
  
  
  General AI vs Domain AI
&lt;/h1&gt;

&lt;p&gt;Imagine a bank wants a model for:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Loan underwriting
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A general model may know about:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;History
Science
Programming
Sports
Movies
Politics
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But the bank primarily needs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Credit policies
Risk models
Regulations
Internal procedures
Financial terminology
Customer data
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A specialized system can focus on those domains.&lt;/p&gt;




&lt;h1&gt;
  
  
  Domain AI Architecture
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                 General Model
                       │
                       ▼
                Domain Adaptation
                       │
          ┌────────────┼────────────┐
          ▼            ▼            ▼
       Banking       Legal       Healthcare
        Model         Model          Model
          │            │             │
          ▼            ▼             ▼
      Enterprise    Enterprise    Enterprise
        Data          Data          Data
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This doesn't necessarily mean training an enormous model from scratch.&lt;/p&gt;

&lt;p&gt;There are many approaches:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fine-tuning&lt;/li&gt;
&lt;li&gt;Retrieval-augmented generation&lt;/li&gt;
&lt;li&gt;Distillation&lt;/li&gt;
&lt;li&gt;Smaller specialist models&lt;/li&gt;
&lt;li&gt;Tool use&lt;/li&gt;
&lt;li&gt;Domain-specific embeddings&lt;/li&gt;
&lt;li&gt;Structured knowledge bases&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  RAG: Giving Models Enterprise Memory
&lt;/h1&gt;

&lt;p&gt;Suppose an employee asks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"What is our company's refund policy?"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead of training the model on the policy, we can retrieve the relevant document.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Question
   ↓
Embedding
   ↓
Vector Search
   ↓
Relevant Documents
   ↓
LLM
   ↓
Answer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is Retrieval-Augmented Generation.&lt;/p&gt;




&lt;h1&gt;
  
  
  A Minimal RAG Pipeline
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;answer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;

    &lt;span class="n"&gt;query_vector&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;embed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;documents&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;vector_db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;query_vector&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;top_k&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;context&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;doc&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;documents&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;prompt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
    Answer using only this context:

    &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;

    Question:
    &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;
    &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;generate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a deceptively simple pattern.&lt;/p&gt;

&lt;p&gt;But it changes enterprise software dramatically.&lt;/p&gt;

&lt;p&gt;The model doesn't need to memorize the company.&lt;/p&gt;

&lt;p&gt;It needs access to the company's knowledge.&lt;/p&gt;




&lt;h1&gt;
  
  
  Enterprise AI Is Becoming a Data Architecture Problem
&lt;/h1&gt;

&lt;p&gt;This is one of the most important lessons.&lt;/p&gt;

&lt;p&gt;Companies may buy the same model.&lt;/p&gt;

&lt;p&gt;But their internal data is different.&lt;/p&gt;

&lt;p&gt;Therefore the competitive advantage often becomes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Model
+
Data
+
Workflows
+
Tools
+
Distribution
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;not merely:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Model
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  The Rise of Small Models
&lt;/h1&gt;

&lt;p&gt;A giant model isn't always the best solution.&lt;/p&gt;

&lt;p&gt;Suppose the task is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Classify support tickets
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Maybe we need:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Model size: small
Latency: 10 ms
Cost: tiny
Accuracy: 98%
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A giant model might provide:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Latency: 500 ms
Cost: high
Accuracy: 98.5%
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The extra intelligence may not justify the cost.&lt;/p&gt;

&lt;p&gt;Enterprise AI will increasingly become an optimization problem.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Quality
   ×
Latency
   ×
Cost
   ×
Privacy
   ×
Reliability
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Putting the Five Trends Together
&lt;/h1&gt;

&lt;p&gt;This is where things become really interesting.&lt;/p&gt;

&lt;p&gt;These technologies don't exist independently.&lt;/p&gt;

&lt;p&gt;They reinforce one another.&lt;/p&gt;

&lt;p&gt;Imagine a future manufacturing company.&lt;/p&gt;

&lt;p&gt;It has:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Robots
Sensors
AI agents
Edge inference
Confidential computing
Domain-specific models
Cloud infrastructure
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The architecture might look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                         ENTERPRISE
                             │
                     ┌───────┴───────┐
                     │               │
                 AI Agents      Domain Models
                     │               │
                     └───────┬───────┘
                             │
                      Policy Engine
                             │
                    Confidential Runtime
                             │
              ┌──────────────┼──────────────┐
              ▼              ▼              ▼
            Cloud          Edge          Robotics
              │              │              │
              └──────────────┼──────────────┘
                             │
                           Data
                             │
                        Knowledge
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This isn't science fiction.&lt;/p&gt;

&lt;p&gt;It's an architectural direction.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Enterprise Is Becoming a Distributed Intelligence System
&lt;/h1&gt;

&lt;p&gt;Traditional enterprise:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;People
  ↓
Applications
  ↓
Databases
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Emerging enterprise:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;People
   │
   ▼
Agents
   │
   ▼
Applications
   │
   ├──────────► APIs
   │
   ├──────────► Databases
   │
   ├──────────► Models
   │
   ├──────────► Edge Devices
   │
   └──────────► Physical Machines
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The application is no longer the only actor.&lt;/p&gt;

&lt;p&gt;Machines are beginning to participate in workflows.&lt;/p&gt;




&lt;h1&gt;
  
  
  What Happens to the Backend Engineer?
&lt;/h1&gt;

&lt;p&gt;I think the role changes.&lt;/p&gt;

&lt;p&gt;The backend engineer used to focus heavily on:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;APIs
Databases
Queues
Services
Authentication
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Those things aren't going away.&lt;/p&gt;

&lt;p&gt;But now we increasingly need:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Agent APIs
Model gateways
Tool permissions
Vector databases
Event-driven workflows
Inference infrastructure
AI observability
Policy engines
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The backend becomes the connective tissue between intelligence and the real world.&lt;/p&gt;




&lt;h1&gt;
  
  
  A New Kind of API
&lt;/h1&gt;

&lt;p&gt;Traditional API:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;POST /orders
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An agent-oriented API might expose capabilities:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;create_order
cancel_order
lookup_customer
check_inventory
request_refund
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The difference is subtle.&lt;/p&gt;

&lt;p&gt;The API is becoming a &lt;strong&gt;tool interface for intelligent software&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;That means APIs need stronger contracts.&lt;/p&gt;




&lt;h1&gt;
  
  
  APIs Need to Become More Machine-Friendly
&lt;/h1&gt;

&lt;p&gt;An AI agent needs to understand:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;What does this tool do?

What parameters does it accept?

What permissions are required?

What can go wrong?

Is this operation reversible?

Does it cost money?

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So API design increasingly becomes partly about machine discoverability.&lt;/p&gt;




&lt;h1&gt;
  
  
  Observability Changes Too
&lt;/h1&gt;

&lt;p&gt;Traditional monitoring:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CPU
Memory
Latency
Errors
Requests
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;AI systems add:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Token usage
Model latency
Tool calls
Prompt failures
Agent loops
Hallucinations
Policy violations
Model versions
Retrieval quality
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Imagine an agent making 17 tool calls for something that should require 3.&lt;/p&gt;

&lt;p&gt;Your infrastructure might be healthy.&lt;/p&gt;

&lt;p&gt;Your software might still be terrible.&lt;/p&gt;




&lt;h1&gt;
  
  
  Agent Tracing
&lt;/h1&gt;

&lt;p&gt;We might need traces like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Request #83921

Agent
 │
 ├── Model call: 320ms
 │
 ├── Search: 40ms
 │
 ├── Database: 12ms
 │
 ├── Model call: 510ms
 │
 ├── Payment API: 210ms
 │
 └── Model call: 280ms

Total: 1.37s
Tokens: 14,280
Tools: 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This becomes the equivalent of distributed tracing for intelligent systems.&lt;/p&gt;




&lt;h1&gt;
  
  
  The New Reliability Problem
&lt;/h1&gt;

&lt;p&gt;Traditional software is usually deterministic.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input A
 ↓
Output B
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;AI is probabilistic.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input A
 ↓
Possible Output B
Possible Output C
Possible Output D
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This changes testing.&lt;/p&gt;

&lt;p&gt;Instead of only:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;expected&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;we may need:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="nf"&gt;passes_policy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="nf"&gt;contains_required_information&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="nf"&gt;does_not_expose_sensitive_data&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The test surface becomes different.&lt;/p&gt;




&lt;h1&gt;
  
  
  Enterprises Will Need AI Governance as Engineering
&lt;/h1&gt;

&lt;p&gt;Governance can't just be a PDF.&lt;/p&gt;

&lt;p&gt;It needs to become infrastructure.&lt;/p&gt;

&lt;p&gt;Imagine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                  AI Request
                       │
                       ▼
                 Policy Engine
                       │
        ┌──────────────┼──────────────┐
        ▼              ▼              ▼
    Identity        Data Rules      Action Rules
        │              │              │
        └──────────────┼──────────────┘
                       ▼
                    Decision
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Policy should be executable.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;agent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;role&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;support&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;deny&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;delete_customer&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;classification&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;restricted&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;require_human_approval&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;action&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;refund&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;require_human_approval&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now governance becomes software.&lt;/p&gt;

&lt;p&gt;That is a much more powerful model.&lt;/p&gt;




&lt;h1&gt;
  
  
  What Companies Should Actually Do
&lt;/h1&gt;

&lt;p&gt;I wouldn't recommend that every enterprise immediately deploy 500 AI agents.&lt;/p&gt;

&lt;p&gt;Technology adoption should follow the problem.&lt;/p&gt;

&lt;p&gt;I'd start with workflows.&lt;/p&gt;

&lt;p&gt;Find processes that are:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Repetitive
Data-heavy
Well-defined
Measurable
Low-risk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then introduce AI.&lt;/p&gt;




&lt;h1&gt;
  
  
  Step 1: Find the Workflow
&lt;/h1&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Customer Support Ticket
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Current process:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Ticket
 ↓
Human reads
 ↓
Find customer
 ↓
Find order
 ↓
Find policy
 ↓
Write response
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Potential AI-assisted process:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Ticket
 ↓
Agent
 ├── Customer lookup
 ├── Order lookup
 ├── Policy retrieval
 └── Draft response
        ↓
     Human review
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a much safer starting point than:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"Let's let an AI run customer support."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Step 2: Introduce Deterministic Tools
&lt;/h1&gt;

&lt;p&gt;Give the agent tools.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;tools&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="n"&gt;get_customer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;get_order&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;search_policy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;draft_response&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Don't initially give it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;delete_database&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The principle is:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Start with read-only capabilities.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Then gradually increase autonomy.&lt;/p&gt;




&lt;h1&gt;
  
  
  Step 3: Add Observability
&lt;/h1&gt;

&lt;p&gt;Track:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Agent requests
Tool calls
Failures
Latency
Cost
Human overrides
Policy violations
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You need data before you can optimize.&lt;/p&gt;




&lt;h1&gt;
  
  
  Step 4: Add Permissions
&lt;/h1&gt;

&lt;p&gt;Every agent should have an identity.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Agent:
    support-agent-01

Permissions:
    customer.read
    order.read
    policy.read
    response.draft
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Not:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;admin.*
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Step 5: Measure Business Outcomes
&lt;/h1&gt;

&lt;p&gt;Don't measure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Number of AI calls
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Measure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Resolution time
Cost per ticket
Customer satisfaction
Human review time
Error rate
Escalation rate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Technology isn't the outcome.&lt;/p&gt;

&lt;p&gt;The business result is.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Architecture I Would Build
&lt;/h1&gt;

&lt;p&gt;If I were designing a modern enterprise platform around these trends, I'd think about it as layers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;┌──────────────────────────────────────┐
│          Business Applications       │
├──────────────────────────────────────┤
│       Agents / AI Workflows          │
├──────────────────────────────────────┤
│      Domain Models / RAG             │
├──────────────────────────────────────┤
│       Policy + Identity              │
├──────────────────────────────────────┤
│       Observability                  │
├──────────────────────────────────────┤
│      Confidential Runtime            │
├──────────────────────────────────────┤
│      Cloud + Edge Compute            │
├──────────────────────────────────────┤
│      Storage + Networking            │
└──────────────────────────────────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is very different from the traditional:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Frontend
 ↓
Backend
 ↓
Database
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;architecture.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Biggest Shift Isn't AI
&lt;/h1&gt;

&lt;p&gt;This might sound strange considering the article is about emerging technology.&lt;/p&gt;

&lt;p&gt;But I don't think AI itself is the deepest change.&lt;/p&gt;

&lt;p&gt;The deeper change is &lt;strong&gt;autonomy&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Software is gradually moving from:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Passive tools
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Active participants
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A database waits for a query.&lt;/p&gt;

&lt;p&gt;An API waits for a request.&lt;/p&gt;

&lt;p&gt;A traditional application waits for a user.&lt;/p&gt;

&lt;p&gt;An agent can initiate work.&lt;/p&gt;

&lt;p&gt;That changes everything.&lt;/p&gt;




&lt;h1&gt;
  
  
  Software Is Becoming More Like an Organization
&lt;/h1&gt;

&lt;p&gt;Think about a company.&lt;/p&gt;

&lt;p&gt;There are:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Employees
Managers
Policies
Departments
Systems
Communication
Permissions
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now imagine representing some of those functions in software.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Sales Agent
Support Agent
Research Agent
Finance Agent
Engineering Agent
Security Agent
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;They communicate through APIs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;             Orchestrator
                  │
      ┌───────────┼───────────┐
      ▼           ▼           ▼
    Sales      Support     Finance
    Agent       Agent       Agent
      │           │           │
      └───────────┼───────────┘
                  ▼
              Enterprise
               Systems
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is why multiagent architectures are receiving attention: the system can divide complex workflows into specialized capabilities rather than relying on one monolithic agent. Gartner explicitly lists multiagent systems among its 2026 strategic trends.&lt;/p&gt;




&lt;h1&gt;
  
  
  But We Should Be Careful
&lt;/h1&gt;

&lt;p&gt;There is a temptation to assume:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;More agents = better
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Not necessarily.&lt;/p&gt;

&lt;p&gt;Every agent adds:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Latency
Cost
Failure modes
Security boundaries
Debugging complexity
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A distributed system with 50 agents can become a distributed systems nightmare.&lt;/p&gt;

&lt;p&gt;Sometimes one deterministic function is better than an agent.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;calculate_tax&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;doesn't need an LLM.&lt;/p&gt;

&lt;p&gt;Use deterministic software where deterministic software works.&lt;/p&gt;

&lt;p&gt;Use intelligence where ambiguity exists.&lt;/p&gt;

&lt;p&gt;That distinction will become extremely valuable.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Future Enterprise Will Be Hybrid
&lt;/h1&gt;

&lt;p&gt;I don't think the future looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Everything = AI
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Deterministic Software
+
AI
+
Humans
+
Robotics
+
Edge Systems
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each should handle what it is good at.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                    Problem
                       │
        ┌──────────────┼──────────────┐
        ▼              ▼              ▼
   Deterministic       AI            Human
      Logic          Reasoning       Judgment
        │              │              │
        └──────────────┼──────────────┘
                       ▼
                     Result
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The best systems will orchestrate all three.&lt;/p&gt;




&lt;h1&gt;
  
  
  What This Means for Startups
&lt;/h1&gt;

&lt;p&gt;There is a huge opportunity here.&lt;/p&gt;

&lt;p&gt;You don't necessarily need to build another generic AI chatbot.&lt;/p&gt;

&lt;p&gt;You can build infrastructure around the emerging architecture.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;h3&gt;
  
  
  Agent security
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Agent
 ↓
Identity
 ↓
Permissions
 ↓
Policy
 ↓
Audit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Edge AI infrastructure
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Model
 ↓
Deployment
 ↓
Device
 ↓
Monitoring
 ↓
Updates
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Domain AI
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Enterprise Data
 ↓
Retrieval
 ↓
Specialized Model
 ↓
Workflow
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  AI observability
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Agent
 ↓
Trace
 ↓
Cost
 ↓
Latency
 ↓
Quality
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are infrastructure problems.&lt;/p&gt;

&lt;p&gt;And infrastructure problems can become enormous companies.&lt;/p&gt;




&lt;h1&gt;
  
  
  What This Means for African Technology
&lt;/h1&gt;

&lt;p&gt;I also think these trends create an interesting opportunity for African engineers.&lt;/p&gt;

&lt;p&gt;There is a tendency to think technological innovation requires recreating Silicon Valley.&lt;/p&gt;

&lt;p&gt;I don't think it does.&lt;/p&gt;

&lt;p&gt;Many African markets have problems that are particularly suitable for these architectures.&lt;/p&gt;

&lt;p&gt;Agriculture.&lt;/p&gt;

&lt;p&gt;Logistics.&lt;/p&gt;

&lt;p&gt;Healthcare.&lt;/p&gt;

&lt;p&gt;Banking.&lt;/p&gt;

&lt;p&gt;Energy.&lt;/p&gt;

&lt;p&gt;Telecommunications.&lt;/p&gt;

&lt;p&gt;Mining.&lt;/p&gt;

&lt;p&gt;Education.&lt;/p&gt;

&lt;p&gt;Consider agriculture.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Farm Sensors
     ↓
Edge AI
     ↓
Local Analysis
     ↓
Agricultural Agent
     ↓
Market Data
     ↓
Farmer Recommendation
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or logistics:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Vehicle
 ↓
Edge Device
 ↓
Route Intelligence
 ↓
Cloud
 ↓
Optimization Agent
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or healthcare:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Local Device
 ↓
Edge Inference
 ↓
Confidential Processing
 ↓
Clinical Workflow
 ↓
Human Decision
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important thing is not copying someone else's application.&lt;/p&gt;

&lt;p&gt;It is understanding the underlying architecture and applying it to local problems.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Engineering Principles Behind All Five Trends
&lt;/h1&gt;

&lt;p&gt;After looking at these technologies, I think several engineering principles emerge.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Move intelligence closer to the decision
&lt;/h2&gt;

&lt;p&gt;Sometimes that means:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Cloud
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sometimes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Edge
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sometimes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Human
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The question is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Where should the decision happen?&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  2. Minimize trust
&lt;/h2&gt;

&lt;p&gt;Don't assume:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The cloud is trusted.
The agent is trusted.
The model is trusted.
The network is trusted.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Identity
+
Policy
+
Attestation
+
Verification
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  3. Make capabilities explicit
&lt;/h2&gt;

&lt;p&gt;An agent shouldn't have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;everything()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It should have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;read_customer()
read_order()
create_ticket()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explicit interfaces create safer systems.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Keep deterministic systems deterministic
&lt;/h2&gt;

&lt;p&gt;Don't use an LLM for:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Tax calculation
Balance calculation
Permission checking
Currency conversion
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use traditional software.&lt;/p&gt;

&lt;p&gt;AI should handle ambiguity.&lt;/p&gt;




&lt;h2&gt;
  
  
  5. Design for observability
&lt;/h2&gt;

&lt;p&gt;Every intelligent action should ideally be traceable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Who?
What?
Why?
Which model?
Which data?
Which tools?
What happened?
How much did it cost?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  The Enterprise Architecture of Tomorrow
&lt;/h1&gt;

&lt;p&gt;Put everything together and the picture becomes fascinating.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                              USERS
                                │
                                ▼
                         Experience Layer
                                │
                                ▼
                     Intelligent Orchestration
                                │
              ┌─────────────────┼─────────────────┐
              ▼                 ▼                 ▼
           Agents          Applications       Humans
              │                 │                 │
              └─────────────────┼─────────────────┘
                                ▼
                         Policy + Identity
                                │
                ┌───────────────┼───────────────┐
                ▼               ▼               ▼
             Models           APIs            Data
                │               │               │
                └───────────────┼───────────────┘
                                ▼
                       Confidential Runtime
                                │
                ┌───────────────┼───────────────┐
                ▼               ▼               ▼
              Cloud           Edge          Physical AI
                │               │               │
                └───────────────┼───────────────┘
                                ▼
                          Infrastructure
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is the direction I see.&lt;/p&gt;

&lt;p&gt;Not one giant AI.&lt;/p&gt;

&lt;p&gt;Not one giant cloud.&lt;/p&gt;

&lt;p&gt;A distributed ecosystem of intelligence.&lt;/p&gt;




&lt;h1&gt;
  
  
  Final Thoughts
&lt;/h1&gt;

&lt;p&gt;The most important technology trends aren't always the ones dominating social media.&lt;/p&gt;

&lt;p&gt;Sometimes the real transformation is happening in architecture diagrams.&lt;/p&gt;

&lt;p&gt;I think these five trends deserve serious attention:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Agentic AI&lt;/strong&gt; is turning software from a passive tool into an active participant.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AI-native infrastructure&lt;/strong&gt; is changing what enterprise computing looks like underneath applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Confidential computing&lt;/strong&gt; is creating stronger trust boundaries for sensitive workloads.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Edge AI and physical intelligence&lt;/strong&gt; are moving computation toward the places where decisions actually happen.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Domain-specific AI&lt;/strong&gt; is pushing enterprises away from the idea that one enormous general-purpose model is the answer to everything.&lt;/p&gt;

&lt;p&gt;And together, they create something bigger.&lt;/p&gt;

&lt;p&gt;They create a new kind of enterprise.&lt;/p&gt;

&lt;p&gt;One where:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Software can reason.
Software can act.
Machines can perceive.
Data can remain closer to its source.
Infrastructure can verify itself.
Models can specialize.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But I don't think the winning companies will simply be the ones with the most AI.&lt;/p&gt;

&lt;p&gt;They'll be the ones that understand &lt;strong&gt;systems&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Because once AI becomes capable of acting, the difficult problems stop being:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Can the model generate an answer?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The difficult questions become:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Should it act?&lt;/p&gt;

&lt;p&gt;What is it allowed to access?&lt;/p&gt;

&lt;p&gt;Where should computation happen?&lt;/p&gt;

&lt;p&gt;Can we verify the environment?&lt;/p&gt;

&lt;p&gt;Can we explain what happened?&lt;/p&gt;

&lt;p&gt;Can we afford the inference?&lt;/p&gt;

&lt;p&gt;What happens when the model is wrong?&lt;/p&gt;

&lt;p&gt;What happens when the network disappears?&lt;/p&gt;

&lt;p&gt;What happens when an agent behaves unexpectedly?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;These are engineering questions.&lt;/p&gt;

&lt;p&gt;And that's why I find this period so interesting.&lt;/p&gt;

&lt;p&gt;We're not merely adding intelligence to existing software.&lt;/p&gt;

&lt;p&gt;We're redesigning the machinery around it.&lt;/p&gt;

&lt;p&gt;The enterprise application of the past looked something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Human
  ↓
Application
  ↓
Database
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The emerging enterprise looks more like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                         HUMAN
                           │
                           ▼
                    INTELLIGENT SYSTEM
                           │
             ┌─────────────┼─────────────┐
             ▼             ▼             ▼
           AGENTS        MODELS        HUMANS
             │             │             │
             └─────────────┼─────────────┘
                           ▼
                    POLICY + IDENTITY
                           │
              ┌────────────┼────────────┐
              ▼            ▼            ▼
            CLOUD         EDGE       PHYSICAL
              │            │            │
              └────────────┼────────────┘
                           ▼
                         DATA
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that is the real story.&lt;/p&gt;

&lt;p&gt;The future of enterprise technology isn't simply &lt;strong&gt;more powerful software&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;It's software that can perceive, reason, coordinate, verify, and act across an increasingly distributed world.&lt;/p&gt;

&lt;p&gt;The companies that understand that architecture early will have an enormous advantage.&lt;/p&gt;

&lt;p&gt;Because the next generation of enterprise systems won't just execute instructions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;They'll participate in the work.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>programming</category>
      <category>softwaredevelopment</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>Building Your Own SQL Database</title>
      <dc:creator>Derek mwale</dc:creator>
      <pubDate>Tue, 04 Aug 2026 00:08:50 +0000</pubDate>
      <link>https://dev.to/derekmwale/building-your-own-sql-database-43o</link>
      <guid>https://dev.to/derekmwale/building-your-own-sql-database-43o</guid>
      <description>&lt;h2&gt;
  
  
  From Bytes on Disk to Tables You Can Query
&lt;/h2&gt;

&lt;p&gt;Every developer uses databases.&lt;/p&gt;

&lt;p&gt;Whether you're building a small blog, a banking platform, an e-commerce store, or a distributed cloud service, sooner or later your application needs somewhere to store information.&lt;/p&gt;

&lt;p&gt;We write SQL queries every day.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;products&lt;/span&gt; &lt;span class="p"&gt;(...);&lt;/span&gt;

&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt; &lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="p"&gt;...;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Most of the time, we stop there.&lt;/p&gt;

&lt;p&gt;We trust PostgreSQL, MySQL, SQLite, or SQL Server to do the rest.&lt;/p&gt;

&lt;p&gt;But have you ever wondered what actually happens after you press &lt;strong&gt;Enter&lt;/strong&gt;?&lt;/p&gt;

&lt;p&gt;How does a database know where your data lives?&lt;/p&gt;

&lt;p&gt;How does it find rows without reading the entire file?&lt;/p&gt;

&lt;p&gt;How does it survive power failures?&lt;/p&gt;

&lt;p&gt;How does it store millions—even billions—of records efficiently?&lt;/p&gt;

&lt;p&gt;When I first started backend development, I imagined databases as giant spreadsheets.&lt;/p&gt;

&lt;p&gt;As I learned more, I realized they are closer to miniature operating systems.&lt;/p&gt;

&lt;p&gt;They manage memory.&lt;/p&gt;

&lt;p&gt;They schedule disk access.&lt;/p&gt;

&lt;p&gt;They recover from crashes.&lt;/p&gt;

&lt;p&gt;They optimize execution plans.&lt;/p&gt;

&lt;p&gt;They maintain consistency while thousands of users access data simultaneously.&lt;/p&gt;

&lt;p&gt;Building a database completely changed the way I think about software.&lt;/p&gt;

&lt;p&gt;In this series, we'll build the foundations of our own SQL database in Rust.&lt;/p&gt;

&lt;p&gt;Not because we're trying to replace PostgreSQL.&lt;/p&gt;

&lt;p&gt;But because building one is one of the best ways to understand how modern software stores, retrieves, and protects information.&lt;/p&gt;

&lt;p&gt;Let's begin with the most fundamental question.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Where does a database actually keep your data?&lt;/strong&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  A Database Starts as a File
&lt;/h1&gt;

&lt;p&gt;Many beginners imagine a database as something abstract living inside a server.&lt;/p&gt;

&lt;p&gt;Reality is much simpler.&lt;/p&gt;

&lt;p&gt;Every database ultimately stores information in files.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Application

      │

      ▼

 SQL Query

      │

      ▼

Database Engine

      │

      ▼

Database File
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Whether you're using SQLite or PostgreSQL, the lowest layer eventually writes bytes to storage.&lt;/p&gt;

&lt;p&gt;The database is simply responsible for organizing those bytes intelligently.&lt;/p&gt;




&lt;h1&gt;
  
  
  Thinking Beyond Tables
&lt;/h1&gt;

&lt;p&gt;Applications show data as tables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Users

+----+--------+

| ID | Name   |

+----+--------+

| 1  | Derek  |

| 2  | Alex   |

+----+--------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The disk never stores tables like this.&lt;/p&gt;

&lt;p&gt;Instead, everything becomes binary.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;01001001

00100111

11100001

...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Tables are abstractions.&lt;/p&gt;

&lt;p&gt;The database translates between human-friendly structures and machine-friendly bytes.&lt;/p&gt;




&lt;h1&gt;
  
  
  Layers of a Database
&lt;/h1&gt;

&lt;p&gt;A modern SQL database resembles a layered architecture.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                SQL

                 │

                 ▼

          Query Engine

                 │

                 ▼

         Storage Engine

                 │

                 ▼

            File System

                 │

                 ▼

             SSD / HDD
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each layer has one responsibility.&lt;/p&gt;

&lt;p&gt;That's good software engineering.&lt;/p&gt;




&lt;h1&gt;
  
  
  Designing Our Database
&lt;/h1&gt;

&lt;p&gt;Our database will be called:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TinyDB
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Project structure.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tinydb/

├── storage/

├── table/

├── page/

├── sql/

├── parser/

├── executor/

├── catalog/

├── buffer/

└── main.rs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice something interesting.&lt;/p&gt;

&lt;p&gt;Large databases are simply well-organized software projects.&lt;/p&gt;




&lt;h1&gt;
  
  
  Representing a Row
&lt;/h1&gt;

&lt;p&gt;Let's begin with one row.&lt;/p&gt;

&lt;p&gt;Rust.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;User&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Simple.&lt;/p&gt;

&lt;p&gt;Applications think in structures.&lt;/p&gt;

&lt;p&gt;Storage engines think differently.&lt;/p&gt;




&lt;h1&gt;
  
  
  Serialization
&lt;/h1&gt;

&lt;p&gt;Before writing data to disk, we must convert structures into bytes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User

↓

Serialize

↓

Bytes

↓

Disk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The reverse process is called deserialization.&lt;/p&gt;




&lt;h1&gt;
  
  
  Example Serialization
&lt;/h1&gt;

&lt;p&gt;Suppose we have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="n"&gt;User&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Derek"&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Serialized representation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;01 00 00 00

05

44 65 72 65 6B
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The exact format is our choice.&lt;/p&gt;

&lt;p&gt;That's one of the fascinating parts of building storage engines.&lt;/p&gt;




&lt;h1&gt;
  
  
  Storage Pages
&lt;/h1&gt;

&lt;p&gt;Databases rarely read individual rows.&lt;/p&gt;

&lt;p&gt;Instead they organize storage into &lt;strong&gt;pages&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Typically:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;4096 Bytes

↓

One Page
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every read.&lt;/p&gt;

&lt;p&gt;Every write.&lt;/p&gt;

&lt;p&gt;Occurs page by page.&lt;/p&gt;




&lt;h1&gt;
  
  
  Why Pages?
&lt;/h1&gt;

&lt;p&gt;Imagine a million users.&lt;/p&gt;

&lt;p&gt;Reading one row at a time would be extremely inefficient.&lt;/p&gt;

&lt;p&gt;Instead:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Disk

┌───────────┐

│ Page 1    │

├───────────┤

│ Page 2    │

├───────────┤

│ Page 3    │

└───────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pages minimize disk operations.&lt;/p&gt;




&lt;h1&gt;
  
  
  Designing a Page
&lt;/h1&gt;

&lt;p&gt;Rust.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;Page&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Vec&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;u8&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Initially...&lt;/p&gt;

&lt;p&gt;Just raw bytes.&lt;/p&gt;

&lt;p&gt;Higher layers interpret them.&lt;/p&gt;




&lt;h1&gt;
  
  
  Table Storage
&lt;/h1&gt;

&lt;p&gt;Suppose each page stores several rows.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Page

+-------------------------+

Row

Row

Row

Row

+-------------------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Eventually pages fill up.&lt;/p&gt;

&lt;p&gt;The database allocates another.&lt;/p&gt;




&lt;h1&gt;
  
  
  Building the Storage Engine
&lt;/h1&gt;

&lt;p&gt;Architecture.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Application

      │

      ▼

Table

      │

      ▼

Page Manager

      │

      ▼

File Manager

      │

      ▼

Disk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each component solves one problem.&lt;/p&gt;




&lt;h1&gt;
  
  
  Writing Pages
&lt;/h1&gt;

&lt;p&gt;Rust implementation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;std&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;File&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;std&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;io&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Write&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;write_page&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;

    &lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;File&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;Page&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="nf"&gt;.write_all&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;

        &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="py"&gt;.data&lt;/span&gt;

    &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nf"&gt;.unwrap&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Simple.&lt;/p&gt;

&lt;p&gt;Yet this is the foundation of every database.&lt;/p&gt;




&lt;h1&gt;
  
  
  Reading Pages
&lt;/h1&gt;

&lt;p&gt;Reading becomes equally straightforward.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;std&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;io&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Read&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;read_page&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;

    &lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;File&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;Page&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="nf"&gt;.read_exact&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;

        &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="py"&gt;.data&lt;/span&gt;

    &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nf"&gt;.unwrap&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Storage engines spend much of their lives performing operations like these.&lt;/p&gt;




&lt;h1&gt;
  
  
  Building a Table
&lt;/h1&gt;

&lt;p&gt;Now we combine pages into tables.&lt;/p&gt;

&lt;p&gt;Rust.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;Table&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;pages&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

        &lt;span class="nb"&gt;Vec&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Page&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Eventually tables may contain thousands of pages.&lt;/p&gt;

&lt;p&gt;Or millions.&lt;/p&gt;




&lt;h1&gt;
  
  
  Inserting Data
&lt;/h1&gt;

&lt;p&gt;Suppose we execute:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;

&lt;span class="k"&gt;VALUES&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;'Derek'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Flow.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SQL

↓

Insert Command

↓

Serialize Row

↓

Find Free Page

↓

Write Bytes

↓

Commit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The SQL statement eventually becomes disk writes.&lt;/p&gt;




&lt;h1&gt;
  
  
  Reading Data
&lt;/h1&gt;

&lt;p&gt;Now imagine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;

&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Execution.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Read Page

↓

Deserialize Rows

↓

Return Results
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Queries simply reverse the insertion process.&lt;/p&gt;




&lt;h1&gt;
  
  
  Catalog
&lt;/h1&gt;

&lt;p&gt;How does the database know which tables exist?&lt;/p&gt;

&lt;p&gt;Using a catalog.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Catalog

+-----------+

Users

Orders

Products

Invoices

+-----------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Think of it as metadata describing the database itself.&lt;/p&gt;




&lt;h1&gt;
  
  
  Catalog Structure
&lt;/h1&gt;

&lt;p&gt;Rust.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;Catalog&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="n"&gt;tables&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

        &lt;span class="nb"&gt;Vec&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Table&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Later this grows considerably.&lt;/p&gt;

&lt;p&gt;Indexes.&lt;/p&gt;

&lt;p&gt;Schemas.&lt;/p&gt;

&lt;p&gt;Constraints.&lt;/p&gt;

&lt;p&gt;Views.&lt;/p&gt;

&lt;p&gt;Statistics.&lt;/p&gt;

&lt;p&gt;Everything begins here.&lt;/p&gt;




&lt;h1&gt;
  
  
  Buffer Pool
&lt;/h1&gt;

&lt;p&gt;Reading directly from disk every time would be painfully slow.&lt;/p&gt;

&lt;p&gt;Instead databases cache pages.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Disk

↓

Buffer Pool

↓

Application
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Recently used pages remain in memory.&lt;/p&gt;




&lt;h1&gt;
  
  
  Why Buffer Pools Matter
&lt;/h1&gt;

&lt;p&gt;Suppose ten users request the same page.&lt;/p&gt;

&lt;p&gt;Without caching.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Disk

↓

Disk

↓

Disk

↓

Disk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With caching.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Disk

↓

Memory

↓

Memory

↓

Memory
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Much faster.&lt;/p&gt;




&lt;h1&gt;
  
  
  Simplified Buffer Manager
&lt;/h1&gt;

&lt;p&gt;Rust.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;std&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;collections&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;HashMap&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;BufferPool&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="n"&gt;pages&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

    &lt;span class="n"&gt;HashMap&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;u32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Page&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Whenever possible:&lt;/p&gt;

&lt;p&gt;Read from memory.&lt;/p&gt;

&lt;p&gt;Otherwise:&lt;/p&gt;

&lt;p&gt;Read from disk.&lt;/p&gt;




&lt;h1&gt;
  
  
  Database Flow
&lt;/h1&gt;

&lt;p&gt;Putting everything together.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Application

↓

SQL

↓

Table Manager

↓

Buffer Pool

↓

Storage Engine

↓

Disk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice how SQL never interacts with files directly.&lt;/p&gt;

&lt;p&gt;Every layer abstracts the one below it.&lt;/p&gt;




&lt;h1&gt;
  
  
  Complete Architecture
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                 SQL Client

                      │

                      ▼

                Query Layer

                      │

                      ▼

              Table Manager

                      │

                      ▼

               Buffer Manager

                      │

         ┌────────────┼─────────────┐

         ▼            ▼             ▼

      Page 1       Page 2        Page 3

         │            │             │

         └────────────┼─────────────┘

                      ▼

                Database File

                      │

                      ▼

                   SSD / HDD
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Even though our database is still small, the architecture already resembles production systems.&lt;/p&gt;




&lt;h1&gt;
  
  
  Implementation Summary
&lt;/h1&gt;

&lt;p&gt;At this point, TinyDB supports the core storage concepts found in real databases:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Rows represented as Rust structures.&lt;/li&gt;
&lt;li&gt;Serialization of rows into bytes.&lt;/li&gt;
&lt;li&gt;Fixed-size storage pages.&lt;/li&gt;
&lt;li&gt;Tables composed of multiple pages.&lt;/li&gt;
&lt;li&gt;A storage engine that reads and writes pages to disk.&lt;/li&gt;
&lt;li&gt;A simple catalog to track tables.&lt;/li&gt;
&lt;li&gt;A buffer pool that caches frequently accessed pages.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These pieces may appear simple, but they form the foundation of nearly every relational database.&lt;/p&gt;




&lt;h1&gt;
  
  
  Looking Ahead
&lt;/h1&gt;

&lt;p&gt;So far, we've focused entirely on &lt;strong&gt;how data is stored&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;But a database becomes truly useful when it understands &lt;strong&gt;SQL&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In Part 2, we'll build our own SQL engine from scratch.&lt;/p&gt;

&lt;p&gt;We'll write a lexer to break SQL into tokens, build a parser that constructs an Abstract Syntax Tree (AST), implement a query planner, and create an execution engine capable of processing commands like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="p"&gt;(...);&lt;/span&gt;

&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="k"&gt;VALUES&lt;/span&gt; &lt;span class="p"&gt;(...);&lt;/span&gt;

&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We'll explore how databases transform human-readable SQL into executable operations, introduce table scans, filtering, and projections, and compare our design to the internal architecture of PostgreSQL and SQLite.&lt;/p&gt;

&lt;p&gt;By the end of the next article, TinyDB won't just store data—it will understand and execute SQL.&lt;/p&gt;




&lt;h1&gt;
  
  
  Final Thoughts
&lt;/h1&gt;

&lt;p&gt;One of the biggest surprises in building a database is realizing how much of it has nothing to do with SQL.&lt;/p&gt;

&lt;p&gt;Before a parser, optimizer, or query planner can exist, the database must solve a far more fundamental problem: how to organize information on disk efficiently and reliably.&lt;/p&gt;

&lt;p&gt;Everything starts with bytes.&lt;/p&gt;

&lt;p&gt;Rows become serialized records.&lt;/p&gt;

&lt;p&gt;Records are packed into pages.&lt;/p&gt;

&lt;p&gt;Pages are written to files.&lt;/p&gt;

&lt;p&gt;Files become tables.&lt;/p&gt;

&lt;p&gt;Tables become databases.&lt;/p&gt;

&lt;p&gt;Only then do higher-level abstractions like SQL begin to make sense.&lt;/p&gt;

&lt;p&gt;That progression mirrors software engineering as a whole.&lt;/p&gt;

&lt;p&gt;The most sophisticated systems are often built from remarkably simple layers, each solving one well-defined problem.&lt;/p&gt;

&lt;p&gt;Understanding those layers gives you a deeper appreciation for every query you write.&lt;/p&gt;

&lt;p&gt;The next time you execute &lt;code&gt;SELECT * FROM users&lt;/code&gt;, you'll know that beneath those four words lies an intricate system of pages, buffers, storage engines, and carefully organized bytes working together to make data appear effortless.&lt;/p&gt;

&lt;p&gt;And we're only just getting started.&lt;/p&gt;

&lt;h1&gt;
  
  
  Building Your Own SQL Database (Part 2)
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Building a SQL Parser, Query Planner, and Execution Engine
&lt;/h2&gt;

&lt;p&gt;In Part 1, we built the foundation of our database.&lt;/p&gt;

&lt;p&gt;We learned that databases are not magical systems. At their core, they organize bytes on disk into pages, pages into tables, and tables into a storage engine capable of persisting information.&lt;/p&gt;

&lt;p&gt;By the end of Part 1, our TinyDB architecture looked like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Application
      │
      ▼
 Table Manager
      │
      ▼
 Buffer Pool
      │
      ▼
 Storage Engine
      │
      ▼
 Database File
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our database could store information.&lt;/p&gt;

&lt;p&gt;But there was one major problem.&lt;/p&gt;

&lt;p&gt;Nobody wants to interact with raw pages or serialized bytes.&lt;/p&gt;

&lt;p&gt;Developers speak SQL.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The computer does not.&lt;/p&gt;

&lt;p&gt;Computers understand instructions.&lt;/p&gt;

&lt;p&gt;Somewhere between SQL and the storage engine, the database must translate human language into executable operations.&lt;/p&gt;

&lt;p&gt;That's exactly what we're building today.&lt;/p&gt;

&lt;p&gt;By the end of this article, TinyDB will understand SQL, build an Abstract Syntax Tree (AST), generate a query plan, and execute queries against our storage engine.&lt;/p&gt;

&lt;p&gt;This is where our database begins to feel alive.&lt;/p&gt;




&lt;h1&gt;
  
  
  SQL Is Just Another Language
&lt;/h1&gt;

&lt;p&gt;We often think of SQL as something special.&lt;/p&gt;

&lt;p&gt;It isn't.&lt;/p&gt;

&lt;p&gt;It's simply a programming language.&lt;/p&gt;

&lt;p&gt;Like Rust.&lt;/p&gt;

&lt;p&gt;Like Python.&lt;/p&gt;

&lt;p&gt;Like JavaScript.&lt;/p&gt;

&lt;p&gt;Every programming language follows the same pipeline.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Source Code

↓

Lexer

↓

Tokens

↓

Parser

↓

AST

↓

Execution
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Databases follow exactly the same idea.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Journey of a Query
&lt;/h1&gt;

&lt;p&gt;Suppose the user writes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Internally our database performs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SQL

↓

Lexer

↓

Tokens

↓

Parser

↓

AST

↓

Query Planner

↓

Execution Engine

↓

Storage Engine

↓

Results
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice how SQL disappears very early.&lt;/p&gt;

&lt;p&gt;Everything afterward operates on structured objects.&lt;/p&gt;




&lt;h1&gt;
  
  
  Step 1 — Lexical Analysis
&lt;/h1&gt;

&lt;p&gt;The lexer breaks raw text into meaningful pieces.&lt;/p&gt;

&lt;p&gt;Input:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT

IDENTIFIER(name)

FROM

IDENTIFIER(users)

SEMICOLON
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These pieces are called &lt;strong&gt;tokens&lt;/strong&gt;.&lt;/p&gt;




&lt;h1&gt;
  
  
  Designing Tokens
&lt;/h1&gt;

&lt;p&gt;Rust.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;enum&lt;/span&gt; &lt;span class="n"&gt;Token&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="n"&gt;Select&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="n"&gt;Insert&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="n"&gt;Update&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="n"&gt;Delete&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="nb"&gt;From&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="n"&gt;Where&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="nf"&gt;Identifier&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;

    &lt;span class="nf"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;u64&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;

    &lt;span class="nf"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;

    &lt;span class="n"&gt;Comma&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="n"&gt;Semicolon&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every SQL statement becomes a stream of these objects.&lt;/p&gt;




&lt;h1&gt;
  
  
  Example Lexer
&lt;/h1&gt;

&lt;p&gt;Suppose our input is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT id FROM users;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The lexer produces:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;+----------------+

SELECT

Identifier(id)

FROM

Identifier(users)

Semicolon

+----------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Simple.&lt;/p&gt;

&lt;p&gt;Deterministic.&lt;/p&gt;

&lt;p&gt;Fast.&lt;/p&gt;




&lt;h1&gt;
  
  
  Why Tokenization Matters
&lt;/h1&gt;

&lt;p&gt;Imagine parsing SQL character by character.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;S

E

L

E

C

T
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Very difficult.&lt;/p&gt;

&lt;p&gt;Instead we work with meaningful units.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Much easier.&lt;/p&gt;




&lt;h1&gt;
  
  
  Parser
&lt;/h1&gt;

&lt;p&gt;Now the parser transforms tokens into meaning.&lt;/p&gt;

&lt;p&gt;Example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT

Identifier(name)

FROM

Identifier(users)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Becomes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Select Query

├── Columns

│      name

└── Table

       users
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This structure is called an Abstract Syntax Tree.&lt;/p&gt;




&lt;h1&gt;
  
  
  Building the AST
&lt;/h1&gt;

&lt;p&gt;Rust.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;SelectStatement&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

        &lt;span class="nb"&gt;Vec&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice something important.&lt;/p&gt;

&lt;p&gt;The SQL text disappears.&lt;/p&gt;

&lt;p&gt;Only structure remains.&lt;/p&gt;




&lt;h1&gt;
  
  
  AST Visualization
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;             SELECT

             /     \

      Columns      Table

        │            │

      name         users
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This tree represents the query.&lt;/p&gt;

&lt;p&gt;Every SQL database builds something similar.&lt;/p&gt;




&lt;h1&gt;
  
  
  Parsing SELECT
&lt;/h1&gt;

&lt;p&gt;Pseudo-code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="nf"&gt;parse_select&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="err"&gt;↓&lt;/span&gt;

&lt;span class="n"&gt;expect&lt;/span&gt; &lt;span class="n"&gt;SELECT&lt;/span&gt;

&lt;span class="err"&gt;↓&lt;/span&gt;

&lt;span class="n"&gt;parse&lt;/span&gt; &lt;span class="n"&gt;columns&lt;/span&gt;

&lt;span class="err"&gt;↓&lt;/span&gt;

&lt;span class="n"&gt;expect&lt;/span&gt; &lt;span class="n"&gt;FROM&lt;/span&gt;

&lt;span class="err"&gt;↓&lt;/span&gt;

&lt;span class="n"&gt;parse&lt;/span&gt; &lt;span class="n"&gt;table&lt;/span&gt;

&lt;span class="err"&gt;↓&lt;/span&gt;

&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;AST&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every parser follows a predictable sequence.&lt;/p&gt;




&lt;h1&gt;
  
  
  Supporting WHERE
&lt;/h1&gt;

&lt;p&gt;Now let's extend our AST.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;

&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;

&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Rust.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;Condition&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;column&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Updated statement.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;SelectStatement&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

        &lt;span class="nb"&gt;Vec&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;condition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

        &lt;span class="nb"&gt;Option&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Condition&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our parser now understands filtering.&lt;/p&gt;




&lt;h1&gt;
  
  
  AST with WHERE
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT

├── Columns

│

├── Table

│

└── WHERE

       │

     id = 7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The AST captures meaning—not syntax.&lt;/p&gt;




&lt;h1&gt;
  
  
  Query Planning
&lt;/h1&gt;

&lt;p&gt;Parsing tells us &lt;strong&gt;what&lt;/strong&gt; the user wants.&lt;/p&gt;

&lt;p&gt;Planning determines &lt;strong&gt;how&lt;/strong&gt; to retrieve it.&lt;/p&gt;

&lt;p&gt;Example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;

&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Planner chooses:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Full Table Scan
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Different query.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;

&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;

&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Planner may choose:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Index Scan
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Different execution.&lt;/p&gt;

&lt;p&gt;Same SQL language.&lt;/p&gt;




&lt;h1&gt;
  
  
  Query Plan
&lt;/h1&gt;

&lt;p&gt;Our first planner is extremely simple.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT

↓

Table Scan

↓

Filter

↓

Projection

↓

Results
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every database starts here.&lt;/p&gt;




&lt;h1&gt;
  
  
  Representing Plans
&lt;/h1&gt;

&lt;p&gt;Rust.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;enum&lt;/span&gt; &lt;span class="n"&gt;Plan&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="n"&gt;TableScan&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="n"&gt;Filter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="n"&gt;Projection&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Later this grows into dozens of node types.&lt;/p&gt;




&lt;h1&gt;
  
  
  Table Scan
&lt;/h1&gt;

&lt;p&gt;Suppose we have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Users

1 Derek

2 Alex

3 Sarah
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Table scan means:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Read Every Row
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Simple.&lt;/p&gt;

&lt;p&gt;Not always efficient.&lt;/p&gt;




&lt;h1&gt;
  
  
  Executing a Scan
&lt;/h1&gt;

&lt;p&gt;Rust.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="nf"&gt;.rows&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{:?}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's literally a table scan.&lt;/p&gt;




&lt;h1&gt;
  
  
  Filtering Rows
&lt;/h1&gt;

&lt;p&gt;Now suppose:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Execution becomes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Read Row

↓

Compare

↓

Keep?

↓

Yes

↓

Return
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Rust.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="py"&gt;.id&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="nf"&gt;.push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Projection
&lt;/h1&gt;

&lt;p&gt;Users often request only specific columns.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ID

Name

Email
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We return:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Projection removes unnecessary data.&lt;/p&gt;




&lt;h1&gt;
  
  
  Execution Pipeline
&lt;/h1&gt;

&lt;p&gt;Putting everything together.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Table

↓

Scan

↓

Filter

↓

Projection

↓

Results
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Modern databases still follow this concept.&lt;/p&gt;




&lt;h1&gt;
  
  
  Example Execution
&lt;/h1&gt;

&lt;p&gt;Suppose our table contains:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 Derek

2 Alex

3 Sarah
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Query.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;

&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;

&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Execution.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Read Derek

↓

No

↓

Read Alex

↓

Yes

↓

Return Alex

↓

Read Sarah

↓

No
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Supporting INSERT
&lt;/h1&gt;

&lt;p&gt;INSERT follows another execution path.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;

&lt;span class="k"&gt;VALUES&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;'Mary'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pipeline.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SQL

↓

Lexer

↓

Parser

↓

Insert AST

↓

Serialize Row

↓

Storage Engine

↓

Disk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Insert AST
&lt;/h1&gt;

&lt;p&gt;Rust.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;InsertStatement&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

        &lt;span class="nb"&gt;Vec&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Value&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Different SQL.&lt;/p&gt;

&lt;p&gt;Different AST.&lt;/p&gt;

&lt;p&gt;Same architecture.&lt;/p&gt;




&lt;h1&gt;
  
  
  Supporting CREATE TABLE
&lt;/h1&gt;

&lt;p&gt;Example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;

&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="nb"&gt;INT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="nb"&gt;TEXT&lt;/span&gt;

&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;AST.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;CreateTable&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

        &lt;span class="nb"&gt;Vec&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Column&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The catalog eventually stores this information.&lt;/p&gt;




&lt;h1&gt;
  
  
  Complete SQL Pipeline
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;             SQL

              │

              ▼

            Lexer

              │

              ▼

            Parser

              │

              ▼

             AST

              │

              ▼

       Query Planner

              │

              ▼

     Execution Engine

              │

              ▼

      Storage Engine

              │

              ▼

            Disk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every layer has a single responsibility.&lt;/p&gt;




&lt;h1&gt;
  
  
  Why Query Planners Exist
&lt;/h1&gt;

&lt;p&gt;Imagine two million users.&lt;/p&gt;

&lt;p&gt;Query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;

&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;

&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;900&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Planner has choices.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Option 1

Table Scan

2 Million Rows

-----------------

Option 2

Index Lookup

1 Row
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same answer.&lt;/p&gt;

&lt;p&gt;Massively different performance.&lt;/p&gt;

&lt;p&gt;We'll build indexes in Part 3.&lt;/p&gt;




&lt;h1&gt;
  
  
  Current Architecture
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                 SQL Client

                      │

                      ▼

                   Lexer

                      │

                      ▼

                   Parser

                      │

                      ▼

                    AST

                      │

                      ▼

                Query Planner

                      │

                      ▼

             Execution Engine

                      │

          ┌───────────┼────────────┐

          ▼           ▼            ▼

     Table Scan    Filter     Projection

                      │

                      ▼

               Storage Engine

                      │

                      ▼

                Database File
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;TinyDB is beginning to resemble a real relational database.&lt;/p&gt;




&lt;h1&gt;
  
  
  Comparing TinyDB to PostgreSQL
&lt;/h1&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Component&lt;/th&gt;
&lt;th&gt;TinyDB&lt;/th&gt;
&lt;th&gt;PostgreSQL&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Lexer&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Parser&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;AST&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Query Planner&lt;/td&gt;
&lt;td&gt;Basic&lt;/td&gt;
&lt;td&gt;Cost-Based&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Execution Engine&lt;/td&gt;
&lt;td&gt;Basic&lt;/td&gt;
&lt;td&gt;Volcano Executor&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Storage Engine&lt;/td&gt;
&lt;td&gt;Basic&lt;/td&gt;
&lt;td&gt;Advanced&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Optimizer&lt;/td&gt;
&lt;td&gt;Planned&lt;/td&gt;
&lt;td&gt;Sophisticated&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Although simplified, the architectural flow is remarkably similar.&lt;/p&gt;




&lt;h1&gt;
  
  
  What's Coming Next
&lt;/h1&gt;

&lt;p&gt;TinyDB can now understand SQL and execute simple queries.&lt;/p&gt;

&lt;p&gt;But performance is still terrible.&lt;/p&gt;

&lt;p&gt;Every lookup scans the entire table.&lt;/p&gt;

&lt;p&gt;If our database stores ten million users, finding one record means examining ten million rows.&lt;/p&gt;

&lt;p&gt;Real databases don't work that way.&lt;/p&gt;

&lt;p&gt;In Part 3, we'll solve this problem by building one of the most important data structures in computer science: the &lt;strong&gt;B-Tree&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;We'll explore clustered and secondary indexes, implement efficient key lookups, introduce a buffer manager for intelligent caching, build a Write-Ahead Log (WAL) to survive crashes, and add transactions with Multi-Version Concurrency Control (MVCC).&lt;/p&gt;

&lt;p&gt;By the end of the next article, TinyDB will begin behaving much more like PostgreSQL or MySQL, capable of handling fast queries while maintaining consistency and durability.&lt;/p&gt;




&lt;h1&gt;
  
  
  Final Thoughts
&lt;/h1&gt;

&lt;p&gt;One of the biggest surprises in building a database is discovering that SQL is only a tiny part of the system.&lt;/p&gt;

&lt;p&gt;The language itself is relatively simple.&lt;/p&gt;

&lt;p&gt;The real engineering lies in everything that happens after the parser finishes its work.&lt;/p&gt;

&lt;p&gt;A database reads text, transforms it into tokens, builds a structured representation, plans an efficient execution strategy, and finally coordinates with the storage engine to retrieve or modify data.&lt;/p&gt;

&lt;p&gt;Those stages mirror the design of compilers, interpreters, and even operating systems.&lt;/p&gt;

&lt;p&gt;Different domains.&lt;/p&gt;

&lt;p&gt;The same architectural thinking.&lt;/p&gt;

&lt;p&gt;Understanding this pipeline fundamentally changes how you write SQL.&lt;/p&gt;

&lt;p&gt;A query stops being just a string.&lt;/p&gt;

&lt;p&gt;It becomes a program that the database must parse, optimize, and execute.&lt;/p&gt;

&lt;p&gt;And once you begin thinking that way, concepts like indexes, execution plans, and query optimization become far less mysterious.&lt;/p&gt;

&lt;p&gt;Instead of seeing SQL as magic, you start seeing it for what it truly is: another elegant programming language executed by one of the most sophisticated pieces of software ever built.&lt;/p&gt;

&lt;h1&gt;
  
  
  Building Your Own SQL Database (Part 3)
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Indexes, B-Trees, Transactions, and Making TinyDB Feel Like a Real Database
&lt;/h2&gt;

&lt;p&gt;In Part 1, we built the foundation.&lt;/p&gt;

&lt;p&gt;We learned that databases are ultimately machines that transform structured information into carefully organized bytes on disk.&lt;/p&gt;

&lt;p&gt;We created:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pages&lt;/li&gt;
&lt;li&gt;Tables&lt;/li&gt;
&lt;li&gt;Serialization&lt;/li&gt;
&lt;li&gt;Storage engines&lt;/li&gt;
&lt;li&gt;Buffer pools&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In Part 2, we gave our database a language.&lt;/p&gt;

&lt;p&gt;TinyDB learned how to understand SQL.&lt;/p&gt;

&lt;p&gt;We built:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A lexer&lt;/li&gt;
&lt;li&gt;A parser&lt;/li&gt;
&lt;li&gt;An Abstract Syntax Tree&lt;/li&gt;
&lt;li&gt;A query planner&lt;/li&gt;
&lt;li&gt;An execution engine&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Our architecture evolved into:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```text id="h5d7mq"&lt;br&gt;
                SQL&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;             │

             ▼

          Parser

             │

             ▼

      Query Planner

             │

             ▼

    Execution Engine

             │

             ▼

    Storage Engine

             │

             ▼

          Disk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


But there is a major problem.

Our database is painfully slow.

Why?

Because we are searching like beginners.

---

# The Problem With Full Table Scans

Imagine we have one billion users.

Our table:



```text id="r2q5jz"
Users

1  Derek

2  Alex

3  Sarah

...

1000000000 John
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now execute:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;

&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;

&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;999999999&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our database currently does this:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```text id="f2m8qy"&lt;br&gt;
Read Row 1&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;Check&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;Read Row 2&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;Check&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;Read Row 3&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;Check&lt;/p&gt;

&lt;p&gt;...&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;Read Row 999999999&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;Found&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


This is called a **full table scan**.

Complexity:



```plaintext
O(n)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The bigger the database becomes, the slower it gets.&lt;/p&gt;

&lt;p&gt;Production databases cannot work this way.&lt;/p&gt;

&lt;p&gt;They need indexes.&lt;/p&gt;


&lt;h1&gt;
  
  
  What Is an Index?
&lt;/h1&gt;

&lt;p&gt;An index is a separate data structure designed to find information faster.&lt;/p&gt;

&lt;p&gt;Think about a dictionary.&lt;/p&gt;

&lt;p&gt;Without alphabetical ordering:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```text id="7m4z1p"&lt;br&gt;
apple&lt;/p&gt;

&lt;p&gt;zebra&lt;/p&gt;

&lt;p&gt;computer&lt;/p&gt;

&lt;p&gt;banana&lt;/p&gt;

&lt;p&gt;network&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


Finding "computer" requires checking every word.

With an index:



```text id="n8s7vz"
A

B

C  → computer

D

E
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The search becomes much faster.&lt;/p&gt;

&lt;p&gt;Databases use the same idea.&lt;/p&gt;


&lt;h1&gt;
  
  
  Database Index Architecture
&lt;/h1&gt;

&lt;p&gt;Without an index:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```text id="f0kqxa"&lt;br&gt;
Query&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;Table&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;Scan Every Row&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;Result&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


With an index:



```text id="zq2m3h"
Query

 ↓

Index

 ↓

Find Location

 ↓

Read Row

 ↓

Result
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The index acts like a roadmap.&lt;/p&gt;


&lt;h1&gt;
  
  
  Choosing the Right Data Structure
&lt;/h1&gt;

&lt;p&gt;Many structures can create indexes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Hash tables&lt;/li&gt;
&lt;li&gt;Binary trees&lt;/li&gt;
&lt;li&gt;Skip lists&lt;/li&gt;
&lt;li&gt;B-Trees&lt;/li&gt;
&lt;li&gt;B+ Trees&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Most relational databases rely heavily on B-Trees.&lt;/p&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;p&gt;Because databases are not only searching memory.&lt;/p&gt;

&lt;p&gt;They are searching disks.&lt;/p&gt;


&lt;h1&gt;
  
  
  Understanding B-Trees
&lt;/h1&gt;

&lt;p&gt;A normal binary tree looks like:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```text id="7xq4kl"&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;         50

        /  \

      25    75

     / \    / \

   10 30  60 90
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


Each node has two children.

A B-Tree expands this idea.

Instead of two children:

A node can have hundreds.



```text id="m2e8k4"

              [50|100|150]

            /      |      \

          /        |       \

     many keys  many keys  many keys
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This reduces the height of the tree.&lt;/p&gt;




&lt;h1&gt;
  
  
  Why B-Trees Are Perfect for Databases
&lt;/h1&gt;

&lt;p&gt;Disk access is expensive.&lt;/p&gt;

&lt;p&gt;Imagine:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```text id="u8b3s1"&lt;br&gt;
Memory&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;Fast&lt;/p&gt;

&lt;p&gt;Disk&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;Slow&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


A binary tree with one billion records might require many disk reads.

A B-Tree keeps the height small.

Example:



```plaintext
B-Tree height: 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;One lookup:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Root
 ↓
Child
 ↓
Leaf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Only a few disk operations.&lt;/p&gt;




&lt;h1&gt;
  
  
  Building Our B-Tree
&lt;/h1&gt;

&lt;p&gt;Let's create a simplified version.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```rust id="w8j3fr"&lt;br&gt;
pub struct BTreeNode {&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pub keys: Vec&amp;lt;u64&amp;gt;,

pub children:

    Vec&amp;lt;u64&amp;gt;,

pub leaf: bool,
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


Each node stores:

* Keys
* Child pointers
* Whether it is a leaf

---

# Example Index

Suppose we insert:



```plaintext
10
20
30
40
50
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Our tree:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```text id="g2a9pm"&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;          [30]

         /    \

   [10|20]   [40|50]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


Searching:



```plaintext
Find 40

↓

Compare with 30

↓

Go right

↓

Find 40
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Much faster.&lt;/p&gt;




&lt;h1&gt;
  
  
  Index Lookup Flow
&lt;/h1&gt;



&lt;p&gt;```text id="j5w0pk"&lt;br&gt;
SELECT *&lt;/p&gt;

&lt;p&gt;WHERE id = 50;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    SQL

     │

     ▼

   Planner

     │

     ▼

   Index

     │

     ▼

B-Tree Search

     │

     ▼

Row Location

     │

     ▼

   Table
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


---

# Adding Indexes to TinyDB

Our table now becomes:



```text id="4q1q5n"
Table

 ┌──────────────┐

 │ Rows         │

 └──────────────┘


 Index

 ┌──────────────┐

 │ B-Tree       │

 └──────────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The index does not replace data.&lt;/p&gt;

&lt;p&gt;It points to data.&lt;/p&gt;


&lt;h1&gt;
  
  
  Storing Row Locations
&lt;/h1&gt;

&lt;p&gt;Instead of storing complete rows:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```text id="j8g6mb"&lt;br&gt;
50 → Derek&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


We store:



```text id="c7v1zq"
50 → Page 15 Offset 200
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Then:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Find location

↓

Read page

↓

Return row
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Implementing Index Entries
&lt;/h1&gt;

&lt;p&gt;Rust:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```rust id="w4d0kr"&lt;br&gt;
pub struct IndexEntry {&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pub key: u64,

pub page_id: u32,

pub offset: usize,
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


The index becomes a navigation system.

---

# The Need for Transactions

Indexes solve searching.

But databases have another massive problem:

Multiple users changing data at the same time.

Imagine:

User A:



```sql
UPDATE accounts

SET balance=500;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;User B:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt;

&lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;700&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Who wins?&lt;/p&gt;




&lt;h1&gt;
  
  
  The Lost Update Problem
&lt;/h1&gt;

&lt;p&gt;Timeline:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```text id="z7j1qm"&lt;/p&gt;

&lt;p&gt;User A&lt;/p&gt;

&lt;p&gt;Reads balance = 100&lt;/p&gt;

&lt;p&gt;User B&lt;/p&gt;

&lt;p&gt;Reads balance = 100&lt;/p&gt;

&lt;p&gt;User A&lt;/p&gt;

&lt;p&gt;Writes 500&lt;/p&gt;

&lt;p&gt;User B&lt;/p&gt;

&lt;p&gt;Writes 700&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


Final result:



```plaintext
700
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;User A's update disappeared.&lt;/p&gt;

&lt;p&gt;This is a concurrency problem.&lt;/p&gt;




&lt;h1&gt;
  
  
  Introducing Transactions
&lt;/h1&gt;

&lt;p&gt;A transaction groups operations into one logical unit.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;BEGIN&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt;

&lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;COMMIT&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A transaction provides:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Atomicity&lt;/li&gt;
&lt;li&gt;Consistency&lt;/li&gt;
&lt;li&gt;Isolation&lt;/li&gt;
&lt;li&gt;Durability&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The famous ACID properties.&lt;/p&gt;




&lt;h1&gt;
  
  
  Transaction Lifecycle
&lt;/h1&gt;



&lt;p&gt;```text id="k2x8pq"&lt;/p&gt;

&lt;p&gt;BEGIN&lt;/p&gt;

&lt;p&gt;|&lt;/p&gt;

&lt;p&gt;|&lt;/p&gt;

&lt;p&gt;Perform Operations&lt;/p&gt;

&lt;p&gt;|&lt;/p&gt;

&lt;p&gt;|&lt;/p&gt;

&lt;p&gt;COMMIT&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


Or:



```text id="m4v2zd"

BEGIN

 |

 |

Error

 |

 |

ROLLBACK

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Transaction Manager
&lt;/h1&gt;

&lt;p&gt;We add:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```rust id="p1q6lm"&lt;br&gt;
pub struct Transaction {&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pub id: u64,

pub state: State,
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


The database tracks active operations.

---

# Write-Ahead Logging (WAL)

What happens if the computer crashes?

Imagine:



```plaintext
Update balance

↓

Write to memory

↓

Power failure
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The change disappears.&lt;/p&gt;

&lt;p&gt;Databases solve this using WAL.&lt;/p&gt;


&lt;h1&gt;
  
  
  The WAL Principle
&lt;/h1&gt;

&lt;p&gt;Before changing the database:&lt;/p&gt;

&lt;p&gt;Write the intention to a log.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```text id="y9p4nv"&lt;/p&gt;

&lt;p&gt;Transaction:&lt;/p&gt;

&lt;p&gt;Change user 5 balance&lt;/p&gt;

&lt;p&gt;Before:&lt;/p&gt;

&lt;p&gt;1000&lt;/p&gt;

&lt;p&gt;After:&lt;/p&gt;

&lt;p&gt;900&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


Then:



```plaintext
Write log

↓

Modify database
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  WAL Architecture
&lt;/h1&gt;



&lt;p&gt;```text id="a7x2qm"&lt;/p&gt;

&lt;p&gt;Application&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; |

 ▼
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Transaction&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; |

 ▼
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Write Ahead Log&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; |

 ▼
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Database Pages&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


The log is the source of truth during recovery.

---

# WAL Implementation

A simple log entry:



```rust id="s8x9jk"
pub struct LogEntry {

    pub transaction_id: u64,

    pub page_id: u32,

    pub before:

    Vec&amp;lt;u8&amp;gt;,

    pub after:

    Vec&amp;lt;u8&amp;gt;,

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Crash Recovery
&lt;/h1&gt;

&lt;p&gt;Imagine:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```text id="c4q9hz"&lt;/p&gt;

&lt;p&gt;Transaction starts&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;Write WAL&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;Update page&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;Crash&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


On restart:

Database reads WAL:



```text id="f9v6kx"

Find unfinished transaction

↓

Redo changes

or

Undo changes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The database repairs itself.&lt;/p&gt;




&lt;h1&gt;
  
  
  Buffer Management Becomes More Important
&lt;/h1&gt;

&lt;p&gt;Now we have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tables&lt;/li&gt;
&lt;li&gt;Pages&lt;/li&gt;
&lt;li&gt;Indexes&lt;/li&gt;
&lt;li&gt;Transactions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Memory becomes critical.&lt;/p&gt;

&lt;p&gt;Our buffer pool now manages:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```text id="r7n2wm"&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;          Buffer Pool
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;+--------------------------+&lt;/p&gt;

&lt;p&gt;| Page 1                   |&lt;/p&gt;

&lt;p&gt;| Page 2                   |&lt;/p&gt;

&lt;p&gt;| Page 3                   |&lt;/p&gt;

&lt;p&gt;| Page 4                   |&lt;/p&gt;

&lt;p&gt;+--------------------------+&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


When memory is full:

Which page leaves?

---

# LRU Cache

Most databases use variations of:

Least Recently Used.

Idea:

Remove pages nobody is using.

Example:



```text id="v5b8df"

Recently Used

↓

Page A

Page B

Page C

↓

Old

Page D

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Page D gets removed.&lt;/p&gt;




&lt;h1&gt;
  
  
  Updated TinyDB Architecture
&lt;/h1&gt;

&lt;p&gt;Our database has grown.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```text id="r8x2kp"&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                 SQL

                  |

                  ▼

            Query Engine

                  |

                  ▼

           Query Planner

                  |

      ┌───────────┴───────────┐

      ▼                       ▼

  Table Scan              Index Scan

      |                       |

      └───────────┬───────────┘

                  ▼

           Transaction Layer

                  |

                  ▼

             Buffer Pool

                  |

      ┌───────────┴───────────┐

      ▼                       ▼

    WAL                 Storage Engine

                              |

                              ▼

                            Disk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


This is now starting to resemble a real database.

---

# What We Have Built

TinyDB now supports:

✅ Persistent storage

✅ Pages

✅ Tables

✅ SQL parsing

✅ Query execution

✅ B-Tree indexes

✅ Faster lookups

✅ Transactions

✅ WAL logging

✅ Crash recovery foundation

The system has evolved from a file writer into a real database engine.

---

# What Comes Next

There is still one major challenge.

Concurrency.

Right now, transactions exist, but they are still limited.

What happens when:

* Thousands of users read simultaneously?
* Multiple transactions update the same rows?
* Long-running queries overlap?
* Data changes while another transaction is reading?

Real databases solve this with **MVCC — Multi-Version Concurrency Control**.

In Part 4, we will build:

* Row versions
* Snapshots
* Isolation levels
* Garbage collection
* Concurrent reads and writes
* A PostgreSQL-style MVCC system

This is where TinyDB becomes truly powerful.

---

# Final Thoughts

Building indexes and transactions changed the way I think about databases.

A database is not simply a place where data lives.

It is an intelligent system constantly balancing competing goals:

* Speed
* Safety
* Consistency
* Reliability
* Scalability

An index sacrifices storage space to gain speed.

A transaction sacrifices simplicity to gain correctness.

A WAL sacrifices extra writes to gain durability.

Every database feature is a carefully engineered trade-off.

The beauty of database engineering is that there is rarely a perfect solution.

There are only intelligent compromises.

And understanding those compromises is what separates someone who uses databases from someone who can design them.





# Building Your Own SQL Database (Part 4)

## MVCC, Isolation, and Making TinyDB a Truly Concurrent Database

In the previous parts, we transformed TinyDB from a simple file storage system into a small relational database engine.

We started with bytes.

Then we built:

* Storage pages
* Tables
* Serialization
* Buffer pools
* SQL parsing
* Query execution
* Query planning
* B-Tree indexes
* Transactions
* Write-Ahead Logging

Our architecture now looks like this:



```text
                         SQL

                          │

                          ▼

                    Query Engine

                          │

                          ▼

                    Query Planner

                          │

          ┌───────────────┴────────────────┐

          ▼                                ▼

     Index Scan                      Table Scan

          │                                │

          └───────────────┬────────────────┘

                          ▼

                  Transaction Manager

                          │

                          ▼

                       Buffer Pool

                          │

              ┌───────────┴───────────┐

              ▼                       ▼

             WAL              Storage Engine

                                      │

                                      ▼

                                    Disk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But there is still a fundamental problem.&lt;/p&gt;

&lt;p&gt;Our database works.&lt;/p&gt;

&lt;p&gt;It stores data.&lt;/p&gt;

&lt;p&gt;It executes queries.&lt;/p&gt;

&lt;p&gt;It survives crashes.&lt;/p&gt;

&lt;p&gt;But it struggles with something every modern database must handle:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thousands of users doing things at the same time.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Imagine an online banking system.&lt;/p&gt;

&lt;p&gt;One user checks their balance.&lt;/p&gt;

&lt;p&gt;Another user transfers money.&lt;/p&gt;

&lt;p&gt;A third user receives a payment.&lt;/p&gt;

&lt;p&gt;All at the same time.&lt;/p&gt;

&lt;p&gt;How does the database make sure everyone sees correct information?&lt;/p&gt;

&lt;p&gt;This is where one of the most beautiful ideas in database engineering appears.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Multi-Version Concurrency Control.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;MVCC.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Concurrency Problem
&lt;/h1&gt;

&lt;p&gt;Let's imagine a simple table.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Accounts

+----+---------+

| ID | Balance |

+----+---------+

| 1  | 1000    |

+----+---------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two transactions start.&lt;/p&gt;

&lt;p&gt;Transaction A:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt;

&lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;900&lt;/span&gt;

&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Transaction B:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt;

&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt;

&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What should B see?&lt;/p&gt;

&lt;p&gt;1000?&lt;/p&gt;

&lt;p&gt;900?&lt;/p&gt;

&lt;p&gt;Something else?&lt;/p&gt;

&lt;p&gt;The database needs rules.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Old Solution: Locks
&lt;/h1&gt;

&lt;p&gt;The traditional approach is locking.&lt;/p&gt;

&lt;p&gt;Transaction A locks the row.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Transaction A

       │

       ▼

   Lock Row

       │

       ▼

   Update Data

       │

       ▼

   Unlock
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Transaction B waits.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Transaction B

       │

       ▼

    Waiting...

       │

       ▼

    Read Data
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This works.&lt;/p&gt;

&lt;p&gt;But it creates problems.&lt;/p&gt;




&lt;h1&gt;
  
  
  Why Locks Become Difficult
&lt;/h1&gt;

&lt;p&gt;Imagine thousands of users.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User 1 ─┐

User 2 ─┤

User 3 ─┤── Waiting

User 4 ─┤

User 5 ─┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The database becomes a traffic jam.&lt;/p&gt;

&lt;p&gt;Readers block readers.&lt;/p&gt;

&lt;p&gt;Readers block writers.&lt;/p&gt;

&lt;p&gt;Writers block readers.&lt;/p&gt;

&lt;p&gt;The system spends more time coordinating than working.&lt;/p&gt;




&lt;h1&gt;
  
  
  The MVCC Idea
&lt;/h1&gt;

&lt;p&gt;MVCC takes a completely different approach.&lt;/p&gt;

&lt;p&gt;Instead of changing data:&lt;/p&gt;

&lt;p&gt;Create a new version.&lt;/p&gt;

&lt;p&gt;Old data stays.&lt;/p&gt;

&lt;p&gt;New data appears.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;Before:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Account

Balance = 1000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After update:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Version 1

Balance = 1000


Version 2

Balance = 900
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both versions exist.&lt;/p&gt;

&lt;p&gt;The database decides which one each transaction can see.&lt;/p&gt;




&lt;h1&gt;
  
  
  Data Becomes a Timeline
&lt;/h1&gt;

&lt;p&gt;Traditional thinking:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Row = Current Value
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;MVCC thinking:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Row = History of Values
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Time

────────────────────────────►


Version 1

Balance = 1000


        Update


Version 2

Balance = 900
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The database becomes aware of time.&lt;/p&gt;




&lt;h1&gt;
  
  
  Adding Versions to Rows
&lt;/h1&gt;

&lt;p&gt;Previously our row looked like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;Row&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Vec&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;u8&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;VersionedRow&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Vec&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;u8&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;created_tx&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;deleted_tx&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Option&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;u64&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every row knows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When it appeared&lt;/li&gt;
&lt;li&gt;When it disappeared&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  Transaction IDs
&lt;/h1&gt;

&lt;p&gt;Every transaction receives an identifier.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Transaction 1

Transaction 2

Transaction 3

Transaction 4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Rust:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;Transaction&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These IDs allow the database to understand history.&lt;/p&gt;




&lt;h1&gt;
  
  
  Creating a Snapshot
&lt;/h1&gt;

&lt;p&gt;When a transaction begins:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;BEGIN TRANSACTION

        │

        ▼

Create Snapshot

        │

        ▼

Execute Queries
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The snapshot defines what data is visible.&lt;/p&gt;




&lt;h1&gt;
  
  
  Example Snapshot
&lt;/h1&gt;

&lt;p&gt;Database:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Version 1

Name = Derek

Created = 1


Version 2

Name = Alex

Created = 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Transaction 3 starts.&lt;/p&gt;

&lt;p&gt;It sees:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Derek
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Transaction 6 starts.&lt;/p&gt;

&lt;p&gt;It sees:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Alex
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same database.&lt;/p&gt;

&lt;p&gt;Different realities.&lt;/p&gt;




&lt;h1&gt;
  
  
  Visibility Rules
&lt;/h1&gt;

&lt;p&gt;A version is visible if:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;created_tx &amp;lt;= transaction_id
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;deleted_tx &amp;gt; transaction_id
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;deleted_tx does not exist
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In simple terms:&lt;/p&gt;

&lt;p&gt;"The row existed during this transaction."&lt;/p&gt;




&lt;h1&gt;
  
  
  Implementing Visibility
&lt;/h1&gt;

&lt;p&gt;Rust:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;impl&lt;/span&gt; &lt;span class="n"&gt;VersionedRow&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;visible&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;

        &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

        &lt;span class="n"&gt;tx_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u64&lt;/span&gt;

    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;


        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.created_tx&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;tx_id&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="p"&gt;}&lt;/span&gt;


        &lt;span class="k"&gt;match&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.deleted_tx&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

            &lt;span class="nf"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;delete_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

                &lt;span class="n"&gt;tx_id&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;delete_id&lt;/span&gt;

            &lt;span class="p"&gt;}&lt;/span&gt;


            &lt;span class="nb"&gt;None&lt;/span&gt; &lt;span class="k"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

        &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This tiny function is the heart of MVCC.&lt;/p&gt;




&lt;h1&gt;
  
  
  Updating Data in MVCC
&lt;/h1&gt;

&lt;p&gt;Traditional database:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Modify existing row
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;MVCC:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Create new version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;Before:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ID

1

Name

Derek
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Update:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;

&lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'Alex'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Version 1

Derek

Created: 1

Deleted: 8



Version 2

Alex

Created: 8

Deleted: NULL
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nothing was overwritten.&lt;/p&gt;




&lt;h1&gt;
  
  
  Delete Operations
&lt;/h1&gt;

&lt;p&gt;Deletion works the same way.&lt;/p&gt;

&lt;p&gt;Traditional:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Remove row
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;MVCC:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Mark version invisible
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Before:


User

Derek



After:


User

Derek

Deleted Transaction = 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Old transactions can still see Derek.&lt;/p&gt;

&lt;p&gt;New transactions cannot.&lt;/p&gt;




&lt;h1&gt;
  
  
  Reading With MVCC
&lt;/h1&gt;

&lt;p&gt;A query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;

&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;becomes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Read all versions

        │

        ▼

Check visibility

        │

        ▼

Return visible versions
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="n"&gt;rows&lt;/span&gt;
&lt;span class="nf"&gt;.iter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nf"&gt;.filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
 &lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt;

 &lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="nf"&gt;.visible&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;transaction&lt;/span&gt;&lt;span class="py"&gt;.id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Handling Multiple Writers
&lt;/h1&gt;

&lt;p&gt;Now imagine:&lt;/p&gt;

&lt;p&gt;Transaction A:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Creates Version 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Transaction B:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Creates Version 6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both changes exist.&lt;/p&gt;

&lt;p&gt;The database later decides whether conflicts exist.&lt;/p&gt;




&lt;h1&gt;
  
  
  Isolation Levels
&lt;/h1&gt;

&lt;p&gt;Databases offer different levels of isolation.&lt;/p&gt;

&lt;p&gt;The most common:&lt;/p&gt;

&lt;h2&gt;
  
  
  Read Uncommitted
&lt;/h2&gt;

&lt;p&gt;You can see changes before they are committed.&lt;/p&gt;

&lt;p&gt;Fast.&lt;/p&gt;

&lt;p&gt;Dangerous.&lt;/p&gt;




&lt;h2&gt;
  
  
  Read Committed
&lt;/h2&gt;

&lt;p&gt;Only committed data is visible.&lt;/p&gt;

&lt;p&gt;Most common default.&lt;/p&gt;




&lt;h2&gt;
  
  
  Repeatable Read
&lt;/h2&gt;

&lt;p&gt;A transaction sees the same data throughout its lifetime.&lt;/p&gt;




&lt;h2&gt;
  
  
  Serializable
&lt;/h2&gt;

&lt;p&gt;Transactions behave as if executed one by one.&lt;/p&gt;

&lt;p&gt;Safest.&lt;/p&gt;

&lt;p&gt;Slowest.&lt;/p&gt;




&lt;h1&gt;
  
  
  Adding Isolation to TinyDB
&lt;/h1&gt;

&lt;p&gt;Transaction state:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;enum&lt;/span&gt; &lt;span class="n"&gt;IsolationLevel&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="n"&gt;ReadCommitted&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="n"&gt;RepeatableRead&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="n"&gt;Serializable&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The visibility engine changes behavior depending on this choice.&lt;/p&gt;




&lt;h1&gt;
  
  
  MVCC Storage Layout
&lt;/h1&gt;

&lt;p&gt;Our storage engine changes.&lt;/p&gt;

&lt;p&gt;Before:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Page

 ├── Row

 ├── Row

 └── Row
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Page


 ├── Row Version

 │       └── Previous Version


 ├── Row Version

 │       └── Previous Version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;History becomes part of storage.&lt;/p&gt;




&lt;h1&gt;
  
  
  Version Chains
&lt;/h1&gt;

&lt;p&gt;Many databases organize versions as chains.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Newest

  │

  ▼

Version 3

  │

  ▼

Version 2

  │

  ▼

Version 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The database walks backward until it finds a visible version.&lt;/p&gt;




&lt;h1&gt;
  
  
  Garbage Collection
&lt;/h1&gt;

&lt;p&gt;A problem appears.&lt;/p&gt;

&lt;p&gt;If every update creates a new version forever:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Derek

↓

Alex

↓

John

↓

Mary

↓

...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Storage grows endlessly.&lt;/p&gt;

&lt;p&gt;We need cleanup.&lt;/p&gt;




&lt;h1&gt;
  
  
  Vacuuming
&lt;/h1&gt;

&lt;p&gt;Databases periodically remove old versions.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Version 1

No transaction needs it

        │

        ▼

Delete
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;PostgreSQL calls this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;VACUUM
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Implementing Simple Cleanup
&lt;/h1&gt;

&lt;p&gt;We track active transactions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;TransactionManager&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="n"&gt;active&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

    &lt;span class="nb"&gt;Vec&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;u64&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Find the oldest active transaction:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Oldest Active = 50
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Any version deleted before 50 can disappear.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Complete Database Architecture
&lt;/h1&gt;

&lt;p&gt;TinyDB is now a real database engine.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                         SQL

                          │

                          ▼

                    SQL Parser

                          │

                          ▼

                  Query Optimizer

                          │

                          ▼

                 Execution Engine

                          │

                          ▼

              Transaction Manager

                          │

              ┌───────────┴───────────┐

              ▼                       ▼

             MVCC                    WAL


              │                       │

              └───────────┬───────────┘

                          ▼

                    Buffer Pool

                          │

                          ▼

                  Storage Engine

                          │

                          ▼

                         Disk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  What We Have Built
&lt;/h1&gt;

&lt;p&gt;After four parts, TinyDB contains the fundamental ideas behind modern relational databases:&lt;/p&gt;

&lt;h2&gt;
  
  
  Storage
&lt;/h2&gt;

&lt;p&gt;✓ Pages&lt;br&gt;
✓ Serialization&lt;br&gt;
✓ Tables&lt;br&gt;
✓ Disk persistence&lt;/p&gt;
&lt;h2&gt;
  
  
  Query Processing
&lt;/h2&gt;

&lt;p&gt;✓ SQL lexer&lt;br&gt;
✓ Parser&lt;br&gt;
✓ AST&lt;br&gt;
✓ Query planner&lt;br&gt;
✓ Execution engine&lt;/p&gt;
&lt;h2&gt;
  
  
  Performance
&lt;/h2&gt;

&lt;p&gt;✓ Buffer pool&lt;br&gt;
✓ B-Tree indexes&lt;br&gt;
✓ Efficient lookups&lt;/p&gt;
&lt;h2&gt;
  
  
  Reliability
&lt;/h2&gt;

&lt;p&gt;✓ Transactions&lt;br&gt;
✓ WAL logging&lt;br&gt;
✓ Crash recovery&lt;/p&gt;
&lt;h2&gt;
  
  
  Concurrency
&lt;/h2&gt;

&lt;p&gt;✓ MVCC&lt;br&gt;
✓ Snapshots&lt;br&gt;
✓ Isolation levels&lt;br&gt;
✓ Version cleanup&lt;/p&gt;


&lt;h1&gt;
  
  
  Comparing TinyDB With Real Databases
&lt;/h1&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;TinyDB&lt;/th&gt;
&lt;th&gt;PostgreSQL&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;SQL Parser&lt;/td&gt;
&lt;td&gt;Basic&lt;/td&gt;
&lt;td&gt;Advanced&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Storage Engine&lt;/td&gt;
&lt;td&gt;Simple&lt;/td&gt;
&lt;td&gt;Highly optimized&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Indexes&lt;/td&gt;
&lt;td&gt;B-Tree&lt;/td&gt;
&lt;td&gt;Multiple types&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Transactions&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;WAL&lt;/td&gt;
&lt;td&gt;Basic&lt;/td&gt;
&lt;td&gt;Advanced&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;MVCC&lt;/td&gt;
&lt;td&gt;Basic&lt;/td&gt;
&lt;td&gt;Advanced&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Query Optimizer&lt;/td&gt;
&lt;td&gt;Simple&lt;/td&gt;
&lt;td&gt;Cost-based&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Replication&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The difference is not the fundamental ideas.&lt;/p&gt;

&lt;p&gt;The difference is years of optimization.&lt;/p&gt;


&lt;h1&gt;
  
  
  Lessons From Building a Database
&lt;/h1&gt;

&lt;p&gt;Building TinyDB taught me something important.&lt;/p&gt;

&lt;p&gt;The hardest part of software engineering is rarely writing code.&lt;/p&gt;

&lt;p&gt;The hardest part is managing complexity.&lt;/p&gt;

&lt;p&gt;A database solves hundreds of difficult problems:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How do we store information?&lt;/li&gt;
&lt;li&gt;How do we find it quickly?&lt;/li&gt;
&lt;li&gt;How do we survive failures?&lt;/li&gt;
&lt;li&gt;How do we support thousands of users?&lt;/li&gt;
&lt;li&gt;How do we prevent corruption?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The answer is not one giant algorithm.&lt;/p&gt;

&lt;p&gt;It is thousands of small engineering decisions working together.&lt;/p&gt;


&lt;h1&gt;
  
  
  Final Thoughts
&lt;/h1&gt;

&lt;p&gt;A database is not just a storage system.&lt;/p&gt;

&lt;p&gt;It is a carefully designed machine for managing reality.&lt;/p&gt;

&lt;p&gt;It remembers the past through MVCC.&lt;/p&gt;

&lt;p&gt;It protects the future through transactions.&lt;/p&gt;

&lt;p&gt;It accelerates the present through indexes and caching.&lt;/p&gt;

&lt;p&gt;Every SQL query is the result of decades of engineering research hidden behind a few simple words.&lt;/p&gt;

&lt;p&gt;When you write:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you are not just reading data.&lt;/p&gt;

&lt;p&gt;You are interacting with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A parser&lt;/li&gt;
&lt;li&gt;A planner&lt;/li&gt;
&lt;li&gt;An optimizer&lt;/li&gt;
&lt;li&gt;A transaction system&lt;/li&gt;
&lt;li&gt;A concurrency engine&lt;/li&gt;
&lt;li&gt;A storage engine&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Building your own database reveals the hidden world underneath everyday software.&lt;/p&gt;

&lt;p&gt;And perhaps the biggest lesson is this:&lt;/p&gt;

&lt;p&gt;Great systems are not built by making things complicated.&lt;/p&gt;

&lt;p&gt;They are built by taking complicated problems and organizing them into simple, understandable layers.&lt;/p&gt;

</description>
      <category>database</category>
      <category>software</category>
      <category>softwaredevelopment</category>
      <category>api</category>
    </item>
    <item>
      <title>Building Reliable UDP</title>
      <dc:creator>Derek mwale</dc:creator>
      <pubDate>Mon, 03 Aug 2026 23:20:28 +0000</pubDate>
      <link>https://dev.to/derekmwale/building-reliable-udp-51ei</link>
      <guid>https://dev.to/derekmwale/building-reliable-udp-51ei</guid>
      <description>&lt;h2&gt;
  
  
  How to Turn an Unreliable Protocol into One You Can Trust
&lt;/h2&gt;

&lt;p&gt;When most developers think about networking, they immediately think of &lt;strong&gt;TCP&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;After all, TCP powers web browsing, APIs, databases, email, and countless distributed systems. It guarantees that data arrives in order, without duplication, and without corruption.&lt;/p&gt;

&lt;p&gt;But there's another protocol that quietly powers some of the fastest systems in the world.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;UDP.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Online multiplayer games.&lt;/p&gt;

&lt;p&gt;Live video streaming.&lt;/p&gt;

&lt;p&gt;Voice-over-IP.&lt;/p&gt;

&lt;p&gt;DNS.&lt;/p&gt;

&lt;p&gt;IoT devices.&lt;/p&gt;

&lt;p&gt;Real-time telemetry.&lt;/p&gt;

&lt;p&gt;These systems often choose UDP instead of TCP.&lt;/p&gt;

&lt;p&gt;At first, that decision seems strange.&lt;/p&gt;

&lt;p&gt;UDP doesn't guarantee delivery.&lt;/p&gt;

&lt;p&gt;It doesn't guarantee order.&lt;/p&gt;

&lt;p&gt;It doesn't prevent duplicates.&lt;/p&gt;

&lt;p&gt;It doesn't even tell you whether the receiver exists.&lt;/p&gt;

&lt;p&gt;It simply sends packets into the network and hopes for the best.&lt;/p&gt;

&lt;p&gt;That sounds terrifying.&lt;/p&gt;

&lt;p&gt;So why do engineers keep using it?&lt;/p&gt;

&lt;p&gt;Because UDP gives us something incredibly valuable:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Control.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Instead of accepting TCP's built-in reliability mechanisms, we can design our own—optimized for our specific application.&lt;/p&gt;

&lt;p&gt;When I first learned about reliable UDP, I assumed it was an entirely different protocol.&lt;/p&gt;

&lt;p&gt;Then I discovered something fascinating.&lt;/p&gt;

&lt;p&gt;Reliable UDP isn't a protocol.&lt;/p&gt;

&lt;p&gt;It's an &lt;strong&gt;engineering pattern&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;You're essentially rebuilding some of TCP's capabilities, but only the parts you actually need.&lt;/p&gt;

&lt;p&gt;Let's build one from scratch.&lt;/p&gt;




&lt;h1&gt;
  
  
  Understanding UDP
&lt;/h1&gt;

&lt;p&gt;Imagine writing a letter and throwing it into the wind.&lt;/p&gt;

&lt;p&gt;Maybe it reaches its destination.&lt;/p&gt;

&lt;p&gt;Maybe it doesn't.&lt;/p&gt;

&lt;p&gt;That's UDP.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Application

      │

      ▼

UDP Socket

      │

      ▼

Network

      │

      ▼

Receiver
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is no handshake.&lt;/p&gt;

&lt;p&gt;No confirmation.&lt;/p&gt;

&lt;p&gt;No guarantee.&lt;/p&gt;




&lt;h1&gt;
  
  
  Why Would Anyone Use UDP?
&lt;/h1&gt;

&lt;p&gt;Because guarantees come with costs.&lt;/p&gt;

&lt;p&gt;TCP introduces:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Connection setup&lt;/li&gt;
&lt;li&gt;Congestion control&lt;/li&gt;
&lt;li&gt;Flow control&lt;/li&gt;
&lt;li&gt;Retransmissions&lt;/li&gt;
&lt;li&gt;Ordered delivery&lt;/li&gt;
&lt;li&gt;Head-of-line blocking&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sometimes those features are exactly what we want.&lt;/p&gt;

&lt;p&gt;Sometimes they're unnecessary.&lt;/p&gt;

&lt;p&gt;Imagine an online shooter game.&lt;/p&gt;

&lt;p&gt;If a player's position update is lost...&lt;/p&gt;

&lt;p&gt;Sending the old position two seconds later is useless.&lt;/p&gt;

&lt;p&gt;The next update will replace it anyway.&lt;/p&gt;

&lt;p&gt;UDP excels in these situations.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Problem
&lt;/h1&gt;

&lt;p&gt;Suppose we send five packets.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Packet 1

Packet 2

Packet 3

Packet 4

Packet 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The network delivers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Packet 1

Packet 2

Packet 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Packets 3 and 4 disappear.&lt;/p&gt;

&lt;p&gt;UDP simply moves on.&lt;/p&gt;




&lt;h1&gt;
  
  
  Designing Reliable UDP
&lt;/h1&gt;

&lt;p&gt;Instead of hoping every packet arrives, we'll build several mechanisms ourselves.&lt;/p&gt;

&lt;p&gt;Our protocol will support:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sequence numbers&lt;/li&gt;
&lt;li&gt;Acknowledgements&lt;/li&gt;
&lt;li&gt;Retransmissions&lt;/li&gt;
&lt;li&gt;Timeouts&lt;/li&gt;
&lt;li&gt;Sliding windows&lt;/li&gt;
&lt;li&gt;Duplicate detection&lt;/li&gt;
&lt;li&gt;Packet ordering&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Together, these transform UDP into a dependable transport layer.&lt;/p&gt;




&lt;h1&gt;
  
  
  Packet Structure
&lt;/h1&gt;

&lt;p&gt;We'll begin by designing our own packet format.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;+--------------------------------+

| Sequence Number |

+--------------------------------+

| Acknowledgement |

+--------------------------------+

| Flags |

+--------------------------------+

| Payload |

+--------------------------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every field serves a purpose.&lt;/p&gt;




&lt;h1&gt;
  
  
  Rust Representation
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;Packet&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;sequence&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;acknowledgement&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;flags&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Vec&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;u8&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice that we've added metadata on top of UDP.&lt;/p&gt;

&lt;p&gt;This metadata is entirely ours.&lt;/p&gt;




&lt;h1&gt;
  
  
  Sequence Numbers
&lt;/h1&gt;

&lt;p&gt;Every outgoing packet receives an increasing identifier.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Packet 1

Sequence = 1

------------------

Packet 2

Sequence = 2

------------------

Packet 3

Sequence = 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the receiver knows exactly which packet it received.&lt;/p&gt;




&lt;h1&gt;
  
  
  Sending Packets
&lt;/h1&gt;

&lt;p&gt;Our sender keeps track of the next sequence.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;packet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Packet&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="n"&gt;sequence&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;next_sequence&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="n"&gt;acknowledgement&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="n"&gt;flags&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="n"&gt;next_sequence&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Simple.&lt;/p&gt;

&lt;p&gt;But incredibly important.&lt;/p&gt;




&lt;h1&gt;
  
  
  Why Sequence Numbers Matter
&lt;/h1&gt;

&lt;p&gt;Imagine receiving:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;5

6

8
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We immediately know:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Packet 7

Missing
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Without sequence numbers, missing packets are invisible.&lt;/p&gt;




&lt;h1&gt;
  
  
  Acknowledgements
&lt;/h1&gt;

&lt;p&gt;The receiver confirms successful delivery.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Sender

↓

Packet 10

↓

Receiver

↓

ACK 10

↓

Sender
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once acknowledged, the sender removes the packet from memory.&lt;/p&gt;




&lt;h1&gt;
  
  
  Packet Flow
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Sender

Packet 12

──────────────►

Receiver

ACK 12

◄──────────────
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Communication becomes two-way.&lt;/p&gt;




&lt;h1&gt;
  
  
  Detecting Lost Packets
&lt;/h1&gt;

&lt;p&gt;Suppose this happens.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Packet 13

──────────────►

Lost
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No acknowledgement arrives.&lt;/p&gt;

&lt;p&gt;Eventually...&lt;/p&gt;

&lt;p&gt;The sender concludes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Packet Lost
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Retransmission Timer
&lt;/h1&gt;

&lt;p&gt;Every sent packet starts a timer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Packet Sent

↓

Timer Starts

↓

ACK Received?

↓

Yes → Done

↓

No

↓

Resend Packet
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This mechanism alone dramatically improves reliability.&lt;/p&gt;




&lt;h1&gt;
  
  
  Tracking Outstanding Packets
&lt;/h1&gt;

&lt;p&gt;Rust.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;std&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;collections&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;HashMap&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;pending&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

&lt;span class="n"&gt;HashMap&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;u32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Packet&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Whenever an ACK arrives:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="n"&gt;pending&lt;/span&gt;&lt;span class="nf"&gt;.remove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;ack_number&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Only unacknowledged packets remain.&lt;/p&gt;




&lt;h1&gt;
  
  
  Timeouts
&lt;/h1&gt;

&lt;p&gt;Choosing timeout values is surprisingly important.&lt;/p&gt;

&lt;p&gt;Too short.&lt;/p&gt;

&lt;p&gt;You resend unnecessarily.&lt;/p&gt;

&lt;p&gt;Too long.&lt;/p&gt;

&lt;p&gt;Recovery becomes slow.&lt;/p&gt;

&lt;p&gt;Typical logic:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Send Packet

↓

Wait 500 ms

↓

ACK?

↓

No

↓

Retransmit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Real protocols adapt this dynamically.&lt;/p&gt;




&lt;h1&gt;
  
  
  Duplicate Packets
&lt;/h1&gt;

&lt;p&gt;Networks sometimes duplicate packets.&lt;/p&gt;

&lt;p&gt;Example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Packet 20

↓

Receiver

↓

Packet 20

↓

Receiver
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The receiver must ignore duplicates.&lt;/p&gt;




&lt;h1&gt;
  
  
  Duplicate Detection
&lt;/h1&gt;

&lt;p&gt;Keep track of processed sequence numbers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="n"&gt;HashSet&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;u32&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When a packet arrives:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;received&lt;/span&gt;&lt;span class="nf"&gt;.contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;

    &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;packet&lt;/span&gt;&lt;span class="py"&gt;.sequence&lt;/span&gt;

&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Simple.&lt;/p&gt;

&lt;p&gt;Effective.&lt;/p&gt;




&lt;h1&gt;
  
  
  Packet Ordering
&lt;/h1&gt;

&lt;p&gt;Packets may arrive out of order.&lt;/p&gt;

&lt;p&gt;Example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Received

3

4

2

5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Applications usually expect:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2

3

4

5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We need a buffer.&lt;/p&gt;




&lt;h1&gt;
  
  
  Reordering Buffer
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Incoming

↓

Buffer

↓

Sort

↓

Deliver
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The application never sees disorder.&lt;/p&gt;




&lt;h1&gt;
  
  
  Sliding Window
&lt;/h1&gt;

&lt;p&gt;Sending one packet at a time wastes bandwidth.&lt;/p&gt;

&lt;p&gt;Instead, we'll allow multiple outstanding packets.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Window

+----------------------+

1

2

3

4

5

+----------------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As acknowledgements arrive, the window moves forward.&lt;/p&gt;




&lt;h1&gt;
  
  
  Sliding Window Example
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Send

1

2

3

4

5

↓

ACK 1

↓

Window Advances

↓

Send 6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The network remains busy.&lt;/p&gt;

&lt;p&gt;Throughput improves dramatically.&lt;/p&gt;




&lt;h1&gt;
  
  
  Sender State
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;Sender&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="n"&gt;next_sequence&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="n"&gt;window_size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;usize&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="n"&gt;pending&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

    &lt;span class="n"&gt;HashMap&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;u32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Packet&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Everything revolves around outstanding packets.&lt;/p&gt;




&lt;h1&gt;
  
  
  Receiver State
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;Receiver&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="n"&gt;expected_sequence&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Whenever packets arrive:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Expected

15

↓

Receive

15

↓

Deliver

↓

Expect

16
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Simple state.&lt;/p&gt;

&lt;p&gt;Huge impact.&lt;/p&gt;




&lt;h1&gt;
  
  
  A Complete Flow
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Sender

Packet 1

────────────►

Receiver

ACK 1

◄────────────

Packet 2

────────────►

Lost

Packet 3

────────────►

Receiver

ACK 3

◄────────────

Timeout

↓

Resend Packet 2

────────────►

Receiver

ACK 2

◄────────────
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Eventually every packet arrives.&lt;/p&gt;




&lt;h1&gt;
  
  
  Connection Setup
&lt;/h1&gt;

&lt;p&gt;UDP has no connection.&lt;/p&gt;

&lt;p&gt;We can create one.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Client

HELLO

────────────►

Server

WELCOME

◄────────────

Connected
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This allows session management.&lt;/p&gt;




&lt;h1&gt;
  
  
  Heartbeats
&lt;/h1&gt;

&lt;p&gt;How do we know the other side still exists?&lt;/p&gt;

&lt;p&gt;Periodic heartbeat packets.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PING

────────────►

PONG

◄────────────
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Miss several heartbeats.&lt;/p&gt;

&lt;p&gt;Disconnect.&lt;/p&gt;




&lt;h1&gt;
  
  
  Congestion Awareness
&lt;/h1&gt;

&lt;p&gt;Sending too fast overwhelms networks.&lt;/p&gt;

&lt;p&gt;Our sender should monitor:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Packet loss&lt;/li&gt;
&lt;li&gt;Round-trip time&lt;/li&gt;
&lt;li&gt;Retransmissions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If loss increases:&lt;/p&gt;

&lt;p&gt;Reduce sending rate.&lt;/p&gt;

&lt;p&gt;Reliability isn't only about delivery.&lt;/p&gt;

&lt;p&gt;It's also about respecting the network.&lt;/p&gt;




&lt;h1&gt;
  
  
  Putting Everything Together
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                 Application

                       │

                       ▼

            Reliable UDP Layer

     ┌────────────┬─────────────┐

     ▼            ▼             ▼

Sequence      ACK Manager    Timers

     │            │             │

     ├────────────┼─────────────┤

     ▼            ▼             ▼

Retransmit   Sliding Window  Ordering

              │

              ▼

           UDP Socket

              │

              ▼

           Network
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice how reliability emerges from multiple cooperating components.&lt;/p&gt;




&lt;h1&gt;
  
  
  Complete Architecture
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;             Application

                  │

                  ▼

       Reliable Transport API

                  │

                  ▼

      Packet Encoder / Decoder

                  │

      ┌───────────┼────────────┐

      ▼           ▼            ▼

 Sequence     ACK Logic    Retransmit

      │           │            │

      ├───────────┼────────────┤

      ▼           ▼            ▼

 Window      Ordering     Heartbeats

                  │

                  ▼

             UDP Socket

                  │

                  ▼

              Internet
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each layer has one responsibility.&lt;/p&gt;

&lt;p&gt;That's good software architecture.&lt;/p&gt;




&lt;h1&gt;
  
  
  Where Real Protocols Go Further
&lt;/h1&gt;

&lt;p&gt;Production systems extend these ideas significantly.&lt;/p&gt;

&lt;p&gt;They include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Adaptive congestion control&lt;/li&gt;
&lt;li&gt;Forward Error Correction (FEC)&lt;/li&gt;
&lt;li&gt;Packet compression&lt;/li&gt;
&lt;li&gt;Encryption&lt;/li&gt;
&lt;li&gt;Connection migration&lt;/li&gt;
&lt;li&gt;Multipath routing&lt;/li&gt;
&lt;li&gt;Flow control&lt;/li&gt;
&lt;li&gt;Bandwidth estimation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Protocols like &lt;strong&gt;QUIC&lt;/strong&gt;, which powers HTTP/3, are built on UDP and implement many of these ideas to provide secure, reliable, high-performance communication.&lt;/p&gt;




&lt;h1&gt;
  
  
  Lessons Learned
&lt;/h1&gt;

&lt;p&gt;Building a reliable transport protocol taught me something broader about software engineering.&lt;/p&gt;

&lt;p&gt;Reliability is rarely a single feature.&lt;/p&gt;

&lt;p&gt;It's usually the result of many small mechanisms working together.&lt;/p&gt;

&lt;p&gt;A sequence number alone isn't enough.&lt;/p&gt;

&lt;p&gt;Acknowledgements alone aren't enough.&lt;/p&gt;

&lt;p&gt;Timeouts alone aren't enough.&lt;/p&gt;

&lt;p&gt;Sliding windows alone aren't enough.&lt;/p&gt;

&lt;p&gt;But together, they create a communication layer that applications can trust.&lt;/p&gt;

&lt;p&gt;That's a recurring theme in engineering.&lt;/p&gt;

&lt;p&gt;Databases achieve reliability through transactions, logging, replication, and recovery.&lt;/p&gt;

&lt;p&gt;Distributed systems combine consensus, retries, and idempotency.&lt;/p&gt;

&lt;p&gt;Operating systems rely on schedulers, virtual memory, and interrupts.&lt;/p&gt;

&lt;p&gt;Complex behavior emerges from simple, well-designed components.&lt;/p&gt;

&lt;p&gt;Reliable UDP is another example of that principle.&lt;/p&gt;




&lt;h1&gt;
  
  
  Final Thoughts
&lt;/h1&gt;

&lt;p&gt;One of the biggest misconceptions about UDP is that it's "unreliable."&lt;/p&gt;

&lt;p&gt;In reality, UDP is simply &lt;strong&gt;minimal&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;It gives developers a blank canvas.&lt;/p&gt;

&lt;p&gt;You decide what reliability means.&lt;/p&gt;

&lt;p&gt;Do you need every packet?&lt;/p&gt;

&lt;p&gt;Do you care about order?&lt;/p&gt;

&lt;p&gt;Can you tolerate duplicates?&lt;/p&gt;

&lt;p&gt;How quickly should lost packets be retransmitted?&lt;/p&gt;

&lt;p&gt;By answering those questions yourself, you can build transport protocols tailored to your application's needs instead of accepting one-size-fits-all behavior.&lt;/p&gt;

&lt;p&gt;That's why technologies like QUIC, multiplayer game networking, live streaming platforms, and many distributed systems continue to embrace UDP.&lt;/p&gt;

&lt;p&gt;Not because it's unreliable.&lt;/p&gt;

&lt;p&gt;But because it gives engineers the freedom to build exactly the reliability they need.&lt;/p&gt;

&lt;p&gt;And perhaps that's the most valuable lesson of all.&lt;/p&gt;

&lt;p&gt;Sometimes the best engineering doesn't come from adding more features.&lt;/p&gt;

&lt;p&gt;It comes from starting with something beautifully simple and carefully building only what your system truly requires.&lt;/p&gt;

</description>
      <category>networking</category>
      <category>programming</category>
      <category>softwaredevelopment</category>
      <category>api</category>
    </item>
    <item>
      <title>MVCC Explained by Building One Yourself</title>
      <dc:creator>Derek mwale</dc:creator>
      <pubDate>Mon, 03 Aug 2026 23:11:39 +0000</pubDate>
      <link>https://dev.to/derekmwale/mvcc-explained-by-building-one-yourself-c61</link>
      <guid>https://dev.to/derekmwale/mvcc-explained-by-building-one-yourself-c61</guid>
      <description>&lt;h2&gt;
  
  
  Understanding Multi-Version Concurrency Control from First Principles
&lt;/h2&gt;

&lt;p&gt;Every database promises something deceptively simple.&lt;/p&gt;

&lt;p&gt;It tells multiple users they can read and write data at the same time.&lt;/p&gt;

&lt;p&gt;Your banking application updates balances while another customer checks their account.&lt;/p&gt;

&lt;p&gt;An online store updates inventory while thousands of customers browse products.&lt;/p&gt;

&lt;p&gt;A social media platform lets millions of people publish posts while everyone else continues scrolling.&lt;/p&gt;

&lt;p&gt;From the outside, everything appears to happen simultaneously.&lt;/p&gt;

&lt;p&gt;But underneath, things are far more complicated.&lt;/p&gt;

&lt;p&gt;Imagine two people trying to edit the same document at the exact same moment.&lt;/p&gt;

&lt;p&gt;Or two customers purchasing the last product in stock.&lt;/p&gt;

&lt;p&gt;Or two bank transfers modifying the same account balance.&lt;/p&gt;

&lt;p&gt;Without careful coordination, databases would constantly overwrite each other's work.&lt;/p&gt;

&lt;p&gt;This is the problem of &lt;strong&gt;concurrency&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;For decades, databases solved this using locks.&lt;/p&gt;

&lt;p&gt;One transaction would lock a row.&lt;/p&gt;

&lt;p&gt;Everyone else had to wait.&lt;/p&gt;

&lt;p&gt;Locks work.&lt;/p&gt;

&lt;p&gt;But they don't scale well.&lt;/p&gt;

&lt;p&gt;Modern databases like PostgreSQL, MySQL (InnoDB), CockroachDB, Oracle, and others rely heavily on a different idea.&lt;/p&gt;

&lt;p&gt;One that initially feels almost magical.&lt;/p&gt;

&lt;p&gt;Instead of making readers wait...&lt;/p&gt;

&lt;p&gt;They create multiple versions of the same data.&lt;/p&gt;

&lt;p&gt;This technique is called &lt;strong&gt;Multi-Version Concurrency Control&lt;/strong&gt;, or &lt;strong&gt;MVCC&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;When I first encountered MVCC, it seemed surprisingly abstract.&lt;/p&gt;

&lt;p&gt;After building one from scratch, however, it became one of the most elegant pieces of engineering I'd ever studied.&lt;/p&gt;

&lt;p&gt;Let's build one together.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Problem with Traditional Locks
&lt;/h1&gt;

&lt;p&gt;Imagine a simple Users table.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Users

+----+---------+
| ID | Name    |
+----+---------+
| 1  | Derek   |
+----+---------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now suppose Transaction A wants to update the row.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;
&lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'Alex'&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Meanwhile...&lt;/p&gt;

&lt;p&gt;Transaction B wants to read it.&lt;/p&gt;

&lt;p&gt;Traditional locking produces:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Transaction A

LOCK ROW

↓

Update

↓

Commit

↓

Unlock

↓

Transaction B Reads
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The reader waits.&lt;/p&gt;

&lt;p&gt;Not ideal.&lt;/p&gt;




&lt;h1&gt;
  
  
  Why Waiting Hurts Performance
&lt;/h1&gt;

&lt;p&gt;Imagine one thousand users reading product information.&lt;/p&gt;

&lt;p&gt;Only one administrator updates the description.&lt;/p&gt;

&lt;p&gt;Without MVCC:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;999 Readers

↓

Waiting

↓

Waiting

↓

Waiting
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Even though readers don't modify data.&lt;/p&gt;

&lt;p&gt;The database becomes unnecessarily slow.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Core Idea Behind MVCC
&lt;/h1&gt;

&lt;p&gt;Instead of modifying rows directly...&lt;/p&gt;

&lt;p&gt;Create a new version.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Version 1

Name = Derek

↓

Update

↓

Version 2

Name = Alex
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Readers continue using Version 1.&lt;/p&gt;

&lt;p&gt;Writers create Version 2.&lt;/p&gt;

&lt;p&gt;Nobody blocks.&lt;/p&gt;




&lt;h1&gt;
  
  
  Thinking in Timelines
&lt;/h1&gt;

&lt;p&gt;MVCC is easier to understand visually.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Time

──────────────────────────►

Version 1

"Derek"

───────────────┐

               │

               ▼

Version 2

"Alex"

──────────────────────────►
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both versions coexist temporarily.&lt;/p&gt;




&lt;h1&gt;
  
  
  Every Row Has History
&lt;/h1&gt;

&lt;p&gt;Instead of storing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User

ID

Name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We store:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User

ID

Name

Created Version

Deleted Version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each row knows when it became visible.&lt;/p&gt;

&lt;p&gt;And when it disappeared.&lt;/p&gt;




&lt;h1&gt;
  
  
  Designing Our Row
&lt;/h1&gt;

&lt;p&gt;Rust implementation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;Row&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;created_tx&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;deleted_tx&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Option&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;u64&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice something important.&lt;/p&gt;

&lt;p&gt;Rows are never immediately overwritten.&lt;/p&gt;




&lt;h1&gt;
  
  
  Transactions Need IDs
&lt;/h1&gt;

&lt;p&gt;Every transaction receives a unique identifier.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Transaction 1

↓

Transaction 2

↓

Transaction 3

↓

Transaction 4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Rust.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;Transaction&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Simple.&lt;/p&gt;

&lt;p&gt;Yet incredibly powerful.&lt;/p&gt;




&lt;h1&gt;
  
  
  Reading Data
&lt;/h1&gt;

&lt;p&gt;Suppose the table contains:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ID

Name

Created

Deleted

---------------------------------

1

Derek

1

None
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Transaction 5 reads.&lt;/p&gt;

&lt;p&gt;Is it visible?&lt;/p&gt;

&lt;p&gt;Yes.&lt;/p&gt;

&lt;p&gt;Because:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Created &amp;lt;= Transaction ID
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The row already existed.&lt;/p&gt;




&lt;h1&gt;
  
  
  Updating Data
&lt;/h1&gt;

&lt;p&gt;Now Transaction 6 executes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;

&lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'Alex'&lt;/span&gt;

&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead of replacing the row...&lt;/p&gt;

&lt;p&gt;We perform:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Old Row

Deleted = 6

↓

New Row

Created = 6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now two versions exist.&lt;/p&gt;




&lt;h1&gt;
  
  
  Table After Update
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;+----+--------+---------+---------+

| ID | Name   | Created | Deleted |

+----+--------+---------+---------+

| 1  | Derek  |    1    |    6    |

| 1  | Alex   |    6    |   None  |

+----+--------+---------+---------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nothing was overwritten.&lt;/p&gt;




&lt;h1&gt;
  
  
  Visibility Rules
&lt;/h1&gt;

&lt;p&gt;Now comes the magic.&lt;/p&gt;

&lt;p&gt;Transaction 5 should see:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Derek
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Transaction 7 should see:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Alex
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same table.&lt;/p&gt;

&lt;p&gt;Different results.&lt;/p&gt;

&lt;p&gt;Depending on when the transaction started.&lt;/p&gt;




&lt;h1&gt;
  
  
  Snapshot Isolation
&lt;/h1&gt;

&lt;p&gt;Every transaction observes a snapshot.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Transaction Starts

↓

Snapshot Created

↓

Reads Always Use Snapshot
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Even if newer updates occur.&lt;/p&gt;

&lt;p&gt;This provides consistency.&lt;/p&gt;




&lt;h1&gt;
  
  
  Visualizing Snapshots
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Time

────────────────────────────────────►

T1

Reads Derek

───────────────────────────

Update to Alex

───────────────────────────

T2

Reads Alex
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Neither transaction blocks the other.&lt;/p&gt;




&lt;h1&gt;
  
  
  Implementing Visibility
&lt;/h1&gt;

&lt;p&gt;Rust.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;impl&lt;/span&gt; &lt;span class="n"&gt;Row&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;visible&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;

        &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

        &lt;span class="n"&gt;tx&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

        &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.created_tx&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;tx&lt;/span&gt;

        &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;

        &lt;span class="k"&gt;match&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.deleted_tx&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

            &lt;span class="nf"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;tx&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

            &lt;span class="nb"&gt;None&lt;/span&gt; &lt;span class="k"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

        &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This small function powers MVCC.&lt;/p&gt;




&lt;h1&gt;
  
  
  Reading Rows
&lt;/h1&gt;

&lt;p&gt;Query execution.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="n"&gt;rows&lt;/span&gt;&lt;span class="nf"&gt;.iter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="nf"&gt;.filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;

    &lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt;

    &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="nf"&gt;.visible&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tx&lt;/span&gt;&lt;span class="py"&gt;.id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every query automatically filters invisible versions.&lt;/p&gt;

&lt;p&gt;Applications never notice.&lt;/p&gt;




&lt;h1&gt;
  
  
  Inserting Rows
&lt;/h1&gt;

&lt;p&gt;Insertion becomes simple.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="n"&gt;Row&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="n"&gt;created_tx&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;tx&lt;/span&gt;&lt;span class="py"&gt;.id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="n"&gt;deleted_tx&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Only one version exists.&lt;/p&gt;

&lt;p&gt;Initially.&lt;/p&gt;




&lt;h1&gt;
  
  
  Deleting Rows
&lt;/h1&gt;

&lt;p&gt;Deletion doesn't remove anything immediately.&lt;/p&gt;

&lt;p&gt;Instead:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Deleted = Transaction ID
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The row remains.&lt;/p&gt;

&lt;p&gt;Older transactions still need it.&lt;/p&gt;




&lt;h1&gt;
  
  
  Example Timeline
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Transaction 2

Insert User

↓

Transaction 4

Delete User

↓

Transaction 3

Still Sees User

↓

Transaction 5

Doesn't See User
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice the overlap.&lt;/p&gt;

&lt;p&gt;Different transactions observe different realities.&lt;/p&gt;




&lt;h1&gt;
  
  
  Version Chains
&lt;/h1&gt;

&lt;p&gt;Many databases organize versions as chains.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Newest

↓

Alex

↓

Derek

↓

Original
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Readers traverse the chain until they find a visible version.&lt;/p&gt;




&lt;h1&gt;
  
  
  Storage Layout
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Users

↓

Version List

↓

Row

↓

Previous Version

↓

Previous Version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Some databases optimize this differently.&lt;/p&gt;

&lt;p&gt;The idea remains similar.&lt;/p&gt;




&lt;h1&gt;
  
  
  Garbage Collection
&lt;/h1&gt;

&lt;p&gt;Eventually...&lt;/p&gt;

&lt;p&gt;Old versions become unnecessary.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Version 1

No Active Transactions

↓

Delete Version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Otherwise storage would grow forever.&lt;/p&gt;




&lt;h1&gt;
  
  
  Vacuuming
&lt;/h1&gt;

&lt;p&gt;PostgreSQL calls this process:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;VACUUM
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It removes obsolete versions once no active transaction can see them.&lt;/p&gt;




&lt;h1&gt;
  
  
  Transaction Manager
&lt;/h1&gt;

&lt;p&gt;Eventually we need something managing transactions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;TransactionManager&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="n"&gt;next_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Creating one.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;begin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;

    &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;Transaction&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.next_id&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="n"&gt;Transaction&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

        &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.next_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every transaction receives a unique snapshot.&lt;/p&gt;




&lt;h1&gt;
  
  
  Building the Engine
&lt;/h1&gt;

&lt;p&gt;Architecture.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Applications

        │

        ▼

Query Engine

        │

        ▼

Transaction Manager

        │

        ▼

MVCC Visibility

        │

        ▼

Storage Engine
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each layer performs one responsibility.&lt;/p&gt;




&lt;h1&gt;
  
  
  Reading Algorithm
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Read Query

↓

Find Candidate Rows

↓

Check Visibility

↓

Return Matching Versions
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Simple.&lt;/p&gt;

&lt;p&gt;Elegant.&lt;/p&gt;

&lt;p&gt;Fast.&lt;/p&gt;




&lt;h1&gt;
  
  
  Updating Algorithm
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Find Row

↓

Mark Deleted

↓

Insert New Version

↓

Commit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No overwriting.&lt;/p&gt;

&lt;p&gt;Ever.&lt;/p&gt;




&lt;h1&gt;
  
  
  Comparing Locking vs MVCC
&lt;/h1&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Locking&lt;/th&gt;
&lt;th&gt;MVCC&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Readers Wait&lt;/td&gt;
&lt;td&gt;Readers Continue&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Writers Block Readers&lt;/td&gt;
&lt;td&gt;Readers Never Block&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Less Storage&lt;/td&gt;
&lt;td&gt;More Storage&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Simple&lt;/td&gt;
&lt;td&gt;More Sophisticated&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Lower Concurrency&lt;/td&gt;
&lt;td&gt;Excellent Concurrency&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The additional complexity buys significantly better scalability.&lt;/p&gt;




&lt;h1&gt;
  
  
  Real Database Behavior
&lt;/h1&gt;

&lt;p&gt;PostgreSQL.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Tuple

↓

xmin

↓

xmax
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These resemble our:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;created_tx

deleted_tx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Different names.&lt;/p&gt;

&lt;p&gt;Same philosophy.&lt;/p&gt;




&lt;h1&gt;
  
  
  Why This Changed My Thinking
&lt;/h1&gt;

&lt;p&gt;Before understanding MVCC, I imagined databases as continuously modifying rows.&lt;/p&gt;

&lt;p&gt;Now I think differently.&lt;/p&gt;

&lt;p&gt;Rows don't simply exist.&lt;/p&gt;

&lt;p&gt;They evolve through time.&lt;/p&gt;

&lt;p&gt;A table becomes a timeline rather than a static structure.&lt;/p&gt;

&lt;p&gt;Queries become historical observations.&lt;/p&gt;

&lt;p&gt;Transactions become snapshots of reality.&lt;/p&gt;

&lt;p&gt;That perspective fundamentally changed how I design backend systems.&lt;/p&gt;




&lt;h1&gt;
  
  
  Complete Architecture
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                    Applications
                           │
                           ▼
                      SQL Queries
                           │
                           ▼
                    Query Planner
                           │
                           ▼
                  Transaction Manager
                           │
                           ▼
                    Snapshot Manager
                           │
                           ▼
                 Visibility Checker
                           │
          ┌────────────────┼────────────────┐
          ▼                ▼                ▼
     Version Chain    Version Chain    Version Chain
          │                │                │
          ▼                ▼                ▼
                  Storage Engine
                           │
                           ▼
                    Disk Persistence
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice how MVCC isn't just one algorithm.&lt;/p&gt;

&lt;p&gt;It's an architecture.&lt;/p&gt;




&lt;h1&gt;
  
  
  Implementation Summary
&lt;/h1&gt;

&lt;p&gt;Our miniature MVCC engine now supports:&lt;/p&gt;

&lt;p&gt;✓ Transaction IDs&lt;/p&gt;

&lt;p&gt;✓ Snapshot visibility&lt;/p&gt;

&lt;p&gt;✓ Multiple row versions&lt;/p&gt;

&lt;p&gt;✓ Inserts&lt;/p&gt;

&lt;p&gt;✓ Updates&lt;/p&gt;

&lt;p&gt;✓ Deletes&lt;/p&gt;

&lt;p&gt;✓ Version filtering&lt;/p&gt;

&lt;p&gt;✓ Garbage collection strategy&lt;/p&gt;

&lt;p&gt;Although simplified, these are the same foundational ideas used inside production databases serving millions of users every day.&lt;/p&gt;




&lt;h1&gt;
  
  
  Where Real Databases Go Further
&lt;/h1&gt;

&lt;p&gt;Production systems extend these ideas considerably.&lt;/p&gt;

&lt;p&gt;They include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Write-Ahead Logging (WAL)&lt;/li&gt;
&lt;li&gt;Crash recovery&lt;/li&gt;
&lt;li&gt;Serializable isolation&lt;/li&gt;
&lt;li&gt;Lock escalation&lt;/li&gt;
&lt;li&gt;Index versioning&lt;/li&gt;
&lt;li&gt;Replication&lt;/li&gt;
&lt;li&gt;Distributed transactions&lt;/li&gt;
&lt;li&gt;Checkpointing&lt;/li&gt;
&lt;li&gt;Compression&lt;/li&gt;
&lt;li&gt;Background vacuum workers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Yet none of those features replace MVCC.&lt;/p&gt;

&lt;p&gt;They build upon it.&lt;/p&gt;




&lt;h1&gt;
  
  
  Final Thoughts
&lt;/h1&gt;

&lt;p&gt;Building a miniature MVCC engine completely changed the way I think about databases.&lt;/p&gt;

&lt;p&gt;Before studying concurrency control, I viewed a table as a collection of rows that were constantly being modified in place.&lt;/p&gt;

&lt;p&gt;After implementing MVCC, I realized that's not how many modern databases think at all.&lt;/p&gt;

&lt;p&gt;Instead of treating data as something that changes, they treat it as something that evolves.&lt;/p&gt;

&lt;p&gt;Each update becomes a new version.&lt;/p&gt;

&lt;p&gt;Each transaction becomes a snapshot in time.&lt;/p&gt;

&lt;p&gt;Each query observes a carefully constructed view of reality that remains consistent from start to finish.&lt;/p&gt;

&lt;p&gt;That's an incredibly elegant solution to one of the hardest problems in computer science.&lt;/p&gt;

&lt;p&gt;It also reinforces a broader lesson about software engineering.&lt;/p&gt;

&lt;p&gt;The fastest systems aren't always the ones that perform less work.&lt;/p&gt;

&lt;p&gt;They're often the ones that organize work more intelligently.&lt;/p&gt;

&lt;p&gt;Rather than forcing readers and writers to compete over the same data, MVCC lets them coexist.&lt;/p&gt;

&lt;p&gt;Instead of serializing the world through locks, it embraces history.&lt;/p&gt;

&lt;p&gt;And perhaps that's why MVCC remains one of my favorite database concepts.&lt;/p&gt;

&lt;p&gt;It's a reminder that some of the best engineering solutions don't eliminate complexity.&lt;/p&gt;

&lt;p&gt;They reorganize it into something that feels almost effortless.&lt;/p&gt;

</description>
      <category>database</category>
      <category>api</category>
      <category>softwaredevelopment</category>
      <category>software</category>
    </item>
    <item>
      <title>The Things I Only Learned After Shipping 20+ Real Projects</title>
      <dc:creator>Derek mwale</dc:creator>
      <pubDate>Sat, 01 Aug 2026 17:09:17 +0000</pubDate>
      <link>https://dev.to/derekmwale/the-things-i-only-learned-after-shipping-20-real-projects-4616</link>
      <guid>https://dev.to/derekmwale/the-things-i-only-learned-after-shipping-20-real-projects-4616</guid>
      <description>&lt;p&gt;When I wrote my first real application, I thought the hardest part of software engineering was getting the code to compile.&lt;/p&gt;

&lt;p&gt;Then I thought it was fixing bugs.&lt;/p&gt;

&lt;p&gt;Later I thought it was learning new frameworks.&lt;/p&gt;

&lt;p&gt;Today, after shipping more than twenty real projects—some successful, some abandoned, some open-sourced, some rewritten entirely—I think the hardest part of software engineering is something else.&lt;/p&gt;

&lt;p&gt;It is learning how to make good engineering decisions.&lt;/p&gt;

&lt;p&gt;Every project leaves behind code.&lt;/p&gt;

&lt;p&gt;But more importantly, every project leaves behind lessons.&lt;/p&gt;

&lt;p&gt;Some lessons arrive through success.&lt;/p&gt;

&lt;p&gt;Others arrive through painful mistakes.&lt;/p&gt;

&lt;p&gt;A few arrive months after deployment when you realize that the architecture you proudly designed now slows down every new feature.&lt;/p&gt;

&lt;p&gt;Experience has a way of changing your priorities.&lt;/p&gt;

&lt;p&gt;Earlier in my career, I optimized for writing more code.&lt;/p&gt;

&lt;p&gt;Today, I optimize for writing better systems.&lt;/p&gt;

&lt;p&gt;Looking back, there are many things I wish someone had told me before I started building production software.&lt;/p&gt;

&lt;p&gt;Ironically, I probably wouldn't have understood them until I experienced them myself.&lt;/p&gt;




&lt;h1&gt;
  
  
  Software Is Never Finished
&lt;/h1&gt;

&lt;p&gt;One of the biggest misconceptions I had was believing projects eventually become "done."&lt;/p&gt;

&lt;p&gt;Reality looks very different.&lt;/p&gt;

&lt;p&gt;Every application becomes a living system.&lt;/p&gt;

&lt;p&gt;Users request new features.&lt;/p&gt;

&lt;p&gt;Businesses change direction.&lt;/p&gt;

&lt;p&gt;Dependencies receive updates.&lt;/p&gt;

&lt;p&gt;Security vulnerabilities appear.&lt;/p&gt;

&lt;p&gt;Performance expectations increase.&lt;/p&gt;

&lt;p&gt;Operating systems evolve.&lt;/p&gt;

&lt;p&gt;Browsers change.&lt;/p&gt;

&lt;p&gt;Cloud providers introduce new services.&lt;/p&gt;

&lt;p&gt;The software never stops moving.&lt;/p&gt;

&lt;p&gt;The goal isn't to finish software.&lt;/p&gt;

&lt;p&gt;The goal is to build software that can continue evolving.&lt;/p&gt;

&lt;p&gt;That realization completely changed how I design systems.&lt;/p&gt;




&lt;h1&gt;
  
  
  Architecture Matters More Than Algorithms
&lt;/h1&gt;

&lt;p&gt;University teaches algorithms.&lt;/p&gt;

&lt;p&gt;Production teaches architecture.&lt;/p&gt;

&lt;p&gt;I've rarely encountered applications that failed because they used the wrong sorting algorithm.&lt;/p&gt;

&lt;p&gt;I've encountered many that struggled because responsibilities weren't clearly separated.&lt;/p&gt;

&lt;p&gt;Business logic lived inside controllers.&lt;/p&gt;

&lt;p&gt;Authentication spread across multiple services.&lt;/p&gt;

&lt;p&gt;Database access appeared everywhere.&lt;/p&gt;

&lt;p&gt;Dependencies became tangled.&lt;/p&gt;

&lt;p&gt;Architecture quietly determines how easy software becomes to change.&lt;/p&gt;




&lt;h1&gt;
  
  
  Every Request Tells a Story
&lt;/h1&gt;

&lt;p&gt;I no longer think about API endpoints individually.&lt;/p&gt;

&lt;p&gt;I think about journeys.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```text id="r7n0av"&lt;br&gt;
                 User Request&lt;br&gt;
                      │&lt;br&gt;
                      ▼&lt;br&gt;
                Load Balancer&lt;br&gt;
                      │&lt;br&gt;
                      ▼&lt;br&gt;
              Authentication&lt;br&gt;
                      │&lt;br&gt;
                      ▼&lt;br&gt;
               API Controller&lt;br&gt;
                      │&lt;br&gt;
                      ▼&lt;br&gt;
              Business Service&lt;br&gt;
               │             │&lt;br&gt;
               ▼             ▼&lt;br&gt;
          Redis Cache    PostgreSQL&lt;br&gt;
               │             │&lt;br&gt;
               └──────┬──────┘&lt;br&gt;
                      ▼&lt;br&gt;
               JSON Response&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


Every layer contributes.

When something becomes slow, the problem usually isn't one function.

It's the interaction between many components.

---

# Simplicity Ages Better

Earlier versions of my software often contained clever abstractions.

Generic builders.

Complicated inheritance.

Nested dependency chains.

They felt impressive.

Six months later they became difficult to understand.

Today I choose clarity instead.

Simple functions.

Predictable naming.

Small services.

Less abstraction.

Future maintainability matters more than present elegance.

---

# Databases Deserve More Respect

One lesson took years to appreciate.

The database isn't just where information lives.

It defines relationships.

Performance.

Consistency.

Integrity.

Good schemas simplify applications.

Poor schemas spread complexity throughout the entire codebase.

Indexes often improve performance more than rewriting application code.

Constraints eliminate entire categories of bugs.

The database quietly influences every request.

---

# Caching Is Architecture

Earlier I viewed Redis as an optimization.

Now I think of caching as part of system design.



```text id="x8h53m"
          Client Request
                 │
                 ▼
            Redis Cache
             │       │
           Hit      Miss
            │        │
            ▼        ▼
      Return Data Database
                     │
                     ▼
              Store Cache
                     │
                     ▼
               Return Data
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Good caching isn't about speed alone.&lt;/p&gt;

&lt;p&gt;It's about reducing unnecessary work.&lt;/p&gt;

&lt;p&gt;The fastest query is often the one you never execute.&lt;/p&gt;


&lt;h1&gt;
  
  
  Events Changed How I Build Software
&lt;/h1&gt;

&lt;p&gt;One architectural lesson transformed the way I think about large systems.&lt;/p&gt;

&lt;p&gt;Instead of letting one service perform every responsibility, I let services communicate through events.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```text id="s4cvny"&lt;br&gt;
        User Registered&lt;br&gt;
              │&lt;br&gt;
      ┌───────┼────────┐&lt;br&gt;
      ▼       ▼        ▼&lt;br&gt;
 Email   Analytics   CRM Sync&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


The registration service no longer knows how emails work.

Or analytics.

Or customer relationship management.

It simply announces that something happened.

Other services react independently.

The architecture becomes remarkably flexible.

---

# Thin Controllers Saved Me Countless Hours

Earlier controllers handled everything.

Validation.

Business rules.

Emails.

Database logic.

Notifications.

Today my controllers barely do anything.



```rust id="fx1lh3"
pub async fn register(
    request: RegisterRequest,
    service: UserService,
) -&amp;gt; Result&amp;lt;ApiResponse&amp;lt;User&amp;gt;&amp;gt; {

    let user =
        service.register(request).await?;

    Ok(ApiResponse::success(user))
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The service contains the actual business logic.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```rust id="q0m1ye"&lt;br&gt;
impl UserService {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pub async fn register(
    &amp;amp;self,
    request: RegisterRequest,
) -&amp;gt; Result&amp;lt;User&amp;gt; {

    let user =
        self.repository
            .create(request)
            .await?;

    self.events.publish(
        UserRegistered {
            id: user.id
        }
    ).await?;

    Ok(user)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


Small responsibilities produce maintainable systems.

---

# Monitoring Beats Guessing

Logging tells you what happened.

Monitoring tells you what's happening.

Earlier I waited for users to report bugs.

Today dashboards often identify problems before users notice them.

CPU usage.

Memory consumption.

Database latency.

Cache hit rate.

Request throughput.

Error percentages.

Observability transforms debugging into engineering.

---

# Testing Changes Design

One unexpected lesson surprised me.

Difficult-to-test code often indicates difficult-to-maintain architecture.

When services become modular...

Testing becomes easier.

When responsibilities become focused...

Unit tests become smaller.

Testing improves design almost as much as it verifies behavior.

---

# Failure Is Part of the Architecture

Production eventually teaches every engineer the same lesson.

Everything fails.

Networks timeout.

Servers restart.

Caches disappear.

Third-party APIs become unavailable.

Instead of asking:

"Will this fail?"

I now ask:

"How gracefully can it recover?"



```text id="c6fjvk"
 External API
      │
Available?
 │       │
Yes      No
 │        │
 ▼        ▼
Proceed  Retry
            │
            ▼
      Cached Result
            │
            ▼
       Log Failure
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reliable software anticipates failure instead of pretending it won't happen.&lt;/p&gt;




&lt;h1&gt;
  
  
  Documentation Saves Future You
&lt;/h1&gt;

&lt;p&gt;One of my favorite engineers once said:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Documentation is a gift to your future self."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I didn't appreciate that enough.&lt;/p&gt;

&lt;p&gt;Months later, opening an old project without documentation feels like exploring an unfamiliar city.&lt;/p&gt;

&lt;p&gt;Clear architecture diagrams.&lt;/p&gt;

&lt;p&gt;API examples.&lt;/p&gt;

&lt;p&gt;Database relationships.&lt;/p&gt;

&lt;p&gt;Deployment instructions.&lt;/p&gt;

&lt;p&gt;These reduce future confusion enormously.&lt;/p&gt;




&lt;h1&gt;
  
  
  Shipping Changes How You Learn
&lt;/h1&gt;

&lt;p&gt;Tutorials teach techniques.&lt;/p&gt;

&lt;p&gt;Production teaches judgment.&lt;/p&gt;

&lt;p&gt;Books explain principles.&lt;/p&gt;

&lt;p&gt;Real systems explain trade-offs.&lt;/p&gt;

&lt;p&gt;Every decision becomes contextual.&lt;/p&gt;

&lt;p&gt;Should we cache this?&lt;/p&gt;

&lt;p&gt;Should we normalize this table?&lt;/p&gt;

&lt;p&gt;Should this service own authentication?&lt;/p&gt;

&lt;p&gt;Should this operation be asynchronous?&lt;/p&gt;

&lt;p&gt;Experience teaches there is rarely one perfect answer.&lt;/p&gt;

&lt;p&gt;Only thoughtful trade-offs.&lt;/p&gt;




&lt;h1&gt;
  
  
  Growth Changes Priorities
&lt;/h1&gt;

&lt;p&gt;Earlier I cared about learning more programming languages.&lt;/p&gt;

&lt;p&gt;Today I care more about designing better systems.&lt;/p&gt;

&lt;p&gt;Languages matter.&lt;/p&gt;

&lt;p&gt;Architecture matters more.&lt;/p&gt;

&lt;p&gt;Frameworks evolve.&lt;/p&gt;

&lt;p&gt;Engineering principles endure.&lt;/p&gt;

&lt;p&gt;Clear responsibilities.&lt;/p&gt;

&lt;p&gt;Loose coupling.&lt;/p&gt;

&lt;p&gt;Simple interfaces.&lt;/p&gt;

&lt;p&gt;Reliable monitoring.&lt;/p&gt;

&lt;p&gt;Good naming.&lt;/p&gt;

&lt;p&gt;Those ideas remain valuable regardless of technology.&lt;/p&gt;




&lt;h1&gt;
  
  
  Software Is Communication
&lt;/h1&gt;

&lt;p&gt;Perhaps the biggest lesson surprised me.&lt;/p&gt;

&lt;p&gt;Software isn't only communication between computers.&lt;/p&gt;

&lt;p&gt;It's communication between engineers.&lt;/p&gt;

&lt;p&gt;Naming communicates.&lt;/p&gt;

&lt;p&gt;Architecture communicates.&lt;/p&gt;

&lt;p&gt;Folder structures communicate.&lt;/p&gt;

&lt;p&gt;API responses communicate.&lt;/p&gt;

&lt;p&gt;Comments communicate.&lt;/p&gt;

&lt;p&gt;The next engineer should understand your intentions without needing to ask.&lt;/p&gt;

&lt;p&gt;Sometimes that next engineer is you.&lt;/p&gt;




&lt;h1&gt;
  
  
  Experience Made Me Slower—and Better
&lt;/h1&gt;

&lt;p&gt;Interestingly, I write code more slowly today than I did years ago.&lt;/p&gt;

&lt;p&gt;Not because I've forgotten anything.&lt;/p&gt;

&lt;p&gt;Because I think longer before typing.&lt;/p&gt;

&lt;p&gt;I sketch architectures.&lt;/p&gt;

&lt;p&gt;Question assumptions.&lt;/p&gt;

&lt;p&gt;Imagine future requirements.&lt;/p&gt;

&lt;p&gt;Consider failure scenarios.&lt;/p&gt;

&lt;p&gt;Good engineering begins long before implementation.&lt;/p&gt;




&lt;h1&gt;
  
  
  Final Thoughts
&lt;/h1&gt;

&lt;p&gt;Looking back at more than twenty real projects, I don't remember every feature I built.&lt;/p&gt;

&lt;p&gt;I don't remember every framework version.&lt;/p&gt;

&lt;p&gt;I don't remember every library I used.&lt;/p&gt;

&lt;p&gt;But I remember the lessons.&lt;/p&gt;

&lt;p&gt;I remember the production bugs that revealed architectural weaknesses.&lt;/p&gt;

&lt;p&gt;I remember the APIs that became difficult to evolve because I hadn't thought about versioning.&lt;/p&gt;

&lt;p&gt;I remember the databases that taught me the value of proper indexing.&lt;/p&gt;

&lt;p&gt;I remember the monitoring dashboards that identified issues before customers did.&lt;/p&gt;

&lt;p&gt;I remember the projects that became easier to maintain because responsibilities were clearly separated.&lt;/p&gt;

&lt;p&gt;Most importantly, I remember realizing that software engineering is far less about writing code than I once believed.&lt;/p&gt;

&lt;p&gt;Code is only one expression of engineering.&lt;/p&gt;

&lt;p&gt;Architecture.&lt;/p&gt;

&lt;p&gt;Data modeling.&lt;/p&gt;

&lt;p&gt;Caching.&lt;/p&gt;

&lt;p&gt;Observability.&lt;/p&gt;

&lt;p&gt;Documentation.&lt;/p&gt;

&lt;p&gt;Testing.&lt;/p&gt;

&lt;p&gt;Reliability.&lt;/p&gt;

&lt;p&gt;Maintainability.&lt;/p&gt;

&lt;p&gt;Those are equally important.&lt;/p&gt;

&lt;p&gt;If I could go back and give my younger self one piece of advice before shipping the first project, it would be this:&lt;/p&gt;

&lt;p&gt;Don't optimize for finishing software.&lt;/p&gt;

&lt;p&gt;Optimize for living with it.&lt;/p&gt;

&lt;p&gt;Because software stays with you far longer than the excitement of launching it.&lt;/p&gt;

&lt;p&gt;Every design decision eventually returns.&lt;/p&gt;

&lt;p&gt;Sometimes as technical debt.&lt;/p&gt;

&lt;p&gt;Sometimes as simplicity.&lt;/p&gt;

&lt;p&gt;Sometimes as confidence.&lt;/p&gt;

&lt;p&gt;And after enough projects, you begin to realize that experience isn't measured by how many applications you've built.&lt;/p&gt;

&lt;p&gt;It's measured by how many engineering lessons those applications quietly taught you along the way.&lt;/p&gt;

</description>
      <category>api</category>
      <category>software</category>
      <category>programming</category>
      <category>softwaredevelopment</category>
    </item>
    <item>
      <title>Caching Strategies Every Backend Engineer Should Know</title>
      <dc:creator>Derek mwale</dc:creator>
      <pubDate>Sat, 01 Aug 2026 17:03:25 +0000</pubDate>
      <link>https://dev.to/derekmwale/caching-strategies-every-backend-engineer-should-know-gmm</link>
      <guid>https://dev.to/derekmwale/caching-strategies-every-backend-engineer-should-know-gmm</guid>
      <description>&lt;p&gt;The first time I heard someone say, &lt;strong&gt;"The fastest database query is the one you never execute,"&lt;/strong&gt; I thought it was just another clever engineering quote.&lt;/p&gt;

&lt;p&gt;Then I deployed applications into production.&lt;/p&gt;

&lt;p&gt;I watched the same products being requested thousands of times.&lt;/p&gt;

&lt;p&gt;I watched users refresh the same pages over and over.&lt;/p&gt;

&lt;p&gt;I watched identical SQL queries hit the database every few milliseconds.&lt;/p&gt;

&lt;p&gt;Suddenly the quote made perfect sense.&lt;/p&gt;

&lt;p&gt;The problem wasn't that the database was slow.&lt;/p&gt;

&lt;p&gt;The problem was that we kept asking it the same question.&lt;/p&gt;

&lt;p&gt;That is where caching changes everything.&lt;/p&gt;

&lt;p&gt;Many developers think of caching as an optimization that comes later. I used to think the same way.&lt;/p&gt;

&lt;p&gt;Today I see it differently.&lt;/p&gt;

&lt;p&gt;Caching is part of architecture.&lt;/p&gt;

&lt;p&gt;It's one of the most effective ways to reduce latency, lower infrastructure costs, improve scalability, and create applications that continue performing well as traffic grows.&lt;/p&gt;

&lt;p&gt;The interesting part is that caching isn't one technique.&lt;/p&gt;

&lt;p&gt;It's an entire family of strategies, each solving a different problem.&lt;/p&gt;

&lt;p&gt;Understanding when to use each one is one of the quiet skills that separates backend engineering from simply writing APIs.&lt;/p&gt;




&lt;h1&gt;
  
  
  Why Caching Exists
&lt;/h1&gt;

&lt;p&gt;Every request consumes resources.&lt;/p&gt;

&lt;p&gt;A database query uses CPU cycles.&lt;/p&gt;

&lt;p&gt;Disk reads take time.&lt;/p&gt;

&lt;p&gt;Network requests introduce latency.&lt;/p&gt;

&lt;p&gt;External APIs may charge money.&lt;/p&gt;

&lt;p&gt;If the same information is requested repeatedly, recomputing it every single time becomes wasteful.&lt;/p&gt;

&lt;p&gt;Caching simply asks a better question:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Can we reuse work we've already done?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That single idea powers some of the fastest software systems in the world.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Journey of a Request
&lt;/h1&gt;

&lt;p&gt;Before discussing strategies, it's useful to understand where caches fit inside a backend architecture.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```text id="r0z5la"&lt;br&gt;
                    Client&lt;br&gt;
                       │&lt;br&gt;
                       ▼&lt;br&gt;
                 Load Balancer&lt;br&gt;
                       │&lt;br&gt;
                       ▼&lt;br&gt;
                  API Gateway&lt;br&gt;
                       │&lt;br&gt;
                       ▼&lt;br&gt;
                 Redis Cache&lt;br&gt;
                  │        │&lt;br&gt;
             Cache Hit   Cache Miss&lt;br&gt;
                  │        │&lt;br&gt;
                  ▼        ▼&lt;br&gt;
           Return Data  Application&lt;br&gt;
                             │&lt;br&gt;
                             ▼&lt;br&gt;
                        PostgreSQL&lt;br&gt;
                             │&lt;br&gt;
                             ▼&lt;br&gt;
                        Store in Cache&lt;br&gt;
                             │&lt;br&gt;
                             ▼&lt;br&gt;
                        HTTP Response&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


Notice something important.

The database is no longer the first stop.

The cache becomes the first place the application looks.

That simple change can dramatically reduce database load.

---

# Strategy 1: Cache-Aside (Lazy Loading)

This is the strategy I use most often.

The application checks the cache first.

If the data exists, it returns immediately.

If not, it queries the database, stores the result in the cache, and returns it.



```text id="u2m8vh"
Incoming Request
       │
       ▼
Check Cache
   │        │
 Hit      Miss
  │         │
  ▼         ▼
Return   Database
             │
             ▼
      Save to Cache
             │
             ▼
        Return Data
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Advantages
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Simple to implement&lt;/li&gt;
&lt;li&gt;Reduces database traffic&lt;/li&gt;
&lt;li&gt;Only caches data that is actually requested&lt;/li&gt;
&lt;li&gt;Works well for read-heavy applications&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Disadvantages
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;First request is slower&lt;/li&gt;
&lt;li&gt;Cache misses still reach the database&lt;/li&gt;
&lt;/ul&gt;


&lt;h1&gt;
  
  
  Rust Example
&lt;/h1&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;find_product&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Uuid&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Result&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Product&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nf"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
        &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.cache&lt;/span&gt;&lt;span class="nf"&gt;.get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="k"&gt;.await&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
        &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.repository&lt;/span&gt;&lt;span class="nf"&gt;.find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="k"&gt;.await&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.cache&lt;/span&gt;
        &lt;span class="nf"&gt;.set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;.await&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nf"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This implementation is remarkably small, yet it can eliminate thousands of unnecessary database queries every hour.&lt;/p&gt;


&lt;h1&gt;
  
  
  Strategy 2: Write-Through Cache
&lt;/h1&gt;

&lt;p&gt;Instead of waiting for the next request, write-through updates the cache whenever data changes.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```text id="f5xqwp"&lt;br&gt;
Application&lt;br&gt;
      │&lt;br&gt;
      ▼&lt;br&gt;
 Update Database&lt;br&gt;
      │&lt;br&gt;
      ▼&lt;br&gt;
 Update Cache&lt;br&gt;
      │&lt;br&gt;
      ▼&lt;br&gt;
 Return Success&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


The cache and database remain synchronized.

Future reads are immediately available.

### Best for

* Frequently accessed data
* User profiles
* Product catalogs
* Configuration settings

---

# Strategy 3: Write-Behind (Write-Back)

Sometimes writing directly to the database becomes expensive.

Instead, the application writes to the cache first.

The cache later persists changes asynchronously.



```text id="k9yrab"
Application
      │
      ▼
 Write Cache
      │
      ▼
Return Success
      │
      ▼
Background Worker
      │
      ▼
Database
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This approach dramatically improves write performance.&lt;/p&gt;

&lt;p&gt;However, it requires careful handling to avoid losing data if the cache fails before persistence.&lt;/p&gt;


&lt;h1&gt;
  
  
  Strategy 4: Read-Through Cache
&lt;/h1&gt;

&lt;p&gt;In this strategy, the application never talks directly to the database.&lt;/p&gt;

&lt;p&gt;The cache becomes responsible for loading missing data.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```text id="t4mnqs"&lt;br&gt;
Application&lt;br&gt;
      │&lt;br&gt;
      ▼&lt;br&gt;
Cache Layer&lt;br&gt;
 │         │&lt;br&gt;
Hit      Miss&lt;br&gt;
 │         │&lt;br&gt;
 ▼         ▼&lt;br&gt;
Data   Load Database&lt;br&gt;
          │&lt;br&gt;
          ▼&lt;br&gt;
      Store Cache&lt;br&gt;
          │&lt;br&gt;
          ▼&lt;br&gt;
     Return Data&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


This keeps application code simpler because the cache handles loading automatically.

---

# Strategy 5: Distributed Caching

As applications grow, one cache server eventually becomes insufficient.

Distributed caches solve this problem.



```text id="g8lrcm"
          API Cluster
     ┌────────┼────────┐
     ▼        ▼        ▼
 App1     App2     App3
     │        │        │
     └────────┼────────┘
              ▼
      Redis Cluster
       │     │     │
       ▼     ▼     ▼
   Node1 Node2 Node3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now cached data scales alongside the application.&lt;/p&gt;

&lt;p&gt;This architecture powers many high-traffic platforms.&lt;/p&gt;


&lt;h1&gt;
  
  
  Strategy 6: HTTP Response Caching
&lt;/h1&gt;

&lt;p&gt;Sometimes entire API responses can be cached.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```text id="v7yape"&lt;br&gt;
Client&lt;br&gt;
   │&lt;br&gt;
   ▼&lt;br&gt;
CDN / Reverse Proxy&lt;br&gt;
 │              │&lt;br&gt;
Hit            Miss&lt;br&gt;
 │              │&lt;br&gt;
 ▼              ▼&lt;br&gt;
Response      API Server&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


Content Delivery Networks (CDNs) often cache images, CSS, JavaScript, and even API responses.

The request never reaches your backend.

That means lower latency and reduced server costs.

---

# Cache Expiration Matters

A cache that never expires eventually becomes incorrect.

Every cached value should have a lifetime.



```text id="m3utfh"
Product Cache

Laptop

TTL: 10 Minutes

↓

Expired?

↓

Reload Database
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Choosing the correct Time-To-Live (TTL) is an engineering trade-off.&lt;/p&gt;

&lt;p&gt;Too short:&lt;/p&gt;

&lt;p&gt;Frequent database queries.&lt;/p&gt;

&lt;p&gt;Too long:&lt;/p&gt;

&lt;p&gt;Stale information.&lt;/p&gt;

&lt;p&gt;The right value depends on how often the underlying data changes.&lt;/p&gt;


&lt;h1&gt;
  
  
  Cache Invalidation Is Hard
&lt;/h1&gt;

&lt;p&gt;One famous quote in software engineering says:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"There are only two hard things in Computer Science: cache invalidation and naming things."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The challenge is knowing exactly when cached information should be removed.&lt;/p&gt;

&lt;p&gt;Suppose a product price changes.&lt;/p&gt;

&lt;p&gt;The database updates.&lt;/p&gt;

&lt;p&gt;If the cache isn't updated too, users continue seeing the old price.&lt;/p&gt;

&lt;p&gt;That's why invalidation strategies are just as important as caching strategies.&lt;/p&gt;


&lt;h1&gt;
  
  
  Combining Multiple Cache Layers
&lt;/h1&gt;

&lt;p&gt;Large applications rarely depend on a single cache.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```text id="q2ehik"&lt;br&gt;
Browser Cache&lt;br&gt;
      │&lt;br&gt;
      ▼&lt;br&gt;
CDN Cache&lt;br&gt;
      │&lt;br&gt;
      ▼&lt;br&gt;
Reverse Proxy&lt;br&gt;
      │&lt;br&gt;
      ▼&lt;br&gt;
Redis&lt;br&gt;
      │&lt;br&gt;
      ▼&lt;br&gt;
Database&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


Each layer removes work from the layer below it.

This dramatically improves scalability.

---

# Monitoring Cache Performance

Adding a cache isn't enough.

Engineers also monitor its effectiveness.

Important metrics include:

* Cache hit ratio
* Cache miss ratio
* Memory usage
* Eviction rate
* Expiration frequency
* Response latency

A cache with a poor hit rate may simply consume memory without improving performance.

Monitoring reveals whether the strategy is actually working.

---

# Practical Example: Redis Integration

A simplified service might look like this.



```rust
pub async fn get_user(
    &amp;amp;self,
    id: Uuid,
) -&amp;gt; Result&amp;lt;User&amp;gt; {

    if let Some(user) =
        self.redis.get(id).await? {

        return Ok(user);
    }

    let user =
        self.repository.find(id).await?;

    self.redis
        .set_with_ttl(
            id,
            &amp;amp;user,
            600
        )
        .await?;

    Ok(user)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This implementation checks Redis first.&lt;/p&gt;

&lt;p&gt;If no value exists, the database is queried.&lt;/p&gt;

&lt;p&gt;The result is then cached for ten minutes before being returned.&lt;/p&gt;

&lt;p&gt;Small code.&lt;/p&gt;

&lt;p&gt;Massive impact.&lt;/p&gt;




&lt;h1&gt;
  
  
  When Not to Cache
&lt;/h1&gt;

&lt;p&gt;Caching is powerful, but not everything benefits from it.&lt;/p&gt;

&lt;p&gt;Avoid caching data that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Changes every second&lt;/li&gt;
&lt;li&gt;Contains highly sensitive user information without proper isolation&lt;/li&gt;
&lt;li&gt;Must always reflect the latest state&lt;/li&gt;
&lt;li&gt;Costs more to invalidate than to compute&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Good engineering is knowing when &lt;strong&gt;not&lt;/strong&gt; to optimize.&lt;/p&gt;




&lt;h1&gt;
  
  
  Lessons Experience Taught Me
&lt;/h1&gt;

&lt;p&gt;Earlier in my career, I saw caching as something I could add after performance problems appeared.&lt;/p&gt;

&lt;p&gt;Now I think differently.&lt;/p&gt;

&lt;p&gt;The architecture itself should identify opportunities to reuse work.&lt;/p&gt;

&lt;p&gt;If an endpoint is expected to receive thousands of identical requests, caching shouldn't be an afterthought.&lt;/p&gt;

&lt;p&gt;It should be part of the design.&lt;/p&gt;

&lt;p&gt;Experience also taught me that the best cache isn't always the largest one.&lt;/p&gt;

&lt;p&gt;It's the one with the highest hit rate, the simplest invalidation strategy, and the clearest purpose.&lt;/p&gt;




&lt;h1&gt;
  
  
  Final Thoughts
&lt;/h1&gt;

&lt;p&gt;Caching is one of those engineering concepts that appears deceptively simple.&lt;/p&gt;

&lt;p&gt;Store some data.&lt;/p&gt;

&lt;p&gt;Retrieve it later.&lt;/p&gt;

&lt;p&gt;Avoid unnecessary work.&lt;/p&gt;

&lt;p&gt;Yet beneath that simplicity lies one of the most influential techniques in backend engineering.&lt;/p&gt;

&lt;p&gt;The world's busiest applications rely on carefully designed caching strategies to remain responsive under enormous traffic.&lt;/p&gt;

&lt;p&gt;But the true value of caching extends beyond speed.&lt;/p&gt;

&lt;p&gt;It protects databases from unnecessary load.&lt;/p&gt;

&lt;p&gt;It reduces infrastructure costs.&lt;/p&gt;

&lt;p&gt;It improves user experience.&lt;/p&gt;

&lt;p&gt;It enables applications to scale gracefully.&lt;/p&gt;

&lt;p&gt;Most importantly, it changes how we think about software.&lt;/p&gt;

&lt;p&gt;Instead of asking, &lt;strong&gt;"How can I make this query faster?"&lt;/strong&gt;, we begin asking, &lt;strong&gt;"Do I need to execute this query at all?"&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That shift in thinking is powerful.&lt;/p&gt;

&lt;p&gt;It transforms optimization from making computers work harder to helping them work smarter.&lt;/p&gt;

&lt;p&gt;And in many ways, that's what great backend engineering is all about—not doing more work, but designing systems that accomplish more by doing less.&lt;/p&gt;

</description>
      <category>api</category>
      <category>softwaredevelopment</category>
      <category>backend</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>How to Build APIs That Handle Millions of Requests</title>
      <dc:creator>Derek mwale</dc:creator>
      <pubDate>Sat, 01 Aug 2026 16:59:10 +0000</pubDate>
      <link>https://dev.to/derekmwale/how-to-build-apis-that-handle-millions-of-requests-53c4</link>
      <guid>https://dev.to/derekmwale/how-to-build-apis-that-handle-millions-of-requests-53c4</guid>
      <description>&lt;p&gt;When most developers build their first API, they focus on one question:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"Does it work?"&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And that's exactly the right question to ask in the beginning.&lt;/p&gt;

&lt;p&gt;Can users register?&lt;/p&gt;

&lt;p&gt;Can they log in?&lt;/p&gt;

&lt;p&gt;Can they retrieve data?&lt;/p&gt;

&lt;p&gt;Can they update a resource?&lt;/p&gt;

&lt;p&gt;At that stage, correctness matters more than performance.&lt;/p&gt;

&lt;p&gt;But after shipping software into production, another question slowly becomes more important.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"Will it still work when millions of requests arrive?"&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That is where software engineering becomes systems engineering.&lt;/p&gt;

&lt;p&gt;Handling millions of requests isn't about writing one brilliant algorithm.&lt;/p&gt;

&lt;p&gt;It isn't about choosing the fastest programming language.&lt;/p&gt;

&lt;p&gt;It isn't about buying a larger server.&lt;/p&gt;

&lt;p&gt;It's about designing an ecosystem where every component shares responsibility.&lt;/p&gt;

&lt;p&gt;I've come to believe that scalable APIs aren't built through optimization alone.&lt;/p&gt;

&lt;p&gt;They're built through architecture.&lt;/p&gt;




&lt;h1&gt;
  
  
  Scaling Begins Long Before Traffic Arrives
&lt;/h1&gt;

&lt;p&gt;One of the biggest misconceptions in backend engineering is that scalability is something you add later.&lt;/p&gt;

&lt;p&gt;It isn't.&lt;/p&gt;

&lt;p&gt;Scalability is a design decision.&lt;/p&gt;

&lt;p&gt;If an API depends on one overloaded database, no amount of optimization will save it.&lt;/p&gt;

&lt;p&gt;If business logic is tightly coupled to HTTP requests, scaling becomes painful.&lt;/p&gt;

&lt;p&gt;If every request performs unnecessary work, traffic eventually overwhelms the system.&lt;/p&gt;

&lt;p&gt;Architecture determines scalability long before the first million requests ever arrive.&lt;/p&gt;




&lt;h1&gt;
  
  
  Understanding the Journey of a Request
&lt;/h1&gt;

&lt;p&gt;Every request travels through many layers before reaching the user.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                    Client
                       │
                       ▼
                DNS Resolution
                       │
                       ▼
                 Load Balancer
                       │
                       ▼
                  API Gateway
                       │
                       ▼
            Authentication Layer
                       │
                       ▼
             Rate Limiting Check
                       │
                       ▼
             Application Service
                │            │
                ▼            ▼
           Redis Cache   PostgreSQL
                │            │
                └─────┬──────┘
                      ▼
              JSON Response
                      │
                      ▼
                    Client
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When millions of requests arrive, every layer becomes important.&lt;/p&gt;

&lt;p&gt;Optimizing only the controller misses the bigger picture.&lt;/p&gt;




&lt;h1&gt;
  
  
  Design Stateless APIs
&lt;/h1&gt;

&lt;p&gt;One lesson that fundamentally changed how I design backend systems was understanding statelessness.&lt;/p&gt;

&lt;p&gt;Each request should contain everything the server needs.&lt;/p&gt;

&lt;p&gt;The server should not rely on memory from previous requests.&lt;/p&gt;

&lt;p&gt;Instead of storing session data in application memory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Server Memory

User A Session

User B Session

User C Session
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I prefer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Client
   │
   ▼
JWT Token
   │
   ▼
Any API Server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now any server can process the request.&lt;/p&gt;

&lt;p&gt;Adding more servers becomes trivial.&lt;/p&gt;

&lt;p&gt;Horizontal scaling becomes possible.&lt;/p&gt;




&lt;h1&gt;
  
  
  Load Balancers Are the Unsung Heroes
&lt;/h1&gt;

&lt;p&gt;One server can only do so much.&lt;/p&gt;

&lt;p&gt;Eventually requests must be distributed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                 Internet
                     │
                     ▼
              Load Balancer
         ┌────────┼─────────┐
         ▼        ▼         ▼
     API 1     API 2     API 3
         │        │         │
         └────────┼─────────┘
                  ▼
             Shared Database
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The load balancer quietly becomes one of the most valuable components in the architecture.&lt;/p&gt;

&lt;p&gt;Users rarely notice it.&lt;/p&gt;

&lt;p&gt;But without it, growth becomes impossible.&lt;/p&gt;




&lt;h1&gt;
  
  
  Cache Before You Query
&lt;/h1&gt;

&lt;p&gt;One lesson production taught me repeatedly:&lt;/p&gt;

&lt;p&gt;Databases are expensive.&lt;/p&gt;

&lt;p&gt;Not because they're slow.&lt;/p&gt;

&lt;p&gt;Because unnecessary queries accumulate.&lt;/p&gt;

&lt;p&gt;A cache avoids repeating work.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;          Incoming Request
                 │
                 ▼
            Redis Cache
             │        │
           Hit       Miss
            │         │
            ▼         ▼
      Return Data   Database
                        │
                        ▼
                 Store in Cache
                        │
                        ▼
                 Return Response
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If thousands of users request the same information every minute, the database shouldn't answer the same question thousands of times.&lt;/p&gt;

&lt;p&gt;Caching transforms scalability.&lt;/p&gt;




&lt;h1&gt;
  
  
  Move Slow Work Into Background Jobs
&lt;/h1&gt;

&lt;p&gt;Not everything belongs inside an HTTP request.&lt;/p&gt;

&lt;p&gt;Suppose a user uploads an image.&lt;/p&gt;

&lt;p&gt;The API could:&lt;/p&gt;

&lt;p&gt;Resize it.&lt;/p&gt;

&lt;p&gt;Generate thumbnails.&lt;/p&gt;

&lt;p&gt;Send notifications.&lt;/p&gt;

&lt;p&gt;Analyze metadata.&lt;/p&gt;

&lt;p&gt;Store backups.&lt;/p&gt;

&lt;p&gt;Or…&lt;/p&gt;

&lt;p&gt;It could simply save the upload and return immediately.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        Upload Request
              │
              ▼
        Save Metadata
              │
              ▼
       Return Success
              │
              ▼
        Publish Event
              │
      ┌───────┼────────┐
      ▼       ▼        ▼
 Resize   Thumbnail   Notify
 Image     Service    Service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Users experience faster responses.&lt;/p&gt;

&lt;p&gt;Servers process expensive work independently.&lt;/p&gt;

&lt;p&gt;Everyone wins.&lt;/p&gt;




&lt;h1&gt;
  
  
  Separate Responsibilities
&lt;/h1&gt;

&lt;p&gt;Large APIs often become difficult to scale because every service tries to do everything.&lt;/p&gt;

&lt;p&gt;Today I prefer smaller responsibilities.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                  API Gateway
                       │
      ┌────────────────┼────────────────┐
      ▼                ▼                ▼
 User Service    Payment Service   Product Service
      │                │                │
      ▼                ▼                ▼
 Database        Payment API       Product DB
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Services become easier to deploy.&lt;/p&gt;

&lt;p&gt;Easier to monitor.&lt;/p&gt;

&lt;p&gt;Easier to replace.&lt;/p&gt;

&lt;p&gt;Growth becomes incremental instead of disruptive.&lt;/p&gt;




&lt;h1&gt;
  
  
  A Practical Rust Implementation
&lt;/h1&gt;

&lt;p&gt;The controller should remain small.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;get_product&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Uuid&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;service&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ProductService&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Result&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;ApiResponse&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Product&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
        &lt;span class="n"&gt;service&lt;/span&gt;&lt;span class="nf"&gt;.find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="k"&gt;.await&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nf"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nn"&gt;ApiResponse&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;success&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The service handles caching before querying the database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Uuid&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Result&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Product&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nf"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
        &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.cache&lt;/span&gt;&lt;span class="nf"&gt;.get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="k"&gt;.await&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
        &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.repository&lt;/span&gt;&lt;span class="nf"&gt;.find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="k"&gt;.await&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.cache&lt;/span&gt;
        &lt;span class="nf"&gt;.set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;.await&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nf"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice what happens.&lt;/p&gt;

&lt;p&gt;The database isn't contacted unless necessary.&lt;/p&gt;

&lt;p&gt;Multiply this by millions of requests and the savings become enormous.&lt;/p&gt;




&lt;h1&gt;
  
  
  Protect the API With Rate Limiting
&lt;/h1&gt;

&lt;p&gt;Scalability isn't only about serving more users.&lt;/p&gt;

&lt;p&gt;It's also about protecting your infrastructure.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User Request
      │
      ▼
Rate Limiter
      │
  Requests &amp;gt; Limit?
      │        │
     No       Yes
      │        │
      ▼        ▼
 Continue   HTTP 429
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Without limits, one client can unintentionally—or intentionally—consume disproportionate resources.&lt;/p&gt;

&lt;p&gt;Healthy systems protect themselves.&lt;/p&gt;




&lt;h1&gt;
  
  
  Design Database Queries Carefully
&lt;/h1&gt;

&lt;p&gt;The fastest API in the world cannot compensate for inefficient SQL.&lt;/p&gt;

&lt;p&gt;Poor query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Better query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;user_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt;
&lt;span class="k"&gt;LIMIT&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Even better:&lt;/p&gt;

&lt;p&gt;Add indexes.&lt;/p&gt;

&lt;p&gt;Avoid unnecessary joins.&lt;/p&gt;

&lt;p&gt;Paginate results.&lt;/p&gt;

&lt;p&gt;Return only required fields.&lt;/p&gt;

&lt;p&gt;Database optimization often produces larger performance improvements than application optimization.&lt;/p&gt;




&lt;h1&gt;
  
  
  Pagination Is Mandatory
&lt;/h1&gt;

&lt;p&gt;Collections grow.&lt;/p&gt;

&lt;p&gt;Endpoints should expect that.&lt;/p&gt;

&lt;p&gt;Instead of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;GET /users
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Prefer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;GET /users?page=2&amp;amp;limit=50
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or cursor-based pagination.&lt;/p&gt;

&lt;p&gt;Returning one million records in one response helps no one.&lt;/p&gt;




&lt;h1&gt;
  
  
  Monitor Everything
&lt;/h1&gt;

&lt;p&gt;You cannot optimize what you cannot see.&lt;/p&gt;

&lt;p&gt;Modern APIs should monitor:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Response time&lt;/li&gt;
&lt;li&gt;Request count&lt;/li&gt;
&lt;li&gt;Error rate&lt;/li&gt;
&lt;li&gt;CPU usage&lt;/li&gt;
&lt;li&gt;Memory usage&lt;/li&gt;
&lt;li&gt;Cache hit ratio&lt;/li&gt;
&lt;li&gt;Database latency&lt;/li&gt;
&lt;li&gt;Queue length&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Monitoring transforms intuition into evidence.&lt;/p&gt;




&lt;h1&gt;
  
  
  Think About Failure Before Success
&lt;/h1&gt;

&lt;p&gt;Large systems eventually encounter failures.&lt;/p&gt;

&lt;p&gt;Databases restart.&lt;/p&gt;

&lt;p&gt;Redis disconnects.&lt;/p&gt;

&lt;p&gt;External APIs timeout.&lt;/p&gt;

&lt;p&gt;Design for resilience.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;External Service
        │
Available?
 │         │
Yes       No
 │         │
 ▼         ▼
Continue  Retry
             │
             ▼
      Cached Response
             │
             ▼
      Error Monitoring
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Graceful degradation keeps systems alive.&lt;/p&gt;




&lt;h1&gt;
  
  
  Horizontal Scaling Changes Everything
&lt;/h1&gt;

&lt;p&gt;Eventually one server becomes many.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;               Load Balancer
          ┌────────┼────────┐
          ▼        ▼        ▼
       Server1  Server2  Server3
          │        │        │
          └────────┼────────┘
                   ▼
          Shared Redis Cluster
                   │
                   ▼
           PostgreSQL Cluster
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The application should not care which server processes the request.&lt;/p&gt;

&lt;p&gt;Stateless design makes this possible.&lt;/p&gt;




&lt;h1&gt;
  
  
  Experience Changed My Perspective
&lt;/h1&gt;

&lt;p&gt;Earlier in my career, I admired APIs with many features.&lt;/p&gt;

&lt;p&gt;Today I admire APIs that remain calm under pressure.&lt;/p&gt;

&lt;p&gt;Fast responses.&lt;/p&gt;

&lt;p&gt;Predictable behavior.&lt;/p&gt;

&lt;p&gt;Simple architecture.&lt;/p&gt;

&lt;p&gt;Clear boundaries.&lt;/p&gt;

&lt;p&gt;Reliable monitoring.&lt;/p&gt;

&lt;p&gt;Graceful failure.&lt;/p&gt;

&lt;p&gt;Scalability is rarely dramatic.&lt;/p&gt;

&lt;p&gt;Most of the time it's the result of hundreds of small engineering decisions working together.&lt;/p&gt;




&lt;h1&gt;
  
  
  Final Thoughts
&lt;/h1&gt;

&lt;p&gt;When people hear that an API handles millions of requests, they often imagine extraordinary hardware or revolutionary algorithms.&lt;/p&gt;

&lt;p&gt;In reality, the secret is usually much quieter.&lt;/p&gt;

&lt;p&gt;Requests are distributed instead of concentrated.&lt;/p&gt;

&lt;p&gt;Frequently accessed data is cached instead of queried repeatedly.&lt;/p&gt;

&lt;p&gt;Background jobs perform expensive work asynchronously.&lt;/p&gt;

&lt;p&gt;Services have clear responsibilities.&lt;/p&gt;

&lt;p&gt;Databases are carefully indexed.&lt;/p&gt;

&lt;p&gt;Rate limiting protects infrastructure.&lt;/p&gt;

&lt;p&gt;Monitoring reveals problems before users do.&lt;/p&gt;

&lt;p&gt;Failures are anticipated instead of ignored.&lt;/p&gt;

&lt;p&gt;The most scalable APIs I've encountered don't feel complicated.&lt;/p&gt;

&lt;p&gt;They feel organized.&lt;/p&gt;

&lt;p&gt;Every component understands its role.&lt;/p&gt;

&lt;p&gt;Every request follows a predictable path.&lt;/p&gt;

&lt;p&gt;Every optimization removes unnecessary work rather than adding unnecessary complexity.&lt;/p&gt;

&lt;p&gt;Perhaps that's the most important lesson I've learned about scalability.&lt;/p&gt;

&lt;p&gt;Building an API that survives millions of requests isn't about creating one incredibly powerful server.&lt;/p&gt;

&lt;p&gt;It's about creating an architecture where thousands of ordinary requests can flow through ordinary components without overwhelming any single part of the system.&lt;/p&gt;

&lt;p&gt;In the end, scalability is less about speed and more about balance.&lt;/p&gt;

&lt;p&gt;When each layer does exactly what it should—and nothing more—the system continues to grow gracefully, one request at a time.&lt;/p&gt;

&lt;p&gt;And that's the kind of backend architecture I aspire to build.&lt;/p&gt;

</description>
      <category>api</category>
      <category>softwaredevelopment</category>
      <category>software</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>Things I Only Learned After Shipping Real Software</title>
      <dc:creator>Derek mwale</dc:creator>
      <pubDate>Fri, 31 Jul 2026 13:48:53 +0000</pubDate>
      <link>https://dev.to/derekmwale/things-i-only-learned-after-shipping-real-software-3bpd</link>
      <guid>https://dev.to/derekmwale/things-i-only-learned-after-shipping-real-software-3bpd</guid>
      <description>&lt;p&gt;There is a difference between building software that works and building software that survives.&lt;/p&gt;

&lt;p&gt;I didn't fully understand that until I started shipping real applications.&lt;/p&gt;

&lt;p&gt;At university, software felt predictable.&lt;/p&gt;

&lt;p&gt;Projects ended when the assignment was submitted.&lt;/p&gt;

&lt;p&gt;Requirements stayed the same.&lt;/p&gt;

&lt;p&gt;Users behaved exactly as expected.&lt;/p&gt;

&lt;p&gt;Servers never crashed.&lt;/p&gt;

&lt;p&gt;Nobody tried to abuse the system.&lt;/p&gt;

&lt;p&gt;Nobody entered invalid data.&lt;/p&gt;

&lt;p&gt;Nobody clicked the same button twenty times.&lt;/p&gt;

&lt;p&gt;Reality is very different.&lt;/p&gt;

&lt;p&gt;Real software lives in an unpredictable world.&lt;/p&gt;

&lt;p&gt;Users surprise you.&lt;/p&gt;

&lt;p&gt;Businesses change direction.&lt;/p&gt;

&lt;p&gt;Traffic spikes unexpectedly.&lt;/p&gt;

&lt;p&gt;Databases fail.&lt;/p&gt;

&lt;p&gt;Networks become unreliable.&lt;/p&gt;

&lt;p&gt;Browsers behave differently.&lt;/p&gt;

&lt;p&gt;APIs evolve.&lt;/p&gt;

&lt;p&gt;Requirements never stop moving.&lt;/p&gt;

&lt;p&gt;The biggest lessons I have learned as a software engineer didn't come from books.&lt;/p&gt;

&lt;p&gt;They came after deployment.&lt;/p&gt;

&lt;p&gt;Production became the greatest teacher I have ever had.&lt;/p&gt;




&lt;h1&gt;
  
  
  Shipping Is the Beginning, Not the Finish
&lt;/h1&gt;

&lt;p&gt;Earlier in my career, I thought deployment was the final milestone.&lt;/p&gt;

&lt;p&gt;Push the code.&lt;/p&gt;

&lt;p&gt;Celebrate.&lt;/p&gt;

&lt;p&gt;Move on.&lt;/p&gt;

&lt;p&gt;Experience taught me something completely different.&lt;/p&gt;

&lt;p&gt;Deployment is where learning begins.&lt;/p&gt;

&lt;p&gt;Before launch, you're mostly making assumptions.&lt;/p&gt;

&lt;p&gt;After launch, reality starts giving feedback.&lt;/p&gt;

&lt;p&gt;Every user interaction becomes data.&lt;/p&gt;

&lt;p&gt;Every support ticket reveals friction.&lt;/p&gt;

&lt;p&gt;Every performance graph tells a story.&lt;/p&gt;

&lt;p&gt;Software becomes a conversation between engineers and the real world.&lt;/p&gt;




&lt;h1&gt;
  
  
  Architecture Becomes Visible Under Load
&lt;/h1&gt;

&lt;p&gt;Small applications can survive questionable architecture.&lt;/p&gt;

&lt;p&gt;Large applications cannot.&lt;/p&gt;

&lt;p&gt;The first hundred users rarely expose weaknesses.&lt;/p&gt;

&lt;p&gt;The first hundred thousand usually do.&lt;/p&gt;

&lt;p&gt;Features that seemed independent suddenly compete for resources.&lt;/p&gt;

&lt;p&gt;Database queries multiply.&lt;/p&gt;

&lt;p&gt;Caches become essential.&lt;/p&gt;

&lt;p&gt;Background jobs accumulate.&lt;/p&gt;

&lt;p&gt;Memory usage grows.&lt;/p&gt;

&lt;p&gt;Latency increases.&lt;/p&gt;

&lt;p&gt;Good architecture isn't tested when everything is quiet.&lt;/p&gt;

&lt;p&gt;It is tested when everything becomes busy.&lt;/p&gt;




&lt;h1&gt;
  
  
  Every Request Is a Journey
&lt;/h1&gt;

&lt;p&gt;One realization changed how I think about backend systems.&lt;/p&gt;

&lt;p&gt;Every request travels through an entire ecosystem.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                User Request
                     │
                     ▼
               Load Balancer
                     │
                     ▼
              Authentication
                     │
                     ▼
              API Controller
                     │
                     ▼
             Business Service
                     │
          ┌──────────┴──────────┐
          ▼                     ▼
     Redis Cache          PostgreSQL
          │                     │
          └──────────┬──────────┘
                     ▼
              Business Result
                     │
                     ▼
               HTTP Response
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Earlier, I only focused on the controller.&lt;/p&gt;

&lt;p&gt;Today I think about the entire journey.&lt;/p&gt;

&lt;p&gt;Every component contributes to the user experience.&lt;/p&gt;




&lt;h1&gt;
  
  
  Monitoring Is More Valuable Than Logging
&lt;/h1&gt;

&lt;p&gt;My first applications had log files.&lt;/p&gt;

&lt;p&gt;My current applications have observability.&lt;/p&gt;

&lt;p&gt;There's a difference.&lt;/p&gt;

&lt;p&gt;Logs tell you what happened.&lt;/p&gt;

&lt;p&gt;Monitoring tells you what is happening.&lt;/p&gt;

&lt;p&gt;Dashboards answer questions before users ask them.&lt;/p&gt;

&lt;p&gt;Which endpoint is slow?&lt;/p&gt;

&lt;p&gt;Which database query is expensive?&lt;/p&gt;

&lt;p&gt;How much memory is the application using?&lt;/p&gt;

&lt;p&gt;What percentage of requests are failing?&lt;/p&gt;

&lt;p&gt;Without visibility, debugging becomes guessing.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Database Is Never Just Storage
&lt;/h1&gt;

&lt;p&gt;Earlier, I thought databases stored information.&lt;/p&gt;

&lt;p&gt;Now I think databases shape applications.&lt;/p&gt;

&lt;p&gt;Poor schemas create complicated code.&lt;/p&gt;

&lt;p&gt;Good schemas simplify everything.&lt;/p&gt;

&lt;p&gt;Indexes affect performance.&lt;/p&gt;

&lt;p&gt;Constraints prevent bugs.&lt;/p&gt;

&lt;p&gt;Relationships define business rules.&lt;/p&gt;

&lt;p&gt;The database quietly influences every API endpoint.&lt;/p&gt;

&lt;p&gt;The longer I build software, the more respect I have for data modeling.&lt;/p&gt;




&lt;h1&gt;
  
  
  Users Never Behave the Way You Expect
&lt;/h1&gt;

&lt;p&gt;Developers imagine ideal users.&lt;/p&gt;

&lt;p&gt;Production introduces real users.&lt;/p&gt;

&lt;p&gt;Someone uploads a 10 GB file.&lt;/p&gt;

&lt;p&gt;Someone submits an empty form.&lt;/p&gt;

&lt;p&gt;Someone refreshes the payment page repeatedly.&lt;/p&gt;

&lt;p&gt;Someone disconnects halfway through a transaction.&lt;/p&gt;

&lt;p&gt;Someone pastes emoji into a phone number field.&lt;/p&gt;

&lt;p&gt;Reality is wonderfully creative.&lt;/p&gt;

&lt;p&gt;Software must be equally resilient.&lt;/p&gt;




&lt;h1&gt;
  
  
  Failure Should Be Expected
&lt;/h1&gt;

&lt;p&gt;One lesson arrived the hard way.&lt;/p&gt;

&lt;p&gt;Everything eventually fails.&lt;/p&gt;

&lt;p&gt;Networks timeout.&lt;/p&gt;

&lt;p&gt;Servers restart.&lt;/p&gt;

&lt;p&gt;Disks fill.&lt;/p&gt;

&lt;p&gt;Third-party APIs disappear.&lt;/p&gt;

&lt;p&gt;Caches expire.&lt;/p&gt;

&lt;p&gt;Databases temporarily disconnect.&lt;/p&gt;

&lt;p&gt;Instead of asking:&lt;/p&gt;

&lt;p&gt;"Will this fail?"&lt;/p&gt;

&lt;p&gt;I now ask:&lt;/p&gt;

&lt;p&gt;"How should the system respond when it fails?"&lt;/p&gt;




&lt;h1&gt;
  
  
  Designing for Failure
&lt;/h1&gt;

&lt;p&gt;Modern systems are built around graceful degradation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;          External API
               │
        Available?
        │       │
      Yes       No
       │         │
       ▼         ▼
Return Live   Return Cached
   Data         Response
       │         │
       └────┬────┘
            ▼
      Notify Monitoring
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Failure isn't the exception.&lt;/p&gt;

&lt;p&gt;It is another architectural scenario.&lt;/p&gt;




&lt;h1&gt;
  
  
  Thin Controllers, Smart Services
&lt;/h1&gt;

&lt;p&gt;One thing I would never go back to is placing business logic inside controllers.&lt;/p&gt;

&lt;p&gt;Today my controllers simply coordinate requests.&lt;/p&gt;

&lt;p&gt;The real intelligence lives inside services.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;create_user&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;UserRequest&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;service&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;UserService&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Result&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="n"&gt;service&lt;/span&gt;&lt;span class="nf"&gt;.create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="k"&gt;.await&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The service contains the business rules.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;impl&lt;/span&gt; &lt;span class="n"&gt;UserService&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;UserRequest&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Result&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
            &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.repository&lt;/span&gt;
                &lt;span class="nf"&gt;.save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="k"&gt;.await&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.events&lt;/span&gt;
            &lt;span class="nf"&gt;.publish&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;UserCreated&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="py"&gt;.id&lt;/span&gt;
            &lt;span class="p"&gt;})&lt;/span&gt;
            &lt;span class="k"&gt;.await&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="nf"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Controllers stay simple.&lt;/p&gt;

&lt;p&gt;Services remain reusable.&lt;/p&gt;

&lt;p&gt;Maintenance becomes easier.&lt;/p&gt;




&lt;h1&gt;
  
  
  Background Jobs Matter More Than I Expected
&lt;/h1&gt;

&lt;p&gt;Not everything belongs inside an HTTP request.&lt;/p&gt;

&lt;p&gt;Emails.&lt;/p&gt;

&lt;p&gt;Image processing.&lt;/p&gt;

&lt;p&gt;Notifications.&lt;/p&gt;

&lt;p&gt;Analytics.&lt;/p&gt;

&lt;p&gt;Video transcoding.&lt;/p&gt;

&lt;p&gt;Search indexing.&lt;/p&gt;

&lt;p&gt;These belong elsewhere.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      User Uploads Image
               │
               ▼
        Save Metadata
               │
               ▼
        Return Success
               │
               ▼
      Publish Event
               │
     ┌─────────┴─────────┐
     ▼                   ▼
 Resize Image      Generate Thumbnail
     ▼                   ▼
 Store Image       Update Database
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Queues dramatically improve responsiveness.&lt;/p&gt;

&lt;p&gt;Users shouldn't wait for work that can happen later.&lt;/p&gt;




&lt;h1&gt;
  
  
  Caching Changes Everything
&lt;/h1&gt;

&lt;p&gt;Caching used to feel like optimization.&lt;/p&gt;

&lt;p&gt;Now it feels like architecture.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        Incoming Request
               │
               ▼
         Cache Lookup
         │         │
      Hit          Miss
       │            │
       ▼            ▼
 Return Data   Query Database
                    │
                    ▼
             Store in Cache
                    │
                    ▼
              Return Result
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A well-designed cache can reduce database load by orders of magnitude.&lt;/p&gt;

&lt;p&gt;Performance often comes from avoiding work, not performing it faster.&lt;/p&gt;




&lt;h1&gt;
  
  
  APIs Are Long-Term Contracts
&lt;/h1&gt;

&lt;p&gt;Earlier I treated APIs as implementation details.&lt;/p&gt;

&lt;p&gt;Today I treat them like products.&lt;/p&gt;

&lt;p&gt;Every endpoint becomes a promise.&lt;/p&gt;

&lt;p&gt;Changing field names affects clients.&lt;/p&gt;

&lt;p&gt;Removing properties breaks integrations.&lt;/p&gt;

&lt;p&gt;Consistency becomes more valuable than cleverness.&lt;/p&gt;

&lt;p&gt;Versioning matters.&lt;/p&gt;

&lt;p&gt;Documentation matters.&lt;/p&gt;

&lt;p&gt;Predictability matters.&lt;/p&gt;




&lt;h1&gt;
  
  
  Shipping Changes Your Relationship With Code
&lt;/h1&gt;

&lt;p&gt;Writing software feels creative.&lt;/p&gt;

&lt;p&gt;Maintaining software feels educational.&lt;/p&gt;

&lt;p&gt;Old code becomes documentation.&lt;/p&gt;

&lt;p&gt;Earlier decisions become visible.&lt;/p&gt;

&lt;p&gt;Naming choices matter.&lt;/p&gt;

&lt;p&gt;Folder structures matter.&lt;/p&gt;

&lt;p&gt;Architecture matters.&lt;/p&gt;

&lt;p&gt;The code eventually teaches its author.&lt;/p&gt;

&lt;p&gt;Sometimes gently.&lt;/p&gt;

&lt;p&gt;Sometimes brutally.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Most Valuable Feature Is Simplicity
&lt;/h1&gt;

&lt;p&gt;One lesson keeps repeating.&lt;/p&gt;

&lt;p&gt;Simple systems survive longer.&lt;/p&gt;

&lt;p&gt;Simple APIs.&lt;/p&gt;

&lt;p&gt;Simple deployment pipelines.&lt;/p&gt;

&lt;p&gt;Simple naming.&lt;/p&gt;

&lt;p&gt;Simple responsibilities.&lt;/p&gt;

&lt;p&gt;Complexity accumulates naturally.&lt;/p&gt;

&lt;p&gt;Simplicity requires intention.&lt;/p&gt;




&lt;h1&gt;
  
  
  Software Is Built by Feedback
&lt;/h1&gt;

&lt;p&gt;The best ideas rarely arrive fully formed.&lt;/p&gt;

&lt;p&gt;Users improve products.&lt;/p&gt;

&lt;p&gt;Bug reports improve architecture.&lt;/p&gt;

&lt;p&gt;Performance metrics improve infrastructure.&lt;/p&gt;

&lt;p&gt;Production traffic improves scalability.&lt;/p&gt;

&lt;p&gt;Feedback shapes software more than planning ever can.&lt;/p&gt;




&lt;h1&gt;
  
  
  Experience Changed My Definition of Success
&lt;/h1&gt;

&lt;p&gt;Years ago, success meant finishing features.&lt;/p&gt;

&lt;p&gt;Today, success means reducing future complexity.&lt;/p&gt;

&lt;p&gt;Can another developer understand this?&lt;/p&gt;

&lt;p&gt;Can I debug this six months later?&lt;/p&gt;

&lt;p&gt;Can the system recover automatically?&lt;/p&gt;

&lt;p&gt;Can it scale gracefully?&lt;/p&gt;

&lt;p&gt;Can it evolve without breaking everything?&lt;/p&gt;

&lt;p&gt;Those questions matter more now than they once did.&lt;/p&gt;




&lt;h1&gt;
  
  
  Final Thoughts
&lt;/h1&gt;

&lt;p&gt;Looking back, I realize that the most important software engineering lessons were never written inside tutorials.&lt;/p&gt;

&lt;p&gt;They were written inside production systems.&lt;/p&gt;

&lt;p&gt;Every deployment challenged assumptions.&lt;/p&gt;

&lt;p&gt;Every unexpected bug revealed a blind spot.&lt;/p&gt;

&lt;p&gt;Every performance issue exposed architectural decisions I hadn't thought deeply enough about.&lt;/p&gt;

&lt;p&gt;Every user interaction reminded me that software exists for people, not for developers.&lt;/p&gt;

&lt;p&gt;Shipping real software taught me that architecture matters more than clever code.&lt;/p&gt;

&lt;p&gt;Observability matters more than guesswork.&lt;/p&gt;

&lt;p&gt;Resilience matters more than perfection.&lt;/p&gt;

&lt;p&gt;Maintainability matters more than speed of implementation.&lt;/p&gt;

&lt;p&gt;Feedback matters more than assumptions.&lt;/p&gt;

&lt;p&gt;Most importantly, it taught me that software engineering is less about predicting the future and more about designing systems that can adapt to it.&lt;/p&gt;

&lt;p&gt;No application is ever truly finished.&lt;/p&gt;

&lt;p&gt;It grows.&lt;/p&gt;

&lt;p&gt;It changes.&lt;/p&gt;

&lt;p&gt;It teaches.&lt;/p&gt;

&lt;p&gt;And if we're paying attention, every project leaves us a little wiser than the one before.&lt;/p&gt;

&lt;p&gt;That's why I no longer see deployment as the end of development.&lt;/p&gt;

&lt;p&gt;I see it as the moment the real education begins.&lt;/p&gt;

</description>
      <category>api</category>
      <category>software</category>
      <category>softwareengineering</category>
      <category>softwaredevelopment</category>
    </item>
    <item>
      <title>What I'd Build Differently Today</title>
      <dc:creator>Derek mwale</dc:creator>
      <pubDate>Fri, 31 Jul 2026 13:39:40 +0000</pubDate>
      <link>https://dev.to/derekmwale/what-id-build-differently-today-4hcp</link>
      <guid>https://dev.to/derekmwale/what-id-build-differently-today-4hcp</guid>
      <description>&lt;p&gt;One of the most valuable things software engineering has taught me is this:&lt;/p&gt;

&lt;p&gt;The code I was most proud of five years ago is probably the code I would rewrite today.&lt;/p&gt;

&lt;p&gt;Not because it was bad.&lt;/p&gt;

&lt;p&gt;Not because it failed.&lt;/p&gt;

&lt;p&gt;But because experience changes how you see systems.&lt;/p&gt;

&lt;p&gt;Earlier in my career, I believed software engineering was mostly about writing code.&lt;/p&gt;

&lt;p&gt;Today, I think it's mostly about making decisions.&lt;/p&gt;

&lt;p&gt;Every project leaves behind lessons.&lt;/p&gt;

&lt;p&gt;Some come from successful launches.&lt;/p&gt;

&lt;p&gt;Others come from production incidents at two in the morning.&lt;/p&gt;

&lt;p&gt;Some come from scaling problems.&lt;/p&gt;

&lt;p&gt;Others come from maintaining code you wrote years ago.&lt;/p&gt;

&lt;p&gt;Every application becomes a teacher.&lt;/p&gt;

&lt;p&gt;Looking back at the systems I've built, I don't regret them.&lt;/p&gt;

&lt;p&gt;I'm grateful for them.&lt;/p&gt;

&lt;p&gt;They taught me exactly what I'd build differently today.&lt;/p&gt;




&lt;h1&gt;
  
  
  I Would Design the Architecture Before the Features
&lt;/h1&gt;

&lt;p&gt;One of my earliest mistakes was thinking about features first.&lt;/p&gt;

&lt;p&gt;Users can register.&lt;/p&gt;

&lt;p&gt;Users can log in.&lt;/p&gt;

&lt;p&gt;Users can upload files.&lt;/p&gt;

&lt;p&gt;Users can purchase products.&lt;/p&gt;

&lt;p&gt;These were useful goals.&lt;/p&gt;

&lt;p&gt;But they weren't architectural goals.&lt;/p&gt;

&lt;p&gt;Today I start somewhere else.&lt;/p&gt;

&lt;p&gt;How will information flow?&lt;/p&gt;

&lt;p&gt;Where does business logic belong?&lt;/p&gt;

&lt;p&gt;Which components should know about each other?&lt;/p&gt;

&lt;p&gt;How will this system grow in three years?&lt;/p&gt;

&lt;p&gt;Features change.&lt;/p&gt;

&lt;p&gt;Architecture remains.&lt;/p&gt;




&lt;h1&gt;
  
  
  From Requests to Information Flow
&lt;/h1&gt;

&lt;p&gt;Every application is really a collection of information moving through a system.&lt;/p&gt;

&lt;p&gt;Once I understood that, software became much easier to reason about.&lt;/p&gt;

&lt;p&gt;Instead of asking:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;"How do I implement login?"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I now ask:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;"Where does authentication fit inside the architecture?"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Instead of asking:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;"How do I upload images?"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I ask:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;"How should media move through the system?"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The questions became architectural instead of functional.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Architecture I'd Build Today
&lt;/h1&gt;

&lt;p&gt;Instead of tightly coupling everything together, I'd organize the application into clear layers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                    Modern Application Architecture

                  Client (Web / Mobile)
                           │
                           ▼
                    REST / GraphQL API
                           │
                           ▼
                 Authentication Middleware
                           │
                           ▼
                  Application Services
               ┌───────────┴───────────┐
               ▼                       ▼
          Domain Logic           Background Jobs
               │                       │
               ▼                       ▼
         Repository Layer         Event Queue
               │                       │
               ▼                       ▼
         PostgreSQL / Redis      Email / Analytics
                           │
                           ▼
                  Monitoring &amp;amp; Logging
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every layer has one responsibility.&lt;/p&gt;

&lt;p&gt;The client presents information.&lt;/p&gt;

&lt;p&gt;The API receives requests.&lt;/p&gt;

&lt;p&gt;Services contain business logic.&lt;/p&gt;

&lt;p&gt;Repositories manage persistence.&lt;/p&gt;

&lt;p&gt;Queues handle asynchronous work.&lt;/p&gt;

&lt;p&gt;Monitoring observes everything.&lt;/p&gt;

&lt;p&gt;The architecture tells the story before the code does.&lt;/p&gt;




&lt;h1&gt;
  
  
  I Would Separate Business Logic Earlier
&lt;/h1&gt;

&lt;p&gt;Earlier versions of my projects often placed too much logic inside controllers.&lt;/p&gt;

&lt;p&gt;It worked.&lt;/p&gt;

&lt;p&gt;Until it didn't.&lt;/p&gt;

&lt;p&gt;Controllers became larger.&lt;/p&gt;

&lt;p&gt;Testing became harder.&lt;/p&gt;

&lt;p&gt;Features became interconnected.&lt;/p&gt;

&lt;p&gt;Today I'd keep controllers incredibly small.&lt;/p&gt;

&lt;p&gt;Their job is simple.&lt;/p&gt;

&lt;p&gt;Receive a request.&lt;/p&gt;

&lt;p&gt;Validate it.&lt;/p&gt;

&lt;p&gt;Call a service.&lt;/p&gt;

&lt;p&gt;Return a response.&lt;/p&gt;

&lt;p&gt;The real intelligence belongs elsewhere.&lt;/p&gt;




&lt;h1&gt;
  
  
  A Simpler Service Layer
&lt;/h1&gt;

&lt;p&gt;Instead of mixing everything together, I'd write services that solve one business problem.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;OrderService&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;repository&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;OrderRepository&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;events&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;EventBus&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;impl&lt;/span&gt; &lt;span class="n"&gt;OrderService&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;create_order&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Order&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Result&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Order&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;saved&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.repository&lt;/span&gt;
            &lt;span class="nf"&gt;.save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;.await&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.events&lt;/span&gt;&lt;span class="nf"&gt;.publish&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;OrderCreated&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;saved&lt;/span&gt;&lt;span class="py"&gt;.id&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="k"&gt;.await&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="nf"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;saved&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice what doesn't happen here.&lt;/p&gt;

&lt;p&gt;No emails.&lt;/p&gt;

&lt;p&gt;No notifications.&lt;/p&gt;

&lt;p&gt;No analytics.&lt;/p&gt;

&lt;p&gt;No inventory updates.&lt;/p&gt;

&lt;p&gt;Those belong to independent services reacting to events.&lt;/p&gt;

&lt;p&gt;Small responsibilities create maintainable systems.&lt;/p&gt;




&lt;h1&gt;
  
  
  I'd Embrace Events From Day One
&lt;/h1&gt;

&lt;p&gt;One lesson experience taught me is that applications should communicate through events whenever possible.&lt;/p&gt;

&lt;p&gt;Instead of this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Order Service
      │
      ▼
Send Email
      │
      ▼
Update Inventory
      │
      ▼
Generate Invoice
      │
      ▼
Notify Analytics
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I'd build this instead:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;            Order Created Event
                    │
      ┌─────────────┼─────────────┐
      ▼             ▼             ▼
 Email Service Inventory Service Analytics
      │             │             │
      ▼             ▼             ▼
 Independent    Independent   Independent
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nothing depends directly on anything else.&lt;/p&gt;

&lt;p&gt;Adding a new feature becomes publishing another subscriber.&lt;/p&gt;

&lt;p&gt;Architecture becomes extensible instead of fragile.&lt;/p&gt;




&lt;h1&gt;
  
  
  I'd Invest More in Observability
&lt;/h1&gt;

&lt;p&gt;Earlier in my career I logged errors.&lt;/p&gt;

&lt;p&gt;Today I monitor systems.&lt;/p&gt;

&lt;p&gt;Those are different things.&lt;/p&gt;

&lt;p&gt;Modern software should answer questions automatically.&lt;/p&gt;

&lt;p&gt;How many requests failed?&lt;/p&gt;

&lt;p&gt;Which endpoint is slow?&lt;/p&gt;

&lt;p&gt;Why is memory increasing?&lt;/p&gt;

&lt;p&gt;Which customer experienced an error?&lt;/p&gt;

&lt;p&gt;Monitoring transforms debugging from guessing into understanding.&lt;/p&gt;

&lt;p&gt;I'd build dashboards before launching products.&lt;/p&gt;




&lt;h1&gt;
  
  
  Caching Would Be Part of the Design
&lt;/h1&gt;

&lt;p&gt;Caching used to be something I added later.&lt;/p&gt;

&lt;p&gt;Now I consider it during architecture.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;             User Request
                  │
                  ▼
              API Gateway
                  │
          Cache Available?
           │             │
         Yes             No
           │             │
           ▼             ▼
     Return Cached    Query Database
        Response           │
                           ▼
                   Store in Cache
                           │
                           ▼
                    Return Response
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Fast systems rarely rely only on faster databases.&lt;/p&gt;

&lt;p&gt;They avoid unnecessary work.&lt;/p&gt;




&lt;h1&gt;
  
  
  I Would Think More About Failure
&lt;/h1&gt;

&lt;p&gt;One question changed how I design systems.&lt;/p&gt;

&lt;p&gt;"What happens if this component fails?"&lt;/p&gt;

&lt;p&gt;Earlier versions of my software assumed success.&lt;/p&gt;

&lt;p&gt;Modern systems assume failure.&lt;/p&gt;

&lt;p&gt;Databases disconnect.&lt;/p&gt;

&lt;p&gt;Networks timeout.&lt;/p&gt;

&lt;p&gt;Caches disappear.&lt;/p&gt;

&lt;p&gt;Queues overflow.&lt;/p&gt;

&lt;p&gt;Users refresh pages.&lt;/p&gt;

&lt;p&gt;Failures become architectural considerations instead of unexpected events.&lt;/p&gt;




&lt;h1&gt;
  
  
  Testing Would Begin Earlier
&lt;/h1&gt;

&lt;p&gt;I once viewed testing as something performed after development.&lt;/p&gt;

&lt;p&gt;Now I see testing as part of design.&lt;/p&gt;

&lt;p&gt;When software is difficult to test...&lt;/p&gt;

&lt;p&gt;It's often difficult to understand.&lt;/p&gt;

&lt;p&gt;Writing testable software usually produces modular software.&lt;/p&gt;

&lt;p&gt;The tests become documentation.&lt;/p&gt;

&lt;p&gt;Future developers—including my future self—benefit.&lt;/p&gt;




&lt;h1&gt;
  
  
  Databases Deserve More Respect
&lt;/h1&gt;

&lt;p&gt;Earlier projects treated the database like storage.&lt;/p&gt;

&lt;p&gt;Today I see it as architecture.&lt;/p&gt;

&lt;p&gt;Tables define relationships.&lt;/p&gt;

&lt;p&gt;Indexes define performance.&lt;/p&gt;

&lt;p&gt;Constraints preserve integrity.&lt;/p&gt;

&lt;p&gt;Transactions preserve consistency.&lt;/p&gt;

&lt;p&gt;A well-designed schema quietly improves every layer above it.&lt;/p&gt;

&lt;p&gt;Poor schemas spread complexity everywhere.&lt;/p&gt;




&lt;h1&gt;
  
  
  I'd Build APIs Like Products
&lt;/h1&gt;

&lt;p&gt;An API isn't simply an interface.&lt;/p&gt;

&lt;p&gt;It's a contract.&lt;/p&gt;

&lt;p&gt;Clients depend on it.&lt;/p&gt;

&lt;p&gt;Future developers depend on it.&lt;/p&gt;

&lt;p&gt;Documentation depends on it.&lt;/p&gt;

&lt;p&gt;Consistency matters.&lt;/p&gt;

&lt;p&gt;Versioning matters.&lt;/p&gt;

&lt;p&gt;Naming matters.&lt;/p&gt;

&lt;p&gt;Clear APIs reduce complexity before code executes.&lt;/p&gt;




&lt;h1&gt;
  
  
  Security Would Be Built In
&lt;/h1&gt;

&lt;p&gt;Earlier projects often added security after features worked.&lt;/p&gt;

&lt;p&gt;Now security becomes part of architecture.&lt;/p&gt;

&lt;p&gt;Authentication.&lt;/p&gt;

&lt;p&gt;Authorization.&lt;/p&gt;

&lt;p&gt;Rate limiting.&lt;/p&gt;

&lt;p&gt;Input validation.&lt;/p&gt;

&lt;p&gt;Encryption.&lt;/p&gt;

&lt;p&gt;Audit logging.&lt;/p&gt;

&lt;p&gt;Security should never feel bolted on.&lt;/p&gt;

&lt;p&gt;It should feel inevitable.&lt;/p&gt;




&lt;h1&gt;
  
  
  I'd Optimize for Maintenance
&lt;/h1&gt;

&lt;p&gt;Earlier I optimized for finishing.&lt;/p&gt;

&lt;p&gt;Today I'd optimize for maintaining.&lt;/p&gt;

&lt;p&gt;Future developers matter.&lt;/p&gt;

&lt;p&gt;Future teammates matter.&lt;/p&gt;

&lt;p&gt;Future Derek matters.&lt;/p&gt;

&lt;p&gt;Readable code.&lt;/p&gt;

&lt;p&gt;Simple naming.&lt;/p&gt;

&lt;p&gt;Predictable architecture.&lt;/p&gt;

&lt;p&gt;Good documentation.&lt;/p&gt;

&lt;p&gt;Maintenance is where software spends most of its life.&lt;/p&gt;




&lt;h1&gt;
  
  
  Continuous Delivery Over Perfect Releases
&lt;/h1&gt;

&lt;p&gt;Another lesson took years to appreciate.&lt;/p&gt;

&lt;p&gt;Shipping once isn't success.&lt;/p&gt;

&lt;p&gt;Shipping continuously is.&lt;/p&gt;

&lt;p&gt;I'd automate deployments.&lt;/p&gt;

&lt;p&gt;Automate testing.&lt;/p&gt;

&lt;p&gt;Automate monitoring.&lt;/p&gt;

&lt;p&gt;Automate rollbacks.&lt;/p&gt;

&lt;p&gt;Automation reduces human error.&lt;/p&gt;

&lt;p&gt;Consistency scales better than heroics.&lt;/p&gt;




&lt;h1&gt;
  
  
  Software Is Never Finished
&lt;/h1&gt;

&lt;p&gt;One belief changed everything for me.&lt;/p&gt;

&lt;p&gt;Applications are living systems.&lt;/p&gt;

&lt;p&gt;Users change.&lt;/p&gt;

&lt;p&gt;Businesses evolve.&lt;/p&gt;

&lt;p&gt;Technology advances.&lt;/p&gt;

&lt;p&gt;Requirements shift.&lt;/p&gt;

&lt;p&gt;Software must evolve alongside them.&lt;/p&gt;

&lt;p&gt;Architecture should welcome change instead of resisting it.&lt;/p&gt;




&lt;h1&gt;
  
  
  Experience Changed My Priorities
&lt;/h1&gt;

&lt;p&gt;Years ago, I admired clever code.&lt;/p&gt;

&lt;p&gt;Today I admire understandable systems.&lt;/p&gt;

&lt;p&gt;Years ago, I chased elegant algorithms.&lt;/p&gt;

&lt;p&gt;Today I chase clear architecture.&lt;/p&gt;

&lt;p&gt;Years ago, I celebrated large features.&lt;/p&gt;

&lt;p&gt;Today I celebrate fewer responsibilities.&lt;/p&gt;

&lt;p&gt;Experience didn't make me write more code.&lt;/p&gt;

&lt;p&gt;It made me write less.&lt;/p&gt;

&lt;p&gt;But with greater intention.&lt;/p&gt;




&lt;h1&gt;
  
  
  Final Thoughts
&lt;/h1&gt;

&lt;p&gt;If I could start every project over again, I wouldn't begin by choosing a framework.&lt;/p&gt;

&lt;p&gt;I wouldn't begin by designing database tables.&lt;/p&gt;

&lt;p&gt;I wouldn't even begin by writing code.&lt;/p&gt;

&lt;p&gt;I'd begin by understanding the problem deeply.&lt;/p&gt;

&lt;p&gt;Then I'd design how information should move through the system.&lt;/p&gt;

&lt;p&gt;I'd define clear boundaries between responsibilities.&lt;/p&gt;

&lt;p&gt;I'd think about failure before success.&lt;/p&gt;

&lt;p&gt;I'd build observability alongside functionality.&lt;/p&gt;

&lt;p&gt;I'd treat APIs as long-term contracts.&lt;/p&gt;

&lt;p&gt;I'd embrace events over tight coupling.&lt;/p&gt;

&lt;p&gt;I'd automate everything that could be automated.&lt;/p&gt;

&lt;p&gt;I'd optimize not only for today's requirements, but for the developer who will maintain the code years from now.&lt;/p&gt;

&lt;p&gt;Ironically, I don't think I'd build dramatically different software.&lt;/p&gt;

&lt;p&gt;Users might never notice the difference.&lt;/p&gt;

&lt;p&gt;The interfaces would look similar.&lt;/p&gt;

&lt;p&gt;The features would behave the same.&lt;/p&gt;

&lt;p&gt;But underneath, the architecture would tell a very different story.&lt;/p&gt;

&lt;p&gt;A story of loose coupling instead of dependency.&lt;/p&gt;

&lt;p&gt;Clarity instead of cleverness.&lt;/p&gt;

&lt;p&gt;Feedback instead of guesswork.&lt;/p&gt;

&lt;p&gt;Maintainability instead of shortcuts.&lt;/p&gt;

&lt;p&gt;And perhaps that's the greatest lesson software engineering has taught me.&lt;/p&gt;

&lt;p&gt;The goal isn't to build software that impresses people on the day it's launched.&lt;/p&gt;

&lt;p&gt;The goal is to build software that still makes sense years later, when requirements have changed, teams have grown, and someone—quite possibly your future self—has to understand every decision you made.&lt;/p&gt;

&lt;p&gt;If there's one thing I'd build differently today, it isn't just the code.&lt;/p&gt;

&lt;p&gt;It's the thinking behind the code.&lt;/p&gt;

&lt;p&gt;Because in the end, architecture is simply experience made visible.&lt;/p&gt;

</description>
      <category>api</category>
      <category>softwaredevelopment</category>
      <category>software</category>
      <category>programming</category>
    </item>
    <item>
      <title>Teaching Machines to Recognize Patterns</title>
      <dc:creator>Derek mwale</dc:creator>
      <pubDate>Fri, 31 Jul 2026 13:15:16 +0000</pubDate>
      <link>https://dev.to/derekmwale/teaching-machines-to-recognize-patterns-2chb</link>
      <guid>https://dev.to/derekmwale/teaching-machines-to-recognize-patterns-2chb</guid>
      <description>&lt;h1&gt;
  
  
  Teaching Machines to Recognize Patterns
&lt;/h1&gt;

&lt;p&gt;When I first started learning about artificial intelligence, I thought machines were being taught to think.&lt;/p&gt;

&lt;p&gt;The more I studied machine learning, the more I realized that wasn't quite true.&lt;/p&gt;

&lt;p&gt;Machines aren't taught to think the way humans do.&lt;/p&gt;

&lt;p&gt;They're taught to recognize patterns.&lt;/p&gt;

&lt;p&gt;That distinction changed everything for me.&lt;/p&gt;

&lt;p&gt;Whether it's recognizing handwritten digits, identifying tumors in medical images, detecting fraudulent transactions, recommending movies, or translating languages, modern AI isn't memorizing answers.&lt;/p&gt;

&lt;p&gt;It's discovering patterns hidden inside data.&lt;/p&gt;

&lt;p&gt;As software engineers, this should sound familiar.&lt;/p&gt;

&lt;p&gt;Much of software engineering is also about patterns.&lt;/p&gt;

&lt;p&gt;Design patterns.&lt;/p&gt;

&lt;p&gt;Architectural patterns.&lt;/p&gt;

&lt;p&gt;Communication patterns.&lt;/p&gt;

&lt;p&gt;Database relationships.&lt;/p&gt;

&lt;p&gt;User behavior.&lt;/p&gt;

&lt;p&gt;Artificial intelligence simply extends this philosophy into data.&lt;/p&gt;

&lt;p&gt;The more I explored machine learning, the more I realized that teaching machines to recognize patterns is one of the greatest engineering challenges of our time.&lt;/p&gt;

&lt;p&gt;It combines mathematics, statistics, software engineering, distributed systems, and human intuition into one extraordinary discipline.&lt;/p&gt;




&lt;h1&gt;
  
  
  Every Intelligent System Starts With Data
&lt;/h1&gt;

&lt;p&gt;Imagine trying to teach a child what a cat looks like.&lt;/p&gt;

&lt;p&gt;You wouldn't begin with equations.&lt;/p&gt;

&lt;p&gt;You would show examples.&lt;/p&gt;

&lt;p&gt;One cat.&lt;/p&gt;

&lt;p&gt;Another cat.&lt;/p&gt;

&lt;p&gt;A black cat.&lt;/p&gt;

&lt;p&gt;A white cat.&lt;/p&gt;

&lt;p&gt;A kitten.&lt;/p&gt;

&lt;p&gt;A large cat.&lt;/p&gt;

&lt;p&gt;Eventually the child notices similarities.&lt;/p&gt;

&lt;p&gt;Whiskers.&lt;/p&gt;

&lt;p&gt;Ears.&lt;/p&gt;

&lt;p&gt;Eyes.&lt;/p&gt;

&lt;p&gt;Tail.&lt;/p&gt;

&lt;p&gt;The child forms a mental model.&lt;/p&gt;

&lt;p&gt;Machine learning follows exactly the same principle.&lt;/p&gt;

&lt;p&gt;The difference is that machines don't see pictures.&lt;/p&gt;

&lt;p&gt;They see numbers.&lt;/p&gt;

&lt;p&gt;Every image becomes a matrix.&lt;/p&gt;

&lt;p&gt;Every sentence becomes tokens.&lt;/p&gt;

&lt;p&gt;Every sound becomes waveforms.&lt;/p&gt;

&lt;p&gt;Teaching begins with representation.&lt;/p&gt;




&lt;h1&gt;
  
  
  Patterns Exist Everywhere
&lt;/h1&gt;

&lt;p&gt;One realization fascinated me.&lt;/p&gt;

&lt;p&gt;Patterns aren't unique to artificial intelligence.&lt;/p&gt;

&lt;p&gt;Nature depends on them.&lt;/p&gt;

&lt;p&gt;Weather follows patterns.&lt;/p&gt;

&lt;p&gt;Economies follow patterns.&lt;/p&gt;

&lt;p&gt;Languages follow patterns.&lt;/p&gt;

&lt;p&gt;Music follows patterns.&lt;/p&gt;

&lt;p&gt;Human behavior follows patterns.&lt;/p&gt;

&lt;p&gt;Software follows patterns.&lt;/p&gt;

&lt;p&gt;Artificial intelligence simply provides another way to discover them.&lt;/p&gt;

&lt;p&gt;The engineer's job is to build systems capable of recognizing those hidden structures.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Journey From Raw Data to Intelligence
&lt;/h1&gt;

&lt;p&gt;Before a neural network can learn anything, data must travel through an engineering pipeline.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                Raw Data
                    │
                    ▼
        Data Collection
                    │
                    ▼
       Data Validation
                    │
                    ▼
       Data Cleaning
                    │
                    ▼
      Feature Extraction
                    │
                    ▼
      Machine Learning Model
                    │
                    ▼
      Pattern Recognition
                    │
                    ▼
        Prediction
                    │
                    ▼
      Continuous Learning
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice something important.&lt;/p&gt;

&lt;p&gt;The neural network occupies only one stage.&lt;/p&gt;

&lt;p&gt;Everything surrounding it is equally important.&lt;/p&gt;

&lt;p&gt;Good engineering creates good intelligence.&lt;/p&gt;




&lt;h1&gt;
  
  
  Representation Is the First Lesson
&lt;/h1&gt;

&lt;p&gt;Machines cannot learn reality directly.&lt;/p&gt;

&lt;p&gt;Reality must first be translated.&lt;/p&gt;

&lt;p&gt;Images become pixels.&lt;/p&gt;

&lt;p&gt;Words become embeddings.&lt;/p&gt;

&lt;p&gt;Transactions become vectors.&lt;/p&gt;

&lt;p&gt;GPS coordinates become numerical features.&lt;/p&gt;

&lt;p&gt;One of the biggest lessons I've learned from AI is this:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Representation determines learning.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A poor representation makes recognition difficult.&lt;/p&gt;

&lt;p&gt;A good representation makes learning almost effortless.&lt;/p&gt;

&lt;p&gt;This principle extends beyond machine learning.&lt;/p&gt;

&lt;p&gt;Well-designed databases are good representations of businesses.&lt;/p&gt;

&lt;p&gt;Good APIs are good representations of communication.&lt;/p&gt;

&lt;p&gt;Good software begins with good models.&lt;/p&gt;




&lt;h1&gt;
  
  
  Features Tell the Story
&lt;/h1&gt;

&lt;p&gt;Early machine learning relied heavily on handcrafted features.&lt;/p&gt;

&lt;p&gt;Engineers manually extracted edges.&lt;/p&gt;

&lt;p&gt;Corners.&lt;/p&gt;

&lt;p&gt;Textures.&lt;/p&gt;

&lt;p&gt;Shapes.&lt;/p&gt;

&lt;p&gt;Modern deep learning automates much of this work.&lt;/p&gt;

&lt;p&gt;Yet the concept remains the same.&lt;/p&gt;

&lt;p&gt;Features are descriptions.&lt;/p&gt;

&lt;p&gt;The better we describe information, the easier patterns become to discover.&lt;/p&gt;

&lt;p&gt;Imagine recognizing faces.&lt;/p&gt;

&lt;p&gt;A neural network gradually learns:&lt;/p&gt;

&lt;p&gt;Edges.&lt;/p&gt;

&lt;p&gt;Curves.&lt;/p&gt;

&lt;p&gt;Eyes.&lt;/p&gt;

&lt;p&gt;Noses.&lt;/p&gt;

&lt;p&gt;Mouths.&lt;/p&gt;

&lt;p&gt;Entire faces.&lt;/p&gt;

&lt;p&gt;Understanding emerges layer by layer.&lt;/p&gt;




&lt;h1&gt;
  
  
  Neural Networks Learn Hierarchically
&lt;/h1&gt;

&lt;p&gt;One of my favorite characteristics of deep learning is hierarchical learning.&lt;/p&gt;

&lt;p&gt;Simple patterns combine into complex patterns.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;         Image

           │
           ▼

    Edge Detection

           │
           ▼

     Shape Detection

           │
           ▼

   Object Components

           │
           ▼

      Full Object

           │
           ▼

     Final Prediction
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This reminds me of software architecture.&lt;/p&gt;

&lt;p&gt;Functions combine into modules.&lt;/p&gt;

&lt;p&gt;Modules combine into services.&lt;/p&gt;

&lt;p&gt;Services combine into systems.&lt;/p&gt;

&lt;p&gt;Complexity emerges from simple building blocks.&lt;/p&gt;




&lt;h1&gt;
  
  
  Every Prediction Is a Guess
&lt;/h1&gt;

&lt;p&gt;A neural network never knows the answer with certainty.&lt;/p&gt;

&lt;p&gt;It estimates.&lt;/p&gt;

&lt;p&gt;Every prediction represents probability.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Dog      94%

Cat       4%

Fox       1%

Wolf      1%
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The model isn't declaring absolute truth.&lt;/p&gt;

&lt;p&gt;It's expressing confidence.&lt;/p&gt;

&lt;p&gt;Understanding uncertainty is one of the most overlooked aspects of artificial intelligence.&lt;/p&gt;

&lt;p&gt;Good engineering embraces probabilities instead of pretending certainty exists.&lt;/p&gt;




&lt;h1&gt;
  
  
  Learning Through Feedback
&lt;/h1&gt;

&lt;p&gt;No pattern is recognized perfectly on the first attempt.&lt;/p&gt;

&lt;p&gt;Learning requires repetition.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input Data
     │
     ▼
Prediction
     │
     ▼
Compare Answer
     │
     ▼
Calculate Error
     │
     ▼
Backpropagation
     │
     ▼
Update Weights
     │
     ▼
Repeat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each cycle slightly improves recognition.&lt;/p&gt;

&lt;p&gt;Millions of iterations eventually produce remarkable accuracy.&lt;/p&gt;




&lt;h1&gt;
  
  
  A Simple Neural Network
&lt;/h1&gt;

&lt;p&gt;At its heart, pattern recognition remains surprisingly elegant.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;torch&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;torch.nn&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;nn&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PatternRecognizer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Module&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;

        &lt;span class="nf"&gt;super&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;network&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;nn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Sequential&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;

            &lt;span class="n"&gt;nn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Linear&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;784&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;256&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;

            &lt;span class="n"&gt;nn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ReLU&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;

            &lt;span class="n"&gt;nn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Linear&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;256&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;128&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;

            &lt;span class="n"&gt;nn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ReLU&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;

            &lt;span class="n"&gt;nn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Linear&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;128&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;forward&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;network&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Training is equally straightforward.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;optimizer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;torch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;optim&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Adam&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parameters&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;

&lt;span class="n"&gt;loss_function&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;nn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CrossEntropyLoss&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;images&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;labels&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;loader&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

    &lt;span class="n"&gt;prediction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;model&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;images&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;loss&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;loss_function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prediction&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;optimizer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;zero_grad&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="n"&gt;loss&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;backward&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="n"&gt;optimizer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;step&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Behind these few lines lies billions of mathematical operations.&lt;/p&gt;

&lt;p&gt;The abstraction is one of modern software engineering's greatest achievements.&lt;/p&gt;




&lt;h1&gt;
  
  
  Convolutional Neural Networks Changed Vision
&lt;/h1&gt;

&lt;p&gt;Traditional neural networks struggled with images.&lt;/p&gt;

&lt;p&gt;Every pixel was treated independently.&lt;/p&gt;

&lt;p&gt;Convolutional Neural Networks (CNNs) introduced a revolutionary idea.&lt;/p&gt;

&lt;p&gt;Local patterns matter.&lt;/p&gt;

&lt;p&gt;Instead of analyzing entire images at once, CNNs examine small regions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Image

████████

Sliding Filter

■■■
■■■
■■■

↓

Edge

↓

Texture

↓

Shape

↓

Object
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This dramatically improved computer vision.&lt;/p&gt;

&lt;p&gt;Today CNNs power:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Medical imaging&lt;/li&gt;
&lt;li&gt;Autonomous vehicles&lt;/li&gt;
&lt;li&gt;Satellite analysis&lt;/li&gt;
&lt;li&gt;Manufacturing inspection&lt;/li&gt;
&lt;li&gt;Face recognition&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sometimes architectural improvements matter more than larger models.&lt;/p&gt;




&lt;h1&gt;
  
  
  Pattern Recognition Beyond Images
&lt;/h1&gt;

&lt;p&gt;Images receive much attention.&lt;/p&gt;

&lt;p&gt;Patterns exist everywhere.&lt;/p&gt;

&lt;p&gt;Fraud detection recognizes unusual transactions.&lt;/p&gt;

&lt;p&gt;Recommendation systems recognize preferences.&lt;/p&gt;

&lt;p&gt;Language models recognize grammar and meaning.&lt;/p&gt;

&lt;p&gt;Speech recognition identifies sound structures.&lt;/p&gt;

&lt;p&gt;Predictive maintenance recognizes equipment failures.&lt;/p&gt;

&lt;p&gt;AI isn't tied to one domain.&lt;/p&gt;

&lt;p&gt;It recognizes structure wherever structure exists.&lt;/p&gt;




&lt;h1&gt;
  
  
  Engineering Reliable Pattern Recognition
&lt;/h1&gt;

&lt;p&gt;Production AI involves more than training.&lt;/p&gt;

&lt;p&gt;Engineers must monitor:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Prediction accuracy&lt;/li&gt;
&lt;li&gt;Latency&lt;/li&gt;
&lt;li&gt;False positives&lt;/li&gt;
&lt;li&gt;False negatives&lt;/li&gt;
&lt;li&gt;Data drift&lt;/li&gt;
&lt;li&gt;Model drift&lt;/li&gt;
&lt;li&gt;User feedback&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;An intelligent system that stops learning eventually becomes outdated.&lt;/p&gt;

&lt;p&gt;Monitoring becomes another form of education.&lt;/p&gt;




&lt;h1&gt;
  
  
  Why More Data Isn't Always Better
&lt;/h1&gt;

&lt;p&gt;One misconception fascinates me.&lt;/p&gt;

&lt;p&gt;People often assume larger datasets automatically create smarter models.&lt;/p&gt;

&lt;p&gt;Quality matters more.&lt;/p&gt;

&lt;p&gt;Balanced examples.&lt;/p&gt;

&lt;p&gt;Correct labels.&lt;/p&gt;

&lt;p&gt;Representative samples.&lt;/p&gt;

&lt;p&gt;Consistent preprocessing.&lt;/p&gt;

&lt;p&gt;Clean information.&lt;/p&gt;

&lt;p&gt;The best models often emerge from better engineering rather than bigger datasets.&lt;/p&gt;




&lt;h1&gt;
  
  
  Distributed Learning
&lt;/h1&gt;

&lt;p&gt;Modern AI trains across many GPUs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;         Training Cluster

     GPU 1      GPU 2

       │          │

       └────┬─────┘

            ▼

 Gradient Synchronization

            │

            ▼

 Updated Global Model
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pattern recognition at scale becomes distributed systems engineering.&lt;/p&gt;

&lt;p&gt;Networking.&lt;/p&gt;

&lt;p&gt;Memory optimization.&lt;/p&gt;

&lt;p&gt;Synchronization.&lt;/p&gt;

&lt;p&gt;Fault tolerance.&lt;/p&gt;

&lt;p&gt;Artificial intelligence increasingly resembles backend engineering.&lt;/p&gt;




&lt;h1&gt;
  
  
  Intelligence Is Generalization
&lt;/h1&gt;

&lt;p&gt;Perhaps the most important lesson in machine learning is this.&lt;/p&gt;

&lt;p&gt;The goal isn't memorization.&lt;/p&gt;

&lt;p&gt;The goal is generalization.&lt;/p&gt;

&lt;p&gt;A good model recognizes patterns it has never seen before.&lt;/p&gt;

&lt;p&gt;This distinguishes intelligence from storage.&lt;/p&gt;

&lt;p&gt;Anyone can memorize answers.&lt;/p&gt;

&lt;p&gt;Recognizing new situations requires understanding.&lt;/p&gt;




&lt;h1&gt;
  
  
  Lessons Beyond Artificial Intelligence
&lt;/h1&gt;

&lt;p&gt;Studying pattern recognition changed how I think about software.&lt;/p&gt;

&lt;p&gt;I became more interested in relationships.&lt;/p&gt;

&lt;p&gt;Representations.&lt;/p&gt;

&lt;p&gt;Feedback.&lt;/p&gt;

&lt;p&gt;Architecture.&lt;/p&gt;

&lt;p&gt;Information flow.&lt;/p&gt;

&lt;p&gt;Machine learning reinforced something I already suspected.&lt;/p&gt;

&lt;p&gt;Good engineering isn't about handling isolated data.&lt;/p&gt;

&lt;p&gt;It's about discovering meaningful structure.&lt;/p&gt;




&lt;h1&gt;
  
  
  Final Thoughts
&lt;/h1&gt;

&lt;p&gt;Teaching machines to recognize patterns is one of the most fascinating engineering achievements of the modern era.&lt;/p&gt;

&lt;p&gt;At first glance, it appears to be a story about algorithms.&lt;/p&gt;

&lt;p&gt;Look closer, and it becomes a story about architecture.&lt;/p&gt;

&lt;p&gt;About carefully designing systems that can transform raw information into meaningful understanding.&lt;/p&gt;

&lt;p&gt;Every successful AI system begins long before a neural network makes its first prediction.&lt;/p&gt;

&lt;p&gt;It starts with collecting reliable data.&lt;/p&gt;

&lt;p&gt;Cleaning it.&lt;/p&gt;

&lt;p&gt;Representing it.&lt;/p&gt;

&lt;p&gt;Designing architectures that can discover hidden relationships.&lt;/p&gt;

&lt;p&gt;Creating feedback loops that encourage continuous learning.&lt;/p&gt;

&lt;p&gt;Monitoring performance.&lt;/p&gt;

&lt;p&gt;Refining models.&lt;/p&gt;

&lt;p&gt;Improving infrastructure.&lt;/p&gt;

&lt;p&gt;The intelligence we admire is rarely the product of one brilliant algorithm.&lt;/p&gt;

&lt;p&gt;It is the result of thousands of thoughtful engineering decisions working together.&lt;/p&gt;

&lt;p&gt;Perhaps that is why artificial intelligence continues to inspire me.&lt;/p&gt;

&lt;p&gt;Not because machines can recognize cats, translate languages, or recommend movies.&lt;/p&gt;

&lt;p&gt;But because behind every one of those capabilities lies a timeless engineering principle.&lt;/p&gt;

&lt;p&gt;Understanding emerges when we organize information well enough for patterns to reveal themselves.&lt;/p&gt;

&lt;p&gt;Whether we are designing databases, building distributed systems, writing backend services, or training neural networks, we are ultimately solving the same problem.&lt;/p&gt;

&lt;p&gt;We are helping systems recognize the patterns that matter.&lt;/p&gt;

&lt;p&gt;And in many ways, that is the true art of building intelligent software.&lt;/p&gt;

</description>
      <category>api</category>
      <category>software</category>
      <category>softwaredevelopment</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
