**The design is not ready to build as written: the checkout flow can charge a customer twice, and can take money while leaving no order record.** The code structure section is sound, and the fix is a rewrite of steps 3–6 (roughly half a day of design work), not a rethink.

## Blocking problems

**1. Retrying on timeout can double-charge.**
A timeout does not mean the charge failed. For example, the provider completes the charge in 6 s, the service gives up at 5 s and retries, and the customer is charged twice for one order (up to four times in the worst case).

Fix: send an idempotency key with every charge attempt, derived from the order id. Confirm your provider supports one; if it doesn't, the retry has to become "query the charge status, then decide".

**2. Rollback on failure erases the only record of a charge that may have succeeded.**
If all attempts time out but one actually went through, step 6 deletes the `PENDING` row. The customer is charged, sees an error, and you have nothing in the database to refund against. The same happens if the process crashes, or the commit fails, after the charge succeeds.

Fix: commit the `PENDING` order before calling the provider, then update it to `PAID` or `FAILED` in a second transaction. An ambiguous outcome becomes a `PAYMENT_UNKNOWN` state that a reconciliation job resolves against the provider.

This also stops holding a database transaction open for up to 20 s across a network call. At 2,000 orders a day that is a correctness issue, not a load issue.

**3. Nothing reserves or decrements stock.**
The flow only reads the cache. Two customers ordering the last unit within the same 5-minute window both pass the check and both get charged. The cached read is fine as a fast pre-check, but it cannot be the only guard.

Fix: either decrement or reserve stock atomically at order time, or accept overselling and write down what happens next (refund, backorder, who is notified). This is a decision for you.

**4. `POST /orders` has no protection against client retries.**
A double-click or a mobile client retrying on a dropped connection creates two orders and two charges.

Fix: the client sends an idempotency key, with a unique constraint on it in the orders table.

## Should fix, not blocking

- **Confirmation email:** send it after commit, and make sure a failed send cannot fail or roll back a paid order. An outbox table or a simple retry job is enough.
- **Tests:** one happy-path integration test misses where this flow breaks. Add integration tests for timeout-then-success, charge succeeded but the update failed, duplicate request, and the last-unit race.
- **Backups:** nightly backups mean losing up to 24 hours of paid orders. Turn on continuous WAL archiving (point-in-time recovery); it is cheap on a single instance.
- **Error handling:** the design only covers timeouts. State which provider errors are retryable (network, 5xx) and which are not (card declined).

## What is fine

Single Postgres instance, one service, and the module boundaries are all appropriate for 2,000 orders a day and a team of four. Don't add queues or sagas beyond the reconciliation job.

## Proposed flow

```mermaid
flowchart TD
    A[POST /orders with idempotency key] --> B{Key seen before?}
    B -- yes --> B1[Return existing order]
    B -- no --> C[Check stock cache]
    C --> D[Transaction 1: reserve stock, insert order PENDING, commit]
    D --> E[Charge provider with order-id idempotency key, retry on timeout]
    E -- success --> F[Transaction 2: mark PAID, queue email]
    E -- declined --> G[Transaction 2: mark FAILED, release stock]
    E -- still unknown --> H[Mark PAYMENT_UNKNOWN, reconciliation job resolves]
```

## Decisions for you before building

1. Does your payment provider support idempotency keys?
2. What is the oversell policy: a hard reservation, or oversell and refund?
3. What does the client see when the payment outcome is unknown? I recommend "order received, confirmation pending".

Module scaffolding and the inventory and order modules can start tomorrow, but the `OrderCheckout` service should wait until steps 3–6 are rewritten.

VERDICT: NOT READY
