---
id: order-lifecycle
name: Order Lifecycle and Status Transitions
version: 1.0.0
summary: >-
  Checkout creates a New Order owned by Ordering API, Finance coordinates
  post-order cleanup and notifications, and explicit business operations move
  the Order to Completed or Cancelled.
owners:
  - commerce-fulfillment-team
diagrams:
  - id: order-lifecycle
    version: 1.0.0
badges:
  - content: Business Process
    backgroundColor: purple
    textColor: purple
steps:
  - id: customer
    title: Customer submits checkout
    actor:
      name: Customer
    next_step:
      id: create-order
      label: Submit basket to Ordering
  - id: create-order
    title: CreateOrder command
    message:
      id: CreateOrder
      version: 1.0.0
    next_step:
      id: order-api
      label: Validate and build New order
  - id: order-api
    title: Ordering API creates New order
    summary: >-
      Authenticates the buyer, resolves basket quantities and Catalog prices,
      and writes the New order snapshot and event stream.
    service:
      id: order-api
      version: 1.0.0
    next_steps:
      - id: order-db
        label: Persist New order and projections
      - id: finance-saga
        label: Publish checkout event to Finance
  - id: order-db
    title: Order Database stores accepted order
    summary: >-
      Stores the authoritative Order record, event-sourced summary projections,
      and transactional outbox messages.
    container:
      id: order-database
      version: 1.0.0
    next_steps:
      - id: order-complete
        label: Explicit completion transition
      - id: order-cancel
        label: Explicit cancellation transition
  - id: finance-saga
    title: Finance coordinates post-checkout work
    summary: >-
      Tracks post-checkout basket cleanup and awaits explicit Ordering status
      events while managing bounded retry timeouts.
    service:
      id: order-orchestration
      version: 1.0.0
    next_steps:
      - id: finance-complete
        label: Await order completion event
      - id: finance-cancel
        label: Await order cancellation event
  - id: order-complete
    title: Order status changed to Complete
    message:
      id: OrderStatusChangedToCompleteIntegrationEvent
      version: 1.0.0
    next_step:
      id: finance-complete
      label: Deliver via ordering.order-status-change-to-complete
  - id: order-cancel
    title: Order status changed to Cancel
    message:
      id: OrderStatusChangedToCancelIntegrationEvent
      version: 1.0.0
    next_step:
      id: finance-cancel
      label: Deliver via ordering.order-status-change-to-cancel
  - id: finance-complete
    title: Finance handles order completion
    summary: >-
      Finalizes the orchestration and emits CompleteOrderCommand to notify the
      customer.
    service:
      id: order-orchestration
      version: 1.0.0
    next_step:
      id: complete-order-command
      label: Publish CompleteOrderCommand
  - id: complete-order-command
    title: CompleteOrderCommand
    message:
      id: CompleteOrderCommand
      version: 1.0.0
    next_step:
      id: notification-complete
      label: Deliver via finance.complete-order
  - id: finance-cancel
    title: Finance handles order cancellation
    summary: >-
      Finalizes the orchestration and emits CancelOrderCommand to notify the
      customer.
    service:
      id: order-orchestration
      version: 1.0.0
    next_step:
      id: cancel-order-command
      label: Publish CancelOrderCommand
  - id: cancel-order-command
    title: CancelOrderCommand
    message:
      id: CancelOrderCommand
      version: 1.0.0
    next_step:
      id: notification-cancel
      label: Deliver via finance.cancel-order
  - id: notification-complete
    title: Notification sends completion email
    service:
      id: notification-api
      version: 1.0.0
  - id: notification-cancel
    title: Notification sends cancellation email
    service:
      id: notification-api
      version: 1.0.0
---

## Trigger & Business Outcome

This lifecycle begins when a customer submits [[command|CreateOrder]] to create a purchase record and spans every authoritative state transition until the [[entity|order]] reaches a terminal **Completed** or **Cancelled** state. Success is confirmed when [[service|order-api]] commits the terminal status in [[container|order-database]], [[service|order-orchestration]] closes its coordination workflow, and [[service|notification-api]] delivers the corresponding status email.

## Interactive Flow Visualization

<NodeGraph />

## Step-by-Step Walkthrough

