System Design
9. Message Queues and Event-Driven SystemsAnimated
Transactional Outbox Pattern
Save the event in the same transaction as the data.
The idea
An outbox table is written with the data change, and a relay publishes it, avoiding lost events.
Watch it work
Press play, pause, or step through. Some animations have settings you can change.
- current message
- earlier
- failure or attack
The business change and the event are written in one local transaction.
- step:
- 1/5
- from:
- Service
- to:
- Database
1/5
Time runs downward. Solid arrows are requests, dashed arrows are replies.
Step by step
- 1Write data and outbox row in one transaction
- 2A relay reads the outbox
- 3Publishes to the broker
- 4Marks it sent
Where it is used
Reliable event publishing.
Watch out for
The relay may publish twice, so consumers must be idempotent.