Functions with HTTP triggers in Azure - Time & Space 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.
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 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.
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 |
|---|---|
| 10 | 10 function executions |
| 100 | 100 function executions |
| 1000 | 1000 function executions |
Pattern observation: The total work increases linearly as the number of HTTP requests increases.
Time Complexity: O(n)
This means the total execution time grows in direct proportion to the number of HTTP requests received.
[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.
Understanding how serverless functions scale with incoming requests helps you design responsive and cost-effective cloud solutions.
"What if the function called another API inside for each request? How would that affect the time complexity?"