server error RFC 9110
HTTP 504 Gateway Timeout
A gateway or proxy timed out waiting for a response from the upstream server.
What it means
The proxy successfully forwarded the request but the upstream took too long to respond and hit the proxy's timeout. Different from 503 (server refusing) and 502 (bad response) — 504 is specifically "waited, gave up". CloudFront's default is 30 seconds; API Gateway is 29 seconds; Cloudflare Free is 100 seconds.
When servers send it
- •Upstream taking longer than the proxy timeout
- •Long-running query or computation blocking the response
- •Downstream API dependency slow to respond
What the client does
Retries after a delay. Retries safe on idempotent methods only.
Common causes
- •Slow database query
- •External API call inside the request handler taking too long
- •Deadlock or long-running lock
- •CPU-bound work in the request path
How to fix it
- 1.Move long work off the request path (background job + polling)
- 2.Add database indexes to speed up slow queries
- 3.Set client-side timeouts LOWER than server timeouts to fail fast
- 4.Return 202 Accepted immediately for long operations and poll for result
Similar codes
408 Request Timeout client error
Client took too long to send the request — server gave up waiting.
502 Bad Gateway server error
A gateway or proxy received an invalid response from the upstream server.
503 Service Unavailable server error
Server is temporarily unable to handle the request — overloaded or down for maintenance.
500 Internal Server Error server error
Something went wrong on the server side — usually an unhandled exception.
501 Not Implemented server error
Server doesn't support the functionality required to fulfill the request.
← All HTTP status codes · HTTP status cheat sheet · HTTP headers reference