Hypothetical scenario. Northwind reserves a unit inside PostgreSQL, then loses the independent payment provider’s response. Dev proposes rolling back the database transaction. Priya asks whether the provider’s effect belongs to that database boundary.
Dev: “We can undo the local reservation change.”
Maya: “What evidence tells us whether the other service has already acted?”
Distinguish a local commit, coordinated preparation and a compensating workflow. Keep the uncertain provider effect visible while deciding what the reservation permits next. The selected workflow cohort is its own exercise, not an implicit increase in catalogue traffic.
Which changes share one decision boundary?
Calling two services in order does not create one transaction. After the first succeeds, the second can fail, time out or become unavailable. The first effect may already be visible to other operations. A retry or a rollback function in the caller cannot automatically restore the world as though nothing happened.
Even a local transaction should cover the actual business invariant. If inventory and reservation records can safely share one authoritative store, that may be simpler than dividing them into services and reconstructing their atomicity over a network.
Identify irreversible effects early. An email cannot be made unseen, a shipment cannot always be recalled and a refund is a new financial action with its own timing and failure modes. Describing every corrective step as rollback hides the consequences users can already observe.
Prepare a decision or record a workflow
In two-phase commit, participating resources first prepare to follow a final commit or abort decision. A prepared participant cannot independently assume abort merely because the coordinator is temporarily unreachable. The decision and recovery protocol determine what happens next.
A saga-style workflow instead commits local steps and records the next action or compensation. It must define intermediate states, concurrent interactions, retries, deadlines and unresolved cases. It does not provide the same isolation as one transaction across all steps.
PostgreSQL 17's PREPARE TRANSACTION reference describes prepared transactions intended for an external transaction manager and warns about leaving them unresolved. The two-phase transaction documentation describes their durable state. A database exposing this mechanism does not mean an arbitrary external provider participates in it.
Show prepared state and compensation as different protocols
Hypothetical scenario. A database reservation and an external provider charge do not share a transaction manager. A durable workflow stores the reservation identity, provider operation identity, evidence and next recovery action. Payment uncertainty stays pending until lookup or reconciliation supplies a stronger fact.
| Workflow evidence | State | Next authorized action |
|---|---|---|
| Provider definite rejection | Payment rejected | Release reservation |
| Provider timeout | Payment uncertain | Lookup same operation |
| Late success after release | Paid but no stock | Compensate under declared policy |
In two-phase commit, participants prepare before a coordinator records and communicates a decision. Prepared resources can remain blocked while the decision is unavailable. Use that design only with actual participating resource managers and a recovery protocol; an arbitrary HTTP service is not a participant merely because the caller waits for it.
A saga instead commits local steps and records compensating work. Release or refund is a new business action, with its own identity, failure and evidence. It does not erase a customer's earlier observation or restore the world atomically. An expiry policy may require accepting a late provider success and then refunding it; label that product rule rather than claiming the timer proved failure.
Calculate exposure and reconciliation work
Hypothetical scenario. Choose 100 purchase workflows. Sixty complete both reservation and payment. Twenty fail payment with a definite rejection and require reservation release. Twenty have an uncertain payment outcome and remain pending. The accounting is 60 + 20 + 20 = 100; pending must not be counted as either confirmed success or definite failure.
If each workflow reserves one item, the uncertain group holds 20 items until reconciliation or a declared expiry transition. Releasing them after a chosen five-minute timer is a business rule that must account for payments confirmed after that timer. A timer does not establish that a provider action never occurred.
Suppose reconciliation can inspect ten pending operations per minute while five new uncertain operations arrive per minute. With a backlog of 20, the net drain is 10 − 5 = 5 operations per minute, giving 20 ÷ 5 = 4 minutes under constant rates and successful inspections. Inspections that remain inconclusive do not count as resolved operations.
For a prepared-resource example, choose 30 prepared transactions each holding two distinct row locks. That is 30 × 2 = 60 held locks under the chosen model. Their impact depends on which rows other transactions need, not just the total. One frequently requested row can cause more disruption than many unused rows.
These numbers expose operational obligations rather than asserting a universal throughput or timeout. A workflow diagram without pending counts, recovery capacity and unresolved-state ownership omits a substantial part of the design.
In the wild: Choose prepared state or a compensating workflow
The primary reference establishes this concrete distinction: prepared PostgreSQL transactions require an external manager and unresolved-state handling.
Compensation preserves a different invariant
The business may accept a temporary reservation followed by release if payment fails. It may not accept a shipment before payment authority is established. Define the allowed states and which transitions make irreversible commitments. Sometimes reordering steps or using a provider-supported authorization stage reduces exposure.
Compensations can fail and require retries with their own operation identities. They may also race with a late success. Record which decision the workflow has made, which effects are confirmed, and how late evidence is interpreted. Do not allow two independent recovery workers to issue incompatible corrective actions.
Atomic commit can be appropriate when all participants support the chosen protocol and the application requires its contract. It also introduces prepared-state recovery obligations. Replicating the coordinator can protect decision state, but cannot make an unreachable participant receive a decision immediately.
The refund succeeds but the status write fails
Hypothetical failure scenario. A workflow decides to refund a payment after a reservation expires. The provider refunds it, but the local process crashes before recording completion. A recovery worker issues another refund because the local state still says pending.
This is the idempotency problem inside compensation. Use the provider's supported identity and reconciliation capabilities, persist the intended corrective action, and distinguish requested, confirmed and unresolved states. Compensation is not exempt from partial failure.
An operational queue should identify unresolved cases and the authorized human decision path where automation cannot establish the outcome. Record the evidence and preserve the original logical operation identity. A manual action without that context can repeat the same mistake as an automated retry.
Three claims to reject in a design review
“A saga is a distributed transaction with automatic rollback.” It permits intermediate commits and uses business-specific corrective actions. Visibility and isolation differ.
“Two-phase commit is the same as consensus.” Atomic commit asks participants to follow one transaction outcome; consensus solves agreement under its specified model. A system can use consensus within its commit machinery without making the concepts identical.
“Expiry resolves uncertainty.” It establishes a policy deadline. Evidence about an external action can still arrive afterward and require reconciliation.
Keep the invariant as local as practical
Prefer a clear local transaction where the ownership and operational requirements allow it. When a workflow genuinely crosses authorities, choose between supported atomic commit and explicit intermediate states from the business requirement, not from a blanket rule about microservices.
Document every externally visible state, the permitted transitions, the owner of recovery and the evidence needed to finish it. Include conflicting user actions such as cancellation while payment is pending. A happy-path sequence alone does not specify the workflow.
The later architecture cases combine these decisions. For each, identify where atomicity is necessary, where asynchronous derived state is acceptable and which failures require an explicit pending or unavailable outcome.
Limits of this model
Prepared transactions require compatible participants and a durable transaction manager. Sagas require meaningful intermediate states and corrective actions. A compensation can fail or become uncertain itself; it cannot promise that users or external systems never observed the earlier action.
Challenge the proposed mechanism
A refund succeeded but its local status write was lost. What should the compensator do?
Reveal the design reasoning
Recover the same refund operation through its protected identity and provider evidence. Creating another refund intention can duplicate compensation. Keep compensating obligations durable until their effects are explained.
Decision and reconsideration: Prefer local invariants where possible. Across owners, choose an actual prepare/commit protocol or an explicit recoverable workflow with honest intermediate states.
Check the pending state
A payment call timed out. Can the reservation be released as though payment definitely failed?
Inspect the required evidence
Not from the timeout alone. Apply the declared expiry and reconciliation policy, accounting for a late confirmed payment. Preserve a pending state where the outcome remains unknown.
The compensation call succeeded remotely but no local completion record exists. What follows?
Inspect the required evidence
Reconcile using the same corrective operation identity and supported provider evidence. Blindly repeating a refund can duplicate the corrective effect.
Inventory and reservation invariants fit one database transaction. Must they become a saga to scale the organization?
Inspect the required evidence
No. Service boundaries should not casually weaken the required invariant. Evaluate ownership and workload evidence against the additional intermediate states and recovery burden.
The workflow needs durable decisions even when a machine disappears. Page 30 examines how a coordination group agrees on one command history, while keeping enforcement of the resulting authority a separate responsibility.
Northwind decision log
Name compensation and reconciliation states explicitly.
Distinguish prepared transactions from compensatable steps.
Expose unresolved payment outcomes to reconciliation; next examine agreement on one decision history.
Go deeper: prepared decisions and explicit workflows
- Book chapter: Principles of Transaction Processing, second edition, chapter 8: Two-Phase Commit — Philip A. Bernstein and Eric Newcomer. Inspect prepared participants and recovery.
- Book chapter: Principles of Transaction Processing, chapter 5: Business Process Management — the same authors. Relate durable process state to intermediate commitments.
- Video lecture: Distributed Systems: Two-phase commit — Martin Kleppmann. Distinguish a prepared resource from a completed business action.
- Primary document: PostgreSQL 17: PREPARE TRANSACTION — PostgreSQL Global Development Group. Inspect transaction-manager requirements and operational warnings.