Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The transactional outbox pattern prevents a service from saving a database change while losing the event meant to announce it. The service commits its business update and an event record to the same database transaction; a separate relay publishes that committed record to a message broker. Delivery is asynchronous, so consumers must be prepared for delay and duplicates.

Why use a transactional outbox?

A service that changes its database and publishes a message is performing two writes to separate systems. Without a practical shared transaction, either operation can succeed while the other fails: the database can commit but the event never reaches the broker, or a message can be sent for a database change that later rolls back. This is the dual-write problem.

The outbox makes the business change and the intent to publish atomic within one local database transaction. AWS describes the pattern as a way to resolve this dual-write issue; microservices.io likewise explains that spanning the database and broker with a distributed two-phase transaction is generally not viable or desirable.

How the pattern works

  1. Start a local transaction in the service’s database.
  2. Insert or update the business record, such as an order or flight record.
  3. In that same transaction, insert an outbox row describing the event. The row can carry an event ID, event type, payload, ordering information, and processing metadata.
  4. Commit the transaction. If it rolls back, neither the business change nor its outbox event becomes available for publication.
  5. A relay reads committed outbox rows and publishes their events to the broker.
  6. After publication, the relay records completion or retry state according to the implementation.

The broker publication is not part of the database transaction. The pattern therefore guarantees atomicity for the database update and the recorded intent to publish—not immediate delivery to every consumer. Consumers may see the change after the service’s database transaction has committed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What reliability does it provide?

Atomic database state and publication intent

Because both rows are written in one local transaction, a committed business change cannot be separated from its corresponding outbox record by a failure between independent database and broker writes. The relay can resume from committed records after an interruption.

Asynchronous propagation, not exactly-once processing

An outbox does not by itself guarantee exactly-once delivery or processing. A relay can publish an event successfully and fail before recording that it did so; on recovery, it may publish the same event again. AWS also notes that standard Amazon SQS queues deliver at least once, so a consumer may receive a message more than once.

Give each event a stable ID and make each consumer safe to retry. Common approaches include storing IDs already handled, performing idempotent upserts, or using a business-operation key that prevents the same effect from being applied twice. Do not assume a broker’s delivery behavior alone makes the full database-to-consumer workflow exactly once.

Ordering only when the domain requires it

If events for one entity must be applied in sequence, include sequence information and preserve the required order in the relay. Select broker features that support the ordering scope the application needs; ordering for one entity or partition is a narrower requirement than global ordering. AWS warns that order matters in event-sourcing use cases, where applying events incorrectly can damage data quality.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose a relay that fits your database and operations

The relay is the component that turns committed outbox rows into broker messages. Polling, change data capture (CDC), and managed change feeds all implement that role, but differ in how they read changes and what infrastructure they require.

Relay approach How it reads events Advantages Trade-offs
Polling publisher A worker periodically queries for unhandled rows, claims them, publishes messages, and marks them processed. Works with ordinary relational databases and is straightforward to understand. Polling interval, safe claiming or locking, batch size, and row cleanup need tuning. The AWS reference architecture uses an event-processing service to read an outbox table and send messages to SQS.
Change data capture (CDC) A connector tails a database log or change stream and routes outbox-table changes to the broker. Can reduce polling load and latency. Debezium’s Outbox Event Router captures outbox-table changes and applies a single-message transformation before emitting events. Adds connector, schema, offset, and operational dependencies.
Managed change feed A platform change feed detects committed changes and passes them to a publisher. Can suit an application already using the platform’s database and cloud services. Couples the implementation to that platform’s change-feed and broker services. Microsoft documents a Cosmos DB transactional batch followed by Change Feed processing that publishes to Azure Service Bus.

There is no universally best relay. Choose based on the database and broker already in use, acceptable publication delay, operational capacity, ordering needs, and the effort required to recover and monitor the relay.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Handle retries, failures, and cleanup deliberately

Keep failed work recoverable

A transient broker or network failure should not cause the relay to discard an unpublished event. Keep it available for retry, and define what happens after repeated failures—such as moving it to a dead-letter or quarantine state under an operational policy. Monitor retry counts and events requiring operator attention.

Make relay progress visible

Track relay lag, retry counts, dead-lettered or quarantined events, and outbox-table growth. These signals help distinguish a quiet system from a stalled publisher and reveal when the relay is falling behind consumers’ needs.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Retain and purge records safely

Decide how long completed rows remain and when they can be purged. Cleanup should follow the system’s recovery and audit requirements rather than removing records simply because they were once marked processed. The exact retention period depends on those requirements; the referenced pattern guidance does not prescribe a universal value.

Outbox design checklist

  • Write the business record and its outbox event in the same local database transaction.
  • Assign a stable event ID and define consumer idempotency before relying on retries.
  • Specify how the relay claims rows, retries failures, records progress, and handles events that cannot be delivered.
  • Define ordering scope explicitly, and implement sequence tracking only where the domain needs it.
  • Ensure the relay reads committed events only; a rolled-back event must never be published.
  • Monitor lag, retries, exceptional events, and table growth, and set a cleanup policy.
  • Treat payload schema evolution and backward compatibility as part of the event contract.

When an outbox is not enough

The outbox coordinates one service’s database change with its outgoing event. It does not create one atomic transaction across several independent services or data stores. For a workflow that spans multiple stores, use an orchestration approach such as a saga to coordinate service-level transactions and their outcomes. AWS identifies saga-style handling as appropriate for transactions across service boundaries.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.