As indicated by their name, 504 errors are much more time-related. Simply put, they happen when a user waits for too long to receive a response from another server. Eventually, this results in expiration or timeout. On the other hand, 502 errors are more of a communicational kind.