Connection Pool Exhaustion That Brought Down 12 Microservices
A single slow migration caused connection pool exhaustion on the RDS primary, cascading to 12 services that shared the same database.
Overview
One schema migration locked the orders table on a shared PostgreSQL instance, and within 4 minutes all 12 microservices had run out of database connections.
What happened
A database engineer ran ALTER TABLE orders ADD COLUMN delivery_estimate_v2 jsonb NOT NULL DEFAULT '{}' during a low-traffic window. Adding a column with a default rewrote all 300 million rows (PostgreSQL before 11 rewrites the table for this), holding a table-level lock for 18 minutes.
The incident ran in five stages.
- The migration started and took a table-level lock on orders.
- Within 4 minutes, the connection pools of all 12 services were exhausted.
- At the 22-minute mark, the migration was killed.
- Over the next 8 minutes, the pools drained as the queued queries resolved.
- In total, users were affected for 27 minutes.
Key concepts
- Table-level lock
- Online schema change
- Connection pool sizing
- PgBouncer
Interview questions
- How do you safely add a column to a 300-million-row PostgreSQL table without downtime?
Sign up free to read the full topic
More War Stories topics
- An IAM Misconfiguration That Let a Developer Become Admin
- AWS Credentials Committed to a Public GitHub Repository
- Backups That Were Never Actually Completing
- BGP Route Leak That Rerouted Traffic Through an Unexpected AS
- Blue-Green Deployment That Resulted in Split-Brain Sessions
- Cache Stampede on a Flash-Sale Product Page
- DynamoDB Hot Partition That Throttled a Flash Sale
- Failover to a Lagging Replica Lost 4 Minutes of Orders
- Internal DNS Cache Poisoning That Redirected API Traffic
- Malicious npm Package Exfiltrated Environment Variables at Build Time
- N+1 Query Pattern That Collapsed Under Load
- NAT Gateway Port Exhaustion Under Bursty Lambda Traffic
Start free on Cariara · Coding problems · System design studio