CDN caching rules in Azure - Time & Space Complexity
We want to understand how the time to apply CDN caching rules changes as we add more rules.
Specifically, how does the system handle more rules when deciding what to cache?
Analyze the time complexity of the following Azure CDN caching rules setup.
// Create CDN endpoint
az cdn endpoint create --name myEndpoint --profile-name myProfile --resource-group myResourceGroup --origin myOrigin
// Add caching rules
az cdn endpoint rule add --endpoint-name myEndpoint --profile-name myProfile --resource-group myResourceGroup --order 1 --action CacheExpiration --cache-behavior Override --cache-duration 3600
az cdn endpoint rule add --endpoint-name myEndpoint --profile-name myProfile --resource-group myResourceGroup --order 2 --action CacheExpiration --cache-behavior BypassCache
This sequence creates a CDN endpoint and adds caching rules that control how content is cached or bypassed.
Look at what happens repeatedly when the CDN processes requests with caching rules.
- Primary operation: Checking each caching rule in order to decide cache behavior.
- How many times: Once per incoming request, checking rules sequentially until a match is found.
As the number of caching rules increases, the CDN checks more rules for each request.
| Input Size (n rules) | Approx. Rule Checks per Request |
|---|---|
| 10 | Up to 10 checks |
| 100 | Up to 100 checks |
| 1000 | Up to 1000 checks |
Pattern observation: The number of checks grows directly with the number of rules.
Time Complexity: O(n)
This means the time to decide caching behavior grows linearly with the number of caching rules.
[X] Wrong: "Adding more caching rules does not affect request processing time."
[OK] Correct: Each request must check rules in order, so more rules mean more checks and longer processing time.
Understanding how rule checks scale helps you design efficient CDN configurations and shows you can think about system performance clearly.
"What if the CDN used a hash map to find the matching caching rule instead of checking rules in order? How would the time complexity change?"