**Not as written, but the fix is small.** The structure is solid: clear module boundaries, thin routes, a single service class that owns the flow, and logging keyed by order id. Two places in steps 3 to 6, though, can take a customer's money without leaving a paid order behind. Both are in the core flow, so fix them before you write `OrderCheckout`. It's probably an hour of rework on the doc, not a redesign.

## Must fix before building

**1. Retrying the charge can bill the customer twice (step 4).** A timeout doesn't mean the charge failed. Often the provider charged the card and the response just arrived late.
- *What happens:* a $50 charge times out after 5 s, the provider has already processed it, you retry and it goes through again. The customer pays $100.
- *What should happen:* one $50 charge.
- *Fix:* send an idempotency key (for example, the order id) with every charge attempt. Most providers support this, so a retry returns the original result instead of charging again. Check that yours does.

**2. The payment call runs inside an open database transaction (steps 3 to 6).** That causes two problems:
- *Money with no order record:* the final retry times out but the charge actually went through. Step 6 rolls back, the `PENDING` row disappears, and nothing in your database shows that the customer paid. The same thing happens if the charge succeeds and the commit then fails.
- *Long-held transactions:* with 4 attempts at 5 s each, one checkout can hold a transaction and its locks for more than 20 s. That will hurt at 2,000 orders a day.
- *Fix:* commit the `PENDING` order first, call the provider outside any transaction, then update the order in a second short transaction. If the result is unknown, mark it something like `PAYMENT_UNKNOWN` and let a reconciliation job ask the provider later. Don't delete the order.

```mermaid
flowchart TD
    A[POST /orders] --> B[Check inventory cache]
    B --> C[Insert order PENDING and commit]
    C --> D[Charge provider with idempotency key = order id]
    D -->|success| E[Mark PAID, commit, send email]
    D -->|declined| F[Mark FAILED, return error]
    D -->|timeout after retries| G[Mark PAYMENT_UNKNOWN]
    G --> H[Reconciliation job asks the provider]
```

## Should fix: decide and write down

**3. Overselling from the 5-minute cache.** Nothing in the flow reserves or decrements stock. Two customers can buy the last unit within the same 5 minutes and both succeed. Accepting the cache is a reasonable choice at your volume, but the doc should say what happens when you oversell: refund, backorder, or a hard check against the warehouse just before charging.

**4. Tests cover only the happy path.** The failures above are exactly the cases that need tests: a timeout followed by a successful retry, a timeout on every attempt, a decline, and a failed commit after a successful charge. Use a fake payment provider so these run quickly.

## Worth noting, not blocking

- **Backups:** with nightly backups, losing the database could lose up to a day of paid orders. Point-in-time recovery (WAL archiving) is cheap insurance once you're taking payments.
- **Email failures:** if the confirmation email fails after commit, it shouldn't fail the request. Say that it's sent asynchronously or retried.

Once you've made fixes 1 and 2 and written down a choice for 3, I'd be comfortable seeing you start building.

VERDICT: NOT READY
