The design in `design.md` is sound enough to start building tomorrow, provided you make three corrections to the doc first; none of them changes the overall shape. The core is right: stock is reserved atomically, the charge happens outside the transaction with the order id as the provider idempotency key, and unknown outcomes are left to a reconciliation job.

## Fix before building

1. **Settling an order can run twice and restore stock twice.** The design does not say the status change is conditional on the order still being `PENDING`, and both instances would run the reconciliation job.
   - **Failing case:** an order for 1 unit is `PENDING` and stock is 0. Both instances' jobs see the charge was declined, and each marks it `FAILED` and adds 1 back. Stock is now 2 when it should be 1, and you oversell a unit.
   - **Fix:** every settle uses `UPDATE orders SET status = … WHERE id = :id AND status = 'PENDING'`, and restores stock or queues the email only if that update changed a row. This applies to steps 4, 5 and 6.

2. **Reconciliation has no defined answer for "the provider has never heard of this order", and nothing to look the charge up by.**
   - **Failing case:** the instance crashes after step 2 commits and before step 3 sends the charge. The provider has no charge, so the order can be settled as neither `PAID` nor `FAILED`. It stays `PENDING` and holds stock until the 30-minute alert.
   - **Fix:** state that "no charge found" settles as `FAILED` with stock restored. This is safe because the in-request retries finish in about 30 seconds, well inside the 2-minute threshold.
   - **Check with the provider:** confirm its API can look a charge up by your order id. Some only look up by their own charge id, or by metadata you must attach to the charge.
   - **Schema:** add a `payment_reference` column to `orders`; you will also need it for refunds and support.

3. **The idempotency key is unique globally, not per customer.**
   - **Failing case:** customer B sends a key that customer A already used, and gets A's order back.
   - **Fix:** make the constraint unique on `(customer_id, idempotency_key)`. Return `422` if the same key arrives with a different cart.

## Smaller additions to the doc

- **Deadlocks:** two orders reserving the same SKUs in opposite order (A then B, B then A) will deadlock. Update stock rows in sorted SKU order.
- **Module boundary:** steps 2 and 5 write `stock` and `orders` in one transaction, which sits awkwardly with "no module reads another module's tables". State that `OrderCheckout` owns the transaction and passes it to the inventory and orders modules.
- **Price source:** state that `unit_price` and `total` are computed server-side, never taken from the client cart.
- **Lost email:** a crash between the `PAID` commit and queueing the email loses it for good, because reconciliation only looks at `PENDING` orders. Write an outbox row or `confirmation_queued_at` in the same transaction as `PAID`.
- **Client after `202`:** the design does not say how the client learns the outcome. Presumably it polls `GET /orders/{id}`; write that down.
- **Request duration:** the worst case is about 27 seconds (4 attempts at 5 s plus backoff). Check that the load balancer timeout is longer than that.
- **Constraints:** add primary keys, `CHECK (available >= 0)` on `stock`, and a check on allowed `status` values.

## Test plan gaps

The listed tests cover the single-request paths only. Add:

- Two concurrent buyers for the last unit: exactly one succeeds.
- Two concurrent `POST`s with the same key: one order, one reservation.
- Reconciliation for each outcome: paid, declined, not found, still unknown.
- Reconciliation run twice on the same order: stock is restored once.
- A crash between reserve and charge.
- A crash between charge success and marking the order `PAID`.

VERDICT: READY WITH CHANGES
