Modelling State Machines

November 2026. 1,760 words.

A syllabus for learning how software systems work has about a hundred topics in it. The one in front of me starts with memory and processes, goes through HTTP, databases and queues, and ends with agents built on language models. DNS, transactions, containers, caching, sharding, retries, migrations, embeddings. Each comes with its own vocabulary, and each looks like a separate thing to learn.

A list that long makes you want to know what’s underneath it. If a hundred topics really are a hundred topics, all you can do is grind through them. But long lists usually aren’t what they look like. Usually there’s a small idea that most of the items are instances of, and if you can find it, you learn the idea once and then learn what’s different about each case.

My first guess at the idea was “a machine.” That’s close, but too vague to do any work. The better answer is to model everything as a state machine, and then, right behind it, as many state machines sending messages to each other.

A state machine is state plus rules. Input arrives, the rules decide how the state changes, and output leaves. That’s the whole thing.

Which moves the question to what state is. State is whatever a system remembers right now that affects what it does next. There’s a simple test for it: if the same input can give different outputs at different times, there’s state in there somewhere.1 Press a light switch and the light comes on. Press it again, the identical press, and it goes off. What the press does depends on whether the light is on, and that “is on” is the state. A calculator adding 2 and 3 has none. It says 5 every time. A bank balance is nothing but state. It depends on every deposit and withdrawal that came before.

This sounds too simple to be useful. But look at what follows from it. The rules don’t change while a system runs. The state does. So state is the only part with a history. When a bug depends on what happened earlier, it’s a state bug. When two things interfere with each other, it’s because both can change the same state. When two parts of a system disagree, each is holding a copy of some state and the copies have drifted apart. And when a crash loses something, the something is state that wasn’t saved anywhere durable. A surprising amount of what’s hard about software is one of those four.

That’s why so much of system design is about where state lives. Stateless servers push it out into a database. Caches hold copies of it somewhere faster. Transactions change several pieces of it together or not at all. The old database advice to store each fact once is advice about copies. And the standard shape, logic with no state wrapped around one well-guarded store, exists because the parts with no state are the easy ones. You can copy them, restart them and test them freely, since they have nothing to lose.

What surprised me is how far the pattern reaches. A memory cell holding one bit is a state machine: the state is a charge, and the input is an electrical signal. A CPU is one, with registers and memory for state and instructions for input. A program is one: variables, changed by function calls. A database is one: rows on a disk, changed by queries. A web service is one. An agent is one, where the state is the conversation so far and the files it has written. A company is one, where the state is documents and what people know, and the inputs are emails and meetings.

It’s the same pattern each time, made of something different. I started calling the something the substrate. And the levels are stacked. Each machine’s state is built out of the machines below it. A row in a database is really bytes on a disk, which are really charges in a chip. Each level hides the one beneath it, and that hiding is all abstraction is.

If that were the whole story, you could learn one level and skip the rest. You can’t, and the reason is the most useful thing I’ve got out of this so far. The pattern is the same at every level, but each substrate has its own physics. State held as charge in memory can be read in nanoseconds and is gone when the power goes. State on a disk is thousands of times slower to reach, and survives. State in someone’s head is slow, forgetful, and can’t be copied exactly. State in an institution, its rules and contracts and habits, lasts for decades and takes about as long to change.

So there’s a short list of things to ask of any substrate. How fast is it? How long does it last? How much does it hold, and what does that cost? How does it fail? Who can change it? The answers are its physics, and the physics leaks upward.2 The speed of light becomes network delay, and network delay becomes a slow page. A lot of engineering is dealing with the properties of a lower level showing up in a higher one. One pattern, many substrates, and each substrate brings its own physics.

This is what made language models easier for me to think about. A model has three substrates. Its weights hold what it learned in training, and can only be read while it runs. Its context window is working memory, gone when the call ends. And outside it are files and databases, which last. In older terms: ROM, RAM and disk. A model on its own is close to stateless. Text goes in, text comes out, and nothing is remembered. An agent is what you get when you wrap a model in a loop, give it tools, and give it somewhere to keep things. So the main job of all the code around the model is to give a stateless thing state.

