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.
More on Reliability Patterns in Production
Clients get 503s with body `upstream connect error or disconnect/reset before headers. reset reason: overflow`, and Envoy logs show flag `UO`.AdvancedNGINX ingress returns 504 and logs `upstream timed out (110: Connection timed out) while reading response header from upstream`.BeginnerCustomers were charged twice during an incident where the payment API timed out.AdvancedEvery rolling deploy produces a short burst of 502s on the AWS ALB.IntermediateRedis restarted and immediately the database CPU hit 100% and the site went down.AdvancedLogs fill with `CallNotPermittedException: CircuitBreaker 'inventory' is OPEN and does not permit further calls` long after inventory recovered.Intermediate