SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
Part 2: APIs and Communication
Part 3: Caching
Part 4: Data and Storage
Part 5: Architecture
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
  • Deployment Strategies Overview
  • CI/CD Pipelines
  • Rolling Deployments
  • Blue-Green Deployments
  • Canary Releases
  • Feature Flags
  • A/B Testing Infrastructure
  • Schema Migrations
  • Rollbacks and Immutable Infrastructure
  • Multi-Region and Active-Active
  • Infrastructure as Code (Terraform)
  • Auto-Scaling Policies
  • Zero-Downtime Deployment
  • Chaos Engineering
  • Shadow Traffic and Dark Launches
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Operations and Security/Deployment Patterns

Auto-Scaling Policies

Add and remove servers by rules (target, step, schedule, prediction) so capacity follows the load.

โฑ 13 min readIntermediateMust KnowInterview FavouriteHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

Auto-scaling adds servers when load goes up and removes them when it goes down, using rules you set. Those rules are the scaling policy. A good policy keeps users fast without paying for idle machines.

  • Four common policies: target tracking, step scaling, scheduled scaling and predictive scaling.
  • Reactive scaling is always a little late. New servers need time to start and warm up.
  • The main dials: the metric, the target, min and max, cooldown, and warm-up time.

02Concept: What is it?

Traffic is rarely flat. It rises in the morning, drops at night, and sometimes jumps because of a sale or a news story. If you buy for the peak, you waste money most of the day. If you buy for the average, you fall over at the peak. Auto-scaling closes that gap: a controller watches a metric, compares it with a goal, and changes the number of servers.

Scaling out (more servers) is called horizontal scaling and is what auto-scaling usually means. Scaling up (a bigger server) is vertical scaling. It often needs a restart, so it is rarely automatic.

The control loop
๐Ÿ“ŠMeasureCPU, requests, queue depth
โ†’โ†“compare to target
๐ŸงฎDecidepolicy + min/max
โ†’โ†“add or remove
๐Ÿ–ฅ๏ธServersstart, warm up, join
โ†‘load changes
Measure, decide, act, wait. Then do it again.
๐Ÿง Time is the enemy
A new server needs time to boot, start the app, fill its caches and pass health checks. That delay is called warm-up. During a sudden spike the old servers must carry the load until the new ones are ready.

03Real-Life Example

๐ŸตA Restaurant Calling in Staff
A restaurant is busy at lunch and quiet at 3 pm. The manager has rules: "if the queue at the door is longer than 10 people, call in another waiter" (a reactive rule). "Every Friday at 6 pm, have 8 waiters on" (a scheduled rule). A waiter takes 20 minutes to arrive and get ready, so a sudden bus tour still finds the room short-staffed. And if the manager calls people in and sends them home every 5 minutes, nobody trusts the rota (flapping).
Restaurant
Auto-scaling
Waiters on shift
Servers in the group
Queue at the door
The metric (CPU, requests, queue depth)
โ€œAim for a queue of about 5โ€
Target tracking
โ€œOver 10 people, call 2 more; over 20, call 5โ€
Step scaling
โ€œFriday 6 pm, 8 waitersโ€
Scheduled scaling
Predicting the lunch rush from past weeks
Predictive scaling
Time for a waiter to arrive and be ready
Warm-up time
Do not change the rota again for 10 minutes
Cooldown

04Why Do We Need It?

๐Ÿ’ธPay for what you use
Fewer servers at night, more at peak. Idle capacity costs money.
๐Ÿ›ก๏ธStay up under load
Capacity follows traffic, so a busy hour does not become an outage.
โฑ๏ธSteady speed
Keeping utilisation in a healthy range keeps latency low.
๐ŸงฏSelf-healing
Failed servers are replaced automatically by the group.
๐Ÿง‘โ€๐Ÿ’ปLess manual work
No one has to add servers at 2 am.
๐Ÿ“ˆHandles growth
A slow rise in traffic is absorbed without a ticket.
Auto-scaling turns capacity from a guess made once into a rule that keeps adjusting.

05Where Do We Use It?

๐ŸŒWeb and API servers
Stateless servers behind a load balancer are the easiest to scale.
๐Ÿ“ฌQueue workers
Scale the number of workers by queue depth or message age.
โ˜ธ๏ธKubernetes
The Horizontal Pod Autoscaler changes the number of pods, and a cluster autoscaler adds machines.
๐ŸงฎBatch and data jobs
Spin up a big cluster for a job, then shut it down.
๐Ÿ—„๏ธServerless and managed databases
Some platforms scale for you, with limits and cold starts.
๐Ÿ›’Sales and events
Scheduled scaling before a known launch, plus reactive rules for surprises.

