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

Start free on Cariara · Coding problems · System design studio