Concept
The Cost of Database Connections
Establishing a TCP connection to a database (especially with TLS handshakes) is slow and memory-intensive. PostgreSQL allocates a separate OS process for every concurrent client connection, consuming ~10MB of server RAM per connection.
To optimize performance, traditional servers use a Connection Pool. The server establishes a fixed number of connections (e.g. 10) on startup and shares them among incoming requests, avoiding connection setup overhead:
Client Request ──▶ Acquire connection from Pool ──▶ Query ──▶ Release back to PoolThe Serverless Connection Exhaustion Problem
In serverless architectures (like AWS Lambda, Vercel Functions), functions spin up in isolated micro-VM containers dynamically based on traffic demand:
┌──────────────────────┐
│ Incoming Traffic │
└──────────┬───────────┘
┌────────────────┼────────────────┐
▼ ▼ ▼
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Lambda VM 1 │ │ Lambda VM 2 │ │ Lambda VM 3 │
│ (1 Connect) │ │ (1 Connect) │ │ (1 Connect) │
└──────┬──────┘ └──────┬──────┘ └──────┬──────┘
│ │ │
└────────────────┼────────────────┘
▼
┌─────────────────┐
│ PostgreSQL DB │
│ (Max: 100 Conn) │
└─────────────────┘