PostgreSQL Connection Pooling at Scale
PgBouncer sizing, Prisma pool tuning, and avoiding connection storms under traffic spikes.
Nestlancer Editorial

Postgres connections are expensive. A traffic spike that opens one connection per request can take down the database faster than application CPU saturates.
PgBouncer sizing
| Mode | Use case |
|---|---|
| Transaction pooling | Stateless APIs (NestJS default) |
| Session pooling | Prepared statements, LISTEN/NOTIFY |
| Statement pooling | Rare; breaks many ORMs |
Start with max_client_conn at 10× expected app instances, default_pool_size tuned to CPU cores on the DB.
Prisma pool tuning
DATABASE_URL="postgresql://...?connection_limit=10&pool_timeout=20"
connection_limit per instance × replica count must stay below PgBouncer and Postgres max_connections. Leave headroom for migrations and admin consoles.
Detecting connection storms
Alert on:
pg_stat_activitycount > 80% ofmax_connections- Rising
pool_timeouterrors in application logs - Sudden spike in idle-in-transaction sessions
Traffic spike playbook
- Scale app horizontally with fixed per-pod pool limits—not unlimited pools
- Queue write-heavy batch jobs separately from interactive API pools
- Use read replicas for analytics queries
Connection pooling is not optional infrastructure—it is part of your availability model.
Comments
Loading comments…
Related posts

Case Studies
Cutting Deploy Time from 45 Minutes to Five
CI caching, smaller artifacts, and service-level pipelines after monolith split.

Case Studies
Scaling a Freelance Marketplace Architecture
Matching algorithms, escrow flows, and dispute resolution at growing GMV.

Case Studies
GDPR Compliance Platform Rebuild
Data maps, deletion workflows, and consent logging across microservices.

Case Studies
Migrating from WebSockets to SSE
Simpler infra, CDN friendliness, and trade-offs for one-way realtime feeds.