Saga
A saga splits 1 order into local steps, and each step has a compensation. When shipping is down for 20 s, the saga refunds the payment and releases the stock. No order stays half done.
See it on the board
The same traffic runs on two boards. The simulator measured both when this page was built.
| Measure | Goal | Steps run with no undo | Durable saga with compensations |
|---|---|---|---|
| Data mismatches | none | 20 Fail | 0 Pass |
| Duplicates | none | 0 Pass | 0 Pass |
| Lost writes | none | 0 Pass | 0 Pass |
| Completion time | under 25 s | 0.81 s Pass | 1.41 s Pass |
| Monthly cost | 28 USD/mo | 28 USD/mo | |
| Error rate | 0% | 0% | |
| Level rules | none broken | Board is not complete Fail | Pass |
Key numbers
| Number | Value |
|---|---|
| Steps per second, one scheduler | 10,000 ops/s |
| Scheduler step, median | 0.3 ms |
| Default delivery tries | 5 tries |
Outbox · 10 orders · 10 events · 0 lost
How it works
A database transaction can make many changes succeed or fail together. A business action often spans several services, each with its own database. There is no single transaction across them. If you reserve stock, charge the card and then find that shipping is down, you hold a half finished order.
A saga solves this with a plan of local steps. Each step is a normal transaction in one service: reserve the stock, charge the payment, request shipping. Each step has a compensation, which undoes it: release the stock, refund the payment. A coordinator runs the steps in order. If a step fails for good, the coordinator runs the compensations of the finished steps, in reverse order.
In the mini board twenty accepted orders reserve stock, charge payment and request shipping. Shipping is unavailable for the first 20 s. Each order must complete, or refund its payment and release its stock, in 25 s. The saga does that, and no partial order is left.
The coordinator must be durable, so a crash does not forget which steps ran. Each step and each compensation must be safe to repeat, because a retry can send them twice. And a compensation is not a rollback: for a short time other users can see the half done state.
In the levels you make the coordinator durable, add the compensations and check for partial orders.