500·502·503 — server-side errors

See the difference between 500, 502 and 503 as animated request→response flows. App crash vs gateway failure vs overload, plus what Retry-After means.

Scenario

Speed
500 — APP ERROR502 — BAD GATEWAY503 — OVERLOADBrowserServer1GET /api/orders2500 Internal Server ErrorAll 5xx codes mean 'your request was fine, the server failed'. Nothing the client can fix — a retry might work, or might not.4GET /api/orders5502 Bad GatewayClient→proxy is healthy but proxy→upstream is broken. Usual causes: the app server is down, a wrong port, or a failed health check — unlike 500, it's a middle-layer problem.7GET /api/orders8503 Service UnavailableRetry-After: 30503's point is 'temporary'. Respect Retry-After and retry later. 500/502/503 share 'not the client's fault', but the cause and retry semantics differ.

Requests

3

Current step 9/9

503's point is 'temporary'. Respect Retry-After and retry later. 500/502/503 share 'not the client's fault', but the cause and retry semantics differ.

Request2xx success3xx redirect/cache4xx client error5xx server error

Arrow color = status class. The key redirect pair: 301 is 'permanent', 307 'keeps the method'. Notice how cheap the second request is when the cache validates (304).

All status codes

1xx Informational

100Continue'Go ahead' before a large body — the answer to Expect: 100-continue
101Switching ProtocolsProtocol switch approved — WebSocket upgrade is the classic case
103Early HintsHeaders sent before the final response — for Link preload hints

2xx Success

200OKThe standard success response
201CreatedA new resource was created — successful POST/PUT
202AcceptedAccepted but not processed yet — async work queued
204No ContentSuccess with nothing to return — common after DELETE
206Partial ContentOnly part of the resource — Range requests, video seeking, resumed downloads

3xx Redirection

300Multiple ChoicesMultiple choices to pick from — rarely used today
301Moved PermanentlyPermanent move — remembered by browsers/search engines, SEO transfers▶ Animate
302FoundTemporary move — original URL keeps its index; POST becomes GET by convention▶ Animate
303See Other'Go GET a different URL' — the standard for redirecting after POST (PRG)▶ Animate
304Not ModifiedCache validation passed — 'use your copy', no body sent▶ Animate
305Use ProxydeprecatedForced proxy use — deprecated over security concerns
307Temporary RedirectTemporary move, method/body preserved — the precise 302▶ Animate
308Permanent RedirectPermanent move, method/body preserved — the precise 301▶ Animate

4xx Client error

400Bad RequestThe request itself is malformed — bad syntax, broken parameters
401UnauthorizedNot authenticated — credentials needed; WWW-Authenticate hints the scheme▶ Animate
402Payment RequiredPayment required — reserved, with almost no standard use
403ForbiddenAuthenticated but not allowed — retrying changes nothing▶ Animate
404Not FoundNot here right now — the most famous code▶ Animate
405Method Not AllowedRight URL, wrong method — the Allow header lists what works
406Not AcceptableCan't produce a format you Accept — content negotiation failed
407Proxy Authentication RequiredProxy authentication needed — corporate proxy environments
408Request TimeoutThe server timed out waiting for the request
409ConflictConflicts with current state — concurrent edits, version mismatch
410GoneExplicitly deleted forever — deindexes faster than 404▶ Animate
411Length RequiredContent-Length is required and missing
412Precondition FailedA precondition like If-Match didn't hold
413Content Too LargeRequest body too large — upload size limit
414URI Too LongRequest URI too long
415Unsupported Media TypeContent-Type not supported
416Range Not SatisfiableRequested Range falls outside the resource
417Expectation FailedCan't satisfy the Expect header
418I'm a teapot'I'm a teapot' — 1998 April Fools' joke; some sites reuse it for rate limiting
422Unprocessable ContentWell-formed but semantically wrong — the standard for validation failures
425Too EarlyReplay risk — rejects 0-RTT early data
426Upgrade RequiredProtocol upgrade required — Upgrade header says to what
428Precondition RequiredConditional requests required — forces If-Match against lost updates
429Too Many RequestsToo many requests — rate limiting; pairs with Retry-After
431Request Header Fields Too LargeRequest headers too large — bloated cookies are the usual cause
451Unavailable For Legal ReasonsBlocked for legal reasons — censorship, DMCA; named after Fahrenheit 451

5xx Server error

500Internal Server ErrorServer code error — the most common 5xx▶ Animate
501Not ImplementedNot implemented — the server doesn't support that method/feature
502Bad GatewayGateway couldn't reach the upstream — a middle-layer problem▶ Animate
503Service UnavailableTemporarily unavailable — overload or maintenance; pairs with Retry-After▶ Animate
504Gateway TimeoutUpstream didn't respond in time — slow queries, timeout misconfig
505HTTP Version Not SupportedThe requested HTTP version isn't supported
507Insufficient StorageServer out of storage — WebDAV
508Loop DetectedInfinite loop detected — WebDAV circular references
511Network Authentication RequiredNetwork auth required — captive portals (Wi-Fi login pages)

All 5xx codes mean 'your request was fine — the server failed'. That's the mirror image of 4xx ('you sent it wrong'), which is why a client receiving 5xx can meaningfully retry, and why servers should be alarming on them.

The three codes differ in where the failure sits. 500 is the app code itself blowing up — an unhandled exception, the classic 'generic error'. 502 means a proxy or gateway (nginx, Cloudflare, a load balancer) failed to talk to the upstream app server — the middle layer broke, not your request. 503 means the server is alive but 'can't take it right now' — overload or maintenance.

Retry semantics differ too. 500 probably fails again until the code is fixed; 502 clears the moment the upstream recovers; 503 may even tell you when to come back via the Retry-After header. Under traffic spikes, 503 + Retry-After is the standard valve that stops clients from stampeding a struggling server. HTTP Status Playground

Frequently asked questions

502 Bad Gateway keeps appearing — where do I look?
Start with the app server behind the proxy. For nginx: is the `proxy_pass` target alive, the port right, the app log clean? For Cloudflare→origin setups, a firewall blocking Cloudflare's IPs is a classic cause.
When should I retry after a 503 without Retry-After?
Exponential backoff — 1s, 2s, 4s, with a cap. Retrying immediately during an overload makes it worse. Adding random jitter prevents a thundering herd of simultaneous retries.
How is 504 different from 502?
502 means the upstream communication itself failed — connection refused, garbled response. 504 means the upstream connected but didn't answer in time — slow queries, misconfigured timeouts. Both are emitted by the proxy layer, so investigate infrastructure, not the client.

Other scenarios

Related tools