Skip to main content

Bounded Context Canvas

Following the ddd-crew Bounded Context Canvas v5. Every message row was checked against the code on this branch: the routes in internal/adapters/inbound/http, the gateways in internal/adapters/outbound and the events in internal/adapters/outbound/kafka.

Canvas at a glance​

Two pictures of the sections below, laid out like the ddd-crew canvas: first the inbound collaborators feeding this context (purpose, domain roles and the business decisions it enforces), then the outbound collaborators it commands, queries and notifies. Arrows follow the message type: solid blue commands (cmd), dotted green queries (qry), thick orange events (evt); each arrow names its channel and the messages it carries. Box shapes mark the collaborator kind: rounded = people, UI or any client; blue = sibling bounded context; red = network context. Channel names on the arrows are abbreviated; the Inbound and Outbound Communication tables carry the exact route, topic and CloudEvents type for every message.

Inbound​

Source: internal/adapters/inbound/http/server.go (the three session routes), internal/application/usecases (the roles and decisions).

Outbound​

Source: cmd/api/adapters.go (the five gateways), internal/adapters/outbound/kafka/encoder.go (the two topics and the seven events).

The diagrams omit assumptions, verification metrics, decisions taken and the ubiquitous language (sections below) and the relationship pattern per message (see the tables). The context consumes no event: everything it learns it learns from a synchronous answer.

Name​

Checkout (checkout, code CK, CloudEvents tier storefront).

Purpose​

To run the purchase saga. The context:

  • opens a session from a cart: reads the cart snapshot, pre-checks that every selected offer is still QUOTED with margin, obtains the binding PriceQuote, numbers the lines 1..n and groups them by the quote's groupNo;
  • on confirm authorizes the quote total with an allocation per group, then places the order through the Anti-Corruption Layer with the stored, PII-free request;
  • settles the three definitive failures (decline, requote, contract bug) and the one unknown (in-doubt placement) with a defined state each;
  • announces the outcome: CheckoutCompleted for the cart and for payments, six analytics events for the funnel and the operators.

Strategic Classification​

AxisVerdict
DomainSupporting subdomain. See the Core Domain Chart.
Business ModelConversion (the purchase transaction).
EvolutionCustom-built.

Domain Roles​

RoleApplies?Evidence in the code
Execution (saga orchestration)Yes, primaryThe CheckoutSession aggregate (OpenSession through ExpireSession), one record of where the purchase stands, plus the five policies.
Enforcer (no two holds on a card for one session)YesThe deterministic Idempotency-Key <sessionId>:auth:<attempt> on AuthorizePayment, the PLACING semantic lock (ErrPlacementInDoubt) and customer-payments' one-authorization-per-session invariant.
AnalysisNoThe cart's readiness is shopping-cart's fact; checkout only enforces it (ErrCartNotCheckoutReady).
SpecificationNoPrices, charges and tax are pricing's specification.

Inbound Communication​

CollaboratorMessageTypeChannelRelationship
Shopper via storefront-bffOpenSessionCommandREST POST /checkout-sessionsUI
Shopper via storefront-bffConfirmSessionCommandREST POST /checkout-sessions/{sessionId}/confirmationsUI
Shopper via storefront-bffGetSessionQueryREST GET /checkout-sessions/{sessionId}UI
AI clientsget_checkout_sessionQueryMCP, Streamable HTTP, cmd/mcpread-only adapter over GetSession
agentscheckout_session_statusQueryA2A JSON-RPC, cmd/a2aread-only adapter over GetSession

Route-to-command note: the three routes map onto OpenSession, ConfirmSession and GetSession. The other commands of the aggregate (RecordAuthorization, RecordDecline, RecordPlacementInDoubt, RecordPlaced, RecordRequoteRequired, RecordFailure, ExpireSession, VoidCompleted, MarkInDoubtAlerted, PurgePlacement) have no inbound route: they are the outcomes the saga records on itself, from the answers of its outbound calls and from the five policies. GetSession is also served over MCP (get_checkout_session) and A2A (checkout_session_status).

