DevTool Desk

5xx Server error

HTTP 504 Gateway Timeout

A gateway or proxy didn't get a response from the upstream server in time.

A 504 Gateway Timeout means a proxy, load balancer, or CDN didn't get a response from the upstream server before its timeout. The upstream may be alive, but it's too slow to answer in time.

Common causes of a 504 error

  • A slow database query, external API call, or heavy computation in the request.
  • The upstream server is overloaded or hung.
  • The proxy's timeout is shorter than the time the request legitimately needs.
  • Network problems or firewall rules between the proxy and the upstream.
  • A DNS resolution delay for the upstream host.

How to fix a 504 error

  1. Find the slow part of the request with logs or tracing, and optimise the slow query or call.
  2. Move long-running work to a background job and return 202 Accepted.
  3. Raise the proxy timeout (for nginx, proxy_read_timeout) if the delay is expected.
  4. Check the upstream's CPU, memory and connection pool for saturation.
  5. As a visitor, retry later; you can't fix the timeout from the client.

Frequently asked questions

What's the difference between 504 and 408?

408 means the server timed out waiting for the client to send its request. 504 means a gateway timed out waiting for the upstream server's response.

Should I just increase the timeout?

Only as a last resort. A longer timeout hides slow code and ties up connections. It's better to make the request faster or run it as a background job.

Other common status codes

See 504 in the full searchable list, or use the HTTP Header Checker to see the status code any URL returns.