Under a 50,000 req/sec payment ingestion load, HTTP 504 Gateway Timeouts frequently mislead engineers into diagnosing edge proxy issues. In reality, the root cause is almost always worker thread connection starvation. When an unindexed table lock or slow transaction holds a database connection, upstream connection pool queues (e.g. HikariCP, pgpool) fill up.
The Cure: Adding more application pods exacerbates the problem by opening even more connection attempts against the saturated database. The correct procedure is querying pg_stat_activity or MySQL SHOW ENGINE INNODB STATUS, isolating the blocking query PID, terminating the hung lock, and enforcing connection pool admission limits with circuit-breaking.