**This design is close, and the foundations are good. Most of what's below is a one-line addition to the document, not a redesign.** Three items could lose money or stock in production, so settle those before you start. The rest you can fix as you build.

What already works: the conditional stock update, the payment call made outside any transaction, the order id reused as the payment provider's idempotency key, the reconciliation job, the email queued only after commit, and the 30-minute alert. All the hard calls are right. At 2,000 orders a day, scale isn't a concern.

## High: settle these before building

**1. Status changes aren't guarded, so stock can be put back twice.** Both service instances run the reconciliation job, and steps 4–6 never say that a change is only allowed from `PENDING`.
- Example: SKU A has `available = 0` and a `PENDING` order for 1 unit. Both instances' reconciliation jobs see the order, both get "declined", and both mark it `FAILED` and put the stock back. `available` ends at 2 when it should be 1.
- The same gap allows a mix-up between the request and the job. Reconciliation marks the order `FAILED` and restores stock, then a late success in the original request marks it `PAID`. Now the order is paid but its stock has been released.
- Fix: every change becomes `UPDATE orders SET status = :new WHERE id = :id AND status = 'PENDING'`. Only restore stock if that update changed a row. Have both the request path and the job use this same code.

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

**2. A negative quantity adds stock.** Nothing rejects `quantity <= 0`.
- Example: a cart line of `quantity = -5` on a SKU with `available = 0` passes the check (`0 >= -5`) and sets `available` to 5.
- Fix: validate the request and add `CHECK (quantity > 0)` on `order_items`. Also add `CHECK (available >= 0)` on `stock`.

**3. The design doesn't say where prices come from.** `unit_price` and `total` are stored, but if they come from the client's cart, a client can set its own price.
- Fix: state that prices are looked up on the server (from which module?) and that `total` is calculated there.

## Medium: decide while building

**4. Reconciliation has cases with no defined outcome.**
- The provider has no record of the charge. This happens if the service crashes after committing in step 2 but before calling the provider.
- The provider reports the charge as still processing.
- Also check two provider behaviours: (a) whether you can look up a charge by your idempotency key, or need to store the provider's charge id (no column for it yet); (b) whether provider idempotency keys expire (Stripe's do after 24 hours).

**5. The confirmation email can be lost.** If the process crashes between committing `PAID` and queueing the email, no email goes out. Write the email job in the same transaction (the "transactional outbox" pattern). Also say whether the job sends the email when it settles an order as `PAID`.

**6. The idempotency key rules are incomplete.**
- A repeated key with a *different* cart silently returns the old order. It should be rejected (usually with `422`).
- The key is unique across all customers. Make it unique per customer: `UNIQUE (customer_id, idempotency_key)`.
- Say what a duplicate request gets while the first is still in progress (probably the `PENDING` order with `202`). Also say that the unique-key error on a simultaneous duplicate is caught and turned into "return the existing order".

**7. Orders with several items can deadlock.** Two carts containing {A, B} and {B, A} lock the stock rows in opposite order. Sort SKUs before updating, and merge repeated lines for the same SKU.

**8. Step 2 conflicts with the module rule.** One transaction updates `stock` (inventory module) and `orders` (orders module), but the module rule says no module touches another's tables. State how this works, for example `inventory.reserve(tx, items)` running inside a transaction that orders opens.

**9. Some tests are missing.** The test list leaves out the reconciliation job and any concurrency. Add:
- both reconciliation jobs settling the same order
- reconciliation finishing at the same moment as a late success in the request
- two simultaneous requests with the same key
- an order with several items where the second item is out of stock (check the first item's stock comes back)
- a decline on the reconciliation path
- the provider having no record of the charge
- the email failing

## Low: minor fixes to the document

**10. The data model is missing constraints.** It needs: primary keys for `stock (sku)` and `order_items (order_id, sku)`, a foreign key from `order_items` to `orders`, a `CHECK` on `status`, an index on `orders (status, created_at)` for the reconciliation query, and a column for the provider's charge id.

**11. The retry policy needs two details.** State that only timeouts, network errors and 5xx responses are retried, never declines. The worst case is about 4 × 5 s plus backoff, roughly 30 s, so confirm the load balancer's timeout is longer.

**12. The design doesn't say what the client gets.** Give the HTTP status codes for success and for a decline (for example `201` and `402`).

**13. The 2-minute rule is right but never written down.** "Older than 2 minutes" has to stay longer than the request's maximum retry time. Note that, so nobody later raises the retries past it.

To start tomorrow, add items 1–3 to the document. Each is a sentence or two, and the rest can go into your build tickets.

VERDICT: READY WITH CHANGES
