5xx Server Errors

HTTP 504 Gateway Timeout

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

When is 504 used?

  • Upstream server slow response
  • Database timeout cascading to gateway
  • Network latency between services

How to handle a 504 response

The problem is on the server side. Check server and proxy logs, retry idempotent requests with exponential backoff, and alert on sustained 5xx rates.

Check the status code a URL returns from the command line:

curl -s -o /dev/null -w "%{http_code}\n" https://example.com

How to return 504 from your server

Node.js (Express)

res.status(504).json({ message: 'Gateway Timeout' });

Python (Flask)

return {"message": "Gateway Timeout"}, 504

Go (net/http)

w.WriteHeader(504)

Frequently Asked Questions

What does HTTP 504 mean?

504 Gateway Timeout: The server acting as a gateway did not receive a timely response from the upstream server.

Is 504 an error?

Yes. 504 is in the 5xx Server Errors class. Server errors: the server failed to fulfil an apparently valid request.