Auto scaling App Service in Azure - Time & Space Complexity
We want to understand how the time to adjust resources changes as demand grows for an App Service.
How does the system handle more users by adding more instances automatically?
Analyze the time complexity of this auto scaling setup.
// Define autoscale setting
az monitor autoscale create \
--name MyAppServiceScaleRule \
--resource-group MyResourceGroup \
--resource MyAppServicePlan \
--resource-type Microsoft.Web/serverfarms \
--min-count 1 \
--max-count 5 \
--count 1
az monitor autoscale rule create \
--resource-group MyResourceGroup \
--autoscale-name MyAppServiceScaleRule \
--metric-name CpuPercentage \
--operator GreaterThan \
--threshold 70 \
--time-aggregation Average \
--time-grain PT1M \
--scale-action-direction Increase \
--scale-action-type ChangeCount \
--scale-action-value 1 \
--cooldown-period PT5M
This sequence sets up auto scaling for an App Service based on CPU usage, scaling out by one instance when CPU goes above 70%.
Look at what happens repeatedly as load changes.
- Primary operation: Checking CPU metric and deciding to add or remove instances.
- How many times: This check happens continuously at regular intervals.
- Scaling action: Adding or removing one instance at a time when threshold is crossed.
As more users come, CPU usage rises and triggers scaling.
| Input Size (Users) | Approx. Scale Actions |
|---|---|
| 10 | 0-1 (likely no scale needed) |
| 100 | 1-3 scale outs over time |
| 1000 | Up to 4 scale outs, limited by max instances |
Scaling actions increase roughly linearly with load until the max instance limit is reached.
Time Complexity: O(n)
This means the number of scaling actions grows roughly in direct proportion to the increase in load.
[X] Wrong: "Auto scaling instantly adds many instances at once as load grows."
[OK] Correct: Auto scaling adds or removes instances one at a time based on rules and cooldowns, so scaling actions grow step-by-step, not all at once.
Understanding how auto scaling reacts to load helps you design systems that handle growth smoothly and efficiently.
"What if we changed the scale out increment from 1 instance to 3 instances? How would the time complexity change?"