How it works · 6 of 38 Core
How do load balancing and autoscaling work?
More counters when the queue grows
Load balancing & autoscaling: A load balancer spreads incoming requests across identical servers and stops sending work to any that fail; autoscaling adds servers when they get busy and removes them when it's quiet, but a new server takes minutes to be ready, so a sudden crowd can outrun it.
Loading the animation…
Say it like this A load balancer spreads requests over identical servers and skips broken ones; autoscaling adds servers when they get busy, but they take minutes to arrive, so for a crowd you can see coming, scale up before it lands.
Under the hood — for builders
- How the balancer picks
- Round robin: each server in turn (the default in AWS's Application Load Balancer). Least outstanding requests: the server with the fewest unfinished requests, better when some requests are slow. A health check (a test request every few seconds) takes failing servers out of the rotation.
- Why help arrives late
- A new server must be launched, boot its operating system, start the app and pass its health checks before it gets any traffic. Simple scaling then waits a cooldown before acting again.
- Four ways to decide
- Target tracking: keep average busy-ness near a number, like a thermostat. Step: add more servers the further past the line. Scheduled: at set times (the IPL final). Predictive: from last weeks' daily and weekly pattern.
- The stage's trade-off, as numbers
- The evening on stage, run for each trigger. One step is 2.5 minutes; each trigger adds one server, ready 5 minutes later.
- Watch out
- More web servers don't make one database faster: it often becomes the queue. Scaling in must let a server finish its open requests first (connection draining). Login state kept on one server breaks when the balancer sends you elsewhere.
- Measure it
- Requests per server, slowest 1% of response times (p99), share of errors, and how long a new server takes to take traffic.
- Sources
- AWS EC2 Auto Scaling user guide (cooldowns, warm-up, scheduled and predictive scaling) · AWS Application Load Balancer guide (routing algorithms, health checks) · JioCinema, IPL 2023 final (3.21 crore peak concurrent viewers).
What happens in the load balancing & autoscaling animation, step by step?
- One server takes every order. As the crowd grows, its gauge climbs towards full.
- A load balancer hands each request to a server with room, and stops sending work to one that fails.
- Autoscaling adds a server when the gauge passes a line. But each new one takes minutes to be ready, so a sudden crowd outruns it.
- Your turn: drag the line. Scale early and you pay for idle servers; scale late and you turn people away.
- For a crowd you can see coming, don't wait for the gauge: add servers beforehand. JioCinema's 2023 IPL final peaked at 3.21 crore viewers at once.
- Your servers now take the orders. But to charge a card they must ask the bank's programs. How do programs ask each other? Next: APIs.
What everyday example explains load balancing & autoscaling?
A railway booking hall. A floor manager waves each person to a free counter (load balancer) and phones for more clerks when the queue passes a line painted on the floor (autoscaling); clerks called from home take a while to arrive, so on festival days the manager calls them in the night before (scheduled scaling).
Why should a team care about load balancing & autoscaling?
You will choose when to scale, by how much, and whether to pre-scale for a known event; get it wrong one way and the bill doubles, the other way and the busiest hour of the year fails.