Once you see that, a lot of agent vocabulary is about state and messages too. Retrieval is moving state from disk into working memory. Memory is state that outlives the call. Prompt injection is a message that gets treated as rules. I once wrote about an agent that says it sent the email when it didn’t. In these terms, the model reported a change of state that never happened. Part of the fix was to make the tool return a confirmation: state you can check, instead of a claim you have to believe.

One machine isn’t enough, though. Real systems are many machines, and the hard problems tend to live between them, not inside them. Inside a machine, a step happens or it doesn’t. Between machines, a message can arrive late, get lost, or arrive twice. The other side can be down. And what arrives may not be something you should trust.

Many of the topics on the syllabus are answers to one of those. Retries are for messages that get lost. Idempotency is for messages that arrive twice. A queue holds messages until someone is ready to read them. Authentication is rules about who may send which messages. Telemetry is a machine sending messages about its own state. A migration changes the shape of state while it’s in use, and an API version changes the contract for messages while people are still sending them.

So can every topic on the list be explained this way? Most of them. The ones that can’t are more interesting. The lens tells you what a system does. It doesn’t tell you what that costs, which is the business of algorithms and trade-offs. It doesn’t tell you why one design is easier to live with than another, which depends on the limits and incentives of the people building it.3 And it treats a language model as a black box. Why a model makes things up is a question about probability and learning, because its rules were learned and not written.

So there are four lenses, not one. Mechanics, which is state, messages and substrates. Cost. People. Uncertainty. And that gives a test for anything new. If I can’t explain it as state and messages, either I haven’t understood it yet or it belongs to one of the other three. Either answer is worth having.

All four apply at every level, but the mix changes as you go up. At the bottom it’s nearly all mechanics and cost. That isn’t how the bottom naturally is. A transistor is a noisy analog device. Digital logic exists to turn noisy voltages into dependable 0s and 1s, and engineers worked very hard so that everyone above could forget about the noise.4 Each level tries to hide the uncertainty of the level below. When it fails, you get what programmers call a leaky abstraction.

Going up, the people and the uncertainty come back. Networks lose messages. Traffic is unpredictable. Organizations are mostly people. By the top, mechanics is the small part.

This is the best explanation I know for why AI systems feel different from ordinary software. In ordinary software the uncertainty is at the edges: the network, the users. The part in the middle does exactly what it was told. A language model puts the uncertain part in the middle. Evals, guardrails and human approval are all ways of managing uncertainty there, where there used to be none. But everything around the model is the old kind of thing. An agent is a distributed system with an unreliable, untrusted component at its center, and what you know about state and messages still applies to it. I think that’s why the syllabus puts AI last.

One caution. “State machine” has a formal meaning too: a small set of states you can list in full, like a traffic light or a checkout flow. Real systems have far too many states to list, so I don’t mean it that way. I mean it as a way of asking questions. Where does the state live, and who can change it? What are the parts, and what are the contracts between them? What crosses each boundary, and can it be trusted? What happens when a part is slow, or fails, or gets a hundred times the load?

I still have to learn the hundred topics. But they arrive differently now. Each one shows up as an answer to a question I already have, and that’s a much easier way to learn anything.

Notes

  1. The test has one exception, which is randomness. A language model can give different answers to the same prompt because its output is sampled, not because it remembers anything. Chance isn’t state.
  2. Joel Spolsky called this the law of leaky abstractions: “All non-trivial abstractions, to some degree, are leaky.” “The Law of Leaky Abstractions,” 2002.
  3. The best known case is Conway’s law: organizations design systems that copy their own communication structures. Melvin Conway, “How Do Committees Invent?”, 1968. In the terms of this essay, how people send messages to each other shapes how the parts of their system do.
  4. They never quite finished. Cosmic rays still flip a bit in memory now and then, which is why servers use memory that checks and corrects itself.
Plain HTML. No tracking. Last updated November 2026. RSS