The core of this design is solid: the conditional stock update, calling the payment provider outside any transaction, reusing the order id as the provider's idempotency key, and the reconciliation job are all the right choices. You can start building tomorrow, but first add about a dozen lines to the doc. Two of the gaps can lose stock or charge a customer for a failed order, and they're much cheaper to fix on paper than in code. You asked for everything, so the full list is below, most severe first.

## High: fix in the doc before writing code

**1. Two parts of the system can settle the same order, and stock can be restored twice.** The request handler (steps 4–5) and the reconciliation job (step 6) can both write a final status to the same order. With two instances, the job may also run twice at once.
- Example: the job's two copies both see order A as `PENDING` with a declined charge. Each marks it `FAILED` and adds the quantity back. One unit becomes two, and you oversell.
- Fix: make every settle step conditional, e.g. `UPDATE orders SET status = 'FAILED' WHERE id = :id AND status = 'PENDING'`, and only restore stock if that update changed a row. Have the job pick orders with `SELECT … FOR UPDATE SKIP LOCKED`, or run it on one instance only.

**2. Orders settled as `FAILED` by the reconciliation job never get their stock back.** Step 5 restores stock on a decline, but step 6 only says "settles them as `PAID` or `FAILED`".
- Example: a charge times out on all attempts, and the job later learns it was declined. The order becomes `FAILED`, but the 2 units it reserved stay out of `available` forever.
- Fix: the job should call the same settle-as-failed code that step 5 uses.

**3. The doc doesn't say what happens when the provider has no record of the charge.** If an instance crashes after step 2 commits but before step 3 reaches the provider, the order is `PENDING` and was never charged. The reconciler asks for its status, and the provider says "not found".
- Without a rule, the order sits in `PENDING` holding stock until the 30-minute alert fires, and then a person has to decide.
- Fix: decide the rule. Either retry the charge (safe, because the idempotency key is the order id) or mark it `FAILED` after a cutoff. Also write down how long the provider keeps idempotency keys, since many expire after about 24 hours.

**4. `unit_price` and `total` have no defined source.** None of the three tables holds prices, so the only data available is the client's cart.
- Example: a client sends `unit_price: 0.01` for a $40 item, and the order is created at that price.
- Fix: state that prices come from a server-side catalog. If that's another service or table, name it.

**5. Idempotency keys are unique across all customers, not per customer.** A key collision, or a malicious client reusing someone else's key, would return another customer's order.
- Fix: put the unique constraint on `(customer_id, idempotency_key)`. Also say what happens when a request reuses a key with a different cart (the usual answer is `422`).

## Medium: decide before the code that depends on them

**6. Two simultaneous requests with the same key aren't covered.** Both requests reserve stock. The second one then blocks on the unique index and fails with a unique-violation error, which becomes a `500` unless you plan for it. Catch that error, roll back, and return the existing order.

**7. Concurrent orders can deadlock.** Order X updates SKU A then B while order Y updates B then A, and Postgres aborts one of them. Fix: sort SKUs before running the updates, and merge cart lines that share a SKU.

**8. A crash can lose the confirmation email.** Step 4 commits `PAID` and then queues the email, so a crash between the two means no email. The doc also doesn't say whether orders the reconciler marks `PAID` send an email at all. Fix: write the email job to an outbox table in the same transaction as the `PAID` update, and have both settle paths use it.

**9. The module boundary rule and the transactions contradict each other.** Step 2 and step 5 change `stock` (inventory module) and `orders` (orders module) in one transaction, but "no module reads another module's tables". Say how this works. The usual answer is that `OrderCheckout` owns the transaction and passes it into the inventory and orders modules' methods.

**10. The doc doesn't store the provider's charge id.** Support needs it, refunds need it, and reconciliation is easier with it. Add `payment_reference` (or a `payments` table).

**11. The API contract is incomplete.**
- The success response code isn't stated (`201`?), and neither is the decline response (`402`? `200` with `FAILED`?).
- A client that gets `202` has no endpoint to check the final status. Add `GET /orders/{id}`.

**12. The test list is missing the riskiest paths.** Add tests for:
- the reconciler settling as `PAID`, as `FAILED` with stock restored, and as "not found"
- the reconciler and the request handler settling the same order at once
- two concurrent requests with the same key
- two buyers racing for the last unit (the current last-unit test is single-buyer)
- a crash between step 2 and step 3
- a decline restoring stock

## Low: tidy-ups

13. One request can run for about 25–30 s (4 attempts × 5 s plus backoff), which is near common load-balancer timeouts. Check your load balancer's timeout, or shorten the retry budget.
14. Say that only timeouts and 5xx responses are retried, never declines.
15. The data model has no keys or constraints. Add primary keys (`order_items (order_id, sku)`, `stock (sku)`), foreign keys, `CHECK (available >= 0)`, `CHECK (quantity > 0)`, and a `CHECK` or enum on `status`.
16. Add an index on `orders (status, created_at)` for the reconciler's query.
17. Add a short non-goals line: refunds, cancellation, and partial fulfillment are out of scope.
18. Add a logging rule that card and payment details never go in logs.

After fixes 1–3, the order lifecycle should look like this, with every arrow guarded by `WHERE status = 'PENDING'`:

```mermaid
stateDiagram-v2
    [*] --> PENDING: stock reserved
    PENDING --> PAID: charge succeeded (request or reconciler) → outbox email
    PENDING --> FAILED: declined, or not found after cutoff → restore stock once
```

None of this changes your architecture. It's all edge-case rules and constraints added to a structure that already works. Items 1–5 are about an hour of doc edits, and you can start on the data model and stock reservation code tomorrow in parallel.

VERDICT: READY WITH CHANGES
