Volume 4 · Chapter 9 — Compute and Containers
Auto Scaling in Depth
9.1 Introduction
The elasticity chapter covered the concept; the exam tests the specifics of EC2 Auto Scaling - the scaling policy types (including predictive and scheduled), health-check sources, instance refresh, warm pools, lifecycle hooks, and mixed-instances/termination behavior. These details determine how gracefully a fleet scales and heals.
9.2 Scaling Policy Types
Auto Scaling adjusts capacity through several policy types.Target trackingkeeps a metric at a target (e.g. average CPU 50% or requests-per-target) - the simplest and most common.Step scalingadjusts capacity in defined steps based on how far a CloudWatch alarm threshold is breached (bigger breach, bigger step).Simple scalingis the older single-adjustment-with-cooldown approach.Scheduled scalingchanges capacity at known times (scale up before market open or payday) for predictable patterns.Predictive scalinguses ML to forecast load and provision capacityaheadof predicted demand - ideal for cyclical patterns. The exam favours target tracking for general use, scheduled for known cycles, and predictive for forecastable recurring load, and often combines predictive (for the baseline curve) with target tracking (for unexpected variation).
flowchart TD
Q{Scaling need?} -->|Hold a metric at a target| TT[Target tracking]
Q -->|Proportional to threshold breach| SS[Step scaling]
Q -->|Known time-based pattern| Sched[Scheduled]
Q -->|Forecast recurring load| Pred[Predictive - ML, provisions ahead]
Pred -.combine with.-> TT 9.3 Health Checks, Cooldowns, and Termination
An Auto Scaling group replaces unhealthy instances, and thehealth-check typematters: the defaultEC2health check only detects instance-level failures (status checks), while theELBhealth check also considers the load balancer’s application health - so you enable ELB health checks so the ASG replaces instances that are running but failing the app’s health check.Cooldownsprevent rapid successive scaling actions before the previous one takes effect. When scaling in, thetermination policydecides which instances to remove (default balances AZs, then oldest launch template/config, then closest to the next billing hour) - and you can protect specific instances from scale-in. Enabling ELB health checks is a frequent exam fix for “instances are unhealthy but not being replaced.”
9.4 Instance Refresh, Warm Pools, and Lifecycle Hooks
Three advanced features.Instance refreshrolls out a new launch template version across the ASG (replacing instances gradually with health checks) - the way to deploy a new AMI/config to a fleet safely.Warm poolskeep pre-initialized (stopped or running) instances ready so scale-out is faster for apps with long boot/initialization times, avoiding the cold-start delay of launching from scratch.Lifecycle hookspause instances at launch or termination so you can run custom actions (install software, drain connections, deregister) before the instance enters service or terminates - essential for graceful bootstrapping and shutdown. These make scaling smooth for real workloads rather than abrupt.
9.5 Mixed Instances and Spot in ASGs
An Auto Scaling group can use amixed-instances policy- multiple instance types and a blend of On-Demand and Spot capacity - so the group is resilient to Spot interruptions and instance-type shortages and can optimize cost (e.g. a baseline of On-Demand plus additional Spot). This is the standard pattern for running fault-tolerant, cost-optimized fleets: define several compatible instance types and a target On-Demand/Spot split, and the ASG diversifies across them. The exam expects mixed instances with Spot for cost-optimized, interruption-tolerant capacity, keeping a guaranteed On-Demand base for stability.
9.6 Banking Production Scenario
A bank’s customer service scales with target tracking on requests-per-target, predictive scaling pre-provisions for the daily payday curve, and scheduled scaling adds capacity before batch windows. The ASG uses ELB health checks so instances failing the application health check are replaced, with scale-in protection on instances running critical in-flight work. Deployments use instance refresh to roll a new golden AMI across the fleet gradually. A warm pool keeps pre-initialized instances ready because the app has a long JVM warm-up, so scale-out is fast. Lifecycle hooks drain connections and deregister from downstream services before termination. A batch-processing ASG uses a mixed-instances policy with an On-Demand base and Spot for the rest. This complete Auto Scaling design delivers smooth, resilient, cost-optimized elasticity - the professional-level expectation.
9.7 Chapter Revision Notes
- Scaling policies: target tracking (hold a metric - default), step (proportional to breach), simple (older), scheduled (known times), predictive (ML forecast, provisions ahead).
- Use ELB health checks (not just EC2) so instances failing the app health check are replaced; cooldowns prevent thrashing; termination policy chooses scale-in victims (protect critical instances).
- Instance refresh rolls a new launch-template version across the fleet; warm pools pre-initialize instances for fast scale-out of slow-booting apps.
- Lifecycle hooks pause launch/terminate for custom bootstrap/drain actions.
- Mixed-instances policy blends instance types and On-Demand + Spot for resilient, cost-optimized fleets (On-Demand base + Spot).