The design is close: the core flow is sound, but four gaps should be closed in the doc before you build, because each one produces wrong stock, stuck orders or wrong charges. All four are small edits, about an hour of doc work in total, so starting tomorrow is realistic.

The parts that hold up are the atomic stock reservation, the charge made outside the transaction with the order id as the provider's idempotency key, and the `PENDING` plus reconciliation path for unknown results. The level of machinery also suits 2,000 orders a day.

## Fix before building

**1. Status changes are not guarded, so stock can be restored twice (high).**
- **Evidence:** the context says two instances, and step 6 does not say the reconciliation job runs on only one of them. Steps 5 and 6 do not make the change to `FAILED` conditional on the order still being `PENDING`.
- **Failing case:** order A holds 1 unit of a SKU and its charge was declined. Both instances' jobs pick up A in the same 5-minute run, and both mark it `FAILED` and add 1 back. `available` ends 1 higher than the real stock, and you later sell a unit you don't have.
- **Fix:** make every 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.

**2. Reconciliation has no rule for "the provider has never heard of this order" (high).**
- **Evidence:** step 6 says the job settles orders as `PAID` or `FAILED`, with no third outcome.
- **Failing case:** an instance restarts, for example during a deploy, after step 2 commits and before step 3 calls the provider. The order is `PENDING` with stock reserved and the provider has no charge for it. The order stays `PENDING`, the stock stays held, and the 30-minute alert fires.
- **Fix:** state that "no charge found" on an order older than 2 minutes is settled as `FAILED` with stock restored. Also say what happens if the provider reports the charge as still processing (leave it for the next run).

**3. The design does not say where prices come from (high if they come from the client).**
- **Evidence:** step 1 says the client sends "the cart". There is no price or product table in the data model, and no step computes `unit_price` or `total`.
- **Failing case:** if the cart carries prices, a client posts `unit_price: 0.01` for a 500.00 item and is charged 0.01.
- **Fix:** name the server-side price source and state that `total` is computed by the service.

**4. Quantity is not validated, and a negative quantity adds stock (medium).**
- **Evidence:** the step 2 update is `available = available - :qty WHERE available >= :qty`, with no bound on `:qty`.
- **Failing case:** a cart line with `quantity: -5` passes the check and raises `available` by 5. Depending on issue 3, it may also reduce the total.
- **Fix:** reject `quantity < 1` at the route and add `CHECK (quantity > 0)` and `CHECK (available >= 0)`.

## Settle while building

| # | Issue | Severity | Evidence and fix |
|---|---|---|---|
| 5 | Two orders with the same SKUs in opposite order can deadlock | Medium | Step 2 updates several `stock` rows in one transaction. Order X locks SKU-1 then SKU-2 and order Y locks SKU-2 then SKU-1; Postgres aborts one and that customer gets a 500. Update rows in sorted SKU order and merge duplicate SKUs in a cart. |
| 6 | Confirmation email can be lost | Medium | Step 4 queues the email after the commit, so a crash between the two means a `PAID` order with no email. Step 6 does not say the reconciliation job queues an email either, so a customer who got `202` and was then charged may hear nothing. Queue the email from both paths, ideally by writing an outbox row in the same transaction as `PAID`. |
| 7 | Idempotency key is unique globally, not per customer | Medium | Step 1 says a repeated key returns the existing order. If customer B sends a key customer A already used, B receives A's order. Make the constraint `(customer_id, idempotency_key)`. Also decide what a repeated key with a different cart returns (suggest `422`). |
| 8 | The single-transaction steps contradict the module rule | Medium | Steps 2 and 5 change `stock` and `orders` in one transaction, while "Code structure" says no module reads another's tables. Both can hold if `OrderCheckout` owns the transaction and passes it to the inventory and orders modules. Write that down. |
| 9 | Retry rule is not specific | Low | Step 3 says "up to 3 retries" without saying for which errors. Retry only timeouts and 5xx. The worst case is about 20 s of timeouts plus backoff, so check it fits under the load balancer and client timeouts. |
| 10 | No way for the client to learn the result after `202` | Low | No `GET /orders/{id}` is listed, and the wait can be about 7 minutes. Add the endpoint and the polling expectation. |
| 11 | Retrying after a decline is not defined | Low | Reusing the same `Idempotency-Key` returns the `FAILED` order forever. State that a new attempt needs a new key. |
| 12 | The provider's charge id is not stored | Low | `orders` has no column for it, and refunds and support lookups will need it. |
| 13 | Keys and indexes are not stated | Low | The data model lists no primary keys, no foreign key from `order_items` to `orders`, and no index for the reconciliation query on `(status, created_at)`. |

## Tests to add to the plan

The listed tests cover the request path only. Add these:
- **Reconciliation outcomes:** paid, declined, no charge found, and provider unreachable.
- **Double reconciliation:** the job run twice at once on one order restores stock once.
- **Concurrent last unit:** two simultaneous buyers of the last unit give one success and one `409`.
- **Concurrent duplicate:** two simultaneous `POST /orders` with the same key create one order and one reservation.
- **Crash before charge:** a crash between reserve and charge is cleaned up by the job.
- **Input and ordering:** negative quantity is rejected, and overlapping carts in opposite SKU order both complete.
- **Email:** it is queued when the reconciliation job settles an order as `PAID`.

## Speculative, not blocking

- `numeric(12,2)` cannot hold three-decimal currencies such as KWD; this only matters if you plan to sell in them.
- If the provider supports asynchronous payment methods such as 3-D Secure redirects, `PENDING` will need a longer life than the 30-minute alert assumes.
- The design has no refund or cancel status; I assumed that is out of scope for this revision.

VERDICT: READY WITH CHANGES
