Skip to main content

Aggregate Design Canvas

Released at v0.1.4, applied to the k3s cluster

Derived from model/model.yaml. The checkout service is built on develop (IQVO/checkout at 51e0379, checked 2026-12-02), released at v0.1.4 and applied to the k3s cluster: the api and the A2A agent are deployed, the MCP server is registered in warehouse-infra and switched off. Every Err... name, REST route and CloudEvents type of this context named on this page exists in the service; where the built service differs from the model's design, the page says so (As built) or the context's Service and operations section lists it.

Following the ddd-crew Aggregate Design Canvas v1.1. The model has one aggregate root in this context, CheckoutSession, and no read models (read_models: []). Go packages as built: internal/domain/checkoutsession (plus shared); the design named internal/domain/session.

CheckoutSession​

1. Name​

CheckoutSession (checkoutsession.CheckoutSession), identified by sessionId.

2. Description​

The purchase transaction from review to placed order. It holds the cart id and version, the shopperId, the shipToAddressId (never the address), the numbered lines and groups, the priceQuoteId, the totals and quoteExpiresAt, the authorizationId, the stored placement request, the orderId, the requotedOffers, a failure code, authAttempt (starts at 0, incremented on each DECLINED → AUTHORIZING) and voidOwed (the authorizationId, set in the same transaction as the decision to void). Value objects:

Value objectFieldsNote
SessionLinelineNo, catalogItemId, quantityThe session numbers the cart's lines 1..n when it opens (gap S1).
SessionGroupgroupNo, offerId, tier, lineNos[]Groups follow the quote's groupNo; the REST contract adds amountMinor, the share of the authorization (the Allocation).
RequotedOfferofferId, groupNo, tier, deliverByEarliest, deliverByLatest, expiresAtOne offer the network returned in a definitive 409; present only in REQUOTE_REQUIRED.
StoredPlacementrequestBody, requestHash, placingSinceThe PII-free placement request replayed byte for byte; placingSince drives the 20 h alert; purged 24 h after a terminal state.

The stored placement request is the StoredPlacement value object, part of the aggregate's state: the PII-free body the Anti-Corruption Layer sends to customer-ordering, kept so that ResolveInDoubtPlacements can re-send it byte for byte with the same Idempotency-Key (hotspot H9, resolved, on EventStorming).

3. State Transitions​

Derived from: model.yaml → contexts[checkout].aggregates[CheckoutSession].states, .transitions, .commands, .policies.

The entry arrow [*] --> OPEN is the creating command OpenSession. Four states are terminal: COMPLETED, EXPIRED, REQUOTE_REQUIRED and FAILED (ErrSessionClosed). PLACING is the semantic lock (no void and no new attempt while the place-order outcome is unknown) and DECLINED accepts another token while the price quote is valid (also after an authorization mismatch, with the void owed: a new confirm is refused with void-pending until the void succeeds). The only loops are DECLINED → AUTHORIZING (a new token) and PLACING → PLACING (an in-doubt outcome that stays in doubt). DECLINED → EXPIRED (ExpireSession) is a modelled transition, as ExpireOnQuoteExpiry says (hotspot H1, resolved). A session stuck in AUTHORIZING is settled by ResolveStuckAuthorizations, not by a state of its own.

4. Enforced Invariants​

InvariantEnforced by
The cart's checkout readiness holds at session openOpenSession → ErrCartNotCheckoutReady
The price quote is unexpired at confirmConfirmSession → ErrPriceQuoteExpired (422 price-quote-expired)
No transition out of COMPLETED, EXPIRED, FAILED or REQUOTE_REQUIREDall commands → ErrSessionClosed
Every selected offer is still QUOTED and expires more than 2 minutes from now at open; no state change, the BFF refreshes the cart quote (the check is not repeated at confirm; REQUOTE_REQUIRED stays a PLACING-time 409 only)OpenSession → ErrOfferNotQuotable (422 offer-not-quotable)
The authorized amount and currency equal the quote's; otherwise the session goes back to DECLINED with the void owedRecordAuthorization → ErrAuthorizationMismatch (409 authorization-mismatch)
A new confirm is refused while a void is still owedConfirmSession → ErrVoidPending (409 void-pending)
No void and no new attempt while the place-order outcome is unknown (the semantic lock)ConfirmSession and the void step in PLACING → ErrPlacementInDoubt

Derived from: model.yaml → contexts[checkout].aggregates[CheckoutSession].invariants. The mapping of an invariant to the command that raises it is read from the REST contract (409 on open: cart-not-checkout-ready; 422 on open: offer-not-quotable; 409 on confirm: session-closed, authorization-mismatch, placement-in-doubt, void-pending, illegal-transition; 422 on confirm: price-quote-expired, validation-failed) and from the invariant text; the model itself pairs rule and error but names no command.

5. Corrective Policies​

