**Not ready to build as written: the flow in steps 3–6 can charge a customer twice, or charge them and leave no order behind.** The code structure section is fine. The fixes are known patterns and are about an hour or two of design revision, plus one product decision from you on overselling.

## Must fix before building

**1. Retrying a timed-out charge can double-charge (step 4).**
A timeout means "we don't know", not "it failed".
- Case: the provider completes the charge at 5.2 s, the service gives up at 5 s and retries, and the second attempt also succeeds.
- Result: the customer is charged twice for one order. Expected: once.
- Fix: send an idempotency key (the order id) on every charge attempt, so the provider treats retries as the same charge.

**2. The rollback erases the only record of an order that may have been paid (steps 3, 6).**
The `PENDING` row is inserted inside a transaction that is still open during the payment call, so it is never visible to anyone and disappears on rollback or crash.
- Case: all three attempts time out but one actually charged, or the process crashes after the charge and before the commit.
- Result: the customer is charged, there is no order row, and nothing to reconcile from. Expected: an order stuck in `PENDING` that can be resolved.
- Fix: commit `PENDING` first, call the provider outside any transaction, then update to `PAID` or `FAILED` in a second short transaction. Add a small job that takes orders `PENDING` for more than a few minutes and asks the provider what happened.
- This also stops a database connection being held for up to 15+ seconds per slow checkout.

**3. `POST /orders` has no protection against the client retrying.**
- Case: the user double-clicks, or the mobile client retries after a network drop.
- Result: two orders and two charges. Expected: one.
- Fix: the client sends an idempotency key, with a unique constraint on it; a repeat returns the original order.

**4. Stock is checked but never reserved or decremented.**
The 5-minute cache is a reasonable trade at this volume; the gap is that nothing in the flow reduces stock.
- Case: one unit left, and two orders arrive within the same 5 minutes.
- Result: both pass the check and both are charged. Expected: the second is rejected, or handled by a stated policy.
- Fix: decrement a local count when an order is placed, and write down what happens when the warehouse later says no (refund or backorder). That policy is your decision.

## Should fix, smaller

- **Email (step 5):** state that a failed email send does not fail or roll back a paid order; send it after commit, with retry.
- **Declines vs timeouts:** a card decline should fail immediately, not go down the retry path. The design only describes timeouts.
- **Tests:** one happy-path integration test leaves the money paths uncovered. Add integration tests for timeout-then-success, decline, a duplicate `POST`, and a crash between charge and commit.
- **Backups:** nightly backups on a single instance mean up to 24 hours of paid orders can be lost. Turn on continuous WAL archiving (point-in-time recovery).

## Revised flow

```mermaid
flowchart TD
    A[POST /orders with idempotency key] --> B{Key seen before?}
    B -- yes --> C[Return existing order]
    B -- no --> D[Check and decrement local stock]
    D --> E[Insert order as PENDING and commit]
    E --> F[Charge provider, order id as idempotency key]
    F -- success --> G[Mark PAID and commit]
    F -- declined --> H[Mark FAILED, restore stock, return error]
    F -- timeout after retries --> I[Leave PENDING, tell client it is processing]
    G --> J[Send confirmation email after commit]
    I --> K[Reconciliation job asks provider, then marks PAID or FAILED]
```

## What is good and should stay

The module boundaries, thin routes, the `OrderCheckout` service class, and order id on every log line are right for a team of four at 2,000 orders a day. Single Postgres is fine at that volume, and no queue or extra service is needed for any of the fixes above.

VERDICT: NOT READY
