System Design Atlas

Grocery orders with store inventory and substitutions

07 / 10Worked example

Critical flow

What effect may be continued after the loss of response?

The architecture must handle a failure between an external effect and the local response. B-17 contains confirmed substitute A-11 for 220 cents. The basket is frozen. At pickup, E-17 is stored durably; the payment service then charges the amount, but the response is lost. Payment instruction, payment success and handover therefore remain separate evidence.

Starting point The processes from step 6 divide local storage and external payment effects.

Assumptions for the example case

Own example design for pick-up from a store and packaged piece goods with strictly positive integer cent prices. Free and fully discounted baskets are outside the case. Replacement items are specifically allowed in advance; the final positive amount arises from goods actually provided and is collected on collection. Figures and target values are illustrative design assumptions.

Commit before transmission, clarification after loss of response

Critical process · commit before transmission, clarification after loss of response

E-17 is stored durably before submission. The charge succeeds, but its response is lost. Reconcile the same instruction.

Store interface
Order API
Transactional store
Background process
Payment service
  1. 01 Store interface → Order APIStart payment for B-17, expected version
  2. 02 Order API → Transactional storeE-17 + zahlung_offen + outbox, one transaction
  3. 03 Transactional store → Order APICommit
  4. 04 Order API → Store interfaceaccepted, result open
  5. 05 Background process → Transactional storeLoad E-17
  6. 06 Background process → Payment service220 cents, stable order reference
  7. 07 Payment service · Local processingCharge completed; response lost on return
  8. 08 Background process → Transactional storeResult still unknown
  9. 09 Background process → Payment serviceCompare E-17 by reference
  10. 10 Payment service → Background process220 cents confirmed
  11. 11 Background process → Transactional storepaid + provider reference, commit
  12. 12 Store interface → Order APIConfirm handover
  13. 13 Order API → Transactional storeCheck bezahlt, single handover, commit
  14. 14 Order API → Store interfaceausgegeben

Result: Exactly one charge and one handover for B-17; both effects refer to E-17 and 220 cents.

Alternative Webhook Branch Payment service → Order API: Feedback; Order API → Transactional store: Store inbox; Commit Order API → Payment service: Confirm receipt; Background process → Transactional store: Process inbox and check E-17.

The failure occurs after the external charge and before the local system learns the outcome. The next step reconciles E-17; it does not create a new payment instruction.

E-17 is permanently stored before transmission. After charging, the response is lost; the background process clarifies the same order before the single handover is released.

Three possible external results

ResultReactionHandover authorisation
Confirmed successCheck authenticated feedback against B-17, E-17, 220 cents, EUR and current provider status and store it permanently.Yes, after full agreement.
Definitive rejectionStore zahlung_fehlgeschlagen and begin goods resolution.No.
UnknownKeep E-17 open and compare it against the same provider reference.No; a network error message does not prove a rejection.

Confirmed success

Reaction
Check authenticated feedback against B-17, E-17, 220 cents, EUR and current provider status and store it permanently.
Handover authorisation
Yes, after full agreement.

Definitive rejection

Reaction
Store zahlung_fehlgeschlagen and begin goods resolution.
Handover authorisation
No.

Unknown

Reaction
Keep E-17 open and compare it against the same provider reference.
Handover authorisation
No; a network error message does not prove a rejection.

Deduplicate duplicate or delayed callbacks. A mismatched order, payment instruction, amount or currency cannot authorise handover; an older event cannot reset bezahlt.

Case decision and verification approach

Clarification of the same payment instruction

Reconcile the existing instruction E-17 and retry it only under the provider’s verified idempotency contract.

The amount may already have been collected, even though the API did not receive a response.

Prevent a second charge and an unpaid handover. The failure test ends with one charge, one handover and the same instruction.

Alternative considered
A new payment with a new key can charge twice.
Trade-off
Open processes require permanent tracking.
Reassess
Frequent or long clearing cases require better provider queries and operational escalation.

Terms in this step

Payment instruction
E-17 binds order, frozen amount, EUR and provider reference permanently.
Unknown result
The external effect may have occurred while the local detection is missing; the same task remains for the clarification anchor.

Try it yourself

Mark the local commit, the time of error and the allowed next step. Explain when handover is possible.

A hint for your attempt

The failure occurs after the external charge and before the local system learns its outcome.

Compare with a possible solution
Local Commit
The first commit saves E-17 including the outbox before transmission.
Error time
The error lies after charging; locally, the result remains unknown.
Permitted next step
The background process clarifies E-17 using the same reference.
Handover authorisation
The issue will only follow if an authenticated confirmation proves B-17, E-17, 220 cents and EUR together; a new payment will remain blocked.

Apply to your project

What external effect could have occurred in your system despite Timeout?

Step 8 examines which waiting times and conflicts limit the architecture.