logo

Gateway Timeout

A gateway timeout is an HTTP 504 error that occurs when an intermediary — such as a reverse proxy (Nginx, Caddy), load balancer (AWS ALB), or CDN (Cloudflare) — fails to receive a response from your backend within its configured time limit.

What Causes a 504

A 504 doesn’t mean your server crashed. It means your server is still processing the request, but the intermediary gave up waiting:

  1. Client sends a request to your domain
  2. The request hits a reverse proxy or load balancer
  3. The proxy forwards it to your backend
  4. Your backend takes too long to respond
  5. The proxy returns 504 Gateway Timeout to the client

Common Timeout Limits

ServiceDefault Timeout
Vercel (Hobby)10 seconds
Vercel (Pro)60 seconds
AWS ALB60 seconds
Cloudflare100 seconds
Nginx60 seconds
Heroku30 seconds

How to Fix Gateway Timeouts

  • Optimize the slow operation: Add database indexes, reduce query scope, cache expensive computations
  • Increase the gateway timeout: A temporary fix — adjust your proxy or platform configuration
  • Move slow work to a background queue: The permanent fix — respond immediately and process asynchronously

Background Processing as the Solution

If your endpoint does work that takes longer than your gateway allows, offload it:

// Instead of a 60-second synchronous call that times out:
app.post('/api/export', async (req, res) => {
  await aq.tasks.create({
    callbackUrl: 'https://your-app.com/api/run-export',
    payload: { userId: req.userId },
    webhookUrl: 'https://your-app.com/api/on-export-done',
    timeout: 300,
  });

  res.json({ status: 'processing' }); // responds in milliseconds
});