Skip to content

Payments with uncertain external outcomes

10 min reading

A reconciliation and recovery design that preserves the original action

Page details

System Design · Compose complete systems

10 min reading · 25 min with practice

Sources

Published · Last edited:

Prerequisite: Payments: record an approved money movement. For basics, use the independent System Design foundations.

More
20px

Hypothetical scenario. Northwind’s provider completes an action, but its reply disappears before local confirmation is recorded. Later evidence arrives after a refund decision. Dev proposes trusting the latest event received; Priya asks whether arrival order establishes the actual payment history.

Maya: “Which status can we justify for the buyer now?”

Dev: “We must connect provider evidence to the original intention and permitted local transition.”

Recover the money-movement workflow without replacing its uncertain intention. Preserve balanced local posting rules while reconciling provider evidence, fulfillment and later events. A pending case is owned unfinished work, not permission to invent an outcome.

Which histories remain possible after the missing response?

The request may never reach the provider, may be rejected, or may commit before its answer is lost. A local timeout distinguishes none of those outcomes conclusively. Retain the original payment identity, bound parameters, attempt evidence and an owned unresolved case. A replacement identity can bypass the provider’s recognition of the original intention.

A provider response and an authenticated webhook are different observation paths to related facts. Validate origin, object identity and the meaning of the reported transition. Repeated observations must not create another local journal or another fulfillment action. A stable provider operation, a stable local journal and a stable fulfillment operation can have different identities connected by explicit references.

Evidence resolves one retained payment intentionProvider lookup and authenticated events supply evidence about the original payment operation. Reconciliation validates that evidence against current workflow state. A legal local transition commits postings and fulfillment intent together, while uncertainty remains retained when evidence is inconclusive.Provider lookupOriginal identityAuthenticated eventRepeated / delayedReconcile stateOr retain unknownLegal local commitPostings + intent
Later arrival is evidence to interpret, not authority to overwrite the current state.

Count unknown outcomes as unfinished obligations

Hypothetical worked example. Choose one thousand intended purchases. Nine hundred have confirmed success, eighty have definite rejection and twenty remain unresolved. The ledger of outcomes balances because 900 + 80 + 20 = 1,000. Report the three states separately rather than inflating either confirmed success or rejection.

Select ten conclusive reconciliation resolutions per minute and two newly unresolved operations per minute. Net drain is 10 − 2 = 8 per minute. The twenty-case backlog then takes 20 ÷ 8 = 2.5 minutes under the fixed-rate model. Repeated status requests that return inconclusive evidence consume resources but do not count as resolved operations.

If newly unresolved work grows to ten per minute while useful resolution remains ten, net drain is 10 − 10 = 0. The backlog stops shrinking. A larger worker pool helps only if the provider, local authority and evidence path can support more conclusive resolutions. The operational objective is useful recovery, not a high query count.

Let evidence advance a payment state legally

Hypothetical scenario. An API call times out, a webhook reports success and a later reconciliation file confirms settlement. Store these as evidence for the same provider operation, retaining event identity, provider object identity and the referenced business intention. Arrival order alone does not determine the legal payment transition.

Let evidence advance a payment state legally — selected design evidence
Evidence recordJoin identityReducer obligation
API replyprovider operationMay be missing or uncertain
Webhookevent + provider objectAuthenticate and deduplicate
Reconciliation itemprovider object + settlement referenceResolve declared state
Refund operationoriginal payment + refund intentionRecover independently
The reducer joins evidence by operation and applies a state rule rather than last-arrival-wins.The reducer joins evidence by operation and applies a state rule rather than last-arrival-wins. Provider API to Evidence ledger: 1 · uncertain reply; Webhook / reconcile to Evidence ledger: 2 · conclusive evidence; Evidence ledger to Evidence ledger: 3 · legal transition only.Provider APIEvidence ledgerWebhook / reconcile1 · uncertain reply2 · conclusive evidence3 · legal transition only
The reducer joins evidence by operation and applies a state rule rather than last-arrival-wins. Enlarge the diagram to inspect its labels; the surrounding records and explanation give the text alternative.

A refund notification arriving before a delayed payment notification must not make the reducer overwrite refunded state with a simpler paid label. Define legal transitions and how conclusive provider evidence resolves contradictions. Webhook delivery identity handles repeated notifications; business-operation identity handles the underlying effect. Verify authenticity and scope before accepting either as evidence.

After local restore, compare the recovered prefix with external history. A provider success absent from that prefix is still a real remote effect. Recover the original intention and fill the evidence gap before allowing a replacement charge. Compensation is another protected action, so a refund with a lost reply needs its own stable identity and reconciliation path.

In the wild: provider rules constrain recovery

Stripe’s idempotency documentation specifies parameter, retention and API-version behavior. Its webhook documentation describes event delivery and signature verification. Inspect the exact selected operation and version; Northwind’s local state names do not override the external contract.

Do not infer that a saved error response means no effect exists or that a late success permits repeating fulfillment. Where current provider evidence conflicts with recorded state, preserve the observations and apply the authorized reconciliation policy. An operator needs the original identity and history, not merely a red status badge and a retry button.

Balance does not establish business correctness

