**Not ready as written, but it can be by tomorrow.** The code structure and the single Postgres instance are fine for 2,000 orders a day, but the payment steps (3–6) can charge a customer twice or charge them with no order on record. Fixing that takes two changes to the flow, plus three smaller decisions.

## Must fix before building

**1. A retry after a timeout can charge the customer twice (step 4).**
A timeout does not mean the charge failed; it means you don't know.
- **Case:** the provider takes 6 s to process the charge and succeeds. The service gave up at 5 s and retries, and the second charge also succeeds.
- **Result:** the customer is charged twice for one order, where one charge is expected.
- **Fix:** send an idempotency key (the order id) on every charge call, so the provider treats retries as the same charge. Most providers support this.

**2. The rollback deletes the only record of an order that may have been paid (steps 3–6).**
The `PENDING` insert sits in an open transaction during the payment call, so it is never visible and disappears on rollback.
- **Case:** all three attempts time out but one actually went through, or the service crashes after the charge and before the commit.
- **Result:** the customer is charged and the database has no order row, so there is nothing to reconcile or refund against. The expected result is an order row showing that payment was attempted and its outcome is unknown.
- **Fix:** commit the `PENDING` order first, call the provider outside any transaction, then update the status in a second short transaction. Add `FAILED` and `PAYMENT_UNKNOWN` statuses, and a small job that asks the provider about `PAYMENT_UNKNOWN` orders.
- **Side benefit:** a database connection is no longer held for up to 20 s per checkout (4 attempts × 5 s).

Revised flow:

```mermaid
flowchart TD
    A[POST /orders with idempotency key] --> B[Check stock]
    B --> C[Insert order as PENDING and commit]
    C --> D[Call charge API with order id as idempotency key]
    D -->|success| E[Mark PAID, commit]
    D -->|declined| F[Mark FAILED, return error]
    D -->|timeout after retries| G[Mark PAYMENT_UNKNOWN]
    E --> H[Send confirmation email]
    G --> I[Reconciliation job asks provider, then marks PAID or FAILED]
```

## Decide before building (smaller)

- **Duplicate orders from client retries.** If a user double-clicks or the app retries `POST /orders` on a flaky network, two orders are created and charged. Accept a client-supplied idempotency key and put a unique constraint on it.
- **Overselling.** Nothing in the flow reserves or decrements stock, and the cache is up to 5 minutes old. Two customers buying the last unit within that window both pass the check and both pay. Either decrement a local count in the same transaction as the order insert, or accept overselling and write down what happens (refund, backorder).
- **Email failure.** Step 5 doesn't say what happens if the email send fails after the commit. The order should stay `PAID`, and the email should be retried from a persisted record rather than lost.

## Worth adding to the doc

- **Tests.** One happy-path integration test leaves the dangerous paths uncovered. Add integration tests for: timeout then success (one charge only), decline, all retries timing out (order ends `PAYMENT_UNKNOWN`), duplicate `POST /orders`, and last-unit contention.
- **Backups.** Nightly backups mean a disk failure can lose up to a day of paid orders. Turn on continuous WAL archiving (point-in-time recovery); it is a config change, not a design change.

## What is good and should stay

Module boundaries with no cross-module table reads, thin routes with the flow in `OrderCheckout`, order id on every log line, and accepting the cache instead of an 800 ms warehouse call.

Update steps 3–6 to the revised flow and record the three decisions; after that you can start building tomorrow.

VERDICT: READY WITH CHANGES
