**Not ready. The payment flow in steps 3–6 can charge customers twice or charge them with no order recorded. Fix those before you build.**

## Blockers (money bugs)

1. **Retrying the charge has no idempotency key (step 4).**
   - A 5 s timeout doesn't mean the charge failed. The provider may have captured the payment while the response was slow.
   - Retrying up to 3 times can charge the customer 2–4 times.
   - Fix: generate a payment idempotency key per order, store it on the order, and send it with every attempt. Check that your provider supports idempotency keys.

2. **A charge can succeed with no order record (steps 3, 5, 6).**
   - The `PENDING` insert is in an uncommitted transaction while the charge is in flight.
   - If the service crashes after the charge succeeds, the transaction rolls back. The customer is charged and you have no record.
   - If all retries time out, step 6 rolls back, but the provider may have captured the payment on one of them.
   - Fix: commit `PENDING` with the idempotency key first, then call the provider outside any transaction. Then record the result (`PAID`, `FAILED`, or `PAYMENT_UNKNOWN`) in a second transaction.
   - Add a reconciliation job that queries the provider for orders stuck in `PENDING` or `PAYMENT_UNKNOWN`. The design currently has no way to detect or repair this.

3. **No idempotency on `POST /orders` itself.**
   - If a client times out or a user double-clicks, they get two orders and two charges.
   - Fix: require a client-supplied idempotency key, with a unique constraint in Postgres.

## Serious problems

4. **Overselling.**
   - The cache is up to 5 minutes stale and is only checked, never decremented or reserved.
   - Two concurrent buyers of the last unit both pass. At 2,000 orders a day, popular items will oversell.
   - Decide explicitly whether to accept oversells with a backorder or refund path, or to reserve stock. "We accept the cache" justifies the latency, not the oversell.

5. **The confirmation email is sent inline after commit.**
   - A crash or email-provider error between commit and send loses the email silently. A slow email provider slows the response.
   - Fix: write an outbox row in the same transaction as the `PAID` update and send from a worker. This is cheap at your scale.

6. **Request latency and connection holding.**
   - Three 5 s attempts mean the client waits 15 s or more, probably longer than the client's own timeout. That will trigger the client retries from item 3.
   - If you keep the transaction open during the charge, it also holds a database connection the whole time.
   - Fix: return `202` with the order id and let the client poll, or at least cap total retry time.

7. **Nightly backups on a single Postgres instance.**
   - A failure can lose up to 24 hours of orders and payment state while the provider still holds the charges. With no way to reconcile, that is unrecoverable.
   - Fix: enable WAL archiving or point-in-time recovery, or use a managed Postgres with it built in. This is a cheap fix.

## Smaller gaps

8. **Error handling.** Step 6 treats every failure the same. Separate a decline (tell the user), a timeout (state unknown), and a provider 5xx (retryable). Retry only the last two, and only with the idempotency key.
9. **Testing.** The only integration test is the happy path, but every risk above is in failure paths. Add a fake payment provider and tests for these cases: timeout then success, duplicate request, crash between charge and commit, decline, and concurrent last-unit purchase.
10. **State machine.** Only `PENDING` and `PAID` exist. Define the full set (`PAYMENT_UNKNOWN`, `FAILED`, `CANCELLED`, and so on) and the allowed transitions.
11. **Observability.** Order id in logs is good. Also add the idempotency key and provider reference, and alert on orders stuck in `PENDING` for more than N minutes.

## What's fine

- The scale, a single Postgres, and one team are fine. Don't add queues or microservices beyond the outbox worker and reconciliation job.
- Module boundaries, thin routes, and the `OrderCheckout` class are reasonable.
- Caching inventory to avoid the 800 ms warehouse call is a fair tradeoff once the oversell policy is stated.

The fixes are mostly design edits rather than a rewrite. Revise steps 3–6, add the state machine, and state the oversell policy. That is probably a day of work, and then it will be safe to build.

VERDICT: NOT READY
