Container Apps scaling rules in Azure - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
When using Container Apps, scaling rules decide how many containers run based on demand.
We want to know how the number of scaling actions grows as the workload increases.
Analyze the time complexity of scaling Container Apps based on CPU usage.
# Define a scaling rule for Container App
az containerapp update \
--name myapp \
--resource-group myrg \
--min-replicas 1 \
--max-replicas 10 \
--scale-rule-name cpu-scale \
--scale-rule-type cpu \
--scale-rule-metadata target=70
This sets the app to scale between 1 and 10 containers based on CPU usage target of 70%.
Look at what happens repeatedly as load changes.
- Primary operation: Scaling actions that add or remove container instances.
- How many times: Up to the max replicas limit, depending on workload spikes.
As workload increases, more containers start to handle the load.
| Input Size (CPU load spikes) | Approx. Scaling Actions |
|---|---|
| 10 | Up to 10 scaling actions (one per container added) |
| 100 | Still capped at 10 scaling actions due to max replicas |
| 1000 | Still capped at 10 scaling actions; no more containers added |
Pattern observation: Scaling actions grow linearly with load until the max container limit is reached, then stay constant.
Time Complexity: O(n)
This means scaling actions increase directly with workload until the maximum number of containers is reached.
[X] Wrong: "Scaling actions happen instantly and infinitely as load grows."
[OK] Correct: Scaling is limited by max replicas and takes time to add containers, so actions are capped and paced.
Understanding how scaling rules affect resource use helps you design apps that handle growth smoothly and predictably.
"What if we changed the max replicas from 10 to 100? How would the time complexity change?"
Practice
Solution
Step 1: Understand scaling rules function
Scaling rules help apps change the number of running instances automatically based on usage.Step 2: Identify the correct purpose
Among the options, only automatic adjustment of instances matches scaling rules' purpose.Final Answer:
To automatically adjust the number of app instances based on demand -> Option AQuick Check:
Scaling rules = auto adjust instances [OK]
- Confusing scaling with manual restarts
- Thinking scaling changes app appearance
- Assuming scaling controls network limits
Solution
Step 1: Identify correct metric type for CPU scaling
The metric type must be "cpu" to scale based on CPU usage.Step 2: Check JSON structure and metadata
{"name":"cpu","type":"cpu","metadata":{"value":"75"}} correctly uses "cpu" type and sets a value of 75 for CPU percentage.Final Answer:
{"name":"cpu","type":"cpu","metadata":{"value":"75"}} -> Option CQuick Check:
CPU scaling JSON uses type "cpu" [OK]
- Using wrong metric type like memory for CPU scaling
- Mixing HTTP request type with CPU
- Incorrect JSON key names
{"name":"http","type":"http","metadata":{"concurrentRequests":"50"}}What happens when the app receives 60 concurrent HTTP requests?
Solution
Step 1: Understand the scaling trigger
The rule triggers scaling when concurrent HTTP requests exceed 50.Step 2: Analyze the scenario with 60 requests
Since 60 > 50, the app will scale out by adding instances to handle load.Final Answer:
The app scales out to add more instances -> Option AQuick Check:
Requests > threshold triggers scale out [OK]
- Thinking app scales in when load increases
- Assuming app crashes on overload
- Believing app blocks extra requests
{"name":"cpu","type":"cpu","metadata":{"value":"abc"}}What is the problem with this configuration?
Solution
Step 1: Check the value field in metadata
The value should be a number representing CPU percentage, but "abc" is not numeric.Step 2: Confirm type correctness
The type "cpu" is correct, and keys are spelled properly.Final Answer:
The value for CPU threshold is not a valid number -> Option DQuick Check:
CPU value must be numeric [OK]
- Using non-numeric strings for threshold values
- Changing correct type names
- Misspelling JSON keys
Solution
Step 1: Verify min and max replicas values
Min replicas should be 2 and max replicas 10 as per requirement; {"minReplicas": 2, "maxReplicas": 10, "rules": [{"name": "cpuRule", "type": "cpu", "metadata": {"value": "70"}}]} matches this correctly.Step 2: Check scaling rule type and metadata
The rule must be type "cpu" with value "70" for CPU usage threshold; {"minReplicas": 2, "maxReplicas": 10, "rules": [{"name": "cpuRule", "type": "cpu", "metadata": {"value": "70"}}]} correctly sets this.Final Answer:
{"minReplicas": 2, "maxReplicas": 10, "rules": [{"name": "cpuRule", "type": "cpu", "metadata": {"value": "70"}}]} -> Option BQuick Check:
Min/max replicas correct and CPU rule set [OK]
- Swapping min and max replica values
- Using wrong metric type like memory or http
- Incorrect metadata keys for CPU scaling
