I read the design, and the core payment flow (steps 3–6) has correctness problems that would cost real money. The code-structure section is fine. The context numbers are fine too: 2,000 orders a day is small, so scale isn't the worry here. Correctness is.

## Blocking issues

**1. Retrying the charge after a timeout will double-charge customers.**
A 5 s timeout doesn't tell you the charge failed. It often means the charge went through and the response was slow. Retrying up to 3 times without an idempotency key can charge a customer up to 4 times.
- **Fix:** generate an idempotency key per order (for example, the order id) and send it on every charge attempt. Check that your payment provider supports this; most do.

**2. The charge happens inside an open database transaction.**
This causes two problems:
- **Charged with no order record.** If the charge succeeds and the commit then fails (connection drop, deploy, crash), the customer has paid and you have nothing. Step 6's rollback also deletes the `PENDING` row, so you lose the record of the attempt.
- **Long-held connections.** With retries, one transaction can stay open for about 20 s while it waits on network calls. That ties up connections and any row locks the whole time.
- **Fix:** split it into separate steps:
  1. Commit the `PENDING` order.
  2. Charge outside any transaction.
  3. Update the order to `PAID` or `PAYMENT_FAILED` in a new short transaction.

  Never delete the order on failure; record the failure state instead.

**3. Some charges will end up in an unknown state, and nothing recovers them.**
Even with fix 2, a crash between "charge succeeded" and "marked `PAID`" leaves an order stuck in `PENDING` that was actually paid.
- **Fix:** add a reconciliation job. It finds orders stuck in `PENDING` past some threshold, asks the provider for their real status, and settles them. Payment provider webhooks can do the same job.

**4. Clients can create duplicate orders.**
A user double-clicking, or a mobile client retrying `POST /orders`, creates a second order and a second charge. The idempotency key from fix 1 only protects one order, not two separate orders.
- **Fix:** have the client send an `Idempotency-Key` header, and enforce it with a unique constraint.

**5. You will oversell stock.**
The stock check reads a cache that can be up to 5 minutes old, and nothing reserves or decrements stock when an order is placed. Two buyers can both get the last unit. Accepting a stale cache is a reasonable call for speed, but the design needs to say what happens when you oversell. Options:
- Reserve or decrement stock when the order is placed.
- Re-check against the warehouse system, either asynchronously or only when the cached stock is low.
- Accept overselling as a policy, with a defined way to cancel and refund.

Right now the case isn't handled at all.

## Should fix before launch

- **Up to 24 hours of payment data loss.** With only nightly backups, losing the database means losing a day of orders that customers have paid for. Turn on WAL archiving / point-in-time recovery, or use a managed Postgres that does this for you.
- **Email sent from inside the request.** If sending fails or hangs, it shouldn't affect the order. Use an outbox table or a queue, and make sure a retry can't send the email twice.
- **Tests only cover the happy path.** That's the one path that isn't risky. Add integration tests for:
  - charge times out, then succeeds on retry
  - charge succeeds, then the commit fails
  - duplicate `POST /orders`
  - provider returns a hard decline

## What's good
- Clear module boundaries, with no module reading another's tables.
- Thin routes, with the flow in a single `OrderCheckout` class.
- Logging with the order id on every line.

Keep all of these.

## Bottom line
You can start the module skeleton, routes and logging tomorrow. Steps 3–6 need to be rewritten as an explicit order state machine (`PENDING → PAID / PAYMENT_FAILED / NEEDS_RECONCILIATION`). It also needs two idempotency keys (one on the charge, one on `POST /orders`) and a decision on overselling, all before anyone writes the payment code. That's probably a few hours of design work, but it changes the central flow, so the design isn't ready as written.

VERDICT: NOT READY
