Outbox Pattern

Commit a domain change and a message-to-publish together.

Problem

A database commit and queue publish cannot usually be one atomic action.

When to use it

  • A committed write must eventually trigger consumers
  • At-least-once delivery is acceptable

When not to use it

  • A synchronous call is sufficient
  • The database itself is not authoritative

Minimal example

In one transaction update the order and insert outbox(event_id, type, payload). A relay publishes and marks the row sent.

Tradeoffs

  • Duplicates remain possible
  • Relay lag and table cleanup need monitoring