Back to Learning Hub
Databases and scalingestimate capacity Last tested 2026-11-27

How many PostgreSQL connections does my API need?

Worked Answer

Multiply requests per second by connection hold time in seconds (Little's Law). At 200 requests/s and 50 ms (0.05 s) holding one connection, average demand is 200 × 0.05 = 10 active connections—but a 4× burst pushes demand to 40 connections, which is why you size pools for peak bursts and use a transaction pooler.

Estimate average active PostgreSQL connections from request rate and connection hold time, then test how a traffic burst changes your pool and max_connections requirements.

How many PostgreSQL connections does my API need? architecture flow diagram

Packages

pgpgbouncer
Interactive Capacity Calculator

Interactive PostgreSQL Concurrency Calculator

Every request holds one database connection for the stated duration.

Average Active

10

200 × 0.050s

Burst Peak (4×)

40

40% of max_connections

Pool Recommendation

Fits within max_connections, but keep a pooler for slow-query spikes.

Baseline worked example: 200 × 0.05 seconds = 10 active connections on average. During a 4× traffic spike, concurrent demand jumps to 40 connections.

Why the average alone cannot size your pool

Average demand assumes uniform arrival. Real API traffic arrives in bursts (webhooks, cron jobs, AI agent fan-outs) and slow queries double hold time. If 200 req/s spikes 4× while a lock doubles hold time from 50 ms to 100 ms, demand hits 80 connections—quickly saturating a default PostgreSQL instance unless you place PgBouncer or Hyperdrive in front.

Checkpoint

Traffic stays constant at 200 req/s, but each request holds its connection twice as long (100 ms instead of 50 ms). What happens to average connection demand?

Production Evidence & Architecture Guides

Official Sources

Next Lesson
How do I build a LangGraph agent that resumes after a crash?

Want this architecture built for your team?

Fixed-scope engineering sprints for databases, AI agents, and production retrieval.

Mugesh Rao
AI Engineer & Full Stack Engineer