HandbookXV the PantheonSagas and distributed transactions
XVthe Pantheon, Design the systemSagas and distributed transactions
In plain words
A saga runs a business process across several services as a series of local steps, each with a compensating action that undoes it, because one database transaction can't span them all.
Where you see it
Upgrading to Harbor Team touches three services: billing authorises the card, deploys raises build limits, identity adds seats, and billing captures the payment last. If adding seats fails, nothing rolls back by itself; the saga restores the limits, releases the authorisation and tells the customer.
What goes wrong
- Assuming a transaction covers several services
A database transaction stops at the edge of its database. A call to Stripe or another service inside it isn't undone when it rolls back, so money can move while your data says it didn't.
- Undos that can't really undo
A sent email can't be unsent, and a refund isn't the same as never charging. Put the hardest-to-reverse steps last, and write each step's compensation before building the step.
- Losing track mid-saga
If the process crashes between steps, something has to know where it got to. Store the saga's state in the database, or use an orchestrator such as Temporal, so it resumes or compensates after a restart.
What to tell your agent
Quick check
Sign in to earn +10 XP for itHarbor's upgrade code charges the card through Stripe inside a database transaction, and then the transaction rolls back. What state is the customer in?