0
0
Azurecloud~5 mins

Functions with HTTP triggers in Azure - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Functions with HTTP triggers
O(n)
Understanding Time Complexity

When using Azure Functions triggered by HTTP requests, it's important to understand how the number of requests affects the system's work.

We want to know how the function's execution scales as more HTTP calls come in.

Scenario Under Consideration

Analyze the time complexity of the following Azure Function triggered by HTTP requests.

[FunctionName("HttpTriggerFunction")]
public static async Task Run(
    [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
    ILogger log)
{
    log.LogInformation("Processing HTTP request.");
    string name = req.Query["name"];
    return new OkObjectResult($"Hello, {name}");
}

This function responds to each HTTP request by reading a query parameter and returning a greeting.

Identify Repeating Operations

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

  • Primary operation: The function execution triggered by each HTTP request.
  • How many times: Once per HTTP request received.
How Execution Grows With Input

Each new HTTP request causes one function execution, so the work grows directly with the number of requests.

Input Size (n)Approx. Api Calls/Operations
1010 function executions
100100 function executions
10001000 function executions

Pattern observation: The total work increases linearly as the number of HTTP requests increases.

Final Time Complexity

Time Complexity: O(n)

This means the total execution time grows in direct proportion to the number of HTTP requests received.

Common Mistake

[X] Wrong: "The function runs once and handles all requests together."

[OK] Correct: Each HTTP request triggers a separate function execution, so work adds up with each request, not just once.

Interview Connect

Understanding how serverless functions scale with incoming requests helps you design responsive and cost-effective cloud solutions.

Self-Check

"What if the function called another API inside for each request? How would that affect the time complexity?"