The design is not ready to build as written: the Flow section can charge a customer twice, and can take a customer's money while leaving no order record. The Code structure section is sound and can stay. The fixes are a few hours of design revision, not a rethink.

## Problems that must be fixed before building

**1. Retrying the charge on timeout can double-charge (step 4).**
A timeout means "we don't know", not "it failed".
- **Case:** the provider completes the charge in 5.2 s, we give up at 5 s and retry, and the provider charges again.
- **Result:** the customer pays twice for one order; the expected result is one charge.
- **Fix:** send an idempotency key (the order id) with every charge attempt, so the provider treats retries as the same charge.

**2. Rollback erases the only evidence of a charge (steps 3–6).**
The order row exists only inside an open transaction while the provider is called.
- **Case:** all three attempts time out, but one actually succeeded at the provider. We roll back and return an error.
- **Result:** the customer is charged, and we have no order row and nothing to reconcile against; the expected result is an order we can either complete or refund.
- **Same outcome if:** the process crashes, or the commit fails, after a successful charge.
- **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 reconciliation job (or provider webhook) that resolves orders stuck in `PENDING` by asking the provider what happened.

**3. `POST /orders` itself is not idempotent (step 1).**
- **Case:** the client waits up to 15 s or more during retries, the user double-clicks or the mobile client retries, and two orders and two charges are created.
- **Fix:** have the client send an idempotency key, with a unique constraint on it.

**4. Nothing reserves or decrements stock (step 2).**
The flow checks a cache that is up to 5 minutes old and then never touches stock again.
- **Case:** one unit is left, two customers check out within the same 5 minutes, and both pass the check and both are charged.
- **Accepting the cache is reasonable** at this volume, but the design has to say what happens next. Either:
  - decrement a local stock count in the same transaction as the order insert, or
  - explicitly accept overselling and define the refund/backorder path.
- Right now it does neither.

**5. The test plan covers only the path where nothing goes wrong.**
"One integration test for the happy path" leaves every case above untested. At minimum, add integration tests for:
- timeout then success
- timeout on all attempts
- card declined
- duplicate `POST`
- crash between charge and status update
- out-of-stock

## Proposed flow

```mermaid
sequenceDiagram
    participant C as Client
    participant S as order-service
    participant DB as Postgres
    participant P as Payment provider
    C->>S: POST /orders (idempotency key)
    S->>DB: Tx 1: insert order PENDING, reserve stock, commit
    S->>P: Charge (idempotency key = order id), retry on timeout
    alt charged
        S->>DB: Tx 2: mark PAID
        S->>C: 201 Created
    else declined
        S->>DB: Tx 2: mark FAILED, release stock
        S->>C: Error
    else still unknown after retries
        S->>C: 202 Pending
        Note over S,P: Reconciliation job asks provider, then marks PAID or FAILED
    end
```

## Smaller gaps to decide, not blockers

- **Confirmation email:** if sending fails after commit, the customer gets no email and nothing retries it. Write an "email due" row in the same transaction as `PAID` and have a worker send it, or explicitly accept the loss.
- **Nightly backups:** a disk failure at 6 pm loses a day of paid orders, while the provider still holds the money. Turn on continuous WAL archiving (point-in-time recovery), or write down that 24 hours of loss is accepted.
- **Missing states:** there is no `FAILED`, cancel, or refund path. You need at least `FAILED` now; refunds can wait if you say so in the design.

## What is fine

- The module boundaries, thin routes, the `OrderCheckout` service class and order-id logging are right for a team of four.
- Load is not a concern: 2,000 orders a day is about one every 40 seconds. The problems are all correctness, not scale.

VERDICT: NOT READY
