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:
- Client sends a request to your domain
- The request hits a reverse proxy or load balancer
- The proxy forwards it to your backend
- Your backend takes too long to respond
- The proxy returns
504 Gateway Timeoutto the client
Common Timeout Limits
| Service | Default Timeout |
|---|---|
| Vercel (Hobby) | 10 seconds |
| Vercel (Pro) | 60 seconds |
| AWS ALB | 60 seconds |
| Cloudflare | 100 seconds |
| Nginx | 60 seconds |
| Heroku | 30 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
});