**You can start building tomorrow once you make a few small edits to design.md.** The overall approach holds up. The payment call happens outside any database transaction, the order id is sent to the provider as the idempotency key, stock is only decremented when enough is available, and the reconciliation job covers payments whose result is unknown. None of that needs redesigning. The doc does have one correctness bug, a few gaps in what it specifies, and tests missing for the paths most likely to break.

## Must fix before coding

**1. Two processes can settle the same order and put its stock back twice.** Nothing in the doc stops it. Both instances can run the reconciliation job, and a slow request can still be working when the job picks up the same order.
- **Example:** order X is `PENDING` and holds 2 units of SKU A. At 12:05 the reconciliation job runs on both instances. Each asks the provider, each hears "declined," and each runs step 5. SKU A goes up by 4 instead of 2, so you can sell 2 units you don't have.
- **Fix:** every status change should be conditional, e.g. `UPDATE orders SET status = 'FAILED', updated_at = now() WHERE id = :id AND status = 'PENDING'`. Only restore stock (or queue the email) if that update changed exactly one row, and do both in the same transaction. Steps 4 and 5 and the job should all go through this one guarded path.

```mermaid
stateDiagram-v2
    [*] --> PENDING: POST /orders (stock reserved)
    PENDING --> PAID: charge succeeded<br/>(request or reconciliation job)
    PENDING --> FAILED: charge declined<br/>(request or reconciliation job)
    PAID --> [*]
    FAILED --> [*]
```
Each arrow fires at most once, and only if `status = 'PENDING'` at that moment. The side effects (restoring stock for FAILED, queuing the email for PAID) happen only on the call that actually made the change.

**2. The doc doesn't say what the reconciliation job does after settling an order.** It says the job "settles them as PAID or FAILED," but not whether it sends the confirmation email for PAID or restores stock for FAILED. Fix 1 settles this if the job reuses the same code path as the request.

**3. The doc doesn't say what happens if the provider has no record of the charge.** If none of the attempts in step 3 ever reached the provider, a status lookup returns "not found," and the doc doesn't say what to do. Marking the order FAILED risks a late charge going through on an order you've cancelled. My recommendation: have the job retry the charge with the same idempotency key instead of only looking up its status. That always gives a definite answer, and the provider still treats it as the same single charge.

**4. Updating several SKUs in one transaction can deadlock.** Order 1 updates A then B while order 2 updates B then A. Postgres aborts one of them, and the doc never mentions that error. Fix: update SKUs in sorted order. If an update still fails on a deadlock, retry the transaction once.

**5. Cart input isn't validated.** A quantity of `-5` makes the step-2 update add 5 units to stock. Add `CHECK (quantity > 0)` on `order_items` and `CHECK (available >= 0)` on `stock`, and reject a non-positive quantity at the route.

## Questions to answer in the doc

- **Where do `unit_price` and `total` come from?** No table holds prices, and the cart comes from the client. If the server uses prices sent by the client, customers can set their own price. The doc should say they come from a server-side catalog.
- **What does a reused idempotency key with a different cart return?** Right now it silently returns the old order. Make the key unique per customer, `UNIQUE (customer_id, idempotency_key)`. Store a hash of the request and return `422` if the same key arrives with a different body.
- **How does the client find out the final status after a `202`?** You need a `GET /orders/{id}`, and it isn't in the doc.
- **What is the queue?** If the process crashes between committing PAID and queuing the email, the email is never sent, and reconciliation won't catch it because the order is no longer PENDING. The simplest fix is an email table that you insert into inside the same transaction that sets PAID.
- **How does one transaction cover two modules?** Step 2 changes inventory and orders together, but "no module reads another module's tables." State how that works: the checkout service opens the transaction and passes it to each module, so neither touches the other's tables directly.
- **Which errors are retried?** Say that only timeouts, network errors and provider 5xx responses are retried, never a decline. Also check the worst case: 4 attempts × 5 s plus backoff is 20–30 s, and that has to stay under your load balancer's timeout.

## Tests to add

The current list covers the request path one request at a time. Add:
- Two concurrent orders for the last unit of a SKU: exactly one succeeds and the other gets `409`.
- Two concurrent `POST /orders` with the same key: one order, and stock decremented once.
- Reconciliation job: charge settles PAID (email queued), settles FAILED (stock restored), provider says "not found," provider unreachable (order stays PENDING).
- Two job runs on the same order at once: stock restored exactly once. This is the regression test for fix 1.
- Two orders with overlapping SKUs in opposite order: no deadlock error.
- A negative or zero quantity is rejected, and a reused key with a different cart returns `422`.
- The email fails and is retried, and the order stays PAID.

The concurrency tests need a real Postgres database, not mocks. Plan for that in the integration test setup.

All of this fits in one more revision of the doc, and none of it changes the architecture. Fix 1 is the one to settle before you write the checkout code.

VERDICT: READY WITH CHANGES