06Types / Parts / How It Works

Policy types

PolicyHow it worksGood forWatch out for
Target trackingKeep one metric near a target (for example CPU 60%). The system works out how many serversMost web services. The simplest good defaultSlow metrics, and a poor choice of metric
Step scalingDifferent actions for different sizes of breach (over 70%: +2, over 90%: +6)Fast reaction to big jumpsMore tuning, and steps can overshoot
ScheduledChange capacity at fixed timesKnown daily or weekly peaks, launchesUseless for surprises, and goes stale
PredictiveForecast load from history and scale ahead of timeRegular patterns with slow warm-upNeeds enough history, and misses new patterns

Choosing the metric

MetricUse whenCaution
CPU utilisationWork is CPU-boundMisleading if the bottleneck is memory, I/O or a database
Requests per targetWeb or API traffic with similar cost per requestNeeds the load balancer metric
Queue depth or message ageWorkers pulling from a queueScale on work per worker, not raw depth
LatencyYou care directly about user speedIt rises after you are already in trouble
Custom (active sessions, jobs)Your own definition of loadNeeds good instrumentation
The guard rails around any policy
Limits
โฌ‡๏ธMinimumnever fewer than this (and spread over zones)
โฌ†๏ธMaximuma cost and blast-radius cap
Timing
๐Ÿ•’Cooldownwait before the next change
๐Ÿ”ฅWarm-upa new server is not ready at once
๐Ÿ›‘Scale-in protectiondo not remove a busy server
Min keeps you safe, max keeps your bill safe.
Limits Timing
VisualizerLoad against capacity over one dayPick a sudden spike, then try each policy. Make the warm-up longer and watch the red overload bars grow. Lower the target to buy headroom, and compare the cost. Try a very short cooldown on the daily wave to see flapping.
Load pattern
Scaling policy
00:0012:0024:00
Load (requests per second) Serving capacity Overloaded
Overloaded
4 / 48
half-hour ticks
Cost
414
server-ticks paid
Peak servers
20
Scaling actions
3
changes made
The spike arrived faster than new servers could start. They take 2 tick(s) to warm up, so the load hit the old fleet and 4 tick(s) were overloaded. Reactive scaling is always a little late. Lower the target, shorten warm-up, or use a schedule or prediction for known peaks.

Illustrative model: one server handles 100 requests per second, one tick is 30 minutes, servers cost the same while starting as when serving, and scaling in is instant. Real systems add health checks, lifecycle hooks and billing rules.

07How to Use It / Steps / Implementation

Setting up a policy

  1. 1
    Make the servers stateless
    Keep sessions, files and state outside, so any server can be added or removed.
  2. 2
    Pick a metric that tracks real load
    It should rise before users feel pain, and fall when servers are added.
  3. 3
    Start with target tracking
    Aim for about 50 to 70 percent utilisation to leave room for a spike.
  4. 4
    Set a minimum and maximum
    Minimum across at least two zones. Maximum so a bug cannot buy 500 servers.
  5. 5
    Measure the real warm-up time
    Include boot, app start, caches and health checks, then set the warm-up setting to match.
  6. 6
    Scale out fast, scale in slowly
    Add on short signals. Remove only after load has stayed low for a while.
  7. 7
    Add schedules for known peaks
    Pre-scale before a launch or daily rush, so you are not racing the spike.
  8. 8
    Load test it
    Replay a spike and watch capacity, latency and errors. Tune from what you see.
๐Ÿ’กLeave headroom
A target of 60% means a sudden 50% jump still fits on the current servers while new ones start. A target of 90% means any jump overloads you.
โš ๏ธCheck the downstream
More app servers means more database connections. A database that does not scale will be the next bottleneck. Scale limits and connection pools together.

08Key Terms to Know

TermMeaning in easy words
Auto-scalingChanging the number of servers automatically based on rules
Horizontal scalingAdding more servers
Vertical scalingUsing a bigger server
Scale out / scale inAdd servers / remove servers
Target trackingKeep a metric near a chosen value
Step scalingBigger breaches trigger bigger changes
Scheduled scalingChange capacity at fixed times
Predictive scalingScale ahead of time using a forecast
CooldownA pause after a scaling action before the next one
Warm-upThe time a new server needs before it can take full load
FlappingScaling up and down again and again
HPAKubernetes Horizontal Pod Autoscaler
Scale-in protectionStops a busy or important server from being removed

