When a service updates its database and then publishes an event (to a queue, a webhook or another service), there's a gap between the two. If the process crashes after the commit, or the broker is down, the change is saved but the event is lost ; publish first instead, and a failed commit leaves an event about something that never happened. The transactional outbox closes the gap: write the change and the event row into an outbox table in the same database transaction , so both are saved or neither is. A separate relay reads the outbox and publishes each event, retrying until it succeeds. Delivery becomes at least once , so consumers must be idempotent . Here's a tested Node.js implementation with the built-in node:sqlite , and an ordering bug worth knowing about.
Why can't you just publish after committing?
In a KYC pipeline, approving a verification has to tell other systems: unlock the account, email the customer, notify compliance.…