Logo
DevUtilsAll-in-one toolkit
Back to all codes
5045xx
5xx — Server Error

Gateway Timeout

The server, acting as a gateway or proxy, did not receive a timely response from the upstream server.

What it means

The HTTP 504 Gateway Timeout status code means that an edge server or proxy gateway dropped the connection because an upstream internal application server took too long to complete its work and return a response. Every proxy has a pre-configured timeout threshold (e.g., 60 seconds) after which it gives up.

How it works

  • 1The client initiates a heavy request (e.g., exporting a massive CSV report).
  • 2The reverse proxy passes the request to the backend worker.
  • 3The backend worker hangs or spends 90 seconds querying millions of unindexed rows.
  • 4At 60 seconds, the proxy's `proxy_read_timeout` limit is breached. It terminates the connection to the client and presents a 504.

Why you're seeing this

  • Unindexed, heavy database queries lagging the main thread.
  • External third-party APIs hanging without an explicit timeout config.
  • Proxy timeout configurations (`fastcgi_read_timeout`, `proxy_read_timeout`) are set too low for long-running scripts.

How to fix it

  • Offload time-consuming processes to an asynchronous background worker queue (e.g., RabbitMQ, Celery, BullMQ) and return a `202 Accepted` immediately.
  • Optimize slow database queries using indexes and execution plans (`EXPLAIN`).
  • Increase the timeout limits in your proxy configuration if long requests are explicitly intended.

Framework Implementations

Nginx Configuration

# Increase timeouts for long-running processes
location /heavy-api {
    proxy_read_timeout 300s;
    proxy_connect_timeout 300s;
    proxy_pass http://backend_workers;
}

Real-Life Scenarios

Configure your proxy layers (like AWS ALB or Cloudflare) to use this when a downstream microservice stops communicating or enters an infinite loop, avoiding hanging connections.

Massive Report Generation Timeout

An HR admin attempts to download an annual analytical PDF summary. The backend script takes 5 minutes to aggregate the data. The web server cuts it off at 60 seconds with a 504.

Slow Third-Party API Reliance

Your server depends on a legacy shipping partner API to calculate cart taxes. The partner's server lags completely. Your web proxy cuts off the stalled connection with a 504.

HTTP Transaction

1. Client Request

GET /api/v1/export-all-data HTTP/1.1
Host: api.example.com

2. Server Response

HTTP/1.1 504 Gateway Timeout
Server: cloudflare
Content-Type: application/json

{"error": "GatewayTimeout", "message": "The upstream server took too long to respond."}

SEO Implications

Frequent 504 timeouts are extremely bad for SEO. Search bots will stop indexing pages that fail to load within standard time frames, lowering your overall Domain Authority due to high latency signals.

Related Codes