Engineering · Accounts · Performance

The fence first, then everything at once

A money export waited eight times for figures that all hung off one answer. The check on who may see them stayed first. Everything after it runs together.


The accounts export is the screen that turns a month of trade into the lines a bookkeeper posts: takings, VAT by band, cost of goods, commission, refunds, each against a nominal code. Three warm loads of it averaged 1.4 seconds, and the one call behind them spent most of that inside the server. The bench that counts statements and waits said eight reads and eight waits before anything was touched.

What the eight were

The venue row, which also carries the company it belongs to. Then the company row. Then five figures one after another: the takings and tenders, the VAT bands, the cost of goods, the commission, the refunds. Then the company's nominal codes. Every read after the first was keyed on the venue, the date window, or the company id, and the venue row already carried the company id. Nothing after the first read needed anything but the first read's answer.

What may run together and what may not

The first read is not a lookup. It is the fence: does this caller get to see this venue's money? On a route that exports a ledger that check stays first, on its own, before a single figure is read, and it was never a candidate for the wave. What follows it is a different matter. The company, the five figures and the codes all hang off what the fence answered, and none hangs off another, so they now go out together. Eight waits became two: the fence, then everything.

The test was written before the change and failed against the old route naming eight serial steps. It passes at two, and the half of it that matters more is the half that checks the money did not move: two paid orders in September, eighteen pounds of goods from the orders and eighteen from the lines, the company's overridden sales code reaching the journal, a venue that does not exist refused after exactly one read, and a missing date window refused after exactly one read. Two older test files that drive the same functions against seeded books, one for commission and one for refunds, stayed green. That is the proof the arithmetic is untouched: only the waiting moved.

Measured

On the live service after the deploy the export for one venue's September answers correctly, three orders and four journal lines, and the route's own share of the time from beside the database dropped to tens of milliseconds. Our probes that day could only stand beside the database, so the seconds a UK browser sees are not ours to quote; the shape is. Six fewer waits is six fewer crossings of whatever wire the reader is on.

For anyone running a floor

Some steps have to happen in order because the second depends on the first. Checking that the person asking for the safe's contents is allowed to see them is one of those, and it stays at the front no matter how slow it makes the morning. Most steps are only in order because somebody wrote them down that way. Once the one real dependency is at the front, everything behind it can go at once, and the cash-up that took eight trips to the office takes two.


Try it on tonight’s service.

Nothing to install, no card. Not better by the weekend? Close the tab.