The structure is solid and you can start building tomorrow, but steps 3–6 of the checkout flow need to change first. As written, the flow can charge a customer twice, or take their money and keep no record of the order. These are not style points. Each is a way to lose real money, and each fix is small.

## What's already good

- The module boundaries are right: separate orders, payments and inventory modules, none reading another's tables, with thin routes and the flow in `OrderCheckout`.
- Putting the order id on every log line will pay for itself the first time a payment goes wrong.
- Using the 5-minute inventory cache instead of an 800 ms warehouse call is a sensible trade. Just write down what happens when it's wrong (point 3 below).

## Must fix before building the payment step

**1. Retrying a timed-out charge can double-charge (step 4).** A timeout doesn't mean the charge failed. It means you don't know.
- Concrete case: attempt 1 reaches the provider and the card is charged, but the response takes 5.1 s, so you time out. Attempt 2 charges again. The customer pays twice for one order.
- Fix: send an idempotency key on every charge attempt, such as the order id. Most payment providers support this, so a retry returns the original result instead of making a new charge.

**2. Holding the database transaction open during the payment call loses payments (steps 3–6).**
- Concrete case: the charge succeeds, then the commit fails or the process restarts. The rollback erases the `PENDING` order, so the customer is charged and you have no order record.
- The same thing happens when all 3 retries time out after the first attempt actually charged. Step 6 rolls back and returns an error, even though the money moved.
- It also holds a database connection for up to about 20 s (4 attempts × 5 s). At 2,000 orders a day that will exhaust the connection pool during peaks.
- Fix: commit `PENDING` first, call payment outside any transaction, then update the order in a second short transaction. Add an `UNKNOWN` (or `PAYMENT_UNCONFIRMED`) state for timeouts, plus a small job that asks the provider for the real status of those orders.

```mermaid
flowchart TD
    A[POST /orders] --> B[Check inventory cache]
    B --> C[Insert order PENDING + commit]
    C --> D[Charge with idempotency key = order id]
    D -->|success| E[Mark PAID + commit]
    E --> F[Send confirmation email]
    D -->|declined| G[Mark FAILED + commit, return error]
    D -->|timeout after retries| H[Mark UNKNOWN + commit]
    H --> I[Reconcile job asks provider, sets PAID or FAILED]
```

## Should decide, not necessarily build now

**3. Overselling.** With a 5-minute cache and no stock reservation, two customers can both buy the last unit. That may be fine for your volume, but decide what happens next (backorder, refund, apology email) and write it in the doc.

**4. A failed email shouldn't fail the order.** Once the order is `PAID`, an email error should be logged and retried, not returned to the client as a checkout failure.

**5. Tests.** One happy-path integration test misses the paths above. Add integration tests for: a declined card, a timeout followed by a successful retry (exactly one charge), a timeout on every retry (order ends up `UNKNOWN`), and the reconcile job.

The design fixes are about an hour of editing. You can start on the inventory and order modules tomorrow and do the payment step once the revised flow is in the doc.

VERDICT: READY WITH CHANGES
