Cap Concurrent Backend Calls With a Semaphore-Guarded Pool
Last updated: November 29, 2026
Quick Overview
A service fans out requests to a fragile backend that can handle only N simultaneous calls. Wrap calls so that at most N run at once, callers wait with a timeout when the cap is reached, and slots are always returned even when a call fails.
0
0
0 solved
A service fans out requests to a fragile backend that can handle only N simultaneous calls. Wrap calls so that at most N run at once, callers wait with a timeout when the cap is reached, and slots are always returned even when a call fails.
Google services protect shared backends (Bigtable tablets, legacy storage, third-party APIs) with client-side concurrency limits. This phone screen question checks basic semaphore use, timeouts instead of indefinite blocking, and exception-safe release.
What the Interviewer Expects
- Chooses a counting semaphore rather than a mutex
- Releases the slot in a finally block or context manager
- Uses an acquire timeout to fail fast when saturated
- Explains why BoundedSemaphore catches double-release bugs
- Mentions how to observe saturation through a metric
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- How would you make the limit adapt to backend latency, like TCP congestion control?
- How does this interact with retries from many clients?
- How would you give interactive traffic priority over batch traffic?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
- At most
max_inflightcalls run at once. - Callers beyond the limit block, or raise
TimeoutErroraftertimeout. - A slot is released whether the call succeeds or raises.
- Expose in-flight and ...
High-Level Design
A BoundedSemaphore(N) holds N permits. Acquire before calling, release in finally. Wrapping it in a context manager makes it impossible for callers to forget the release. Peak tracking is a separa...