How to reduce costs of Azure subscription

This article describes a way to reduce the cost of a Pay As You Go Azure subscription if you host several applications and the capabilities of the virtual machines (VM) used (CPU and Memory) are excessive to the small load on these applications. It is often useful for early-stage startups hosted on Azure.

Azure has become a very popular platform for hosting applications as a service, as well as for website hosting. Azure attracts users with ease of administration, extensive features, scalability, and stability. Azure is used not only by customers with high-load applications but also by small startups. However, using Azure often turns out to be much more expensive than using an ordinary hosting. For large applications, this is compensated by flexibility and scalability of Azure services, but for small applications, it may become a significant problem.

In practice, there is often a situation where you may need to host several web applications within one Azure subscription. These can be microservices related to the same startup or even different web applications of the same customer. For example:

  • an interactive web site of the product,
  • the product itself (web application),
  • an authorization service (microservice),
  • an integration service (microservice)

The most convenient solution for hosting all applications is to create your own App Service for each application. This will allow administering them independently, publishing them directly from Visual Studio, and easily accessing them and their logs and statistics through Azure Portal.

Every application must run in a service plan that determines the size (CPU and Memory) of VMs used to host that application. Azure allows using the Free and the Shared plans and several paid plans, starting with the Basic one. For more information about the service plans, see the documentation.

For example, for our startup, we need to create 3 applications and place each one as a separate App Service. Let’s create the first application:

Creating the second application:

Creating the third application - in a similar way. Pay attention to the red-highlighted area on each of the forms. By default, Azure suggests creating an individual service plan for each of App Services. Respectively, each application will be hosted on its own VM.

We can choose the Free plan, however, if we make professional applications, then Free and Shared plans are not suitable for us. As you can see from the table below, the Free plan does not allow using SSL and a custom domain name, and the Shared plan does not allow using SSL. In addition, these plans have restriction to the maximum calculation time of 3 minutes and do not allow running WebJobs and enabling the AlwaysOn option. This is described in the App Service Limits section of the Azure documentation.

Actually, after creating apps on the Free plan, we can see the following in the Custom Domains section:

And in the TLS/SSL settings section:

So, we have to use a paid plan.

The cost of the most low-cost Basic plan, which allows using a custom domain name and SSL, as well as WebJobs and has no restrictions to the calculation time is approximately ~$54.75 per month. This plan allows using up to 3 VMs with 1.75 GB of RAM each and a single-core CPU. Prices for Azure.

If we follow Azure Portal recommendations and create three applications with three different the Basic plans, then the total cost of subscription will multiply. For our three applications created on Basic plans, the accumulated cost reaches $100 per month.

You can see in the figure above that when we added the third app (dark blue color), the cost increased by almost a third. Using different App Services on different plans turns out to be not beneficial when applications are recently developed and do not yet have very many real users. The capabilities of the cheapest Basic plan are often excessive for such applications. For example, programmers of our company use a web application called ProjectSputnik written by us for work time logging. The Basic plan for this application is sufficient with a large overabundance, with daily use by 50 users.

As it can be seen in the figure above, in our case, the peak load on the CPU does not exceed 4%, and only 33% of the RAM is used. This is for all the three apps. There is no cheaper plan that meets the criteria for professional hosting in Azure. To solve this problem, we need to host all the three applications on the same VM in order to use Azure resources more efficiently.

To do this, we may:

  • rent a virtual machine and place all the resources on it,
  • use a docker container for applications

These solutions allow hosting web applications on an individual VM. This can be done within the same Azure subscription or by choosing a different hosting. But all this requires additional steps, reduces the ability to scale further, and often requires direct access to the VM via Remote Desktop. In any case, we lose the benefits of using App Services.

But our goal is to maintain the advantages of using separate App Services and, at the same time, to make them hosted on the same virtual machine, for usage of which (i.e. the VM) we’re going to pay.

Fortunately, there is a solution. According to the documentation, Azure runs all applications on the same VM when they run in the same plan and are placed in the same resource group and region.

Since you pay for the computing resources your App Service plan allocates (see How much does my App Service plan cost?), you can potentially save money by putting multiple apps into one App Service plan. You can continue to add apps to an existing plan as long as the plan has enough resources to handle the load. However, keep in mind that apps in the same App Service plan all share the same compute resources.

We advise you to carefully read the above-mentioned documentation to fully understand how Azure uses the VM on different plans.

Thus, to achieve our goal we must:

  • create a single Basic Plan for all App Services
  • create one resource group for all App Services
  • place our App Services into one resource group in one region and assign them the same plan

The plan and the resource group we need can be created directly from the form where we create the first App Service. Next, we create the remaining App Services, specifying the same resource group, region, and the same plan for all applications.

If Azure Portal doesn't show the previously created plan in the other app creation forms, don't forget to select the same region and an Operating System.

As a result, after creating the three applications on the same service plan, we pay only for a single VM.

The subscription cost has been reduced by 1.5 times. In each case, the result depends on the specific resources placed in this resource group and their load. In our case, part of the cost is added by databases.

For sure, when the load on our single VM exceeds its capabilities, we will need:

  • either increase the number of VMs on the plan to distribute the load more evenly,
  • either change the plan to a more productive one,
  • or create a separate plan for the most loaded applications.

For our 3 applications created on the same Basic Plan, the weekly performance metrics for CPU and Memory looks as follows.

As it can be seen from the figure above, about 60% of RAM and 2% of CPU are used on average, with daily peaks of about 50%, in rare cases reaching up to 90%. It follows from the metrics that the single VM has resources to host additional non-intensive applications on it. Also, the graph shows that the use of RAM in percentage terms significantly exceeds the use of CPU. In our case, when the load reaches the limit, setting a separate Basic plan for the selected application seems to be a more rational way to distribute the load compared to choosing a more productive plan. A more productive Standard plan costs 1.5 times more and offers a more productive CPU, but the same 1.75 GB of RAM. The closest plan that offers a larger memory capacity is Premium. It provides 3.50 GB of RAM at a cost of ~$146 per month, i.e., 3 times more expensive than the Basic plan.

In our case, it will be more beneficial to dedicate one more Basic Plan for a separate application. It should be taken into account that it must be a different plan because if we just increase a number of VMs on an existing plan, all the three applications will use all the VMs. If we want a VM to be used by a single application, we need to dedicate a separate plan for it. Azure allows changing the plan for applications if the dedicated plan is located in the same region. Move an app to another App Service plan.

* * *

In this article, we found out that in order to reduce the cost of Azure subscription, we can combine applications into one service plan and one resource group. This is especially true for startups that need the benefits of professional applications (SSL, a custom domain name, WebJobs, AlwaysOn), the load on which is significantly lower than the capabilities of the most low-cost Azure plan.

By: Andrey Antonov