---
title: Understand Order and Finance status
summary: Distinguish the Order's business status from Finance's checkout saga, basket cleanup, and notification outcomes.
version: 1.0.0
type: guides
order: 2
badges:
  - content: Guide
    backgroundColor: teal
    textColor: teal
---

**Audience & Outcome:** This guide is for support engineers, operators, and backend developers debugging post-checkout state. You will learn how [[service|order-api]] commercial status differs from [[service|order-orchestration]] workflow state and how to interpret cross-service outcomes.

BookWorm separates every checkout into two independent state machines: [[service|order-api]] owns the authoritative commercial status of an [[entity|order]] in [[container|order-database]], while [[service|order-orchestration]] coordinates post-checkout basket cleanup and notification commands using Azure Functions and Azure Durable Task Scheduler.

:::warning
Never infer an order's business status from basket contents, [[service|order-orchestration]] state, or delivered emails.
:::

## Context and motivation

After a customer submits checkout, three asynchronous activities occur outside the original HTTP request: clearing the customer's shopping basket, tracking retry timers if cleanup stalls, and sending lifecycle emails. When a cleanup command fails, a retry timer expires, or a customer receives a cancellation email, support engineers can mistake those operational signals for changes to the commercial order record.

Keeping Ordering's domain model strictly isolated from Finance's workflow engine prevents transient infrastructure failures or retry exhaustion from corrupting commercial order records.

## How it works

[[service|order-api]] publishes [[event|UserCheckedOutIntegrationEvent]] when an order is created, triggering [[service|order-orchestration]]. From that point onward, the two services maintain independent state stores and communicate exclusively over Kafka.

The visual below shows how [[service|order-api]], [[service|order-orchestration]], [[service|basket-api]], and [[service|notification-api]] exchange events and commands across separate state boundaries.

<MermaidFileLoader file="mermaids/02-understand-order-and-finance-status-diagram-1.mmd" />

### Two independent state models

| Dimension           | [[service\|order-api]] ([[container\|order-database]])           | [[service\|order-orchestration]] (Durable Task Scheduler)            |
| :------------------ | :--------------------------------------------------------------- | :------------------------------------------------------------------- |
| **Authority**       | Authoritative commercial order status and purchase snapshot      | Post-checkout workflow coordination and compensation only            |
| **Status values**   | `New`, `Completed`, `Cancelled` (plus separate soft-delete flag) | `Placed`, `Completed`, `Cancelled`, `BasketDeletionFailed`, `Failed` |
| **Persisted store** | PostgreSQL via EF Core + Marten event store                      | Azure Durable Task Scheduler (`finance-taskhub`)                     |
| **How to inspect**  | Orders REST endpoints (`GET /api/v1/orders/{id}`)                | Durable Task orchestration custom status                             |

### Interpreting cross-service outcomes

- **Basket deletion succeeds:** [[service|basket-api]] publishes [[event|BasketDeletedCompleteIntegrationEvent]]. [[service|order-orchestration]] records completion and sends [[command|DeleteBasketCompleteCommand]] to [[service|order-api]], which logs the event and leaves the order status `New`.
- **Basket deletion fails:** [[service|basket-api]] publishes [[event|BasketDeletedFailedIntegrationEvent]]. [[service|order-orchestration]] marks its orchestration `BasketDeletionFailed` and sends [[command|DeleteBasketFailedCommand]] to [[service|order-api]], which soft-deletes the matching order without changing `Status` to `Cancelled`.
- **Finance retry timers expire:** If an open orchestration exhausts its configured retry window (`30m` timeout, `3` attempts), [[service|order-orchestration]] marks its own state `Cancelled` and publishes [[command|CancelOrderCommand]] to [[service|notification-api]]. It never cancels the commercial order in [[service|order-api]], so Ordering can still report `New`.
- **Explicit order completion or cancellation:** When [[service|order-api]] accepts a completion or cancellation request, it publishes [[event|OrderStatusChangedToCompleteIntegrationEvent]] or [[event|OrderStatusChangedToCancelIntegrationEvent]]. [[service|order-orchestration]] transitions accordingly and publishes [[command|CompleteOrderCommand]] or [[command|CancelOrderCommand]].
- **Customer email sent or missing:** [[service|notification-api]] is a stateless delivery worker. Sending or skipping an email never proves or alters an order's business status.

<AccordionGroup>
<Accordion title="Design trade-offs and alternatives considered">

| Decision                                               | Benefits                                                                                    | Costs and limits                                                                        |
| :----------------------------------------------------- | :------------------------------------------------------------------------------------------ | :-------------------------------------------------------------------------------------- |
| **Independent Durable Functions orchestration**        | Isolates long-running timers, retries, and compensations from [[container\|order-database]] | Finance orchestration status can diverge from Ordering `Status` after retry exhaustion  |
| **Soft deletion on explicit basket-cleanup failure**   | Removes broken checkouts from active listings without recording a false cancellation        | Operators must inspect both Ordering visibility and Finance status for the full picture |
| **Bounded retry window (`3` attempts, `30m` timeout)** | Prevents orphaned orchestrations from running indefinitely                                  | Transient outages longer than the retry window require operational investigation        |

**Rejected alternatives:**

- **Letting Finance mutate Ordering `Status` on timeout:** Infrastructure timeout exhaustion is not an explicit commercial cancellation.
- **Persisting Finance saga state in PostgreSQL:** Durable Task Scheduler natively manages durable timers and replay-safe orchestration history for Azure Functions.

</Accordion>
</AccordionGroup>

## Related documentation

- [[flow|order-lifecycle]] — Order status transitions and downstream event propagation.
- [[adr|adr-005-finance-separate-workflow-and-order-status]] — Why Finance workflow outcomes stay separate from Order status.
- [[doc|arc42]] — System-wide architecture overview.
