Fluxtail
Log Management Guides

What Is a 504 Error? Gateway Timeout Explained

A 504 Gateway Timeout means a proxy waited too long for an upstream response. Learn safe visitor steps, 504 vs 408/502/503, and operator diagnosis.

By Fluxtail Engineering Updated

A 504 Gateway Timeout means a server acting as a gateway or proxy did not receive a timely response from an upstream server it needed to complete your request. That is the HTTP definition in RFC 9110. A browser may show a 504 page, but the status alone does not identify which upstream component was slow, whether the underlying operation eventually finished, or which timeout fired.

If you are visiting a site, wait briefly and try a safe page load again. If the failed action could create, pay for, upload, or delete something, check whether it completed before submitting it again. If you operate the service, start by identifying which proxy returned 504 and correlate its request with the next hop. Increasing a timeout before finding the delay can simply make users wait longer.

What happened in a 504 request?

A typical path is browser or API client → CDN or edge proxy → load balancer or ingress → application → dependency. Any intermediate server acting as a gateway can wait for the next hop and return 504 when that wait exceeds its configured limit. A proxy can also return 504 when it cannot complete a connection to its target in time; the exact behavior depends on the product and configuration. The upstream application might be overloaded, blocked on a database, stuck behind a queue, unreachable over the network, or simply doing work longer than the gateway allows. Those are hypotheses until the request-path evidence supports one.

The visible 504 is a symptom at the reporting hop, not proof that the application crashed. It also does not prove the application did no work. A gateway can time out after an upstream operation has committed a change but before its reply reaches the client. That ambiguity is why indiscriminate retries of non-idempotent requests can create duplicate effects. RFC 9110 distinguishes idempotent methods, but an API's actual side effects and retry contract still need checking.

504 versus 408, 502, and 503

The codes point to different boundaries, according to RFC 9110's status definitions:

  • 408 Request Timeout: The server did not receive the complete client request within the time it was prepared to wait. It is not another name for an upstream gateway timeout. A client may repeat an outstanding request under the RFC, but application side effects still deserve care.
  • 502 Bad Gateway: A gateway or proxy received an invalid response from the upstream server while trying to fulfill the request.
  • 503 Service Unavailable: The responding server is temporarily unable to handle the request, commonly because of overload or maintenance. It may include Retry-After; a 503 does not by itself reveal every contributing cause.
  • 504 Gateway Timeout: A gateway or proxy did not receive a timely upstream response.

Do not rewrite one code as another just to make dashboards look tidy. Preserve the status observed at each hop; an upstream may itself return a 5xx while an outer gateway returns a different status.

Is Cloudflare 524 the same error?

No. Cloudflare Error 524 is Cloudflare-specific: Cloudflare connected to the origin, but either did not receive a response before its proxy read timeout or could not complete a write to the origin before its proxy write timeout. A site behind Cloudflare can also show an HTTP 504 from Cloudflare or another hop. Record the actual code and the page or response headers rather than treating 524 and 504 as interchangeable. Avoid transferring Cloudflare's timeout values to another CDN, ingress, or deployment; each has its own configuration and behavior.

What can a visitor do?

For an ordinary read-only page, wait briefly and retry once. Check whether other pages or a published service-status page work. If the problem persists, report the affected page, approximate time with timezone, device/network context, and any request or support ID shown by the site. Omit passwords, session tokens, private query strings, and payment details from screenshots or support messages.

For a checkout, upload, account change, or API write, first inspect the resulting account or transaction state. If the service supplies an idempotency key or operation-status endpoint, follow that contract. A 504 can leave the outcome unknown to the client; repeatedly pressing Submit is not a general fix. Clearing browser data, changing DNS, or restarting a device will not repair an overloaded upstream service, though a site operator may ask for a bounded comparison from a second network to distinguish a local connectivity problem.

Diagnose a 504 from the emitting hop inward

The fastest reliable investigation is a narrow chain of evidence, not a global search for the text 504. Preserve one representative request without reissuing a potentially state-changing operation. Record the UTC timestamp and timezone, method, sanitized route, status, response headers that identify the gateway, request ID if present, and the observed duration. Keep a short interval around that request, then compare it with a successful request on the same route and release. Do not copy authorization headers, cookies, full query strings, bodies, or customer identifiers into a shared incident note.

1. Find the server that returned 504

Map the actual request path: CDN, WAF, load balancer, ingress, reverse proxy, application, and its dependencies. Examine the edge or load-balancer access record for the response status, upstream or target status if recorded, target address, timing fields, and request ID. Field names and availability depend on the product and log format. A Server header or branded error page is a clue, not conclusive proof of the entire path; intermediaries can add or replace headers and bodies.

