**The design isn't ready to build tomorrow.** As written, step 4 can charge a customer more than once, and a crash between the charge and the commit leaves a customer charged with no order. Both need fixing before any code is written.

## Blockers

**1. The charge retry can double-charge.**
- A 5 s timeout doesn't mean the charge failed. It means you didn't hear back.
- Example: the provider charges $80, the response is slow, and you time out. You retry, and the customer is charged $160. Nothing in the design stops this.
- Fix: send an idempotency key with every charge call. Use the order id or a stored payment-attempt id, so retries are safe. Check that your provider supports this.
- Also define what happens after 3 timeouts. You don't know whether the charge went through, so look up its status or reconcile later. Don't roll back and tell the client "failed".

**2. A crash after the charge loses the order.**
- The flow charges the card inside an open database transaction. If the process dies or the commit fails after the charge succeeds, the `PENDING` row is rolled back. The customer is charged and you have no record of it.
- Fix:
  - Commit the order as `PENDING` first, together with a payment-attempt row.
  - Call the provider outside the transaction.
  - Record the result in a second short transaction.
  - Add a reconciliation job that checks stale `PENDING` orders against the provider.
- Add `PAYMENT_FAILED` and `PAYMENT_UNKNOWN` states. Right now there are only `PENDING` and `PAID`.

**3. The same fix covers a second problem: the database connection is held for up to 15 seconds.**
- Three attempts at 5 s each hold a connection and any locks for 15 s or more.
- At 2,000 orders a day this is survivable. A slow provider on a bad day will still exhaust your connection pool.

**4. Nothing reserves stock, so you can oversell.**
- Step 2 reads a cache that is up to 5 minutes old, and nothing decrements stock afterward.
- Example: 1 unit is left and 3 customers check out within the same 5 minutes. All 3 pass the check and all 3 pay.
- The 800 ms warehouse call is not the real choice. You need either a local reservation or decrement at order time, or an explicit decision to oversell and handle it afterward (backorder or refund). The doc does neither. It also doesn't say who decrements stock after a sale.

**5. `POST /orders` has no client-side idempotency.**
- A double-click, or a client retry after a network blip, creates two orders and two charges.
- Fix: require an `Idempotency-Key` header and enforce it with a unique constraint.

## Should fix before building

- **Confirmation email:** it is sent inline after the commit, and the design doesn't say what happens if sending fails. Write an outbox row in the same transaction as the `PAID` update and let a worker send it. An email failure must not turn a paid order into an error response.
- **Backups:** nightly backups on a single instance means a crash can lose up to 24 hours of paid orders. Enable WAL archiving or point-in-time recovery. It is cheap and the doc ignores it.
- **Cart validation:** the doc doesn't say where prices come from. The server must price the cart itself and never trust client-sent amounts. It also doesn't mention auth, currency, or amount rounding.
- **Failure responses:** "return an error" is too vague. A card decline (4xx, safe to retry with a new card), a provider timeout (outcome unknown), and out of stock should each return something different.
- **Tests:** only a happy-path integration test is planned, but your own standards require failure cases. At minimum add:
  - timeout then success, asserting a single charge;
  - three timeouts;
  - decline;
  - crash between charge and commit;
  - duplicate idempotency key;
  - oversell.
  
  Use a fake payment provider that can inject these faults.

## What's sound

- Module boundaries and thin routes are fine.
- Putting the flow in `OrderCheckout` is fine.
- Logging the order id on every line is fine.
- The volume (200 to 2,000 orders a day) doesn't need anything more than one Postgres instance, so don't over-engineer the infrastructure. The gaps are in correctness, not scale.

## Next step

Revise the flow section to cover points 1, 2, 4 and 5 above, and add an order-state diagram. That is about half a day of design work, and it is much cheaper than finding out about double charges in production.

VERDICT: NOT READY
