Microsoft Azure provides a powerful set of services to help developers build and deploy their apps. Azure makes it so easy to use that you can quickly let your Azure hosting costs get out of control. However, there are ways to better manage your Azure pricing and optimize your overall costs.

At Stackify, we have been using Azure for over 4 years. We have grown up with Azure as we like to say and leverage a wide array of different Azure services and spend a small fortune on it every year. We are writing this article to share some of our best tips.

Let’s focus on 5 different ways to lower your costs:

How to Lower Microsoft Azure Pricing & Effective Azure Cost Management

One of the easiest things you can do is simply get some discounts on your bill or get something for free!

1. Pre-pay to get a discount, even on a pay-as-you-go account.

Microsoft has offered discounts of 2.5-5% based on 6 or 12 months pre-payment. Check to see if you can take advantage of this. However, an EA agreement may be a better option.

2. Get an EA Agreement for maximum Azure discounts.

EA agreements require selecting an annual monetary commitment and that locks in a discount rate. You are then billed quarterly for any overages beyond your annual commit.

An EA agreement can save you up to 20-30% or so for some Azure products. Be warned, the discounting rate schedules are a mess. Just as an example, your discount rate on SQL Azure could be 5% but Cloud Services could be something like 10-20% and it is different for every single SKU they sell. Some may not offer much of a discount at all. There are thousands of SKUs. So be sure to know what Azure services you really need and maximize the discount on those SKUs in your EA agreement.

3. Can you sign up for Bizspark?

Stackify was originally in Bizspark and was able to get a lot of awesome free benefits. Microsoft advertises up to $120,000 in free benefits for startups. Not a bad deal!

4. Can you switch Azure regions for better azure pricing?

Azure pricing varies from one region to another, even in the US. Double check the pricing in various regions to see if you can save a little.

Example: A2 VM in West US is $133.92 but $126.48 in West US 2. Australia East is $168.14

5. Get free money from Microsoft by working with an Azure partner on a project.

If you have a big project to move to Azure, you can get some discounts to help incentivize and pay for a Microsoft partner to assist making it happen. As one example, we were able to do this to help do a bunch of work with Chef.

Figure Out What Your Current Azure Costs Are and Organize Reporting

Odds are, you don’t know what you don’t know when it comes to how much you are spending and what you are spending it on. It is so easy with Azure to spin up new resources and simply forget about them.

6. Know how much you spend on what, which is hard without a tool for it.

Microsoft has a couple of tools you can use to analyze your billing:

Both of these leave a lot to be desired for any advanced level of reporting. You can connect your EA data to PowerBI which opens up some more opportunities for crunching the data, but you really need to segment the data by project, departments and etc. to get more insights into it.

