Implement a Client Connection Pool With Idle Timeout and Health Checks

Last updated: November 29, 2026

Quick Overview

Write a connection pool for an RPC client talking to a backend: reuse idle connections, cap total connections per backend, evict connections idle too long or marked unhealthy, and make callers wait with a deadline when the pool is full.

Google
Software Engineering Fundamentals
Software Engineer
Google
November 29, 2026
Software Engineer
Onsite
Software Engineering Fundamentals
Medium

0

0

0 solved


Write a connection pool for an RPC client talking to a backend: reuse idle connections, cap total connections per backend, evict connections idle too long or marked unhealthy, and make callers wait with a deadline when the pool is full.

Every Google service calls dozens of backends, and connection setup with TLS can cost several round trips, so pooling and its failure modes are standard fundamentals. The interviewer checks concurrency correctness, eviction policy, and behavior under backend failures.

What the Interviewer Expects
  • Reuse idle connections in LIFO order to keep them warm
  • Cap open connections and block callers with a deadline
  • Discard connections that are idle past a timeout or fail a check
  • Return broken connections without putting them back
  • Use a condition variable rather than busy waiting
Key Topics to Cover
connection pooling
concurrency
condition variables
timeouts
resource limits
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
  • Why prefer LIFO over FIFO for idle connections?
  • How would you pre-warm connections at startup?
  • How does HTTP/2 multiplexing change pool sizing?
  • How do you avoid every client reconnecting at once after a backend restart?
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
  • Pool(factory, max_size, idle_timeout, clock).
  • acquire(timeout) returns a connection or raises PoolTimeout.
  • release(conn, broken=False).
  • Idle connections older than idle_timeout, or w...
High-Level Design

State: idle stack of (conn, last_used), open_count, and a condition variable. Acquire loops: pop idle connections from the top, closing any that are stale or unhealthy; return the first good one...


Submit Your Answer
Markdown supported