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
QUOTEDwith margin, obtains the bindingPriceQuote, numbers the lines1..nand groups them by the quote'sgroupNo; - 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:
CheckoutCompletedfor the cart and for payments, six analytics events for the funnel and the operators.
Strategic Classification
| Axis | Verdict |
|---|---|
| Domain | Supporting subdomain. See the Core Domain Chart. |
| Business Model | Conversion (the purchase transaction). |
| Evolution | Custom-built. |
Domain Roles
| Role | Applies? | Evidence in the code |
|---|---|---|
| Execution (saga orchestration) | Yes, primary | The 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) | Yes | The deterministic Idempotency-Key <sessionId>:auth:<attempt> on AuthorizePayment, the PLACING semantic lock (ErrPlacementInDoubt) and customer-payments' one-authorization-per-session invariant. |
| Analysis | No | The cart's readiness is shopping-cart's fact; checkout only enforces it (ErrCartNotCheckoutReady). |
| Specification | No | Prices, charges and tax are pricing's specification. |
Inbound Communication
| Collaborator | Message | Type | Channel | Relationship |
|---|---|---|---|---|
Shopper via storefront-bff | OpenSession | Command | REST POST /checkout-sessions | UI |
Shopper via storefront-bff | ConfirmSession | Command | REST POST /checkout-sessions/{sessionId}/confirmations | UI |
Shopper via storefront-bff | GetSession | Query | REST GET /checkout-sessions/{sessionId} | UI |
| AI clients | get_checkout_session | Query | MCP, Streamable HTTP, cmd/mcp | read-only adapter over GetSession |
| agents | checkout_session_status | Query | A2A JSON-RPC, cmd/a2a | read-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
| Collaborator | Message | Type | Channel | Relationship |
|---|---|---|---|---|
shopping-cart | GetCart | Query | REST GET /carts/{cartId} | Customer/Supplier (we are the Customer) |
delivery-promise (network) | GetDeliveryOffer | Query | REST 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 |
pricing | IssuePriceQuote | Command | REST POST /price-quotes | Customer/Supplier (we are the Customer) |
customer-payments | AuthorizePayment | Command | REST POST /payment-authorizations (Idempotency-Key <sessionId>:auth:<attempt>, allocations per group) | Customer/Supplier (we are the Customer) |
customer-payments | VoidAuthorization | Command | REST 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) | PlaceOrder | Command | REST POST /checkout through the ACL (internal/adapters/outbound/customerordering); Idempotency-Key is the sessionId; shipToAddressId (NG1), never an inline address | Open Host Service behind an Anti-Corruption Layer; we are the Customer |
shopping-cart, customer-payments | CheckoutCompleted | Event | Kafka retailnetwork.checkout.events, com.retailnetwork.storefront.checkout.checkoutsession.CheckoutCompleted | Customer/Supplier (we are the Supplier) |
| analytics only | CheckoutOpened | Event | Kafka retailnetwork.checkout.analytics, com.retailnetwork.storefront.checkout.checkoutsession.CheckoutOpened | analytics stream |
| analytics only | CheckoutDeclined | Event | Kafka retailnetwork.checkout.analytics, com.retailnetwork.storefront.checkout.checkoutsession.CheckoutDeclined | analytics stream |
| analytics only | CheckoutRequoteRequired | Event | Kafka retailnetwork.checkout.analytics, com.retailnetwork.storefront.checkout.checkoutsession.CheckoutRequoteRequired | analytics stream |
| analytics only | CheckoutFailed | Event | Kafka retailnetwork.checkout.analytics, com.retailnetwork.storefront.checkout.checkoutsession.CheckoutFailed | analytics stream |
| analytics only | CheckoutSessionExpired | Event | Kafka retailnetwork.checkout.analytics, com.retailnetwork.storefront.checkout.checkoutsession.CheckoutSessionExpired | analytics stream |
| analytics only | CheckoutPlacementInDoubt | Event | Kafka retailnetwork.checkout.analytics, com.retailnetwork.storefront.checkout.checkoutsession.CheckoutPlacementInDoubt | analytics 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
- Money flow (D5). Authorize before placing the order; capture per
shipment group on
FulfillmentShipped; release onFulfillmentCancelled; refund onPackageLostorPackageReturned. - 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. - A decline keeps the session open for another token while the price
quote is valid; a definitive
409voids the authorization and asks for a requote; a400or422is a contract bug: void,FAILED, alert. - A
503or timeout leaves the sessionPLACING, answers202, andResolveInDoubtPlacementsreplays the stored body with the sameIdempotency-Keyuntil a definitive answer; alert at 20 h, give up and void at 22 h, before the network's 24 h idempotency window. - The cart must be ready, the offers quotable, the quote unexpired.
ErrCartNotCheckoutReadyandErrOfferNotQuotableat open,ErrPriceQuoteExpiredat confirm, andExpireOnQuoteExpiryends an open or declined session with its quote. - The authorized amount equals the quote total
(
ErrAuthorizationMismatch). - A closed session never changes (
ErrSessionClosed):COMPLETED,EXPIRED,FAILEDandREQUOTE_REQUIREDallow no transition out. - No PII. The session holds
shopperIdandshipToAddressId; the stored placement request is PII-free.
Assumptions
- The BFF mints the
Idempotency-Keyfor every write and readsGET /checkout-sessions/{sessionId}to poll aPLACINGsession after a202(REST contract description). customer-orderingreplays the first response to a repeatedIdempotency-Key(the policyResolveInDoubtPlacementssays so), and the network's idempotency window is 24 h (decision text; see Open Questions).- The network exposes
shipToAddressIdonPOST /checkout(the EXTEND NG1), and its wire names (Checkout,offer-not-quotable,requotedOffers) stay inside the ACL. customer-paymentsreturns 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
currencyandtotalMinorfrom the quote, and anamountMinorper group.
Verification Metrics
| Metric | Target (proposed) | Source |
|---|---|---|
Sessions confirmed to COMPLETED over sessions confirmed | tracked; the conversion signal | metric checkout.sessions.confirmed (outcome), CheckoutCompleted and CheckoutOpened counts |
Share of confirms ending DECLINED | tracked; alert on a spike | metric outcome declined, CheckoutDeclined |
Share of sessions ending REQUOTE_REQUIRED | low; a rise means offers expire between cart and confirm | CheckoutRequoteRequired |
FAILED sessions (contract bug) | 0; each one alerts | CheckoutFailed |
Sessions in PLACING and their age | 0 older than 20 h; alert at 20 h, before the network's 24 h window | checkout_sessions.state, updated_at |
Sessions with an authorization and no orderId after a definitive answer | 0 | authorizationId vs orderId |
| Authorization/void calls per session | one authorization key per attempt (<sessionId>:auth:<attempt>) | customer-payments metrics |
| Outbox age of the oldest unpublished checkout event | below 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:
| Hotspot | Answer 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 race | The resolver alerts at 20 h and gives up and voids at 22 h; the void is idempotent. |
| H7 Silent outcomes | CheckoutSessionExpired and CheckoutPlacementInDoubt are published (analytics). |
| H8 The network contract | Resolved: shipToAddressId, offer-not-quotable and requotedOffers are in customer-ordering's contract. |
| H9 The stored placement request | StoredPlacement{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. |