Question
Database connection timeout with Django CONN_MAX_AGE
Neel Maple
0 reputation · 10 Feb 2026, 23:51 UTC
117.9K views0
Goal
Determine the optimal CONN_MAX_AGE setting that minimizes latency spikes when Django serves a high volume of concurrent requests.
Constraints & Uncertainty
- Persistent connections reuse a shared pool; the pool size is bounded by the database server’s maximum connections and the web server’s worker count.
- When the pool is saturated, new requests block waiting for a free connection, producing noticeable latency spikes.
- Django’s documentation recommends a positive
CONN_MAX_AGEfor production but offers no specific value, leaving the choice to the deployment environment. - It is unclear whether a fixed age (e.g., 60 s) or a dynamic strategy (e.g., external pooler) yields lower latency under varying concurrency levels.
Unresolved Questions
- What
CONN_MAX_AGEvalue produces the lowest maximum latency when handling 500 concurrent requests on PostgreSQL? - Is a fixed
CONN_MAX_AGEsuperior to a dynamic connection‑pooling approach for mitigating latency spikes? - How does Django’s default connection‑close behavior compare to persistent connections in terms of latency under high concurrency?