The overall structure is solid, so you can start building tomorrow. But the payment step (steps 3 to 6) has two problems that can lose customers' money, and you should fix them on paper before you write that code. Both fixes are small. Everything else is either fine or can wait.

## What's already right
- **Module boundaries.** Orders, payments and inventory each keep to their own tables. That's the right choice for a team of four and it will scale to 2,000 orders a day.
- **Thin routes with an `OrderCheckout` service class.** The flow lives in one place you can test.
- **The inventory cache.** Accepting a 5-minute-old cache to avoid an 800 ms warehouse call is a deliberate tradeoff, and you wrote down why.
- **Logging the order id on every line.** You'll be glad of this the first time a payment goes wrong.

## Must fix before building the payment step

**1. Retrying a timed-out charge can charge the customer more than once.**
A timeout doesn't mean the charge failed. It only means you didn't get the answer back.
- *Case:* a customer pays $50. The provider takes the money, but its reply arrives after your 5 s timeout. You retry, and the provider takes another $50.
- *Expected:* one $50 charge.
- *Actual:* up to four charges, because you allow 3 retries.

*Fix:* send an idempotency key with every charge call and reuse the same key on each retry. The order id works well as the key. Most providers support this; check that yours does.

**2. The charge happens inside an open database transaction.**
- *Case:* the charge succeeds, then the commit fails, or the process crashes before it commits. The rollback removes the order.
- *Expected:* a `PAID` order.
- *Actual:* the customer has paid and you have no record of the order.

This setup also holds a database connection for up to 20 s (four 5 s attempts) during every slow payment.

*Fix:* commit `PENDING` first, then charge outside the transaction, then update the order in a second short transaction. An order left in `PENDING` then shows you exactly which ones need a status check with the provider.

```mermaid
flowchart TD
    A[POST /orders] --> B[Check stock against inventory cache]
    B --> C[Insert order as PENDING and commit]
    C --> D[Charge with idempotency key = order id<br/>retry on timeout with the same key]
    D -->|success| E[Mark PAID, commit]
    E --> F[Send confirmation email]
    D -->|declined| G[Mark FAILED, return error]
    D -->|still unknown| H[Leave PENDING<br/>check with provider later]
```

## Worth deciding now (each takes one line in the doc)
- **Overselling.** Two customers can both buy the last unit if they check out within the same 5-minute cache window. That may be acceptable, but write down what happens when it occurs: refund, backorder, or something else.
- **Email failure.** If the confirmation email fails after a successful payment, the client should still get a success response. Say so in the doc so nobody wires the email into the error path.
- **Backups.** Nightly backups mean losing up to a day of paid orders. Turning on point-in-time recovery (WAL archiving) is a cheap fix.

## Tests
One happy-path integration test isn't enough for this flow. Add tests for:
- a timeout followed by a successful retry, asserting a single charge with the same idempotency key
- a declined payment
- a payment whose outcome is still unknown after the last retry
- a failure after the charge has succeeded

Write these first. They pin down exactly the behaviour described in points 1 and 2.

You can start tomorrow on the module scaffolding, the inventory check and the order model. Do the two payment fixes before you get to the charge step.

VERDICT: READY WITH CHANGES
