5xx Server ErrorCommonly usedRFC 9110

504Gateway Timeout

Upstream server did not respond in time.

What it means

The server, acting as a gateway, did not receive a timely response from an upstream server. Different from 502 — the upstream server was reached but took too long to respond.

When to use it

  • Upstream API is slow or unresponsive
  • Database query is taking too long
  • Third-party service is timing out
  • Long-running operation exceeded proxy timeout

Common causes

  • Slow database query without a timeout
  • Third-party API taking too long
  • nginx proxy_read_timeout exceeded
  • Missing database indexes causing slow queries

Code Examples

Express — add timeouts to external calls
javascript
// Always set timeouts on external API calls
const response = await fetch('https://api.example.com/data', {
  signal: AbortSignal.timeout(5000), // 5 second timeout
});

// Or with axios:
const response = await axios.get('https://api.example.com/data', {
  timeout: 5000,
});

Quick Facts

Code504
CategoryServer Error
SpecRFC 9110
CommonYes
← Back to all status codes