I read design.md. The structure is solid: separate modules that don't read each other's tables, thin routes, one `OrderCheckout` class, and the order id on every log line. That will hold up as you go from 200 to 2,000 orders a day, and you can start on the module scaffolding tomorrow.

But steps 3–6, the payment path, need changing before you write that code. As written, it can charge a customer and leave no record of the order.

## Must fix before building the payment path

**1. Retries can charge a customer twice.** A timeout doesn't mean the charge failed. The provider may have processed it and the response got lost. Retrying up to 3 times without an idempotency key can charge the card up to 4 times.
- **Fix:** create one idempotency key per order (the order id works) and send it with every attempt. Most payment providers support this.

**2. A charge can succeed and then the order disappears.** The charge happens inside an open database transaction. If all retries time out, or the process crashes before commit, the rollback deletes the `PENDING` row. The customer has paid, and you have no order.
- **Fix:** commit `PENDING` in its own short transaction before calling the provider. Then charge outside any transaction, and update to `PAID` or `FAILED` afterwards.
- **Fix:** if retries run out, mark the order `PAYMENT_UNKNOWN` instead of failing it. A small job can check those with the provider later, or use the provider's webhooks.
- This also stops each checkout holding a database connection for up to 20 s (4 × 5 s), which would drain your connection pool under load.

**3. You can sell stock you don't have.** Checking a 5-minute-old cache is fine for showing what's in stock. But nothing reserves or decrements stock at checkout, so two customers can buy the last unit.
- **Fix:** keep the cache. Add a conditional reserve/decrement at order time, then either re-check with the warehouse after payment or have a clear plan for handling oversells.

## Worth adding, but not blocking
- **Tests:** add integration tests for payment timeout, decline, and a crash between charge and commit. That's where the bugs above would show up, and one happy-path test won't catch them.
- **Email:** send it asynchronously, from an outbox table or a queue, after `PAID`. Then a slow or failed email can't affect checkout.
- **Backups:** nightly backups mean you could lose up to a day of paid orders. Point-in-time recovery (WAL archiving) is cheap insurance once real money is going through the system.

Points 1–3 are a small redesign of steps 3–6, maybe an hour's work. Once that's done, the design is in good shape for what you're building.

VERDICT: READY WITH CHANGES
