408 vs 504: Request Timeout vs Gateway Timeout
408 and 504 can look similar in logs, but they tell clients, crawlers, and API consumers different things.
| Aspect | HTTP 408 โ Request Timeout | HTTP 504 โ Gateway Timeout |
|---|---|---|
| Definition | The server closed the connection because the client took too long to send the request. This is a server-initiated timeout, not a proxy timeout (see 504 for that). | Your reverse proxy (nginx, Cloudflare, etc.) gave up waiting for the origin server to respond within the configured timeout. The origin may be overloaded, slow, or hung. |
| Plain-language summary | The server timed out waiting for the client to send a complete request. This is a server-initiated timeout on an idle or slow connection, not a proxy timeout. The server may close the connection after sending 408. | A gateway or proxy timed out waiting for a response from an upstream server. The upstream received the request but did not respond within the allowed time window. This is different from 502 (upstream sent a bad response) โ 504 means the upstream sent no response at all within the timeout. |
| When to use | Servers emit this automatically based on their request timeout configuration. As a developer, implement request timeouts to avoid holding connections open indefinitely. Tune the timeout value based on your slowest legitimate request path. | Gateways and proxies emit 504 automatically. As an application developer, tune upstream timeout configurations and optimize slow processing paths to avoid 504s. Always implement request timeouts on all outbound HTTP calls. |
| Client behavior | May retry the request on a new connection. The original connection is typically closed by the server. | May retry โ the upstream may be temporarily slow. Implement bounded retry with exponential backoff. After repeated 504s, surface the error and alert. |
| Caching behavior | Not cached. | Not cached. |
| SEO / crawler impact | Search crawlers interpret 408 (client-errors) for indexation and link equity accordingly. | Search crawlers interpret 504 (server-errors) for indexation and link equity accordingly. |
| API / backend impact | API clients branching on 408 expect Request Timeout semantics. | API clients branching on 504 expect Gateway Timeout semantics. |
| Safe to retry? | Only after fixing the underlying cause | Yes, with backoff โ server may recover |
Common real-world scenarios
When you see HTTP 408
Appears in server logs during slow client uploads, mobile apps on intermittent connections, or malformed HTTP requests that send headers but hang before completing the body. Also occurs during DDoS-style slow-read attacks.
When you see HTTP 504
In Nginx: "upstream timed out." In Cloudflare: <a href="/guides/cloudflare-524/">Cloudflare error 524</a> (a Cloudflare-specific timeout code). Common causes: database query that ran over the timeout threshold, external API call that was slow or hung, application code in an infinite loop or deadlock, or upstream server under high load and processing slowly.
Decision rule
Use 408 when the response should communicate request timeout behavior; use 504 when gateway timeout is the accurate protocol signal.
A frequent mistake is swapping 408 and 504 for convenience; that causes client retry bugs, incorrect cache signals, and misleading monitoring data.
Use 408 when the correct protocol signal is Request Timeout. Use 504 when the correct signal is Gateway Timeout. Returning either code for the wrong reason breaks client expectations, cache behavior, and monitoring accuracy.
FAQ
What is the biggest difference between 408 and 504?
408 communicates Request Timeout, while 504 communicates Gateway Timeout. Choosing the right one keeps clients and intermediaries predictable.
Do 408 and 504 have SEO or caching impact?
Yes. Search engines and caches interpret status classes differently. Use each code according to its semantics to avoid accidental indexing, stale responses, or crawl inefficiency.
Can APIs safely return 408 instead of 504?
Only when it matches contract semantics. API clients often branch logic by exact code, so swapping them can break retries, auth handling, or user-facing errors.
Full guides
HTTP 408 Request Timeout โ full guide ยท HTTP 408 status reference ยท HTTP 504 Gateway Timeout โ full guide ยท HTTP 504 status reference ยท All comparisons