The design is sound at its core and you can start tomorrow, but four gaps should be closed in the doc first, because each one produces wrong stock, a stuck order, or a wrong charge. None needs a structural change.

## Fix before building

1. **Stock can be restored twice.** Both instances will run the reconciliation job, and the doc does not say status changes are conditional.
   - **Failing case:** order A is `PENDING` for 1 unit of a SKU with `available = 4`. Both instances see the declined charge and both run step 5, so `available` ends at 6 instead of 5.
   - **Fix:** make every transition `UPDATE orders SET status = … WHERE id = … AND status = 'PENDING'`, and restore stock or queue the email only if that update changed a row. This also covers a slow request racing the job.

2. **The reconciliation job has no rule for "provider has never heard of this order".**
   - **Failing case:** the instance crashes after step 2 commits and before step 3 sends the charge. The order is `PENDING` with stock reserved, and the provider returns "not found", which is neither `PAID` nor `FAILED`. The order stays stuck until the 30-minute alert.
   - **Fix:** treat "not found" as `FAILED` and restore stock. The 2-minute age threshold is safe, since step 3 finishes within about 30 s.

3. **The idempotency key is unique globally, not per customer.**
   - **Failing case:** customer B sends a key customer A already used and receives A's order back.
   - **Fix:** make the constraint `(customer_id, idempotency_key)`. Also decide what a repeated key with a different cart returns; I'd use `422`.

4. **The doc does not say where `unit_price` and `total` come from.** If they come from the client's cart, a customer can set their own price. State that the server looks prices up and computes the total, and name the source, since there is no price table in the data model.

## Settle during the build

- **Confirmation email can be lost.** Step 4 queues it after the commit, so a crash in between drops it. Orders settled as `PAID` by the reconciliation job are not said to get an email at all. Queue it wherever the `PENDING` → `PAID` update succeeds.
- **Deadlocks on overlapping carts.** Two orders reserving the same two SKUs in opposite order will deadlock, and one gets a 500. Reserve in sorted SKU order.
- **Request duration.** Four attempts at 5 s plus backoff holds the request for about 30 s. Check that the load balancer timeout is longer, or cut the retries.
- **Module rule versus step 2.** Step 2 writes `stock` and `orders` in one transaction, while the code structure says no module touches another's tables. Say that inventory exposes a `reserve` call that joins the caller's transaction.
- **Missing constraints.** Add primary keys on `order_items` and `stock`, `quantity > 0`, `available >= 0`, and a rule for the same SKU appearing twice in a cart.
- **Missing endpoint.** After a `202`, the client needs something like `GET /orders/{id}` to learn the outcome.

## Test plan gaps

The test list has nothing for the reconciliation job, which is where items 1 and 2 live. Add these:

- The job settles a paid order, a declined order and a "not found" order.
- Two job runs on the same order restore stock once.
- Two simultaneous `POST /orders` with the same key create one order.
- Two simultaneous buyers of the last unit get one success and one `409`.
- The same key from a different customer does not return the first customer's order.

VERDICT: READY WITH CHANGES
