502 vs 503: Bad Gateway vs Service Unavailable

502 and 503 can look similar in logs, but they tell clients, crawlers, and API consumers different things.

Aspect502503
MeaningBad Gateway describes how the server processed the request and what the client should do next.Service Unavailable describes how the server processed the request and what the client should do next.
Typical use caseHTTP 502 Bad Gateway indicates a server errors response outcome.HTTP 503 Service Unavailable indicates a server errors response outcome.
Caching/client behaviorCheck cache headers and downstream behavior for 502.Check cache headers and downstream behavior for 503.
SEO implicationsSearch crawlers interpret 502 according to server-errors semantics.Search crawlers interpret 503 according to server-errors semantics.
API/backend impactAPI clients may branch logic specifically on 502.API clients may branch logic specifically on 503.

When to use one vs the other

Use 502 when the response should communicate bad gateway behavior; use 503 when service unavailable is the accurate protocol signal.

A frequent mistake is swapping 502 and 503 for convenience; that causes client retry bugs, incorrect cache signals, and misleading monitoring data.

Decision summary: if user agents should receive the Bad Gateway signal, return 502; if they should receive Service Unavailable, return 503.

FAQ

What is the biggest difference between 502 and 503?

502 communicates Bad Gateway, while 503 communicates Service Unavailable. Choosing the right one keeps clients and intermediaries predictable.

Do 502 and 503 have SEO or caching impact?

Yes. Search engines and caches interpret status classes differently. Use each code according to its semantics to avoid accidental indexing, stale responses, or crawl inefficiency.

Can APIs safely return 502 instead of 503?

Only when it matches contract semantics. API clients often branch logic by exact code, so swapping them can break retries, auth handling, or user-facing errors.

Related guides: 502 Bad Gateway ยท 503 Service Unavailable

Related comparisons