Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 4 of 6 · Concept · 15 min · revision 1

Autoscaling signals, limits and warm-up

Choose what an autoscaler should follow, set minimum, maximum and speed limits that protect the rest of the system, and size the headroom that covers the minutes new instances need to warm up.

Contentsand lesson path

What you will learn

  • Make a stateful service horizontally scalable by externalizing session and cache state, and choose an autoscaling signal and limits.

01. Why it matters

An autoscaler is a control loop. At a fixed interval it reads a metric, compares it with a target and changes the number of instances. The Kubernetes HorizontalPodAutoscaler (HPA), the instance groups of cloud providers and most serverless platforms all follow this pattern, with different names for the same knobs. Done well, it lets a stateless tier, like the one you built in the lab, follow demand: more instances at the evening peak, fewer at night, and room for growth nobody forecast.

Three limits are worth stating up front. Autoscaling is slow: new capacity takes from tens of seconds to several minutes to become useful, so on its own it cannot absorb a sudden spike. It is bounded: by your maximum, by provider quotas and by what sits downstream. And it only helps tiers that can scale out; no autoscaler can clone a service that keeps its state in memory. This lesson covers the three decisions you make for every autoscaled tier: the signal it follows, the limits it respects and how it copes with warm-up.

02. Choosing a signal

A good scaling signal rises and falls with load, measures how busy each instance is, reacts within seconds, and is not driven by problems that more instances cannot fix. The usual candidates:

  • CPU utilisation. Simple and available everywhere, and a good fit for CPU-bound stateless tiers. It misleads when work mostly waits on I/O, because such instances fall behind at low CPU, and it is inflated by start-up work and garbage collection.
  • Requests per instance, or requests in flight per instance. This ties directly to lesson 02, with one adjustment. There, 315 requests/s per instance was the plan before adding zone redundancy. To keep that margin, target about two thirds of it, roughly 210/s, so that losing one of three zones pushes the survivors up to about 315/s and no further. By Little's law, requests in flight equal rate times latency, so a concurrency target behaves similarly but also rises when latency does.
  • Work waiting per worker. For consumers of a queue, the backlog divided by the number of workers measures exactly the work that is not getting done.
  • Latency. Tempting, because latency is what users feel, but it is a symptom with many causes. If latency rises because a database slowed down, more instances add load to that database instead of relieving it. Use latency for alerts and as a guard, rather than as the main signal.
  • Schedules and forecasts. If you know when the morning peak or a sale starts, scale ahead of it. Scheduled or predictive scaling complements a reactive signal; it does not replace it.

Many autoscalers size the tier in proportion to the signal. The Kubernetes documentation gives the HPA's rule as desiredReplicas = ceil(currentReplicas × currentMetricValue ÷ desiredMetricValue). With 10 replicas averaging 90% CPU against a 60% target, that is ceil(10 × 90 ÷ 60) = 15. The HPA skips changes within a tolerance, 10% by default, and when several metrics are configured it uses the largest result. A proportional rule only works if the signal really is proportional to the load on each instance, which is one more reason to choose it with care.

03. Limits: minimum, maximum and speed

Every autoscaled tier needs limits, and they are design decisions, not defaults to accept:

  • Minimum. Enough instances to survive the failure you planned for (lesson 02 planned for losing a zone), plus enough warm capacity to carry the first minutes of a spike while new instances start. A minimum of one is rarely right for a production tier.
  • Maximum. Set by budget, by provider quotas (cores, IP addresses, instances per region) and, most often forgotten, by what downstream systems can take. Every new instance brings its own connection pool and its share of calls to dependencies; in lesson 02, 36 pools of 8 connections already exceeded a typical database limit.
  • Speed. Scale out quickly and scale in slowly. Removing capacity too early causes flapping: the tier shrinks, latency rises, the tier grows again. The HPA's default behaviour reflects this: no stabilisation window when scaling up, and a 300-second window when scaling down, in which it acts on the highest recommendation of the last five minutes. Policies can also cap how many instances are added or removed per period.
  • Graceful scale-in. An instance chosen for removal should stop receiving new requests, finish the ones in flight and only then exit. This draining is a load balancer feature, covered in the Load balancing skill; without it, every scale-in becomes a small burst of errors.

