The design is sound at its core and you can start building tomorrow, but it has two gaps that would corrupt stock counts and one that can show a customer someone else's order. All three are spec additions of a line or two.

## Must fix before building

1. **Orders that were never charged have no defined outcome.**
   - **Case:** the instance crashes after step 2 commits and before step 3 calls the provider. The order is `PENDING` with stock reserved, and the provider has no record of a charge.
   - **What happens:** step 6 says the reconciliation job settles orders as `PAID` or `FAILED`, but does not cover "provider has no such charge". The order stays `PENDING` and the stock stays reserved until the 30-minute alert.
   - **Fix:** state that "no charge found" settles as `FAILED`, and that every `FAILED` settlement by the job restores stock, as step 5 does.

2. **Stock can be restored twice.**
   - **Case:** there are two instances, so the reconciliation job runs on both. Both see the same `PENDING` order for 1 unit of a SKU, both get "declined" from the provider, and both mark it `FAILED` and restore stock.
   - **What happens:** `available` rises by 2 instead of 1, and you later sell a unit you do not have.
   - **Fix:** make every status change conditional (`UPDATE orders SET status = ... WHERE id = :id AND status = 'PENDING'`) and restore stock only if that update changed a row. Apply this to steps 4 and 5 and to the job.

3. **The idempotency key is unique globally, not per customer.**
   - **Case:** customer B sends a key that customer A already used.
   - **What happens:** B gets A's order back, instead of their own new order.
   - **Fix:** make the constraint unique on `(customer_id, idempotency_key)`. Also decide what a repeated key with a different cart returns; I recommend `422`.

## Should fix, cheap to do now

- **Deadlocks on multi-item carts.** Order 1 reserves SKU A then B while order 2 reserves B then A; each waits on the other and Postgres aborts one. Reserve SKUs in sorted order.
- **Price source is unspecified.** The design does not say where `unit_price` and `total` come from. They must come from the server, not the cart payload, or a client can set its own price.
- **Missing test cases.** Add these to the integration list:
  - crash after reservation (item 1)
  - the reconciliation job settling an order as paid, declined and not found
  - two job runs on the same order (item 2)
  - two concurrent requests for the last unit
  - two concurrent requests with the same key
- **Worst-case response time.** Four attempts at 5 s plus backoff is roughly 25–35 s before the `202`. Check that this is under the load balancer and client timeouts, or cut the retries to one and let the job handle the rest.
- **Lost confirmation email.** A crash between the `PAID` commit and queueing the email in step 4 loses the email. Either write the queue entry in the same transaction or have the job re-queue it.
- **Missing keys.** `order_items` needs a primary key, such as `(order_id, sku)`, and `stock` needs one on `sku`.

## What is already right

Reservation is a conditional update inside one transaction, the provider call is outside any transaction, the order id is the provider idempotency key, and unknown outcomes go to reconciliation with an alert behind it. The 2-minute reconciliation threshold is safely above the longest in-request retry window, so the job will not race a live request.

VERDICT: READY WITH CHANGES
