Events are published through an outbox
A state change and the event that announces it are saved together, so one never happens without the other.
HighChecked by hand
- Applies to:
- Services that publish events
- Rule id:
- events.publish-through-outbox
Why it matters
Writing to the database and then publishing to the broker are two separate operations, and the process can die between them. Either the order is saved and no event goes out, so downstream services never hear of it, or the event goes out and the transaction rolls back, so they act on an order that does not exist. Both are silent.
How to apply it
- In the same database transaction as the state change, insert the event into an outbox table.
- A separate relay (a poller, or change data capture on the outbox table) reads the table and publishes to the broker, marking rows as sent.
- The relay delivers at least once, so consumers must handle duplicates.
- Monitor the age of the oldest unsent row; a growing backlog is your signal that events have stopped flowing.
Example
placeOrder() inserts into orders and outbox in one transaction. A relay publishes OrderPlaced to the broker a few milliseconds later and sets outbox.sent_at.
References
Checklists with this rule
Related agent skill: transactional-outbox-inbox