04. Lag and warm-up

Between "load went up" and "new capacity is serving" there are several delays. The metric is averaged over a window. The autoscaler acts on an interval (15 seconds by default for the HPA). A machine or container must be scheduled and started. The application must load its configuration, open connection pools and fill caches. Only then does its readiness check pass and the load balancer send it traffic. Depending on the platform and the application, the total runs from under a minute to several minutes.

Warm-up also distorts the signal. A fresh instance often burns CPU on start-up work, such as loading data or compiling code at run time, so its CPU reading says nothing about the traffic it serves, and an autoscaler that counts it may add even more instances. Platforms deal with this in similar ways. The HPA sets aside CPU samples from pods that are not yet ready, using two cluster-wide settings with defaults of 30 seconds and 5 minutes, and its documentation recommends a readiness or startup probe that passes only after the start-up spike. AWS EC2 Auto Scaling has a default instance warmup during which a new instance's metrics are not counted, and suggests 300 seconds as a starting value when you do not know better. The rule behind both: an instance should report ready only when it can do real work at normal cost.

The lag also sets your target. Whatever growth can arrive during the lag must fit into the headroom you keep:

Python · target.py
# Highest average utilisation target that still absorbs the growth in traffic
# that can arrive before new instances are ready (assumes load scales linearly).
for growth in (0.10, 0.25, 0.40, 0.60):
    print(f'traffic +{growth:.0%} in the lag: target at most {1 / (1 + growth):.0%}')
Expected output
traffic +10% in the lag: target at most 91%
traffic +25% in the lag: target at most 80%
traffic +40% in the lag: target at most 71%
traffic +60% in the lag: target at most 62%

If traffic can rise 40% before new instances are ready, a target of about 70% is the highest that avoids overload, and that is before any margin for bursts within the minute. When the answer is uncomfortably low, shorten the lag instead of only lowering the target: keep a warm minimum, scale on a schedule ahead of known peaks, make start-up faster, and warm caches and pools before reporting ready. To watch an HPA scale a deployment on CPU, work through the autoscaling step of the Kubernetes rollouts lab.

05. Check your understanding

Practice check · 3 questions

Signals, limits and lag

Three autoscaling situations.

Q1. An autoscaler targets 60% CPU. Each new instance spends its first 90 s loading a model at full CPU before it can serve, and every scale-out seems to trigger another one. What should you fix first?
Q2. Traffic dips for a few minutes several times an hour. The tier keeps shrinking from 12 instances to 8 and growing back, and latency jumps each time it grows. Which change helps most?
Q3. Traffic can rise 30% in the four minutes a new instance needs to boot and warm up. If CPU grows in proportion to traffic and 100% means overload, what is the highest average CPU target that avoids overload until the new capacity arrives?
Practice only: not graded, not saved, not evidence.

06. Apply it

Write a one-page autoscaling policy for the cart service from the lab of this skill, or for a tier you run. Include the signal and its target, with the measurement behind the target; the minimum and the maximum, each with its reason (failure plan, budget, quota, downstream limit); how fast it may scale out and in; what "ready" means for a new instance; and what you will alert on, such as "running at maximum for 15 minutes". Then describe a test that proves it works, for example a load ramp that you can repeat, and what you expect to see.

07. Review prompt

Without looking back: list four possible scaling signals and one situation in which each misleads; explain why the maximum instance count depends on downstream systems; explain why tiers usually scale out fast and in slowly; name the delays that make up autoscaling lag; and calculate the highest utilisation target when traffic can grow 50% during that lag.

References

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

8 questions · about 6 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check