The split between business logic and infrastructure

AI agents have changed what business applications do. A request is no longer one call and one answer. An agent asks a model, waits for tools, waits for a person, and asks again. Every run is a flow of many steps, on machines that fail. Models, agent frameworks and protocols change every few weeks. Code tied closely to this month's tooling is next year's rewrite.

Software as a service grew into a business worth hundreds of billions of dollars a year, and it is everywhere. Much of it is not only used but built on, and a service that is built on comes with an SDK. Through the SDKs it made its way all the way into the business logic. Teams accepted that as the price of not building it themselves. With AI writing the logic, that price has become friction: the part that should change every week is tied to the part that must not.

Two kinds of code

The article identifies two categories of code that have become increasingly distinct. Layer 1 is the business logic: the rules of the business and the agent's loop — judge the risk, screen the payee, ask a person when in doubt, move the money. Layer 2 is the infrastructure: durability, calls that run in parallel safely, the undo when a step fails, knowing where the work was when the machine died.

Layer 1 stays free only if it is written with the language's own types: Function in Java, Callable in Python, a function type in TypeScript. No SDK. Then it is tied to no model, no agent framework and no engine. Anyone who knows the business can check it by reading it. A person should check it.

Layer 2 is notoriously hard to write, even with an AI. An extremely seasoned engineer can check it, and not by reading alone. A compiler should check it. The contrast is sharp: business logic is small, rule-based, one step after another. Infrastructure is many machines, listeners, retries and timing; the order of things is not on the page.

The SDK as a constraint

The first decision is made before a line of code is written: what you install. An IDE plugin ties you to one platform's way of writing a flow. A command-line tool or a local server ties you to one platform's way of running it. An SDK in the build file ties you to one platform's types, in every file that uses them.

The SDK is the one that matters most. The moment it is installed, the code is written against that platform. When platforms change as fast as they do now, the team that installed it is the team that carries the cost of moving. So the IDE should open in a browser. No plugin, nothing to install, and no SDK. The code is written against the language itself: pure Java, pure Python, pure TypeScript.

Here is the whole bank transfer written against the same invented SDK. MyEngine is no product's API. Real SDKs differ in their names. The shape is familiar.

import com.myengine.sdk.Engine;
import com.myengine.sdk.Workflow;
import com.myengine.sdk.Pending;
import com.myengine.sdk.Compensations;
@Workflow
public class CoreTransferWorkflow {
    private final Engine engine = Engine.current();
    public String run(Transfer t) {
        Pending risk = engine.async(() -> {
            Transcript question = engine.step("riskPrompt", () -> prompts.risk(t));
            LlmResponse answer = engine.step("riskModel", () -> model.ask(question));
            return engine.step("readVerdict", () -> verdicts.read(answer));
        });
        Pending screening = engine.async(() ->
            engine.step("sanctions", () -> sanctions.screen(t)));
        engine.awaitAll(risk, screening);
        String decision = "approved";
        if (risk.get().level().equals("high") || screening.get().result().equals("hit")) {
            decision = engine.waitForSignal("review");
        }
        String outcome = "rejected in review";
        if (decision.equals("approved")) {
            Compensations undo = engine.compensations();
            try {
                String posting = engine.step("debit", () -> bank.debit(t));
                undo.add(() -> engine.step("reverse", () -> bank.reverse(posting)));
                String sent = engine.step("send", () -> rail.send(posting));
                outcome = "sent " + sent;
            } catch (Exception e) {
                undo.run();
                outcome = "refused by the rail - the debit is reversed";
            }
        }
        return outcome;
    }
}

The marked lines name the engine. They are the lines you do not want in your code. And they are only the ties you can see.

Ties you can see in the codeTies you cannot
The importsThe SDK's version in the build file, kept in step with the server's
engine.step around every effectRules on what the code between steps may do: the clock, random numbers, threads
engine.async and engine.awaitAll for parallel callsThe workers, queues and registrations a flow needs before it starts
The undo, added by handWhat a change to the code does to runs already under way

Infrastructure entangled with business logic

One would expect to open a file and see it: here is the business logic, there is the infrastructure. There is no such file. The infrastructure is in-band: it is part and parcel of the business logic. This has three costs.

You cannot review the logic on its own. When an AI produces a flow, you want to look at it and say yes or no to the business. You cannot: every change touches both layers, so every review needs someone who knows the engine as well as the business. The logic cannot be upgraded or refined independently.

The plumbing is the hard part to get right. Platform code runs across many machines, with listeners, retries and timing between them. That is where the race conditions live. You can test for the bugs you know. You cannot test every order in which things may happen, so a test can show that a bug is there, and never that none is left.

