Distributed systems / Autoscaling

Autoscaling

A group of servers that grows when traffic rises and shrinks when it falls: the metric it watches, the two rules, the cooldown, the limits and the bill.

Intermediate7 steps~7 min
Users — send the traffic
Server — handles requests; the gauge is its CPU
Autoscaler — reads the metric, adds or removes servers
// THE SHORT VERSION

In 30 seconds

Autoscaling changes the number of servers automatically, so there are enough when it is busy and few when it is quiet.

An autoscaler watches a metric, such as average CPU use. Above one threshold it adds servers (scale out); below another it removes them (scale in). After each change it waits a cooldown so the numbers can settle.

A minimum keeps the service alive and a maximum caps the bill. Because servers are billed while they run, following demand costs less than running the peak number all day.

Autoscaling, step by step

STEPS01 / 07

Simplified: CPU is taken to rise in step with traffic, and one server is added at a time. Many autoscalers instead compute the count needed to hit a target value. The $0.10 hourly rate is illustrative.

STEP 01 / 07 Load never stands still
THE MATH
each server: 100 req/s CPU = 72 / (2 × 100) = 36%
  1. Step 1: Load never stands still. A shop runs on two servers, each able to handle about 100 requests a second. At night 72 requests a second arrive, so each server is 36% busy. At noon 330 arrive, more than two servers can serve. A fixed number of servers is either too few at noon or too many at night.
  2. Step 2: Watch a metric. An autoscaler is a control loop that keeps reading one number about the group of servers, here their average CPU use. Two thresholds split the scale into three zones. Traffic has grown to 180 requests a second, both servers sit at 90%, and the reading lands in the zone that says add.
  3. Step 3: Scale out. The scale-out rule fires only after the average has stayed above 70% for three minutes, so a brief spike is ignored. The autoscaler starts one more server and the load balancer shares the same 180 requests among three: each drops to 60%. Adding machines like this is called scaling out.
  4. Step 4: Cooldown. A new server needs a couple of minutes to boot, and until it takes traffic the average still reads 90%. Without a pause the rule would fire again and again and add far too many. So after every change the autoscaler waits out a cooldown, here five minutes, before it acts on the metric again.
  5. Step 5: Scale in. In the evening traffic falls back to 72 requests a second. Three servers now idle at 24% each, below the 30% line, so the scale-in rule removes one. The two that remain rise to 36%. The gap between 30% and 70% matters: it stops a removal from immediately triggering an addition.
  6. Step 6: Minimum and maximum. Two limits fence the rules in. The minimum keeps two servers running however quiet it gets, so one can fail without the site going down. The maximum stops the group at six even if the rule asks for more: it caps the bill when traffic explodes or a bug sends requests in a loop.
  7. Step 7: What it costs. Over the whole day the group follows the traffic: two servers at night, five around noon, 76 server-hours in all. Keeping five running all day to be safe at noon would be 120. At $0.10 an hour that is $7.60 against $12.00. Servers are paid for while they run, so fewer idle hours means a smaller bill.
VALUES SO FAR
capacity100 req/s eachinput
metric····input
out····rule
cooldown····rule
in····rule
min····limit
max····limit
cost····result

Spotted a mistake on this page?