TwiceToldby Develoker
ConceptsSystem designLabsCheat sheetsAbout

Develoker makes free tools for learning to build software. TwiceTold explains each idea twice, as an everyday analogy and the real thing; CloudArch lets you design cloud systems and put load on them.

About ยท Labs ยท Cheat sheets ยท Learning paths

โ† Back to Load balancing

๐ŸŽก 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.
Spreading the crowdStep 3 of 3
๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งFamily 1๐Ÿ‘ฉโ€๐Ÿ‘ฆFamily 2๐Ÿ‘จโ€๐Ÿ‘งFamily 3๐Ÿง‘โ€๐Ÿ’ผPark host๐ŸŽ Ride A9 busy๐ŸŽกRide B2 busy๐ŸŽขRide C4 busy
  1. Every family arrives at the same gate. They don't need to know how many identical rides there are.
  2. The host sends the first family to ride A, the next to ride B, the next to ride C, then starts again.
  3. Ride A has a slow group, so its queue is long. A clever host sends the next family to the shortest queue instead.
Skipping a broken rideStep 4 of 4
๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งFamily๐Ÿง‘โ€๐Ÿ’ผPark host๐ŸŽ Ride A๐ŸŽกRide B๐ŸŽขRide C
  1. Every few seconds, the host radios each ride, "all OK?", and each replies "yes".
  2. Ride B breaks down. It stops answering the radio.
  3. After a couple of missed calls, the host stops sending families there. Nobody ends up queuing at a broken ride.
  4. Once ride B is fixed and answers the radio again, the host starts sending families back to it.
New rides openStep 3 of 3
๐Ÿง‘โ€๐Ÿ’ผPark host๐Ÿ“‹ Ride board3 open๐ŸŽ Ride A๐ŸŽกRide B๐ŸŽขNew ride C
  1. The host doesn't memorise the rides. There's a board listing which rides are open and where.
  2. It's a busy day, so a new ride opens. It writes itself on the board.
  3. The host checks the board, spots ride C, and starts sending families there. No one had to tell the host anything.
A broken ride that still says yesStep 5 of 5
๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งFamily๐Ÿง‘โ€๐Ÿ’ผPark host๐ŸŽ Ride Abusier๐ŸŽกRide Bejected๐ŸŽขRide Cbusier
  1. All three rides answer the radio with "yes", and families are happily sent to each of them.
  2. Ride B starts jerking and stopping. Still, when the host radios, it cheerfully says "yes".
  3. The host keeps sending families to ride B, and they climb off upset. The host has no idea yet.
  4. After several unhappy families in a row, the host pulls the rope across ride B, even though its radio still says yes.
  5. 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.