Outbound Communication​

CollaboratorMessageTypeChannelRelationship
shopping-cartGetCartQueryREST GET /carts/{cartId}Customer/Supplier (we are the Customer)
delivery-promise (network)GetDeliveryOfferQueryREST GET /delivery-offers/{offerId} (at open: pre-check that every selected offer is still QUOTED, with a 2-minute margin)Open Host Service; we are the Customer
pricingIssuePriceQuoteCommandREST POST /price-quotesCustomer/Supplier (we are the Customer)
customer-paymentsAuthorizePaymentCommandREST POST /payment-authorizations (Idempotency-Key <sessionId>:auth:<attempt>, allocations per group)Customer/Supplier (we are the Customer)
customer-paymentsVoidAuthorizationCommandREST POST /payment-authorizations/{authorizationId}/voids (Idempotency-Key <sessionId>:void; after a requote, a rejection, a mismatching authorization or the 22 h give-up)Customer/Supplier (we are the Customer)
customer-ordering (network)PlaceOrderCommandREST POST /checkout through the ACL (internal/adapters/outbound/customerordering); Idempotency-Key is the sessionId; shipToAddressId (NG1), never an inline addressOpen Host Service behind an Anti-Corruption Layer; we are the Customer
shopping-cart, customer-paymentsCheckoutCompletedEventKafka retailnetwork.checkout.events, com.retailnetwork.storefront.checkout.checkoutsession.CheckoutCompletedCustomer/Supplier (we are the Supplier)
analytics onlyCheckoutOpenedEventKafka retailnetwork.checkout.analytics, com.retailnetwork.storefront.checkout.checkoutsession.CheckoutOpenedanalytics stream
analytics onlyCheckoutDeclinedEventKafka retailnetwork.checkout.analytics, com.retailnetwork.storefront.checkout.checkoutsession.CheckoutDeclinedanalytics stream
analytics onlyCheckoutRequoteRequiredEventKafka retailnetwork.checkout.analytics, com.retailnetwork.storefront.checkout.checkoutsession.CheckoutRequoteRequiredanalytics stream
analytics onlyCheckoutFailedEventKafka retailnetwork.checkout.analytics, com.retailnetwork.storefront.checkout.checkoutsession.CheckoutFailedanalytics stream
analytics onlyCheckoutSessionExpiredEventKafka retailnetwork.checkout.analytics, com.retailnetwork.storefront.checkout.checkoutsession.CheckoutSessionExpiredanalytics stream
analytics onlyCheckoutPlacementInDoubtEventKafka retailnetwork.checkout.analytics, com.retailnetwork.storefront.checkout.checkoutsession.CheckoutPlacementInDoubtanalytics stream

What the neighbours do with them: the cart closes on CheckoutCompleted (CloseOnCheckoutCompleted); customer-payments binds the order to the session's authorization on it (BindOrderOnCheckoutCompleted). Both consume it from their own consumer group (shopping-cart-checkout, customer-payments-checkout in warehouse-infra helm-values). Relationship evidence: Context Map.

Ubiquitous Language​

