ADR-00025 — Cached Checkout-Session Snapshot vs. Recompute at Order Creation
- Status: Approved / Implemented
- Date: 2026-10-02
- Authors: Engineering Team
Context
By the time a customer places an order, shop-service’s checkout flow has already resolved everything needed to charge them correctly: per-item pricing and tax, the chosen shipment tier and its fee, applicable cash-on-delivery charges, rounding, and the grand total — all of it already shown to the customer on the checkout screen. order-service needs that same information to create the order record, build the fulfillment-saga input, and compute the payment amount. The choice is whether order creation treats the checkout screen’s quote as merely advisory and re-derives price/tax/shipping fresh from the same downstream services checkout used, or whether it reuses the already-resolved aggregate verbatim.
Decision Drivers (FRs & NFRs)
See SR-012 for the full requirement list.
- BR-03 (BRD-011): the amount a customer is charged must exactly match the amount they reviewed at checkout, with no silent recalculation in between.
- BR-06 (BRD-011): a customer must be able to re-quote (change payment method/courier) without restarting checkout.
- FR-07 through FR-12 (SR-012): full-aggregate checkout-session caching, a single scoped update exception for re-quoting, and verbatim price-summary reuse at order-creation time.
Options Evaluated
Option 1 — Cache the full resolved checkout aggregate; order creation reuses it verbatim (CHOSEN)
shop-service caches everything it resolves for a checkout read — addresses (as references), order items, tax summary, warehouse, weight, shipment tiers, allowed payment methods, and the computed price summary — into a short-lived checkout_session record keyed by a freshly minted token. order-service resolves that session exactly once by token, maps it into a single in-memory snapshot, and builds the persisted order, the fulfillment-saga input, and the payment amount all from that one snapshot — copying the price summary’s fields verbatim rather than recalculating any of them.
- Pros:
- Guarantees the charge matches the quote. Because the price summary is copied field-for-field from what the customer already reviewed, there is no window in which a pricing/tax/shipping rule could change or be computed slightly differently between the checkout screen and the actual charge — directly satisfying BR-03. This mirrors the owning service’s own stated rationale: re-deriving free-delivery thresholds, cash-on-delivery surcharges, or rounding a second time in
order-servicewould risk that second implementation drifting out of sync withshop-service’s, silently showing the customer one total while charging another. - Avoids repeating four to five downstream calls on the hot order-creation path. Re-fetching pricing from
inventory-service, re-quoting shipment fromshipment-service, and re-reading payment methods frompayment-servicewould all be redundant — that information was already resolved, seconds or minutes earlier, by the same checkout flow. - One mapped snapshot, reused for everything that needs it. Mapping the cached session into a domain snapshot exactly once, then reusing that single value for the persisted order, the PII-address-resolution inputs, and the fulfillment-saga input, keeps order-creation’s own logic simple and avoids re-deriving the same values separately per destination.
- A re-quote (BR-06) stays cheap. Because the cache already holds everything except the parts that genuinely can change with payment method (addresses, shipment tiers), a re-quote only needs to re-resolve those two things live and can reuse the rest — order items, tax, and warehouse — from the same cached record, rather than re-running the entire checkout resolution.
- Guarantees the charge matches the quote. Because the price summary is copied field-for-field from what the customer already reviewed, there is no window in which a pricing/tax/shipping rule could change or be computed slightly differently between the checkout screen and the actual charge — directly satisfying BR-03. This mirrors the owning service’s own stated rationale: re-deriving free-delivery thresholds, cash-on-delivery surcharges, or rounding a second time in
- Cons & Accepted Trade-offs:
- The cached snapshot can become stale within its lifetime. If an underlying price or tax rule changed in the short window between quoting and placing the order, the cached figure would not reflect that change — accepted because the window is short and bounded (1 hour) and because the alternative (always recomputing) reintroduces the quote/charge mismatch risk BR-03 exists to prevent.
- A second service now depends on the cache being reachable and valid.
order-servicecannot create an order from a token it cannot resolve — an expired or unknown token is treated as a validation error, not a silent fallback to recomputing from scratch. - Realizing this cache today means a flagged, temporary direct cross-service database read (
order-servicereadingshop-service’scheckout_sessioncollection via its own already-injected database connection, rather than a dedicated API) rather than a formal, long-term cache service — an accepted, explicitly temporary trade-off adopted specifically to avoid standing up dedicated caching infrastructure this early; it is not re-adjudicated by this ADR and is tracked separately (see Related Documents).
Option 2 — Treat the checkout quote as advisory; recompute price, tax, and shipping fresh at order-creation time
Order creation re-calls the same downstream services checkout used — re-fetch per-item pricing and tax from inventory-service, re-quote shipment from shipment-service, re-check allowed payment methods from payment-service — and recomputes the price summary itself at the moment the order is placed, treating whatever checkout displayed as a preview only.
- Pros:
- Always reflects the absolute latest pricing/tax/shipping rules, with no staleness window at all, however short.
- Removes the dependency on the checkout-session cache being reachable or still valid at order-creation time.
- Cons (Why Rejected For This Stage):
- Duplicates free-delivery-threshold, cash-on-delivery-surcharge, and rounding logic in a second place. Two independent implementations of the same business rules can drift apart over time even without anyone intending it to — exactly the risk BR-03 is meant to prevent, and the owning service’s own documented concern for not building this path.
- Directly risks showing the customer one total and charging another if the two implementations ever disagree, even momentarily, which is a worse customer-trust outcome than a narrow staleness window within a short cache lifetime.
- Adds four to five more downstream calls to the hot order-creation path for information that was already resolved and shown to the customer seconds or minutes earlier, with no corresponding business benefit in the common case where nothing changed in between.
- Makes
order-serviceresponsible for business rules it doesn’t own — free-delivery thresholds, surcharge rules, and rounding areshop-service’s checkout logic; duplicating them intoorder-servicespreads ownership of the same rule across two services. - With no server-held session to resolve by token, the client becomes the only place order-creation’s inputs can come from. Without a cached aggregate,
order-servicehas nothing to look up — the resolved items, addresses, shipment tier, payment method, and price summary would have to be sent down to the client at checkout and sent back up again unchanged when the order is placed. That couples three codebases to the exact same payload shape instead of one: the mobile/admin client (to carry every field down and back),shop-service(to produce it), andorder-service(to accept and trust it) all have to change together every time a field is added or removed — a new surcharge type or address attribute becomes a three-repo change instead of a change insideshop-service’s cache alone.
Final Decision
Option 1 is selected and implemented. order-service resolves the cached checkout_session exactly once per order creation and reuses its price summary, order items, tax summary, and warehouse information verbatim — satisfying BRD-011’s BR-03 and BR-06, and SR-012’s FR-07 through FR-12.
This decision is revisited, not fixed. If the cache’s staleness window is ever found to cause a real customer-facing price mismatch, the time-to-live should be shortened or a freshness re-check introduced before charging; separately, the direct-database-read mechanism behind the cache is already flagged as temporary and intended to migrate to a dedicated cache service once that infrastructure exists (see Technical Debt — Reusable Checkout Orchestration Gaps) — that migration would not change this ADR’s underlying decision to reuse a cached snapshot rather than recompute.
Related Documents
- BRD-011 — Reusable Product-to-Order Journey With Trustworthy Totals
- SR-012 — Reusable Checkout Orchestration: System Requirements
- ADR-00024 — Shared Checkout-Info Resolution vs. Per-Screen Enrichment
- Architecture: Reusable Product-to-Order Orchestration
- Architecture — Checkout Completion: Payment Capture and Fulfillment Handoff — detailed payment-capture flow downstream of this decision
- Architecture — Multi-Courier Fulfillment via Shiprocket — detailed shipment/courier flow downstream of this decision
- Technical Debt — Reusable Checkout Orchestration Gaps
- Microservices: shop-service, order-service, pii-service