Blog

Deterministic simulation testing isn't just for databases

Deterministic simulation testing (DST) has a reputation as something only database engineers do. A recent piece on Outdata, Deterministic Simulation Testing Is for Everyone, argues against that view. It makes the case that any application with a clear boundary between its logic and its environment can benefit. We agree with the thrust of it. We’d add that the interesting part for most organisations isn’t the testing technique itself. It’s the architectural discipline the technique forces on you.

The real cost is the bug you can’t reproduce

Most engineering leaders have lived through this. A production incident happens once a fortnight, under load, maybe involving a slow third-party API and a retry. Nobody can reproduce it locally. The test suite is green. Someone adds more logging and everyone waits for it to happen again.

That cycle is expensive. It eats senior engineering time, it erodes trust between delivery teams and the business, and in regulated environments it produces incident reports with uncomfortable “root cause unknown” sections.

Flaky tests are the same problem in miniature. A test that fails one run in twenty teaches the team to ignore failures. Once that habit forms, the suite stops being a safety net and becomes a ritual.

DST attacks both problems at the source. If every run is driven by a seed, and the same seed always produces the same behaviour, then any failure the simulator finds can be replayed exactly. “Can’t reproduce” stops being an acceptable answer.

What it actually requires

The shape of a DST setup is simple to describe. The test harness feeds a seed into a simulated environment, which drives a deterministic core of the application. After each step, the harness checks that the system’s properties still hold.

graph LR
  S[Test seed] --> E[Simulated environment]
  E -->|inputs, faults, time| M[Deterministic core]
  M -->|outputs, IO requests| E
  M --> P{Properties hold?}
  P -->|yes| E
  P -->|no| F[Report failing seed]

The hard part is the middle box. For the core to be deterministic, it cannot read the system clock, call the network, touch the disk, generate its own randomness or depend on thread scheduling. All of those have to come in through interfaces the simulator can control.

That is not a testing library you install. It is a design decision, and it is much cheaper to make at the start of a project than in year four.

The payoff is that the simulator can be nasty in ways the real world rarely is on demand: duplicate messages, timeouts at the worst moment, clocks that jump, partial writes. As the Outdata piece puts it, “A good simulation is an exercise in amplifying the deviousness of those parts of the environment we cannot control.” Because nothing actually waits, months of simulated activity can run in a fraction of the time.

Where it earns its keep outside databases

In our experience, the systems most likely to benefit are not exotic. They are the ones with lots of state, lots of external dependencies and expensive failure modes:

The properties you check are business rules, not implementation details: a balance never goes negative, a booking is never allocated twice, every submitted application eventually reaches a terminal state. That is a big part of the appeal. Properties at this level map to things a product owner actually cares about, and they survive refactoring far better than example-based unit tests.

The honest trade-offs

DST is not free, and it’s worth being clear-eyed before committing.

Retrofitting is hard. A codebase that calls now() in fifty places and talks to the database from its controllers needs real restructuring. Budget for it, or start with a new component.

The simulation is only as good as your model. If your simulated payment gateway never returns the odd error code the real one does, you won’t find bugs that depend on it. You still need integration tests against real dependencies and good production observability.

Writing good properties is a skill. Teams used to asserting that a function returns a specific value need time to learn to think in invariants.

Concurrency needs care. Multi-threaded code has to be deterministically scheduled, which can constrain how you use certain frameworks.

None of these are reasons to avoid it. They are reasons to introduce it deliberately rather than as a side project someone picks up on a Friday.

What this means if you’re buying or running software

You don’t need to mandate DST to benefit from the thinking behind it. The underlying question is whether your system’s behaviour is reproducible, and that’s something any organisation can ask of its teams and vendors.

Questions we’d put to a delivery team or supplier:

Vague answers aren’t necessarily a red flag, but they tell you where the risk sits.

For teams considering it, we’d recommend starting narrow. Pick the one module where a defect would hurt most, such as settlement, allocation or a state machine at the heart of a workflow. Pull its clock, randomness and IO behind interfaces. Write three or four properties a product owner would recognise. Run the simulator in CI with random seeds and log any failing seed. If that catches something your existing suite missed, you have your business case for going further.

The broader point from the source article is one we share: a technique being associated with one domain shouldn’t stop you from using it in yours. “Development is the best place to find bugs.” Making your system deterministic enough to simulate is one of the most direct ways to act on that.

If you’re weighing up whether this fits a system you’re building or inheriting, we’re happy to talk it through. You can book a free 30-minute session at /book and we’ll look at where reproducibility risk sits in your stack and what a sensible first step would be.

← All posts