Yes, you can start building tomorrow, but first make four short edits to design.md. None of them changes the architecture. The core of revision 3 is sound:

- Reserving stock with a conditional `UPDATE` is atomic.
- The payment call happens outside any transaction.
- The order id is reused as the payment idempotency key on every retry.
- The email is queued after commit, so a failed email never fails the order.
- Unknown payment results go to a reconciliation job, and an alert covers orders stuck in `PENDING`.

The problems are in the parts the design doesn't spell out, mostly the reconciliation job.

## Order status lifecycle (as the design describes it)

```mermaid
stateDiagram-v2
    [*] --> PENDING: POST /orders, stock reserved
    PENDING --> PAID: charge succeeds (request or reconciliation)
    PENDING --> FAILED: charge declined (request or reconciliation)
    PENDING --> PENDING: result unknown, client gets 202
    PAID --> [*]: confirmation email queued
    FAILED --> [*]: stock restored
```

Two different code paths can move an order out of `PENDING`: the original request and the reconciliation job. Most of the findings below come from that.

## Findings

**1. High: stock can be restored twice, which leads to overselling.**
- Evidence: there are two service instances (line 6) and the reconciliation job runs every 5 minutes (line 37). Nothing says it runs on only one instance, and nothing says a status change only applies when the order is still `PENDING`.
- Example: SKU A has `available = 0` and order X (1 unit) is `PENDING`. The provider reports the charge as declined. Both instances pick up order X, and each one marks it `FAILED` and restores stock. Stock goes to 2 when it should be 1, so you can sell a unit you don't have. On the `PAID` path the same race queues two confirmation emails.
- Fix: make every status change conditional, e.g. `UPDATE orders SET status = 'FAILED' WHERE id = :id AND status = 'PENDING'`. Only restore stock or queue the email when that update changed exactly one row. Optionally, also make the job claim its rows with `FOR UPDATE SKIP LOCKED` or an advisory lock.

**2. Medium: the reconciliation job doesn't say it does the follow-up work that steps 4 and 5 do.**
- Evidence: line 38 says only "settles them as `PAID` or `FAILED`".
- Example: a charge times out on every attempt but actually succeeded. Reconciliation marks the order `PAID`, but the customer never gets a confirmation email. In the declined case, the order is marked `FAILED` but its stock stays reserved for good.
- Fix: state that reconciliation calls the same settle-paid and settle-failed code as steps 4 and 5.

**3. Medium: there is no rule for when the provider has no record of the charge.**
- Evidence: line 26 calls the provider outside the transaction that committed the order, so a crash in between leaves a `PENDING` order that was never charged. Line 38 only describes two outcomes.
- Example: an instance restarts right after step 2 commits. Reconciliation asks the provider about the order and gets "not found". The design doesn't say what happens next, so the order sits in `PENDING` and fires the 30-minute alert every time this happens.
- Fix: list the provider responses and what each one does:
  - succeeded → `PAID`
  - declined → `FAILED`
  - not found → `FAILED` and restore stock (safe, because the 2-minute threshold is longer than the roughly 25-second retry window)
  - still processing → leave `PENDING`

**4. Medium: there are no tests for the reconciliation job.**
- Evidence: lines 49–51 cover only the request path.
- Fix: add integration tests for:
  - reconciliation settling `PAID` (email queued once)
  - reconciliation settling `FAILED` (stock restored once)
  - provider returns "not found"
  - two reconciliation runs at the same time on the same order (the test for finding 1)

## Smaller items

- **Low: no way for the client to find out how a `202` order ended.** No `GET /orders/{id}` is defined. Repeating the `POST` with the same key works as a status check, but it's better to say so explicitly.
- **Low: the idempotency key is unique across all customers (line 20).** If two customers' clients send the same key, one of them gets back the other customer's order. Scope the constraint to `(customer_id, idempotency_key)`. Also decide what happens when a repeated key arrives with a different cart.
- **Low: two checkouts at the same time can deadlock.** Step 2 locks stock rows in cart order. Two carts containing {A, B} and {B, A} can deadlock, and Postgres will abort one of them with an error. Fix: sort SKUs before running the updates.
- **Low: the data model doesn't declare keys.** `stock.sku` should be the primary key; without it, the step 2 `UPDATE` could match more than one row. `order_items` needs a primary key and a foreign key to `orders`.
- **Low: the module rule (line 41) and the shared transactions (lines 22 and 33) need reconciling.** Steps 2 and 5 change orders and stock in one transaction. Say that the inventory module exposes `reserve` and `release` functions that take the caller's transaction, so the orders module never touches the `stock` table directly.
- **Low: the request can be slow.** Worst case is about 4 attempts × 5 s plus backoff, so over 20 s. Check that the load balancer's idle timeout is longer than that.
- **Low: tests are missing for two duplicate `POST`s arriving at the same time and two buyers racing for the last unit.** The existing tests cover these cases one request at a time.

## Speculative (depends on things not in the doc)

- **Price source.** The client sends "the cart" and there's no price table, so where `unit_price` comes from is undefined. If prices come from the client, someone could set their own price. If a catalog service supplies them, add one line saying so.
- **Index for the job.** A partial index on `orders(created_at) WHERE status = 'PENDING'` keeps the job's query cheap as the table grows. It doesn't matter yet at 2,000 orders a day.

Findings 1–3 can be fixed with a few sentences in the doc, and finding 4 adds four test cases. Once those are in, the plan is solid.

VERDICT: READY WITH CHANGES
