---
id: order-system
name: Order System
version: 1.0.0
summary: |
  Internal system that creates and manages accepted customer Orders, preserving
  purchase-time items and prices while owning the Order business lifecycle.
scope: internal
owners:
  - commerce-fulfillment-team
services:
  - id: order-api
    version: 1.0.0
flows:
  - id: user-checkout
    version: 1.0.0
containers:
  - id: order-database
    version: 1.0.0
  - id: order-cache
    version: 1.0.0
relationships:
  - id: cart-system
    version: 1.0.0
    label: reads the current customer basket during checkout
  - id: product-catalog-system
    version: 1.0.0
    label: resolves books and their current prices during checkout
  - id: identity-provider
    version: 1.0.0
    label: verifies customer identity for protected order and buyer requests
actors:
  - id: customer
    name: Customer
    label: creates and views their Orders
    direction: inbound
entities:
  - id: order
    version: 1.0.0
  - id: buyer
    version: 1.0.0
  - id: order-item
    version: 1.0.0
diagrams:
  - id: order-lifecycle
    version: 1.0.0
badges:
  - content: Internal
    backgroundColor: gray
    textColor: gray
    icon: LockClosedIcon
---

## System Purpose & Boundary

The Order System owns accepted customer purchases, [[entity|buyer]] profiles, and the authoritative [[entity|order]] lifecycle (`New`, `Completed`, `Cancelled`) within the [[domain|ordering]] domain. It serves **Customers** placing and tracking orders and **Administrators** managing fulfillment status and viewing backoffice dashboards. Mutable shopping baskets ([[domain|shopping]]), live product catalog pricing ([[domain|catalog]]), payment settlement, and post-checkout orchestration ([[system|finance-system]]) are explicitly out of scope.

:::note
At checkout, the Order System snapshots book quantities and active prices onto [[entity|order-item]] records so future catalog edits never alter accepted orders. Soft deletion is separated from business status: failed basket cleanup soft-deletes the order record for auditability without changing its business status.
:::

## Contained Capabilities

| Service / Agent        | Role in System                                                                                                    | Primary Data Store                                        | Interaction Style (Sync / Async) |
| :--------------------- | :---------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------- | :------------------------------- |
| [[service\|order-api]] | Exposes authenticated HTTP endpoints and SSE dashboards, snapshots checkout items, and publishes lifecycle events | [[container\|order-database]], [[container\|order-cache]] | Sync (HTTP/gRPC) & Async (Kafka) |

## External Interactions & Trust Boundaries

- **Customer & admin entry points:** Authenticated requests enter via the API Gateway with [[system|identity-provider]] JWT validation, per-user rate limiting, and required idempotency keys on state-changing order operations.
- **Checkout enrichment:** During order creation, [[service|order-api]] synchronously queries [[system|cart-system]] for the customer's basket and [[system|product-catalog-system]] for authoritative prices over internal gRPC.
- **Post-checkout coordination:** Publishes [[event|UserCheckedOutIntegrationEvent]], [[event|OrderStatusChangedToCompleteIntegrationEvent]], and [[event|OrderStatusChangedToCancelIntegrationEvent]] to [[system|finance-system]] over Kafka, and consumes basket-cleanup outcomes back from Finance.

<Accordion title="Concurrency & Idempotency Notes">
	- **Buyer write locks & idempotency:** Distributed locks and short-lived idempotency markers in
	[[container|order-cache]] prevent duplicate checkouts and concurrent buyer mutations. -
	**Event-sourced audit trail:** Order domain events append to an event stream in
	[[container|order-database]] to support order history and summary views.
</Accordion>

## System Visualizations

### System Context

<ContextDiagram />

### Component Topology

<NodeGraph />

### Architecture Decisions

<ADRTable />

## Related Documentation

- [[diagram|order-lifecycle]] — Permitted order status transitions and saga separation.
- [[flow|user-checkout]] — End-to-end checkout flow.
- [[doc|domains/bookworm/subdomains/ordering/engineering/01-order-consistency-and-data-ownership]] — Ordering consistency and ownership boundaries.
- [[doc|domains/bookworm/subdomains/ordering/guides/01-create-and-manage-orders]] — Guide for order creation and lifecycle management.
