**Not quite ready to build as written, but the fix is small: one change to the charge step (steps 3–6), which you can make in an hour or two before you start.** The code structure and the scale-appropriate choices (single Postgres, the inventory cache) are solid. The module boundaries, thin routes, a single `OrderCheckout` class and order-id logging are the right foundation.

## Must fix before building: the charge step can double-charge or lose an order

**Case 1: retrying a timeout.**
- Step 4 calls the charge API and it times out at 5 s. The payment provider may still have processed the charge.
- The service retries, and the customer is charged twice. Today's design has no way to tell the provider "this is the same attempt".
- Fix: generate one idempotency key per order (the order id works) and send it on every attempt. Most providers dedupe on it. Check that yours supports one.

**Case 2: charge succeeds, but the order is lost.**
- The charge goes through, then the service crashes or the commit fails before step 5 finishes. The transaction rolls back, so the `PENDING` row disappears.
- The customer is charged and you have no record of the order.
- Step 6 has a similar gap. If all retries time out and you roll back, the charge may still have succeeded on the provider's side.
- Fix: commit the `PENDING` order in its own short transaction before calling the provider. Then do the charge outside any transaction. Then update to `PAID` or `FAILED` in a second short transaction. After a timeout, look up the charge by idempotency key rather than assuming it failed. A small job that sweeps stale `PENDING` orders and checks them against the provider covers the crash case.

A side benefit: you no longer hold a database transaction open across a call that can take 15 s or more (3 attempts × 5 s).

## Decide now, no redesign needed

- **Overselling.** The cache is up to 5 minutes stale and the design never decrements stock. So two customers can buy the last unit. At 200–2,000 orders a day this is probably acceptable. Just write down the policy (for example, oversells are backordered or refunded manually) so it's a decision and not a surprise.
- **Confirmation email.** If sending fails after commit, the order is still `PAID`. Say whether you retry it or just log it. Sending it from a small outbox table or a background job would be the cleaner version.
- **Backups.** Nightly backups mean a database loss could drop up to 24 hours of paid orders. This is fine for launch, but turn on point-in-time recovery (WAL archiving) before you reach the 2,000/day mark.

## Tests

Add two tests to your plan, since they cover exactly the risks above: a charge that times out and then succeeds on retry (it must not be charged twice), and a crash between the charge and the `PAID` update (the sweeper must recover it). Your current plan only covers the happy path for integration.

VERDICT: READY WITH CHANGES
