The structure is solid and most of the design can be built tomorrow. The payment step (steps 3 to 6) needs a rewrite first, because as written it can charge customers twice, or charge them and then lose their order. These are well-known fixes and should take hours, not days.

## What's already good
- **Context is stated up front.** Current and expected volume, team size and database setup let a reader judge every tradeoff.
- **The stale-cache tradeoff is explicit.** The 800 ms warehouse call against a 5-minute stale cache is written down with a reason.
- **Module boundaries are clean.** No module reads another's tables, routes stay thin, and the flow lives in `OrderCheckout`.
- **Every log line carries the order id**, which will matter a lot when debugging payments.

## Must fix before building the payment step

**1. Retrying the charge after a timeout can charge the customer twice.**
A timeout doesn't mean the charge failed. It means you don't know. Here is the failing case:
- The provider takes the money at 4.9 s, but its reply arrives after your 5 s limit.
- You retry, and the provider charges a second time.
- The customer pays twice for one order. The expected result is one charge.

Fix: send an idempotency key (for example the order id) with every charge attempt. Most payment providers support this, so a retry returns the original result instead of charging again.

**2. The charge happens inside an open database transaction, so a failure after the charge erases the order.**
The failing case:
- The charge succeeds, then the commit fails (or the process crashes, or every retry times out).
- The transaction rolls back and the `PENDING` row disappears.
- The customer has paid, but you have no record of the order. The expected result is an order record you can reconcile against the payment.

A smaller cost: a single checkout can hold a transaction open for up to 20 s (4 attempts × 5 s).

Fix: commit the `PENDING` order in its own transaction *before* calling the provider. Then update the order to `PAID` or `FAILED` in a second transaction. Right now the `PENDING` state is never visible to anyone, because it only exists inside the uncommitted transaction.

**3. No state for "we don't know whether the charge went through."**
After the last retry times out, the order should be marked `PAYMENT_UNKNOWN` (or similar), not rolled back. Something then has to resolve it: either the provider's webhook or a periodic job that asks the provider for the charge status.

```mermaid
flowchart TD
  A[POST /orders + client idempotency key] --> B[Check inventory cache]
  B --> C[Insert order PENDING, commit]
  C --> D[Charge with idempotency key = order id]
  D -->|success| E[Mark PAID, commit] --> F[Send email]
  D -->|declined| G[Mark FAILED, commit] --> H[Return error]
  D -->|timeout after retries| I[Mark PAYMENT_UNKNOWN] --> J[Webhook or reconcile job resolves]
```

## Should add (can be done while building)
- **Client-side duplicates.** If the client retries `POST /orders` (double-click, mobile network drop), you get two orders. Accept a client idempotency key on that request too.
- **Overselling.** Stock is checked against a cache that can be 5 minutes old, and the flow never reserves or decrements stock. The design should say what happens when you sell something that is out of stock: cancel and refund, backorder, or something else. At 2,000 orders a day this will happen.
- **Email failure.** Decide whether a failed confirmation email is retried (for example through a queue or outbox table) or only logged.
- **Tests beyond the happy path.** Add integration tests for a timeout followed by a successful retry (exactly one charge), a declined card, a timeout on every retry (ends in `PAYMENT_UNKNOWN`), and a commit failure after a successful charge. This matches your tests-first standard and is where the real risk sits.

## Suggested plan for tomorrow
Start on the modules, routes, inventory cache and logging, since all of that is fine as designed. Before writing the `OrderCheckout` payment code, update steps 3 to 6 in the doc to match the diagram above.

VERDICT: READY WITH CHANGES