There are a lot of third party tools available, although appallingly, many of them over $1,000 a month! We recommend using a service called Azure Costs (https://azure-costs.com/) which is inexpensive and does a great job. It has a free tier and paid options from $29 – $199 a month.

Just to give you an idea, you can group the reporting a bunch of different ways to understand if you are spending a lot on VMs, SQL Azure, App Services, etc.

7. Assign Azure spending by project, environment, or client for better reporting.

At Stackify, we host our production, pre-production, QA, development and test apps all with Azure. When looking at our bill at a high level, there is no good way to know how much we are spending on which environment, which is important to us.

How much we spend in production impacts our margins as a business and we want to also minimize costs in dev/test environments.

We use Azure Costs to organize what we are spending money on. We simply tag each Azure resource and then we can get reporting by the tags to easily see expenses per environment.

We can then get reporting by each tag to understand how we are spending our money.

Optimize How You Deploy Your Apps to Save Money on Azure

If you are moving an application to Azure, there are a few ways to save money that you may not even be thinking of. Also want to give you some tips on optimizing App Services, Cloud Services, etc.

8. Pick the right type and size of Virtual Machines.

If you are using Azure for hosting Virtual Machines, make sure you pick the correct type of instance. There are literally dozens of different types and sizes. Make sure you select the right type based on if you need more memory, CPU, faster disk, etc.

9. Use Azure DevTest Labs to ensure test VMs get auto shutdown to save money.

Nothing is more annoying than someone setting up a test server and finding out later you have been paying for it for months and months. Azure DevTest Labs is awesome for creating servers that you need occasionally or just certain hours of the day.

DevTest Labs can automatically turn them on and shut them down on a schedule. This helps a lot with solving the issue of your QA team forgetting to shut down servers before they leave for the day or weekend.

Note: DevTest Labs does not cost anything additional to use. You simply pay for the VMs themselves.

10. Avoid paying for staging slots on Cloud Services.

With Azure Cloud Services for Web and Worker roles, you pay the full price for staging slots just like you do production slots. It is a good idea to deploy to staging slots and then swap staging into production to minimize downtime.

Be sure you delete the staging slots as fast possible. Nothing makes me madder than logging into Azure and seeing a bunch of stuff deployed in staging slots sitting there for no reason.

Edit the view in the Azure Portal to add columns for “Staging” and “Production” so you can quickly see which ones have something in the staging slots. Cloud Services cost you money even if the servers are stopped. You have to delete them!

11. Combine web apps with Azure App Service Plans to reduce server count.

One of the absolute best features of Azure is App Services. You can create an App Service Plan which represents 2-3 or more servers and then pack as many web applications as you want on to them.

This is a huge advantage over paying for an entire server for a web application that hardly does anything. We have used Cloud Service Web Roles forever and in some cases have 3 instances for high availability on a web app that gets virtually no traffic. It is a huge waste.

12. Stop using Cloud Service Web Roles unless you have to.

Unless you have to use Azure Cloud Services for Web Roles, I would work towards switching your apps to App Services to take advantage of combining multiple apps to fewer servers.

Cloud Services also take FOREVER to deploy to. App Services are light years faster for deploying to.

13. Use Azure Service Fabric or Container Service to combine apps.

For the exact same reasons I mention above with App Services and Web roles, look at moving your Worker Roles to Service Fabric or Container Service. Both follow the pattern like App Service Plans where you basically provision a group of servers and then throw a bunch of apps on them.

14. Use auto-scaling to reduce costs during off hours.

Most apps have busier and slower periods throughout a week or day. Take advantage of auto-scaling built into Azure to save some money during slow periods.

These deployment types all support auto-scaling:

Cloud Services

App Services

VM Scale Sets (Including Batch, Service Fabric, Container Service)

Scaling could also mean shutting your app down completely. App Services have a feature called AlwaysOn that controls if the app should shut down due to no activity. You could also schedule shutting down your dev/QA servers with something like DevTest Labs. There are also third party services like Park My Cloud.

15. Use Azure PaaS features; don’t roll your own on VMs unless you have to.

I have talked to several people who use Azure and their version of using Azure is setting up some VMs and hosting their app and SQL Server on those VMs.

Leveraging Azure for virtual machines and IaaS is fine, but you are missing out on a lot of opportunities to reduce management costs and lower Azure costs as a whole. Unless you have a really, really good reason to use SQL in a VM, like buying some third party load balancer running in a VM and other scenarios, just don’t.

At Stackify, we leverage every PaaS feature of Azure we can. That includes SQL Azure, Redis, Table Storage, Service Bus, etc. The thought of setting up VMs for Redis or some other queuing service seems like a really terrible idea. The only exception to that for us is elasticsearch.

Azure Search is available and is a basic elasticsearch PaaS offering. Due to the sheer size and scale of our elasticsearch cluster, it makes more sense to manage it ourselves.

16. Use SQL Elastic Pools.

If you have a lot of databases, you should consider SQL Elastic pools.

With Azure, you have to pick a performance tier for each individual database. This works very well and provides a predictable level of performance. However, it also results in over provisioning performance in a lot of cases.

Think of an Azure SQL Elastic Pool as more of a server and you can get assign a bunch of databases to that server. That allows the performance of each database to ebb and flow within the total resources of the server.

At Stackify every one of our clients has their own SQL databases. We literally have hundreds of them, and we add new ones and de-provision some every single day. SQL Elastic Pools are critical for us to manage that many databases at scale.

Improve the Performance of Your Application Itself

OK, if you have maximized how much you spend on Azure when it comes to your overall Azure pricing and how you deploy your apps, it is time to start doing some performance tuning.

I would suggest using some type of APM tool like Retrace, Azure Application Insights, or New Relic.

17. Time to get out the profilers!

If you want to optimize the performance of your code, you need to do some code profiling. There are three different types of profilers and you may need all three to really improve your code.

Standard profiler – profile your code on your workstation to look for slow methods in your code

Transaction tracing – capture complete web requests via an ASP.NET profiler and review what is happening

APM – Track the overall performance of your application and its dependencies

18. Identify your most used and slowest web requests or transactions.

Look for requests that are taking a lot of time or happen a moderate number of times but take way too long. Look at ASP.NET transaction traces to see if too many SQL queries are happening, slow web services, etc.

Most modern applications are more bound by database or web service calls. If your code itself may be slow, you probably want to use a standard .NET profiler, like the Visual Studio profiler to try and figure out why.

19. Optimize SQL database performance.

Every busy application can usually benefit from some basic SQL tuning. SQL Azure has some great basic functionality for performance reporting and index tuning recommendations.

If you need to go deeper, be sure to query the DMVs in SQL to identify which queries are accessed the most, use the most IO, take the longest, etc. Also, be careful to see how long the queries take from the point of view from your app.

You can also leverage your APM tool to identify which queries are used the most and what actions in your software are calling them.

20. Track usage and performance of all application dependencies.

Beyond just SQL server, your application probably makes web service calls, uses queues, caching, and other dependencies, including other Azure features like DocumentDB, Azure Storage, etc.

Make sure that all of those dependencies are performing well and properly scaled via Azure.



Other Ideas to Lower Azure Costs

Here are some other ideas to consider to help lower how much you are spending on Azure.

21. Can you use a CDN?

A CDN like Cloudflare makes it really easy to add caching of all your static files with no code changes. Cloudflare also has a ton of cool features that can be used to optimize performance.

Azure does have a very simple CDN offering as well that you can try, but it doesn’t do what Cloudflare does.

22. Can you use the new Azure cold storage option?

Azure now offers warm and cold Azure storage. Warm is designed for data that is used frequently and cold is for data that is rarely used. If you have a lot of data that is hardly used, backups, archives, or other data, be sure to check out cold storage.

Optimizing Azure Cloud Hosting Costs

I hope you found this list to be helpful. Be sure to start with some of the simplest ideas to implement and leave optimizing your code for last.

Optimizing your code is by far the hardest part to do and can take an enormous amount of time and regression testing. At Stackify, we have APIs that get called millions and millions of times a day. If you have code that gets called as many times as ours, it is definitely worth investing in the low-level code optimizations, otherwise…maybe not.

Have any other tips on how to save money on your Azure bill? Please tell us in the comments below!







