A production alert fires while users report blank pages and failed API calls. The dashboard shows a growing count of 504 Gateway Timeout responses, but the application health check still says the service is running. That combination is what makes a 504 incident so uncomfortable: the visible failure sits at the gateway, while the underlying cause may be a database, worker pool, network path, or timeout policy somewhere behind it.
The fastest investigations treat a 504 as a timing and request-path problem. You need to identify which intermediary returned the response, determine how long it waited, and correlate that request with the upstream service that was supposed to answer.
Table of Contents
- When a 504 Hits Production
- The Technical Definition of a 504 Gateway Timeout
- How 504 Differs from 502 and 503 and 408 Errors
- Common Technical Causes of 504 Errors
- Diagnostic Checks and Log Queries for 504 Incidents
- Why Raising Timeouts Is Rarely the Right Fix
- Mitigation Strategies and Incident Playbook Actions
When a 504 Hits Production
The alert usually arrives before the root cause is obvious. A reverse proxy starts returning 504 responses for a small set of routes. Users see a generic gateway timeout page, retry the request, and sometimes create more work for an already overloaded backend. Meanwhile, application dashboards may show healthy processes because the origin hasn't crashed. It's not completing requests quickly enough for the component in front of it.

What the user sees
From the browser, a 504 often looks like a site outage. A page may fail to load, an API client may receive an error response, or a report screen may remain pending until the gateway gives up. The user usually can't tell whether the application is overloaded, the database is slow, or an intermediary has a more aggressive timeout than the workload requires.
From the SRE perspective, the first useful clues are more specific:
- Status code: Confirm that the response is 504, not a client-side timeout or a different gateway error.
- Route concentration: Check whether failures cluster around one endpoint, service, tenant, or request type.
- Timing: Compare request duration at the proxy with application-side duration.
- Path: Identify which CDN, load balancer, reverse proxy, or API gateway generated the response.
Practical rule: A 504 tells you that a request exceeded an intermediary's waiting policy. It doesn't identify the slow component by itself.
Why the dashboard can look healthy
A backend can accept connections, pass a basic health check, and still fail real traffic. Health checks often exercise a lightweight route, while production requests perform database joins, call dependent services, generate files, or wait for limited worker capacity. The gateway sees only the missing response within its configured window.
That distinction shapes the response. Restarting a healthy application server may destroy useful evidence without removing the slow query or blocked dependency. Start with the proxy and request path, then follow the request into the origin and its dependencies.
The Technical Definition of a 504 Gateway Timeout
The formal answer to what is a 504 error comes from RFC 9110, the HTTP semantics standard published on 2022-06-06. It defines a 504 as the response generated when a server acting as a gateway or proxy doesn't receive a timely response from an upstream server needed to complete the request. RFC 9110 replaced the earlier HTTP semantics text from RFC 7231, so the current definition is part of the modern global HTTP standard.

