Scaling policies (target tracking, step, simple) in AWS - Time & Space Complexity
When using scaling policies in AWS, it's important to understand how the number of scaling actions grows as demand changes.
We want to know how the system reacts over time as load increases or decreases.
Analyze the time complexity of these scaling policy operations.
aws application-autoscaling put-scaling-policy --policy-name my-step-policy --service-namespace ecs \
--resource-id service/default/sample-webapp --scalable-dimension ecs:service:DesiredCount \
--policy-type StepScaling --step-scaling-policy-configuration file://step-config.json
aws application-autoscaling put-scaling-policy --policy-name my-target-tracking-policy --service-namespace ecs \
--resource-id service/default/sample-webapp --scalable-dimension ecs:service:DesiredCount \
--policy-type TargetTrackingScaling --target-tracking-scaling-policy-configuration file://target-tracking.json
These commands set up step and target tracking scaling policies for an ECS service.
Look at what happens repeatedly as load changes:
- Primary operation: Scaling actions that adjust the number of instances.
- How many times: Each scaling action happens whenever the metric crosses thresholds or deviates from the target.
As load increases, the number of scaling actions grows roughly in proportion to how often the metric crosses thresholds.
| Input Size (Load Changes) | Approx. Scaling Actions |
|---|---|
| 10 | About 10 scaling actions |
| 100 | About 100 scaling actions |
| 1000 | About 1000 scaling actions |
Pattern observation: Scaling actions increase linearly with the number of load changes.
Time Complexity: O(n)
This means the number of scaling actions grows directly with the number of load changes.
[X] Wrong: "Scaling happens instantly and only once regardless of load changes."
[OK] Correct: Scaling policies react each time the metric crosses thresholds, so multiple scaling actions happen as load fluctuates.
Understanding how scaling actions grow with load helps you design systems that respond well to demand and avoid surprises in performance.
What if we changed from step scaling to simple scaling? How would the time complexity change?