ADR-00027 — Asynchronous Saga + Webhook Relay vs. Synchronous Payment Capture for Checkout Completion

By Engineering Team•October 5, 2026•6 min read
  • Status: Approved / Implemented
  • Date: 2026-10-05
  • Authors: Engineering Team

Context

BRD-015 requires that a customer’s payment be genuinely, verifiably collected before an order is treated as paid (BR-01), and BRD-013 requires that nothing is left stuck if payment collection fails (BR-04), and that the customer can watch progress in real time (BR-08). Completing a Razorpay payment is not instantaneous from the backend’s point of view — the customer leaves the app’s own request/response cycle entirely to interact with Razorpay’s hosted checkout UI, and Razorpay’s own confirmation of success arrives later, out-of-band, as a webhook. The question this ADR settles is how order-service’s order-creation step and payment-service’s Razorpay integration should be sequenced around that gap: block the original request until payment is confirmed, or schedule the fulfillment work and let a webhook resume it asynchronously.

Decision Drivers (FRs & NFRs)

See SR-014 and SR-016 for the full requirement list.

  • FR-01 (SR-014 — Order Creation Schedules, Never Executes, the Saga): order creation MUST schedule a CheckoutSagaWorkflow, never perform inventory/payment/shipment steps synchronously itself.
  • FR-01 (SR-016 — Real Payment-Provider Order Creation): the saga’s payment step MUST create a real Razorpay order, never treat a selected payment method as an already-completed charge.
  • FR-02 (SR-016 — Signature-Verified Webhook Before Any Action): a webhook delivery MUST have its signature verified before any event it carries is acted upon.
  • FR-03 (SR-016 — Captured-Only Saga Relay): only a verified “payment captured” event is relayed into the running saga today.
  • NFR-01 (SR-014 — Saga Execution Requires Its Own Running Worker): the saga is only “in progress” once its dedicated worker process is confirmed running.

Options Evaluated

Option 1 — Asynchronous Temporal saga, resumed by a signature-verified webhook relay (CHOSEN)

Order creation starts a CheckoutSagaWorkflow and returns immediately. A dedicated Temporal worker (a separate cmd/worker binary, per order-service) executes the workflow’s activities: reserve inventory, call payment-service’s CreatePaymentOrder to create a real Razorpay order, then block in a workflow.Selector waiting on either a payment_captured signal or a 15-minute timer (checkout_saga_workflow.go:19,76-84,108-124). Razorpay’s own webhook delivery — HMAC-signature-verified before anything is persisted (FR-04) — is what actually resumes the workflow, via a gRPC call into PaymentSignalService.SignalPaymentCaptured.

  • Pros:
    • The order-creation HTTP/gRPC request stays fast and bounded, regardless of how long the customer takes to complete Razorpay’s checkout UI — a step that can legitimately take anywhere from seconds to several minutes and is entirely outside the backend’s control. FR-01 depends directly on this.
    • Durable execution survives a worker restart. Temporal persists the workflow’s state between activities; a worker crash mid-saga does not lose track of which step an order was on, unlike an in-memory synchronous call chain that would simply be gone if the serving process died while waiting.
    • Compensation is a natural extension of the same workflow function, not a bolted-on afterthought — CreatePaymentOrderActivity failing, or the payment-wait step timing out, both run releaseInventory before failing the saga (checkout_saga_workflow.go:61-65,77-84), directly satisfying BR-04.
    • A late webhook is still resolvable to a correct outcome. Because the saga’s own state (order_orchestrations) persists past the saga’s own completion, a SignalPaymentCaptured call that arrives after the 15-minute timeout has already compensated the original workflow doesn’t get silently dropped — it falls through to a dedicated LatePaymentReconciliationWorkflow that re-checks stock and either resumes fulfillment or refunds (BRD-015 BR-02). This reconciliation path is a direct structural consequence of choosing an asynchronous, signal-driven design — a synchronous design would have nothing left running to signal.
  • Cons & Accepted Trade-offs:
    • Added operational surface. A Temporal cluster and a separate always-running worker process are now load-bearing infrastructure for every checkout — NFR-01 exists specifically because “scheduled but the worker isn’t running” is a real, distinct failure mode this design introduces that a synchronous design would not have.
    • A definitively failed payment is not relayed any faster than a payment that simply never resolves. Because only the captured-event path signals the saga (SR-016 FR-03), a Razorpay payment.failed webhook does nothing to shorten the wait — the saga still sits on its full 15-minute timer before compensating, even though the outcome was already known the moment the webhook arrived. This is the most significant accepted gap in this design, tracked as TD-01.
    • Retry semantics need their own idempotency story. Temporal’s at-least-once activity execution means CreatePaymentOrderActivity can run more than once for the same order; nothing in payment-service today prevents a retry from creating a second real Razorpay order, tracked as TD-02.

Option 2 — Synchronous confirm-and-block order creation

The order-creation request itself would call Razorpay to create an order, then hold the connection open — polling Razorpay or waiting on some in-process signal — until the customer completes payment or a timeout is hit, only returning a response once the outcome is known.

  • Pros:
    • Conceptually simpler for a single request/response read: no separate workflow engine, no worker process, no signal RPCs — the caller just gets a final answer on the same connection it started with.
    • No distinct “scheduled but not yet executed” state to reason about — the request either finishes or fails outright.
  • Cons (Why Rejected):
    • Blocks a request/connection for an unbounded, customer-controlled duration. Razorpay checkout completion is a human-paced step; holding an HTTP connection (or a gRPC call) open for however long a customer takes to pay is a direct availability risk under load — every concurrent checkout would pin a connection and a goroutine/thread for the full duration.
    • No durable execution. If the serving process restarted while a request was blocked waiting on payment, the in-flight checkout’s state would simply be lost, with no persisted record of which step it reached — Temporal’s workflow-history persistence has no synchronous equivalent without building an equivalent durability layer from scratch.
    • Compensation becomes bespoke per failure path rather than falling out of one workflow function’s control flow — synchronous code has no built-in analogue to Temporal’s activity retry policy or workflow-history replay.
    • Directly violates FR-01’s explicit requirement that order creation schedule, never execute, the saga’s steps.

Final Decision

Option 1 is selected and implemented. Order creation always schedules a CheckoutSagaWorkflow and returns immediately; payment capture is confirmed asynchronously by a signature-verified Razorpay webhook relaying into the running saga via PaymentSignalService.SignalPaymentCaptured, with a 15-minute timeout as the saga’s own backstop if no capture signal ever arrives. A dedicated LatePaymentReconciliationWorkflow additionally resolves a webhook that arrives after that timeout has already fired, so a captured payment is never left unresolved even on the failure path’s own timeline.

This decision is not cost-free — it requires order-service’s dedicated worker process to be running at all times (NFR-01), and it accepts, for now, that a definitively failed payment resolves no faster than one that simply times out (SR-016 FR-03’s explicit scope line). Both trade-offs are tracked, not silently absorbed — see Technical Debt — Checkout Completion Payment Flow Gaps.