The design is mostly ready. The basic structure is right: stock is reserved with a conditional update, the payment call happens outside any transaction, the order id is sent as the payment idempotency key, and a reconciliation job settles unknown results. You can start tomorrow, but six gaps should be fixed in the doc first. Each is a sentence or two to write. Two of them can cause oversold stock or orders stuck at `PENDING` forever.

## Fix before building

**1. Stock can be restored twice when the request and the reconciliation job both settle an order.**
Example: the charge times out on every retry, so the order stays `PENDING`. The provider later declines it. The request path and the reconciliation job both see the decline and both run "mark `FAILED` and restore stock". The stock for that order is now counted twice, so you sell units you don't have.
*Fix:* every status change is conditional (`UPDATE orders SET status = 'FAILED' WHERE id = :id AND status = 'PENDING'`). Stock is restored, or the email queued, only if that update changed a row. Use one shared "settle order" function for both the request path and the job.

**2. The reconciliation job's outcomes aren't fully defined.**
- When the job settles an order as `FAILED`, step 5's stock restore must also run, and when it settles one as `PAID`, the email must be queued. The doc doesn't say either happens. Item 1's shared function covers both.
- The doc has no rule for when the provider has no record of the charge. Example: an instance crashes after committing the order (step 2) but before calling the provider (step 3). The provider has nothing for that order id, so the job can't settle it, and the order sits at `PENDING` until the 30-minute alert fires. Write the rule down, for example: "if the provider has no charge after N minutes, mark `FAILED` and restore stock."

**3. Orders that buy the same items concurrently can deadlock.**
Example: order 1 reserves SKU A then B, while order 2 reserves B then A. Each waits on a row the other has locked, and Postgres kills one of the transactions. *Fix:* reserve items in SKU order.

**4. The client has no way to learn the result after a `202`.**
The doc only defines `POST /orders`. Add a `GET /orders/{id}` endpoint, or state that the client re-sends the same `POST` to poll for the result.

**5. The doc doesn't say where prices come from.**
"The client sends the cart" could mean `unit_price` and `total` are taken from the request, which would let a client pick its own price. State that both are computed on the server from a trusted price source. That source also needs to appear in the data model.

**6. The tests don't cover the riskiest parts.** Add tests for:
- the reconciliation job: provider reports paid, declined, and no record;
- the job and a live request settling the same order (stock restored exactly once);
- two concurrent requests for the last unit (exactly one succeeds, the other gets `409`);
- two concurrent `POST`s with the same `Idempotency-Key`. The second one fails on the unique constraint after it has reserved stock, so it must roll back and return the first order, not an error.

```mermaid
stateDiagram-v2
    [*] --> PENDING: POST /orders (stock reserved)
    PENDING --> PAID: charge succeeds (request or reconciliation job), then queue email
    PENDING --> FAILED: charge declined, or no charge found after N min, then restore stock
    note right of PENDING: Every change is conditional on status = PENDING, so it runs only once
```

## Worth noting, not blocking

- **Lost confirmation emails.** The email is queued after the commit, so a crash between the two loses it. Nothing retries it, because the order is already `PAID`. At 2,000 orders a day this will be rare. If it matters, write the queue entry in the same transaction as the status change (the "transactional outbox" pattern).
- **Modules sharing a transaction.** Step 2 changes `stock` and `orders` in one transaction, while the module rule says no module reads another module's tables. That works if `OrderCheckout` passes one transaction to the inventory and orders modules. Decide that interface up front so nobody bypasses it with a cross-module query.
- **The job runs on both instances.** That is harmless once item 1 is in place, but a Postgres advisory lock (or `FOR UPDATE SKIP LOCKED`) avoids doing the work twice.

VERDICT: READY WITH CHANGES
