**The design is not quite ready as written: the payment step can charge a customer more than once, or charge them and leave no order record.** Both are fixed by one change to steps 3–6, small enough to make today and still start building tomorrow. The module boundaries, the thin routes with an `OrderCheckout` class, and the inventory cache tradeoff are sound for this volume and I would keep them.

## What to change before building

**1. Retrying on timeout can double-charge (step 4).**
A timeout does not mean the charge failed.
- **Case:** the provider takes 6 s to process a charge and succeeds, but the service gave up at 5 s and retries.
- **What happens:** the provider charges the card a second time.
- **What should happen:** one charge, however many attempts.
- **Fix:** send an idempotency key (the order id) with every charge call, so the provider treats retries as the same charge.

**2. Rolling back can erase the order for a charge that went through (steps 3, 5, 6).**
The `PENDING` row lives only inside the open transaction, so a rollback or crash deletes it.
- **Case:** the charge succeeds, then the commit fails or the process dies. The same happens if all attempts time out but one actually landed.
- **What happens:** the customer is charged and the database has no order at all, so there is nothing to refund or reconcile from.
- **What should happen:** the order row survives, in a state that says what is known about the payment.
- **Fix:** commit the `PENDING` order first, charge outside any transaction, then record the result in a second short transaction. This also stops a database connection being held for up to 20 s during the payment call.

```mermaid
flowchart TD
    A[POST /orders] --> B[Check stock in inventory cache]
    B --> C[Insert order as PENDING and commit]
    C --> D[Charge with idempotency key = order id]
    D -->|success| E[Mark PAID and commit]
    D -->|declined| F[Mark FAILED and commit]
    D -->|still timing out after retries| G[Leave PENDING]
    E --> H[Send confirmation email]
    G --> I[Reconciliation job asks provider for charge status]
    I --> E
    I --> F
```

The reconciliation job is the one new piece: a periodic check that asks the provider what happened to orders stuck in `PENDING`.

**3. The test plan covers only the happy path.**
The defects above are all on failure paths. Add integration tests for a declined payment, a timeout followed by a successful retry (asserting one charge), and a timeout on every attempt (asserting the order stays `PENDING`).

## Two decisions to write down (not blockers)

- **Overselling:** with a cache up to 5 minutes old, two customers can occasionally buy the last unit. That is acceptable at 200–2,000 orders a day, but the design should say what happens then (refund, backorder, or manual handling).
- **Email failure:** state that the confirmation email is sent after the commit and that a failed send does not fail the order.

VERDICT: READY WITH CHANGES
