Try
↑ ↓ move↵ openesc close

Interview prep / Idempotency and the outbox

Senior · Idempotency and the outbox · System design interview question

Design a flow so an order is created once and its event is processed once, with retries at every hop. What does each layer need?

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

A strong answer

The client sends an idempotency key with the order. The API stores the key, the order row and an outbox row in one transaction. A retry returns the stored result, and a late retry after key expiry is the known gap.

The relay publishes outbox rows at least once, with a stable event id. The consumer applies each event and records its id in the same transaction as its effect, so a repeat does nothing.

Each layer makes its own retry safe. No layer can promise exactly once alone. The system gets the effect of exactly once from at-least-once delivery plus idempotent handling. List the leftovers: keys that expire, an outbox that grows if the relay stalls, and a consumer table to prune. Monitor relay lag and the age of the oldest unsent row.

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