I read design.md (revision 3). It's close to ready. The overall approach is sound: stock is reserved in one transaction, the payment call happens outside any transaction with a stable idempotency key, and unknown payment results go to a reconciliation job. Expected volume (2,000 orders a day) is far below anything Postgres would notice. One thing needs fixing before you write code, because it decides how the status updates are written. The rest are small additions to the doc.

## Must fix before building

**1. Settling an order can happen twice, which puts stock back twice.**
The doc never says that moving an order out of `PENDING` only works if it is still `PENDING`. Three things can settle the same order: the request path (steps 4–5), the reconciliation job on instance A, and the same job on instance B (you run two instances, and nothing limits the job to one).

Here's what goes wrong: a customer buys the last unit of SKU `X`, so stock goes to 0. The charge result is unknown and the order stays `PENDING`. The job runs on both instances at the same time, and both are told the charge was declined. Both mark the order `FAILED` and both add 1 back. Stock for `X` is now **2**, but it should be **1**. The same gap lets a late `FAILED` overwrite a `PAID` order.

Fix: make every change of status a guarded update, and only touch stock if that update actually changed a row:

```sql
UPDATE orders SET status = 'FAILED', updated_at = now()
WHERE id = :id AND status = 'PENDING';
-- restore stock only if this updated 1 row, in the same transaction
```

Do the same for `PAID`. Also either make sure only one instance runs the job, or have the job take rows with `SELECT … FOR UPDATE SKIP LOCKED`. The guarded update alone already prevents the double restore, so this second part just saves the extra calls to the provider.

```mermaid
stateDiagram-v2
    [*] --> PENDING: POST /orders, stock reserved
    PENDING --> PAID: charge succeeded (only if still PENDING)
    PENDING --> FAILED: declined or no charge (only if still PENDING), stock restored
    PAID --> [*]
    FAILED --> [*]
```

## Should add to the doc (small)

2. **The job has no rule for "the provider has no record of this charge".** This happens if an instance crashes after committing the order but before calling the provider. Right now the order stays `PENDING` forever and its stock stays reserved, with only the 30-minute alert to catch it. Pick a rule: mark it `FAILED` and restore stock, or retry the charge using the same order id as the idempotency key.
3. **Two identical `POST /orders` arriving at the same moment.** The unique constraint means one of them will fail on insert. That transaction rolls back, so the stock is safe. But the doc should say the service catches that error and returns the existing order, not a `500`. Also decide whether the key is unique across all customers or only per customer, and what happens when the same key arrives with a different cart.
4. **Confirmation email.** If the service crashes after the `PAID` commit but before the email is queued, the email is lost. Writing the email job into the same transaction as the status change, and sending it from a background worker (the "outbox" pattern), fixes this. Also state that orders the job settles as `PAID` get the email too.
5. **What a client does after a `202`.** Nothing in the doc lets the client find out the final status. Add `GET /orders/{id}` or say how the client is told.
6. **Module boundaries versus the one transaction in step 2.** "No module reads another module's tables" is fine. But step 2 and step 5 write to both `stock` and `orders` in one transaction. State that the inventory module offers reserve and restore functions that run inside the caller's transaction, so nobody ends up writing SQL against `stock` from the orders code.

## Tests to add

- Two job runs, or a job run plus the request path, settling the same order at once: it is settled once and stock is restored once.
- Two concurrent duplicate `POST /orders` calls: both get the same order and stock drops by one.
- The job settling an order as `PAID`, as `FAILED`, and when the provider has no record of the charge.
- A late `FAILED` arriving after `PAID`: nothing changes.

Item 1 is a small code change, but it's a correctness bug that would quietly inflate stock. Write it into the doc and into the first tests. Items 2–6 are short additions you can make before or on day one.

VERDICT: READY WITH CHANGES
