๐ก Load balancing: cheat sheet
๐จ The analogyA theme-park host sending each family to the ride with the shortest queue, skipping rides that are broken.
๐ The regular explanationSpreading requests across several identical servers, skipping unhealthy ones, and finding new ones automatically through service discovery, all behind one address.
- Every family arrives at the same gate. They don't need to know how many identical rides there are.
- The host sends the first family to ride A, the next to ride B, the next to ride C, then starts again.
- Ride A has a slow group, so its queue is long. A clever host sends the next family to the shortest queue instead.
- Every few seconds, the host radios each ride, "all OK?", and each replies "yes".
- Ride B breaks down. It stops answering the radio.
- After a couple of missed calls, the host stops sending families there. Nobody ends up queuing at a broken ride.
- Once ride B is fixed and answers the radio again, the host starts sending families back to it.
- The host doesn't memorise the rides. There's a board listing which rides are open and where.
- It's a busy day, so a new ride opens. It writes itself on the board.
- The host checks the board, spots ride C, and starts sending families there. No one had to tell the host anything.
- All three rides answer the radio with "yes", and families are happily sent to each of them.
- Ride B starts jerking and stopping. Still, when the host radios, it cheerfully says "yes".
- The host keeps sending families to ride B, and they climb off upset. The host has no idea yet.
- After several unhappy families in a row, the host pulls the rope across ride B, even though its radio still says yes.
- Ride B stays roped off for a while, then the host lets families back on; if they come back upset again, it stays roped off for longer.
๐งฉ Key questions
- What does the simplest host do at the gate?
- Sends families to rides in turn: A, B, C, A, B, C. A smarter host looks at the queues and picks the shortest.
- A ride stops answering the host's "all OK?" radio. What happens?
- It's skipped until it's fixed. No family ends up queuing at a broken ride.
- On busy days rides open and close. How does the host keep track?
- Every ride writes itself on a board when it opens, and the host reads the board. Nobody has to memorise anything.
- Ride B answers the host's radio with "yes" but jerks and stops, and families come back upset. What should the host do?
- Rope off the ride after several unhappy families in a row. The radio only proves the ride is switched on. The families' experience shows it is broken.