I read through the design. The structure and scale assumptions hold up, but the payment part of the flow (steps 3–6) can charge customers twice, or take their money and keep no record of the order. Both are fixable in an hour of design work. Fix them before you write `OrderCheckout`.

## Must fix before building

**1. Retrying the charge on timeout can charge twice (step 4).**
A timeout doesn't mean the charge failed. The provider may have processed it and the reply just didn't arrive in time. Retrying up to 3 times with no idempotency key could charge the customer up to 4 times.
→ Send an idempotency key with every charge call (the order id works), and check that your provider supports it.

**2. The database transaction stays open during the payment call (steps 3–5).**
- **Slow:** with 4 attempts × 5 s, one checkout can hold a transaction and a pool connection for about 20 s. At 2,000 orders a day, a slow afternoon at the provider could use up the connection pool.
- **Lost orders:** if the charge succeeds but the commit fails (crash, deploy, connection drop), the rollback deletes the `PENDING` row. The customer has paid and no order exists.
- **No audit trail:** on failure, step 6 rolls back, so there's no record that the attempt ever happened.

→ Change the flow to:
1. Insert the order as `PENDING` and commit.
2. Call the payment provider outside any transaction, with the idempotency key.
3. In a short new transaction, set the order to `PAID` or `FAILED`.

**3. Add a third outcome: "we don't know" (step 6).**
After the last retry times out, the design returns an error to the client, but the charge may have gone through. Leave the order `PENDING` and resolve it later, using the provider's webhook or a job that looks up stuck `PENDING` orders by idempotency key. Tell the client the order is "processing", not "failed". Otherwise they'll retry and pay twice.

**4. `POST /orders` has no idempotency.**
If the client double-clicks or retries after a network drop, it creates a second order and a second charge. Have the client send an idempotency key and dedupe on it.

## Should fix (can come during the build)

- **Inventory is never reserved or decremented.** Step 2 checks stock against a cache that can be 5 minutes old, and nothing in the flow reduces stock. The cache trade-off is reasonable, but the design should say what happens when you oversell (refund? backorder?) and how the warehouse learns about the sale.
- **Send the confirmation email asynchronously,** for example from an outbox table. Right now an email failure has no defined behavior, and it should never affect the order.
- **Tests:** one happy-path integration test misses the risky paths. Add integration tests for a payment timeout, a timeout followed by success, a commit failure after a successful charge, and a duplicate `POST /orders`.
- **Backups:** nightly backups mean you could lose up to 24 hours of paid orders. Point-in-time recovery (WAL archiving, or the managed equivalent) is cheap insurance.

## What's fine

- At 200–2,000 orders a day, a single Postgres instance is plenty.
- The module boundaries with no reading of another module's tables, the thin routes, the `OrderCheckout` service class, and logging the order id on every line are all good choices for a team of four.

You can start on the modules, schema and routes tomorrow. Rewrite steps 3–6 along the lines above before you implement the payment call.

VERDICT: READY WITH CHANGES
