ASP.NET Core Interview Question #190

What is connection pooling and why does it matter?

Performance, Caching & HTTP Senior Advanced

Quick Interview Answer

Connection pooling reuses expensive connections instead of creating a new physical connection for every operation. Database providers commonly pool database connections, while HttpClient infrastructure pools outgoing network connections through handlers.

Detailed Explanation

Connection pooling reuses expensive connections instead of creating a new physical connection for every operation. Database providers commonly pool database connections, while HttpClient infrastructure pools outgoing network connections through handlers.

Code should generally open database connections late and dispose them promptly; disposing a pooled connection normally returns it to the pool rather than destroying the underlying physical connection.

Incorrect lifetime management can exhaust pools and cause latency or failures under load.

Code Example

await using var connection =
    new SqlConnection(connectionString);

await connection.OpenAsync(cancellationToken);

// Use the connection and dispose promptly.
// Pooling is managed by the provider.