I wouldn't start building this tomorrow. The context, scale assumptions and code structure are fine. The problem is the payment flow in steps 3–6, which is the core of the service: as written, it will double-charge some customers and charge others without creating an order. Those flaws would only show up in production, and fixing them changes the shape of `OrderCheckout`, so they need fixing before you write it.

## Blocking issues

**1. Retrying the charge after a timeout can charge the customer twice (step 4).**
A timeout doesn't mean the charge failed. It means you don't know. The provider may have charged the card, and then you send the same charge again, up to 3 more times. Each retry needs to carry the same **idempotency key** (for example, the order id) so the provider treats it as the same charge. If your provider doesn't support idempotency keys, you can't safely retry automatically. You'd have to look up the charge's status before trying again.

**2. A rollback after a timeout loses an order that was actually charged (steps 3, 6).**
The `PENDING` row only exists inside an uncommitted transaction. If the charge went through but the response timed out, or the process crashes after the charge and before the commit, step 6 rolls back. The customer has been charged, there's no order row, and nothing in your system records that a charge was attempted. That's the worst possible failure for a checkout.

**3. The database transaction stays open across a slow external call.**
With 4 attempts at 5 s each, one transaction can sit open for over 20 s while it waits on the payment provider. That holds a connection and locks the whole time. At 2,000 orders a day you won't run out of connections, but it's still the wrong structure, and it's the reason issue 2 exists.

**Fix for 1–3 (one redesign):**
- Commit `PENDING` in its own short transaction, *before* you charge.
- Call the provider outside any transaction, using the order id as the idempotency key.
- Record the result in a second short transaction: `PAID`, `FAILED`, or `PAYMENT_UNKNOWN`.
- Add a reconciliation job that finds orders left in `PENDING` or `PAYMENT_UNKNOWN` for more than N minutes and asks the provider what actually happened.
- Write down the states and the allowed transitions between them. That list *is* the design for this service, and it isn't in the doc yet.

**4. Nothing stops a client from creating the same order twice (step 1).**
Mobile clients and users who double-click will retry `POST /orders`, and each retry currently creates a new order and a new charge. Accept an `Idempotency-Key` header from the client, store it with a unique constraint, and return the existing order when the same key comes back.

**5. Stock is checked but never reserved (step 2).**
There are two separate problems here:
- **Stale cache:** stock is up to 5 minutes out of date.
- **No reservation:** two orders for the last unit can both pass the check, even with a perfectly fresh cache.

The doc also doesn't say when or how the warehouse finds out about a sale. Either add a reservation or decrement step, or write down explicitly that "we accept overselling, and here's what happens when we do" (refund, backorder, or apologise to the customer). Either choice is fine, but it has to be a decision someone made.

Also, the reason given for using the cache doesn't hold up. You already accept a payment call of several seconds in the same request, so 800 ms for a direct warehouse call isn't what makes checkout slow.

## Should fix before launch (not blocking tomorrow)

- **Backups:** with only nightly backups, a failure late in the day loses up to a day of *paid* orders. At 2,000 orders a day that's up to 2,000 customers you've charged and have no record of. Turn on WAL archiving / point-in-time recovery. On managed Postgres it's a setting.
- **Confirmation email:** step 5 sends it inline, and the doc doesn't say what happens if sending fails. Queue it after commit (an outbox table works) so a mail outage can't break checkout.
- **Tests:** one happy-path integration test isn't enough for code that handles money. Write integration tests for these cases:
  - the charge times out but actually succeeded
  - a retry is sent with the same idempotency key
  - the process crashes between the charge and the commit
  - the client sends the same `POST` twice
  - the reconciliation job resolves a stuck order
- **Inventory module:** if it owns stock and the orders module can't read its tables, you need to define the interface for reserving and releasing stock (it ties into issue 5).

## What's already good

- Your scale assumptions are realistic: a single Postgres instance and a four-person team are both fine at 2,000 orders a day.
- The module boundaries are sensible, the routes are thin, and logging the order id on every line will make the reconciliation work much easier.

Rewriting steps 3–6 as a state machine with idempotency keys and a reconciliation job, and making the stock decision, is probably half a day to a day of design work. Once that's done, I'd expect this to be ready.

VERDICT: NOT READY
