**The design is close, but it needs a few fixes first. Two of them, the stock leak and the missing way to read an order's status, are one-line edits you can make tonight. You can start building tomorrow on the parts the fixes don't touch: schema, `POST /orders` and the reserve step.**

The flow is sound: stock is reserved atomically, the charge happens outside a transaction, the order id is the provider's idempotency key, and a reconciliation job covers unknown outcomes. The problems are in the gaps around it.

## Must fix before building the affected part

**1. High: reconciliation can leak stock (step 6).**
- Step 5 restores stock when a charge is declined. Step 6 settles orders as `FAILED` from reconciliation but never says to restore stock.
- Case: the charge times out on every retry, the order stays `PENDING` with 1 unit reserved, and reconciliation later finds the charge was declined. The order becomes `FAILED` and the unit is never returned. Stock drifts down permanently.
- Fix: put "mark `FAILED` and restore stock" in one shared operation that step 5 and reconciliation both call.
- The status change should be `UPDATE ... WHERE status = 'PENDING'`, and stock is restored only if a row changed. That also stops a double restore if the request and the job race.

**2. High: no way for the client to learn the outcome of a `202`.** There is no `GET /orders/{id}`. Without it, a client holding a `PENDING` order can't find out if it was paid. Add the endpoint to the design.

**3. Medium: reconciliation runs on two instances.** Both instances would run the job every 5 minutes and process the same orders. The status-change guard from #1 makes this safe but wasteful. Pick one approach, such as `SELECT ... FOR UPDATE SKIP LOCKED` or an advisory lock, and write it down.

**4. Medium: the design assumes things about the provider that nobody has checked.**
- Can the provider look up a charge by our idempotency key?
- What should happen when it reports "no such charge", meaning the request never arrived? That case should settle as `FAILED`, and the design doesn't say so.
- How long does the provider remember idempotency keys?

Confirm these with the provider's docs before you build step 6.

**5. Medium: concurrent updates to stock rows can deadlock (step 2).** Two orders that reserve the same SKUs in different orders will deadlock. Sort the items by SKU before the updates.

**6. Medium: the module rule conflicts with step 2.**
- "No module reads another module's tables" conflicts with one transaction that updates `stock` (inventory) and inserts into `orders` (orders).
- Decide how the transaction spans modules. For example, `OrderCheckout` opens the transaction and passes it to each module. Name that choice in the doc.

**7. Medium: the idempotency key handling is under-specified.**
- The unique constraint should cover `(customer_id, idempotency_key)`, not the key alone, because keys are client-generated.
- Two simultaneous requests with the same key will hit a unique violation. The design should say that case returns the existing order.
- It should also say what happens when the same key arrives with a different cart.

**8. Medium: nothing says where `unit_price` and `total` come from.** If the client sends them, a customer can set their own price. State that the server looks up prices and computes the total.

## Fix soon (safe to defer past the first build)

- **Low–medium:** the confirmation email is queued after the commit, so a crash in between loses it silently. An outbox row written in the `PAID` transaction fixes that.
- **Low:** the schema has no primary keys or constraints.
  - `stock.sku` needs to be unique.
  - `stock.available` needs a `CHECK (available >= 0)`.
  - Foreign keys are missing from `order_items`.
  - The reconciliation query needs an index on `(status, created_at)`.
- **Low:** the request can block up to about 20 s or more (4 attempts × 5 s plus backoff). Check that this fits the load balancer's timeout.
- **Low:** the design has no authentication or authorization on `POST /orders`.

## Tests

The test list skips reconciliation, which is the most intricate part. Add these cases:
- Reconciliation settles `PAID`.
- Reconciliation settles `FAILED` and restores stock exactly once.
- Two concurrent duplicate `POST /orders` requests.
- Two concurrent orders for the same SKUs in opposite order.
- A failed email doesn't fail the order.

Per your TDD standard, write the reconciliation tests before the job.

VERDICT: READY WITH CHANGES
