Overview
Auto scaling automatically adjusts the amount of compute to match demand: adding instances when load rises and removing them when it falls. This keeps latency stable during peaks and cuts cost during quiet periods. It applies to VMs (EC2 Auto Scaling groups), containers (HPA, ECS service scaling), serverless (automatic concurrency), and databases (Aurora Serverless, DynamoDB on-demand).
Policies include target tracking (keep CPU at 60%), step scaling (add 3 instances if CPU > 80%), scheduled scaling (scale up before 9 AM), and predictive scaling (forecast from history). Effective auto scaling requires stateless instances, fast startup, good health checks, and awareness of downstream limits.
More agents are scheduled for Monday mornings (scheduled), extra agents are called in when hold times exceed two minutes (target tracking), and staff go home when calls drop.
When to use it
- Traffic that varies by time of day, week, or season.
- Unpredictable spikes (viral content, launches).
- Batch and worker fleets driven by queue depth.
- Reducing cloud costs.
Where it shows up in interviews
Recognize it when: handle 10x peaks.
- Design a ticket booking site for a concert sale
- Design Black Friday readiness
Recognize it when: scale with backlog.
- Design a video processing pipeline
- Design batch report generation
Where it is used in real software
Target tracking, step, scheduled, and predictive policies with health-check-based replacement.
Netflix built predictive auto scaling that pre-scales ahead of daily viewing patterns.
Scales automatically per request up to account and reserved concurrency limits.
Key terms
- Target tracking
- Keep a metric near a target value.
- Cooldown / warm-up
- Wait after scaling before acting again / time before a new instance counts.
- Min / max / desired
- Capacity bounds and current target.
- Predictive scaling
- Forecast demand and scale in advance.
- Scale-in protection
- Prevent specific instances from being terminated.
How it works, step by step
- 1Make instances stateless
Sessions and files in shared services.
- 2Pick the metric
CPU, RPS per target, queue depth, latency.
- 3Set min, max, and target
Min for availability, max to protect downstream and budget.
- 4Tune warm-up and cooldowns
Avoid flapping and overshoot.
- 5Add scheduled or predictive scaling
For known peaks.
Scaling policies
When to use each
| Policy | How it works | Good for |
|---|---|---|
| Target tracking | Keep metric at target | Most services (default) |
| Step scaling | Add or remove by thresholds | Custom, aggressive responses |
| Scheduled | Change capacity at set times | Known peaks (business hours) |
| Predictive | Forecast from history | Regular daily or weekly patterns |
| Queue-based | Workers per backlog | Async workers |
NOWPolicy: Target tracking | How it works: Keep metric at target | Good for: Most services (default)
Combine predictive or scheduled scaling for baselines with target tracking for surprises.
Implementation
resource "aws_autoscaling_group" "api" { name = "api" min_size = 3 max_size = 60 vpc_zone_identifier = aws_subnet.private[*].id target_group_arns = [aws_lb_target_group.api.arn] health_check_type = "ELB" default_instance_warmup = 120 launch_template { id = aws_launch_template.api.id version = "$Latest" }} resource "aws_autoscaling_policy" "requests_per_target" { name = "rps-target" autoscaling_group_name = aws_autoscaling_group.api.name policy_type = "TargetTrackingScaling" target_tracking_configuration { predefined_metric_specification { predefined_metric_type = "ALBRequestCountPerTarget" resource_label = "${aws_lb.api.arn_suffix}/${aws_lb_target_group.api.arn_suffix}" } target_value = 800 }}Complexity and performance
Boot + app start.
If nodes available.
Trade-offs
Aggressive policies respond quickly but can oscillate; conservative ones are stable but may lag spikes.
Keeping a higher minimum wastes money but absorbs sudden spikes before new capacity arrives.
Variants and related techniques
Per-request scaling with concurrency limits.
Aurora replicas, DynamoDB capacity, storage growth.
Common mistakes
- Scaling beyond downstream capacity.
Fix: Set max limits and protect databases with pooling and rate limits.
- Slow startup.
Fix: Bake images, keep warm pools, or pre-scale for known events.
- Stateful instances.
Fix: Scale-in destroys local sessions or data.
Interview questions
How would you prepare a system for a flash sale?
Pre-scale (scheduled) compute, caches, and databases ahead of time, raise auto scaling limits, load test, add queues and rate limits for write paths, use a waiting room if needed, and keep target tracking for unexpected load.
What metric would you scale a queue worker on?
Backlog per worker or age of the oldest message, rather than CPU, because it directly reflects the work waiting.
Practice problems
| Problem | Difficulty | What it trains |
|---|---|---|
| Configure target tracking for an API | Easy | Metrics. |
| Design auto scaling for a concert ticket sale | Hard | Pre-scaling and protection. |