The design isn't ready for tomorrow. The code structure section is fine, but the payment part of the checkout flow (steps 3–6) can charge a customer twice, or take their money and keep no order. It's a known fix and the doc edit should take a few hours, but it changes the flow you would build first.

## Must fix before building

**1. Retrying the charge can bill the customer more than once.**
Step 4 retries on a 5-second timeout. But a timeout doesn't mean the charge failed. It often means the provider charged the card and the reply was slow.
- **Case:** a $50 charge succeeds at the provider and the reply arrives after 6 s. The service retries. **Actual:** two $50 charges, and up to four if every reply is slow. **Expected:** one charge.
- **Fix:** send an idempotency key with every charge (the order id works), so the provider treats a retry as the same charge. Most payment providers support this. Retry only on timeouts and 5xx errors, never on declines.

**2. Rolling back after a timeout loses the record of a real charge.**
Steps 3–6 make the charge inside an open database transaction. So the `PENDING` row only exists if the commit succeeds, and other connections can't see it before then.
- **Case:** all retries time out, but the first charge actually went through. Step 6 rolls back. **Actual:** the customer paid and the database has no order. **Expected:** an order you can find, marked "payment unknown", that gets reconciled.
- The same thing happens if the `COMMIT` itself fails after a successful charge. The open transaction also holds a database connection for up to about 20 s (4 attempts × 5 s).
- **Fix:** split it into separate steps, as shown below.

```mermaid
flowchart TD
    A[POST /orders with idempotency key] --> B[Check stock]
    B --> C[Commit order as PENDING]
    C --> D[Charge provider with order id as idempotency key]
    D -->|success| E[Commit order as PAID and queue email]
    D -->|declined| F[Commit order as FAILED]
    D -->|timeouts used up| G[Leave PENDING; background job asks provider for status]
    E --> H[Email sender delivers confirmation]
```

**3. Two orders can buy the same last item, and nobody has decided what happens then.**
The stock cache can be up to 5 minutes old, and nothing reserves stock.
- **Case:** one unit is left. Customer A buys it at 10:00. Customer B orders at 10:02, the cache still shows 1, and B is charged too. **Actual:** two paid orders for one item. **Expected:** whatever the business decides.
- Even a live warehouse call wouldn't stop this when two orders arrive at the same moment.
- This is a decision for the product owner, not a code fix. Either accept occasional overselling and define the refund or backorder process, or add stock reservation. Either answer is fine at 2,000 orders a day, but write it down.

## Should fix (can be done during the build)

4. **The client can create duplicate orders.** A request can take more than 20 s, so clients and users will retry `POST /orders`. Accept an idempotency key on `POST /orders`.
5. **Email failure behaviour isn't defined.** After the commit, the order is already paid. If sending the email fails, the request must not return an error. Write the email to an outbox table in the same commit and send it from a separate job.
6. **One happy-path integration test isn't enough.** The bugs above all happen on failure paths. Add integration tests for:
   - timeout, then a successful retry, with exactly one charge
   - all retries timing out, leaving the order `PENDING` for reconciliation
   - a decline, with no retry
   - a commit failure after a successful charge
   - a duplicate `POST /orders`
   - email failure leaving the order `PAID`

   Use a fake payment provider you can script.
7. **The design doesn't say where `OrderCheckout` lives.** It calls the orders, payments and inventory modules. Say which module owns it, and that it only calls their public interfaces, so it doesn't become the place that reads everyone's tables.
8. **Nightly backups could lose up to a day of paid orders.** That's a lot for payment data. Turning on continuous WAL archiving gives point-in-time recovery and is cheap on a single Postgres instance.

## What's fine as written
- The module boundary rule (no module reads another's tables)
- Thin routes with the flow in a service class
- Logging with the order id on every line
- Using the cache for availability at this volume, once item 3 is decided

**What to do next:**
1. Rewrite Flow steps 3–6 to match the diagram.
2. Get the overselling decision from the product owner.
3. Add the failure-path tests to the test plan.

You could start on the module skeletons and the inventory cache tomorrow while that happens. Don't start the payment flow until those changes are in the doc.

VERDICT: NOT READY
