Interview Prep/SRE & Reliability/Reliability Patterns in Production

After a 30-second database blip, Postgres keeps rejecting connections with `FATAL: sorry, too many clients already` for 20 minutes.

AdvancedTroubleshootingReliability Patterns in Production
Answer

Likely causes → A retry storm and connection storm: every pod retried immediately, opened new connections to replace broken ones, and the pools' total maximum exceeds max_connections. The DB is now saturated by reconnect attempts (a metastable failure).

Diagnose →

SELECT state, count(*) FROM pg_stat_activity GROUP BY state;
SHOW max_connections;

Compare pods x pool max with max_connections.

Fix → Shed load: scale callers down or disable retries via flag, terminate idle connections, then bring traffic back gradually. Longer term, put PgBouncer or RDS Proxy in front, cap pool sizes so their sum fits, and add backoff with jitter on reconnects.

Prevent → Capacity check in reviews: replicas x maxPoolSize must fit max_connections at max HPA scale.

All SRE & Reliability questions

More on Reliability Patterns in Production