Skip to main content
← PROBLEMS / SYSTEM-DESIGN
An end-to-end domain learning journey

Eliminating 502 Races
in Rolling Deploys.

Resolve intermittent 502 Bad Gateway spikes during 10,000 req/sec rolling deployments.
Start the journey7 stages· Last modified Nov 23, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

To keep the architecture evolvable without sacrificing reliability, coordinate Readiness probes, preStop sleep, and HTTP keep-alive Connection: close headers.

TL;DR30-second simplified summary
▾

Even when apps drain in-flight requests, long-lived HTTP keep-alive connections and async kube-proxy updates cause 502s. Flipping Readiness to 503, sleeping in preStop, and closing keep-alive sockets after active responses eliminates rollout errors.

Full walkthrough · 7 stages
01
foundation

Stage 1: Termination Lifecycle.

Why this matters: Establish termination lifecycle for Eliminating 502 Races in Rolling Deploys.

Think of Stage 1: Termination Lifecycle as the intuition layer for Eliminating 502 Races in Rolling Deploys: Establish termination lifecycle for Eliminating 502 Races in Rolling Deploys.

Stage 1: Termination Lifecycle establishes how Eliminating 502 Races in Rolling Deploys behaves under real production load.

Request & State Flow

Stage 1: Termination Lifecycle

Control PlaneScheduler / IngressWorker NodePod / Container1. Apply desired replica & PDBspec2. Bind pod respecting CPU/memlimits3. Run readiness probe beforetraffic4. Drain in-flight connections onrollout
02
foundation

Stage 2: Async Endpoint Race.

Why this matters: Establish async endpoint race for Eliminating 502 Races in Rolling Deploys.

Think of Stage 2: Async Endpoint Race as the intuition layer for Eliminating 502 Races in Rolling Deploys: Establish async endpoint race for Eliminating 502 Races in Rolling Deploys.

Stage 2: Async Endpoint Race establishes how Eliminating 502 Races in Rolling Deploys behaves under real production load.

Design Trade-Off

Stage 2: Async Endpoint Race

Before · Unbounded Pods & Abrupt Kill
  • 502s during rolling updates
  • ndots:5 DNS flood or OOMKill
  • Unprotected node drains
After · PDB + Probes + Graceful Drain
  • Zero-drop SIGTERM draining
  • Bounded cgroup & conntrack
  • Canary metrics gate rollout
Engineering Decision Framework
Problem
How to implement Eliminating 502 Races in Rolling Deploys without hitting unbounded tail latency, state divergence, or operational fragility.
Naive Solution
Use a single unpartitioned path with unbounded retries and synchronous global coordination.
Why It Fails
Global coordination serializes throughput under load, while unbounded retries amplify transient stalls into full outages.
Alternatives
Compare synchronous strict-consistency paths against bounded asynchronous replication, local caching, or partitioned ownership.
Engineering Decision
To keep the architecture evolvable without sacrificing reliability, coordinate Readiness probes, preStop sleep, and HTTP keep-alive Connection: close headers.
Trade-Offs
Gains predictable p99 latency and fault isolation in exchange for explicit bounding, observability, and slightly higher implementation complexity.
Decision Exercise · Make the Call

When Eliminating 502 Races in Rolling Deploys experiences a sudden 5x traffic spike alongside a slow downstream dependency, which engineering choice best protects system stability?

03
intermediate

Stage 3: Naive SIGTERM.

Why this matters: Establish naive sigterm for Eliminating 502 Races in Rolling Deploys.

Think of Stage 3: Naive SIGTERM as the intuition layer for Eliminating 502 Races in Rolling Deploys: Establish naive sigterm for Eliminating 502 Races in Rolling Deploys.

Stage 3: Naive SIGTERM establishes how Eliminating 502 Races in Rolling Deploys behaves under real production load.

Component Topology

Stage 3: Naive SIGTERM

Ingress / LBingressK8s ControlcomputeWorker NodestorageApp Podscontrolactive trafficreconcileprobe / SIGTERM
04
intermediate

Stage 4: PreStop & Readiness.

Why this matters: Establish prestop & readiness for Eliminating 502 Races in Rolling Deploys.

Think of Stage 4: PreStop & Readiness as the intuition layer for Eliminating 502 Races in Rolling Deploys: Establish prestop & readiness for Eliminating 502 Races in Rolling Deploys.

Stage 4: PreStop & Readiness establishes how Eliminating 502 Races in Rolling Deploys behaves under real production load.

05
intermediate

Stage 5: Keep-Alive Draining.

Why this matters: Establish keep-alive draining for Eliminating 502 Races in Rolling Deploys.

Think of Stage 5: Keep-Alive Draining as the intuition layer for Eliminating 502 Races in Rolling Deploys: Establish keep-alive draining for Eliminating 502 Races in Rolling Deploys.

Stage 5: Keep-Alive Draining establishes how Eliminating 502 Races in Rolling Deploys behaves under real production load.

Lifecycle & Failure Recovery

Stage 5: Keep-Alive Draining

probe passesburst > limitSIGTERM + preStopPending ScheduleReady (Serving)CFS / OOM RiskGraceful Drain
06
advanced

Stage 6: Grace Period Sizing.

Why this matters: Establish grace period sizing for Eliminating 502 Races in Rolling Deploys.

Think of Stage 6: Grace Period Sizing as the intuition layer for Eliminating 502 Races in Rolling Deploys: Establish grace period sizing for Eliminating 502 Races in Rolling Deploys.

Stage 6: Grace Period Sizing establishes how Eliminating 502 Races in Rolling Deploys behaves under real production load.

07
advanced

Stage 7: Rollout Telemetry.

Why this matters: Establish rollout telemetry for Eliminating 502 Races in Rolling Deploys.

Think of Stage 7: Rollout Telemetry as the intuition layer for Eliminating 502 Races in Rolling Deploys: Establish rollout telemetry for Eliminating 502 Races in Rolling Deploys.

Stage 7: Rollout Telemetry establishes how Eliminating 502 Races in Rolling Deploys behaves under real production load.

Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

Why do 502s occur on SIGTERM (Check 1)?

Recommended Learning Flow