**The design is sound and you can start building tomorrow, provided you first fix two gaps in how `PENDING` orders are settled.** Both can corrupt stock counts, and both are small edits to the doc, not a redesign. The core of the flow holds up.

## Must fix before building

**1. An order can be settled as `FAILED` twice, restoring its stock twice.**
Nothing in the design says the `PENDING` → `FAILED` transition happens only once, and you run two instances, so the reconciliation job runs twice.
- **Case:** an order for the last unit of SKU A sits `PENDING` and `available` is 0. Both instances' jobs pick it up in the same 5-minute tick, both get "declined" from the provider, and both run step 5.
- **Wrong result:** `available` is 2, so you sell a unit that doesn't exist.
- **Expected:** `available` is 1.
- **Fix:** make every settlement a guarded transition, `UPDATE orders SET status = ... WHERE id = :id AND status = 'PENDING'`, and restore stock or queue the email only if that update changed a row. Apply this to steps 4, 5 and 6.

**2. The reconciliation job has no rule for "the provider has never heard of this charge".**
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 step 3 sends anything, or all four attempts time out before reaching the provider. The job asks for the charge status and gets "not found".
- **Wrong result:** the order stays `PENDING` forever with its stock locked, and the only signal is the 30-minute alert.
- **Expected:** the order is marked `FAILED` and its stock restored.
- **Fix:** state that "not found" for an order older than 2 minutes settles as `FAILED` with stock restored, and that the job follows the same paths as steps 4 and 5, including the confirmation email on `PAID`.

## Should specify, but can be done during the build

- **Idempotency key scope.** Make the unique constraint `(customer_id, idempotency_key)`. With a global key, a second customer who sends the same key gets the first customer's order back.
- **Deadlocks on multi-item carts.** Order 1 reserves SKU A then B while order 2 reserves B then A; Postgres kills one and the client gets a 500. Reserve in sorted SKU order.
- **Where prices come from.** There is no price table, and the doc doesn't say whether `unit_price` and `total` are computed server-side. If they come from the cart, a client can set its own price.
- **How the client learns the outcome after a `202`.** The doc has no `GET /orders/{id}` or equivalent.
- **Lost email on crash.** If the instance dies between committing `PAID` and queueing the email in step 4, the email is never sent. At 200 orders a day this may be acceptable; either write that down as accepted or queue the email in the same transaction.

## Tests to add to the plan

- Two settlements of the same order running concurrently restore stock exactly once.
- Reconciliation when the provider returns "not found".
- Reconciliation for a charge that succeeded but was never marked `PAID`, including the email.
- Two concurrent `POST /orders` with the same key produce one order and one stock decrement.
- Two concurrent orders with overlapping SKUs in opposite order.

## What I checked and found solid

- The charge runs outside the database transaction.
- The order id is the provider's idempotency key, so retries cannot double-charge.
- The conditional stock update prevents overselling on the reserve side.
- The 2-minute reconciliation threshold sits safely above the roughly 30-second worst-case retry window.
- One Postgres and two instances is the right size for 2,000 orders a day.

VERDICT: READY WITH CHANGES
