← Back
00:00

Thread-Safe Connection Pool

MongoDB interview questions · Hard · Coding round · 7 tests

Design the core logic for a thread-safe connection pool. The pool owns a fixed number of reusable database connections. Callers can acquire an available connection, release it back to the pool when finished, and observe how many connections are currently available.

For this interview version, model each connection as an integer ID from 0 through maxConnections - 1. You do not need to implement real database handles or OS-level locking; instead, implement the pool's capacity and reuse semantics exactly.

Interface

Idle