The important word is upstream. The client sends a request to an intermediary, such as a reverse proxy, load balancer, CDN, or API gateway. That intermediary forwards the request or otherwise depends on another server. If the upstream response doesn't arrive before the intermediary's timeout policy expires, the intermediary returns 504 to the client.
A 504 is about lateness, not necessarily reachability
A 504 doesn't prove that the origin was unreachable. The proxy may have connected successfully, sent the request, and then waited while the application processed it. The upstream could still be running when the gateway sends the error to the user.
MDN's 504 documentation describes the same behavior: a server acting as a gateway or proxy cannot obtain a response in time from the upstream server. Operationally, that means a single slow request can produce a 504 even while the origin continues serving other requests.
Why multiple hops complicate ownership
Modern requests commonly cross several intermediaries. A browser may reach a CDN, which contacts an edge service, which forwards to a load balancer, which selects an application instance. Each layer can have its own connection, response, or idle timeout. The layer that returns the 504 may not be the layer where the work became slow.
Record the component that emitted the response and compare its timeout with the timing observed by the next hop. A gateway timeout policy can expose an application bottleneck, a network delay, or a mismatch between legitimate request duration and infrastructure defaults. The response code identifies the failed waiting relationship, not the complete root cause.
How 504 Differs from 502 and 503 and 408 Errors
Related HTTP errors describe different failure signals, and confusing them leads teams toward the wrong logs. A 504 means the intermediary waited too long for an upstream response. A 502 usually means the intermediary received an invalid response or couldn't interpret the upstream exchange. A 503 indicates temporary unavailability, while a 408 concerns the client's request arriving too slowly for the server.
| Error Code | What It Signals | Typical Root Cause | First Diagnostic Step |
|---|---|---|---|
| 504 Gateway Timeout | A gateway or proxy didn't receive a timely upstream response | Slow application work, dependency latency, network delay, or an unsuitable timeout policy | Compare proxy timing with upstream request timing |
| 502 Bad Gateway | A gateway received an invalid response from upstream | Broken upstream connection, malformed response, or protocol failure | Inspect proxy error logs and upstream connection details |
| 503 Service Unavailable | The service can't handle the request temporarily | Capacity protection, maintenance, unavailable workers, or deliberate overload signaling | Check service health, admission controls, and capacity |
| 408 Request Timeout | The server didn't receive the client request within its waiting policy | Slow client upload, interrupted connection, or incomplete request transmission | Inspect client-to-server connection and request-read timing |
Use the code as a routing signal
For a 504, begin at the intermediary that emitted the response and work downstream. For a 502, examine the exchange itself, including whether the upstream returned something the proxy couldn't accept. For a 503, focus first on service availability and deliberate overload behavior rather than assuming a dependency is slow.
A 408 sends you in the opposite direction. It points toward the client-to-server request path, not necessarily the proxy-to-origin response path. The distinction matters during incidents because the same user report, “the page timed out,” can map to entirely different systems.
A useful classification test: Ask which side failed to make progress, the client sending the request, the gateway interpreting an upstream response, the service accepting work, or the upstream completing work.
Don't rely on the status code alone. Read the response headers, gateway logs, load balancer records, and application trace for the same request identifier. If different layers disagree, preserve those observations. A CDN-generated 504 and an application-generated 504 can represent different incidents even when the browser displays the same number.
Common Technical Causes of 504 Errors
A 504 usually emerges from one of four practical conditions: the origin is slow, the origin is overloaded, work is stuck, or the gateway can't complete the network path to the origin. AWS CloudFront's 504 guidance connects these failures to backend processing time, exhausted CPU, memory, or IOPS, and blocked access caused by firewalls, security groups, DNS, or routing.

