PostgreSQL has a well-known scaling problem: every connection spawns a dedicated OS process. At 50 connections that's fine. At 500, the scheduler overhead starts showing up. At the default max of 100, your app returns errors.
The naive fix is to raise max_connections. Don't do t