I reviewed `design.md` (revision 3). The overall approach holds up: stock is reserved before payment, the payment call happens outside any transaction, retries reuse one idempotency key, and a reconciliation job settles unknown results. You can start tomorrow. First, though, add about five sentences to the doc to settle four gaps, because each one changes code you would write in the first days.

## Order lifecycle as designed, with the gaps marked

```mermaid
stateDiagram-v2
    [*] --> PENDING: POST /orders (stock reserved)
    PENDING --> PAID: charge succeeds
    PENDING --> FAILED: charge declined (stock restored)
    PENDING --> PENDING: result unknown, client gets 202
    PENDING --> PAID: reconciliation job, provider says paid
    PENDING --> FAILED: reconciliation job, provider says failed (stock restored? not stated)
    PENDING --> PENDING: provider has no record of a charge (not handled)
```

## Must fix before building

1. **Stock can be restored twice.** Nothing says that settling an order only works while it is still `PENDING`. Both instances may run the reconciliation job, and a late request can overlap with it. Example: order X is `PENDING` with 1 unit and the provider reports it failed. Both instances mark it `FAILED` and each adds 1 back, so stock goes up by 2 when it should go up by 1. **Fix:** every status change is `UPDATE orders SET status = … WHERE id = :id AND status = 'PENDING'`. Restore stock only if that update changed a row, in the same transaction. Also decide whether the job runs on one instance or both.
2. **The reconciliation job ignores orders the provider never saw.** If an instance crashes after step 2 commits but before step 3 sends the charge, the order is `PENDING` and the provider has no charge for it. Step 6 only covers "PAID or FAILED". As written, that order sits `PENDING` with its stock held until the 30-minute alert fires, every time. **Fix:** say what "no charge found" means. Either mark the order `FAILED` and restore stock, or retry the charge with the same order id, and set a cutoff age.
3. **It is unclear whether the reconciliation job restores stock on `FAILED`.** Step 5 restores stock only on the decline path. If the job doesn't do it too, every unknown result that ends in failure loses stock for good. **Fix:** state that the job uses the same settle-as-failed code as step 5.
4. **A negative quantity would add stock.** Nothing validates `quantity`. With `:qty = -5`, `available >= -5` is always true, so the update raises stock by 5 and the order goes through. **Fix:** reject `quantity <= 0` at the edge, and add `CHECK (quantity > 0)` on `order_items` and `CHECK (available >= 0)` on `stock`.

## Should fix (decide this week; small to do now, costly to change later)

5. **Idempotency key scope.** The key is unique across all customers, so if two customers send the same key, one gets back the other's order. Make it `UNIQUE (customer_id, idempotency_key)`. Also decide what happens when the key repeats but the cart is different: the usual answer is `422`, which means storing a hash of the request.
6. **Where the price comes from.** `unit_price` and `total` are stored, but the doc doesn't say whether they come from the client's cart. They must be looked up on the server, or a client can set its own price.
7. **How a client finds out the result after `202`.** No endpoint is described, so a client that got `202` has no way to see the outcome. Add `GET /orders/{id}`, or say that retrying the `POST` with the same key is the way to check.
8. **Possible deadlock when reserving several items.** Two checkouts that both contain SKUs A and B, locked in opposite order, can deadlock. Postgres then aborts one and that customer gets an error. Reserve SKUs in sorted order.
9. **Missing tests.** Add tests for: two buyers racing for the last unit at the same time; the reconciliation job settling as paid, as failed, and as "no charge found"; the job and a live request settling the same order; a crash between step 2 and step 3; a repeated key with a different cart; and a quantity of 0 or less.

## Minor

10. **Confirmation email can be lost.** If the instance crashes between committing `PAID` and queuing the email, the email is never sent. That is acceptable if emails are best-effort. If not, write the email job in the same transaction (an outbox table). Either way, record the choice in the doc.
11. **The module rule conflicts with step 2.** Step 2 updates `stock` and inserts into `orders` in one transaction, which looks like it breaks "no module reads another module's tables". State that the inventory module exposes a reserve function that takes the caller's transaction.
12. **Missing keys and constraints.** `stock.sku` and `order_items` have no primary key. Add a `CHECK` that `status` is one of the three values.
13. **Request time.** With a 5 s timeout and up to 3 retries plus backoff, a request can run 25 s or longer. Confirm that the load balancer and client timeouts are longer than that.

Load is not a concern: 2,000 orders a day is very light for this setup.

Items 1–4 are each a sentence or two in the doc plus a few lines of code. If you settle them before you write the checkout service class and the reconciliation job, nothing you build tomorrow has to be redone.

VERDICT: READY WITH CHANGES
