Saga and Reconciliation
A saga coordinates business steps across independent transactional boundaries; compensation is a new business action, not a database rollback.
Saga and Reconciliation
A saga coordinates business steps across independent transactional boundaries; compensation is a new business action, not a database rollback. An orchestrator or choreography tracks durable workflow state. Each forward step has timeout, idempotency key and outcome. A compensating action attempts to restore a business invariant but can fail or be impossible. Reconciliation compares authoritative records and provider outcomes.
Mechanism and worked example
A travel booking reserves a seat, authorizes payment, confirms ticket and sends notification. If confirmation fails after authorization, void or refund using the original payment identity. If provider outcome is unknown, query it before issuing another authorization.
| State | Meaning | Safe action |
|---|---|---|
| Pending | Intent durable | Call with stable identity |
| Succeeded | Provider effect confirmed | Advance workflow |
| Unknown | Timeout or lost response | Query provider |
| Compensation pending | Forward effect confirmed; later step failed | Retry or escalate |
| Reconciled | Records and provider agree | Close workflow |
Failure modes and operations
A timeout does not prove the remote step failed. Compensation can be duplicated or rejected. A workflow may crash after external effect but before recording completion. Retrying a non-idempotent step can charge twice. Some states need manual intervention.
Trade-offs and design boundary
Orchestration centralizes state and visibility but adds a workflow dependency. Choreography reduces central coordination but makes global diagnosis harder. Sagas provide eventual business recovery, not atomic isolation across services.
Interview transfer exercise
Payment authorization times out after request submission. Persist intent and stable identity, query provider outcome, then compensate only after confirming the forward effect occurred.
Read the diagram
Persist step and idempotency key → Execute external action → Record confirmed or unknown outcome → Compensate or reconcile before closing
Payment authorization times out after request submission. Persist intent and stable identity, query provider outcome, then compensate only after confirming the forward effect occurred.
Your design draft
Clarify assumptions, explain your approach, and test the difficult cases. Save your draft, then compare it with the study notes.
Self-review checklist
Self-guided practice. Automated AI feedback and code execution are not connected.