Two balanced postings can still use the wrong customer, amount or account. Validate identity, currency, authority and the business transition as well as the algebra. Keep currencies separate unless an explicit conversion model and its accounting rules are supplied.

Concurrent reservations or captures need a coordinated limit. Two workers reading the same available amount can each accept work that exceeds it in aggregate. Select the transaction and isolation behavior deliberately; the PostgreSQL isolation chapter is a concrete example of why “uses transactions” is not the entire concurrency argument.

A local outbox can coordinate a recorded state change with intent to notify fulfillment. It cannot atomically include an arbitrary provider. Fulfillment must also deduplicate its effect and understand whether the event represents authorization, capture or another explicitly defined state.

An old webhook arrives after a refund

Hypothetical failure scenario. A refund completes, then a delayed earlier payment-success event reaches the consumer. A handler that simply assigns the event's status can return the order to paid and trigger fulfillment again.

Apply legal transitions against current state and recorded operation evidence. Preserve event identity and distinguish provider event order from local arrival order. When an event conflicts with known state, investigate or reconcile through the documented provider object rather than choosing the last network arrival as truth.

Use a durable unresolved-work queue with ownership and audit evidence. Sensitive payment material should not be copied into generic logs. A provider-hosted payment interface can reduce some application handling, but does not automatically establish the application's complete security or compliance posture.

Three payment shortcuts to reject

“The request failed, so no charge happened.” Only the relevant operation evidence can establish the effect; a missing response leaves uncertainty.

“Balanced means correct.” Balance is one invariant. Identity, authorization, amount, currency and permitted state transitions remain necessary.

“Webhooks arrive once and in business order.” Design from the provider's actual delivery contract. Repeated or delayed observations must not repeat fulfillment or reverse newer state.

Choose a small authoritative boundary

Keep the internal transaction record, postings and local state transition within one transactional authority when feasible. Separate provider communication and reconciliation as explicit workflow stages. Use stable operation identities at every external effect boundary.

Monitor pending age, mismatched provider/local outcomes, duplicate observations and reconciliation capacity. Test restoration against known transaction identities and invariant checks. A restored database that forgets completed external effects can cause duplicate actions after restart.

Reject a distributed rewrite before the invariant fits a clear local model. Reject universal “exactly once charged” language unless the entire provider and retry contract supports the precise claim. The design review should expose what remains unknown and who may resolve it.

Boundaries of the ledger exercise

Signed posting examples use one currency and a simplified account model, not an organization’s complete chart of accounts or compliance program. A local transaction cannot include an arbitrary provider, and retries depend on that provider’s documented identity and retention rules. Capacity arithmetic excludes physical storage overhead, while restoration must preserve operation identities as well as account totals.

A restore can recreate uncertainty

A recovery point can precede a provider confirmation that already caused a real effect. Restored account totals may look internally balanced while operation references are missing. Before resuming external writes, reconcile the retained provider identities and independently available observations against the restored local state.

A correction has the same obligation. A remotely completed refund whose local answer was lost remains one refund operation. Reusing its supported identity or inspecting its outcome differs from issuing another refund. Human decisions must preserve this distinction and record the authority and evidence for the chosen transition.

Challenge the proposed mechanism

Older payment evidence cannot reverse an already established refund transition.Older payment evidence cannot reverse an already established refund transition. Outcome uncertain to Payment confirmed: conclusive operation evidence; Payment confirmed to Refund recorded: protected refund evidence.Outcome uncertainPayment confirmedRefund recordedconclusive operation evidenceprotected refund evidence
Older payment evidence cannot reverse an already established refund transition. Enlarge the diagram to inspect its labels; the surrounding records and explanation give the text alternative.

A restored system receives refund evidence and then a delayed paid event. What should its model answer demonstrate?

Reveal the design reasoning

Reconstruct the payment and refund identities, apply the legal evidence precedence and preserve the refund. If provider semantics are insufficient, keep a reconciliation case open. Do not create a second charge to repair missing local history.

Decision and reconsideration: Persist authenticated evidence and monotonic business transitions. Treat restore as a new reconciliation with unreversed external history.

Defend the next transition

  1. A provider call times out. Should the service create a new payment identity?

    Keep the original intention

    No automatic replacement follows. Reconcile or safely repeat the original operation under the provider contract, retaining unresolved state where evidence is inconclusive.

  2. An old success event arrives after a confirmed refund. What decides the local result?

    Interpret evidence against current state

    The legal state machine and operation history decide. Last network arrival is not business order. Preserve evidence and prevent repeated fulfillment.

  3. The recovery worker issues ten queries per minute, but half remain inconclusive. May capacity be counted as ten resolutions?

    Count useful completions

    No. Resolution capacity counts conclusive legal transitions. Attempt volume can be high while the unresolved backlog still grows.

The payment pair separates accepted intent from independently confirmed effects. Page 49 uses a similar discipline for media: completing an upload does not establish that a coherent presentation is ready for viewers.

Northwind decision log

Retain uncertain provider operations under their original identities.
Commit legal local postings and downstream intent from validated evidence.
Next, separate media upload, processing and publication authority.

Go deeper: recovery boundaries