**Not as written, but you can start tomorrow if you make four changes to the document first.** The overall shape is right for 2,000 orders a day and a team of four: reserve stock, charge outside the transaction, settle unknowns with a reconciliation job. However, as written it can charge a customer twice, create duplicate orders and oversell stock.

## 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.
   - Case: attempt 1 times out at 5 s but the provider did charge the card. Attempt 2 goes out with key `…-2` and the provider charges again.
   - Expected: one charge.
   - Fix: send the order id alone as the key on every attempt, and put the attempt number in metadata or logs for tracing.

2. **Duplicate `POST /orders` is only caught on the same instance (step 1).** Each of the two instances keeps its own in-memory map of keys, and the map is lost on restart.
   - Case: the client times out and retries, and the load balancer sends the retry to the other instance. The result is a second order, a second stock deduction and a second charge.
   - Expected: the original order is returned.
   - Fix: store the key on `orders` with a unique constraint on `(customer_id, idempotency_key)`, inserted in the step 2 transaction. On conflict, return the existing order.

3. **Two buyers can both get the last unit (step 2).** The transaction reads `available`, then writes `available - quantity`. Under Postgres's default isolation, two concurrent transactions can both read the same value.
   - Case: `available = 1`, and two orders for 1 unit arrive together. 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. Add `CHECK (available >= 0)`, and update SKUs in sorted order to avoid deadlocks.

4. **Settling an order is not guarded, so stock can be restored twice (steps 5 and 6).** The request handler and the reconciliation job can both settle the same order, and the job itself runs on both instances.
   - Case: both instances' jobs see the same declined `PENDING` order. Both mark it `FAILED` and both restore stock, so `available` ends up one order's quantity too high.
   - Expected: stock is restored once.
   - Fix: make every transition `UPDATE orders SET status = … WHERE id = … AND status = 'PENDING'`, and only restore stock or queue the email if that updated one row.
   - Also specify what the job does when the provider has no record of the charge, for example after a crash between steps 2 and 3. I'd mark it `FAILED` and restore stock, which is safe once fix 1 is in.

## Should fix, cheap now and painful later

- **Money is stored as `double precision`.** Totals will drift by fractions of a cent (0.1 + 0.2 ≠ 0.3). Use integer minor units or `numeric`.
- **The data model has no keys or constraints.** State the primary keys (`orders.id`, `stock.sku`, `order_items (order_id, sku)`), the foreign key, and a `CHECK` on `status`.
- **The confirmation email can be lost (step 4).** A crash after the `PAID` commit and before the email is queued means it is never sent. Write an "email pending" row in the same transaction as `PAID`, or have the reconciliation job pick up paid orders with no email.
- **The request can hang for 20 seconds or more.** Four attempts at 5 s plus backoff will exceed most client timeouts, which triggers the retries in point 2. Cap the total time (about 10 s) and return `202` sooner.
- **The same idempotency key with a different cart is undefined.** Return `422`.
- **The module rule conflicts with the flow.** "No module reads another module's tables" clashes with steps 2 and 5, which change `stock` and `orders` in one transaction. Say explicitly that `OrderCheckout` owns the transaction and calls the inventory module inside it.

## Test plan gaps

The listed tests would all pass with the four bugs above present, because they are sequential and single-instance. Add:

- Two concurrent purchases of the last unit.
- A duplicate `POST` against a second instance, and two concurrent duplicates.
- A timeout where the fake provider did charge, asserting exactly one charge.
- A crash between the order commit and the charge.
- Reconciliation running twice or racing the request handler, asserting stock is restored once.

VERDICT: READY WITH CHANGES
