504 Server Error

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

Stop debugging HTTP errors in production

Get full error context and fix issues faster with self-hosted error tracking.