A 504, or gateway timeout, is a close cousin of the 502: a gateway server reached out to a backend server to fulfill a request, but this time the backend simply never answered in time rather than sending back a bad response. The gateway gives up waiting and reports the timeout instead.
Slow database queries, an overloaded backend under heavy traffic, or a downstream service (an API, a third-party integration) taking too long to respond are typical causes. Because the timeout threshold is usually just a few seconds, 504s often show up first on the heaviest or most complex pages on a site, the ones pulling data from the most places, before lighter pages are affected at all. Persistent 504s are worth treating as a performance problem to fix at the source rather than a threshold to raise, since raising the timeout just delays how long a visitor waits before seeing the same failure.

