Database

Plan Database Connection Pooling and Saturation Monitoring

Prevent connection exhaustion by measuring demand, limits, wait time, and connection lifetime.

Database connection limits are shared capacity constraints. A web application can exhaust them by increasing worker concurrency or holding connections while waiting on unrelated services.

Understand total demand

Estimate potential connections across PHP-FPM pools, queue workers, scheduled jobs, admin tools, and replicas. Leave headroom for maintenance and failover. Do not size the database based only on one application process.

Monitor saturation

Track active connections, connection creation failures, wait time, idle connections, transaction duration, and database CPU. A high connection count may indicate long transactions or slow queries rather than insufficient capacity.

Use pooling carefully

Persistent connections or external poolers can reduce connection setup overhead, but they introduce lifecycle and state concerns. Ensure transactions, session variables, and temporary state are reset before a connection is reused.

Control concurrency

Bound worker counts and queue concurrency to database capacity. Backpressure is often safer than allowing every layer to create more simultaneous work.

Checklist

  • Calculate connection demand across all workers.
  • Monitor active, idle, and waiting connections.
  • Keep transactions short.
  • Reset session state before reuse.
  • Align application concurrency with database capacity.
Share this page Help other developers discover this resource.