PolicyOwnerRuleEffect on this aggregate
ResolveInDoubtPlacementsthis contextRe-send the stored placement body with the same Idempotency-Key (customer-ordering replays the first response) with backoff until a definitive answer; alert at 20 h (from placingSince); give up and void at 22 h; customer-payments VoidUnboundAuthorizations is the 24 h backstop.A PLACING session reaches COMPLETED (RecordPlaced), REQUOTE_REQUIRED (RecordRequoteRequired) or FAILED (RecordFailure), or stays PLACING (RecordPlacementInDoubt).
ResolveStuckAuthorizationsthis contextA session in AUTHORIZING for more than 2 minutes re-calls AuthorizePayment with the same key, which is idempotent and yields the true outcome; customer-payments' 24 h void stays the backstop.AUTHORIZING reaches PLACING (RecordAuthorization) or DECLINED (RecordDecline).
RetryOwedVoidsthis contextEvery minute, until success, void the authorization named by voidOwed (covers ErrAuthorizationMismatch and every definitive-rejection void); Void is idempotent.Clears voidOwed; no state change.
ExpireOnQuoteExpirythis contextAn OPEN or DECLINED session expires with its price quote.OPEN → EXPIRED and DECLINED → EXPIRED (ExpireSession).
Idempotent writesthis contextEvery write route takes an Idempotency-Key; a repeated key returns the stored response of the first call.A repeated ConfirmSession with the same key does not authorize twice.
Deterministic downstream keysthis context<sessionId>:auth:<authAttempt> on authorize (a new attempt after a decline, the same key for a stuck call), <sessionId>:void on void, the sessionId on place-order.No two holds on a card for one session; a replayed place-order is answered with the first response.

6. Handled Commands​

CommandTriggerTransition
OpenSessionShopper via BFF, REST POST /checkout-sessions (reads the cart, pre-checks offers, issues the PriceQuote)[*] → OPEN
ConfirmSessionShopper via BFF, REST POST /checkout-sessions/{sessionId}/confirmationsOPEN → AUTHORIZING; DECLINED → AUTHORIZING (increments authAttempt)
RecordAuthorizationthe answer to AuthorizePayment (authorized)AUTHORIZING → PLACING
RecordDeclinethe answer to AuthorizePayment (declined)AUTHORIZING → DECLINED
RecordPlacementInDoubtPlaceOrder timed out or answered 503; also each unsuccessful pass of ResolveInDoubtPlacementsPLACING → PLACING (raises CheckoutPlacementInDoubt on the first pass only)
RecordPlacedPlaceOrder succeeded (first call or replay)PLACING → COMPLETED
RecordRequoteRequiredPlaceOrder answered a definitive 409 with re-quoted offers, sets voidOwedPLACING → REQUOTE_REQUIRED
RecordFailurePlaceOrder answered 422 (a contract bug); sets voidOwedPLACING → FAILED
ExpireSessionthe ExpireOnQuoteExpiry policy (clock, quote expiry)OPEN → EXPIRED; DECLINED → EXPIRED

GetSession (REST GET /checkout-sessions/{sessionId}) is a query and changes nothing. The seven Record... and Expire commands have no inbound route; they are applied by the use cases that make the outbound call.

7. Created Events​

EventRaised whenFull CloudEvents type
CheckoutOpenedOpenSession is savedcom.retailnetwork.storefront.checkout.checkoutsession.CheckoutOpened
CheckoutDeclinedRecordDecline is savedcom.retailnetwork.storefront.checkout.checkoutsession.CheckoutDeclined
CheckoutCompletedRecordPlaced is savedcom.retailnetwork.storefront.checkout.checkoutsession.CheckoutCompleted
CheckoutRequoteRequiredRecordRequoteRequired is savedcom.retailnetwork.storefront.checkout.checkoutsession.CheckoutRequoteRequired
CheckoutFailedRecordFailure is savedcom.retailnetwork.storefront.checkout.checkoutsession.CheckoutFailed
CheckoutSessionExpiredExpireSession is savedcom.retailnetwork.storefront.checkout.checkoutsession.CheckoutSessionExpired
CheckoutPlacementInDoubtRecordPlacementInDoubt is savedcom.retailnetwork.storefront.checkout.checkoutsession.CheckoutPlacementInDoubt

CheckoutCompleted goes to retailnetwork.checkout.events (the cart and customer-payments consume it); the other six are analytics-only (topic retailnetwork.checkout.analytics). ConfirmSession and RecordAuthorization raise nothing: CheckoutCompleted already covers the outcome (hotspot H7, resolved). The pairing of event to command is read from the event names and data; the model lists the events on the aggregate without naming the raising command. Events leave through the transactional outbox in the same transaction as the save.

8. Throughput​

Estimate. The model says "medium: one session per purchase attempt". Contention is per session: a double click or a polling BFF meets the same version column, and the Idempotency-Key makes a retry harmless.

9. Size​

Estimate. The model says "one row per session; placement request retained for the idempotency window". One root row with its lines, groups and requoted offers; the stored placement request is the one field that is deliberately kept for the network's idempotency window and then no longer needed: StoredPlacement is purged 24 h after a terminal state (hotspot H9, resolved).

Read models​

The model lists none for this context. Checkout takes the cart, the offers, the quote and the authorization by synchronous call at the moment it needs them, and reads no event.