**The design is close: build can start tomorrow if you first fix three gaps in how stuck orders get settled.** The core checkout is sound. Stock is reserved in one database step, retried charges can't double-bill, and the email can never fail an order. What's missing is mostly what happens to an order that stays `PENDING`: who settles it, and whether its stock comes back. These are edits to the document, not a redesign.

## Order lifecycle as written, with the gaps marked

```mermaid
stateDiagram-v2
    [*] --> PENDING: stock reserved, order inserted
    PENDING --> PAID: charge succeeds (request or reconciliation job)
    PENDING --> FAILED: declined in request (stock restored)
    PENDING --> FAILED: reconciliation job (stock restored? not stated)
    PENDING --> PENDING: provider has no record of charge (not handled)
```

## Problems, by severity

**High: fix in the doc before coding**

1. **Status changes aren't guarded, so stock can be restored twice.** Both instances will run the 5-minute reconciliation job unless the design says otherwise. Example: an order for 2 units is declined. Both jobs see it as `PENDING`, both mark it `FAILED`, and both add 2 back. Stock goes up by 4 when it should go up by 2. Fix: every transition is `UPDATE orders SET status = … WHERE id = … AND status = 'PENDING'`. Restore stock only if that update changed a row. Also decide whether the job runs on one instance only or takes a row lock (`FOR UPDATE SKIP LOCKED`).
2. **The reconciliation job doesn't say whether it restores stock when it settles `FAILED`.** Only the decline path (step 5) does. As written, every order that times out and then fails keeps its units reserved forever. Fix: settle `FAILED` the same way everywhere, through one shared function.
3. **"Provider has no record of this charge" isn't handled.** This happens when the service crashes after step 2 commits but before step 3 sends the charge. The order stays `PENDING` forever and its stock stays reserved. All the 30-minute alert does is announce this. Fix: decide the rule, for example "no record after 2 minutes → `FAILED` and restore stock". Also confirm the provider can look up a charge by *our* idempotency key or order id. Some providers can't (Stripe can't query by idempotency key), and the job is built on that lookup.

**Medium: decide this week, can land during the build**

4. **The design doesn't say where prices come from.** `unit_price` and `total` are stored, and the client sends "the cart". If those prices come from the client, a buyer can change them. The server should look prices up itself and ignore client-sent amounts. State this in the doc.
5. **A client that gets `202` has no way to learn the outcome.** There's no `GET /orders/{id}` and no other status channel. Add one.
6. **The idempotency key is unique across all customers, not per customer.** If one customer sends another customer's key, they get the other customer's order back, which leaks data. Make the unique constraint `(customer_id, idempotency_key)`. Also decide what happens when the same key arrives with a different cart: return `409` or `422`, rather than silently returning the old order.
7. **The test plan misses the riskiest paths.** Add tests for:
   - the reconciliation job settling `PAID`, settling `FAILED` (stock restored), and the no-record case
   - two reconciliation jobs settling the same order at once (stock restored exactly once)
   - two concurrent `POST /orders` with the same key
   - two buyers racing for the last unit
   - a crash between step 2 and step 3

**Low: note it and move on**

8. **Possible deadlock.** Two carts that update the same SKUs in different orders can deadlock each other. Sort SKUs before updating, and turn a deadlock abort into a retry, not a `500`.
9. **The confirmation email can be lost.** If the service crashes after `PAID` commits but before the email is queued, no email goes out. A transactional outbox fixes this. Otherwise, accept the risk and write it down.
10. **The module rule conflicts with step 2.** Step 2 writes orders and stock in one transaction, but the design says no module touches another's tables. Say that inventory exposes a `reserve` call that takes the caller's transaction, so the boundary holds.
11. **Schema gaps.** Add `CHECK (available >= 0)` on `stock`. Add primary keys on `stock(sku)` and `order_items`. Consider storing the provider's charge id on the order.
12. **Slow worst case.** A request can wait about 25 s or more (4 attempts × 5 s plus backoff). Check that this is under the load balancer's timeout.

The expected scale (about 2,000 orders a day) is no problem for this setup.

VERDICT: READY WITH CHANGES
