The design isn't ready to build exactly as written, but it's close. The overall approach holds up: reserve stock, then charge, then settle, with a reconciliation job behind it. There are four correctness bugs, though, and each is a small fix to the text. If you put those fixes into design.md before you code the parts they touch, you can start tomorrow.

## High: fix in the design before coding that part

**1. Orders that the reconciliation job marks `FAILED` never get their stock back.** Step 5 restores stock on a decline, but step 6 only says the job "settles them as PAID or FAILED". Example: an instance crashes right after step 2 commits, so the charge is never sent. Five minutes later the job asks the provider, gets "no such charge", and marks the order `FAILED`. The 3 units stay reserved forever when they should go back to `available`.
- **Fix:** whenever an order is settled as `FAILED`, it goes through the same "mark FAILED and restore stock" code. Also define what "provider has no record of this charge" means (I'd treat it as `FAILED`).

**2. Stock can be restored twice, because status changes aren't checked against the current status.** Both instances run the reconciliation job every 5 minutes, and the request path settles orders too. Example: both instances' jobs read order X as `PENDING`, both see a decline, and both restore stock. A 2-unit order adds 4 units back.
- **Fix:** every settlement is a compare-and-set, `UPDATE orders SET status = :new WHERE id = :id AND status = 'PENDING'`. Only touch stock or queue email when that update changed exactly one row. Optionally, have the job claim orders with `FOR UPDATE SKIP LOCKED`.

```mermaid
stateDiagram-v2
    [*] --> PENDING: stock reserved
    PENDING --> PAID: charge succeeded (only if still PENDING)
    PENDING --> FAILED: declined or no charge (only if still PENDING) + restore stock
```

**3. The idempotency key is unique across all customers, and it doesn't check the cart.** Example: customer B's app reuses or collides with customer A's key and gets back A's order, which leaks A's data. Separately, a retry that uses the same key with a different cart silently returns the old order.
- **Fix:** make the unique constraint `(customer_id, idempotency_key)`. Store a hash of the request and return `422` when the same key comes with a different body.

**4. The design doesn't say where prices come from.** `order_items.unit_price` and `orders.total` exist, but no price source is named. If the price comes from the client's cart, a client can send `unit_price: 0.01`.
- **Fix:** say that the server looks up prices from a catalog it controls (and name that catalog) and computes `total` itself.

## Medium

**5. Negative or zero quantities aren't rejected.** `available - :qty` with `qty = -5` passes the `available >= :qty` check and adds 5 units of stock. Validate `quantity > 0` and add a `CHECK (quantity > 0)` constraint.

**6. Reservations can deadlock.** Order A reserves SKU 1 then SKU 2, while order B reserves SKU 2 then SKU 1. Postgres aborts one of them. Fix: always update SKUs in sorted order, and merge duplicate SKUs in the cart first.

**7. Confirmation emails can be lost.** Step 4 commits `PAID` and then queues the email, so a crash between the two means no email is ever sent. It's also unclear whether orders the reconciliation job settles as `PAID` get an email at all. Fix: write the email job in the same transaction as the status change (an outbox table), and use it on both paths.

**8. After a `202` the client can't find out the result.** No `GET /orders/{id}` or webhook is defined. Add one.

**9. The data model is missing constraints.** Needed: a primary key on `stock.sku`, so a duplicate row can't get decremented twice; a primary key and a foreign key on `order_items`; `CHECK (status IN (...))`; and `CHECK (available >= 0)`.

**10. The test plan skips the risky parts.** There are no tests for:
- the reconciliation job (paid, declined, provider has no record)
- two jobs settling the same order at once
- two buyers racing for the last unit at the same time
- a crash between step 2 and step 3
- the same key with a different cart
- the same key across two customers
- negative quantities

Each of bugs 1 to 3 and item 5 needs a test written before its fix.

## Low

**11. The request can take a long time.** A 5 s timeout with 3 retries plus backoff can hold the request for about 25 to 30 s. Check that the load balancer and client timeouts are longer than that, or lower the retry budget.

**12. The module rule conflicts with step 2.** "No module reads another module's tables" doesn't match step 2, which touches `stock` and `orders` in one transaction. State that the inventory module exposes `reserve(tx, items)` and runs inside the caller's transaction.

**13. A duplicate of an in-flight request has no defined response.** Say what a duplicate `POST` returns while the original is still charging, e.g. `202` with the `PENDING` order.

None of these changes the architecture. Fixes 1 to 4 are a few sentences each in design.md, plus the tests listed in item 10.

VERDICT: READY WITH CHANGES
