Module 4 / When one server isn't enough / Health checks and failover

Lesson9 minModule 4 · lesson 5 of 9

Health checks and failover

How the balancer notices a dead server and stops sending it traffic.

Servers fail: a process crashes, a disk fills, a deploy goes wrong, a whole machine disappears. A load balancer that keeps sending requests to a dead server turns a small problem into user-visible errors for roughly one in N requests. So balancers run health checks: regular probes that decide which servers are fit to receive traffic.

Active health checks send a probe on a schedule, for example GET /health every 5 seconds with a 2-second timeout. After a number of consecutive failures (say 3) the server is marked unhealthy and removed from rotation; after a number of consecutive successes it comes back. Passive checks watch real traffic instead: if a server returns errors or times out repeatedly, it is ejected. Using both is common: active probes find dead servers quickly when traffic is low, passive ones react to real failures.

Load balancerServer 1 (healthy)Server 2 (failing)Server 3 (healthy)probe okprobe failsprobe ok
The balancer probes each server and routes only to healthy ones.

Timeline of a failure

Step 1 of 4

T+0 s: server 2 crashes

The next requests sent to it fail. 1 in 3 users see errors.

Failover is the wider idea: when something fails, traffic moves to a standby or to the survivors. For stateless servers it is automatic. For the balancer itself you run a pair or a managed multi-node service. For retries to be safe, requests that may be repeated (like placing an order) should be idempotent, which means a duplicate has the same effect as the original, usually enforced with an idempotency key. Also use connection draining on deploys: stop sending new requests to a server and let in-flight ones finish before stopping it.

Question 1

Probes run every 5 seconds and a server is marked down after 3 consecutive failures. About how long can a dead server keep receiving traffic?

Question 2

Three servers each run at 70 percent load and one fails. What load do the other two face?

Your turn

Design a /health endpoint for an order service that depends on a database and a cache. What does it check, and what does it do if the cache is down?

Stuck? Avoid removing every server because of a shared dependency.

What to remember

  1. Health checks let the balancer stop routing to failed servers; active probes and passive error tracking complement each other.

  2. Detection takes interval × failure threshold, so some requests may fail before removal.

  3. Survivors need spare capacity to absorb a failed server's share.

  4. Use idempotent requests, careful health endpoints and connection draining.