Q: You have hundreds of AWS Lambda functions connecting to a traditional PostgreSQL database. Under heavy load, the database crashes with "Too many connections" before the Lambdas finish executing. How do you fix this?
Serverless functions (like AWS Lambda) scale highly concurrently. If 5,000 requests come in, 5,000 ephemeral Lambda containers spin up, a...
🛠️ Production Runbook & Step-by-Step Resolution
Production Solution & Architecture
Serverless functions (like AWS Lambda) scale highly concurrently. If 5,000 requests come in, 5,000 ephemeral Lambda containers spin up, and *each one* attempts to open a separate, direct TCP connection to the PostgreSQL database. Traditional databases are designed to handle a few hundred persistent connections, not thousands of short-lived ones, leading to connection exhaustion and failure. To fix this, you must introduce a Connection Pooler between the Lambdas and the Database. In AWS, the best managed solution is Amazon RDS Proxy. The Lambdas connect to the RDS Proxy, and the proxy multiplexes those thousands of requests over a small, stable pool of persistent connections to the database, protecting it from being overwhelmed.
- Immediate Triage: Serverless functions (like AWS Lambda) scale highly concurrently. If 5,000 requests come in, 5,
- Run targeted verification commands before modifying configuration.
- Automate permanent guardrails (CI check, alerts, IaC policy) to prevent recurrence.