**Not quite ready to build as written, but close.** The core shape is right, and there are three gaps that can each corrupt stock or strand an order. All three are paper fixes you can make tonight, so I would still start tomorrow.

## Fix before building

**1. Stock can be restored twice for one failed order.**
The design has two instances and a reconciliation job, but does not say the job runs on only one of them or that status changes are conditional.
- **Case:** an order for 3 units of SKU X is declined at the provider while `PENDING`. Both instances run the job at 12:05, both see "declined", and both restore stock.
- **Wrong result:** `available` goes up by 6.
- **Expected:** it goes up by 3. The extra 3 units get oversold later.
- **Fix:** make every status change `UPDATE orders SET status = … WHERE id = … AND status = 'PENDING'`, and restore stock only if that update changed a row. This also covers the request handler and the job overlapping.

**2. The reconciliation job has no rule for "provider has never heard of this order".**
Step 6 says the job settles orders as `PAID` or `FAILED`, but there is a third answer.
- **Case:** the instance crashes after step 2 commits and before the charge call in step 3 reaches the provider. The job asks for the charge status and gets "not found".
- **Wrong result:** the order stays `PENDING` forever and holds its stock until the 30-minute alert brings in a human.
- **Expected:** the job settles it as `FAILED` and releases the stock.
- **Fix:** treat "not found" after the retry window as `FAILED` with stock restore. Also write the rule for "provider says still processing" (leave it, check next run).
- **Remaining risk:** a charge that lands after you marked the order `FAILED` needs a refund, and the design has no refund path. Either add one or record this as a manual procedure.

**3. The idempotency key is unique across all customers.**
- **Case:** customer B sends a key that customer A already used.
- **Wrong result:** B gets A's order back.
- **Expected:** B gets a new order.
- **Fix:** make the constraint unique on `(customer_id, idempotency_key)`.
- **Also decide:** what the same key with a different cart returns (I suggest `422`), and that a simultaneous duplicate catches the unique violation and returns the existing order, not a `500`.

## Fix this week, not blocking

- **Confirmation email can be lost.** Step 4 commits `PAID` and then queues the email. A crash between the two means a paid customer never gets one, and nothing sweeps for it. Write an outbox row in the same transaction as `PAID`.
- **Price source is not stated.** If `unit_price` and `total` come from the client's cart, a customer can set their own price. State that the server computes both.
- **Multi-item orders can deadlock.** Two orders that reserve SKUs A, B and B, A at once will deadlock, and Postgres will abort one as a `500`. Update stock in sorted SKU order.
- **Tables are missing keys.** `order_items` has no primary key, and `stock` has no `CHECK (available >= 0)` as a backstop.
- **A declined order is final for its key.** Retrying with a new card needs a new idempotency key. Put that in the API contract.

## Test plan gaps

The reconciliation job is the piece that handles every ambiguous payment, and it has no tests listed. Add these:

- The job settling `PAID`, `FAILED`, "not found" and "still processing".
- The job running twice at once on the same order (finding 1).
- Two simultaneous buyers for the last unit; the listed test only covers a single buyer.
- Two simultaneous `POST /orders` with the same key.
- A crash after reservation and before the charge.
- An email queue failure after `PAID`.

## What is solid

- Reserving stock with a guarded `UPDATE` inside one transaction.
- Charging outside any transaction, with the order id as the provider's idempotency key.
- Returning `202` with later reconciliation when the charge result is unknown.
- The module boundaries and the thin routes.
- The overall weight of the design: at 2,000 orders a day, one Postgres and no message broker is the right call.

VERDICT: READY WITH CHANGES
