**Not ready to build from: three flaws in the core flow would cause double charges, oversold stock and duplicate orders.** Each fix is small, but it changes the design, so make them in `design.md` first. I only read the file. I didn't check it against any code.

## Blockers

1. **Retries can charge the customer twice (step 3).**
   - **The flaw:** The provider key is `<order id>-<attempt number>`, so every retry carries a different key. The provider treats each retry as a new charge.
   - **Failing case:** Attempt 1 times out after the provider charged the card. Attempt 2 uses key `abc-2` and charges again. The customer pays twice, and the order is marked `PAID` once.
   - **Expected:** Use one stable key per order (`<order id>`) on every attempt, so the provider returns the original result. Log the attempt number separately for tracing.
   - **Related:** Reconciliation (step 6) has to find a charge by order. With per-attempt keys it can't tell which charge is the real one.

2. **Stock can be oversold (step 2).**
   - **The flaw:** The service reads `available`, checks it, then writes `available - quantity`. With no row lock, two concurrent checkouts both read the same value.
   - **Failing case:** `available = 1`. Two customers each order 1. Both read 1, both pass the check, both write 0, and two orders exist for one unit.
   - **Expected:** Use a single atomic statement: `UPDATE stock SET available = available - $q WHERE sku = $s AND available >= $q`. Treat zero rows updated as out of stock. Add `CHECK (available >= 0)` as a backstop.
   - **Test gap:** The "buying the last unit" test must run two checkouts at the same time. A sequential test passes on the broken design.

3. **Duplicate orders under the load balancer (step 1).**
   - **The flaw:** Idempotency keys live in a per-instance in-memory map. There are two instances, and the map is lost on restart.
   - **Failing case:** The client posts with key K and the first instance handles it. The client retries after a timeout and the load balancer sends it to the second instance. That instance has never seen K and creates a second order and a second charge.
   - **Expected:** Store the key in Postgres with a unique constraint, for example `orders.idempotency_key` unique per customer. Say what a repeat request returns while the first is still in flight.

## Should fix before or early in the build

- **Money type:** `total` and `unit_price` are `double precision`, which gives rounding errors. Use `numeric(12,2)` or integer minor units.
- **Missing schema constraints:** There are no primary keys on `order_items` and `stock` (`sku`), no foreign keys, and no `CHECK` constraints.
- **Reconciliation runs on both instances:** Two instances will both settle the same `PENDING` order. Use `FOR UPDATE SKIP LOCKED` or an advisory lock. Also add a rule that a settled order can't change status again.
- **Stock restore is underspecified:**
  - Step 6 says reconciliation settles an order as `FAILED` but doesn't say whether it restores stock. It must, or stock leaks.
  - The restore must run only once per order, tied to the status change in the same transaction.
- **Email can be lost (step 4):** The service commits `PAID` and then queues the email. A crash between the two means no email is sent. Write the email request in the same transaction (an outbox table).
- **Modules versus the transaction:** "No module reads another's tables" conflicts with step 2, which updates `stock` and inserts into `orders` in one transaction. Say which module owns that transaction, for example `OrderCheckout` calling an inventory interface within a shared transaction.

## Test plan gaps
- Add a concurrent oversell test, a concurrent duplicate-key test across both instances, and an assertion that retries reuse the same provider key.
- Add a reconciliation test where a charge succeeded at the provider but the order is still `PENDING`, and one for `FAILED` restoring stock exactly once.
- The existing list is a good start. Keep it.

## What is good
- The flow is sound: stock and order are committed first, the charge runs outside the transaction, and a reconciliation job settles unknown outcomes.
- The 5 s timeout with retries, the `202` for unknown results, the 30-minute alert, and thin routes with a service class all fit the scale of 200 to 2,000 orders a day.

VERDICT: NOT READY
