I reviewed design.md. It isn't ready yet. The code structure section is fine, but the payment part of the checkout flow can charge a customer twice, or take their money and keep no record of the order. Both problems are in the core flow, so fix them on paper before you write code. They are small changes at your scale.

## Must fix before building

**1. Retrying the charge without an idempotency key can charge the customer twice.** (Step 4)
A timeout doesn't mean the charge failed. It often means the provider charged the card and the reply never reached you.
- **Case:** a cart costs $50. Attempt 1 times out after the provider has charged the card. Attempt 2 succeeds.
- **Wrong result:** the customer pays $100 for one order.
- **Expected:** the customer pays $50.
- **Fix:** send the payment provider an idempotency key with every attempt, and use the same key for all retries of one order. The order id is the natural choice. Check that your provider supports this before building.

**2. The payment call happens inside an open database transaction, so a charge can succeed while the order disappears.** (Steps 3 to 6)
- **Case A:** the charge succeeds, then the commit fails or the process crashes.
- **Wrong result:** the customer is charged and no order exists.
- **Expected:** a stored order that matches the charge.
- **Case B:** all four attempts time out, but attempt 1 had actually gone through.
- **Wrong result:** step 6 rolls back, the client gets an error, and the customer has been charged.
- **Expected:** the order is kept in an "unknown" state and checked against the provider.

The open transaction also holds a database connection for up to 20 seconds (4 attempts × 5 s). With a single Postgres instance, that's how the connection pool runs out under load.
- **Fix:** commit the order as `PENDING` first, call the provider outside any transaction, then update the status in a second short transaction. Never delete the order row.

**3. Some payment outcomes have no status.** The design only has `PENDING` and `PAID`. Add:
- `FAILED`, for a definite decline;
- `PAYMENT_UNKNOWN`, for when every retry timed out;
- a small reconciliation job that asks the provider how `PENDING` and `PAYMENT_UNKNOWN` orders ended up.

Without the job, orders like Case B stay wrong forever.

**4. A client retry of `POST /orders` creates a duplicate order.** A 20-second worst case is longer than most client and gateway timeouts, so these retries will happen. Have the client send an `Idempotency-Key` header and store it with a unique constraint. Also make the total payment wait shorter than the client's timeout. For example, 2 attempts at 3 s each is safer than 4 attempts at 5 s each.

**5. The test plan only covers the happy path.** That breaks your own standard, and the bugs above are all in the failure paths. Add tests for:
- the provider timing out and then succeeding (exactly one charge, same key each time);
- every attempt timing out (`PAYMENT_UNKNOWN`, order row kept);
- a definite decline (`FAILED`);
- the commit failing after a successful charge;
- a repeated `Idempotency-Key` (the original response is returned);
- the email failing (the order stays `PAID`).

You will need a fake payment provider that can be scripted to do each of these.

## Proposed flow

```mermaid
sequenceDiagram
    participant C as Client
    participant S as order-service
    participant DB as Postgres
    participant P as Payment provider
    C->>S: POST /orders (Idempotency-Key)
    S->>S: Check stock (cache)
    S->>DB: Tx 1: insert order PENDING, commit
    S->>P: Charge (idempotency key = order id), bounded retries
    P-->>S: success / decline / timeout
    S->>DB: Tx 2: PAID / FAILED / PAYMENT_UNKNOWN
    S-->>C: Response
    S->>DB: Write "send email" record (later sender delivers it)
    Note over S,P: Reconciliation job re-checks PENDING / PAYMENT_UNKNOWN with provider
```

## Should decide, but they don't block you

- **Overselling.** A stock cache that can be 5 minutes old, with no reservation, will sometimes sell the last item twice. At 2,000 orders a day that's acceptable, but write down what happens when it occurs: refund, backorder, or cancel the order.
- **Confirmation email.** The design doesn't say whether a failed email fails the request. It shouldn't. Write a "send email" row in Tx 2 and have a background worker send it.
- **Backups.** Nightly backups mean up to 24 hours of paid orders could be lost with no local record. Turn on point-in-time recovery (WAL archiving). It's cheap and matters once real money is involved.

## What's good

The design has clear module boundaries with no reading of another module's tables, thin routes, and a single `OrderCheckout` service class. Logging the order id on every line is right, and it will make the reconciliation job much easier to debug. Accepting the stock cache instead of the 800 ms warehouse call is a reasonable tradeoff, and the design states it openly.

## What you can do tomorrow

Fixes 1 to 4 should take about half a day of design work. While you settle them, you can still start the module skeletons, the inventory cache, and the scriptable fake payment provider, because none of those depend on the fixes. Hold off on `OrderCheckout` until the payment flow is settled.

VERDICT: NOT READY
