**The design is sound enough to start building tomorrow. Before you write the settlement code, add four rules to the doc.** The main path holds up: reserving stock and inserting the order in one transaction, calling the payment provider outside any transaction, reusing the same idempotency key on every retry, and having the reconciliation job sweep orders stuck in `PENDING`. The gaps are all about what happens when two writers touch the same order, or when something crashes halfway through.

## Changes to make before building

**1. Only change an order's status if it is still `PENDING`, and restore stock only when that update succeeds.**
Right now nothing stops the same order from being settled twice. You run two instances. If both run the 5-minute reconciliation job, they can both settle the same order.
- **Case:** an order for 2 units is declined. Both instances mark it `FAILED` and both restore stock.
- **Wrong result:** stock goes up by 4.
- **Expected:** stock goes up by 2.

The same thing can happen when a slow request and the reconciliation job finish at the same moment. The fix is `UPDATE orders SET status = :new WHERE id = :id AND status = 'PENDING'`. Only restore stock or queue the email if that statement changed exactly one row. Use this one rule in steps 4, 5 and 6.

```mermaid
stateDiagram-v2
    [*] --> PENDING: POST /orders (stock reserved)
    PENDING --> PAID: charge succeeded (request or reconciliation)
    PENDING --> FAILED: declined or no charge found (stock restored once)
    PAID --> [*]
    FAILED --> [*]
```

**2. Say what reconciliation does when the provider has no record of the charge.**
This happens if an instance crashes after committing the order but before calling the provider. The doc only says reconciliation "settles them as PAID or FAILED". It should state that "not found" means `FAILED`, that stock is restored, and that a reconciled `PAID` order still gets its confirmation email.

**3. Decide how the order code changes the `stock` table.**
Step 2 updates `stock` and inserts into `orders` in one transaction, and step 5 does the same in reverse. That conflicts with the rule that no module reads another module's tables. My recommendation: keep the single transaction. Have the inventory module expose `reserve(tx, items)` and `release(tx, items)`, which take the transaction they should run in. That way only inventory touches `stock`. Write this down so nobody "fixes" it later by splitting the transaction.

**4. Say how a client learns the outcome after getting `202`.**
The doc doesn't define this. Add `GET /orders/{id}`, or state that repeating the `POST` with the same key is how clients poll.

## Smaller points (can be decided during the build)
- **Order total:** the design doesn't say where `unit_price` comes from. Calculate the total on the server, never from prices in the client's cart.
- **Idempotency key:** decide whether the unique constraint covers the key alone or `(customer_id, idempotency_key)`. Also decide what happens when a key is reused with a different cart. Most APIs return `422`.
- **Lost email:** if an instance crashes after the `PAID` commit but before the email is queued, the email is lost. At 2,000 orders a day that's acceptable to log and accept. The fix is to write an email row in the same `PAID` transaction and send it from there (the outbox pattern). Either way, write the decision down.
- **Schema:** make `stock.sku` a primary key, add `CHECK (available >= 0)`, and give `order_items` a primary key.

## Tests to add to the plan
- Reconciliation finds a charge that succeeded, a charge that was declined, and no charge at all.
- Two reconciliation runs settle the same order at once, and stock is restored only once.
- Two simultaneous `POST`s arrive with the same key.
- Two customers try to buy the last unit at the same time. The current "buying the last unit" test only has one buyer.
- A decline restores the stock.

The load needs no change: 2,000 orders a day is light work for one Postgres database. The worst-case request time is about 27 s (4 attempts × 5 s plus backoff). That's well under the 2-minute age at which reconciliation picks up an order, so the job won't collide with a request that's still running normally.

VERDICT: READY WITH CHANGES
