HTTP 504 Gateway Timeout
The middleman gave up waiting: the upstream server did not answer within the proxy's time limit.
What HTTP 504 means
HTTP 504 Gateway Timeout is issued by a proxy, load balancer or CDN whose request to the upstream server received no response within its timeout. Unlike 502 — where the upstream answered badly — with 504 it did not answer at all in time.
The root cause is almost always something slow behind the scenes: an expensive database query, an unresponsive external API, or an application thread pool starved by load.
Common causes of 504 errors
- A slow database query or missing index making one endpoint take longer than the proxy allows.
- The application waiting on an external API that is itself slow or down.
- Backend saturated: all workers busy, requests queueing past the timeout.
- Network issues between proxy and upstream (routing, packet loss, DNS).
- Timeout mismatch: the app legitimately needs 60s, the proxy cuts off at 30s.
How to fix it as a visitor
- Retry after a moment — a single 504 is often one slow request, not an outage.
- For an action you submitted (payment, order), check whether it actually went through before retrying.
How to fix it as a developer
- Find the slow endpoint in access logs/APM: fix the query, add indexes, cache the result.
- Move slow work to background jobs and return quickly with a status the client can poll.
- Align timeout budgets end to end (app < proxy < CDN) so the slowest link is known and intentional.
- Add circuit breakers around flaky external APIs instead of letting them stall your workers.
Example response
HTTP/1.1 504 Gateway Timeout Server: nginx Content-Type: text/html <html><body><h1>504 Gateway Timeout</h1></body></html>
FAQ
What is the difference between 504 and 502?
504 means the upstream never answered within the timeout; 502 means it answered with something invalid.
Is a 504 the user's connection problem?
No — it is between the site's proxy and its backend. The user's network is fine.
Was my submitted request processed if I got a 504?
Possibly yes — the timeout hit the response, not necessarily the processing. Check state before blindly retrying non-idempotent actions.