Microsoft Docs

Scaling Azure App Service

Azure App Service provides powerful capabilities for automatically scaling your web applications up or out to meet demand. Understanding how to configure and manage scaling is crucial for ensuring performance, availability, and cost-effectiveness.

Understanding Scaling Concepts

There are two primary types of scaling in Azure App Service:

Automatic Scaling Rules

Azure App Service allows you to configure automatic scaling rules based on various metrics. These rules enable your app to adjust its instance count dynamically without manual intervention.

Common Metrics for Scaling:

Configuring Automatic Scaling in the Azure Portal:

  1. Navigate to your App Service in the Azure portal.
  2. In the left-hand menu, under "Settings," select "Scale out (App Service plan)."
  3. Choose between "Manual scale" and "Custom autoscale."
  4. For "Custom autoscale," define your rules. You can set minimum and maximum instance counts and specify trigger conditions based on metrics.
  5. You can also configure a default capacity for when no rules are met.
Note: When setting autoscale rules, consider setting a cooldown period. This prevents rapid scaling up and down, which can be resource-intensive and lead to instability.

Manual Scaling

While automatic scaling is often preferred, manual scaling provides direct control over your instance count. This is useful for predictable traffic patterns or during planned maintenance.

To scale manually:

  1. Navigate to your App Service.
  2. Go to "Scale out (App Service plan)."
  3. Select "Manual scale."
  4. Enter the desired number of instances.
  5. Click "Save."

Best Practices for Scaling

Example Autoscale Rule

Consider a rule that scales out your app when the average CPU percentage goes above 70% for 10 minutes, and scales in when it drops below 30% for 15 minutes. This helps to maintain performance during peak loads while conserving resources during quieter periods.


// Example configuration snippet (conceptual, not actual API)
{
  "autoscaleSettings": {
    "minCapacity": 1,
    "maxCapacity": 10,
    "defaultCapacity": 2,
    "rules": [
      {
        "name": "ScaleOutOnCpu",
        "description": "Scale out when CPU > 70%",
        "scaleAction": {
          "direction": "Increase",
          "value": "1",
          "count": 1
        },
        "metricTrigger": {
          "metricName": "CpuPercentage",
          "statistic": "Average",
          "timeAggregation": "PT10M", // 10 minutes
          "threshold": 70
        }
      },
      {
        "name": "ScaleInOnCpu",
        "description": "Scale in when CPU < 30%",
        "scaleAction": {
          "direction": "Decrease",
          "value": "1",
          "count": 1
        },
        "metricTrigger": {
          "metricName": "CpuPercentage",
          "statistic": "Average",
          "timeAggregation": "PT15M", // 15 minutes
          "threshold": 30
        }
      }
    ]
  }
}
            
Tip: Use Azure Monitor to create custom metrics that can be used for more granular autoscale control.