Interview questions and model answers
"Explain 502 vs 503 vs 504."
All three usually come from a proxy or load balancer. 502 means it got an invalid response or the upstream closed the connection — crashed app, wrong port, keep-alive race. 503 means it couldn't serve the request at all — typically no healthy targets, overload or maintenance. 504 means the upstream didn't respond within the proxy's timeout — slow backend or misaligned timeouts. My first step is identifying which layer generated it, for example ELB vs target 5xx metrics on an ALB.
"Users get 504 after exactly 60 seconds through an ALB. Why?"
The ALB's idle timeout defaults to 60 seconds, so requests whose backend takes longer are cut off with a 504. I'd find out why the request is slow; if it's legitimately long — like report generation — make it asynchronous with a 202 and a job status endpoint. If I must raise the idle timeout, I'd align nginx, app and client timeouts too.
"Intermittent 502s behind an ALB with 'target closed connection'. Fix?"
That's the keep-alive race: the app closes idle connections before the ALB's 60-second idle timeout, and the ALB reuses one just as it closes. Set the app server's keep-alive timeout longer than the ALB idle timeout — for example 65 to 75 seconds — which matters especially for Node.js with its 5-second default.
"401 vs 403?"
401 means unauthenticated — the credentials are missing or invalid, so authenticating may fix it. 403 means the identity is known but not permitted, so only a permission change helps. For sensitive resources, returning 404 instead of 403 avoids revealing they exist.
"You see 502s spiking right after a deploy. What do you do?"
Check whether they're ELB- or target-generated, whether new pods are crashing or not ready, target group health, and app logs for the failing request IDs. If the errors line up with the release and persist, roll back immediately — revert the GitOps commit or abort the canary — then investigate. Prevention: canary analysis on error rate, readiness gates and preStop delays.
"Should clients retry on 500?"
Only when the request is idempotent or protected by an idempotency key, with exponential backoff, jitter and a cap. 502, 503, 504 and 429 are typical transient retry candidates; 4xx errors like 400, 401, 403 and 404 shouldn't be retried. And retries at several layers multiply load, so they need a budget.
"Why are 4xx errors often excluded from SLOs?"
Because most are client mistakes — bad input, missing auth — that don't reflect service reliability, and a misbehaving client could otherwise consume the error budget. I'd still alert on unusual 4xx spikes, especially 429s from our own throttling and 401/403 surges after deploys.
"What does a 499 in Nginx logs mean?"
The client closed the connection before Nginx sent a response — usually because the client timed out waiting. Rising 499s point to slow upstreams, and often appear alongside 504s at other layers.