The core design is sound, and you can start tomorrow once you've settled five gaps. Each needs a sentence or two in the doc, not a redesign. The basic shape is right: stock is reserved in one transaction, the payment call happens outside any transaction with the order id as its idempotency key, unknown results go to a reconciliation job, and an alert covers orders stuck in `PENDING`. The gaps are in the failure paths, which is where most checkout bugs come from.

## Settle these before you write code

**1. Reconciliation has no rule for "the provider never saw this charge."**
- The service can crash, deploy or lose its network after step 2 commits and before step 3 sends the charge.
- Example: an order for 1 × SKU-A commits as `PENDING`, then the instance restarts. Reconciliation asks the provider about the order id and gets "not found." The design only covers settling as `PAID` or `FAILED`, so the order stays `PENDING`, SKU-A stays reserved, and the alert fires 30 minutes later.
- Decide: does "not found" mean `FAILED` with stock restored, or does the job retry the charge? Also check that the provider can actually look up a charge by your idempotency key. Step 6 depends on that and the doc assumes it.

**2. The same order can be settled twice and its stock restored twice.**
- Both instances will run the 5-minute job unless something stops them. A late reply to the original request can also overlap with the job.
- Example: an order for 3 × SKU-A is declined. Both instances' jobs see it as `PENDING` and both run step 5, so `available` goes up by 6 instead of 3.
- Fix: every status change is conditional (`UPDATE orders SET status = 'FAILED' WHERE id = :id AND status = 'PENDING'`). Stock is restored only if that update changed a row. Steps 4, 5 and 6 should all go through that one transition function.

**3. The idempotency key's scope and mismatch behaviour aren't defined.**
- If the unique constraint is on `idempotency_key` alone, keys are shared across customers. Example: customer B reuses a key that customer A already sent, and B gets back A's order. That leaks data. Make the constraint `UNIQUE (customer_id, idempotency_key)`.
- If the same key arrives with a different cart, return `422`. Don't silently return the old order.
- When two duplicate requests arrive at the same moment, both pass the existence check and one insert fails on the unique constraint. Say that this error is caught and the existing order returned, not a `500`.

**4. The doc doesn't say where prices come from.**
- `order_items.unit_price` and `orders.total` exist, but nothing says who sets them, and there is no price table.
- If they come from the client's cart, a client can send `unit_price: 0.01`.
- State that prices are looked up on the server, and name the module that owns them.

**5. Step 2 breaks the module rule.**
- "No module reads another module's tables," yet one transaction both decrements `stock` (inventory) and inserts into `orders` (orders).
- Pick an approach on purpose and write it down. My recommendation: inventory exposes `reserve(tx, items)` and `release(tx, items)`, which take the caller's transaction. Inventory still owns its SQL and the transaction stays atomic.

## Fix during the build

- **Deadlocks:** sort cart lines by SKU before the `UPDATE`s, and merge repeated SKUs into one line. Two carts that lock {A, B} and {B, A} in opposite order will deadlock.
- **Lost confirmation emails:** step 4 says "commit, then queue." A crash between those two steps loses the email for good. Write the email job to an outbox table in the same transaction as `PAID`.
- **The `202` path has no follow-up:** the client gets `202` and can't find out what happened. Add `GET /orders/{id}`.
- **Schema:** make `stock.sku` the primary key, add `CHECK (available >= 0)`, give `order_items` a primary key, and add a `CHECK` that limits `status` to the three allowed values.
- **Request duration:** a request can be held open for about 20–30 s (4 attempts × 5 s plus backoff). Check that this is under the load balancer's idle timeout.

## Tests to add

The current list covers the request path but not the code paths these gaps would break:
- reconciliation settling as `PAID`, as `FAILED`, and as "not found"
- a crash after step 2 and before step 3
- two reconciliation runs on the same order (stock restored once)
- two concurrent `POST /orders` with the same key
- two buyers racing for the last unit, against real Postgres, not run one after the other
- the same key with a different cart (`422`)
- a cart with an attacker-supplied price (ignored)

Here is the order lifecycle the design needs. The dashed transition is the one that's missing today:

```mermaid
stateDiagram-v2
    [*] --> PENDING: stock reserved
    PENDING --> PAID: charge succeeded (request or reconciliation)
    PENDING --> FAILED: declined, stock restored once
    PENDING --> FAILED: provider has no charge (missing rule)
    PAID --> [*]
    FAILED --> [*]
```

The scale (2,000 orders a day, two instances, one Postgres) is well within what this design can handle. Don't add more infrastructure.

VERDICT: READY WITH CHANGES
