**The design is not ready to build as written: steps 3–6 of the flow can charge a customer more than once, and can take their money while leaving no order record.** The code structure section is sound and the fixes are small, about half a day of redesign, with nothing extra to build beyond a small reconciliation job.

## Blockers (fix before building)

**1. The retry on timeout can double-charge.**
A timeout means "we don't know", not "the charge failed".
- **Case:** the provider takes 6 s to process a charge successfully. The service gives up at 5 s and retries, and the provider charges again.
- **Result:** the customer pays up to four times for one order, where the expected result is one charge.
- **Fix:** send an idempotency key (the order id) on every charge call, so retries of the same order collapse into one charge. Confirm the provider supports this; the design doesn't say which provider it is.

**2. A charged customer can end up with no order.**
The `PENDING` insert and the charge sit inside one open database transaction.
- **Case:** the charge succeeds, then the process crashes or the commit fails. The transaction rolls back, including the `PENDING` row.
- **Result:** the money is taken and the database has no trace of the order, where the expected result is an order you can find and either complete or refund.
- **Same problem in step 6:** if all retries time out, the rollback erases the only evidence of a charge that may have gone through.
- **Side effect:** each checkout holds a database connection for up to 20 s (four attempts at 5 s each), so a slow provider can exhaust the connection pool.
- **Fix:** commit `PENDING` first, call the provider with no transaction open, then record the result in a second short transaction. Never delete the order; mark it `FAILED` instead.

**3. There is no state for "payment outcome unknown" and nothing to resolve it.**
After the retries are exhausted, the order needs a state such as `PAYMENT_UNKNOWN`. A small reconciliation job, or the provider's webhook, then asks the provider what happened and settles the order to `PAID` or `FAILED`.

**4. `POST /orders` itself is not idempotent.**
- **Case:** the client times out or the user double-clicks, and the same cart is posted twice.
- **Result:** two orders and two charges, where the expected result is one.
- **Fix:** have the client send an idempotency key, with a unique constraint on it.

**5. Stock is checked but never reserved or decremented.**
- **Case:** two customers order the last unit. Both pass the cache check, both are charged, and one order cannot ship.
- **Result:** this happens regardless of the 5-minute staleness, which only widens the window.
- **Fix:** the cache is acceptable at this volume, but the design must do one of two things. Either decrement stock locally in the same transaction as the order insert, or state the oversell policy explicitly (auto-refund or backorder, and who gets told).

**6. The test plan covers only the happy path.**
Every blocker above lives on a failure path. Add integration tests, against a fake provider, for:
- timeout then success
- timeout on all attempts
- card declined
- crash between charge and commit
- duplicate `POST`
- last-unit race

## Proposed flow

```mermaid
flowchart TD
    A[POST /orders with idempotency key] --> B{Key seen before?}
    B -- yes --> C[Return existing order]
    B -- no --> D[Transaction 1: check and reserve stock, insert order PENDING, commit]
    D --> E[Charge provider, idempotency key = order id, retry on timeout]
    E -- success --> F[Transaction 2: mark PAID, queue confirmation email]
    E -- declined --> G[Mark FAILED, release stock, return error]
    E -- all attempts time out --> H[Mark PAYMENT_UNKNOWN, tell client 'processing']
    H --> I[Reconciliation job asks provider, settles to PAID or FAILED]
```

## Not blockers, but decide and write down

- **Confirmation email:** if the send fails after commit, it is lost. Write an email row in the same transaction as `PAID` and send it from a retrying worker.
- **Nightly backups only:** a disk failure loses up to 24 hours of paid orders. Turn on continuous WAL archiving (point-in-time recovery). This is cheap and needs no code change.
- **Retry policy:** add backoff between attempts, and never retry a decline, only timeouts and 5xx responses.

## What's right

- Synchronous checkout on a single Postgres instance is the correct size for 2,000 orders a day; a queue or separate services would be over-building.
- The module boundaries, thin routes, `OrderCheckout` service and order id on every log line are worth keeping as they are.

VERDICT: NOT READY
