Try
↑ ↓ move↵ openesc close

Interview prep / Idempotency and the outbox

Mid · Idempotency and the outbox · System design interview question

Why is the outbox relay at least once, and what must the consumer do about it?

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

A strong answer

The relay publishes, then marks the row sent. These are two steps on two systems, so the dual-write problem appears again inside the relay. If it crashes between them, it publishes the event again on restart. It cannot do better without a shared transaction with the broker.

So consumers must be idempotent. Each event carries a stable id. The consumer records the ids it has applied, in the same transaction as its effect, and drops an id it has seen. That turns at-least-once delivery into effectively-once processing.

Ordering is a related point. Publish events for one entity in the order of the outbox, and key the partition by entity.

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