The design is close to ready, and you can start building tomorrow if you make a few fixes first. The core of it is right:

- Stock is reserved with one conditional update.
- The payment call happens outside any database transaction.
- The order id is sent to the provider as its idempotency key.
- The email goes out only after the order is committed.
- A reconciliation job and an alert cover lost payment results.

Most of what's below is detail the doc doesn't spell out yet, not a flaw in the approach. Two items can corrupt data and should be fixed before you write code: #1 and #3.

## High: fix before building

**1. Order status changes aren't guarded, so stock can be put back twice.** Nothing says a status change only applies if the order is still `PENDING`. If both instances run the reconciliation job, or a slow request and the job finish at the same time, both can settle the same order.
- Example: an order for 2 units of SKU A leaves `available = 0`. Both instances see "declined", both mark it `FAILED`, and both add 2 back. Stock ends at 4 when only 2 exist.
- Fix: `UPDATE orders SET status = :new WHERE id = :id AND status = 'PENDING'`. Restore stock only if that update changed exactly one row. Also say whether the job runs on one instance only, for example behind a Postgres advisory lock.

```mermaid
stateDiagram-v2
    [*] --> PENDING: stock reserved, order inserted
    PENDING --> PAID: charge succeeded (only if still PENDING)
    PENDING --> FAILED: declined or no charge found (only if still PENDING), then restore stock
    PAID --> [*]
    FAILED --> [*]
```

**2. Reconciliation has no rule for "the provider has no record of this charge."** If every attempt timed out before reaching the provider, the job finds nothing. The order stays `PENDING` forever and the stock stays held. The 30-minute alert fires, but nothing resolves it.
- Fix: after N minutes with no charge found, either retry the charge with the same order id, or mark the order `FAILED` and release the stock.
- Also check how long the provider honours idempotency keys (often 24 hours), so a late retry can't create a second charge.

**3. Cart quantities aren't validated.** With `quantity = -5`, the check `available >= -5` passes and stock goes up by 5. Require `quantity > 0` in the API. Back it up with `CHECK (quantity > 0)` on `order_items` and `CHECK (available >= 0)` on `stock`.

**4. The doc doesn't say where prices come from.** `order_items.unit_price` and `orders.total` are stored, but there's no price lookup. If they're taken from the client's cart, a client can set its own price. State that the server looks up prices (from which module?) and computes the total.

## Medium: settle while building

**5. The idempotency key is unique across all customers, and a mismatched body is never detected.**
- Make the unique constraint `(customer_id, idempotency_key)`.
- If the same key arrives with a different cart, return `422` instead of silently returning the original order.
- Two identical requests at once: the second insert waits, then fails the unique check. The code must catch that error and return the existing order. Say so explicitly.

**6. Overlapping carts can deadlock.** Two concurrent orders for {A, B} and {B, A} lock the stock rows in opposite order. Update SKUs in sorted order, and merge duplicate SKU lines first.

**7. The module rule and the flow contradict each other.** "No module reads another module's tables," yet step 2 writes `stock` and `orders` in one transaction, and so does step 5. That's the right call for correctness, but write down how it works. For example: `OrderCheckout` opens the transaction and passes it to the inventory and orders modules, each of which touches only its own tables.

**8. A crash can lose the confirmation email.** If the process dies after "commit PAID" and before "queue email", no email is sent. Writing an outbox row in the same transaction as the `PAID` update fixes this. Also say whether orders the reconciliation job marks `PAID` get an email.

**9. A `202` response leaves the client with no way to learn the result.** There's no `GET /orders/{id}` and no notification. Also define what a repeated `POST` returns while the order is still `PENDING`: `200` or `202`?

**10. The worst-case request time is about 30 seconds.** Four attempts at 5 s each, plus backoff. Check that this fits inside the load balancer and client timeouts. Also say retries happen only on timeouts, network errors and 5xx responses, never on a decline or other 4xx.

**11. Important tests are missing:**
- the reconciliation job, which has no tests listed at all
- two buyers racing for the last unit at the same time
- two identical `POST`s at the same time
- the same idempotency key with a different cart
- a decline restoring stock
- an email failure not affecting the order
- the database being down when the order should be marked `PAID`
- negative and zero quantities

## Low: minor

12. Keys and indexes are missing from the data model:
    - Primary keys: `stock(sku)`, `order_items(order_id, sku)`.
    - Foreign key: `order_items.order_id` should reference `orders`.
    - Index `orders(status, created_at)` for the reconciliation and alert queries.
13. Enforce the allowed `status` values with a `CHECK` constraint or enum, not free `text`.
14. Nothing says how `updated_at` is maintained (trigger or app code).
15. `customer_id` should come from the authenticated user, not the request body.
16. Logging: never log card or payment details. A metric for the count of `PENDING` orders would complement the alert.
17. No cancel or refund path. That's fine for v1, but say it's out of scope.
18. No rule for how long idempotency keys are kept.

The load is no concern: 2,000 orders a day is easy for this setup.

VERDICT: READY WITH CHANGES
