0
0
Azurecloud~5 mins

CDN caching rules in Azure - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: CDN caching rules
O(n)
Understanding Time 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?

Scenario Under Consideration

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.

Identify Repeating Operations

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.
How Execution Grows With Input

As the number of caching rules increases, the CDN checks more rules for each request.

Input Size (n rules)Approx. Rule Checks per Request
10Up to 10 checks
100Up to 100 checks
1000Up to 1000 checks

Pattern observation: The number of checks grows directly with the number of rules.

Final Time Complexity

Time Complexity: O(n)

This means the time to decide caching behavior grows linearly with the number of caching rules.

Common Mistake

[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.

Interview Connect

Understanding how rule checks scale helps you design efficient CDN configurations and shows you can think about system performance clearly.

Self-Check

"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?"