QA
Senior LevelREST APIs & Web Services

How do you configure resilience parameters for database connection pools in high-throughput APIs?

❓ Interview Prompt: Explain database connection pooling parameters (`max`, `idleTimeoutMillis`, `connectionTimeoutMillis`), pool exhaustion, and PgBouncer connection queuing.

Un-tuned database connection pools under heavy API traffic spikes cause thread starvation, query timeouts, and API crashes:

Key Pool Tuning Parameters:

•
'max': Max active DB connections (typically 20-50 per Node.js process; setting to 500 crashes PostgreSQL!).
•
'connectionTimeoutMillis': Max time an API request waits for an available pool connection before throwing a '503' error (set to ~2000ms).
•
PgBouncer: Use external connection poolers (PgBouncer) in transaction pooling mode to support 10,000 concurrent API requests over 100 physical DB connections!

Code Implementation Example

typescript
import { Pool } from 'pg';

// Tuned PostgreSQL Connection Pool for High-Throughput API
export const dbPool = new Pool({
  max: 20, // Keep max connections low to prevent DB CPU thrashing
  idleTimeoutMillis: 30000,
  connectionTimeoutMillis: 2000, // Fail fast after 2s if pool exhausted
});
💡Tuned PostgreSQL connection pool configuration in TypeScript.
🎯 Interview Key Takeaway

Keep database connection pool sizes low and fail fast with short connection timeouts to prevent database CPU thrashing under API load spikes.

#Connection Pooling#PostgreSQL#PgBouncer#Senior
Back to all REST APIs & Web Services Questions→

More REST APIs & Web Services Interview Questions

Beginner LevelREST APIs & Web Services

What is HTTP Method Idempotency and how do you implement Idempotency Keys for REST APIs?

Beginner LevelREST APIs & Web Services

What are standard HTTP Status Codes (200, 201, 204, 400, 401, 403, 404, 409, 429, 500, 503)?

Beginner LevelREST APIs & Web Services

What are HTTP Verbs (GET, POST, PUT, PATCH, DELETE) and when to use PUT vs PATCH?