Q9 · What’s the role of sagas in long-running workflows?

Back to 24 Architecture Questions.

The question is not “how do you sequence steps”. The axis it turns on: who compensates when step four fails, and whether compensation is a real business action. A saga is a sequence of local transactions, each committing on its own, with no global rollback. When step four fails, consistency is restored by running compensations backward: the design, not the database, owns the undo.

Compensation runs backward A saga moves forward through reserve, charge, ship, and notify. When notify fails, compensation runs backward through the completed steps: cancel the shipment, refund the charge, release the inventory hold. FIGURE 9 COMPENSATION RUNS BACKWARD Reserve hold inventory Charge take payment Ship book carrier Notify failed cancel booking, refund, release hold each step names its undo before it runs, and the undo is a business action a refund is real money moving; deleting a row is not compensation

What the answer should contain

The saga is the distributed answer to “no global transaction”. Each step commits locally. When a later step fails, the earlier ones are undone by compensations, in reverse order. There is no rollback; there is only a plan for going backward.

Every step declares its compensation before it runs. Reserve declares release, charge declares refund, ship declares cancel. Some steps cannot be compensated at all (the email sent, the goods delivered): place them last, or design a pivot action (accept the state and finish differently) instead of pretending an undo exists.

Compensations are real business actions. A refund moves money through a payment provider; it is not a DELETE. If the business would not actually take the compensating action in practice, the saga is fiction, and finding that out during an incident is the expensive way.

Two coordination styles, both legitimate. Orchestration: a coordinator owns the plan, the step states, and the compensation sequence; the plan is visible and testable, the coordinator must persist its state. Choreography: services react to each other’s events; no central point, and the plan is invisible in any single place. Pick orchestration when the workflow has money in it, choreography when it is a few loosely coupled reactions.

Choreography still needs three designed things. A correlation ID on every message. A failure event each participant subscribes to, which is what triggers its own compensation. And a per-step deadline, so a step whose expected next event never arrives compensates itself. Each service persists only its own step state. For one view of a whole saga, add a read-only tracker fed by the same events; if one owner must decide when a saga is dead, use an orchestrator.

Compensations assume a repeat. They run under at-least-once delivery, so they must be idempotent, and the saga state must persist so a crashed coordinator resumes rather than restarts. A compensation that fails is parked for a human, with the full saga state attached.

Sagas expose intermediate states. Between charge and ship, the order is “placed, not yet shipped”. Readers must tolerate that window: isolation is weaker than a transaction, and the design must say so instead of hiding it.

Ideas worth mentioning out loud

Follow-ups to expect

Red flags in an answer

Sources