Full glossary: Ubiquitous Language. Top terms: Checkout Session, Place-Order Step (the network's "Checkout"), In-Doubt Placement, Requote, Allocation.

Business Decisions​

  1. Money flow (D5). Authorize before placing the order; capture per shipment group on FulfillmentShipped; release on FulfillmentCancelled; refund on PackageLost or PackageReturned.
  2. The network's "Checkout" is the place-order step, reached through an Anti-Corruption Layer in internal/adapters/outbound/customerordering, the only place that knows network wire names.
  3. A decline keeps the session open for another token while the price quote is valid; a definitive 409 voids the authorization and asks for a requote; a 400 or 422 is a contract bug: void, FAILED, alert.
  4. A 503 or timeout leaves the session PLACING, answers 202, and ResolveInDoubtPlacements replays the stored body with the same Idempotency-Key until a definitive answer; alert at 20 h, give up and void at 22 h, before the network's 24 h idempotency window.
  5. The cart must be ready, the offers quotable, the quote unexpired. ErrCartNotCheckoutReady and ErrOfferNotQuotable at open, ErrPriceQuoteExpired at confirm, and ExpireOnQuoteExpiry ends an open or declined session with its quote.
  6. The authorized amount equals the quote total (ErrAuthorizationMismatch).
  7. A closed session never changes (ErrSessionClosed): COMPLETED, EXPIRED, FAILED and REQUOTE_REQUIRED allow no transition out.
  8. No PII. The session holds shopperId and shipToAddressId; the stored placement request is PII-free.

Assumptions​

  • The BFF mints the Idempotency-Key for every write and reads GET /checkout-sessions/{sessionId} to poll a PLACING session after a 202 (REST contract description).
  • customer-ordering replays the first response to a repeated Idempotency-Key (the policy ResolveInDoubtPlacements says so), and the network's idempotency window is 24 h (decision text; see Open Questions).
  • The network exposes shipToAddressId on POST /checkout (the EXTEND NG1), and its wire names (Checkout, offer-not-quotable, requotedOffers) stay inside the ACL.
  • customer-payments returns a decline as a definitive answer and a successful void as a definitive answer; the session records both.
  • Every POST route is idempotent on Idempotency-Key (global to the service, 409 on reuse); every published event leaves through the transactional outbox.
  • One configured currency everywhere; the session records currency and totalMinor from the quote, and an amountMinor per group.

Verification Metrics​

MetricTarget (proposed)Source
Sessions confirmed to COMPLETED over sessions confirmedtracked; the conversion signalmetric checkout.sessions.confirmed (outcome), CheckoutCompleted and CheckoutOpened counts
Share of confirms ending DECLINEDtracked; alert on a spikemetric outcome declined, CheckoutDeclined
Share of sessions ending REQUOTE_REQUIREDlow; a rise means offers expire between cart and confirmCheckoutRequoteRequired
FAILED sessions (contract bug)0; each one alertsCheckoutFailed
Sessions in PLACING and their age0 older than 20 h; alert at 20 h, before the network's 24 h windowcheckout_sessions.state, updated_at
Sessions with an authorization and no orderId after a definitive answer0authorizationId vs orderId
Authorization/void calls per sessionone authorization key per attempt (<sessionId>:auth:<attempt>)customer-payments metrics
Outbox age of the oldest unpublished checkout eventbelow 5 s (no metric or alert exists; query outbox_events)outbox_events.created_at where published_at IS NULL

Decisions taken since the design model, and what stays open​

The design model left ten hotspots (H1 to H10). The code settles most of them:

HotspotAnswer in the code
H1 Where does DECLINED go when the quote expires?ExpireSession accepts OPEN and DECLINED; both go to EXPIRED (ExpireOnQuoteExpiry).
H2 What key does the second authorize use?<sessionId>:auth:<attempt>; the attempt grows each time a DECLINED session is confirmed again, and a stuck call re-uses the same attempt.
H3 What if an offer is no longer quotable?offer-not-quotable (422) at open, no state change. The code does not repeat the check at confirm: after an offer expired between open and confirm the answer comes from customer-ordering as a requote.
H4 What ends AUTHORIZING if the outcome is unknown?ResolveStuckAuthorizations after 2 minutes, re-calling with the same key.
H5 What does a failed void do?The debt stays on the session (void_authorization_id) and RetryOwedVoids retries every minute.
H6 The resolver and the 24 h void raceThe resolver alerts at 20 h and gives up and voids at 22 h; the void is idempotent.
H7 Silent outcomesCheckoutSessionExpired and CheckoutPlacementInDoubt are published (analytics).
H8 The network contractResolved: shipToAddressId, offer-not-quotable and requotedOffers are in customer-ordering's contract.
H9 The stored placement requestStoredPlacement{RequestBody, RequestHash, PlacingSince}, dropped 24 h after a closed state by PurgeStoredPlacements.
H10 How does the cart take the requoted offers?Not verifiable from this repository: the session only carries requotedOffers; whether the BFF writes them into the cart is outside this code.