The design is close: the structure is right-sized and you can start building tomorrow, but steps 3–6 of the flow need to change first, because as written they can charge a customer twice or charge them with no order on record. The fix is about an hour of design revision and does not touch your module layout.

## What must change before building

**1. A payment retry can double-charge.**
A timeout does not mean the charge failed. For example, the provider takes 6 s to process a charge and succeeds, the service gives up at 5 s and retries, and the customer is charged twice when they should be charged once.
- **Fix:** send an idempotency key (the order id) with every charge attempt, so the provider treats retries as the same charge.

**2. A customer can be charged with no order on record.**
The `PENDING` row lives inside a transaction that stays open during the payment call. If the charge succeeds and then the commit fails, the process crashes, or all three attempts time out and step 6 rolls back, the row disappears. The money is taken, the database has no trace of the order, and there is nothing to reconcile against.
- **Fix:** commit the `PENDING` order first, call the provider outside any transaction, then update to `PAID` or `FAILED` in a second short transaction.
- **Also needed:** a small job that looks up `PENDING` orders older than a few minutes with the provider and settles them.
- **Side benefit:** this stops holding a database connection for up to 20 s per order.

**3. Stock is checked but never reserved.**
Two customers buying the last unit both pass the check in step 2, and nothing in the flow decrements stock. The 5-minute cache widens the window, but the gap exists even with a fresh cache.
- **Decision for you:** accepting the cache is reasonable at 200 orders a day, but only if the design says what happens on oversell. Either decrement a local stock count in the same transaction as the order insert, or accept oversell explicitly and write down the refund or backorder path.

**4. The test plan covers only the path where nothing goes wrong.**
The money risk is all in the failure paths. Add integration tests for at least a payment timeout followed by success, a declined payment, and a crash between charge and commit.

## Smaller items, fine to settle while building

- **Duplicate submits:** a double-click or client retry on `POST /orders` creates two orders. Accept a client-supplied idempotency key.
- **Confirmation email:** a failed send after commit is lost silently. Decide whether it is retried, and where.

## What is already good

- No queues, no microservices, single Postgres: correct for 2,000 orders a day and a team of four.
- Modules that do not read each other's tables, thin routes, and one `OrderCheckout` class are a clean base, and all the fixes above fit inside it.
- The order id on every log line is exactly what the reconciliation job will need.

## Revised flow

```mermaid
flowchart TD
    A[POST /orders with cart and idempotency key] --> B[Check stock]
    B --> C[Transaction 1: insert order as PENDING, reserve stock, commit]
    C --> D[Charge payment provider, order id as idempotency key, up to 3 retries on timeout]
    D -->|success| E[Transaction 2: mark PAID, commit]
    D -->|declined| F[Transaction 2: mark FAILED, release stock, commit]
    D -->|still timing out| G[Leave PENDING, tell client payment is being confirmed]
    E --> H[Send confirmation email]
    G --> I[Reconciliation job asks provider for outcome, then marks PAID or FAILED]
```

If you choose to accept oversell in item 3, drop "reserve stock" and "release stock" from the diagram.

VERDICT: READY WITH CHANGES
