Noticing a server that died
After this: Follow nine requests past a crashed server, find the one that fails, and say how health checks shorten the gap.
On this page · 4 sections · 3 checks
Lesson 1 added a spare server in case one dies. Servers do die: a power supply fails, a bug crashes the program, or someone restarts the wrong machine. But round robin from lesson 2 only follows its order. If B is dead, B still gets every third request. How does the load balancer find out?
Asking "are you alive?"
The load balancer can ask. Every so often it sends each server a tiny request, such as "are you alive?", and waits for an answer. This is a . A server that answers stays in the order. A server that does not answer is taken : round robin skips it, and its turns go to the others.
Nine requests, one crash
Three servers, A, B and C. A health check runs after requests 3, 6 and 9. Server B crashes right before request 4. Follow the requests:
- Requests 1, 2 and 3 go to A, B and C. The check after request 3 finds every server alive.
- B crashes. Nothing tells the load balancer, so B stays in the order.
- Request 4 goes to A. Request 5 is B's turn: it goes to B and fails. Request 6 goes to C.
- The check after request 6 gets no answer from B, so the load balancer takes B out of rotation.
- Requests 7, 8 and 9 go to A, C and A. Round robin skips B.
| request | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|---|---|---|
| server | A | B | C | A | B | C | A | C | A |
| result | ok | ok | ok | ok | failed | ok | ok | ok | ok |
In the end, A served 4, B served 1 and failed 1, and C served 3: 8 requests succeeded and 1 failed.
- Round robin: 9 requestsRun it and step through. Server B crashes before request 4. Find the request that fails, then find the health check that takes B out of rotation.
Press Run it, then step through and watch the requests move.
The gap costs requests
Between the crash and the check that noticed it there is a gap. Every request that reaches B in that gap fails. Here the gap held one of B's turns, request 5.
How often the check runs decides the size of the gap. On the same nine requests:
- With one check, after request 9, the gap holds two of B's turns, requests 5 and 8: 2 fail.
- With a check after every third request, as above, 1 fails.
- Check 3 below asks what happens with a check after every request.
Checking more often means fewer failed requests. The cost is more checks: every server answers every check, all day. Real load balancers run checks on a clock, not after a count of requests. How often depends on the product and its settings: anything from every second or two to every half minute or so. The scenario counts requests so that you can follow each step.
Check yourself
A health check asks Server B whether it is alive, and B does not answer. What does the load balancer do?
Same nine requests and the same checks after requests 3, 6 and 9, but this time Server C crashes right before request 4, not B. Which request fails?
Back to the lesson's run: B crashes right before request 4. Now the check runs after every request instead of every third. How many of the nine requests fail?
- Say what a health check is: a small request the load balancer sends to each server, over and over, to find out whether it still answers.
- Say that a server that does not answer is taken out of rotation, and round robin skips it from then on.
- Follow the nine requests: B crashes before request 4, request 5 fails, the check after request 6 takes B out, and 8 succeed while 1 fails.
- Say that checking more often shortens the gap and costs fewer failed requests, and that real systems usually wait for two or three failed checks in a row.