Implementing Autoscaling for Azure App Service
Learn how to implement autoscaling for Azure App Service using Azure Monitor, Application Insights, and adjustments for web and API apps.
We'll cover the following
While a heavy focus on Kubernetes has been present throughout this course as well as this chapter, we can leverage less complex Platform-as-a-Service (PaaS) components to host our application. Azure App Service offers a much lower barrier to entry than Kubernetes and allows us to craft different service types based on our needs. Autoscaling is one of the many features built into App Service and can be configured through different avenues. Two such avenues are Azure Monitor, the platform-level monitoring and alerting suite, and Application Insights. We’ll also be examining some App Service specifics that can be applied to web apps, as well as API apps.
Common platform options
One of the benefits of using cloud-native platform components is that we can apply them to just about any resource type within the cloud environment we’re using. With Azure Monitor, we can tap into a large ecosystem of monitors, diagnostic information, and alerts to help us proactively and reactively manage our application’s performance, availability, and reliability.
Azure Monitor
There are four main types of conditions that Azure Monitor uses to signal that a potential problem is afoot. These are as follows:
Metric alerts: These are alerts based on a specific metric meeting or exceeding a predefined target value. These would include CPU usage, memory usage, and so on. An added dimension with metric alerts is time. We can set a threshold that invokes an alert if CPU usage crosses 75% over a sustained five-minute period.
Log alerts: These are alerts that look for specific values or strings within Log Analytics that might be indicative of an error or issue.
Activity log alerts: These are alerts that specify when an action or event occurs that’s not allowed or might indicate a compromised system. For example, the Activity log captures information about creating and destroying cloud resources, as well as authentication and auditing infrastructure-level failures.
Smart detection alerts: These are alerts that use the power of machine learning to adapt to our application’s steady state and then use that information to detect anomalies and issue alerts based on those anomalies. Application Insights is one platform component that can utilize smart detection alerts.
While Azure Monitor is not solely about alerting, the ability to measure different platform aspects to determine if a resource needs to be scaled up can be helpful. Alerts can be auto-remediated using action groups, which are Azure constructs allowing for automation to fix issues that bubble up as alerts to the platform. These conditions also factor into the ability to scale App Service, more specifically App Service plans, to match demand. Let’s look at how to configure autoscaling in the next two subsections.
Smart detection alerts are particularly interesting because they allow us to leverage machine learning to detect failures and anomalies in our application with a simple configuration setting. That’s not to say that other implications will not arise—cost, for example, may become a problem, especially if the volume of information that Application Insights is ingesting rises to hundreds of megabytes (MB) or even GB per day. Regardless of volume, we can still glean useful insights from Application Insights coupled with smart detection.
Application Insights
We have already seen how Application Insights offers a wealth of monitors, insights, and data points by simply creating an instance and integrating the SDK into our code base. The additional benefit of using smart detection is that it gives engineers a proactive diagnostic report when anomalies or failures are detected. While the use of smart detection does aid in offering automated alerts, setting up rules to scale other resources based on these alerts might not be practical.
Get hands-on with 1400+ tech skills courses.