I wouldn't build steps 3–6 as written. The way it handles payment can charge a customer twice, or take their money and keep no record of the order. The fixes are standard and small, so this is an afternoon of rewriting the doc, not a redesign.

## Blockers (fix before building)

**1. Retrying the charge on timeout can charge customers twice (step 4).**
A 5 s timeout doesn't mean the charge failed. It may have gone through and only the response was 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 on every charge attempt. Check that your provider supports this. Most do.

**2. The database transaction stays open during the payment call (steps 3–6).**
- **Lost charges:** if the charge succeeds but the service then crashes, times out, or fails to commit, the rollback deletes the order. The customer has paid and you have no record of it.
- **No history:** the `PENDING` row is never committed, so you can't see or reconcile attempts that were in progress or failed.
- **Long locks:** one request can hold a transaction and connection open for about 20 s (4 × 5 s) or more. With one Postgres instance, a slow provider can use up your connection pool.
- **Fix:** commit `PENDING` first, then charge, then update to `PAID` or `FAILED` in a second short transaction. Never roll back money-related state. Record what happened.

**3. Some outcomes are unknown, and nothing handles them.**
After the retries run out, you don't know whether the customer was charged. Step 6 sends the client an error anyway, the customer tries again, and with #1 that's another charge.
- **Fix:** add an `UNKNOWN` or `PAYMENT_PENDING` state. Settle it using the provider's webhooks, or a job that looks the charge up by its idempotency key. Tell the client "processing", not "failed".

**4. Nothing stops `POST /orders` from creating duplicate orders.**
Double-clicks, mobile retries and proxy retries will create two orders and two charges.
- **Fix:** require an `Idempotency-Key` header from the client and enforce it with a unique constraint.

## Decide before building

**5. Selling stock you don't have.**
- **The cache doesn't reserve stock.** It's up to 5 minutes old, so two buyers can both get the last unit.
- **Stock is never reduced.** Nothing in the flow tells the warehouse an order was placed, so the cache never goes down because of your own orders.
- **No policy for when it happens.** The doc doesn't say what the customer sees: refund, backorder, or an apology email.

Accepting the cache to avoid the 800 ms call can be a fair trade-off, but you have to choose it on purpose and write down what happens when you oversell. One cheap option: make the warehouse call or reservation asynchronously after payment, and handle the rare oversell with a refund.

**6. Up to a day of payment data can be lost.**
With nightly backups only, losing the database means losing up to 24 h of orders that customers have paid for. You'd then have to rebuild them from the payment provider's records. Point-in-time recovery (WAL archiving, or the managed Postgres option for it) costs little and closes this gap.

## Smaller issues
- **Email failures:** the confirmation email must not be able to fail or roll back the order. Send it after commit, ideally through an outbox table or a queue so a failed send can be retried.
- **Tests:** one happy-path integration test isn't enough for this flow. Add tests for a payment timeout, a timeout followed by success on retry, a crash after the charge but before marking the order `PAID`, and a duplicate client request. These are the cases that cost money.
- **Payment timeout:** 5 s may be too short for some providers. Check their recommended timeout and use backoff between retries.

## What's fine
- **Scale:** 2,000 orders a day is about 1.4 a minute, so one Postgres instance and a monolith are the right size. Don't add more infrastructure.
- **Code structure:** keeping modules out of each other's tables, keeping routes thin, putting the flow in `OrderCheckout`, and logging the order id on every line are all good choices. Keep them.

## Starting tomorrow
You can start on the module scaffolding, the schema, and the inventory and orders modules now. Leave the payment section of `OrderCheckout` until steps 3–6 are rewritten:
1. Insert the order as `PENDING` and commit.
2. Charge with the idempotency key.
3. Update the order to `PAID`, `FAILED` or `UNKNOWN` in a short transaction.
4. Queue the confirmation email.
5. Run a job that settles `UNKNOWN` orders.

VERDICT: NOT READY
