**Not ready to build tomorrow. Three flaws in the design would charge customers twice or oversell stock under normal traffic.** All three are cheap to fix on paper and expensive to fix after launch.

## Blocking

**1. A retry creates a second charge (step 3).** The payment idempotency key is `<order id>-<attempt number>`, so every retry sends a different key. The provider treats each one as a new charge.
- Case: attempt 1 times out at 5 s, but the provider did charge the card. Attempt 2 sends `abc-2`, and the customer is charged twice.
- Fix: use one stable key per order, such as the order id. Traceability comes from logging the attempt number, not from the key.
- The fake provider in your tests must also honor idempotency keys. Otherwise no test catches this.

**2. Idempotency keys live in each instance's memory (step 1).** You run two instances behind a load balancer.
- Case: the client's request times out and it retries with the same key. The load balancer sends the retry to the other instance, which has never seen the key. That creates a second order, a second stock decrement and a second charge.
- A restart also wipes the map.
- Fix: store the key in Postgres with a unique constraint, for example on `(customer_id, idempotency_key)`. Insert it in the same transaction as the order.

**3. Stock can be oversold (step 2).** The service reads `available` and then writes `available - quantity`. At Postgres's default isolation level, two requests can both read `1` and both succeed.
- Case: two customers buy the last unit at the same moment, and both orders go through.
- Fix: use a single conditional update, `UPDATE stock SET available = available - q WHERE sku = ? AND available >= q`. Check the affected row count, and lock SKUs in a fixed order to avoid deadlocks.
- Add `CHECK (available >= 0)` and a primary key on `stock.sku`.
- The "last unit" test needs to run two requests concurrently. A sequential test would pass on the broken design.

## Should fix before building (each is a gap, not a design change)

- **Money as `double precision`:** `total` and `unit_price` will accumulate rounding errors. Use `numeric(12,2)`, or integer minor units plus the currency.
- **Where prices come from:** the design never says. The server must look up `unit_price` itself and must not trust the cart.
- **Stock restore must happen exactly once:** step 5 restores stock, but step 6 also settles orders as `FAILED` and doesn't mention restoring stock. A failed-then-reconciled order would leak stock forever.
  - Make every status change a compare-and-set, `UPDATE ... WHERE status = 'PENDING'`.
  - Restore stock only if that update changed a row.
  - This also protects against the reconciliation job and a still-retrying request settling the same order at once.
- **Reconciliation job on two instances:** both will run it every 5 minutes. Use `SELECT ... FOR UPDATE SKIP LOCKED` or an advisory lock.
- **Provider says "no such charge":** the design doesn't say what reconciliation does when the provider has no record, which happens when the process crashed before charging. As written, those orders stay `PENDING` and hold stock until the 30-minute alert. Define the rule: retry the charge with the stable key, or fail the order after N minutes.
- **What counts as "declined":** separate a definitive decline (settle `FAILED`) from a 5xx or timeout (unknown, retry). Without this, a provider outage could fail good orders.
- **Request latency:** 4 attempts at 5 s plus backoff can hold the client request for 30 s or more. Pick a total deadline, and decide whether to return `202` sooner and let reconciliation finish.
- **Lost confirmation email:** a crash between the `PAID` commit and the enqueue loses the email. Either write an outbox row in the `PAID` transaction or accept this and say so. At 2,000 orders a day, accepting it is defensible.
- **Missing specifics:** the schema has no primary key on `order_items`, no indexes (at minimum `orders(status, created_at)` for reconciliation), no API response shapes (`202`, `409`) and no authentication.

## Tests to add
- Concurrent last-unit purchase.
- Duplicate `POST` handled by a different instance (use two app instances in the test).
- Timeout where the provider did charge, then retry: assert exactly one charge.
- Reconciliation settles `FAILED` and restores stock exactly once.
- Reconciliation and the live request racing on the same order.
- Provider reports no such charge.

## What's good
The module boundaries, thin routes, structured logging, the 30-minute `PENDING` alert and the reconciliation job itself are the right shape. You are fixing details of a sound design, not rewriting it.

Estimate: about half a day to revise the document, then build. Want me to make the edits to `design.md`?

VERDICT: NOT READY
