The design is close: the module boundaries, the thin routes, and accepting the 5-minute inventory cache are right for a team of four at 200 to 2,000 orders a day. The payment steps (3 to 6), though, can charge a customer twice or charge them and lose the order, so those need to change before you write the payment code.

## Must fix before building

**1. Retrying a timed-out charge can charge the customer twice.**
A timeout does not mean the charge failed, only that you did not hear back.
- **Case:** the provider takes 6 s to process a $50 charge, so the service times out at 5 s and retries.
- **What happens:** the retry succeeds too, and the customer is charged $100.
- **Expected:** one $50 charge.
- **Fix:** send an idempotency key (the order id) with every charge attempt, so the provider treats retries as the same charge.

**2. Rolling back on failure can leave a customer charged with no order.**
The `PENDING` row lives inside an open transaction, so it is never visible to anyone and disappears on rollback or crash.
- **Case:** all four attempts time out, but the provider actually processed the first one. Step 6 rolls back.
- **What happens:** the customer is charged $50 and the database has no trace of the order. The same happens if the service crashes between the charge and the commit.
- **Expected:** a record that shows a charge was attempted, so it can be completed or refunded.
- **Fix:** commit the `PENDING` order first, charge outside any transaction, then update the status in a second short transaction. Add a small job that checks orders stuck in `PENDING` against the provider.

This also stops a database connection being held open for up to 20 s while the provider is slow.

```mermaid
flowchart TD
    A[POST /orders] --> B[Check stock against inventory cache]
    B --> C[Insert order as PENDING and commit]
    C --> D[Charge with order id as idempotency key]
    D -->|success| E[Mark PAID, commit, send email]
    D -->|declined| F[Mark FAILED, return error]
    D -->|timeout after retries| G[Leave PENDING, return 'payment being confirmed']
    G --> H[Reconciliation job asks provider, then marks PAID or FAILED]
```

## Decide and write down
These do not block starting; each needs a sentence or two in the doc.

- **Failure-path tests.** The plan has one integration test, for the happy path. Add integration tests for timeout-then-success, decline, and crash after charge, since those are the paths that cost money.
- **Double-submitted checkout.** If the client retries `POST /orders` (double click, flaky network), you get two orders and two charges. A client-supplied idempotency key on the request closes this.
- **Overselling.** The flow never reserves or decrements stock, so two orders inside the same 5-minute window can both buy the last unit. This is fine at your volume, but say what happens when it occurs (refund, backorder).
- **Confirmation email failure.** State that a failed email is retried or logged and does not fail the order.

You can start tomorrow on the modules, routes and inventory check as designed, as long as the payment flow is updated in the doc first.

VERDICT: READY WITH CHANGES
