Storefront has been decoupled into micro-frontends with a dedicated commerce app and shared shell.

Read the architecture guide →

Basket consistency, enrichment, and cleanup

Engineering invariants, Redis ownership, Catalog enrichment purity, and checkout cleanup idempotency for Basket API.

Architecture

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 ID ClaimsPrincipal (customer role with basket_read / basket_write scopes), 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 BookId and a strictly positive Quantity (> 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} returns 404 Not Found; missing baskets are never masked as empty 200 OK responses.
Warning

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

ConcernStrategy & GuaranteeFailure / Edge-Case BehaviorRelated Resources
Persistencebasket-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 & EnrichmentGET /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
MessagingConsumes 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 & IdempotencyPlaceOrderCommand 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

Safe Change & Verification Checklist