Interview Q&A / System Design

AdvancedQuick answer1 min readUpdated 3 Oct 2026

What is the transactional outbox pattern and what problem does it solve?

SHORT ANSWER

It solves the dual-write problem: updating a database and publishing an event can't be atomic. The outbox writes the event into a table in the same database transaction, and a separate process publishes it to the broker.

Explain it simply

A service saves an order in its database and then publishes "OrderPlaced" to Kafka. If it crashes between the two steps, the order exists but nobody hears about it. If it publishes first and the database write fails, others act on an order that does not exist. A database and a broker cannot share one transaction.

Outbox pattern:

  1. In one database transaction, insert the order row and an event row into an outbox table. Both commit or neither does.
  2. A relay process reads unsent outbox rows and publishes them to the broker, marking them sent. Alternatively, change data capture reads the database log and publishes it.
  3. If the relay crashes after publishing but before marking, it republishes, so consumers must be idempotent (at-least-once).

Result: no lost events and no phantom events, with the broker eventually consistent with the database.

Example

sql
BEGIN;
INSERT INTO orders (id, user_id, total) VALUES (981, 12, 499);
INSERT INTO outbox (event_id, type, payload)
VALUES ('e-5501', 'OrderPlaced', '{"order_id":981}');
COMMIT;
-- relay later: publish e-5501 to the broker, then mark it sent

What to say in the interview

"The outbox pattern makes the state change and the event a single local transaction, then publishes the event asynchronously via a relay or CDC. It guarantees no lost events, at the cost of at-least-once duplicates, so consumers need to be idempotent."

#messaging#consistency

Related questions

Practise more System Design questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open System Design quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.