**Nearly ready. You can start tomorrow if you first fix two gaps in the design that cause wrong data.** The core flow is sound: stock is reserved in one transaction, the payment call happens outside any transaction, the order id is sent as the idempotency key, and a reconciliation job settles unknown results. What's wrong is mostly unstated edge rules. Each one is a few lines in the doc.

## Order lifecycle as designed

```mermaid
stateDiagram-v2
    [*] --> PENDING: POST /orders (stock reserved)
    PENDING --> PAID: charge succeeds (request or reconciliation job)
    PENDING --> FAILED: declined in request (stock restored)
    PENDING --> FAILED: reconciliation job (stock restore NOT specified)
    PENDING --> PENDING: result unknown, client gets 202
```

## Problems, by severity

**High: fix before coding**

1. **The reconciliation job doesn't put stock back.** Step 5 restores stock when a charge is declined, but step 6 only says the job "settles them as PAID or FAILED". Example: a customer buys the last unit, the charge times out, and the job later finds it declined. The order becomes `FAILED`, but `stock.available` stays at 0 when it should be 1, so the unit can never be sold again. Fix: both paths should call the same "fail order and restore stock" operation.
2. **Moving an order out of `PENDING` isn't guarded, so stock can be restored twice.** There are two instances, and the job may run on both. The request path and the job can also both settle the same order. Example: two job runs each read order X as `PENDING` and as declined, and each adds its 2 units back, so stock goes up by 4 instead of 2. Fix: settle with `UPDATE orders SET status = 'FAILED' WHERE id = :id AND status = 'PENDING'`, and restore stock only if that update changed exactly 1 row. Also say how the job runs on only one instance at a time, for example with `pg_try_advisory_lock`.

**Medium: decide before or while coding the affected part**

3. **The idempotency key is unique across all customers, not per customer.** Example: customer A and customer B's apps happen to send the same key. Customer B gets back customer A's order. Make the constraint unique on `(customer_id, idempotency_key)`. Also say what happens when the same key arrives with a different cart. I'd return `422` rather than silently return the old order.
4. **Duplicate requests that arrive at the same moment aren't covered.** Both pass the "does this key exist?" check, and the second insert then fails the unique constraint. The transaction rolls back, so stock is safe. But the second request gets a `500` when it should get the existing order. Say that a unique-constraint violation is caught and the existing order is returned.
5. **The single transaction conflicts with the module boundary rule.** Step 2 writes `stock` and `orders` in one transaction. The code structure section says no module reads another module's tables. Decide how this works, for example: inventory exposes `reserve(tx, items)` and `release(tx, items)`, and they take the caller's transaction. Otherwise the first developer will just write `UPDATE stock` inside the orders code.
6. **The design doesn't say where prices come from.** The client sends "the cart". If `unit_price` and `total` come from that cart, a client can send `unit_price: 0.01`. State that prices are looked up on the server.
7. **A client that gets `202` has no way to learn the outcome.** The design has no `GET /orders/{id}` and no notification. Add one of them.
8. **The reconciliation job has no rule for "the provider has no record of this charge".** This happens when every attempt timed out before reaching the provider. Decide whether the job marks the order `FAILED` and restores stock, or tries the charge again.
9. **The test plan doesn't cover the riskiest code.** Missing tests:
   - the reconciliation job settling `PAID`, and settling `FAILED` with stock restored
   - two job runs at the same time, which must restore stock only once
   - two duplicate `POST /orders` requests at the same time
   - the same key sent with a different cart
   - two buyers racing for the last unit (the current "last unit" test is a single buyer)
   - a crash after a successful charge but before the order is marked `PAID`

**Low: note it and move on**

10. **The email is queued after the commit, so a crash in between loses it.** Accept this for now, or add an outbox table later. Also say whether the reconciliation job queues the email when it marks an order `PAID`.
11. **A deadlock is possible on multi-item carts.** Two orders that touch the same SKUs in opposite order can deadlock. Postgres aborts one, which then gets a `500` or `409`. Fix: reserve SKUs in sorted order.
12. **The data model is missing keys and a constraint.** Add a primary key on `stock.sku`, a primary key on `order_items`, and `CHECK (available >= 0)` as a safety net.
13. **A request can take 25 seconds or more.** The worst case is 4 attempts × 5 s plus backoff. Check that the load balancer and client timeouts are longer than that.

None of this needs a redesign. Items 1–2 are about a paragraph in the doc, items 3–8 are one decision each, and item 9 adds about six test cases.

VERDICT: READY WITH CHANGES
