Yes, you can start tomorrow, but first make four changes to the design. They're small and sit in a few specific lines. Your overall structure is good: a short stock transaction, the payment call made outside any transaction, a reconciliation job for charges with unknown results, an alert on stuck orders, and clear module boundaries. That's the right design for this service. The four changes matter because without them customers can be charged twice or sold stock you don't have.

## Must fix before building

**1. Retries can charge a customer twice (step 3).** The key changes on every attempt (`<order id>-1`, `<order id>-2`, …), so the payment provider sees each retry as a new charge.
- Case: attempt 1 times out after 5 s, but the provider actually charged the card. Attempt 2 is sent with a new key, so the provider charges again. The customer pays twice when they should pay once.
- Fix: use the order id alone as the provider's idempotency key. Every attempt can still be traced by order id in your structured logs. This also gives the reconciliation job one key to look up. With the current scheme, it's unclear which attempt's key the job would query.

```mermaid
sequenceDiagram
    participant S as order-service
    participant P as Payment provider
    S->>P: charge (key order-1)
    P-->>S: charge succeeds, but reply arrives after 5 s timeout
    S->>P: retry (key order-2)
    P-->>S: charged again, customer pays twice
    Note over S,P: Using the same key (order id) on every attempt makes the provider return the first result instead
```

**2. Duplicate requests aren't caught across your two instances (step 1).** Each instance keeps seen keys in its own memory, and those keys are also lost on restart or deploy.
- Case: the client times out and resends `POST /orders` with the same key. The load balancer sends it to the other instance, which has never seen the key. You get two orders, stock taken twice and two charges. Expected: one order.
- Fix: add an `idempotency_key` column to `orders` with a unique constraint. Insert it in the step 2 transaction, and on a conflict return the existing order.

**3. Two buyers can both get the last unit (step 2).** "Read `available`, then write `available - quantity`" lets concurrent transactions overwrite each other. Postgres's default isolation level (READ COMMITTED) doesn't stop this.
- Case: `available = 1`, and two checkouts run at the same time. Both read 1, both write 0, and both orders succeed. You've sold 2 units of 1 in stock. Expected: one succeeds, one gets `409`.
- Fix: `UPDATE stock SET available = available - $qty WHERE sku = $sku AND available >= $qty`, then treat 0 rows updated as "short" and return `409`. Alternatively, read with `SELECT … FOR UPDATE`.

**4. Money is stored as `double precision`.** Floating-point numbers can't hold most decimal amounts exactly.
- Case: in floating point, items priced 0.10 and 0.20 add up to `0.30000000000000004`, so totals drift from what the provider charged. Expected: exactly 0.30.
- Fix: change `total` and `unit_price` to `numeric(12,2)`, or to integer minor units such as cents.

## Small clarifications (can be settled while building)

- **Make every status change conditional.** Write it as `UPDATE orders SET status = 'FAILED' … WHERE id = $1 AND status = 'PENDING'`, and only restore stock if a row changed. Without the condition, the reconciliation job running on both instances, or racing a late reply from the provider, could restore stock twice. Also state that settling an order as `FAILED` in step 6 restores its stock, just as step 5 does.
- **Your module rule and step 2 disagree.** Step 2 writes `stock` and `orders` in one transaction, but the design also says no module reads another module's tables. Write down which way you're going. Allowing the checkout transaction to span both tables is a reasonable exception at this scale.
- **Possible lost emails (step 4).** If the service crashes after committing `PAID` but before queuing the email, that email is never sent. That's acceptable for now if you note it. The usual fix is an outbox table written in the same transaction.

## Tests to add
- Two simultaneous checkouts for the last unit: exactly one succeeds.
- A duplicate `POST /orders` sent to *different* instances: one order.
- The provider charges but the reply times out, then a retry: exactly one charge.
- The reconciliation job settles a `PENDING` order while a late reply arrives at the same time: stock is restored at most once.

Load isn't a concern: 2,000 orders a day is light for two instances and one Postgres database.

VERDICT: READY WITH CHANGES
