Autoscaling: automatically matching capacity to demand
Quick answer
Autoscaling automatically adds or removes server instances based on a metric threshold, commonly CPU usage, request rate, or queue length, so the number of running instances roughly tracks real demand. It avoids running enough servers for peak load around the clock, and avoids getting overwhelmed during a spike you didn't provision for.
Provisioning for a fixed number of servers means picking one of two losing trade-offs: size for peak demand and pay for capacity that sits idle most of the time, or size for average demand and risk being overwhelmed the moment traffic spikes. Autoscaling is the general pattern that avoids that choice, by adjusting the number of running instances automatically as demand changes.
The basic mechanism
Autoscaling systems, across virtually every platform that offers them, are built from the same handful of pieces:
- A monitored metric. Something measurable and continuously tracked, most commonly average CPU usage across the instance group, but request rate and queue length (for example, the length of a message queue waiting to be processed) are common too.
- A scaling policy. A threshold that triggers a scaling action (for example, "if average CPU stays above 70% for five minutes, add an instance"), how many instances to add or remove at once, and how quickly the system is allowed to react, to avoid scaling up and down repeatedly in response to short-lived spikes.
- A way to launch ready instances fast. A new instance is only useful once it can actually receive traffic, and that has to happen almost immediately after it launches. That usually rules out a lengthy manual install. In practice it means starting from a pre-built image that already has the application installed, or running an automated first-boot setup script the moment the instance starts. See Cloud-init: automating first-boot setup for your VPS for how that kind of automated setup typically works.
Scaling down matters too
Autoscaling isn't only about adding capacity. The same policy that adds instances when demand rises should also remove them once demand falls, otherwise you're back to paying for idle capacity, just capacity you added yourself instead of provisioning for it up front. A well-tuned policy scales in both directions, usually more cautiously on the way down than on the way up, so a brief lull doesn't remove capacity you're about to need again.
Why autoscaling needs a load balancer
Autoscaling on its own only changes how many instances exist, it doesn't do anything about directing traffic to them. For it to be useful, something has to distribute incoming traffic across whatever number of instances currently happens to be running, and update that distribution as instances are added or removed. That's the job of a load balancer sitting in front of the group. See Understanding load balancing: what it does and how it decides for how that side of the pattern works. The two are usually described together because neither is much use without the other, in an autoscaled setup.
Signs you might be reaching for the wrong tool
Autoscaling solves a specific problem: variable demand across a group of interchangeable instances. It's not always the right fix. If a single server is consistently maxed out rather than experiencing spikes, the answer might simply be a bigger server rather than more of them, see Signs you've outgrown your VPS for that distinction.