The design is sound at its core and you can start building tomorrow, provided you settle three gaps in the document first; each is a few lines of design, not a rework. I reviewed the document only; there is no code to run.

The parts that usually go wrong are right: the stock reservation is an atomic conditional update, the payment call sits outside any transaction, the provider gets the order id as its idempotency key, and unknown outcomes go to a reconciliation job with an alert behind it.

## Fix before building

| # | Severity | Problem | Fix |
|---|---|---|---|
| 1 | High | **Stock can be restored twice.** Nothing says the move to `FAILED` only happens from `PENDING`, and the reconciliation job runs on both instances. | Make every status change conditional (`UPDATE orders SET status = 'FAILED' WHERE id = :id AND status = 'PENDING'`) and restore stock only if that changed a row. Same guard for `PAID`. |
| 2 | High | **Reconciliation has no rule for "provider has no record of this charge".** Step 6 only says orders settle as `PAID` or `FAILED`. | State that "no charge found" means `FAILED` plus stock restore. |
| 3 | High | **The design does not say where prices come from.** The client sends the cart, and there is no price table or pricing module. If `unit_price` and `total` come from the request, a customer can set their own price. | State that the server looks up prices and computes the total, and name the module that owns them. |

- **Case for 1:** an order holding 1 unit of SKU A is declined at the provider after a timeout. Both instances run the job at 12:05, both mark it `FAILED`, and both add 1 back. `available` rises by 2 when it should rise by 1, so you later sell a unit that does not exist.
- **Case for 2:** an instance crashes after step 2 commits but before step 3 calls the provider. The order is `PENDING`, stock is held, and no charge exists. Without a rule, the order stays `PENDING` and the stock stays locked until someone answers the 30-minute alert by hand.

## Fix during the build

| # | Severity | Problem | Fix |
|---|---|---|---|
| 4 | Medium | **Reconciliation assumes the provider can look up a charge by your order id.** Some providers cannot look up by idempotency key. No provider charge id is stored on `orders` either. | Confirm the lookup in the provider's API docs. Add a `payment_reference` column; you will also need it for refunds and support. |
| 5 | Medium | **The test plan does not cover the recovery paths.** Reconciliation has no tests at all, and no listed test involves concurrency. | Add tests for: reconciliation settling as paid, declined and not found; the job running twice on one order; two buyers racing for the last unit; two simultaneous `POST /orders` with the same key. |
| 6 | Medium | **Confirmation emails can be lost.** The email is queued after the `PAID` commit, so a crash between the two drops it. Step 6 also does not say reconciliation sends the email. | Write an "email pending" row in the same transaction as `PAID` and have the queue read from it. Use the same code path for reconciliation. |
| 7 | Medium | **The idempotency key is unique across all customers.** If customer B sends a key that customer A already used, B gets A's order back. | Make the constraint `(customer_id, idempotency_key)`. |
| 8 | Low | **Two carts with the same SKUs in opposite order can deadlock in step 2.** Postgres aborts one, which reaches the client as a 500. | Update stock rows in sorted SKU order. |
| 9 | Low | **The request can hold the connection for about 25 to 30 seconds.** That is four 5-second attempts plus backoff, and the backoff base is not stated. | Check it against the load balancer timeout, or cap the total and return `202` sooner. |
| 10 | Low | **The data model lists no keys.** `order_items` and `stock` have no primary key, and there is no foreign key or `available >= 0` check. | Add them in the first migration. |
| 11 | Low | **Three client-facing behaviours are unspecified.** | Decide: which provider errors are retried and which count as a decline; what a repeated key with a different cart returns; that a retry after `FAILED` needs a new key. |

VERDICT: READY WITH CHANGES
