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 Elastic Load Balancing: ALB and NLB

๐Ÿ›ฌ Elastic Load Balancing: ALB and NLB: cheat sheet

๐ŸŽจ The analogyAn airport arrivals hall: a guide reads tickets and walks people to gates, or a turnstile waves them through.
๐ŸŽ“ The regular explanationAWS's managed load balancers. Listeners accept connections, rules pick a target group, and health checks keep traffic on healthy targets; the Application Load Balancer routes HTTP by path, host and header, while the Network Load Balancer forwards TCP, UDP and TLS with static IPs and the client's own address.
Listener, rules and target groupsStep 4 of 4
๐Ÿ›ฌ Arrivals hall๐Ÿ›ซ Gate A๐Ÿ›ซ Gate B๐ŸงณPassenger๐ŸšชDoor 443๐Ÿง‘โ€โœˆ๏ธGuidedefault โ†’ B๐Ÿง‘โ€๐Ÿ’ผDesk A1๐Ÿง‘โ€๐Ÿ’ผDesk A2๐Ÿ‘ฉโ€๐Ÿ’ผDesk B1๐Ÿ‘ฉโ€๐Ÿ’ผDesk B2
  1. A passenger walks into the arrivals hall through door 443 and hands over their ticket.
  2. The guide reads the ticket. The first line on the card that fits says "shop tickets go to gate A", so the guide walks the passenger to desk A1.
  3. Desk A1 gives its answer to the guide, and the guide brings it back out through the door to the passenger.
  4. The next ticket fits no line on the card, so the guide follows the last line, "everyone else to gate B", and picks a desk there.
ALB rules and TLS terminationStep 5 of 5
๐ŸงณPassenger๐Ÿชช Official badge๐Ÿง‘โ€โœˆ๏ธGuideopened here๐Ÿ›๏ธShop gate๐Ÿง‘โ€๐Ÿ”งStaff gate๐ŸงชTrial gate๐Ÿ›Ž๏ธBell for a helper
  1. The ticket arrives sealed. The guide shows the official badge, so the passenger trusts them, and the guide opens the envelope.
  2. This ticket is for the shop, so the guide sends the passenger to the shop gate, and the answer comes back the same way.
  3. This ticket was issued by the airline to its own staff, so the card sends it to the staff gate.
  4. This ticket carries a "trial" stamp, so the guide sends it to the new gate being tried out.
  5. This one needs a gate with no desk. The guide rings the bell, a helper appears, deals with the passenger and goes away again.
An NLB passes connections throughStep 4 of 4
๐Ÿข Wing A๐Ÿข Wing B๐ŸงณPassengerโœ• โœ•๐Ÿ’ซTurnstile, wing Afixed .10๐ŸšงTurnstile, wing Bfixed .20โœ• โœ•๐Ÿ’ซDesk Asees real sender๐Ÿง‘โ€๐Ÿ’ผDesk B
  1. Each wing's turnstile has a fixed spot on the airport map. A passenger heads for the one in wing A.
  2. The turnstile doesn't read the ticket. It sends the passenger straight on to desk A, and the desk sees the passenger's own face.
  3. The desk's answer goes back through the same turnstile to the passenger.
  4. Wing A loses power. The map stops pointing passengers there, so they use the turnstile in wing B instead.
Health checksStep 4 of 4
๐Ÿ›ซ Gate๐ŸงณPassengers๐Ÿง‘โ€โœˆ๏ธGuide and supervisor๐Ÿง‘โ€๐Ÿ’ผDesk 1๐Ÿง‘โ€๐Ÿ’ผDesk 2healthy๐Ÿง‘โ€๐Ÿ’ผDesk 3
  1. The supervisor walks past every desk and asks "are you open?". All three answer yes.
  2. Desk 2's computer freezes. When the supervisor asks, there's no answer. One miss isn't enough to close it yet.
  3. A second miss, so desk 2 gets a "closed" sign. The guide now sends passengers only to desks 1 and 3.
  4. Desk 2 is fixed and starts answering. After five answers in a row the sign comes down and passengers arrive again.
Cross-zone load balancingStep 3 of 3
๐Ÿข Wing A๐Ÿข Wing B๐ŸงณPassengers๐ŸšงTurnstile, wing Across-zone on๐Ÿง‘โ€๐Ÿ’ผDesk A125%๐ŸšงTurnstile, wing Bcross-zone on๐Ÿ‘ฉโ€๐Ÿ’ผDesk B1๐Ÿ‘ฉโ€๐Ÿ’ผDesk B225% each๐Ÿ‘ฉโ€๐Ÿ’ผDesk B3
  1. Passengers are split evenly between the two wings. Wing A's turnstile only uses its own desk, so desk A1 gets half of everyone.
  2. Wing B's turnstile shares its half between its three desks, so each of them gets only a sixth.
  3. Now the turnstiles may send passengers to desks in either wing. Every desk gets the same share, a quarter each.
Deregistration delay in a deployStep 4 of 4
๐Ÿ›ซ Gate๐ŸงณPassengers๐Ÿง‘โ€โœˆ๏ธGuide๐Ÿ‘ฉโ€๐Ÿ’ผNew deskhealthy
  1. Before the swap, every passenger at this gate goes to the old desk.
  2. A new desk opens next to it. The supervisor checks it answers before the guide sends anyone there.
  3. The old desk gets a "no new passengers" sign. Newcomers go to the new desk, while the old one finishes the passenger already in front of it.
  4. The old desk has no one left, so it closes for good. Nobody was turned away during the swap.
An NLB in front of an ALBStep 4 of 4
๐ŸงณPartner airline passenger๐ŸšงTurnstilefixed spot๐Ÿง‘โ€โœˆ๏ธGuideopened here๐Ÿ›๏ธShop gate๐Ÿ›ซMain gate
  1. The partner's passenger heads for the turnstile's fixed spot, the one the partner wrote down once.
  2. The turnstile doesn't open the ticket. It sends the passenger straight on to the guide.
  3. The guide reads the ticket, sees it's for the shop, and walks the passenger to the shop gate.
  4. The answer goes back through the guide and the turnstile to the passenger.

๐Ÿงฉ Key questions

You want shop tickets to go to one gate and staff tickets to another, sorted by what's written on each ticket. Who can do that?
The guide, who reads every ticket and follows the card. The turnstile never opens the envelope, so it can't see what the ticket says. Only the guide can.
A partner airline will only let passengers through from spots on the map it has written down once and for all. What do you give it?
The turnstiles' fixed spots, one in each wing. Each turnstile has a fixed spot that never moves. The guide's spot shifts as the hall grows, and desks come and go.
A desk's computer freezes and it stops answering the supervisor. What happens to passengers?
After two missed answers it gets a closed sign and passengers go to the other desks. The supervisor keeps checking, and the desk reopens after five answers in a row.
Wing A has one desk and wing B has three, and the turnstiles only use desks in their own wing. Which desk is busiest?
Desk A1, which gets half of all passengers. Passengers are split evenly between the wings, not between desks. Letting turnstiles use any wing's desks fixes it.
You swap an old desk for a new one. How do you avoid sending away passengers who are halfway through?
Put up a no-new-passengers sign and let the old desk finish, within a time limit. The waiting time lets the people already at the desk finish, while everyone new goes to the new desk.