<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged systemsdesign</title>
<link>https://coderlegion.com/tag/systemsdesign</link>
<description>Powered by Question2Answer</description>
<item>
<title># Why You Must Revisit the Stack Data Structure in the Age of AI</title>
<link>https://coderlegion.com/10404/why-you-must-revisit-the-stack-data-structure-in-the-age-of-ai</link>
<description>&lt;p&gt;With the rise of AI-assisted coding, execution has become cheap.&lt;/p&gt;
&lt;p&gt;You can let the AI do the wiring.&lt;br&gt;
What you &lt;strong&gt;cannot&lt;/strong&gt; delegate is the choice of abstractions.&lt;/p&gt;
&lt;p&gt;And that changes everything.&lt;/p&gt;
&lt;p&gt;If &lt;em&gt;you&lt;/em&gt; choose the right abstractions, your system scales.&lt;br&gt;
If you don’t, you don’t get “bad code” — you get &lt;strong&gt;semantic debt&lt;/strong&gt;:&lt;br&gt;
a pile of spaghetti whose behavior you no longer understand.&lt;/p&gt;
&lt;p&gt;That’s why data structures matter more today than they did before.&lt;br&gt;
Not because you must be able to &lt;em&gt;implement&lt;/em&gt; them,&lt;br&gt;
but because you must understand the &lt;strong&gt;semantic consequences&lt;/strong&gt; of choosing one.&lt;/p&gt;
&lt;p&gt;Those consequences often cascade far beyond what you intended.&lt;/p&gt;
&lt;p&gt;Let’s see this with the simplest example possible.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-stack-is-not-just-a-stack&quot;&gt;The Stack Is Not Just a Stack&lt;/h3&gt;
&lt;p&gt;A stack is one of the simplest data structures we have.&lt;br&gt;
So simple, in fact, that it exists physically in hardware.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;CPUs implement stack pointers  &lt;/li&gt;
&lt;li&gt;Operating systems allocate a stack per process  &lt;/li&gt;
&lt;li&gt;Languages expose it implicitly via function calls and scopes  &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In C-like languages, opening a &lt;code&gt;{}&lt;/code&gt; opens a stack frame.&lt;br&gt;
When you exceed stack memory, the OS kills your program.&lt;br&gt;
Even &lt;em&gt;Stack Overflow&lt;/em&gt; is named after this exact failure mode.&lt;/p&gt;
&lt;p&gt;You &lt;strong&gt;cannot&lt;/strong&gt; write a program without a stack.&lt;/p&gt;
&lt;p&gt;So far, nothing surprising.&lt;/p&gt;
&lt;p&gt;But now track execution &lt;em&gt;mentally&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;If function &lt;code&gt;A&lt;/code&gt; calls &lt;code&gt;B&lt;/code&gt;, and then &lt;code&gt;C&lt;/code&gt;, execution looks like this:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Enter &lt;code&gt;A&lt;/code&gt;  &lt;/li&gt;
&lt;li&gt;Enter &lt;code&gt;B&lt;/code&gt;  &lt;/li&gt;
&lt;li&gt;Exit &lt;code&gt;B&lt;/code&gt;  &lt;/li&gt;
&lt;li&gt;Enter &lt;code&gt;C&lt;/code&gt;  &lt;/li&gt;
&lt;li&gt;Exit &lt;code&gt;C&lt;/code&gt;  &lt;/li&gt;
&lt;li&gt;Exit &lt;code&gt;A&lt;/code&gt;  &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;At runtime, the stack is a &lt;strong&gt;path&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;But over time, the trace of execution forms a &lt;strong&gt;tree&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;A&lt;/code&gt; is the parent  &lt;/li&gt;
&lt;li&gt;&lt;code&gt;B&lt;/code&gt; and &lt;code&gt;C&lt;/code&gt; are siblings  &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The stack is not “just LIFO”.&lt;br&gt;
It is a traversal of a tree-shaped execution history.&lt;/p&gt;
&lt;p&gt;This matters more than most developers realize.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;execution-leaves-a-shape&quot;&gt;Execution Leaves a Shape&lt;/h3&gt;
&lt;p&gt;Most developers are comfortable with stack behavior.&lt;br&gt;
Far fewer are comfortable with &lt;strong&gt;closures&lt;/strong&gt; — and this is why.&lt;/p&gt;
&lt;p&gt;Closures break the illusion that execution is only a stack.&lt;/p&gt;
&lt;p&gt;Consider this example:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;const makeClosure = () =&amp;gt; {
  let a = 10;
  function closure() {
    console.log(a);
  }
  return closure;
};

const myClosure = makeClosure();
myClosure(); // prints 10

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here’s the puzzle:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;makeClosure() creates a stack frame&lt;/li&gt;
&lt;li&gt;That stack frame exits&lt;/li&gt;
&lt;li&gt;Yet a is still accessible later&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So where is &lt;code&gt;a&lt;/code&gt;?&lt;/p&gt;
&lt;p&gt;It cannot be on the stack.&lt;br&gt;
The stack frame is gone.&lt;/p&gt;
&lt;p&gt;The only possible conclusion:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;execution is no longer a simple stack.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;What actually happens is this:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The stack is one branch of a larger execution tree&lt;/li&gt;
&lt;li&gt;Closures preserve parts of that tree after the branch collapses&lt;/li&gt;
&lt;li&gt;Variables escape time, not scope&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Once you understand this, async functions, promises, callbacks,&lt;br&gt;
and event-driven runtimes stop feeling magical.&lt;/p&gt;
&lt;p&gt;They are not “stack tricks”.&lt;br&gt;
They are graph-shaped execution.&lt;/p&gt;
&lt;h3 id=&quot;why-you-should-care&quot;&gt;Why You Should Care&lt;/h3&gt;
&lt;p&gt;In an age where any of us can spin up a workforce in the form of AI agents,&lt;br&gt;
the real challenge is no longer writing code — it’s &lt;strong&gt;scaling systems&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;People sense this intuitively.&lt;br&gt;
That’s why they keep building frameworks, layers, and tooling&lt;br&gt;
with increasing internal complexity.&lt;/p&gt;
&lt;p&gt;Frameworks consume your code — or AI-generated wiring —&lt;br&gt;
and impose their own abstractions and limitations.&lt;br&gt;
That is precisely where architectural decisions become irreversible.&lt;/p&gt;
&lt;p&gt;Here’s the key point:&lt;/p&gt;
&lt;p&gt;Seeing the stack as the &lt;strong&gt;active trunk of an execution tree&lt;/strong&gt;&lt;br&gt;
is the mental model behind virtual machines,&lt;br&gt;
language runtimes,&lt;br&gt;
and frameworks themselves.&lt;/p&gt;
&lt;p&gt;If you don’t understand the semantic consequences of your data structures,&lt;br&gt;
you are outsourcing architecture to tools&lt;br&gt;
that don’t pay the cost when things go wrong.&lt;/p&gt;
&lt;p&gt;I’ll write more about this using concrete examples&lt;br&gt;
from a VM I built using exactly this perspective.&lt;br&gt;
As a preview: it supports async pipelines natively —&lt;br&gt;
but more on that later.&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/10404/why-you-must-revisit-the-stack-data-structure-in-the-age-of-ai</guid>
<pubDate>Sat, 24 Jan 2026 15:28:16 +0000</pubDate>
</item>
</channel>
</rss>