A gateway or proxy did not receive a response from an upstream server in time.
What 504 Gateway Timeout means
504 Gateway Timeout means the proxy or CDN waited for the origin to respond and gave up. Common timeout values: Cloudflare 100s on free, Nginx 60s default, AWS ALB 60s default, API Gateway 29s for HTTP and 30s for WebSocket. 504s usually mean the origin is doing too much work per request: a slow database query, an unindexed scan, an external API call that did not have its own timeout.
When servers should return it: A proxy returns 504 when the origin does not respond within the configured timeout. Origin operators see 504 as "we are too slow".
Common causes
Slow database query
Long-running computation in the request path
External API call without a sane timeout
Origin overloaded, requests queuing
Network issue between proxy and origin
How to fix 504 Gateway Timeout
Profile the slow request
Add a shorter timeout on external API calls (always less than the proxy timeout)
Move long-running work to async jobs (return 202 instead of waiting)
Add database indexes for slow queries
Increase upstream timeout if the work is genuinely slow but legitimate
408 = the client did not finish sending the request in time. 504 = the upstream did not finish sending the response in time.
Why does my request work locally but 504 in production?
Production usually has tighter timeouts (Cloudflare 100s, ALB 60s, API Gateway 29s). Local has no proxy and no timeout. Profile the slow request and either speed it up or move to async.
Defined in: RFC 9110 · Class:5xx Server Error
More references
For a one-page reference of all HTTP status codes, see the HTTP cheat sheet. For testing API responses, try the API Tester tool. For inspecting responses on the command line, the curl cheat sheet covers the most common flags.