The design is close, and you can start building tomorrow, but first add about four short paragraphs to the doc. Two cases in the current flow leave stock wrong, and the reconciliation job has no tests in the plan. The core approach is sound: reserving stock with a conditional update, charging outside the transaction, sending the provider a stable idempotency key, and reconciling unknown results. At 2,000 orders a day, load is not a concern.

## Must fix before building

**1. A crash between reserving stock and charging leaves stock reserved forever (High).**
Step 2 commits a `PENDING` order with stock taken off. Step 3 then calls the provider. If the instance dies in between, the charge was never attempted.
- **Case:** an order for 1 unit of SKU `A` commits and the process restarts. The reconciliation job asks the provider about it and gets "no such charge." The doc only says the job settles orders as `PAID` or `FAILED`, so this one stays `PENDING`, the unit of `A` stays unavailable, and the 30-minute alert fires with no defined action.
- **Expected:** the doc says what happens when the provider has no record of the charge. It should either retry the charge (safe, since the key is the order id) or mark the order `FAILED` and return the stock. Retrying the same `Idempotency-Key` doesn't help either, because step 1 just returns the existing order without resuming the charge.

**2. Two instances running reconciliation can return stock twice (High).**
There are two service instances (line 6), and nothing says the job runs on only one of them. Nothing says a status change only happens if the order is still `PENDING`.
- **Case:** a `PENDING` order for 1 unit of `A` is declined at the provider. Both instances' jobs pick it up, and both mark it `FAILED` and add the stock back. `available` goes up by 2 instead of 1. The same race can also send the confirmation email twice for `PAID`.
- **Fix:** make every settle step conditional, e.g. `UPDATE orders SET status = 'FAILED' WHERE id = :id AND status = 'PENDING'`. Only return stock or queue the email if that update changed a row. A single-runner lock for the job is a nice extra, but the conditional update is the actual fix.

**3. The reconciliation job doesn't say it uses the same settle logic as the request path (Medium).**
Step 5 returns stock on a decline. Step 6 only says "settles them as `PAID` or `FAILED`," without saying it also returns stock or queues the email. Write down that both paths call one settle function in `OrderCheckout`. That also keeps the logic in one place.

**4. The test plan has no tests for reconciliation, which is the riskiest part (Medium).**
Missing:
- reconciliation settles as paid
- reconciliation settles as declined and stock is returned
- provider has no record of the charge (issue 1)
- two jobs run at once (issue 2)
- crash after step 2 commits
- two concurrent requests with the same key
- two buyers racing for the last unit
- a decline returns the stock

The current "last unit" and "duplicate" tests may only be run one request at a time.

## Should fix (small, but specify them now)

**5. Idempotency keys are globally unique, not unique per customer (Medium).** If two customers send the same client-generated key, the second one gets the first customer's order back. Make the unique constraint `(customer_id, idempotency_key)`. Optionally, reject a reused key that comes with a different cart.

**6. The doc doesn't say where prices come from (Medium).** `order_items.unit_price` and `orders.total` are stored, but there's no price source. If prices come from the client's cart, a client can set their own price. State that prices are looked up on the server.

**7. One step crosses the module boundary (Medium).** Step 2 updates `stock` (owned by inventory) and inserts into `orders` in one transaction, but line 41 says no module reads another module's tables. Say how this works, e.g. inventory exposes `reserve(tx, items)` and takes the caller's transaction. Otherwise someone will put the `stock` SQL into orders code.

**8. A client that gets `202` has no way to learn the outcome (Medium).** There's no `GET /orders/{id}`, and the doc doesn't say what status code a repeated key returns while the order is still `PENDING`.

**9. The confirmation email can be lost (Low).** Step 4 commits `PAID` and then queues the email. A crash between the two drops the email without anyone noticing. If the queue is a database table, write the email row in the same transaction.

**10. Concurrent checkouts can deadlock (Low).** Two carts `[A, B]` and `[B, A]` can deadlock in step 2. Postgres will abort one of them, which shows up as a 500 unless you handle it. Fix it by updating SKUs in sorted order and merging duplicate SKU lines first.

**11. The schema is missing constraints (Low).** No primary keys on `orders.id` or `stock.sku`, no foreign key from `order_items` to `orders`, no `CHECK (available >= 0)`, and no `CHECK` on `status` values.

**12. Retry rules aren't specified (Low).** Say that only timeouts and 5xx responses are retried, never declines. The worst case is about 4 × 5 s plus backoff, which is 25 s or more while the request is held open. Check that this fits under the load balancer's timeout.

## Speculative (check with your provider, not defects in the doc)
- Reconciliation assumes the provider can look up a charge by your idempotency key or order id even when you never got a charge id back, because the call timed out. Some providers can't do this, or only keep keys for about 24 hours.

## Order lifecycle with fixes 1 and 2 applied

```mermaid
stateDiagram-v2
    [*] --> PENDING: POST /orders, stock reserved
    PENDING --> PAID: charge succeeds (only if still PENDING)
    PENDING --> FAILED: declined, or provider has no record of the charge (only if still PENDING), stock returned once
    PENDING --> PENDING: result unknown, reconciliation tries again
    PAID --> [*]
    FAILED --> [*]
```

## Next steps
Issues 1–4 are what block the build, and each needs about a paragraph in the doc. You can start on the data model and stock reservation tomorrow while you write them. Write the tests from issue 4 first: they'll show whether 1 and 2 are fixed.

VERDICT: READY WITH CHANGES
