**Almost. The main flow is sound and right-sized, but the recovery paths have gaps that will cause wrong stock counts or stuck orders. Each one is a few sentences of design to settle before you write the code.**

What's good: the payment call sits outside the transaction, the provider gets the order id as its idempotency key, there's a reconciler and an alert, and nothing is over-engineered for 2,000 orders a day.

## Must fix before building

1. **The reconciler doesn't say what to do when the provider has no record of the charge.**
   - Case: the instance crashes after step 2 commits and before step 3 sends the charge. The order is `PENDING` and the stock is reserved, but the provider has never heard of it.
   - The reconciler asks the provider and gets "not found". Step 6 only covers `PAID` or `FAILED`.
   - Decide whether "not found after N minutes" means mark `FAILED` and restore stock, or retry the charge.
   - Without this, stock stays reserved until someone acts on the 30-minute alert.

2. **Nothing prevents stock from being restored twice.**
   - Step 5 (decline) and the reconciler both settle orders to `FAILED` and both restore stock. Step 6 never mentions restoring stock at all.
   - Two instances means two reconcilers, and a reconciler can also overlap a request that is still retrying.
   - Example: an order is declined, the handler marks it `FAILED` and restores 3 units, then the reconciler does the same. The stock is now 3 too high, and you will oversell.
   - Fix: make every status change conditional (`UPDATE … WHERE status = 'PENDING'`) and restore stock only if that update changed a row. Put stock restore in one shared function used by both paths.
   - The reconciler also needs a lock or `FOR UPDATE SKIP LOCKED`, so only one instance works on an order at a time.

3. **The idempotency key is unique across all customers.**
   - Case: two customers' clients generate the same key. The second gets the first customer's order back.
   - Fix: make the constraint `(customer_id, idempotency_key)`.
   - Also decide what happens when the same key arrives with a different cart. Return `422` rather than the old order.

4. **The API is incomplete.**
   - A `202` response has no way for the client to learn the outcome. You need `GET /orders/{id}`.
   - Success and decline response codes aren't specified.
   - Who sets `unit_price` and `total`? There is no catalog table, so the design reads as if the client sends prices. The server must price the order.

5. **Reserving several SKUs in step 2 can deadlock.** Order A reserves X then Y while order B reserves Y then X, and Postgres kills one of them. Sort the SKUs before updating. Also add `CHECK (available >= 0)` as a backstop.

## Should fix (cheap now, costly later)

- **Schema:** the tables have no primary keys, foreign keys, indexes or `NOT NULL`. At minimum, `order_items(order_id)` needs a foreign key and an index, and `stock.sku` needs a primary key. The reconciler's query needs an index on `(status, created_at)`.
- **Lost emails:** a crash between the `PAID` commit and queueing the email loses the email. For a confirmation email you can accept that, but write it down as an accepted risk, or insert the email job in the same transaction as the `PAID` update. The design also never says what the queue is.
- **The module rule contradicts step 2.** "No module reads another's tables" conflicts with one transaction that spans inventory and orders. Say how that works, for example a shared unit-of-work that orders passes to inventory.
- **No refund or cancel path for `PAID` orders.** That's fine to leave out of v1, but say so explicitly.

## Tests

The test list skips the riskiest part: reconciliation. Add these:
- Crash after reserve and before charge.
- Crash after charge succeeds and before `PAID` is written.
- Decline restores stock exactly once.
- Reconciler racing a live request.
- Two concurrent identical `POST`s.
- Two orders with the same SKUs in opposite order.

Without them, items 1 and 2 will ship untested.

I also noticed you asked me to challenge designs hard, so I held back nothing. These are real gaps, not nitpicks. None of them require rethinking the architecture.

VERDICT: READY WITH CHANGES
