HTTP 504 Gateway Timeout — What It Means and How to Fix It

The 504 Gateway Timeout status code indicates that the server, while acting as a gateway or proxy, did not receive a timely response from an upstream server it needed to access in order to complete the request. This typically means there's a problem with communication between two servers, not necessarily with the client's request itself.

Last updated: 2026-06-11

RECOMMENDED

Essential Reading: Designing Data-Intensive Applications

The system design bible for software engineers. Learn to build reliable, scalable, and maintainable systems.

View on Amazon →
Status Code 504
Name Gateway Timeout

Common Causes

  • Upstream server is down or unresponsive (e.g., database server, API server).
  • Network connectivity issues between the gateway/proxy and the upstream server.
  • The upstream server is overloaded and cannot respond within the gateway's timeout period.
  • Incorrect proxy or gateway configuration leading to timeouts.

Code Examples to Handle HTTP 504

curl -I https://httpbin.org/status/504

How to Fix It

  1. Check the status and logs of the upstream servers that the gateway/proxy relies on. Look for errors, high CPU/memory usage, or service outages.
  2. Verify network connectivity between the gateway/proxy and the upstream server using tools like `ping` or `traceroute`.
  3. Increase the timeout settings on the gateway or proxy server if the upstream server genuinely needs more time to process requests (though this might mask performance issues).
  4. Review the configuration of the gateway/proxy to ensure it's correctly forwarding requests and has appropriate timeout values set.
💡 Example: A user tries to access an e-commerce website. The website's load balancer (acting as a gateway) forwards the request to a web server. The web server then tries to fetch product data from a separate database server. If the database server is slow or unresponsive, the web server might not reply to the load balancer in time, causing the load balancer to return a 504 Gateway Timeout to the user.
🛠️ Developer Tip: When encountering a 504, focus your debugging efforts on the backend services and the network path between them, rather than the client-side code. Implement robust logging on your gateway and upstream services to quickly pinpoint the source of the timeout.

Related Status Codes

Frequently Asked Questions

What causes HTTP 504?

HTTP 504 is caused when a server, acting as a gateway or proxy, doesn't receive a timely response from another server it's trying to reach. This can be due to the upstream server being down, network issues, or the upstream server being overloaded.

How do I fix HTTP 504?

To fix HTTP 504, you should investigate the health and logs of your backend (upstream) servers, check network connectivity between your gateway/proxy and those servers, and review timeout configurations on your gateway. It's often an infrastructure or backend service issue.