Concurrent Entry Permits Exceed a Zone's Capacity
Level 2 · node · Concurrency · Non-atomic capacity check and decrement across an asynchronous permit step
Scenario
A fictional laboratory access system tracks remaining occupancy capacity for each zone. Before issuing an entry permit, it checks capacity, waits for an asynchronous approval step, and then decrements capacity. When two workers request the last available spot simultaneously, both can be approved and the remaining count becomes negative. Inspect the atomicity boundary across repository, asynchronous service, and controller.
Requirements
Prevent issuance of more permits than a zone's remaining capacity. Keep the asynchronous approval step, but allow only one successful request for the final spot even when requests overlap. Rejected requests must not decrement capacity. Preserve independent zones and read-only lookups without external dependencies.
Acceptance criteria
- Issuing one permit decrements the capacity of its zone by one.
- Capacity is tracked independently for each zone.
- A zone with no remaining capacity rejects further permits.
- Concurrent requests for one zone cannot approve more permits than remaining capacity.
- A rejected concurrent request must not make capacity negative.
- Reading remaining capacity does not mutate stored values.