5xx

504 Gateway Timeout

The gateway server did not receive a timely response from the upstream server.

What is HTTP 504?

This status code indicates that the server, while acting as a gateway or proxy, did not receive a response from the upstream server within the time it was willing to wait. Unlike 408 which is about the client being slow, 504 is about the server-to-server communication timing out. This commonly occurs when backend processing takes too long or the upstream server is overloaded.

Defined in RFC 9110

Common Causes

  • The upstream server is taking too long to process the request, exceeding the proxy timeout
  • The backend server is overloaded and cannot respond within the timeout window
  • Network issues between the proxy and the upstream server causing connection delays
  • A long-running database query or external API call blocking the backend response

How to Fix

  • Increase the proxy timeout settings if the backend legitimately needs more time
  • Optimize slow backend operations, database queries, or external API calls
  • Check network connectivity and latency between the gateway and the upstream server
  • Consider making long-running operations asynchronous and returning a 202 Accepted instead