**Not as written, but you can start tomorrow if you rewrite steps 3–6 of the flow first.** The payment step can charge a customer twice, or charge them and leave no order record. The module layout and the choice to keep it simple at 2,000 orders a day are sound.

## Must fix before writing checkout code

**1. A retry after a timeout can charge the customer twice (step 4).**
A timeout means "no answer", not "not charged". For example, the provider takes the charge at 4.9 s, the response arrives at 5.1 s, the service retries, and the customer pays twice for one order. Send an idempotency key (the order id) on every charge attempt so the provider treats retries as the same charge. Confirm your provider supports this; most do.

**2. Rollback erases the only record of an order that may have been paid (steps 3, 5, 6).**
The `PENDING` row lives inside an uncommitted transaction while the payment call runs. Two failing cases:
- All three attempts time out but the first one actually succeeded. The service rolls back and returns an error, so the customer is charged and no order exists.
- The charge succeeds, then the process crashes or the commit fails. The outcome is the same, and there is nothing to reconcile against.

Commit `PENDING` first, call the provider outside any transaction, then update to `PAID` or `FAILED` in a second short transaction. Add a small reconciliation job (or the provider's webhook) that resolves orders stuck in `PENDING` by asking the provider what happened.

**3. `POST /orders` has no protection against the client retrying.**
A customer on a slow connection double-clicks, or the app retries after its own timeout, and you get two orders and two charges. Accept a client-generated idempotency key with a unique constraint, and return the existing order on a repeat.

**4. Nothing ever reserves or decrements stock (step 2).**
The 5-minute cache is a reasonable trade, but the flow only reads it. With one unit left, every order in the next 5 minutes passes the check, and two concurrent requests both pass even with a fresh cache. Either decrement a local count in the same transaction as the order insert, or decide explicitly that overselling is allowed and write down what happens (backorder or refund, and who is told). This needs a product decision today.

```mermaid
sequenceDiagram
    participant C as Client
    participant S as order-service
    participant DB as Postgres
    participant P as Payment provider
    C->>S: POST /orders (cart, idempotency key)
    S->>DB: Check stock, decrement, insert order PENDING, commit
    S->>P: Charge (key = order id), retry on timeout
    alt charged
        S->>DB: Mark PAID, commit
        S->>C: Success
        S-->>C: Confirmation email (failure does not fail the order)
    else declined
        S->>DB: Mark FAILED, restore stock, commit
        S->>C: Error
    else still unknown after retries
        S->>C: "Payment pending"
        Note over S,P: Reconciliation job resolves PENDING later
    end
```

## Should fix, can land in the first week

- **Tests:** one happy-path integration test leaves out everything above. Add integration tests for a timeout that later succeeds, a decline, a duplicate `POST`, a crash between charge and `PAID`, and two concurrent orders for the last unit.
- **Declines and timeouts are treated alike:** a declined card should fail immediately, not be retried. Only timeouts and 5xx responses should retry, with backoff.
- **Email:** say what happens when the send fails. It should be logged and retried, and should never turn a paid order into an error response.
- **Backups:** nightly backups on a single instance mean a disk failure at 5 pm loses a day of orders whose payments were taken. Turn on point-in-time recovery (WAL archiving).

## What I would not add

At 2,000 orders a day (about 1.4 a minute) you do not need queues, a saga framework, or a second database. The fixes above are a few extra columns, a unique constraint, and one scheduled job.

VERDICT: READY WITH CHANGES
