504 Gateway Timeout Explained: When Servers Get Stuck Communicating
- RFC 9110
This is a reference to the document that defines the current standard for HTTP. It specifies the meaning and usage of the 504 code among others. - 504 Gateway Timeout
This specific code belongs to the 5xx class of codes, which indicates server-side errors. A 504 error means a server acting as an intermediary (gateway or proxy) didn't receive a timely response from another server it was relying on to fulfill the original client request. - HTTP Status Codes
These are codes used to indicate the outcome of a communication between a client (like your web browser) and a server (like a web server).
While the user sees the 504 error, the problem lies in the communication between servers. There isn't specific programming code that generates a 504 error on the server itself; it's a result of a timeout mechanism.
4xx Client Errors
These indicate issues with the request itself, often due to user errors. They aren't directly related to 504, but can be helpful for troubleshooting:- 404 Not Found
The requested resource couldn't be found on the server.
- 404 Not Found
5xx Server Errors
These all indicate errors originating from the server-side. Examples include:- 500 Internal Server Error
A generic error message indicating the server encountered an unexpected issue and couldn't complete the request. - 502 Bad Gateway
Similar to 504, but occurs when a bad response is received from the upstream server. - 503 Service Unavailable
The server is currently unavailable due to maintenance or overload.
- 500 Internal Server Error
- 503 Service Unavailable
If the timeout resulted from the upstream server being overloaded or under maintenance, this code might be a better choice. - 502 Bad Gateway
This code can be used if the upstream server sent a bad or unexpected response that caused the timeout. It provides a slightly more detailed picture of the issue.
Here are some other options depending on the cause of the timeout:
- Custom Error Messages
While not technically a status code, some servers might provide custom error messages with the 504 response that offer more specific information about the cause of the timeout. - Retry After
This header can be included with the 504 response to suggest a time for the client to retry the request.