Messaging Patterns

The Outbox Pattern for Reliable Messaging

Guarantee at-least-once event delivery without two-phase commit by writing events to the database in the same transaction as your business data.

February 19, 2026
#outbox#event-driven#distributed-systems

The dual-write problem: if you write to your database and then publish to a message broker, a crash between the two leaves them inconsistent. The outbox pattern solves this by writing messages to an outbox table in the same local transaction as the business data. A relay process reads the outbox and publishes to the broker, marking messages as sent. Atomicity is guaranteed by the database; the broker gets at-least-once delivery.

sql
CREATE TABLE outbox (
    id          UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    aggregate   TEXT        NOT NULL,
    event_type  TEXT        NOT NULL,
    payload     JSONB       NOT NULL,
    created_at  TIMESTAMPTZ NOT NULL DEFAULT now(),
    sent_at     TIMESTAMPTZ
);
Outbox table structure

Continue reading