ECS service auto scaling in AWS - Time & Space Complexity
When using ECS service auto scaling, it's important to understand how the number of scaling actions grows as the workload changes.
We want to know how the system reacts over time as demand increases or decreases.
Analyze the time complexity of this ECS auto scaling setup.
aws application-autoscaling register-scalable-target \
--service-namespace ecs \
--resource-id service/clusterName/serviceName \
--scalable-dimension ecs:service:DesiredCount \
--min-capacity 1 \
--max-capacity 10
aws application-autoscaling put-scaling-policy \
--service-namespace ecs \
--resource-id service/clusterName/serviceName \
--scalable-dimension ecs:service:DesiredCount \
--policy-name cpu-scaling-policy \
--policy-type TargetTrackingScaling \
--target-tracking-scaling-policy-configuration file://config.json
This sequence registers the ECS service for auto scaling and sets a policy to adjust the number of tasks based on CPU usage.
Look at what happens repeatedly as load changes.
- Primary operation: Scaling actions that adjust the desired task count.
- How many times: Each time the monitored metric crosses thresholds, a scaling action triggers.
As workload increases, the number of scaling actions grows roughly in proportion to how often the metric changes enough to trigger scaling.
| Input Size (n) | Approx. Scaling Actions |
|---|---|
| 10 | About 10 scaling checks, few actions |
| 100 | About 100 scaling checks, more actions |
| 1000 | About 1000 scaling checks, many actions |
Pattern observation: The number of scaling actions grows linearly with the number of metric evaluations.
Time Complexity: O(n)
This means the number of scaling operations grows directly with the number of metric checks or workload changes.
[X] Wrong: "Scaling happens instantly and only once regardless of workload size."
[OK] Correct: Scaling triggers repeatedly as metrics change, so more workload changes mean more scaling actions over time.
Understanding how auto scaling reacts over time helps you design systems that respond well to demand without overloading or wasting resources.
"What if we changed the scaling policy from target tracking to step scaling? How would the time complexity change?"