System design · interactive
Sagas and the transactional outbox
Placing an order touches four services, each with its own database. There's no transaction across all of them. A saga runs the steps one by one and, if one fails, runs compensating steps to undo the earlier ones.
Orders
Create order (pending)
Inventory
not started
Payments
not started
Shipping
not started
- → Orders: Create order (pending)
Publishing the OrderCreated event, with a crash
- BEGIN; INSERT order; INSERT outbox row; COMMIT
- process crashes
- relay reads unsent outbox rows and publishes OrderCreated
- The event is saved in the same transaction as the order, so it can't be lost.
Create order (pending)
What happens
Publish events
Step 1 of 4 · read left to right
In production
Tools and technologies
Workflow engines run sagas; CDC tools relay outboxes.
Not tied to one language — use these names when you search docs or design a system.