Skip to content
IT glossary
ArchitectureUpdated December 3, 2026

Transactional outbox

Transactional Outbox

A pattern that saves a data change and a record of the event in the same database transaction. A separate process publishes the event later, so a crash after the database commit does not erase the record of what needs to be sent.

Also known as: outbox

The problem it solves

When a customer places an order, the order service needs to save it and tell the inventory service about it. Writing to the database and publishing to a message broker are two separate operations. If the database write succeeds and the service crashes before publishing, inventory never hears about the order. Publishing first has the opposite risk: inventory may act on an order that never commits. This is the dual-write problem.

A transactional outbox turns those two writes into a single local database transaction. The application writes the order and inserts an OrderCreated event into an outbox table. Both records commit together or neither does. A separate publisher sends the event after the commit. The database transaction does not include the broker.

How publishing works

A background worker can poll for unpublished rows, send them to the broker, and mark them as sent only after the broker acknowledges them. Another option is change data capture (CDC): a connector follows committed changes to the outbox table through the database log and tracks its position so it can resume after a restart.

A minimal order write looks like this:

BEGIN;
INSERT INTO orders (id, status) VALUES (42, 'new');
INSERT INTO outbox (event_id, event_type, payload)
VALUES ('evt-42', 'OrderCreated', '{"orderId":42}');
COMMIT;

If the transaction rolls back, there is no event to send. If the commit succeeds while the broker is down, the row is still there when publishing resumes. The order API can return success without waiting for the inventory service, but that response says nothing about whether inventory has processed the event yet.

What it does not guarantee

A publisher can crash after the broker accepts the message but before it records success. On restart, it may publish the same event again. Design for at-least-once delivery with retries, not exactly-once processing. For example, an inventory consumer can record the stable event_id and apply the stock update in the same local transaction. A uniqueness constraint on the recorded ID lets it recognize a duplicate without applying the update twice.

The outbox also does not guarantee ordering. With multiple workers or retries, OrderCancelled might reach a consumer before OrderCreated for the same order. If order matters, design for it explicitly at the level that needs it, such as per order. In production, monitor the age of the oldest unpublished event as well as the backlog size: even a small backlog can contain a stuck message.

Where it comes up in interviews

Common examples include notifying inventory, updating a search index, and triggering the next step in a saga. In a system design interview, walk through a crash just after the database commit and another just after the broker acknowledgment. The first shows why the event needs a durable record; the second shows why consumers must tolerate duplicates. An outbox makes publication recoverable without a distributed transaction, but downstream state still catches up asynchronously.