Light ALA: which parts of ALA pay for themselves
The earlier posts built ALA variants of one Phoenix app until the checklist and the linter scored them 100. That answers whether a LiveView app can be written in Spray’s style. It does not answer what the style costs once the app has to change, which is the claim ALA is built on: Spray’s applications kept their simplicity “after considerable maintenance” (§1.5.1). So I measured it, and then went looking for the lightest version of ALA that keeps what the measurements said was worth having.
This post is for readers who know ALA. If you don’t, start with the thermometer.
How it was measured
One app: the storefront and B2B portal every Elixir variant here implements. Ten requirement changes, given in order, each building on the last: promo codes and gift wrap in the portal, undo holding three removals, the portal taking stock, order history, a new calibration, promo minimums, reorder, stock caps, saved lists surviving checkout, and live price changes.
Each change was made by an agent (Opus 5.5) working alone on one variant, with a standing brief: the variant’s design rules, the spec, and the gates it had to pass (suite green, format, credo, coverage, and for the ALA variants the linter at 100). A grader then re-ran the gates and measured three things:
- Cost: the tokens and tool calls the change took, and the production lines it touched.
- Breakage: how many of the previous step’s own tests failed against the new code.
- Correctness and design: a reviewer agent read each change at its tag and judged every clause, every defect it introduced, and the design fit and test quality out of 5.
The comparison is always V0, a conventional Phoenix app written “by the guides”, and V51B, the strict-ALA variant with stories, ports and wiring.
Strict ALA cost a third more per change
Over the ten changes, V51B took 1.34× V0’s tokens and changed 1.91× its production lines. It broke fewer of the previous step’s tests (19 against 33), its design fit was about equal (3.9 against 4.0), and it was no more correct: 6 clauses only partly met against V0’s 3, and one more confirmed defect.
The cost was not spread evenly. The dearest step, order history (S04), cost 1.9×: to record what an order charged, the priced summary had to travel along wires through two state machines to the code that writes the order. V0’s page already held the summary and passed it in. That is the port tax, paid on parts that only one page ever placed.
First try: relax R11
The obvious lighter ALA keeps the checklist and reads R11 (composition only) as advice, so a page may keep a one-page rule as a function, as Spray does in his scoreboard because “all the code in the application is specific to the application requirements” (§6.28.1). The Phoenix variant built that way from V51B ran its first seven changes at 0.97× strict ALA’s cost: no saving that a single run can see (a Rails one did the same). Agents seldom used the allowance, the rules folded onto pages moved back into parts as soon as a second page needed them, and every S04 run paid the same port tax, because every part was still wired. Relaxing a rule did not remove the structure the rule had built, and agents extend the structure they find.
Second try: build up from V0
So I reversed the direction. Start from V0, where everything is a plain call, and add one piece of ALA at a time, keeping a piece only if the next run said it paid. These are checklist readings, not Spray’s ALA, which also composes by ports (§3.5, §7.2.3):
| Form | Adds | Variant |
|---|---|---|
| 1 | Layers (app → contexts → domain → platform), no context calls another; every literal in the app layer’s calibration; rules as named pure domain modules | V54 |
| 1b | Configuration and session values passed once as structs, so a new input is a field, not an argument | V55 |
| 1c | A value the domain needs is an enforced key, never a default; a guard sits where the data is written; a name never changes meaning | V56 |
| 2 | One generic live-update feed: writers publish facts keyed by identity, pages declare what they listen to | V57 |
| hybrid 1 | Form 1c plus a composition root per page (one parts function that builds what the page uses) and tests that build structs only through the app’s builders | V58 |
The results
All ten changes, Phoenix, one run per step:
| V0 | strict ALA | Form 1c | Form 2 | Hybrid 1 | |
|---|---|---|---|---|---|
| Tokens / V0 | 1.00 | 1.34 | 1.07 | 1.10 | 1.12 |
| Production lines | 1,158 | 2,216 | 1,278 | 1,347 | 1,327 |
| Previous-step tests broken | 33 | 19 | 19 | 25 | 23 |
| Clauses partly met | 3 | 6 | 4 | 4 | 4 |
| Defects confirmed | 2 | 3 | 3 | 3 | 3 |
| Design fit (/5) | 4.0 | 3.9 | 4.3 | 4.2 | 4.2 |
| Test quality (/5) | 4.9 | 4.5 | 4.6 | 4.7 | 4.7 |
Form 1c costs about what V0 costs (1.00× over the last four changes), breaks no more of the previous step’s tests than strict ALA, and has the best design fit of the five. Forms 1 and 1b, run through the first six changes, explain how it got there.
Form 1 kept the cheap wins and lost the breakage. It ran the first six changes at 1.04× V0, never paid the S04 tax (1.15× V0 where strict ALA paid 1.9×), and kept strict ALA’s one cost win, S06’s promo minimum checked at one point every subtotal change already passes (0.91× V0). But it broke 1.44× V0’s tests. The reviewer traced the whole excess to interfaces: calibration accessors renamed when a value split by channel, context functions growing a positional argument for each value passed down, rule functions reshaped instead of extended.
Form 1b fixed the interfaces, partly by hiding things. Passing calibration and session values once, as structs, removed every interface break: 11 tests broken over six changes against V0’s 27. Some of that was bought with defaults that hide a missing value (a session id that could be nil, so orders nobody can see) and a guard kept only on the page. A breakage figure rewards code that checks less.
Form 1c kept the gain honestly. Enforcing every value the domain needs, and putting each guard in the context that writes the data, closed both. Its breakage, counted fairly, is strict ALA’s: 19 over ten changes.
Counting fairly needs one caveat. When a struct gains a required key, every test that builds it through a shared fixture fails at once: form 1c’s raw count was 147, and 128 of those came through a handful of fixture lines. I re-ran each step’s previous tests with that step’s own fixtures to separate the two. The 128 were real work, but small: one or two lines each time.
Where the knee is
Plotted as cost against what each form bought, the curve bends in one place:
- Below the knee, at 1.0–1.1× V0: forms 1, 1b and 1c. Layers, calibration at the top, named rules, structs passed once, honest contracts.
- At the knee: a generic live-update feed and composition roots. The feed (form 2) cost 3% more over ten changes and made only S10, live prices, cheaper (112k tokens against form 1c’s 125k), because V0’s existing product broadcast already reached every page the spec names. Composition roots (hybrid 1) cost 49 production lines over ten changes and no later change went around them; their benefit is a reader seeing what a page is made of in one place, which only the design score sees.
- Past the knee: ports and wiring on every part. Strict ALA and the R11-relaxed variants at 1.3–1.4×, for benefits the forms below the knee also got.
The feed in form 2 is worth a closer look, because it is the one programming paradigm the light forms kept. In the strict variants, outside change already had a paradigm, ChangeFeed, a part with ports that the page wires (field guide, R1). V57 keeps the idea and drops the ports: a context publishes a fact by kind and identity after it commits, and a page maps the kinds it listens to onto handler functions once, in mount. It is small (39 lines) and pleasant to read, and in this app it bought one cheaper change, because V0’s existing broadcast had already reached every page. In an app whose pages build their own live channels, it is the first thing I would add to V59.
Every form built up from V0 kept these, and none of them needs a port:
- A rule named once, checked at one point every relevant change passes. S06’s promo minimum was cheaper than in V0, which copied the check into each page, in every ALA-shaped variant but hybrid 1 (130k tokens against V0’s 128k).
- The page passes values down to the parts it calls. No relay of a value between parts or between contexts. This is what kept S04 at 1.1–1.3× V0 in the forms built from V0, against strict ALA’s 1.9×.
- Calibration in one place at the top, passed down rather than held by the contexts. (V0 already kept its numbers in one module, so this one bought correctness, not cost.)
- Configuration passed once as structs, a needed value enforced, a guard where the data is written. Together these brought breakage down to strict ALA’s level without its cost.
What they leave out is what costs: ports on parts that only one page places, wiring between them, and pages that may only compose. In Spray’s account a feature “creates instances of domain abstractions, configures the instances with feature specific details, and connects them together” (§2.2). These forms keep the creating and configuring and replace the connecting with calls.
Two things the runs caught
Hybrid 1’s roots invited one shortcut. Its reorder ran as a LiveView event using the shops its root had built at mount; after the portal’s Submitted step the LiveView session still named the completed draft, and the reordered lines were lost. Forms 1c and 2 had put the reorder behind a POST for exactly that reason. And its tests, built only through the app’s builders, still broke 119 at once when a builder that took positional arguments gained one.
Both are cheap to guard against, and V59 does.
V59: the light ALA variant
V59 is form 1c with hybrid 1’s composition roots and those two guards: an action that changes a cart found through the session runs through a request, or re-resolves the cart, and every cart writer refuses a cart that is no longer open; and every struct builder takes keyword overrides, so adding a field never changes its arity. It implements the base requirements, not the ten changes, so you can read it as a starting point. Its 175 tests pass, coverage is 99.61%, and the linter, with the port and wiring checks switched off, scores it 100 at every tier with all seven rules it adopts met. Its own post, V59, light ALA, walks the twelve rules and the linter settings that keep the design honest.
What this says about ALA itself
The parts of ALA that paid for themselves here are not its distinctive parts. Dependency direction, named abstractions, calibration at the top and explicit configuration are layered architecture done strictly, and much of it already has names in the Elixir community: a pure core, contexts that don’t call each other, configuration passed in. What is distinctive about ALA, composition by ports and wiring, an application layer that only composes, a diagram that is the program, is where the cost was, and in this app it bought little the light forms did not also get.
So a Phoenix team is far more likely to take V59 than V51B, but it may take it as disciplined Phoenix rather than as ALA. And if a team would not take even V59, the objection is to the bookkeeping that discipline asks for, not to anything ALA introduced.
That does not settle ALA. Its distinctive claim is about systems kept simple through years of maintenance, and about parts placed and rewired in many configurations, as in Spray’s embedded examples. A store with two pages offers almost no rewiring: two parts here ever had a second placement. LiveView already supplies the long-lived process, the PubSub and the components that ALA’s paradigm layer would otherwise build. And every change was made by a model that knows conventional Phoenix well. For an app like this one, light ALA is the version worth adopting; full ALA is a bet on a different kind of system, and this exploration could not test it.
What this does not show
- One app, one language, one run per step. Two runs of the same step differed by up to 7% in tokens and 15% in production lines, so differences smaller than that between forms are noise. Forms 1c, 2 and hybrid 1 are within it of each other.
- Agents, not people. Every change was made by a model, which knows conventional Phoenix well. The forms built up from V0 look more like code it has seen, and part of their advantage may be that familiarity rather than the rules.
- Ten changes is not “considerable maintenance”. Spray’s claim is about systems kept for years. Ten changes cannot show it, in either direction.
- The benefit measures are narrow. Breakage, clause results, defects and a reviewer’s 1–5 scores. Whether the code is pleasant to change for a person, over time, is not on the list.
What it does show is that most of ALA’s measured gain over conventional code came from its layers and its discipline about interfaces and guards, and almost none from wiring every part. If you want ALA’s structure at conventional code’s price, start with the four parts above, and add ports where a part really has two placements that route its outputs differently.