Autoscaling
Add and remove capacity automatically, and design for the minutes it takes to react.
15 min readWhat autoscaling does
An autoscaler watches a metric and adjusts instance count to keep it near a target, for example keeping average CPU at 60%. It saves money at night and adds capacity for daily peaks. Target tracking is the usual policy: if 10 instances run at 90% CPU against a 60% target, the autoscaler aims for about 10 x 90 / 60 = 15 instances. Scale stateless tiers this way; stateful tiers such as databases scale far more slowly and usually need planned capacity.
Pick the right signal
CPU is a fine signal for compute-bound services but misleading for others. A service waiting on I/O can be overloaded at 30% CPU. The best metric is the one that rises before users feel pain and falls when you add instances.
- Request rate per instance: good for web tiers with predictable per-request cost
- Queue depth or age of the oldest message: best for workers
- Concurrency or p99 latency: catches I/O-bound overload that CPU misses
The reaction gap
Scaling is not instant. Metrics are aggregated over a minute or more, the new VM or container must boot, pull an image, warm caches and pass readiness checks. Two to ten minutes from spike to useful capacity is typical. A spike that doubles traffic in 30 seconds is over or has already caused an outage before new instances arrive. Cover the gap with headroom, load shedding and queues, and use scheduled or predictive scaling for known events such as a 9 am rush or a product launch.
Scaling safely
Scale out fast and scale in slowly, with cooldowns, so the fleet does not oscillate. Set a minimum that survives losing a zone and a maximum that protects downstream databases and your budget: autoscaling the API to 500 instances can open 500 connection pools against a database sized for 100. Watch for feedback loops too: a retry storm looks like real demand, and scaling up to meet it can make the dependency's overload worse.
Key takeaways
- Target tracking adjusts instance count in proportion to how far the metric is from target
- Scale workers on queue depth and I/O-bound services on concurrency or latency, not CPU alone
- Autoscaling takes minutes; headroom and load shedding must cover the gap
- Set minimums for zone loss and maximums that protect downstream capacity
Sign in to track lessons and earn badges.