Skip to content

The replay that calculated a different invoice

Failure story 08, in events and replay.

Same events, same code. Why does the invoice rebuilt from history disagree with the invoice the customer paid?

Assumption Value
Event OrderShipped { orderId, netAmount: 100.00, shipTo }
Invoice handler On OrderShipped, looks up the current sales-tax rate for the destination from a configuration service and builds the invoice
Rate 8.25% in March; changed to 8.50% from July 1
What’s stored The invoice view, built from events and rebuildable
Step What happens
1 March 10: order O-3 ships. The handler finds 8.25% and issues an invoice for $108.25. The customer pays.
2 July 1: the rate changes to 8.50% in the configuration service.
3 September: the team rebuilds the invoice view to fix a formatting problem, replaying every OrderShipped.
4 The handler processes O-3’s event again and finds 8.50%: the rebuilt invoice says $108.50.
5 Accounts receivable now shows the customer owing 25 cents, and an auditor finds that the system can’t reproduce an invoice it issued.

Scale that to 200,000 invoices and it’s a finance incident.

Replay gives the same answer only if every input is the same. The events were the same, but the handler also read an input from outside the event log, and that input had changed. The event recorded what happened; it didn’t record what the system knew when it decided. Any lookup of current configuration, prices, exchange rates, feature flags or a model’s score has the same problem.

Aspect Design A: look up current values Design B: immutable, versioned inputs
Tax rate source Whatever the configuration says now A rate table with effective dates, never edited in place
What the handler asks “What’s the rate?” “What was the rate on the tax-point date, March 10?”
What’s recorded The invoice total An InvoiceIssued event with the net amount, the rate, the rate table’s version and the total
Replay Recomputes with today’s values Rebuilds the view from InvoiceIssued, reproducing the original exactly
A deliberate recalculation Indistinguishable from a replay A separate, labeled action that produces its own events

Recording the decision as an event, not only its trigger, is the stronger half. Then the invoice view can be rebuilt without running the calculation at all: the past is read, not recomputed.

  1. Reproduce the past. Rebuild the invoice view from history after changing today’s tax rate. Expected: every invoice matches the issued invoice, to the cent. Compare a hash of each invoice, not only the totals.
  2. Recalculation is visible. Run an intentional recalculation of March invoices under a corrected rate. Expected: the original invoices are unchanged and the recalculation produces new, separately identifiable records, such as credit notes or adjustments, that reference the originals.

This check is in the checks catalog as test templates in Java and Python.

  • The view is a convenience that’s allowed to show today’s interpretation of history, such as a what would this cost now? report, and everyone who uses it knows that.
  • The external value genuinely never changes. Few business values qualify.

Discussion question. List the external lookups in one of your event handlers. For each, is the right value the one now or the one then? Who decides?

Exercise. Finance discovers that the March rate should legally have been 8.00%, not 8.25%. They want corrected invoices. Under Design B, what do you produce, and what happens to the original $108.25 invoice?

Worked answer

The original invoice stays exactly as issued, because it’s a record of what the customer was actually sent and paid. The correction is a new fact: issue a credit note of $0.25 referencing invoice O-3, as an InvoiceAdjusted event that records the corrected rate, the reason and who approved it. A rebuilt view then shows the invoice, the adjustment and a net of $108.00. This is replay versus correction: replay reproduces what was known; a correction records what’s known now. The address correction that rewrote history is the same distinction applied to records that aren’t money.

Written and edited by Abhinav Taduka, enterprise software architect.