**design.md is close, but it needs about five fixes before you build. Most are small, and two of them (the reconciler gaps) change what you build first.**

## Must fix before building

1. **The reconciler can leak stock or double-restore it.**
   - Step 5 restores stock when a charge is declined. Step 6 says the reconciler "settles as `PAID` or `FAILED`" but never says it restores stock.
   - Example: a charge times out, the order stays `PENDING`, and the reconciler later learns it was declined. The order becomes `FAILED` and the reserved units stay gone forever.
   - Both the request path and the reconciler can settle the same order. Make every settle a conditional update (`... WHERE status = 'PENDING'`) and restore stock only if that update changed a row. Put this in one shared "settle order" function.

2. **The reconciler's case of "provider has no record of this charge" is undefined.**
   - Example: the process crashes after step 2 commits but before step 3 calls the provider. The order is `PENDING`, stock is reserved, and the provider has nothing for that order id.
   - The doc doesn't say what the reconciler does here. Pick one: retry the charge (safe, because the order id is the idempotency key) or mark the order `FAILED` and restore stock. Without this, the order sits until the 30-minute alert.

3. **The reconciler runs on two instances.** Both will pick up the same `PENDING` orders every 5 minutes. Specify `SELECT ... FOR UPDATE SKIP LOCKED` or an advisory lock. Fix 1 makes this safe, but state it.

4. **Step 2 contradicts the "no module reads another module's tables" rule.** One transaction updates `stock` (inventory) and inserts into `orders` (orders). You need to decide how that works: pass a shared transaction handle owned by `OrderCheckout` and have inventory expose `reserve(tx, items)`, or relax the rule. The first option keeps the boundary, but write it down.

5. **The `202` response has no follow-up endpoint.** The client gets `202` but the doc has no `GET /orders/{id}` (or equivalent) to check the result. Add it to the design and the tests.

## Should fix (cheap now, costly later)

- **Lost confirmation email.** If the process dies after the `PAID` commit but before the email is queued, the email is never sent. Write an outbox row in the same transaction as `PAID` instead of queuing after commit.
- **Duplicate key race.** Two concurrent `POST`s with the same key: the loser's insert hits the unique constraint and rolls back. Say that it then reads and returns the winner's order, not a `500`. Also decide what happens when the same key arrives with a different cart (suggest `422`).
- **Schema gaps.**
  - No primary keys or foreign keys. `stock.sku` needs a primary key and `order_items` needs an index on `order_id`.
  - Add a `CHECK (available >= 0)` on stock as a backstop.
  - Add a `CHECK` on `status`.
  - Decide whether the idempotency key is unique globally or per customer.
- **Request duration.** 5 s × 4 attempts plus backoff is more than 20 s in one HTTP request. Check that against the load balancer timeout. Also confirm the reconciler's 2-minute age cutoff is longer than the worst-case retry time, so it can't settle an order a live request is still working on.

## Tests to add

The current list covers the charge outcomes and the last unit of stock. It misses the riskiest parts:
- The reconciler settling to `PAID` and to `FAILED`, including the stock restore.
- The reconciler racing a live request on the same order.
- The "provider has no record" case from fix 2.
- Decline restores stock. A multi-item cart where item 2 is out of stock rolls back item 1.
- Email failure leaves the order `PAID`.
- Concurrent duplicate `POST`s.

Following your TDD rule, write the reconciler tests first.

The scale (2,000 orders a day, one database) is fine for this design, and nothing needs to be more complex.

VERDICT: READY WITH CHANGES
