ADR-00033 — Saga/Orchestration vs. Choreography for Checkout Distributed Transaction Coordination
- Status: Approved / Implemented
- Date: 2026-10-08
- Authors: Engineering Team
Context
Completing a checkout touches three independent services with no shared database transaction between them — inventory-service (stock reservation), payment-service (Razorpay payment capture), and shipment-service (courier handoff) — yet BRD-013 requires the whole sequence to behave as one logical transaction: nothing is left stuck if a step fails (BR-04), and every step’s outcome is tracked and attributable (BR-09). Distributed-transaction coordination across independently-owned services has two well-known patterns: Saga/Orchestration, where one coordinator sequences every step and decides on compensation, and Choreography, where each service reacts to events published by the others with no central coordinator. This ADR settles which pattern the checkout flow uses, distinct from ADR-00032’s choice of which engine implements the orchestration style this ADR picks.
Decision Drivers (FRs & NFRs)
See SR-014 and SR-018 for the full requirement lists.
- BR-04 (BRD-013 — Nothing Is Left Stuck When a Step Fails): a failure partway through must trigger a deterministic, known compensation sequence — not an open question of which service notices the failure and acts on it.
- BR-09 (BRD-013 — Every Step Is Tracked, and Any Failure Is Visible and Attributable): the business needs one place that holds the full, ordered history of what happened to a given order’s transaction — a “statement” a support engineer or an auditor can read end to end.
- SR-018 FR-03 (One Addressable Coordinator Instance per Transaction): compensation spanning more than one prior step must be decided with full context of what already completed, not reconstructed from each participant’s own partial, locally-visible view — see BRD-017 BR-01.
- FR-01 (SR-014 — Order Creation Schedules, Never Executes, the Saga): order creation schedules one
CheckoutSagaWorkflow— the system already has a single entry point that owns the whole sequence, not three independently-triggered reactions. - FR-08 (SR-014 — Saga State Isolated in
order_orchestrations): saga progress is recorded in one dedicated collection, separate from the immutableorderdocument.
Options Evaluated
Option 1 — Saga/Orchestration: one central Temporal workflow sequences every step (CHOSEN)
CheckoutSagaWorkflow (order-service’s workflow/checkout_saga_workflow.go) is the single coordinator for the entire checkout transaction. It calls ReserveInventoryActivity, then CreatePaymentOrderActivity, then blocks on a workflow.Selector waiting for either a payment_captured signal or a 15-minute timeout, then executeCreateShipment, then the best-effort consumeInventory step, explicitly deciding at each point whether to proceed or to run a compensating action (releaseInventory, refundPayment). Every transition — success or failure — is recorded via AppendStepTransitionActivity into the order_orchestrations collection’s SagaHistory array ([]SagaHistoryEntry{Step, Status, Timestamp, Metadata}), keyed by OrderID.
- Pros:
- One place holds the entire transaction’s logic and its entire history.
CheckoutSagaWorkflow’s own control flow is the full sequence — reserve, pay, ship, with every compensation branch spelled out inline — so understanding “what can happen to an order’s checkout” means reading one function, not reconstructing a sequence of independently-triggered reactions scattered across three services. This directly satisfies BR-09:order_orchestrations’SagaHistoryis a single, ordered, queryable statement of record for one order’s transaction, not an inference drawn from correlating separate event logs after the fact. - Compensation decisions are made with full context, not local guesswork. When
CreatePaymentOrderActivityfails, the workflow knows inventory was already reserved and callsreleaseInventorydirectly; when shipment creation fails after payment was already captured, it knows to call bothrefundPaymentandreleaseInventory. A choreography-style design would need each service to independently infer this context from whatever events it happens to have received so far — a strictly harder problem, and the exact one BR-04 is written against. - A late or duplicate signal has one well-defined place to reconcile against.
reconcileLatePaymentCaptureandlistenForLateShipmentConfirmationboth work by readingorder_orchestrations’CurrentStep/SagaHistoryas the single source of truth for “what state is this order’s transaction actually in” — there is no need to poll or correlate multiple services’ independent states to answer that question. - The saga’s progress is naturally streamable to the customer. Because one coordinator already knows the full step sequence,
PublishOrderStreamEventActivitycan emit exactly four well-defined progress events (payment-ready, payment-captured, shipment-created, saga-failed) at exactly the points the coordinator decides they’re meaningful — BRD-013’s BR-08 (live progress) falls out of the orchestration model directly, rather than needing a separate aggregation step to synthesize “overall progress” out of independent service events.
- One place holds the entire transaction’s logic and its entire history.
- Cons & Accepted Trade-offs:
order-servicebecomes a single point of sequencing responsibility for a transaction it doesn’t fully own the data for. The saga coordinator calls intoinventory-service/payment-service/shipment-serviceas a client of each — if the coordinator itself is unavailable, no step of the transaction can progress, by design (this is the same NFR-01 “the saga requires its own running worker” trade-off ADR-00027 already accepted).- Each participating service needs a signal/RPC surface for the coordinator to call into, rather than simply publishing its own domain events to a shared bus and being otherwise untouched —
PaymentSignalService.SignalPaymentCaptured/ShipmentSignalService.SignalShipmentCreatedexist specifically because the coordinator (not the participant) decides when a workflow should resume. - The coordinator’s own workflow-definition code is a central piece of business logic that must be kept correct — a bug in
CheckoutSagaWorkflow’s own sequencing affects every checkout, where a choreography design would at least isolate a bug to one participant’s own event-handling logic.
Option 2 — Choreography: each service reacts to the others’ published events independently
order-service would publish an OrderCreated event and have no further sequencing responsibility. inventory-service would subscribe and reserve stock, then publish InventoryReserved. payment-service would subscribe to that and capture payment, then publish PaymentCaptured. shipment-service would subscribe to that and create the shipment, publishing ShipmentCreated — and a failure at any step would need that same service to publish a *Failed event that upstream services would, in turn, subscribe to and react to by compensating their own previously-completed step.
- Pros:
- No single coordinator service is a load-bearing dependency for every checkout — each participant only needs its own Pub/Sub subscription to progress its own step.
- Each service’s own reaction logic is genuinely local and independently deployable, without touching a shared workflow definition.
- Cons (Why Rejected):
- No single place holds the transaction’s full history or current state, directly working against BR-09. Reconstructing “what happened to order X’s checkout” would mean correlating events across
inventory-service,payment-service, andshipment-service’s independent logs/event streams after the fact — there is no equivalent of a singleorder_orchestrationsdocument with one orderedSagaHistory, only whatever each service separately chose to record about its own step. - Compensation logic has to be reinvented, distributed, and kept consistent across every participant. Each service would need to know not just how to run its own step, but how to undo it, and which of the other services’ steps might already have completed by the time its own failure event arrives — exactly the context-dependent decision
CheckoutSagaWorkflowalready makes centrally in Option 1. A shipment-creation failure needing to trigger both a payment refund and an inventory release means eithershipment-servicepublishes two separate compensation-triggering events thatpayment-serviceandinventory-serviceeach subscribe to and interpret correctly, or some new coordinating logic re-emerges somewhere to decide that — which is choreography quietly re-growing an orchestrator by another name. - Cyclic/implicit coupling through the event stream. Three services each independently subscribing to one another’s events (directly or via a growing chain) is harder to reason about than one coordinator’s explicit call sequence — a new step inserted into the middle of the flow means auditing every existing subscriber’s handling logic for ordering assumptions, rather than editing one workflow function in one place.
- No natural single point to emit a customer-facing “overall progress” event from. BR-08’s live-progress requirement would need a separate aggregating service to listen to all the choreographed events and synthesize “where is this order’s checkout right now” — which is most of what the orchestrator in Option 1 already does as a side effect of coordinating the transaction, not a new cost unique to choreography, but clear evidence that this design doesn’t actually eliminate the need for something playing the orchestrator’s role — it just relocates and duplicates it.
- Reintroduces a saga coordinator role at the exact moment any end-to-end timeout or reconciliation path is needed. The payment-wait timeout, the late-signal reconciliation path (
reconcileLatePaymentCapture), and the late-duplicate-shipment-signal listener (listenForLateShipmentConfirmation) all depend on one place owning “what state is this transaction in and how long has it been there” — a purely choreographed design would need an equivalent timer/reconciliation service per transition, multiplying the same complexity Option 1 already centralizes once.
- No single place holds the transaction’s full history or current state, directly working against BR-09. Reconstructing “what happened to order X’s checkout” would mean correlating events across
Final Decision
Option 1 is selected and implemented. The checkout saga’s distributed transaction across inventory-service, payment-service, and shipment-service is coordinated by a single Temporal workflow (CheckoutSagaWorkflow), which owns the step sequence, the compensation decisions, and — via order_orchestrations’ SagaHistory — the single authoritative statement of what happened and when, satisfying BRD-013’s BR-04 and BR-09 directly. Choreography would have left the “who tracks the whole transaction” and “who decides compensation” questions open, both of which this platform’s business requirements explicitly need answered by one, queryable source.
Related Documents
- BRD-013 — Checkout Completion: Real Payment Capture and Reliable Fulfillment Handoff
- BRD-017 — Dependable, Auditable Coordination of Multi-Step Order Transactions
- SR-014 — Checkout Completion: Payment Capture & Fulfillment Handoff System Requirements
- SR-018 — Dependable, Auditable Multi-Step Order Transaction Coordination: System Requirements
- ADR-00027 — Asynchronous Saga + Webhook Relay vs. Synchronous Payment Capture for Checkout Completion
- ADR-00032 — Temporal vs. Camunda for Checkout Saga Workflow Orchestration
- ADR-00034 — Temporal SDK vs. Hand-Built Saga Coordination Code
- Architecture — Checkout Saga Orchestration Pattern & Audit Trail
- Architecture — Checkout Completion: Payment Capture and Fulfillment Handoff
- Microservices: order-service