Try
↑ ↓ move↵ openesc close

Interview prep / Idempotency and the outbox

Mid · Idempotency and the outbox · System design interview question

How does the transactional outbox solve the dual-write problem?

Sketch your own answer first, then compare it with the one below.

A strong answer

The service writes the business row and an event row in the same local database transaction. They commit together or not at all. A separate relay reads unsent rows from the outbox table and publishes them to the broker, then marks them sent.

The event can no longer be lost while the database survives, and it cannot describe a write that rolled back. The cost is delay, since the event goes out after the relay polls, and an extra table to prune.

The relay can crash after publishing and before marking, so the same event goes out again. The outbox gives at-least-once publication, and not more.

Sources

Learn it by running it

The idempotency keys and the outbox lesson explains the mechanism behind this question, and its lab lets you change the parameters and watch the effect.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms