Order consistency and data ownership
Authoritative stores, checkout price snapshotting, Redis coordination, and Ordering vs. Finance boundaries.
Purpose & Scope
This document defines data ownership, transactional outbox guarantees, checkout snapshotting, and Redis coordination rules 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 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 in the OrderingDomainv1.0.0OrderingCreates durable Orders from a buyer's current basket, locks purchase-time pricing, and owns order lifecycle transitions ...Ownercommerce-fulfillment-teamDiagramOpen docs subdomain. Use it when modifying order creation, Marten projections, Redis locks/idempotency, or cross-service checkout orchestration.
Visual Reference
The visual below illustrates how 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 isolate backing stores while coordinating via gRPC queries and Kafka messages.
Loading graph...
Ordering and Finance Data Ownership and Messaging Boundaries
Core Invariants & Design Rules
- Authoritative order state: Order DatabaseContainerv1.0.0Order DatabaseAuthoritative PostgreSQL system of record owned by the Ordering bounded context for buyers, accepted orders, purchase-ti...Ownercommerce-fulfillment-teamDiagramOpen docs (PostgreSQL) is the sole system of record for BuyerEntityv1.0.0BuyerRepresents a customer's ordering profile and delivery address within the Ordering bounded context.Ownercommerce-fulfillment-teamOpen docs, OrderEntityv1.0.0OrderDurable purchase record owned by a Buyer, capturing immutable purchase-time line items and governing order lifecycle tra...Ownercommerce-fulfillment-teamOpen docs, and Order ItemEntityv1.0.0Order ItemChild entity within an Order capturing a purchased book identifier, positive quantity, and locked checkout-time unit pri...Ownercommerce-fulfillment-teamOpen docs aggregates, Marten audit event streams (
DaemonLockId = 44444), and Wolverine outbox/inbox tables. Marten projections (OrderSummary,OrderSummaryView) are derived views and never replace theOrderaggregate. - Deterministic checkout snapshot: During
POST /api/v1/orders, 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 reads the customer’s basket via Get basket over gRPCQueryv1.0.0Get basket over gRPCReturns the current basket through the basket.v1 gRPC contract.Ownercommerce-fulfillment-teamSchemaDiagramOpen docs, resolves every distinctBookIdvia Get books over gRPCQueryv1.0.0Get books over gRPCReturns multiple Catalog books by identifier through the book.v1 gRPC contract.Ownercatalog-experience-teamSchemaDiagramOpen docs (aborting with404 Not Foundif any book is missing), locks inPriceSale ?? Priceper Order ItemEntityv1.0.0Order ItemChild entity within an Order capturing a purchased book identifier, positive quantity, and locked checkout-time unit pri...Ownercommerce-fulfillment-teamOpen docs, and persists the sum as the immutable order total. Subsequent 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 or 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 changes never rewrite accepted orders. - Strict status vs. orchestration separation: Only explicit HTTP transitions (
POST /api/v1/orders,PATCH .../complete,PATCH .../cancel) mutate an order’sStatus(New→CompletedorNew→Cancelled). 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 maintains an independent saga state in Azure Durable Task Scheduler (finance-taskhub) and never calls 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 to cancel an order. - Soft delete vs. cancellation: Handle basket deletion failedCommandv1.0.0Handle basket deletion failedReports Finance's failed basket-cleanup outcome so Order API can
soft-delete the affected Order.
Ownercommerce-fulfillment-teamSchemaDiagramOpen docs triggers soft deletion (
IsDeleted = true) to hide the order from standard queries without settingStatustoCancelled. Acknowledge basket deletion completedCommandv1.0.0Acknowledge basket deletion completedReports Finance's successful basket-cleanup outcome to Order API without changing the Order's business status. Ownercommerce-fulfillment-teamSchemaDiagramOpen docs is logged and leavesStatusasNew. - Bounded saga retries: When 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 exhausts its bounded retry budget (
MaxAttempts: 3at30mtimer intervals), it transitions its own orchestration state toCancelledand emits Send order cancelled notificationCommandv1.0.0Send order cancelled notificationShared Finance cancellation command consumed by Notification to render and submit a canceled-order email. Ownerplatform-engineering-teamSchemaDiagramOpen docs to Notification APIServicev1.0.0Notification APIInternal background worker that consumes order commands from Kafka, renders MJML email templates, and submits mail over ...SubscribesPlaceOrderCommand, CancelOrderCommand +1APIsAsyncAPIOwnerplatform-engineering-teamDiagramRepositoryOpen docs.
Never flush Redis broadly during incidents. Order Cache and Distributed LocksContainerv1.0.0Order Cache and Distributed LocksRedis-backed coordination and caching slice owned by the Ordering bounded context for buyer-scoped creation locks, HTTP ...Ownercommerce-fulfillment-teamDiagramOpen docs holds active HTTP idempotency markers ({METHOD}:{PATH}:{x-request-id}, 3600s TTL) and buyer creation locks (order-create:{userId}, 60s TTL) alongside FusionCache read entries. Broadly flushing Redis exposes concurrent checkouts to duplicate order creation.
Boundaries & Guarantees
| Concern | Strategy & Guarantee | Failure / Edge-Case Behavior | Related Resources |
|---|---|---|---|
| Persistence | order-database commits Order aggregates, Marten event streams, and Wolverine outbox messages in a single ACID transaction; order-orchestration persists saga state in finance-taskhub (no PostgreSQL). | Uncommitted writes never publish Kafka events; Marten async projections recover automatically from the authoritative event stream. | order-database, order, order-item, adr-001-postgresql-order-system-of-record, adr-001-finance-persisted-order-saga |
| Caching | order-cache provides FusionCache L1/L2 (2h fail-safe) for Catalog lookups and dashboard reads. | Safe to invalidate individual cache keys without losing order or buyer state. | order-cache, adr-002-preserve-checkout-purchase-snapshot |
| Messaging | order-api emits UserCheckedOutIntegrationEvent, OrderStatusChangedToCompleteIntegrationEvent, and OrderStatusChangedToCancelIntegrationEvent partitioned by OrderId; consumes DeleteBasketCompleteCommand and DeleteBasketFailedCommand. | Exhausted retries route to <code>bookworm.{env}.ordering.dead-letter-queue</code>; notification-api delivery never proves authoritative order status. | <code>bookworm.{env}.ordering.user-checked-out</code>, <code>bookworm.{env}.finance.delete-basket-complete</code>, <code>bookworm.{env}.finance.delete-basket-failed</code>, <code>bookworm.{env}.ordering.dead-letter-queue</code> |
| Concurrency & Idempotency | POST/PATCH endpoints require x-request-id ({METHOD}:{PATH}:{x-request-id}, 3600s TTL, returns 409 Conflict on duplicate, cleared on exception or >= 500); order-create:{userId} (60s TTL) serializes buyer writes after gRPC lookups; inbound Kafka handlers use a 24h Redis idempotency guard. | Concurrent checkout attempts for the same buyer fail fast with conflict/lock error; duplicate x-request-id does not replay a cached response body. | CreateOrder, user-checkout, adr-003-separate-order-status-from-finance-saga, adr-005-finance-separate-workflow-and-order-status |
Safe Change & Verification Checklist
- Keep Order ItemEntityv1.0.0Order ItemChild entity within an Order capturing a purchased book identifier, positive quantity, and locked checkout-time unit pri...Ownercommerce-fulfillment-teamOpen docs purchase prices (
PriceSale ?? Price) immutable after checkout; allow read-time Catalog enrichment for display titles only. - Preserve
x-request-ididempotency,order-create:{userId}buyer write locking, and24hintegration-event idempotency guards. - Keep
Order.Statustransitions (New→Completed|Cancelled), soft deletion (IsDeleted), andfinance-taskhuborchestration states strictly decoupled. - Verify Pact contracts (
Ordering-Finance,Finance-Ordering) and runmise run format,mise run build, andmise run test.
Related Resources
- 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 — Authoritative Ordering REST API and Marten/Wolverine host
- 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 — Durable Task Scheduler post-checkout saga
- Order Lifecycle and Status TransitionsFlowv1.0.0Order Lifecycle and Status TransitionsCheckout creates a New Order owned by Ordering API, Finance coordinates post-order cleanup and notifications, and explic...Ownercommerce-fulfillment-teamView flowOpen docs, 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 lifecycle flows
- ADR-001: Use PostgreSQL as the Order system of recordDecision Recordv1.0.0ADR-001: Use PostgreSQL as the Order system of recordPostgreSQL is the authoritative store for Buyer profiles and accepted Orders; Redis and read projections do not own this...Ownercommerce-fulfillment-teamOpen docs, ADR-002: Preserve the checkout-time purchase snapshotDecision Recordv1.0.0ADR-002: Preserve the checkout-time purchase snapshotEach accepted Order records the book identifiers, quantities, and prices selected at checkout so later Catalog changes d...Ownercommerce-fulfillment-teamOpen docs, ADR-003: Keep Order status separate from Finance saga stateDecision Recordv1.0.0ADR-003: Keep Order status separate from Finance saga stateOrdering owns the Order's business status, while Finance owns checkout coordination state; basket cleanup outcomes do no...Ownercommerce-fulfillment-teamOpen docs, ADR-004: Bound placement retries with scheduled saga timeoutsDecision Recordv1.0.0ADR-004: Bound placement retries with scheduled saga timeoutsFinance uses Wolverine timeout messages and a persisted counter to bound placement-command reissues, cancelling only the...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