Autoscaling and Traffic Distribution
Balancer and fleet growing together
Load balancers and autoscaling are designed to work as one unit: the fleet scales on LB-side signals (request count, latency), the LB follows fleet size, and weighted/least-connections distribution keeps load balanced across capacities.
What you will learn
- Integrate autoscaling groups with the balancer's target group
- Design scaling on request-based metrics
- Explain weighted and least-connection distributions
Autoscaling keeps the fleet sized to demand and registers/removes instances with the LB automatically. Scales on 'requests per target' or load-balancer latency; the LB spins distribution across whatever the group produces, weighted where speeds differ.
What is this?
Integration: ASG/VMSS/MIG attach a target group; scale events register/deregister instances. Scale metrics: requests-per-target on ALB, queue depth via custom metrics; App Gateway autoscale on RU; GCP MIG autoscaler on utilization. Distribution: round-robin, least-outstanding-requests, weighted targets (AWS target weight, Azure weight-based backends, GCP capacity scaler/weights). Weighted routing is used at canary releases (0/90/10) and when instance capabilities differ.
Why do you need it?
- LBs + autoscaling together = the fleet matches demand AND is load-balanced.
- LB-side metrics capture the actual service experience better than host CPU alone.
- Weighted distribution enables canary/traffic-splitting without DNS tricks.
- Least-requests prevents a slow box from hogging the queue.
Mental model
A mall opening more checkout lanes (fleet) and a manager balancing queues (LB)
Autoscaling + traffic distribution
The manager opens lanes when lines get long (ASG on queue depth), and the registration desk (LB) sends each customer to whichever lane is shortest, weighting lanes if some workers are faster.
How it works
- ASG attaches a target group; instances launched by the group register automatically.
- Scaling policies read metrics like ALB 'RequestCountPerTarget' or CPU and adjust the fleet.
- Scale-in terminates instances from the group; the LB drains them before actual termination.
- Weighted targets split traffic by weight for canary; least-outstanding-requests avoids stragglers.
- The LB DNS/endpoint stays constant — only the fleet behind it changes.
LB + ASG loop.
Examples
Scale on request-based metrics
# ALB-backed ASG with target tracking on requests per targetaws autoscaling attach-load-balancer-target-groups \ --auto-scaling-group-name web-asg --target-group-arns <tg>aws autoscaling put-scaling-policy --auto-scaling-group-name web-asg \ --policy-name req-target --policy-type TargetTrackingScaling \ --target-tracking-configuration '{ "PredefinedMetricSpecification": { "PredefinedMetricType": "ALBRequestCountPerTarget", "ResourceLabel": "app/<lb>/<tg>" }, "TargetValue": 1000}'The group scales when the average request load per target crosses the target — a service-level signal, not host CPU.
In production
- A retail back office scales 2→40 nodes on ALB request count during a flash sale.
- GCP MIG autoscaling hooks utilization to the LB so pushes never saturate any zone.
- Azure App Gateway RU autoscale sizes gateways as the fleet grows underneath.
Best practices
- Scale on the metric that predicts add-times: request count beats CPU-for-latency services.
- Couple ASG and LB lifecycle: attach the target group, let the group drive registrations.
- Weighted canaries: 0/90/10 then 50/50 then 100 — with LB drain for the old version.
- Set max group size to bound scale-related spend and LB connection burst.
Common mistakes
- Scaling on CPU while the real signal is request latency → wrong fleet sizes.
- Manual register/deregister with AMI changes — group+LB should own the lifecycle.
- Weighted 0 on a canary that never gets verified (0% receives a trickle — that's intentional).
- Autoscaling on LB metrics while the LB is the bottleneck (scale LB first).
Common issues
Group connects but 0 trafficListener/target-group association or weight 0
Confirm the listener forwards to the TG and the correct rule priority matches.
Scale in terminates a bursty new instanceGroup drained it while the spike returned
Use cooldown/warm pool, and choose an instance protection policy for recent launches.
Debugging tips
- 'Scaling did nothing' — check the metric exists and the ASG is attached to the TG.
- Requests peaked but group flat: policy throttled or max reached; inspect scale activity history.
- Canary at 10% drifting: verify weight actually applies (listener rule → target group weight).
- If instances spin up but immediately unhealthy, re-check the health-check port on the new AMI.
Interview checkpoint
Quick quiz
Why prefer request-count-per-target over host CPU as a scaling metric?