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.

Google
Software Engineering Fundamentals
Software Engineer
Google
November 29, 2026
Software Engineer
Phone Screen
Software Engineering Fundamentals
Easy

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
semaphore
concurrency limit
timeouts
exception safety
load shedding
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. 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 Problems
Sample Answer
Requirements
  • At most max_inflight calls run at once.
  • Callers beyond the limit block, or raise TimeoutError after timeout.
  • 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...


Submit Your Answer
Markdown supported