The design is sound in structure and right-sized for your scale, but the payment step as written can charge a customer more than once and can take money without leaving any order record. Both are fixed by reworking steps 3–6, which is an hour of design editing, not a rethink.

## Fix before building

**1. Retrying a timed-out charge can charge the customer again.**
A timeout means "no answer", not "charge failed".
- **Case:** the provider processes the charge in 6 s, the service gives up at 5 s and retries, and the retry also succeeds.
- **Result:** the customer is charged twice for one order.
- **Expected:** one charge.
- **Fix:** send an idempotency key (the order id) with every charge call, so the provider treats retries as the same charge.

**2. A rollback after an unclear payment result erases the order.**
The `PENDING` row lives only inside the open transaction, so a rollback or crash removes it.
- **Case:** all attempts time out, but one actually went through at the provider. Step 6 rolls back.
- **Result:** the customer is charged, the database has no order, and there is nothing to refund against or investigate.
- **Expected:** an order row that records the unresolved payment.
- **Fix:** commit the `PENDING` order first, call the provider outside any transaction, then record `PAID` or `FAILED` in a second short transaction. A small periodic job asks the provider about orders stuck in `PENDING`.

This also stops each checkout holding a database connection open for up to 20 seconds while the provider is slow.

```mermaid
flowchart TD
    A[POST /orders] --> B[Check stock in inventory cache]
    B --> C[Insert order as PENDING and commit]
    C --> D[Charge via payment provider, order id as idempotency key]
    D -->|success| E[Mark PAID, commit, send email]
    D -->|declined| F[Mark FAILED, commit, return error]
    D -->|timeouts exhausted| G[Leave PENDING, return 'payment unconfirmed']
    G --> H[Periodic job checks provider, sets PAID or FAILED]
```

**3. The test plan covers only the happy path.**
The money risk is all in the failure paths. Add integration tests for:
- timeout then success, asserting one charge;
- a declined card;
- all attempts timing out, asserting the order stays `PENDING`.

## Decide and write down (not blockers)

- **Overselling:** with a 5-minute cache and no reservation, two customers can both buy the last unit. Accepting that at 200–2,000 orders a day is reasonable; just state what happens when it occurs (refund, backorder).
- **Duplicate submissions:** a double-click or client retry on `POST /orders` creates two orders. A client-supplied request key fixes it cheaply.
- **Email failure:** say that a failed confirmation email does not fail the order, and whether it is retried.

## Keep as is

- The module boundaries, with no module reading another's tables.
- Thin routes with the flow in `OrderCheckout`.
- The order id on every log line.
- A single Postgres instance, and the cache instead of the 800 ms warehouse call.

VERDICT: READY WITH CHANGES
