Problem statement
Design the object model and public APIs for a generic connection pool: the in-process component that hands out reusable, expensive-to-create connections (think database sessions or sockets to a remote service) to many caller threads and takes them back when done.
Operating context. One process, many worker threads sharing a single pool over a fixed backing resource. Creating a connection is slow (tens of milliseconds) and the resource caps total connections, so the pool keeps a warm set between a minimum and a maximum size. A caller acquires a connection, uses it, and releases it back; if none is free and the pool is at max, the caller waits up to a bounded timeout, then fails rather than blocking forever. Idle connections beyond the minimum are retired, and connections are health-checked so a dead one is never handed out. The pool must stay correct under concurrent acquire and release.
Out of scope. The wire protocol of the underlying connection, the SQL/RPC executed over it, distributed or cross-process pooling, connection multiplexing over one socket, TLS handshake details, and any deployment or configuration-file format (design the in-process object model, not the ops surface).
What to produce. The class hierarchy (the pool, the pooled-connection wrapper, the factory that creates/validates/destroys raw connections, and the config/policy seams), the public API each class exposes, and the state transitions of a pooled connection (idle, in-use, validating, evicted). Be explicit about: how acquire blocks with a deadline and how waiters are woken fairly, how min/max sizing and idle eviction are enforced, how a broken connection is detected and replaced without handing it to a caller, how a connection leaked by a caller who never released it is detected, and how every operation stays thread-safe.
Requirements
This assessment is a Premium feature.
The statement above is free to read. The functional and non-functional requirements, and the graded canvas that scores your design against them, come with Premium.
Topics
- System Design LLD
- Concurrency Locks
- Statemachine
- Patterns Factory
- Testability Clock