Azure Functions can scale out to an extremely large number of instances, potentially running up to 200 instances per function app by default.

Let’s see how this looks in practice with a simple HTTP-triggered function.

using System;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;

public static class HttpTriggerScaleDemo
{
    [FunctionName("HttpTriggerScaleDemo")]
    public static async Task<IActionResult> Run(
        [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req,
        ILogger log)
    {
        log.LogInformation($"C# HTTP trigger function processed a request. Instance ID: {Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID")}");

        // Simulate some work
        await Task.Delay(1000);

        string name = req.Query["name"];
        if (string.IsNullOrEmpty(name))
        {
            name = "World";
        }

        return new OkObjectResult($"Hello, {name}! This is instance {Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID")}.");
    }
}

When you hit this function repeatedly, especially with a load testing tool, Azure Functions will automatically spin up new instances to handle the incoming requests. You can observe this by looking at the WEBSITE_INSTANCE_ID environment variable logged with each request. Each unique ID represents a separate instance of your function app running to serve the traffic. By default, Azure Functions can scale out to 200 instances. This automatic scaling is a core benefit, allowing your application to handle fluctuating demand without manual intervention.

However, this default behavior can sometimes lead to unexpected costs or resource contention if not managed. This is where controlling the maximum number of instances comes in. You can cap the scale-out behavior by setting a specific app setting.

The key app setting is AzureFunctionsMaxInstanceCount. By default, this is not set, allowing the platform to scale up to the maximum allowed (currently 200). If you want to limit the number of instances, you would add this app setting to your Function App configuration.

For example, if you want to ensure your Function App never exceeds 10 instances, you would add an app setting with the key AzureFunctionsMaxInstanceCount and the value 10.

Here’s how you’d do it in the Azure portal:

  1. Navigate to your Function App.
  2. Under Settings, select Configuration.
  3. Go to the Application settings tab.
  4. Click New application setting.
  5. For Name, enter AzureFunctionsMaxInstanceCount.
  6. For Value, enter 10.
  7. Click OK, then Save at the top of the Configuration page.

Alternatively, you can set this using Azure CLI:

az functionapp config appsettings set --name <YourFunctionAppName> --resource-group <YourResourceGroupName> --settings AzureFunctionsMaxInstanceCount=10

Replacing <YourFunctionAppName> and <YourResourceGroupName> with your actual resource names.

Once this setting is applied, the Azure Functions host will stop creating new instances once the count reaches the configured limit. If your application is still receiving more traffic than these instances can handle, requests might start to be rejected or experience longer response times, as the scaling mechanism will no longer add more capacity. This provides a hard cap on the number of compute instances your function app can utilize, which is crucial for cost management and preventing runaway scaling in certain scenarios.

The one thing most people don’t realize is that AzureFunctionsMaxInstanceCount is a hard limit imposed by the host. It doesn’t just influence the scaling logic; it actively prevents the creation of new instances beyond the specified number, regardless of the incoming load. This means that if your application’s performance degrades under load once this limit is hit, it’s a clear signal that you’ve reached the maximum capacity you’ve allocated for this function app.

The next logical step after controlling instance count is to understand how to monitor your function app’s scaling behavior and performance metrics to ensure you’ve set an appropriate limit.

Want structured learning?

Take the full Azure-functions course →