**Not ready. The charge-retry step can charge a customer up to three times for one order, and the doc doesn't say how to stop that.** That needs fixing before you write code. The other gaps are smaller.

## Blocking problems

**1. Retrying the charge can double-charge (step 4).**
- Case: the payment provider charges the card, but the response takes longer than 5 s. Your service treats that as a timeout and retries. The provider charges again, and the customer is billed twice for one order.
- The doc doesn't mention an idempotency key, which is a unique ID sent with each charge so the provider ignores repeats. Most providers support one. Derive it from the order id and send the same key on every retry.
- The doc also doesn't say what happens if all 3 retries time out. The charge may have gone through, and "roll back and return an error" would leave a paid customer with no order.

**2. The database transaction stays open during the payment call (steps 3–6).**
- The transaction opens in step 3 and doesn't commit until step 5. Three retries at 5 s each means it can hold a connection for 15 s or more.
- With a single Postgres instance and a normal connection pool, a slow payment provider can use up the pool and take down the whole service, including requests that don't involve payments.
- At 2,000 orders a day the average load is small. The risk is a burst combined with a slow provider.

**3. Rolling back after a charge hides the money.**
- If the charge succeeds but the commit or the `PAID` update fails, the rollback erases the order while the customer has already paid. Nothing records that a charge happened.
- Fix: commit the `PENDING` order first. Store the charge attempt and its key. Update the order to `PAID` or `FAILED` afterward. Add a reconciliation job that finds orders stuck in `PENDING` and asks the provider what happened.

**4. Stock checking can oversell.**
- The cache is up to 5 minutes old, and the flow only reads it. It never reserves stock.
- Case: 1 unit is left and two customers check out within the same minute. Both pass the check, both get charged, and one order can't be filled.
- The doc justifies the cache by speed (800 ms), but speed isn't the problem. The problem is that nothing decrements or reserves stock. Decide what happens on oversell, such as backorder or refund, or add a reservation step.

## Should fix before building

**5. Duplicate orders.**
- If a client times out or double-clicks and sends `POST /orders` again, it creates a second order and a second charge.
- Add an `Idempotency-Key` header on the endpoint, with a unique constraint in the database.

**6. Confirmation email is in the commit path (step 5).**
- If the email provider is down, does the order fail? If it's sent after the commit and the send fails, the email is lost silently.
- Use an outbox table (a row written in the same transaction, sent later by a worker) or at least a retry. State which one you chose.

**7. Backups are nightly on a single instance.**
- A failure at 5pm loses up to 17 hours of orders, and some of those customers have already been charged.
- The provider's records could rebuild some of them, but that's a recovery plan you'd have to write. For payments data, point-in-time recovery (continuous archiving of the database log) is cheap to turn on and worth it.

**8. Missing from the doc:**
- An order state machine: the allowed statuses and transitions (`PENDING`, `PAID`, `FAILED`, plus refund and cancel).
- Refund handling.
- Authentication on the endpoint.
- Rate limiting.
- Which errors the client sees, and which are safe to retry.

## Testing plan is too thin

"One integration test for the happy path" skips exactly the cases that fail in production. Add tests, written first per your standards, for:
- A payment timeout followed by a retry that succeeds, asserting exactly one charge.
- All retries failing.
- A charge that succeeds followed by a database failure.
- A duplicate `POST /orders` with the same key.
- A stale cache with the last unit of stock.
- An email failure, which must not affect order status.

Use a fake payment provider that can simulate delayed responses.

## What's fine
- The module separation and the thin routes with an `OrderCheckout` service are sound.
- Using a cache at your current volume is defensible, once oversell is handled.
- The scale (200 to 2,000 orders a day) doesn't need a queue or a distributed system. Don't add one. The fixes above are all small changes.

## Suggested next step
Revise the flow to this order: save the `PENDING` order and commit, then call the payment provider with an idempotency key, then record the result. Add the reconciliation job. That is about a half-day of design work, and it prevents the worst failure (charging customers with no record).

VERDICT: NOT READY
