504 Gateway Timeout

504
Gateway Timeout
⚙️
⚙️

Example HTTP Response

HTTP Response
HTTP/1.1 504 Gateway Timeout
Common Causes
  • Upstream server too slow
  • Network issues between servers
  • Backend request processing timeout
Technical Details

What does this mean?

The middleman gave up waiting! The proxy knocked on the backend's door but nobody answered in time.

Technical Definition

The server was acting as a gateway and could not get a response in time.

RFC Says

"The 504 (Gateway Timeout) status code indicates that the server, while acting as a gateway or proxy, did not receive a timely response from an upstream server it needed to access in order to complete the request."

Plain English:

504 means 'I'm a proxy/gateway, and the server behind me took too long to respond, so I gave up.' This happens when a reverse proxy has a timeout (say 60 seconds) and your application server doesn't respond within that time. Unlike 408 (client took too long), 504 means the backend took too long.

Common Misinterpretation

Like 502, this should come from infrastructure (proxies, load balancers, API gateways), not your application code. If your app times out waiting for a database or external API, consider returning 500 or 503 instead. 504 specifically means a proxy gave up waiting for an upstream server.

Code Snippets

Ready-to-use code for returning this HTTP status in your application:

Node.js
// Express.js
app.get('/example', (req, res) => {
  res.status(504).json({
    error: 'Gateway Timeout',
    message: 'Your error message here'
  });
});

// Native HTTP
const http = require('http');

http.createServer((req, res) => {
  res.writeHead(504, { 'Content-Type': 'application/json' });
  res.end(JSON.stringify({
    error: 'Gateway Timeout',
    message: 'Your error message here'
  }));
}).listen(3000);
When to Use This Code
  • Proxy/gateway timed out waiting for upstream server
  • Backend server is taking too long to respond
  • Use when acting as gateway and upstream doesn't respond in time
  • Use 408 for client request timeout, 504 for gateway timeout
SEO Handling

Indexing

Like other 5xx errors, temporary 504s don't immediately affect indexing. Google retries before taking action.

Crawler Behavior

Crawlers see 504 as a temporary performance issue and will retry. Persistent timeouts indicate infrastructure problems.

Google Notes

Frequent 504 errors suggest your site is too slow for Googlebot. Optimize performance to improve crawl efficiency and rankings.

504 Gateway Timeout FAQ

What causes a 504 Gateway Timeout error?

Upstream server too slow. Network issues between servers. Backend request processing timeout.

When should I use 504 Gateway Timeout?

Proxy/gateway timed out waiting for upstream server. Backend server is taking too long to respond. Use when acting as gateway and upstream doesn't respond in time. Use 408 for client request timeout, 504 for gateway timeout.