504 Gateway Timeout
An HTTP 504 Gateway Timeout error means that a server acting as a gateway or proxy did not receive a timely response from the upstream server it needed to access to complete the request. This is distinct from a 502 in that the upstream server did not respond at all within the allowed time, rather than sending a bad response. End users experience a long wait followed by an error, while developers should investigate latency in the backend.
Common causes
- Slow database queries or unoptimized API calls causing the upstream server to exceed the proxy timeout window
- Network latency or routing issues between the gateway and the upstream server
- The upstream server is under heavy load and cannot process requests within the configured timeout period
- Proxy or load balancer timeout settings are too aggressive for the expected response time of the backend
- DNS resolution delays or intermittent DNS failures when the gateway tries to reach the upstream server
How to fix it
- Identify and optimize slow backend operations such as database queries, external API calls, or heavy computations
- Increase gateway timeout settings (e.g., proxy_read_timeout, proxy_connect_timeout) to allow more time for slow endpoints
- Add caching layers (CDN, Redis, Varnish) to reduce the number of requests that reach the backend
- Implement asynchronous processing for long-running tasks and return a 202 Accepted with a polling endpoint instead
- Check network connectivity and latency between the proxy and upstream servers using tools like traceroute or mtr
Detect 504 Gateway Timeout errors with Checkend
Checkend monitors your application and alerts you when 504 errors occur, with full request context:
- Full request details (URL, headers, params)
- Server-side stack trace and error context
- Automatic grouping of similar errors
- Instant notifications when error rates spike
Related HTTP errors
An HTTP 502 Bad Gateway error means that a server acting as a gateway or proxy received an invalid o...
An HTTP 503 Service Unavailable error indicates that the server is temporarily unable to handle the ...
A 408 Request Timeout error means the server waited too long for the client to complete sending the ...
Stop debugging HTTP errors in production
Get full error context and fix issues faster with self-hosted error tracking.