The app returns 500s and logs show "FATAL: sorry, too many clients already" from Postgres.

BeginnerTroubleshooting5xx errors
Answer

Likely causes → Total connections from all app replicas exceeded max_connections. Common after scaling out replicas, after an HPA event, or when connections leak.

Diagnose →

SHOW max_connections;
SELECT usename, application_name, state, count(*) FROM pg_stat_activity GROUP BY 1,2,3 ORDER BY 4 DESC;

Fix → Terminate idle leaked connections (pg_terminate_backend), reduce per-pod pool size, and stop scaling further until fixed.

Prevent → Put PgBouncer (transaction pooling) or RDS Proxy in front, calculate max replicas × pool size against the limit, and alert on connection usage at 80%.

All Real-World Interview questions Roadmap: Interview readiness

More on 5xx errors