Stock Expiry Job Releases a Renewed Reservation Hold
Level 3 · node · Concurrency · Missing expiry generation validation
Scenario
An order system holds stock while payment is pending, and an expiry worker later processes the job created for that reservation generation. When payment is retried, the hold with the same reservation ID is renewed with a newer generation. If the old generation expiry job arrives late, it can release the renewed hold and make the stock available to another order.
Requirements
- Release stock only when the expiry job generation matches the current hold generation - Ignore delayed expiry jobs from older generations - On a valid expiry, decrease the reserved quantity exactly - Do not affect reservations for other SKUs - Remove an expired hold from the repository
Acceptance criteria
- An expiry for the current generation releases the hold
- An older generation expiry keeps the renewed hold
- Reserved quantity decreases after a valid expiry
- Inventory for another SKU is unchanged
- A validly expired hold can no longer be read