Loading articles…
Loading articles…
Loading article…
Loading article…
An order service updates its database and then publishes OrderCreated to a queue. If the process crashes between those steps, the database says the order exists but downstream systems never hear about it. Reversing the order creates the opposite failure: a message can announce a change that later rolls back.
An outbox adds an events table to the service's database. In one database transaction, write the order and an outbox row containing a unique event ID, event type, aggregate ID, schema version, timestamp, and a minimal payload. If either insert fails, the transaction rolls back both. A separate publisher reads committed outbox rows and sends them to the broker.
The publisher can send a message successfully and crash before recording that it sent it. It will publish the same row again on restart. That is expected in an at-least-once system. Consumers should keep a processed-event table or another idempotent state transition keyed by event ID, and commit that record with their own business update.
Claim batches safely when more than one publisher runs, retry transient failures with backoff, and move persistently failing events into an observable error path. Track the age and count of the oldest unpublished row, publish failures, duplicate handling, and consumer lag. A growing outbox is a delivery incident even if the API is still accepting requests.
Use an outbox when a durable business write must reliably trigger work in another process or service. For a single application with no cross-system event, a direct transaction may be simpler. Choose the pattern because a real dual-write failure matters to the product, then budget for the publisher, idempotent consumers, monitoring, and replay tooling.
Chief Technology Officer
Newsletter
New articles from our engineers, straight to your inbox. One email a month, no spam.