0
0
Azurecloud~5 mins

Why serverless matters in Azure - Performance Analysis

Choose your learning style9 modes available
Time Complexity: Why serverless matters
O(n)
Understanding Time Complexity

We want to understand how the time to run serverless functions changes as we add more tasks.

How does the number of function calls grow when the workload grows?

Scenario Under Consideration

Analyze the time complexity of the following operation sequence.


// Azure Function triggered by HTTP request
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, ILogger log)
{
    var tasks = new List<Task>();
    for (int i = 0; i < n; i++)
    {
        tasks.Add(ProcessItemAsync(i));
    }
    await Task.WhenAll(tasks);
    return req.CreateResponse(HttpStatusCode.OK);
}

private static async Task ProcessItemAsync(int itemId)
{
    // Simulate processing
    await Task.Delay(100);
}

This code runs a serverless function that processes n items in parallel by calling a helper function for each item.

Identify Repeating Operations

Identify the API calls, resource provisioning, data transfers that repeat.

  • Primary operation: Calling ProcessItemAsync for each item.
  • How many times: Exactly n times, once per item.
How Execution Grows With Input

Each new item adds one more function call to process it, so the total calls grow directly with n.

Input Size (n)Approx. Api Calls/Operations
1010 calls to ProcessItemAsync
100100 calls to ProcessItemAsync
10001000 calls to ProcessItemAsync

Pattern observation: The number of calls grows linearly as the input size increases.

Final Time Complexity

Time Complexity: O(n)

This means the total work grows in direct proportion to the number of items to process.

Common Mistake

[X] Wrong: "Serverless functions run instantly, so time does not grow with more items."

[OK] Correct: Each item still needs its own function call, so more items mean more calls and more total time.

Interview Connect

Understanding how serverless scales with workload helps you design efficient cloud solutions and explain your reasoning clearly in interviews.

Self-Check

"What if we changed the code to process items one after another instead of in parallel? How would the time complexity change?"