Topic 095 / Core
Auto scaling
Chapter 6.3 · Scaling Services
What and why
Horizontal scaling (→ 90) answers "can we add machines"; auto scaling answers "when, and how many, without a human watching a dashboard." It adds or removes instances automatically based on a measured signal, with rules that stop it from reacting too fast or too slow. Builds on: → 90 (vertical and horizontal scaling).
Diagram
metric (CPU, RPS, or queue depth)
│
▼
above high threshold? ──yes──► add instance(s) ──► cooldown ──► re-check
│ no
▼
below low threshold? ───yes──► remove instance(s) ──► cooldown ──► re-check
│ no
▼
hold current instance count
How it works
- Pick a leading metric that correlates with actual load: CPU utilization, requests per second, or queue depth; CPU alone can lag behind what actually hurts users (→ 103, utilization vs. saturation).
- Set a scale-out threshold and a scale-in threshold with a gap between them, so the system doesn't flip instances on and off at the boundary.
- After scaling, wait a cooldown period before evaluating again — new instances take time to start and warm up (a cold cache, → 82), and reacting to an unstabilized metric causes overshoot.
- New instances must register with the load balancer (→ 92) and pass health checks before receiving traffic; removed instances must drain in-flight requests first (→ 98) — auto scaling and both of those mechanisms are the same event, viewed from different angles.
- Auto scaling reacts only after the metric crosses a threshold, so it always lags a sudden spike by at least the time to detect, start, and warm a new instance — it is not a substitute for load shedding (→ 97) during that lag window, only a longer-term capacity response.
Practical example
(numbers illustrative). A service scales out above 70% average CPU and scales in below 30%, with a 5-minute cooldown. Traffic doubles in 30 seconds. Detecting the breach (a 1-minute metric window) plus starting and warming a new instance (2 minutes) means roughly 3 minutes pass between the spike starting and new capacity actually serving traffic — during those 3 minutes, the existing instances absorb the full doubled load alone, exactly the gap load shedding (→ 97) is designed to survive.
When to use it
- Use auto scaling for load that varies predictably or gradually enough that the detection-plus-startup lag doesn't matter — daily traffic cycles, gradual growth, planned events with lead time.
- Avoid relying on it alone for sudden spikes (flash sales, viral moments) within its own reaction window — that gap needs load shedding or pre-provisioned headroom (→ 102), not a faster auto scaler.
- Failure scenarios: thresholds too close together causing instances to oscillate (flapping); a cooldown too short, scaling out repeatedly for what was really one spike, overshooting capacity and cost; a leading metric that doesn't actually correlate with user-facing pain (CPU looking fine while connection pools are exhausted, → 103).
- Simpler alternative: fixed, manually-sized capacity with generous headroom, resized on a schedule — simpler to reason about than tuning thresholds and cooldowns, at the cost of paying for unused headroom most of the time.
Practice
(process kind — fill a template on a small scenario, 15–20 min).
- For a service with daily traffic ranging from 100 to 800 requests/second on a daily curve, and one instance sustaining 200 requests/second, define scale-out/scale-in thresholds, a metric, and a cooldown; justify each choice.
- Using the practical example's 3-minute lag and 200 requests/second per instance, compute the pre-provisioned headroom (in instances) needed to survive a sudden spike from a 600 requests/second baseline to double that, without load shedding.
- Describe one scenario where your chosen thresholds would flap, and fix it.
Done when your threshold-and-cooldown design, walked through the daily curve by hand, neither flaps nor leaves an obvious capacity gap.
Key takeaway
Auto scaling automates the "when and how many" of horizontal scaling (→ 90) from a leading metric, but it always lags a sudden spike by its detection-plus-startup time — pair it with load shedding (→ 97) for that gap. Done when you can: design thresholds and a cooldown for a given traffic pattern that neither flaps nor leaves an unprotected gap. Used next in → 97 (backpressure and load shedding, covering the reaction lag), → 98 (graceful shutdown, how scale-in removes an instance cleanly), → 102 (capacity planning, pre-provisioned headroom for what auto scaling can't catch in time).
References
None — this topic makes no external claims.
Source directory