504 Gateway Timeout: what it means and what to do
A 504 means a middleman waited and the real server never answered. The official definition in RFC 9110 is that the server, acting as a gateway or proxy, did not receive a timely response from the upstream server it needed to complete the request. Your request arrived fine and the front door answered fine; the kitchen simply never called back. Long-running reports, overloaded backends, and slow database queries hiding behind a healthy-looking website are the classic setup.
If you are just visiting a site
- Wait a few minutes and retry. Most 504s are a backend having a slow moment, a heavy report, a restart, a traffic surge. They clear when the load does.
- Retry gently. If the action itself is heavy, like generating a report or exporting data, repeated rapid retries pile identical heavy work onto a struggling backend.
- Check whether the whole service is affected via its status page. A widespread incident means waiting is the entire fix.
- If only one heavy action fails while the rest of the site flies, that action is timing out specifically. Smaller date ranges or fewer items often get it under the wire.
If it is your site
- Identify the slow upstream call. The gateway log shows which upstream and how long it waited. The application and database logs for that window show what it was doing instead of answering.
- Hunt the slow query. The single most common root cause is a database query or external API call that degraded over time as data grew. Profile the exact request, not the homepage.
- Raise timeouts only after fixing the cause. A longer gateway timeout converts 504s into very slow successes, which may be better or may just let slow requests accumulate until the pool drains.
- Move heavy work off the request path. Reports and exports that take minutes belong in a background job with a status page, not inside a web request racing a 60 second clock.
Visitors: no setting on your device causes or cures a 504. Owners: the timeout value is a symptom threshold, the slow upstream work is the disease.
Common questions
What is the difference between 502 and 504? Both involve a gateway and an upstream server. A 502 means the upstream answered, but with something invalid or by dying mid-response. A 504 means the upstream never answered within the time limit at all. One is a bad reply, the other is silence.
How long is the timeout behind a 504? Whatever the gateway is configured with, commonly 30 to 120 seconds depending on the platform and plan. There is no universal value, which is why the same slow page can fail on one host and barely succeed on another.
Related errors