The design isn't ready to build as written. The structure and scale assumptions are fine, but the payment part of the flow (steps 3–6) can charge customers twice, or charge them with no order saved. Those steps need rewriting first. The fix is small and well understood, so you can probably get it done before tomorrow.

## Must fix before building

**1. Retrying the charge on timeout can charge the customer twice (step 4).**
A timeout doesn't mean the charge failed. It means you don't know whether it went through.
- **Case:** the first charge call succeeds at the provider, but the response takes longer than 5 s. The service retries, and the second call also succeeds.
- **Result:** the card is charged twice and there is one `PAID` order.
- **Expected:** one charge.
- **Fix:** send an idempotency key (the order id) with every charge call, so the provider treats retries as the same charge. Check that your provider supports this; most do.

**2. The charge happens inside an open database transaction, so a payment can exist with no order (steps 3–6).**
The `PENDING` row is never committed, so nobody else can see it. If anything goes wrong after the charge, the order disappears.
- **Case:** the charge succeeds, then the commit fails, or the process restarts before committing.
- **Result:** the customer is charged and the database has no order.
- **Expected:** an order record that matches the charge.
- **Second problem:** with 4 attempts × 5 s, one database connection can stay open for over 20 s per checkout.
- **Fix:** commit the `PENDING` order first, call the provider outside any transaction, then mark the order `PAID` in a second short transaction. Add a scheduled job that finds orders stuck in `PENDING` and asks the provider what happened.

**3. A failed checkout can be reported as failed when the payment went through (step 6).**
After 3 timeouts, the payment state is unknown, not failed. The design treats "card declined" and "no answer" the same way.
- **Fix:** add a separate state such as `PAYMENT_UNKNOWN`. Tell the customer the order is being confirmed, and let the scheduled job from fix 2 settle it.

**4. A client retry can create a duplicate order (step 1).**
If the user double-clicks, or the client gives up during the 20 s wait and resubmits, you get a second order and possibly a second charge.
- **Fix:** accept an `Idempotency-Key` header on `POST /orders` and return the existing order when a key repeats.

Proposed flow after fixes 1–4:

```mermaid
flowchart TD
  A[POST /orders with Idempotency-Key] --> B{Key seen before?}
  B -- yes --> R[Return existing order]
  B -- no --> C[Check stock in inventory cache]
  C --> D[Insert order PENDING and commit]
  D --> E[Charge provider, idempotency key = order id, retry on timeout]
  E -- success --> F[Mark PAID and commit]
  F --> G[Send confirmation email in the background]
  E -- declined --> H[Mark FAILED, return error]
  E -- still timing out --> I[Mark PAYMENT_UNKNOWN, tell client it is being confirmed]
  I --> J[Scheduled job asks provider, then sets PAID or FAILED]
```

## Needs a decision from outside the team

**5. Overselling (step 2).** The stock check uses a cache that can be up to 5 minutes old, and nothing reserves or reduces stock. If two customers buy the last unit within that window, both orders succeed. Accepting the cache is a reasonable choice at this volume. But someone on the business side needs to say what happens to the second order: backorder, cancel and refund, or something else. The design should also say when the warehouse system is told about the sale.

## Should fix, not blocking

- **Tests (Code structure section):** one happy-path integration test misses the cases that cost money. Add integration tests for a charge timeout followed by a successful retry (exactly one charge), a declined card, a commit failure after a successful charge, a repeated `Idempotency-Key`, and the job that settles stuck `PENDING` orders.
- **Email failures:** say that a failed confirmation email never fails the order. Send it in the background after the commit and retry it there.
- **Backups:** nightly backups of a single Postgres instance mean up to a day of orders could be lost. At 2,000 orders a day, ask whether point-in-time recovery is worth adding. The provider would still hold the charges, but you'd have to rebuild the orders from them.

The rest holds up: 2,000 orders a day is light load, and the module boundaries and thin routes are sound. Once steps 3–6 are rewritten as above and the overselling question is answered, you can start building.

VERDICT: NOT READY
