The design is nearly ready to build: the module layout, thin routes and sizing are sound, but the payment step (steps 3–6) can charge a customer twice or take their money without recording an order. Both are fixed by small changes to the flow, not a redesign.

## Fix before building

**1. Retrying a timed-out charge can charge the customer twice.**
A timeout means "no answer", not "the charge failed".
- **Case:** the provider processes the charge in 6 s, the service gives up at 5 s and retries, and the provider charges again.
- **Result:** the customer is charged twice for one order; the expected result is one charge.
- **Fix:** send an idempotency key (the order id) with every charge attempt, so the provider treats retries as the same charge. Most providers support this.

**2. A charge can succeed with no order left in the database.**
The `PENDING` row lives in an uncommitted transaction while the payment call runs.
- **Case:** the charge succeeds, then the service crashes or the commit fails. The same happens if all three retries time out but one charge actually went through.
- **Result:** the transaction rolls back, the customer is charged, and there is no order row to refund or reconcile against. The expected result is an order row that records that a charge was attempted.
- **Fix:** commit the `PENDING` order first, call the provider outside any transaction, then update to `PAID` or `FAILED` in a second short transaction. Add a small job that checks old `PENDING` orders against the provider.

This also stops a database connection being held open for up to 20 s per checkout.

```mermaid
sequenceDiagram
    Client->>Service: POST /orders
    Service->>DB: insert order PENDING, commit
    Service->>Payment: charge (idempotency key = order id)
    Payment-->>Service: success / decline / timeout
    Service->>DB: update to PAID or FAILED, commit
    Service->>Client: result
    Service-)Email: confirmation (after PAID)
```

## Decide, but can be built in parallel

- **Stock is checked but never reserved or decremented.** Two customers can buy the last unit within the 5-minute cache window. Accepting the cache is reasonable at this volume, but the design should say what happens on an oversell (refund and apology, or backorder) and who decrements stock.
- **Duplicate `POST /orders`.** A double-click or client retry creates two orders. Accepting a client-supplied idempotency key on the request solves it.
- **Test plan covers only the happy path.** The risk in this flow is on the failure paths, so add integration tests for decline, timeout then success, and a crash between charge and update.
- **Confirmation email failure.** State that a failed email does not fail the order, and that it gets retried.

Once fixes 1 and 2 are in the doc, you can start tomorrow; the code structure section needs no changes.

VERDICT: READY WITH CHANGES
