Size each application pool for the maximum number of pools that can exist at the same time, not for today’s replica count. Pick the number of database connections your service may use, divide it by the peak pool count (autoscaler ceiling, rollout surge, worker processes, separate data sources), round down, then load test. This article gives the formula, a worked example, and the pooler and proxy details that change the math.
The formula
A sound starting point:
max_pool_per_process = floor(service_connection_allowance / (ceil(max_replicas × (1 + max_surge_fraction)) × pools_per_pod))
As an Amazon Associate I earn from qualifying purchases.
This allocates a budget. It does not find a performance optimum. Query duration, transaction length, database CPU and I/O, lock contention and burst shape all still decide whether the resulting pool is fast enough.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minuteWorked example
A focused autoscaling guide uses these inputs: an allowance of 180 connections, 16 maximum replicas, 25% rollout surge, and two pools per pod.
#1 Best Overall
- Peak pods:
ceil(16 × 1.25) = 20 - Peak pools:
20 × 2 = 40 - Per-pool maximum:
floor(180 ÷ 40) = 4
That is the guide’s illustration, not a benchmark or a universal setting.
A second, purely illustrative calculation with a multi-worker web server: allowance 200, 10 maximum replicas, 25% surge, 4 worker processes per pod, each with its own pool. Peak pods are ceil(12.5) = 13, peak pools are 52, and floor(200 ÷ 52) = 3. Each worker gets 3 connections, so the real lever is often worker count, not pod count.
The inputs, one by one
| Input | What to use | Common mistake |
|---|---|---|
| Connection allowance | This service’s share of usable backend connections, after reserving capacity for admin access, migrations, monitoring, other applications, readers/replicas, failover and a safety margin | Using the database’s advertised maximum |
| Maximum replicas | The autoscaler’s configured ceiling | Using the current replica count |
| Rollout surge | Replicas temporarily allowed above the desired count during a rolling update (16 at 25% surge can mean 20 pods) | Ignoring deploys that happen while traffic is at peak |
| Pools per pod | Every process and every independent pool: workers per pod, plus separate read and write data sources | Assuming one pool per pod |
Connection allowance
Start from the database’s real usable connection budget and subtract everyone who is not this service. If you front the database with a proxy, the proxy’s permitted backend connections become the backend budget, and application-to-proxy pools are sized separately (see below).
Rank #2
Check how your pool library behaves
Verify whether the pool creates connections lazily or eagerly, what its minimum idle setting is, how long connections live, and how its acquisition queue behaves. A pool with a nonzero minimum claims its share the moment a pod starts, which is exactly the surge moment. Lazy pools may hide an overcommitment until traffic arrives.
What happens when the answer is too small
If the per-pool result is 1 or 2, requests will queue for connections. A smaller pool protects the database but moves pressure into wait time and timeouts. Options, in rough order of preference:
- Cut pools per pod (fewer workers, or share one pool across read paths where sensible).
- Lower the autoscaler ceiling or surge fraction if the database, not the app, is the bottleneck.
- Put a pooler or proxy between the app and database so many client connections share fewer backend connections.
- Increase database capacity. Do not simply raise the database’s connection limit to hide a pool multiplication problem; more backend connections add memory and contention cost without adding throughput.
Poolers and proxies change the budget
With a pooler there are two separate budgets: client connections into the pooler, and server connections to the database. Size them independently.
PgBouncer
PgBouncer’s documentation describes three pool modes. In session mode the server connection is released when the client disconnects. In transaction mode it is released after the transaction; the documentation puts it as “transaction — Server is released back to pool after transaction finishes.” In statement mode it is released after each query, and multi-statement transactions are disallowed.
default_pool_size is the maximum number of server connections per user/database pair, and per-database or per-user settings can override it. The client ceiling, max_client_conn, is a distinct setting. Raising it can require higher OS file-descriptor limits, and the documentation gives theoretical maximum file-descriptor calculations based on client count and pool count. When several user/database pairs exist, multiply accordingly when checking the total against the database limit.
Amazon RDS Proxy
AWS’s documentation distinguishes client connections to the proxy from backend connections to the database. The backend cap is MaxConnectionsPercent, a percentage of the target’s max_connections; the proxy does not pre-create the full allowance. AWS recommends setting it at least 30% above the maximum recently monitored usage, and notes that redistribution of proxy capacity may need more headroom. Watch DatabaseConnections, MaxDatabaseConnectionsAllowed and DatabaseConnectionsBorrowLatency. When the proxy reaches its backend maximum, AWS documents higher query latency and increased borrow latency as the side effect.
Rank #4
You can still pool in the application in front of the proxy to avoid repeatedly establishing client-to-proxy connections. Those client connections aren’t bound by the same numeric ceiling as backend connections, so match pool lifetimes and idle timeouts to the proxy’s enforced client limits.
Pinning
Session state such as SET commands or temporary objects can pin a client connection to a backend connection, reducing multiplexing. An idle pinned client keeps its backend connection unavailable for reuse, so client counts alone don’t show backend use. Inspect proxy logs and metrics for pinning.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallFor scale: an AWS Prescriptive Guidance test application reached 20,000 client connections while the database instance was capped at 187 concurrent connections (the opened document shows no year). Treat it as one AWS test, not a capacity promise or an expected ratio.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Validate with a scale test
- Configure the autoscaler at its real maximum and the deployment at its largest permitted surge.
- Graph replica and process counts beside total database backend connections.
- Trigger a scale-out and a rolling deploy; note the moment new pods start and whether pools connect eagerly or lazily.
- Track pool in-use, idle and waiting counts, acquisition latency and timeouts, and query latency. On RDS Proxy add borrow latency and pinning metrics.
- Confirm backend connections stay under the allowance with margin, and that acquisition waits stay within request timeouts.
Recalculate whenever the replica ceiling, surge policy, worker count, data sources, database limits or other workloads’ shares change. The cited official sources document connection caps and proxy behavior; none establishes a universal best pool size, so the final value depends on your own capacity and measurements.
Quick Recap
Checklist
- Divide the service’s safe allowance by the peak number of independent pools.
- Use the autoscaler maximum and include surge.
- Multiply by workers and data sources per pod.
- Treat pooler client connections and backend connections as separate budgets.
- Monitor wait and borrow latency, since small pools shift pressure into queues.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




