The design is close but not ready to build from as written. The overall approach is right: reserve stock, charge outside the transaction, reconcile anything still unknown. But four gaps would cause real money or stock bugs. Each one is a small edit to the doc, so it's realistic to fix them today and still start tomorrow.

## Must fix before coding

**1. High: the design never says where prices come from.** The data model has no price or catalog table, and step 1 only says "the client sends the cart." If `unit_price` comes from the request, a customer can send `unit_price: 0.01` and pay 0.01. The service should look up prices itself and ignore any price the client sends. State which module owns prices.

**2. High: order status changes aren't guarded, so stock can be restored twice.** Both instances run the reconciliation job every 5 minutes. Suppose order X (2 units) is `PENDING` and the provider says "declined." Both job runs read X, both mark it `FAILED`, and both restore stock, so `available` goes up by 4 instead of 2. Two fixes are needed:
- Make every status change conditional: `UPDATE orders SET status = 'FAILED' WHERE id = :id AND status = 'PENDING'`. Only restore stock if that update changed a row.
- Make sure only one instance runs the job at a time, using a Postgres advisory lock or `SELECT … FOR UPDATE SKIP LOCKED`.

**3. High: reconciliation doesn't restore stock.** Step 5 restores stock on a decline, but step 6 only says reconciliation "settles them as PAID or FAILED." Take an order whose charge timed out and was actually declined: reconciliation marks it `FAILED`, and its units stay reserved forever. Expected: `FAILED` always comes with a stock restore, in the same transaction, whichever path sets it. The simplest way to guarantee that is one shared method that does both.

**4. High: the design doesn't say what happens when the provider has no record of the charge.** This will happen on every deploy. If an instance restarts after step 2 commits but before step 3 calls the provider, order X is `PENDING` with stock reserved, and the provider has no charge under that idempotency key. Step 6 only covers `PAID` or `FAILED`, so X stays `PENDING` forever, holds its stock, and sets off the 30-minute alert. Decide on one rule: either mark it `FAILED` and restore stock, or submit the charge now using the same idempotency key.

```mermaid
stateDiagram-v2
    [*] --> PENDING: stock reserved, order inserted
    PENDING --> PAID: charge succeeded (request or reconciliation), queue email
    PENDING --> FAILED: declined OR provider has no charge, restore stock
    note right of PENDING: every move out of PENDING is guarded by WHERE status = 'PENDING'
```

## Should fix (can be decided during the first days of building)

**5. Medium: idempotency keys are unique across all customers, not per customer.**
- If customer B sends a key that customer A already used, B gets A's order back.
- If the same key is sent with a different cart, the old order comes back silently, with no error.

Fix: make the unique constraint `(customer_id, idempotency_key)`, store a hash of the request, and return `422` when the same key arrives with a different body.

**6. Medium: carts can deadlock each other.** Order 1 contains [A, B] and order 2 contains [B, A]. If they run at the same time, Postgres detects a deadlock and aborts one of them, which surfaces as a `500`. Fix: update stock rows in sorted SKU order, and merge duplicate SKU lines first.

**7. Medium: the confirmation email can be lost.** If an instance crashes after the `PAID` commit but before the email is queued, the customer paid and never hears about it. The design also doesn't say whether orders that reconciliation marks `PAID` get an email at all. Fix: write the email job to a table (an "outbox") in the same transaction as the `PAID` update. A separate worker then sends from that table.

**8. Medium: important test cases are missing.** Per your test-first standard, add:
- two buyers racing for the last unit at the same time
- a decline restores stock
- the reconciliation job, for all three outcomes: paid, declined, and no record
- two reconciliation runs at the same time (no double restore)
- a crash between the stock commit and the charge
- the same idempotency key with a different cart
- two identical `POST /orders` requests arriving at the same time

**9. Low: a request can be held for close to 30 seconds.** Four attempts at 5 s each, plus backoff, comes to about 27 s. That may exceed the load balancer's timeout. If so, clients just retry and get the `PENDING` order back, so nothing breaks, but a total time budget of about 10 s would be kinder.

**10. Low: the provider's charge id isn't stored.** You'll need it for refunds and support lookups. Add a column such as `provider_charge_id`.

**11. Low: the schema has no keys or constraints.** Add:
- a primary key on `stock.sku`
- a primary key on `order_items`, for example `(order_id, sku)`
- foreign keys from `order_items` to `orders`
- `CHECK (available >= 0)`

**12. Low: step 2 doesn't fit the module rule as worded.** One transaction writes to both the orders and the inventory tables, which goes against "no module reads another module's tables" unless inventory provides `reserve` and `release` functions that run inside the caller's transaction. Say so in the doc, so the coupling is a stated decision rather than a hidden one.

The rest is fine for 2,000 orders a day and a team of four: charging outside the transaction with the order id as the provider's idempotency key, the conditional stock update, thin routes with an `OrderCheckout` class, and the logging and alerting.

VERDICT: READY WITH CHANGES
