Bookmarks

Autoscaling

A mechanism that automatically adds and removes compute resources — service replicas, cluster nodes or virtual machines — following the load.

Also: automatic scaling, auto scaling

checked 18 Nov

All terms

Load is rarely even: at night it is several times lower than in the daytime, while promotions and surges produce spikes that are hard to predict in advance. Keeping a standing fleet sized for the peak means paying for idle capacity, and a shortage of resources turns into errors. Autoscaling watches the metrics and changes the number of replicas or nodes so that capacity follows real demand.

How it works

A cycle of four steps is at work: a controller periodically measures a metric, compares it with the target value, decides how many objects are needed, and adds or removes them. The limits are set in advance: a minimum so that the service does not disappear, and a maximum so that the budget is not exceeded.

StepWhat happens
Measurementevery few seconds the controller reads metrics: CPU utilisation, memory, queue length, requests per second per replica
Comparisonthe current value is compared with the target — for example, 60% CPU utilisation per replica; a deviation within the tolerance (10% by default) is ignored
Calculationusing the formula for the desired number of replicas: multiply the current number by the ratio of the measured value to the target and round up
Executionsurplus replicas are removed and missing ones added; a new replica counts only once it is ready to serve traffic

Example: a service keeps CPU utilisation of each replica at about 60%; there are four replicas, and utilisation has risen to 90%. The controller computes 4 × 90 / 60 = 6 and adds two replicas. When traffic subsides and utilisation drops below the target, the surplus replicas will be removed.

Where it is used: Kubernetes and the cloud

In Kubernetes, autoscaling is split into three mechanisms: one changes the number of pods, another the resources of pods, and the third the number of cluster nodes. In the cloud, autoscaling groups play the same role for virtual machines.

MechanismWhat it scalesWhat it decides on
HPA (Horizontal Pod Autoscaler)the number of podsCPU and memory utilisation relative to requests, custom metrics — requests per second, queue length
VPA (Vertical Pod Autoscaler)resource requests and limits of podsactual CPU and memory consumption
Cluster Autoscalerthe number of cluster nodespods that did not fit on the existing nodes, and nodes left idle for long stretches
Groups in the cloud (Auto Scaling group in AWS, Virtual Machine Scale Sets in Azure, MIG in Google Cloud)the number of virtual machinesCPU utilisation, load balancer metrics, schedules, machine health

The mechanisms work together: HPA adds pods when there is no room for them, Cluster Autoscaler adds nodes to run them on, and when load falls it removes the idle ones. Alongside it, Karpenter is being developed — another open source node autoscaler.

What to configure in advance

  • A minimum and a maximum: without them the controller will either burn through the budget or fail to survive a spike.
  • Resource requests on the pods: without them HPA cannot work out utilisation and cannot make a decision.
  • A stabilisation window — a pause between changes so that a brief spike does not make the size jitter; in HPA it defaults to 5 minutes for scaling down.
  • A metric that genuinely correlates with load and updates in time: with a lagging indicator the controller scales only after the spike has passed.
  • Correct readiness probes: a replica may be removed only when it is not serving requests.

Sources

the term is written from these pages

Verified 18 Nov

Not to be confused with

what it is mixed up with and how it differs

  • horizontal and vertical scaling

    Horizontal and vertical scaling determine the direction of growth — more replicas or a more powerful machine; autoscaling determines who does it automatically, and by what rule.

  • serverless architecture

    In serverless, the platform manages scaling and the code scales down to zero; here the team sets the rules, and the minimum is above zero.

In depth in the references

where the topic is covered in detail