Last week I spent ten hours on one database migration for Statpro, a sports stats site I build. It adds two columns, a foreign key and some search indexes, which on paper is a single ALTER TABLE. It took twelve commits, and the bugs I fixed weren't in the migration. They were hiding in the machinery around it, and I only found them because I'd built a system that refuses to believe a step happened until the step proves it.
A receipt is a document, and the pipeline waits for it
When I say receipt, I don't mean a log line scrolling past. I mean a structured document, written to an immutable archive, that records exactly what was checked, what was found and what was repaired. If a migration step runs, it has to produce a receipt, and if it can't, the pipeline halts.
That sounds bureaucratic until it catches a real bug. The migration runs inside an ECS task, a container that AWS starts for one job, and my first receipt gate checked whether the task reached STOPPED with a zero exit code. That seemed straightforward. ECS has eight lifecycle states, though, and my gate knew three. A task can be DELETED before the poller ever sees it, and the gate had no branch for that. It hung, waiting for a status that was never going to arrive.
Without the gate, the migration would have looked like a success. The task ran, the columns got added, and life went on. The gate refused to record a receipt for a task it couldn't confirm had stopped cleanly, and that refusal blocked the pipeline until I taught it the full lifecycle.
Missing and forbidden looked identical
The second bug was sneakier than the first. The migration writes its receipts to an archive, and the task's permissions produced the same "access denied" answer for an object that doesn't exist and an object it isn't allowed to read. The receipt checker saw "denied" and concluded the receipt was missing, when the receipt was sitting right there.
Picture that without a gate in the way. The migration writes a receipt, a later step looks for it, gets denied, and treats that as "not written." The migration appears to have failed, so I retry it. Now there are two partial receipts and a confused operator at 2am, and the operator is me. The fix was a small change that lets the checker tell absence from denial explicitly. The bug it exposed had been latent since the first deployment.
A reserved word inside a DO block
The third one is my favorite of the three. The migration SQL includes a precondition block that validates all ten search indexes before the main ALTER runs. Inside that block, a column alias in a SELECT INTO query collided with a Postgres reserved word. The failure was a syntax error deep inside a DO block, so the message pointed at the wrong line and said nothing useful.
That precondition only existed because I wanted a receipt for index validation. If I had run the ALTER and hoped, the indexes would have been created without trouble. The extra rigor is what surfaced the collision, in a block I would never have run on its own.
Receipts changed how I write the steps
I first used this pattern to certify historical sports data on Statpro. Certifying a season means checking its data until I can call it complete and trustworthy. Every step of cleaning a season produces a receipt: how many entries were checked, how many were repaired, and what the repairs were. When I sealed the NBA 1979-80 season last week, meaning I marked its data complete and locked it, I could point at 1,487 checked entries and 12 repairs.
What I didn't expect was how the receipts would change the way I write code. Knowing that every step must produce verifiable evidence, I build smaller steps, because each one needs its own receipt. I handle edge cases earlier, because the gate will catch the ones I miss. I trust structured proof where I used to trust logs.
The cost is real, since migration 0024 took twelve commits and a full day. There was the ECS lifecycle fix, the archive permissions, the reserved word, and two small fixes to how receipts are named and written. Each was a place where my evidence system was stricter than the system it was checking, and each time I had to choose between relaxing the gate and fixing the underlying code.
I almost always fixed the code, because the gate was reporting something true. There was a state I wasn't handling, a permission I was missing, or a word I was shadowing.
Two ways receipts go wrong
It's possible to overdo this, and I did. I caught myself writing receipt gates for steps that couldn't meaningfully fail, which only added latency and false alarms. My test is one question: if this step failed silently, would the data downstream be corrupted? The migration's index preconditions need receipts, because a broken index means wrong query results later. A Lambda's warmup step doesn't, because a cold Lambda only starts slower, and a log line covers it.
The other failure is a receipt that lies. One that says "checked" without verifying anything is worse than no receipt at all, because it creates false confidence. The NBA certification receipts include the actual repair records. When a gate checking that the 1960s American Football League's games were included in the schedule failed, it showed up as a specific failed check naming a specific missing season. A receipt has to carry enough detail that I could redo the verification by hand.
The halt does the work
The pattern itself fits in two sentences. Every step that modifies data or state writes a structured receipt somewhere immutable. The next step looks for that receipt before it runs, and if the receipt is missing or incomplete, the pipeline stops.
The checking is the ordinary part. Most systems check things and log the results, and very few refuse to continue when a check fails. The refusal is what turns a log into a guard, because a log describes a failure afterward and a gate stops the next step from building on it.
The ten hours on migration 0024 felt excessive while I was inside them. Most of that time went to bugs that had been sitting in my infrastructure for weeks. The migration didn't create them. The receipts found them, and every gate I fixed stays fixed for the next migration.