Basket consistency, enrichment, and cleanup
Engineering invariants, Redis ownership, Catalog enrichment purity, and checkout cleanup idempotency for Basket API.
Purpose & Scope
This document defines the data ownership, consistency model, read-time enrichment rules, and asynchronous checkout cleanup guarantees for Basket APIServicev1.0.0Basket APIInternal HTTP and gRPC service for managing customer-scoped shopping baskets, Catalog price enrichment, and post-checkou...PublishesGetBookGrpc, GetBooksGrpc +2SubscribesCreateBasket, UpdateBasket +4APIsOpenAPI, AsyncAPIOwnercommerce-fulfillment-teamDiagramRepositoryOpen docs in the ShoppingDomainv1.0.0ShoppingCoordinates the customer basket and pre-purchase checkout intent, from selecting books through handing an accepted purch...Ownercommerce-fulfillment-teamDiagramOpen docs subdomain. Use it when modifying basket endpoints, gRPC contracts, Redis persistence, or post-checkout Kafka handlers.
Visual Reference
The visual below shows how Basket APIServicev1.0.0Basket APIInternal HTTP and gRPC service for managing customer-scoped shopping baskets, Catalog price enrichment, and post-checkou...PublishesGetBookGrpc, GetBooksGrpc +2SubscribesCreateBasket, UpdateBasket +4APIsOpenAPI, AsyncAPIOwnercommerce-fulfillment-teamDiagramRepositoryOpen docs interacts with Basket DatabaseContainerv1.0.0Basket DatabaseAuthoritative Redis key-value store owned by the Shopping bounded context for customer-scoped pre-checkout shopping bask...Ownercommerce-fulfillment-teamDiagramOpen docs, Catalog APIServicev1.0.0Catalog APIInternal HTTP and gRPC service for Catalog product management, hybrid discovery, and authoritative book metadata. PublishesBookUpdatedRatingFailedIntegrationEventSubscribesCreatePublisher, UpdatePublisher +24APIsOpenAPI, AsyncAPIOwnercatalog-experience-teamDiagramRepositoryOpen docs, Order APIServicev1.0.0Order APIAuthenticated Ordering service for Buyer profiles and the Order lifecycle, creating Orders from baskets, snapshotting pr...PublishesGetBasketGrpc, GetBookGrpc +5SubscribesCreateOrder, CompleteOrder +11APIsOpenAPI, AsyncAPI, Carrier Service LevelsOwnercommerce-fulfillment-teamDiagramRepositoryOpen docs, and Order OrchestrationServicev1.0.0Order OrchestrationMessage-driven Finance workflow service that coordinates post-checkout basket cleanup and order notifications using Dura...PublishesPlaceOrderCommand, DeleteBasketCompleteCommand +3SubscribesUserCheckedOutIntegrationEvent, OrderStatusChangedToCompleteIntegrationEvent +3APIsAsyncAPIOwnercommerce-fulfillment-teamDiagramRepositoryOpen docs.
Loading graph...
Basket Persistence, Enrichment, and Checkout Cleanup Boundaries
Core Invariants & Design Rules
- Customer-scoped identity: Basket APIServicev1.0.0Basket APIInternal HTTP and gRPC service for managing customer-scoped shopping baskets,
Catalog price enrichment, and post-checkou...PublishesGetBookGrpc, GetBooksGrpc +2SubscribesCreateBasket, UpdateBasket +4APIsOpenAPI, AsyncAPIOwnercommerce-fulfillment-teamDiagramRepositoryOpen docs derives the basket key (
basket:{userId}) strictly from the authenticated Microsoft Entra IDClaimsPrincipal(customerrole withbasket_read/basket_writescopes), never from caller-supplied route or body identifiers. - Transient pre-order intent: BasketEntityv1.0.0BasketCustomer-scoped, mutable pre-order collection of requested books and quantities managed prior to checkout.Ownercommerce-fulfillment-teamOpen docs and Basket ItemEntityv1.0.0Basket ItemChild entry within a Basket pairing a Catalog book identifier with a positive requested quantity.Ownercommerce-fulfillment-teamOpen docs records represent mutable pre-order customer intent only; they are out of scope for order totals, payments, or fulfillment.
- No persisted prices or titles: Basket DatabaseContainerv1.0.0Basket DatabaseAuthoritative Redis key-value store owned by the Shopping bounded context for customer-scoped pre-checkout shopping bask...Ownercommerce-fulfillment-teamDiagramOpen docs stores only
BookIdand a strictly positiveQuantity(> 0). Live titles, regular prices, and sale prices are never persisted in Redis. - Full-set replacement semantics: Updating a basket replaces the entire item collection atomically rather than merging individual items, and requires at least one item.
- Explicit missing-basket semantics: Reading, updating, or deleting an absent
basket:{userId}returns404 Not Found; missing baskets are never masked as empty200 OKresponses.
Read-time enrichment must remain pure. During GET /api/v1/baskets, if Catalog APIServicev1.0.0Catalog APIInternal HTTP and gRPC service for Catalog product management, hybrid
discovery, and authoritative book metadata.
PublishesBookUpdatedRatingFailedIntegrationEventSubscribesCreatePublisher, UpdatePublisher +24APIsOpenAPI, AsyncAPIOwnercatalog-experience-teamDiagramRepositoryOpen docs has no record for a stored BookId, Basket APIServicev1.0.0Basket APIInternal HTTP and gRPC service for managing customer-scoped shopping baskets,
Catalog price enrichment, and post-checkou...PublishesGetBookGrpc, GetBooksGrpc +2SubscribesCreateBasket, UpdateBasket +4APIsOpenAPI, AsyncAPIOwnercommerce-fulfillment-teamDiagramRepositoryOpen docs must preserve the stored Basket ItemEntityv1.0.0Basket ItemChild entry within a Basket pairing a Catalog book identifier with a positive requested quantity.Ownercommerce-fulfillment-teamOpen docs and omit unavailable display fields—never invent prices or mutate Basket DatabaseContainerv1.0.0Basket DatabaseAuthoritative Redis key-value store owned by the Shopping bounded context for customer-scoped pre-checkout shopping bask...Ownercommerce-fulfillment-teamDiagramOpen docs during a read.
Boundaries & Guarantees
| Concern | Strategy & Guarantee | Failure / Edge-Case Behavior | Related Resources |
|---|---|---|---|
| Persistence | basket-database (Redis) is the sole authoritative store (basket:{userId}, camelCase JSON); no relational database is used. | Missing keys return 404 Not Found on HTTP reads/writes and empty/absent responses over gRPC without auto-creating state. | basket-database, basket, basket-item, adr-001-redis-authoritative-basket-store |
| Caching & Enrichment | GET /api/v1/baskets resolves distinct BookId values on demand via GetBooksGrpc on catalog-api; basket-database also backs FusionCache. | Unavailable Catalog fields are omitted gracefully on read; order-api snapshots prices independently at checkout via GetBasketGrpc. | GetBasket, GetBasketGrpc, GetBooksGrpc, adr-004-catalog-enrichment-at-read-time |
| Messaging | Consumes PlaceOrderCommand partitioned by OrderId and emits BasketDeletedCompleteIntegrationEvent or BasketDeletedFailedIntegrationEvent to order-orchestration. | Missing basket on cleanup emits BasketDeletedFailedIntegrationEvent (signals cleanup failure only, never order/payment failure); unhandled exceptions exhaust Wolverine retries (50ms / 250ms / 1s with jitter) and route to <code>bookworm.{env}.basket.dead-letter-queue</code>. | PlaceOrderCommand, BasketDeletedCompleteIntegrationEvent, BasketDeletedFailedIntegrationEvent, <code>bookworm.{env}.basket.dead-letter-queue</code>, adr-005-explicit-checkout-cleanup-outcomes |
| Concurrency & Idempotency | PlaceOrderCommand handling is guarded by a 24h Redis integration-event idempotency guard keyed by OrderId; all HTTP routes enforce PerUserRateLimit. | Duplicate OrderId deliveries within 24h immediately re-emit BasketDeletedCompleteIntegrationEvent without touching Redis; exceptions release the OrderId guard so retries can execute cleanly. | basket-api, order-orchestration, user-checkout |
Once Order APIServicev1.0.0Order APIAuthenticated Ordering service for Buyer profiles and the Order lifecycle, creating Orders from baskets, snapshotting pr...PublishesGetBasketGrpc, GetBookGrpc +5SubscribesCreateOrder, CompleteOrder +11APIsOpenAPI, AsyncAPI, Carrier Service LevelsOwnercommerce-fulfillment-teamDiagramRepositoryOpen docs commits an order, Order OrchestrationServicev1.0.0Order OrchestrationMessage-driven Finance workflow service that coordinates post-checkout basket cleanup and order notifications using Dura...PublishesPlaceOrderCommand, DeleteBasketCompleteCommand +3SubscribesUserCheckedOutIntegrationEvent, OrderStatusChangedToCompleteIntegrationEvent +3APIsAsyncAPIOwnercommerce-fulfillment-teamDiagramRepositoryOpen docs issues Place orderCommandv1.0.0Place orderShared Finance order-placement command consumed by Notification to render and submit a new-order email. Ownerplatform-engineering-teamSchemaDiagramOpen docs asynchronously to clean up the customer’s basket. If the basket was already deleted or expired, Basket APIServicev1.0.0Basket APIInternal HTTP and gRPC service for managing customer-scoped shopping baskets, Catalog price enrichment, and post-checkou...PublishesGetBookGrpc, GetBooksGrpc +2SubscribesCreateBasket, UpdateBasket +4APIsOpenAPI, AsyncAPIOwnercommerce-fulfillment-teamDiagramRepositoryOpen docs emits Basket deletion failedEventv1.0.0Basket deletion failedIndicates that Basket could not delete the submitted basket during checkout cleanup. Ownercommerce-fulfillment-teamSchemaDiagramOpen docs so the saga can record the cleanup outcome without rolling back an already-accepted order.
Returning false from basket deletion (key absent) is a deterministic business outcome that
emits Basket deletion failedEventv1.0.0Basket deletion failedIndicates that Basket could not delete the submitted basket during checkout
cleanup.
Ownercommerce-fulfillment-teamSchemaDiagramOpen docs. Throwing a transient infrastructure
exception (e.g., Redis timeout) releases the 24h OrderId idempotency guard so Wolverine
retries or DLQ replay can re-attempt deletion.
Safe Change & Verification Checklist
- Keep customer identity derived exclusively from Entra ID claims and preserve
basket:{userId}key isolation andcustomerauthorization policies. - Preserve full-set replacement semantics on Update basketCommandv1.0.0Update basketReplaces a basket's item collection with the supplied items.Ownercommerce-fulfillment-teamSchemaDiagramOpen docs and non-empty, positive-quantity validation on Create basketCommandv1.0.0Create basketCreates a basket containing the supplied item identifiers and quantities.Ownercommerce-fulfillment-teamSchemaDiagramOpen docs and Update basketCommandv1.0.0Update basketReplaces a basket's item collection with the supplied items.Ownercommerce-fulfillment-teamSchemaDiagramOpen docs.
- Verify Get basket over gRPCQueryv1.0.0Get basket over gRPCReturns the current basket through the basket.v1 gRPC contract.Ownercommerce-fulfillment-teamSchemaDiagramOpen docs remains backward-compatible for Order APIServicev1.0.0Order APIAuthenticated Ordering service for Buyer profiles and the Order lifecycle, creating Orders from baskets, snapshotting pr...PublishesGetBasketGrpc, GetBookGrpc +5SubscribesCreateOrder, CompleteOrder +11APIsOpenAPI, AsyncAPI, Carrier Service LevelsOwnercommerce-fulfillment-teamDiagramRepositoryOpen docs and Get books over gRPCQueryv1.0.0Get books over gRPCReturns multiple Catalog books by identifier through the book.v1 gRPC contract.Ownercatalog-experience-teamSchemaDiagramOpen docs degradation never mutates Redis on read.
- Test both Basket deletion completedEventv1.0.0Basket deletion completedIndicates that Basket successfully deleted the submitted basket during
checkout cleanup.
Ownercommerce-fulfillment-teamSchemaDiagramOpen docs and Basket deletion failedEventv1.0.0Basket deletion failedIndicates that Basket could not delete the submitted basket during checkout
cleanup.
Ownercommerce-fulfillment-teamSchemaDiagramOpen docs outcomes, plus
OrderIdidempotency guard release on exception. - Run
mise run format,mise run build, andmise run testto verify Basket unit tests and Pact contracts (Basket-Finance,Finance-Basket).
Related Resources
- Basket APIServicev1.0.0Basket APIInternal HTTP and gRPC service for managing customer-scoped shopping baskets, Catalog price enrichment, and post-checkou...PublishesGetBookGrpc, GetBooksGrpc +2SubscribesCreateBasket, UpdateBasket +4APIsOpenAPI, AsyncAPIOwnercommerce-fulfillment-teamDiagramRepositoryOpen docs — Authoritative Shopping basket service
- Create basketCommandv1.0.0Create basketCreates a basket containing the supplied item identifiers and quantities.Ownercommerce-fulfillment-teamSchemaDiagramOpen docs, Update basketCommandv1.0.0Update basketReplaces a basket's item collection with the supplied items.Ownercommerce-fulfillment-teamSchemaDiagramOpen docs, Delete basketCommandv1.0.0Delete basketDeletes the current basket.Ownercommerce-fulfillment-teamSchemaDiagramOpen docs, Get basketQueryv1.0.0Get basketReturns the current basket and its item details.Ownercommerce-fulfillment-teamSchemaDiagramOpen docs, Get basket over gRPCQueryv1.0.0Get basket over gRPCReturns the current basket through the basket.v1 gRPC contract.Ownercommerce-fulfillment-teamSchemaDiagramOpen docs — Basket commands and queries
- Place orderCommandv1.0.0Place orderShared Finance order-placement command consumed by Notification to render and submit a new-order email. Ownerplatform-engineering-teamSchemaDiagramOpen docs, Basket deletion completedEventv1.0.0Basket deletion completedIndicates that Basket successfully deleted the submitted basket during checkout cleanup. Ownercommerce-fulfillment-teamSchemaDiagramOpen docs, Basket deletion failedEventv1.0.0Basket deletion failedIndicates that Basket could not delete the submitted basket during checkout cleanup. Ownercommerce-fulfillment-teamSchemaDiagramOpen docs — Checkout cleanup contracts
- User CheckoutFlowv1.0.0User CheckoutAn authenticated customer checks out a persisted basket through Ordering API; Finance coordinates asynchronous basket cl...Ownercommerce-fulfillment-teamView flowOpen docs — End-to-end checkout and basket cleanup flow
- ADR-001: Use Redis as the authoritative basket storeDecision Recordv1.0.0ADR-001: Use Redis as the authoritative basket storeRedis is the authoritative store for active customer baskets, while accepted orders and Catalog data remain owned by the...Ownercommerce-fulfillment-teamOpen docs, ADR-002: Scope each basket to the authenticated customerDecision Recordv1.0.0ADR-002: Scope each basket to the authenticated customerEach customer has an independently addressed pre-order basket, and the Cart System does not expose a shared cart or own ...Ownercommerce-fulfillment-teamOpen docs, ADR-003: Replace the basket item collection on updateDecision Recordv1.0.0ADR-003: Replace the basket item collection on updateBasket updates replace the complete item collection, with validation enforcing non-empty baskets and positive quantities...Ownercommerce-fulfillment-teamOpen docs, ADR-004: Enrich basket items from Catalog at read timeDecision Recordv1.0.0ADR-004: Enrich basket items from Catalog at read timeBasket persistence stores book references and quantities, while current book presentation data is resolved from Catalog ...Ownercommerce-fulfillment-teamOpen docs, ADR-005: Publish explicit basket cleanup outcomesDecision Recordv1.0.0ADR-005: Publish explicit basket cleanup outcomesCheckout basket deletion publishes distinct completion and failure integration events so downstream workflows can recove...Ownercommerce-fulfillment-teamOpen docs
- API and contracts indexCustom DocAPI and contracts indexConsolidated index of BookWorm HTTP v1, gRPC, AG-UI, MCP, A2A, and Kafka/Wolverine contracts grouped by service with aut...Ownerplatform-engineering-teamOpen doc — Consolidated HTTP, gRPC, and Kafka contracts