.NET Architecture & System Design Interview Question #83

What is connection pooling?

Transactions, CQRS, Event Sourcing & Distributed Consistency Mid-Level Intermediate

Quick Interview Answer

Connection pooling reuses already-created database connections instead of creating a new physical connection for every operation. Opening a logical connection usually borrows a connection from the pool and closing it returns the connection for reuse.

Detailed Explanation

Connection pooling reuses already-created database connections instead of creating a new physical connection for every operation. Opening a logical connection usually borrows a connection from the pool and closing it returns the connection for reuse.

Pooling reduces connection setup cost, but pool size is finite. Slow queries, leaked connections, or excessive concurrency can exhaust the pool and cause requests to wait or fail.

Code Example

Request -> Open connection
          -> borrow from pool
          -> execute
          -> Close/Dispose
          -> return to pool