Scaling Everything Except the Database
We scaled our 20 services beautifully. They all hit the same PostgreSQL instance.
The architecture:
- 20 microservices (independently scalable! ✅)
- 1 PostgreSQL database (not scalable ❌)
- Each service: 10 connection pool size
- PostgreSQL max_connections: 100
The math:
- 20 services × 10 connections = 200 needed
- Max available: 100
- Result: Connection starvation during scaling
What actually happened:
- Services A, B, C grab all connections
- Services D-T: "connection refused"
- Health checks fail
- Pods restart, grab more connections
- Death spiral
The fix:
- PgBouncer for connection pooling
- Connection limits per service
- Read replicas for read-heavy services
- Eventually: database per service pattern
Lesson: "Microservices" with a shared database is a distributed monolith with extra steps.