---
title: Checkout and Order Coordination
summary: Checkout creation and asynchronous basket and email coordination.
owners:
  - commerce-fulfillment-team
badges:
  - content: Runtime Scenario
    backgroundColor: purple
    textColor: purple
---

Checkout converts a mutable basket into an authoritative purchase-time order, then delegates basket cleanup and email delivery to asynchronous coordination. The synchronous portion establishes the order before the customer receives the order identifier.

## Purpose & Trigger

The flow creates an order with immutable item and price snapshots while keeping external cleanup outside the ordering transaction. It starts when an authenticated customer submits a checkout request.

## Visual References

_Checkout and Order Coordination_

<MermaidFileLoader file="mermaids/001-checkout-and-order-coordination-diagram-1.mmd" />

## Step-by-Step Walkthrough

1. Commerce sends the checkout request through API Gateway, including the caller's idempotency identity.
2. Ordering API synchronously reads current basket quantities from Basket API and authoritative book and price data from Catalog API.
3. Ordering API records the order and purchase-time snapshots, commits the state, and returns the order identifier. This synchronous response does not mean basket cleanup or email delivery has completed.
4. Ordering API publishes a checkout fact asynchronously. Finance starts a workflow correlated by the order identifier.
5. Finance publishes basket cleanup and email commands independently. Basket API and Notification consume the commands in separate paths.
6. Basket API deletes the basket and reports success or failure asynchronously.
7. Notification applies idempotency and submits the email independently of basket cleanup.
8. Finance records the basket outcome and reconciles the workflow. A timeout or repeated failure triggers bounded compensation rather than a distributed transaction.

## Error Handling & Edge Cases

- Repeated checkout requests use the same idempotency identity and must not create a second order.
- Basket or catalog read failures leave checkout uncommitted and allow a caller retry.
- Kafka retries may duplicate downstream commands; basket deletion and email delivery must remain repeatable safely.
- A missing basket outcome is bounded by a workflow timeout and retry limit.
- Timeout compensation may notify the customer, but it does not by itself change the authoritative order status.

## Quality & Consistency Notes

- Checkout latency depends on basket and catalog reads, plus the synchronous order commit; slow email delivery is outside this critical path.
- The order preserves purchase-time prices and remains independent of later catalog changes.
- Basket cleanup, email delivery, and workflow completion are eventually consistent with the committed order.
