The design is not safe to build as written, but the fixes are confined to steps 2 to 6 of the flow and are about an hour of doc edits, so you can still start tomorrow. The code structure and the scale assumptions are fine: 2,000 orders a day is trivial load for a single Postgres instance and a team of four.

## Must fix before writing payment code

**1. Retrying the charge on timeout can charge the customer twice.**
A timeout means "no answer", not "charge failed". For example, attempt 1 succeeds at the provider but the response takes 6 s; the service retries, and the customer is charged twice for one order.
- **Fix:** send an idempotency key (the order id) with every charge call, so the provider treats retries as the same charge.

**2. A charge can succeed with no record of the order.**
The `PENDING` insert sits in an open transaction during the payment call, so a rollback erases it. For example, all three attempts time out but one actually went through; step 6 rolls back, and the customer has paid for an order that does not exist in the database. A process crash between the charge and the commit does the same.
- **Fix:** commit the `PENDING` order first, call the provider outside any transaction, then update to `PAID` or `FAILED` in a second short transaction.
- **Also needed:** a small scheduled job that asks the provider about orders stuck in `PENDING` and resolves them.
- **Side benefit:** the service no longer holds a database connection for up to 15 s per slow checkout.

**3. A client retry of `POST /orders` creates a duplicate order.**
The request can take over 15 s, so client timeouts and double-taps are likely. For example, the app times out at 10 s and resends, giving two orders and two charges.
- **Fix:** accept a client-supplied idempotency key, store it with a unique constraint, and return the existing order on a repeat.

**4. Nothing in the flow reduces stock, so the service can oversell.**
The cache is up to 5 minutes stale and no step decrements or reserves anything. For example, with one unit left, two customers who order within the same 5 minutes both pass the check and both pay.
- **Fix:** the cache is fine as a first filter, but track reservations in the service's own table and decrement in the same transaction as the `PENDING` insert.
- **Decision for you:** if you accept occasional oversell instead, write down what happens next (refund, backorder, who is notified).

**5. The test plan only covers the path where nothing goes wrong.**
Every failure above is on a non-happy path. Add integration tests, against a fake provider, for:
- timeout then success
- timeout on all attempts
- declined card
- duplicate client request
- crash between charge and status update
- out of stock

## Revised flow

```mermaid
flowchart TD
    A[POST /orders with idempotency key] --> B{Key seen before?}
    B -- yes --> C[Return existing order]
    B -- no --> D[Transaction: reserve stock, insert order PENDING, commit]
    D --> E[Charge provider, order id as idempotency key, retry on timeout]
    E -- success --> F[Update order to PAID, commit]
    E -- declined --> G[Update order to FAILED, release stock]
    E -- still unknown --> H[Leave PENDING for reconciliation job]
    F --> I[Send confirmation email]
```

## Should fix, not blocking

- **Email failure:** state that a failed confirmation email does not fail the order, and that it is retried.
- **Backups:** nightly backups mean a disk failure can lose up to a day of paid orders. Turn on continuous WAL archiving (point-in-time recovery).
- **Retry wording:** say whether "retries up to 3 times" means 3 or 4 attempts in total, and add a backoff between them.

VERDICT: READY WITH CHANGES
