Should we use database connection pooling instead of opening a new connection for every request? #211034
🏷️ Discussion TypeQuestion BodyI've noticed that creating a new database connection for every incoming API request can add unnecessary latency and increase the load on the database, especially when traffic spikes. Should we introduce database connection pooling to reuse existing connections? Guidelines
|
Replies: 1 comment
|
I'd recommend connection pooling for most production applications, but I'd size it based on workload and database capacity rather than choosing an arbitrary number.
|
I'd recommend connection pooling for most production applications, but I'd size it based on workload and database capacity rather than choosing an arbitrary number.
Calculate the connection budget. Account for every application instance, background worker, migration process, and administrative connection.
Set sensible limits. Start with a conservative maximum pool size and increase it only when metrics show connection contention.
Configure timeouts. Set connection acquisition and query timeouts so requests fail predictably instead of consuming resources indefinitely.
Monitor pool behavior. Track active and idle connections, pending acquisition requests, wait duration, and timeout …