Code RoomDatabase connection pool exhaustion
MediumPrep Room Coding #2940

Database connection pool exhaustion

On-callDatabases & SQLMid–Senior~35 min

During a flash sale, the app starts returning 500s and logs fill with "FATAL: sorry, too many clients already" and "remaining connection slots are reserved." Postgres `max_connections` is 200. The dashboard shows `pg_stat_activity` near 200 connections, but most are in state `idle in transaction` or plain `idle`, not actually running queries — DB CPU is low. The app runs 30 Kubernetes pods that just autoscaled from 8, each with its own connection pool sized at 20. No PgBouncer in front. A new feature shipped last week that opens a transaction early in a request handler. Triage and mitigate.

What a strong answer looks like

Stop the bleeding first (mitigate), then form hypotheses from real signals. Separate root cause from symptom, communicate status as you go, and close with what prevents a repeat.

0:00 of about 35 min
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.