If the reporting gateway has no matching upstream request, inspect its routing, connection, DNS, TLS, and network evidence before blaming application code. If the target received the request, follow the same request ID or a carefully bounded timestamp/route comparison into application logs. A missing app log is not proof that the app never saw it: collection gaps, logging placement, clock skew, and retention can all hide a record. AWS's Application Load Balancer guide illustrates why this distinction matters: ALB-generated 504 causes include connection timeout, a target that does not respond before the idle timeout, network ACL return-path problems, and a response body shorter than the declared Content-Length. Those examples are ALB-specific, not a universal 504 checklist.

2. Locate where the request spent its time

Compare timing across hops rather than assuming all time was spent in the application handler. Useful boundaries include client-to-edge, edge-to-target connection, time until target response headers, total upstream response time, application queue time, and calls to databases or external services. Use whichever measurements the deployed components actually expose, with the same request and clock basis where possible. If the gateway waited on a target that completed only after the 504, check whether work continued and whether a write committed.

Look for a change in scope: one target or all targets; one route, region, tenant class, or release; only writes or both reads and writes. Compare with request volume and error rate. A rising 504 count alone may reflect rising traffic rather than a worse failure fraction. A low-traffic route may show a high percentage from just one request, so retain the numerator and denominator and inspect actual examples.

3. Test causes against evidence

  • Application work: A slow query, lock wait, blocking external call, expensive serialization, or unexpectedly large response may delay headers or body completion. Inspect the relevant spans or dependency measurements if separately instrumented, and correlate with application logs. Do not infer a database root cause merely from a slow endpoint.
  • Capacity and queueing: CPU, memory pressure, thread or worker exhaustion, connection-pool saturation, and backlog can delay otherwise normal requests. Compare these signals with the failure window and target group; a healthy liveness check does not prove the affected route has capacity.
  • Connectivity: Connection failures, DNS resolution, TLS handshakes, security rules, and return-path filtering can consume the gateway's wait budget before application logic runs. Check the emitting product's own error reason and network evidence.
  • Timeout chain: Client, CDN, load balancer, ingress, application, and dependency deadlines can differ. Determine which one expired first and whether upstream work was canceled or continued. A blanket increase may increase resource occupancy and obscure a regression. If a legitimate long-running operation cannot fit the interactive request budget, a documented asynchronous job with status polling can be a better design, but it is an application change requiring its own correctness review.

Keep symptom, immediate trigger, and root cause separate. “The gateway idle timeout elapsed” explains the response; it does not explain why the target failed to answer in time. How to read logs covers bounded context and evidence quality when tracing the request across services.

Mitigate and verify without making the incident worse

Prefer a reversible, authorized action tied to the observed cause: route away from a demonstrably unhealthy target, restore a failed dependency, reduce an expensive request path, or revert a change that correlates with the regression. Check the operation's side effects, approval path, and rollback procedure first. Retry storms, broad restarts, cache flushes, and unbounded timeout increases can amplify load or hide the defect. Change one variable when practical and preserve the original evidence.

After mitigation, verify the affected user journey, not just a green health check. Confirm the same route succeeds at a reasonable latency, compare 504 ratio and upstream duration against a pre-incident baseline, and check for duplicate or unfinished writes. Watch adjacent routes and target groups for displaced load. An alert should distinguish a sustained, user-impacting 504 ratio from a single low-volume event, include a minimum traffic or absolute-count safeguard, and route to an owner who can act. See alerting best practices for that alert contract.

Prevention follows the evidence: set explicit deadline budgets between hops, make retried operations safe where possible, cap concurrency and queues, test dependency failure, and expose gateway-versus-target status and duration. Review timeouts together rather than copying a number from another architecture. Include synthetic or external checks for the complete request path; gateway and application logs alone may miss a client-visible failure.

Use central logs as evidence, not as a gateway fix

When proxy and origin logs are actually delivered through a supported collector or receiver, Fluxtail's paid Starter and Pro logs-focused service can help search, filter, and Live Tail retained events around a 504. Field names such as request ID, upstream duration, and target status depend on the source's log format and collector mapping; verify them with a known event. Fluxtail does not instrument gateway timing, guarantee upstream-log completeness, or change load-balancer behavior. A gateway-generated 504 might have no corresponding origin event. Use raw gateway and target evidence, alongside separately sourced metrics or traces if available, before deciding on a fix. Search and filters is one investigation surface, not a timeout remedy.