Exercise 2: 502 vs. 504 — Possible Solution ==================================================================== 502 BAD GATEWAY ------------------------------ Per this chapter, 502 means "a reverse proxy or gateway received an invalid or malformed response from the backend it forwarded the request to - the proxy itself is fine; its upstream isn't." The backend DID respond - the response it sent back was simply invalid or malformed in some way the proxy couldn't accept. 504 GATEWAY TIMEOUT ------------------------------ Per this chapter, 504 means "a reverse proxy or gateway's upstream never responded within the allowed time - distinct from 502, where the upstream did respond, just invalidly." The backend did NOT respond at all within the time the proxy was willing to wait. WHAT EACH TELLS YOU ABOUT WHERE THE FAILURE HAPPENED ------------------------------ Both point to the same general location - the connection between the proxy/gateway and its own backend, not the connection between the client and the proxy (which worked, since a response was received at all). But they differ in what state the backend was in: 502 implies the backend was reachable and processing but produced a broken response (perhaps a crash mid-response, or a protocol mismatch); 504 implies the backend was either unreachable, overloaded, or simply too slow to answer in time. WHY THIS WORKS AS AN ANSWER ------------------------------ It states the specific chapter definition of each code accurately, and explains the concrete difference between "backend responded, but invalidly" (502) and "backend never responded in time" (504) rather than treating both as interchangeable "gateway problem" codes.