Not as written, but it's close. The scale assumptions, module boundaries and code structure are fine for 2,000 orders a day and four people. The problem is the payment step: as designed it can charge a customer twice, or take their money and keep no record of the order. Those two fixes, plus a stock policy and failure-path tests, are maybe half a day of design work. Make them before you build the checkout flow; you can start on the modules tomorrow.

## Must fix before building the payment step

**1. Retrying a timed-out charge can double-charge the customer (step 4).**
A timeout doesn't mean the charge failed, only that you didn't hear back.
- Case: the provider charges £50, but its reply takes 6 s. Your 5 s timeout fires and you retry, and the provider charges another £50.
- What happens: the customer pays £100 for one order.
- What should happen: £50.

Fix: send an idempotency key (for example, the order id) with every charge attempt, so the provider treats retries as the same charge. Check that your provider supports this. Most do.

**2. The charge runs inside an open database transaction (steps 3–6).**
This causes two problems:
- **Money taken, order lost.** Case: the charge succeeds, then the commit fails (connection drop, deploy, crash). The rollback removes the `PENDING` row. The customer has paid and you have no order and no record of the attempt, so you can't reconcile it.
- **Slow failures hold connections.** With 3 retries, a single order can hold a transaction open for over 20 s. A slow payment provider would then use up your database connections.

Fix: commit the `PENDING` order first, call the provider outside any transaction, then update the order in a second short transaction. On failure, mark the order `FAILED` instead of deleting it. Add a small job that checks orders stuck in `PENDING` against the provider.

```mermaid
flowchart LR
  subgraph Before
    A1[Begin txn] --> A2[Insert PENDING] --> A3[Charge, retry x3] --> A4[Mark PAID, commit]
  end
  subgraph After
    B1[Insert PENDING, commit] --> B2[Charge with idempotency key, retry x3] --> B3[Mark PAID or FAILED, commit] --> B4[Send email]
  end
```

## Should fix (decide now, cheap to do)

**3. The client can submit the same order twice.** If a client retries `POST /orders` (double-click, mobile network retry), you create two orders and two charges. Accept a client-supplied idempotency key on the endpoint.

**4. Overselling from the stock cache (step 2).** Accepting a cache up to 5 minutes old is a reasonable tradeoff. But the doc doesn't say what happens when it's wrong.
- Case: 1 unit left, two customers check out within the same 5 minutes. Both pass the stock check and both are charged.

Write down the policy: either reserve or decrement stock when the order is placed, or accept occasional overselling and define the refund-and-notify path.

**5. Tests only cover the happy path.** One integration test won't catch any of the problems above. Add tests for:
- a timeout followed by a retry: exactly one charge
- a commit failure after a successful charge: the order is still recorded
- a duplicate `POST`: one order
- a payment decline: the order ends up `FAILED`

## Minor
- **Email:** if sending the email fails after the order is `PAID`, it shouldn't fail the request. Send it after the commit, ideally asynchronously.

VERDICT: READY WITH CHANGES
