
How 500 Lambda Functions Took Down Our Database in 4 Seconds
One cron trigger, one queue backlog, and our RDS instance was dead in under 5 seconds. Here's the hidden conflict between Lambda's scale-out model and relational databases — and the fix that took one afternoon.
How 500 Lambda Functions Took Down Our Database in 4 Seconds
The 2:14 AM page
At 2:14 AM, our on-call alert fired:RDS CPU 100%, application error rate 78%, "Too many connections."
What had we deployed that evening? Almost nothing. A small change to an image-processing Lambda function. Harmless.
By 2:15 AM, the production database was unreachable. And the scariest part?No one had touched the database at all.
[INSERT SCREENSHOT 1: CloudWatch alarm graph — RDS CPU and DatabaseConnections spiking together. The two lines moving in lockstep tells the whole story.]
What actually happened
Here's the trap that catches almost every team moving to serverless:
Lambda scales by the thousands. RDS does not.
Our image queue had a backlog of ~10,000 jobs. Each Lambda invocation:
- Openedits own connectionto the database
- Held it for the whole invocation
- Concurrency spun up to500 parallel executionsto clear the backlog
Our**
db.t3.medium caps out at roughly~450 connections**.500 Lambdas × 1 connection each.You don't need to be a DBA to see where this goes.
| Lambda's assumption | RDS's reality |
|---|---|---|
Scaling | 1,000+ concurrent in seconds | ~450 max connections |
Connection cost | Trivial | Memory + process per connection |
Idle behavior | Dies after invocation | Connection lingers in pool |
The queue backlog was the accelerant. Lambda saw 10,000 messages and did exactly what it's designed to do:**scale out as fast as possible.**It was working perfectly. The database just couldn't survive its success.
[INSERT SCREENSHOT 2: Lambda metrics — Invocations and ConcurrentExecutions nearly vertical at 2:14 AM]
The fix: stop every connection from being a new handshake
We didn't want to rewrite the app around a NoSQL database over one incident. We wanted the simplest change that made the architecture survivable.
1. RDS Proxy — the connection shock absorber
RDS Proxy sits between Lambda and the database, multiplexing hundreds of client connections onto a small pool of real DB connections.
bash
aws rds create-db-proxy \
--db-proxy-name prod-app-proxy \
--engine-family MYSQL \
--auth '{"AuthScheme":"SECRETS","SecretArn":"arn:aws:secretsmanager:...:secret:db-creds"}' \
--role-arn arn:aws:iam::123456789:role/rds-proxy-role \
--vpc-subnet-ids subnet-0aaa subnet-0bbb \
--max-connections-percent 80
Lambda now talks to theproxy endpoint, not the database directly. 500 Lambdas arrive; the proxy feeds them from a pool of ~50 real connections. The database never feels the stampede.
2. Reserved concurrency as a circuit breaker
We capped the image function at 100 concurrent executions:
bash
aws lambda put-function-concurrency \
--function-name image-processor \
--reserved-concurrent-executions 100
Yes, this throttles throughput. That's the point —a slower pipeline beats a dead database.
3. Backoff and requeue for the rest
Anything that couldn't grab a connection went back to the queue with exponential backoff instead of crashing.
The results
Metric | Before | After |
|---|---|---|
Max DB connections seen | 480+ (hard cap) | ~55 (pooled) |
Error rate under load | 78% | 0.2% |
Backlog clear time | ❌ never completed | ~11 minutes |
Incident recurrence since | Every queue spike | None in months |
[INSERT SCREENSHOT 3: Post-fix load test — high Lambda concurrency with flat, low DatabaseConnections line. This "flat line under pressure" graph is the proof the fix works.]
4 lessons worth stealing
- **Serverless and relational databases speak different scaling languages.**Never connect Lambdas directly to RDS at any real scale — put a proxy (or a connection pooler) in between.
- **Concurrency limits aren't a hack — they're a safety system.**Every production Lambda that touches shared infrastructure deserves a reserved concurrency cap.
- **Queues turn small bugs into outages.**A backlog isn't just "work waiting" — it's stored energy that will discharge into your weakest component. Know which one that is.
- **The scariest incidents come from code that worked correctly.**Nothing was "broken" that night. Two healthy systems interacted catastrophically. Design for the interaction, not just the components.
Your turn
Audit your account today:**Lambda → check every function that connects to RDS/Aurora → is anything pooling your connections?**If the answer is no, you have a 2 AM page scheduled for a date you don't know yet.
Been burned by a serverless + database collision? Share your war story in the comments — the best architecture lessons come from other people's outages.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article