The design isn't ready to build from as written. Two parts of the payment step can charge customers wrongly. The fix is contained: it changes steps 3–6 of the flow and leaves the rest alone.

## What's solid
- **The context fits the scale.** 200 to 2,000 orders a day on one Postgres instance is reasonable, and you don't over-build for it.
- **The module boundaries are right.** Orders, payments and inventory are separate, and no module reads another module's tables. That's the hardest rule to add later, and you have it from day one.
- **The code is organized well.** Routes stay thin, the flow lives in `OrderCheckout`, and every log line carries the order id. That will make the payment problems below much easier to debug.

## What to change before building

**1. Retrying on a timeout can charge a customer twice.** A timeout doesn't mean the charge failed. It only means you didn't hear back in time.
- *Case:* attempt 1 succeeds at the provider after 5.2 s. Your client has already timed out at 5 s and retries. The customer is charged twice for one order.
- *Fix:* send an idempotency key with every charge, such as the order id. Most payment providers support this. Every retry reuses the same key, so the provider charges at most once.

**2. The charge happens inside an open database transaction.** Two things go wrong:
- *Case:* the charge succeeds, then the commit fails or the process crashes before step 5 finishes. The rollback deletes the `PENDING` row. The customer has paid, and you have no order and no record of it.
- With 3 retries at 5 s each, one request can hold a transaction and a connection for up to 20 s. That's fine at 200 orders a day, but it will hurt at 2,000.
- *Fix:* commit the `PENDING` order first, call the payment provider outside any transaction, then update the status in a second short transaction.

**3. A payment can end with an unknown result.** If every attempt times out, you don't know whether the customer paid. Add a status for that case (e.g. `PAYMENT_UNKNOWN`) and a small reconciliation job that asks the provider what happened, using the idempotency key.

**4. A double-click creates two orders.** `POST /orders` has no idempotency, so a double-click or a client retry produces two orders. Accept a client-supplied idempotency key on the endpoint.

**5. Decide what happens when you oversell.** The stock cache can be up to 5 minutes old and nothing reserves stock, so two buyers can both get the last item. Accepting that is a fair tradeoff given the 800 ms warehouse call. But write down what happens when it occurs: refund, backorder, or manual handling.

**6. Test the failure paths, not just the happy path.** Planning one integration test for the happy path won't catch any of the above. Add tests for:
- a timeout followed by a successful retry, checking the customer is charged only once
- a crash after the charge but before the status update
- every attempt timing out, which should lead to reconciliation
- a duplicate `POST /orders`

Smaller point: send the confirmation email after the commit, from a queue or outbox table. That way a slow email server can't fail or delay checkout.

## Suggested revised flow

```mermaid
flowchart TD
    A[POST /orders with idempotency key] --> B[Check inventory cache]
    B --> C[Txn 1: insert order PENDING, commit]
    C --> D[Charge payment provider<br/>idempotency key = order id<br/>retry on timeout, same key]
    D -->|success| E[Txn 2: mark PAID, queue confirmation email]
    D -->|declined| F[Txn 2: mark FAILED, return error]
    D -->|all retries timed out| G[Mark PAYMENT_UNKNOWN]
    G --> H[Reconciliation job asks provider, sets PAID or FAILED]
```

Once you've updated design.md with changes 1–4 and the failure-path tests, I'd consider it ready. Changes 5 and 6 are quick to add. This is roughly one revision of the Flow section, so it can be done before tomorrow.

VERDICT: NOT READY
