The design is ready to build on once you change the payment step (steps 3–6). As written, it can charge a customer twice, or charge them and leave no order record. The module boundaries, thin routes, the `OrderCheckout` service and the logging plan are sound, and I would not change them.

## The two changes to make before building

**1. Retrying on timeout can charge the customer twice.**
A timeout does not mean the charge failed, only that you did not hear back.
- **Input:** the charge call succeeds at the provider, but the response takes 6 seconds.
- **What happens:** the service times out at 5 s and retries, and the provider charges the card a second time.
- **Expected:** one charge.
- **Fix:** send an idempotency key (the order id works) on every charge attempt, so the provider treats retries as the same charge. Most providers support this.

**2. The order row exists only inside an open transaction while the charge happens.**
- **Input:** the charge succeeds, then the commit fails or the process crashes before it (deploy, lost connection).
- **What happens:** the `PENDING` insert rolls back, so the customer has paid and the database has no trace of the order.
- **Expected:** a record that survives, so the charge can be matched up or refunded.
- **Same root cause:** if all three retries time out, step 6 rolls back and returns an error, though one of those charges may have gone through.
- **Side effect:** the transaction holds a database connection open for up to 20 seconds (4 attempts × 5 s) per slow checkout.
- **Fix:** commit the `PENDING` order first, call the provider outside any transaction, then update the status in a second short transaction. Send the email after that commit.

```mermaid
flowchart TD
    A[POST /orders] --> B[Check stock]
    B --> C[Insert order as PENDING and commit]
    C --> D[Charge with order id as idempotency key]
    D -->|success| E[Mark PAID and commit]
    E --> F[Send confirmation email]
    D -->|declined| G[Mark FAILED, return error]
    D -->|still timing out after retries| H[Leave PENDING, return 'payment processing']
    H --> I[Background job asks provider for the outcome]
    I --> E
    I --> G
```

The background job is what makes the timeout case safe: an order stuck in `PENDING` is resolved by asking the provider what happened rather than by guessing.

## Decisions to write down, not blockers

- **Stock:** the flow checks stock but never reserves or decrements it. With a cache up to 5 minutes old, two customers can both buy the last unit. At 200 orders a day this may be rare enough to handle by apology and refund, but the design should say so and name who handles an oversold order.
- **Tests:** one happy-path integration test will not cover the payment step. Add integration tests for timeout-then-success, decline, and crash between charge and commit, since those are the cases above.

Single-instance Postgres with nightly backups is fine for 2,000 orders a day.

VERDICT: READY WITH CHANGES
