R231 · Infrastructure for agents at scale › Consistency and storage tradeoffs

Outbox plus inbox under chaos: four ways to wire one sale to one message, measured

Read the original

Authors Lukas Grigis

messagingoutboxidempotencychaos-testingrabbitmqspringopen-source

· Source: Lukas Grigis, Spring Boot outbox and inbox and the MIT-licensed companion repo lukas-grigis/spring-outbox-inbox, Spring Boot 4.2, Spring Modulith 2.2, RabbitMQ 4.4 over AMQP 1.0, Postgres 18, Java 25.

The short version

A service records a sale and must tell another service about it. That is two systems and two commits, with no transaction spanning them. Most teams know the outbox pattern in theory. This experiment measures four wirings under identical, seeded chaos: kill -9 on both apps, SIGKILL on RabbitMQ, and Toxiproxy dropping broker confirmations and consumer acknowledgements for 6 seconds at a time. A script counts the damage directly from both databases.

Each run sent 2,000 sale requests; between 1,049 and 1,415 sales committed depending on the wiring:

WiringLostGhosts (stamped but rolled back)Applied twice
Commit, then send2740n/a
Send inside the transaction025n/a
Transactional outbox (Spring Modulith)0025
Outbox plus consumer inbox000 (25 duplicates caught)

There was one run per version on one machine, and the inbox version ran on three seeds. The direction matches the theory, and the scale is the useful part: 274 of 1,316 committed sales (about one in five) lost by the naive "save then send" approach under this fault mix.

How the winning design works

  1. Producer outbox. The sale row and an event_publication row commit in one local transaction. A relay sends after commit and marks the publication complete only when the broker answers ACCEPTED. A scheduled resubmitter retries failed or stale publications with the same bytes, the same message id and the same SHA-256 content hash.

  2. Broker. A quorum queue with a delivery limit and a dead-letter (parking) queue, configured by policy, not queue arguments.

  3. Consumer inbox. In one transaction, INSERT INTO inbox (message_id) ... ON CONFLICT DO NOTHING, and apply the effect only if the insert returned 1. A 0 means already seen: count a duplicate if the hash matches, and park the message as an id-reuse error if it doesn't.

  4. Settle after commit. The consumer accepts the delivery only after its transaction commits, requeues with a count on error, and discards to the parking queue when the message is bad.

The outbox fixes lost and ghost messages but guarantees at-least-once delivery, so duplicates appear. The inbox turns at-least-once delivery into effectively-once processing.

Non-obvious findings (each pinned by a test in the repo)

Tradeoffs

Review checklist

Connections

See R231 on the knowledge map

Part of the Research notes on nowucca.com. Figures and claims are the source's own unless the summary says otherwise.