Autoscaling is the automatic adjustment of compute capacity to current demand. A controller observes metrics such as CPU utilization, request rate or queue depth and adds or removes instances (horizontal scaling), changes their resources (vertical scaling) or adds nodes to a cluster. The goal is stable performance at the lowest reasonable cost.
What is autoscaling?
Autoscaling means that a system adapts its capacity to the load without manual intervention. Instead of sizing for the busiest hour of the year, you define a target, for example 70 percent average CPU per pod, and a controller adds or removes capacity to keep the actual value close to it. Done well, autoscaling keeps latency stable during peaks and saves money during quiet hours. Done badly, it reacts too late, oscillates or scales on the wrong signal.
Autoscaling does not replace capacity planning. It works within limits such as maximum replicas, cloud quotas and the capacity of shared dependencies like databases, and those limits still need to be planned.
Types of autoscaling
- Horizontal scaling changes the number of instances. In Kubernetes this is the Horizontal Pod Autoscaler (HPA); in the cloud it corresponds to auto scaling groups for virtual machines.
- Vertical scaling changes CPU and memory per instance. The Kubernetes Vertical Pod Autoscaler (VPA) recommends or applies requests based on observed usage.
- Cluster or node autoscaling adds nodes when pods cannot be scheduled and removes underused nodes. Common tools are the Kubernetes Cluster Autoscaler and Karpenter.
- Event-driven scaling scales on external signals such as Kafka consumer lag or the length of a message queue. KEDA, a CNCF project, adds this to Kubernetes and can scale workloads down to zero.
How the Horizontal Pod Autoscaler works
The HPA runs as a control loop, by default every 15 seconds. It compares the current metric value with the target and calculates the desired number of replicas:
desiredReplicas = ceil(currentReplicas * currentMetricValue / desiredMetricValue)
With four pods at 90 percent CPU and a target of 60 percent, the HPA wants ceil(4 * 90 / 60) = 6 pods. A tolerance (10 percent by default) prevents changes for tiny deviations, and a scale-down stabilization window (300 seconds by default) keeps the controller from removing pods right after a short dip. With the autoscaling/v2 API you can scale on resource metrics, custom metrics per pod or external metrics, and define separate behavior policies for scaling up and down.
Utilization-based scaling only works if containers have resource requests, because CPU utilization is measured relative to the request.
Cloud providers offer comparable mechanisms outside Kubernetes: auto scaling groups on AWS, virtual machine scale sets on Azure and managed instance groups on Google Cloud. They scale virtual machines on similar signals and often support scheduled or predictive scaling for known daily patterns. In serverless platforms, scaling is fully managed by the provider and happens per request or per event, which removes the configuration effort but shifts attention to concurrency limits and cold starts.
Choosing the right scaling metric
CPU is the default but not always the best signal. A good scaling metric rises before users notice a problem and falls when load decreases:
- CPU and memory suit compute-bound services. Memory is a poor signal for runtimes that rarely give memory back, such as the JVM.
- Request rate per pod works well for stateless APIs with predictable cost per request.
- Queue depth or consumer lag fits workers that process messages; see saturation.
- Latency is tempting but risky: if a slow database causes it, more replicas only add load to the database.
Common pitfalls
- Slow start-up. If new pods need a minute to become ready, scaling reacts too late for sudden spikes. Readiness checks via readiness probes ensure that pods receive traffic only when ready, but they do not make them start faster; serverless platforms face the same problem as cold starts.
- Flapping. Too aggressive policies scale up and down in quick succession. Stabilization windows and rate limits in
behaviorhelp. - Wrong limits. Tight CPU limits cause CPU throttling, which raises latency without a matching rise in utilization, so the HPA does not react.
- Shared bottlenecks. Scaling the application tier can exhaust database connections or downstream rate limits.
- HPA and VPA on the same metric. Both controllers would work against each other on CPU or memory.
How Obseria helps
With Kubernetes monitoring, Obseria shows replica counts, HPA targets, resource requests and actual usage next to the latency and error rate of each service. You can check whether scaling events kept up with load, spot throttled or overprovisioned workloads and see the cost effect of scaling decisions in cloud cost management.