Latency grows with traffic and logs show "QueuePool limit of size 5 overflow 10 reached, connection timed out, timeout 30.00".

IntermediateTroubleshootingLatency
Answer

Likely causes → The app's DB connection pool is too small for its concurrency, connections leak (not returned), or slow queries hold connections longer than expected.

Diagnose →

SELECT state, count(*) FROM pg_stat_activity WHERE datname='app' GROUP BY state;
-- many "idle in transaction" = leaked or long transactions

Fix → Fix leaks and long transactions first. Then size the pool (pool_size, max_overflow) so replicas × pool stays below the DB's max_connections, or add PgBouncer/RDS Proxy.

Prevent → Export pool metrics (in-use, waiters, wait time), and set idle_in_transaction_session_timeout on the DB.

All Real-World Interview questions Roadmap: Interview readiness

More on Latency