The design is sound in shape and you can start building tomorrow, but four things in it will charge customers twice, oversell stock, or miscalculate totals as written. Each has a small fix that does not change the architecture.

## Must fix before building

**1. Payment retries can charge the customer twice (step 3).**
The key sent to the provider is `<order id>-<attempt number>`, so each retry looks like a new charge to the provider.
- **Case:** attempt 1 succeeds at the provider but the response takes 6 s, so the service times out and sends attempt 2 with key `…-2`.
- **Result:** the provider charges the card again.
- **Expected:** the provider recognises the retry and returns the first charge.
- **Fix:** send the order id alone as the key on every attempt, and log the attempt number on your side for tracing.

**2. A duplicate `POST /orders` creates a second order when it lands on the other instance (step 1).**
Each instance keeps its own in-memory map of seen keys, and there are two instances.
- **Case:** the client times out and retries with the same `Idempotency-Key`; the first request went to instance A and the load balancer sends the retry to instance B.
- **Result:** B has never seen the key, so it creates a second order and a second charge. A restart loses the map in the same way.
- **Expected:** B returns the existing order.
- **Fix:** store the key in an `idempotency_key` column on `orders` with a unique constraint, and return the existing row on conflict.

**3. Two buyers can both get the last unit (step 2).**
The service reads `available`, then writes `available - quantity`; at Postgres's default isolation level, a transaction does not stop two requests reading the same value.
- **Case:** `available = 1`, and two requests for that SKU arrive together.
- **Result:** both read 1, both write 0, and both orders succeed.
- **Expected:** one order succeeds and the other gets `409`.
- **Fix:** use `UPDATE stock SET available = available - $q WHERE sku = $sku AND available >= $q` and treat zero rows updated as short stock.

**4. Money is stored as `double precision`.**
- **Case:** three items at 0.10 sum to 0.30000000000000004, not 0.30.
- **Result:** totals can drift from what the provider charged.
- **Fix:** use integer minor units (cents) or `numeric` for `total` and `unit_price`.

## Worth adding, not blocking

- **Guard status changes:** the request handler and the reconciliation job can both settle the same order. Make each transition `UPDATE … WHERE status = 'PENDING'` and only restore stock if a row changed; otherwise stock can be restored twice.
- **Tests:** the current list would not catch items 1–3. Add:
  - two concurrent buyers for the last unit;
  - a duplicate `POST` sent to a different instance;
  - a timeout where the first charge actually succeeded, asserting exactly one charge.

## What is already right

- The payment call sits outside the database transaction.
- An unknown result leaves the order `PENDING`, returns `202`, and is settled by the reconciliation job, with an alert at 30 minutes.
- A failed confirmation email never fails the order.
- The module boundaries and thin routes fit a team of four at this scale.

VERDICT: READY WITH CHANGES
