The design is not safe to build as written, but it is close: steps 3–6 of the flow can charge a customer twice or take their money without recording an order. The fixes are small and need no new infrastructure. The module layout and the overall simplicity suit 200 to 2,000 orders a day and can stay.

## Must fix before building

**1. Retrying the charge on timeout can double-charge.**
A timeout means "we don't know", not "it failed". Example: the provider completes the charge in 6 seconds, the service gives up at 5 and retries, and the customer is charged twice for one order.
- **Fix:** send an idempotency key (the order id) with every charge attempt, so the provider treats retries as the same charge.
- **To check:** I assumed your provider supports idempotency keys, as most do; confirm that today.

**2. Rolling back on failure can erase the only record of a charged order.**
The `PENDING` row is inserted inside a transaction that stays open during the payment call, so it is never visible to anyone until commit. Example: all attempts time out but one actually went through at the provider. Step 6 rolls back, the customer has been charged, and the database has no trace of the order. The same happens if the service crashes after the charge but before commit.
- **Fix:** commit the `PENDING` order first, call the provider outside any transaction, then update the order to `PAID` or `FAILED` in a second short transaction.
- **Fix:** add a `PAYMENT_UNKNOWN` state for exhausted timeouts, plus a small job that asks the provider what happened to those orders and to stale `PENDING` ones.
- **Side benefit:** this stops holding a database connection for up to 20 seconds per checkout.

**3. `POST /orders` has no protection against duplicate submissions.**
Example: a double-click or a mobile client retrying on a flaky network creates two orders and two charges.
- **Fix:** have the client send an idempotency key, put a unique constraint on it, and return the existing order on a repeat.

**4. Nothing reserves or decrements stock.**
The flow only checks a cache that is up to 5 minutes old. Example: two customers buy the last unit within the same 5 minutes, and both are charged.
- **Fix (my recommendation):** keep the cache for the check, since at this volume overselling will be rare, but write down what happens on an oversell (refund or backorder, and who is notified).
- **Alternative:** decrement a local stock count in the same transaction as the order insert.

## Revised flow

```mermaid
flowchart TD
    A[POST /orders with idempotency key] --> B{Key seen before?}
    B -- yes --> C[Return existing order]
    B -- no --> D[Check stock against inventory cache]
    D --> E[Insert order as PENDING and commit]
    E --> F[Charge payment provider, order id as idempotency key, retry on timeout]
    F -- success --> G[Mark PAID, commit, send confirmation email]
    F -- declined --> H[Mark FAILED, return error]
    F -- still timing out --> I[Mark PAYMENT_UNKNOWN, reconciliation job resolves it]
```

## Should fix, not blocking

- **Tests:** one happy-path integration test leaves the risky paths uncovered. Add integration tests for a declined charge, a timeout followed by success, exhausted timeouts, and a duplicate `POST`, written first against a fake payment provider.
- **Email:** a failed confirmation email must not fail a paid order. Send it after commit, then log and retry on failure.
- **Backups:** nightly backups on a single instance mean a disk failure can lose up to a day of paid orders. Turn on point-in-time recovery (continuous log archiving).
- **Declines:** the design does not say how a decline differs from a timeout. Declines should never be retried.

If you update steps 3–6 as above and confirm the provider's idempotency support, you can start building tomorrow.

VERDICT: READY WITH CHANGES