Slow upstream work
Database latency is a common starting point. A request may wait on an inefficient query, lock contention, an exhausted connection pool, or a downstream API. The application process remains alive, but the request handler doesn't produce a response before the proxy's deadline.
Look for route-specific latency and correlate it with database timings. If only reporting or aggregation endpoints fail, the workload may be doing legitimate but unsuitable synchronous work. Move expensive processing to an asynchronous workflow where the user receives a job state rather than holding an edge request open.
Resource exhaustion
An overloaded application server may have enough capacity to answer health checks but not enough to drain production traffic. CPU saturation slows execution, memory pressure increases pauses or triggers restarts, and exhausted IOPS makes otherwise ordinary database operations wait. A busy worker pool can create the same symptom even when host-level CPU appears moderate.
Check queue depth, active requests, worker availability, connection pools, and dependency saturation together. Scaling the application tier can help when requests are independently parallelizable. It won't fix a lock, a slow shared database, or a dependency that every new instance continues to overload.
Stalls and network-path failures
A stuck background operation, deadlocked thread, blocked socket, or unbounded retry can hold a request open until the gateway gives up. Separately, the proxy may fail to reach the origin because a firewall, security group, DNS resolution path, or route blocks access. AWS specifically documents these reachability checks alongside backend timeout causes.
For Nginx deployments, review the relevant proxy and upstream directives with this Nginx configuration guide. Don't change settings blindly. First establish whether the proxy is waiting for headers, waiting for a response body, or failing to connect.
A useful mental model is:
- Latency: The origin eventually answers, but too late.
- Capacity: The origin can't process work at the required rate.
- Stall or path failure: The request stops progressing, or the gateway can't reach the required upstream.
A diagnostic video can help engineers unfamiliar with proxy-level timing visualize the request path:
Diagnostic Checks and Log Queries for 504 Incidents
Start with evidence, not configuration edits. Confirm the response producer, affected route, request duration, upstream target, and request identifier before restarting services or increasing a timeout.
Begin at the proxy
Search access logs for 504 responses and group them by route, upstream, and timing fields. A generic command-line workflow might look like this:
grep ' 504 ' /var/log/nginx/access.log
grep ' 504 ' /var/log/nginx/access.log | awk '{print $7}' | sort | uniq -c
Use your platform's actual field names rather than assuming the access log format. You want to answer whether failures are concentrated on one endpoint or spread across the service.
Then inspect error logs for upstream timing and connection messages:
grep -iE 'upstream|timeout|504' /var/log/nginx/error.log
For a centralized system, filter on fields such as status=504, route, service, host, request_id, and upstream_status. Fluxtail's log-reading guidance is useful when you need to keep proxy, application, and infrastructure records separated while correlating one incident window.
Follow the request into the origin
Search application logs using the request ID from the gateway record. Compare the application's start and completion timestamps with the proxy's recorded duration. Three outcomes are especially informative:
- The application never saw the request: Investigate routing, DNS, firewall, security group, or connection handling.
- The application started but never completed it: Inspect database waits, dependency calls, thread pools, locks, and background work.
- The application completed before the gateway timed out: Look for response transmission, buffering, intermediary limits, or clock and log-order problems.
If traces exist, inspect spans for the slowest child operation. If they don't, add structured fields for route, request ID, upstream service, database duration, and total request duration. Avoid logging sensitive payloads merely to gain correlation.
Verify the path without guessing
Test connectivity from the proxy's network context, not from a developer laptop. Confirm that name resolution, routing, security policy, and the upstream listener all behave from the actual gateway environment. A successful test from another network doesn't clear the production path.
Preserve logs before rotating or clearing them. During the incident, record the timeout values at each intermediary and the observed duration at each hop. That timeline often reveals a policy mismatch more quickly than a broad infrastructure restart.
Why Raising Timeouts Is Rarely the Right Fix
Increasing a timeout can stop visible 504 responses for a request that is legitimately long-running, but it doesn't make the origin faster. It may allow more requests to occupy workers, database connections, memory, or sockets while users wait. If the bottleneck is a slow query or exhausted backend capacity, the change can turn a clear failure into a slower and larger outage.
Cloud and CDN defaults also differ. Alibaba Cloud's CDN documentation notes a 30-second default CDN origin timeout, while an Azure Front Door discussion describes origin timeout behavior in a different stack. Those settings aren't interchangeable, and copying a value from one platform into another can create a false sense of safety.
When a change can be justified
Raising a timeout is reasonable when you can demonstrate that the request is valid, bounded, and expected to take longer than the current policy. You should also understand the concurrency cost and confirm that every intermediary in the path permits the intended duration. The application, database, client, CDN, load balancer, and proxy must agree on the request's lifecycle.
The safer sequence is:
- Measure where the request spends its time.
- Remove avoidable database and dependency latency.
- Reduce synchronous work or move it to a job.
- Confirm capacity and concurrency behavior.
- Adjust the timeout only when the workload still needs the extra budget.
The timeout is a guardrail, not a performance plan.
A temporary increase can be part of mitigation, especially if a known long-running operation is causing user impact. Treat it as a controlled experiment with monitoring and a rollback condition. If latency, queueing, or resource use worsens, restore the previous policy and fix the request path instead.
Mitigation Strategies and Incident Playbook Actions
During a 504 spike, separate reducing user impact from finding the bottleneck. Apply the least destructive mitigation first, then keep collecting evidence so the emergency change doesn't become the permanent configuration.

Stabilize the request path
If the origin is overloaded, reduce incoming work or add capacity where scaling will help. If one expensive route is responsible, temporarily disable that feature, route it to a less busy pool, or serve a degraded response. Circuit breakers can stop repeated calls to a failing dependency and let the service fail fast rather than consuming every worker while waiting.
Check dependencies separately. A database, cache, queue, or external API can create the apparent application failure. For name-resolution failures or routing anomalies, use the focused checks in this DNS troubleshooting guide, while keeping the investigation grounded in the production network path.
Keep the incident diagnosable
Assign one engineer to the gateway and another to the origin when possible. Record the affected routes, timeout policies, deployment changes, dependency health, and request IDs. Separate public traffic, CDN fetches, internal administration, and reporting workloads into distinct log streams so a noisy batch operation doesn't hide customer-facing failures.
A centralized log platform such as Fluxtail can ingest records from multiple protocols, route them into named streams, and filter by fields including service, host, route, request ID, namespace, and pod. Its MCP server can also let an MCP-compatible AI client query recent errors from chat, which is useful when an incident commander needs a quick view without passing screenshots between teams.
Longer-term prevention depends on request-level tracing, latency alerts, capacity planning, and explicit timeout budgets. Alert on upstream latency before the gateway starts failing, review slow queries and dependency waits, and test graceful degradation under saturation. In the post-incident review, ask not only why the origin slowed down, but also why the gateway allowed the failure to reach users without a safer fallback.
If your team needs faster answers during gateway timeout incidents, visit Fluxtail to centralize proxy, application, and infrastructure logs in readable streams. Use correlated request fields and live filtering to determine whether the 504 starts with backend latency, capacity pressure, or the network path.