504

Gateway Timeout

5xx Server Error

Back to list

Server perspective

Use 504 when acting as a gateway or proxy and the upstream server did not respond before your timeout expired.

When to use

  • Return 504 when a backend or origin takes too long and the intermediary times out waiting
  • Use it only when this server depends on an upstream response to finish the request

How to respond

  • Set and monitor realistic upstream deadlines, then log which dependency timed out and after how long
  • Return a clear timeout response instead of leaving the client hanging on an open connection

Headers to consider

  • No status-specific header is required; include request or trace metadata when it helps operators correlate the upstream timeout

Response body

  • A body is optional but helpful; explain that an upstream dependency timed out and include safe retry guidance when appropriate

Server-side pitfalls

  • Do not use 504 for client-to-server request timeouts; that is 408 Request Timeout
  • Do not use 504 for malformed upstream responses; that is 502 Bad Gateway

Examples

Gateway times out waiting for search backend

Request:GET /search?q=payments via an API gateway
Response:504 Gateway Timeout with error: upstream_timeout

The gateway had a valid request but could not get a timely answer from the backend before its deadline expired.

References

Related 5xx Server Error Codes