**Short answer:** The structure is solid and nearly ready to build. Three flaws would cause real money or inventory bugs, but each is a small edit to the design, so you can fix them tonight and still start tomorrow.

**What's strong**
- The flow is well thought out. It keeps the payment call outside the database transaction, handles the "payment result unknown" case with `202` plus a reconciliation job, and never lets an email failure fail an order.
- Module boundaries are clear, routes are thin, and there's a `PENDING` alert.
- The test list covers the right scenarios, including timeout-then-success.

**Fix before building**

1. **Duplicate-request protection doesn't work with two instances (step 1).**
   - Each instance keeps its own in-memory map of keys.
   - Case: the client sends `POST /orders` with key `K`, the request times out, and it retries. The load balancer routes the retry to the other instance, which has never seen `K`. The result is two orders, stock decremented twice, and two charges.
   - A restart also wipes the map.
   - Fix: store the key in Postgres with a unique constraint, for example an `idempotency_key` column on `orders`. A repeat then returns the existing order.

2. **The payment retries can double-charge (step 3).**
   - The key sent to the provider is `<order id>-<attempt number>`, so every retry has a different key.
   - Case: attempt 1 times out after the provider actually charged the card. Attempt 2 sends key `…-2`, so the provider treats it as a new charge and the customer is charged twice.
   - Fix: send the same key on every attempt, such as the plain order id. Keep the attempt number in your logs for tracing.

3. **Two buyers can both get the last unit (step 2).**
   - The service reads `available` and then writes `available - quantity`.
   - Case: stock is 1 and two requests read 1 at the same time. Both pass the check, both write 0, and two orders exist for one unit.
   - Fix: use a single conditional update, `UPDATE stock SET available = available - :q WHERE sku = :sku AND available >= :q`, and treat zero rows updated as "short". Alternatively, use `SELECT … FOR UPDATE`.
   - Your "last unit of stock" test only catches this if it fires two requests concurrently, so make it do that.

**Worth doing in the same pass (small)**
- **Money type:** `total` and `unit_price` are `double precision`, which gives rounding errors such as 0.1 + 0.2. Use `numeric(12,2)` or integer minor units.
- **Keys and constraints:** none of the tables declares a primary key. Add them for `orders`, `stock(sku)` and `order_items(order_id, sku)`.
- **Reconciliation:** two instances will both run the 5-minute job and could settle the same order twice. Use a Postgres advisory lock or `FOR UPDATE SKIP LOCKED`. Also state that settling as `FAILED` restores stock, and that the restore happens once only.
- **Lost email on crash:** if the service crashes between commit and queueing in step 4, the email is never sent. Writing the email job in the same transaction (an outbox table) closes that gap. This is acceptable to defer if you note it as known debt.

**Suggested tests to add:** concurrent duplicate `POST` with the same key hitting both instances, a retry that reuses the same provider key, and two simultaneous buyers of the last unit.

VERDICT: READY WITH CHANGES
