skip to content
← cd ../work

case study / Reliability / distributed systems

Finding the failures that look healthy

A correctness audit for an event-sourced platform, built around the invariants that functional tests never exercise.

my role
Designed and ran the audit, led remediation in my domains, triaged teammates’ audits, and reviewed the fixes, including my own.
stack
NestJSPostgreSQLKafkaKubernetesHelmAI agents

## Context

The platform is event-sourced. Services append events to a shared store, change data capture publishes them to Kafka, and separate read models are built from that stream. Delivery is at-least-once on every hop. Correctness comes from idempotency at each consumer, not from exactly-once delivery.

That is a sound design. It also moves risk into places a test suite rarely looks.

## The problem

Functional tests run the happy path once. In this architecture the bugs that matter show up on the second delivery, the out-of-order callback, or two requests racing for the same record. A system with those bugs passes QA and looks healthy in staging. It fails in production, quietly, on a busy day.

A green dashboard is evidence of nothing in an at-least-once system.

## Approach

  1. 01

    Start from invariants, not code

    I wrote down what had to stay true no matter how messages arrived: a redelivered event changes nothing; an external provider is called once per intent; a read model never moves backward; one tenant’s data never reaches another.

  2. 02

    Turn the invariants into a reusable audit

    I built a review prompt around those invariants and ran it domain by domain with AI assistance, starting where the blast radius was largest: compliance, trials and account management. Every finding was checked by hand against the code and, where possible, against production-shaped data, using counts only.

  3. 03

    Track everything, then parallelize the fixes

    Findings became tickets with an owner and a severity. For my own domains I ran one implementer agent and one reviewer agent per ticket, each on its own branch from the latest main, and deployed the fixes end to end in ephemeral environments.

  4. 04

    Review the fixes adversarially, including mine

    After the hardening work merged, I re-reviewed it against main as if a stranger had written it. That found two launch blockers in changes I had already shipped, and showed that none of the fixes had a test that would fail if the fix were reverted.

## What it found

  • Consumers that were not idempotent, so a redelivered event would apply its effect twice.
  • Dual writes to external providers, where a retry could create the same billable resource twice.
  • Last-writer-wins races on read models.
  • A service whose event consumers had never started in any deployed environment, so the features downstream of it silently did nothing.
  • A deployment template default that would have quietly undone a production safety hold, starting a deliberately disabled service against a billable carrier API on day one.

## Trade-offs

  • chose: Scope the audit to the highest-risk domains instead of the whole platform.

    cost: Lower-risk areas got a lighter pass. It was the only way to finish before launch without stopping feature work.

  • chose: Use AI to make audits cheap enough to run per domain.

    cost: AI produces confident wrong answers. Its first read of the deployment issue was wrong, and I had it re-check against the actual chart templates. Every finding needed a human check.

  • chose: Fix in parallel with agents.

    cost: Throughput went up and so did review load. The adversarial pass afterward was not optional.

## Outcome

Findings were tracked and remediated ahead of launch, and the team adopted the audit method for other domains. The count of issues matters less than the method: write down the invariants, then go looking for the second delivery.

Details are generalized. Nothing here is proprietary code, customer data or internal metrics.