Scheduled scaling in AWS - Time & Space Complexity
We want to understand how the time to apply scheduled scaling changes as we add more schedules.
How does the number of scheduled scaling actions affect the work done by AWS?
Analyze the time complexity of the following operation sequence.
# Create multiple scheduled scaling actions for an Auto Scaling group
for ((i = 0; i < n; i++)); do
aws autoscaling put-scheduled-update-group-action \
--auto-scaling-group-name my-asg \
--scheduled-action-name "scale-action-$i" \
--start-time 2024-07-01T00:00:00Z \
--desired-capacity 5
done
This sequence creates n scheduled scaling actions, each setting desired capacity at a specific time.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: The
put-scheduled-update-group-actionAPI call to create a scheduled scaling action. - How many times: This call is made once per schedule, so n times.
Each new scheduled scaling action requires one API call, so the total calls grow directly with the number of schedules.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | 10 |
| 100 | 100 |
| 1000 | 1000 |
Pattern observation: The number of API calls grows linearly as you add more scheduled scaling actions.
Time Complexity: O(n)
This means the time to create scheduled scaling actions grows directly in proportion to how many schedules you add.
[X] Wrong: "Adding more scheduled scaling actions won't affect the time because AWS handles them all at once."
[OK] Correct: Each scheduled action requires a separate API call, so more schedules mean more calls and more time to set up.
Understanding how scheduled scaling scales helps you design systems that grow smoothly and predict how setup time changes as you add more automation.
"What if we batch multiple scheduled scaling actions into a single API call? How would the time complexity change?"
Practice
Solution
Step 1: Understand scheduled scaling concept
Scheduled scaling is designed to change resource capacity automatically based on a set schedule.Step 2: Compare options with the concept
Only To automatically adjust resources at specific times describes automatic adjustment at specific times, matching scheduled scaling.Final Answer:
To automatically adjust resources at specific times -> Option AQuick Check:
Scheduled scaling = automatic timed resource adjustment [OK]
- Confusing scheduled scaling with manual scaling
- Thinking it handles security or backups
- Assuming it reacts only to traffic, not time
Solution
Step 1: Review cron expression format in AWS
AWS cron expressions have six fields: minutes, hours, day-of-month, month, day-of-week, year.Step 2: Validate each option
cron(0 12 * * ? *) is valid: minute=0, hour=12, day-of-month=*, month=*, day-of-week=?, year=*. cron(0 0 0 0 ? *) has invalid zero day-of-month and month values. cron(60 24 * * ? *) has invalid 60 minutes and 24 hours. cron(* * * * *) has only five fields, missing year.Final Answer:
cron(0 12 * * ? *) -> Option DQuick Check:
Valid AWS cron = 6 fields, correct ranges [OK]
- Using 5-field cron instead of 6-field
- Setting minutes or hours out of range
- Confusing day-of-week and day-of-month
{"ScheduledActionName": "ScaleUpMorning", "StartTime": "2024-07-01T08:00:00Z", "DesiredCapacity": 5}What will happen at 8 AM UTC on July 1, 2024?
Solution
Step 1: Understand the scheduled action parameters
The action named "ScaleUpMorning" is set to start at 8 AM UTC on July 1, 2024, with DesiredCapacity 5.Step 2: Interpret the effect of StartTime and DesiredCapacity
At the StartTime, the capacity will be set to 5. EndTime is optional and does not block the action.Final Answer:
The resource capacity will be set to 5 -> Option AQuick Check:
StartTime triggers capacity change to DesiredCapacity [OK]
- Thinking EndTime is required to trigger scaling
- Assuming capacity decreases without explicit setting
- Ignoring the StartTime effect
cron(0 25 * * ? *)Why does the scaling not trigger as expected?
Solution
Step 1: Check the hour field in the cron expression
The hour field is set to 25, but valid hour values are 0 to 23.Step 2: Understand cron validation rules in AWS
AWS rejects cron expressions with invalid field values, so the scaling action won't trigger.Final Answer:
The hour value 25 is invalid in cron expressions -> Option CQuick Check:
Hour must be 0-23 in AWS cron [OK]
- Assuming minute 0 is invalid
- Thinking day-of-week is mandatory
- Using 5 fields instead of 6
Solution
Step 1: Understand the scheduling requirements
Capacity should be 2 at 11 PM daily and 10 at 7 AM on weekdays only.Step 2: Match cron expressions to requirements
cron(0 23 * * ? *) runs daily at 11 PM; cron(0 7 ? * MON-FRI *) runs at 7 AM Monday to Friday. Two separate scheduled actions are needed with correct DesiredCapacity values.Final Answer:
Create two scheduled actions: one with cron(0 23 * * ? *) setting DesiredCapacity=2, another with cron(0 7 ? * MON-FRI *) setting DesiredCapacity=10 -> Option BQuick Check:
Separate cron for each time and capacity [OK]
- Trying to set two capacities in one scheduled action
- Using rate expressions instead of cron for weekdays
- Missing weekday restriction for morning scale-up
Ready to prove it?
Pass the test and this pattern moves unknown