<Steps title="Order Lifecycle and Downstream Coordination">
	<Step title="Accept New order in Ordering">
		[[service|order-api]] authenticates the buyer, resolves the persisted [[entity|basket]] and
		[[domain|catalog]] prices, persists the **New** [[entity|order]] in
		[[container|order-database]], and publishes [[event|UserCheckedOutIntegrationEvent]] via its
		transactional outbox.
	</Step>
	<Step title="Coordinate post-checkout work in Finance">
		[[service|order-orchestration]] consumes [[event|UserCheckedOutIntegrationEvent]], coordinates
		basket cleanup (detailed in [[flow|user-checkout]]), and remains active until an explicit
		order-status event arrives or bounded retries exhaust.
	</Step>
	<Step title="Transition to Completed or Cancelled">
		When an authorized business operation invokes [[command|CompleteOrder]] or
		[[command|CancelOrder]], [[service|order-api]] commits the irreversible terminal transition and
		publishes [[event|OrderStatusChangedToCompleteIntegrationEvent]] or
		[[event|OrderStatusChangedToCancelIntegrationEvent]].
	</Step>
	<Step title="Route status notifications">
		[[service|order-orchestration]] consumes the status event, completes its workflow to stop any
		pending timeout timers, and publishes [[command|CompleteOrderCommand]] or
		[[command|CancelOrderCommand]] to [[service|notification-api]] for customer email delivery.
	</Step>
</Steps>

## Failure, Retry & Compensation Behavior

| Failure Point                             | System Behavior                                                                                                                                                                                     | Compensation / Recovery                                                                                                                                                                                                        |
| :---------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Invalid transition on terminal order**  | <ResourceLink id="order-api" type="service">order-api</ResourceLink> rejects completion or cancellation once **Completed** or **Cancelled**                                                         | Terminal states are immutable; handle post-finalization exceptions through external compensating workflows                                                                                                                     |
| **Basket cleanup failure after checkout** | <ResourceLink id="order-orchestration" type="service">order-orchestration</ResourceLink> sends <ResourceLink id="DeleteBasketFailedCommand" type="command">DeleteBasketFailedCommand</ResourceLink> | <ResourceLink id="order-api" type="service">order-api</ResourceLink> soft-deletes the order record while preserving **New** business status                                                                                    |
| **Finance timeout exhaustion**            | <ResourceLink id="order-orchestration" type="service">order-orchestration</ResourceLink> cancels its own workflow after three attempts                                                              | Sends <ResourceLink id="CancelOrderCommand" type="command">CancelOrderCommand</ResourceLink> for email notification only; does not mutate order status in <ResourceLink id="order-api" type="service">order-api</ResourceLink> |
| **Notification delivery failure**         | <ResourceLink id="notification-api" type="service">notification-api</ResourceLink> retries with backoff, then dead-letters                                                                          | Routed to <ResourceLink id="bookworm.{env}.notification.dead-letter-queue" type="channel">`bookworm.{env}.notification.dead-letter-queue`</ResourceLink>; order status remains intact                                          |

:::warning
**[[service|order-api]] is the sole authority for order business status.**

Neither [[service|order-orchestration]] nor [[service|notification-api]] can transition an [[entity|order]] to **Completed** or **Cancelled**. Always inspect [[diagram|order-lifecycle]] when distinguishing business cancellation from technical soft deletion or orchestration timeouts.
:::

## Participating Resources

- **Domains & Systems:** [[domain|ordering]], [[domain|shopping]], [[domain|platform]], [[system|order-system]], [[system|finance-system]], [[system|notification-system]]
- **Services:** [[service|order-api]], [[service|order-orchestration]], [[service|notification-api]]
- **Messages:** [[command|CreateOrder]], [[command|CompleteOrder]], [[command|CancelOrder]], [[event|UserCheckedOutIntegrationEvent]], [[event|OrderStatusChangedToCompleteIntegrationEvent]], [[event|OrderStatusChangedToCancelIntegrationEvent]], [[command|CompleteOrderCommand]], [[command|CancelOrderCommand]]
- **Channels & Stores:** <ResourceLink id="bookworm.{env}.ordering.order-status-change-to-complete" type="channel">`bookworm.{env}.ordering.order-status-change-to-complete`</ResourceLink>, <ResourceLink id="bookworm.{env}.ordering.order-status-change-to-cancel" type="channel">`bookworm.{env}.ordering.order-status-change-to-cancel`</ResourceLink>, <ResourceLink id="bookworm.{env}.finance.complete-order" type="channel">`bookworm.{env}.finance.complete-order`</ResourceLink>, <ResourceLink id="bookworm.{env}.finance.cancel-order" type="channel">`bookworm.{env}.finance.cancel-order`</ResourceLink>, [[container|order-database]]
- **Related Views:** [[diagram|order-lifecycle]], [[flow|user-checkout]], [[flow|notification-delivery]]