09Pros, Cons and Trade-offs

โœ… Pros
  • Cost follows the load
  • Handles growth and peaks without people
  • Replaces failed servers
  • Keeps latency steadier
  • Works well with stateless services
โš ๏ธ Cons
  • Reactive rules are always a little late
  • Needs careful tuning
  • Can flap or overshoot
  • Hard for stateful systems
  • A bug or attack can run up a large bill

Trade-offs

ChoiceWe gainWe lose
Low target (50%)Headroom for spikesMore idle servers, higher cost
High target (80%)Lower costLittle room for a surprise
Short cooldownReacts quicklyFlapping and wasted starts
Long cooldownStableSlow to follow the load
Scheduled + reactiveReady for known peaks and surprisesMore rules to maintain
PredictiveCapacity is ready ahead of timeNeeds history, wrong when patterns change

10Common Problems and Mistakes

Common mistakes

  1. Ignoring warm-up. New servers are counted as ready, take traffic too early and fail.
  2. Scaling on the wrong metric. CPU stays low while the database is the real limit.
  3. No maximum. A runaway loop or an attack buys servers without end.
  4. Scaling in too fast. The fleet shrinks, then a normal bump overloads it, and it scales out again (flapping).
  5. All servers in one zone. A zone failure takes the whole fleet down, whatever the policy.
  6. Removing servers that still serve requests. Without draining, in-flight requests fail.
  7. Never testing. The first real spike is the test, and it fails.

Things to watch

๐Ÿ˜Thundering herd
Many new servers start at once and hit the database and caches together. Stagger starts and warm caches.
๐Ÿ”ŒConnection limits
Each server opens database connections. More servers can exhaust the database.
๐Ÿ—„๏ธStateful systems
Databases and caches with data are hard to scale automatically. Moving data takes time and care.
๐ŸงพCost surprises
Billing is often per minute or hour. Short-lived servers can cost more than expected.

11Real-World Examples

โ˜๏ธAWS Auto Scaling groups
Target tracking, step, scheduled and predictive policies, with cooldown and warm-up settings.
โ˜ธ๏ธKubernetes HPA
Adds or removes pods using CPU, memory or custom metrics, with a cluster autoscaler adding nodes.
๐Ÿ”ทAzure and Google Cloud
Virtual machine scale sets and managed instance groups offer the same ideas.
๐Ÿ“ฌQueue-based workers
Workers scale on queue depth or message age, so a backlog is cleared automatically.
๐Ÿ›’Retail events
Teams pre-scale for a known sale, and rely on reactive rules for the rest.
โšกServerless
Functions scale per request with no groups to manage, but have concurrency limits and cold starts.
Mini case: spike with and without headroom
Target 90%
๐Ÿ“ˆSpike +50%
โ†“
๐Ÿ”ฅOverloadeduntil new servers are ready
Target 60%
๐Ÿ“ˆSpike +50%
โ†“
โœ…Absorbedthen scales out calmly
Same spike, different target. The lower target already had room.

12Related Topics to Read Next

Capacity Planningโ†’

Work out the limits and the baseline that policies sit on.

Health Checksโ†’

How new servers are judged ready, and bad ones replaced.

Kubernetes Basicsโ†’

Where the HPA and cluster autoscaler live.

Scalabilityโ†’

The big idea of growing by adding machines.

What are Load Balancers?โ†’

They spread traffic over the servers that scaling adds.

Message Queuesโ†’

Queue depth is a classic scaling signal for workers.

Stateless vs Statefulโ†’

Why stateless services scale easily.

Infrastructure as Code (Terraform)โ†’

Scaling groups and limits are defined as code.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • โœ”Goal: match capacity to load, automatically.
  • โœ”Policies: target tracking, step, scheduled, predictive.
  • โœ”Dials: metric, target, min, max, cooldown, warm-up.
  • โœ”Reactive = late: leave headroom (target about 60%) and pre-scale known peaks.
  • โœ”Scale out fast, in slow to avoid flapping.
  • โœ”Needs: stateless servers, health checks, draining, several zones.
  • โœ”Watch: database connections, thundering herd, cost cap.
  • โœ”One line: โ€œMeasure, decide, act, wait, and always plan for the server that is not ready yet.โ€
โ† Previous
Infrastructure as Code (Terraform)
Next โ†’
Zero-Downtime Deployment