Checking such code takes an extremely seasoned engineer, and concurrency bugs get past seasoned engineers too. If an AI writes this code again each time the logic changes, it must be checked again each time, by the few people who can. The tokens are spent on the part nobody can validate by reading.

Where the tokens go

An AI is paid by the token: for every line it reads and every line it writes. In a working session it reads the code again at each turn. So the cost grows faster than the code does: twice the code is more than twice the cost, because there is more to read, more turns to get it right, and more to read again at every turn.

The plumbing is where that cost is highest, three times over.

Cost ofWhy the plumbing costs more
Writing itIn the transfer above, 20 of the 36 lines name the engine, and they are written again whenever the logic around them changes
Getting it rightThey are the lines that take the most turns, and then a seasoned engineer
Testing itThe largest of the three

Testing is the largest because the two kinds of code are tested in different ways. Business logic is tested with examples: this transfer is risky, that one is not. A few lines each, and an AI writes them in one pass. Plumbing is tested against what might go wrong: a machine dies between the debit and the send, two answers arrive in the wrong order, a retry lands twice. Each case needs a harness of its own, and nobody can list all the cases. So the tests grow larger than the code they test, they are written in the hope of catching most of it, and every line of them is read and written by the token.

The two layers mixedThe two layers split
What the AI reads and writesBoth layers, every timeThe business logic only
A change to one ruleThe plumbing around it is read again, and often written againThe plumbing is not in the file
Getting the plumbing rightMany turns, then a seasoned engineerNo turns: a compiler derives it
The testsHarnesses for crashes, orderings and retries; many lines, never completeExamples of the business rule; a few lines
Tokens spent on plumbingA large share, and the costliestNone

A small sum shows the size of it. Suppose taking the plumbing out makes the code half as large. If the number of turns grows with the size of the code, and every turn reads all of it again, the cost does not fall to a half. It falls to about a quarter. And that counts the code only. Add the tests the plumbing needed, which are no longer written at all, and the saving is larger still.

The glue between layers

There is a third piece of code. It lives at the boundary, where the business logic meets the infrastructure.

The glueThe question it answers
VersionsWhich version does a run follow, when the code changed while it was waiting?
ContractsWhen what a service is sent or answers changes, what happens to its callers?
Typed wiringDoes every call reach something of the right type, and every component the right kind of machine?
RoutingA canary, a split, a rollback: who gets the new version, and how is it taken back?
ConversationsSome end in a second, some wait days for a person. Who keeps them while they wait?
UpgradesWhat happens to the conversations under way when a new version arrives?

One might think the glue is the easy part. It is the hardest of the three.

WhyWhat it means
It has two mastersIt must fit the business code as it is today and the platform as it is today. Every publish moves one side; every platform upgrade moves the other.
It lives in timeThe old version and the new one run at the same moment. A conversation that began last week is still waiting for a person.
It fails quietlyA mistake here does not crash. It sends a good message to the wrong version, and shows up days later.

When the glue is written into the business code, it looks like this. MyEngine again, invented:

int v = engine.version("add-sanctions-check", 1, 2);   // runs begun before the change keep the old path
if (v >= 2) {
    screening = sanctions.screen(t);
}
String rail = engine.flag("canary-rail-v2") ? "rail-v2" : "rail-v1";

A version check and a canary flag, in the file a person who knows banking is supposed to read. Glue should never be part of the business logic. The further it is pushed to the infrastructure side, the better.

How to solve the glue: eight rules

Take two small changes to what the risk agent answers.

record RiskVerdict(String level) {}                  // contract 1
record RiskVerdict(String level, String reason) {}   // a field added: still contract 1
record RiskVerdict(int score) {}                     // a field removed, another kind: contract 2

The transfer that calls the agent was built against contract 1. Runs are under way. What should happen?

What changedThe contract?What should happen
A commentNoNothing; it is not even a new version
A settingNoThe same version; the change is recorded beside it
The code inside the risk agentNoA new version of the same contract; callers are not touched
The answer gains reasonNoAn added field is compatible: a caller that does not read it is not touched
A field a caller reads is removed, or changes its kindYesA new contract. Old callers keep contract 1, through an adapter

Behind that table are rules. They hold for any platform, whoever builds it.

RuleWhat it means
1. The contract is what a caller can seeWhat a service is sent and what it answers. A field that is added and that no caller reads does not break it; a field that is removed or changes its kind does. Everything else is not the contract.
2. A version never changesA change is a new version. The old one stays as it was.
3. The compiler works out the versionFrom what changed.

The article concludes that infrastructure code that is generated, and entangled with the business code, will soon be an albatross around the neck of every enterprise system that carries it. Each change costs more than the last: more to read, more to test, more to have checked. And it grows with every feature the AI adds.

The cost is removed where it was highest. A compiler is not paid by the token, and a platform is tested once, by the people who build it, not again by every team that uses it.