The bulkhead pattern partitions a service's resources so overload in one dependency or tenant cannot consume capacity reserved for another. Each compartment has its own limit and fills independently.
Design a BulkheadAdmissionController class:
BulkheadAdmissionController() creates a stateless controller.boolean[] admit(int[] capacities, int[] requests) returns the admission decision for every request in chronological order.
capacities[p] is the number of slots in pool p. Each value in requests is the index of the pool targeted by that request.
For each request:
- Return
true and occupy one slot when the target pool still has capacity. - Return
false when the target pool is already full.
An admitted request remains active for the rest of that simulation; there are no releases. A rejected request consumes no slot. Pools never share or borrow capacity, even when another pool has unused slots. Each call to admit is a new simulation and must not retain occupancy from an earlier call.
Example 1:
Input:
Output:
Explanation: Pool 0 admits its first two requests and then rejects its third. Pool 1 has a separate budget, so it also admits its first two requests before rejecting its third.
Example 2:
Input:
Output:
Explanation: The first three requests fill pool 1. Pool 0 is unaffected and still admits one request before reaching its own capacity of 1.
Constraints
1 <= capacities.length <= 1000 <= capacities[p] <= 10^60 <= requests.length <= 10^50 <= requests[i] < capacities.length- Requests are processed in the given order.
- At most
100 calls are made to admit.