Save money on Azure with cost analysis and free tools
Microsoft Azure is an awesome cloud platform. We have been hosting elmah.io on Azure since day one. To say that Azure is expensive is probably not fair. But the easy point-and-click interface and the advanced scaling options can quickly cause your bill to grow out of control. In this post, I'll go through some of the things we have done and still do to keep our Azure bill as low as possible.
Let's be honest. I probably cannot help you cut your costs in half (happy if it turns out I can). So, how much money can you save? I'll go the safe road with the commonly used consultant term: it depends. Every application is different and needs different resources and have different needs when needing to scale. What I can do is to introduce you to a range of techniques and tools that will help you figure out if there is something to save. Let's go ahead and look at the possibilities.
Use PaaS over IaaS
I'm starting simple and I hope that you already follow this one. Azure provides a great set of platform-as-a-service options like App Services. An App Service is simply a weird name for either a website or a Function. With App Services, you get Azure to manage the server(s) for you and you can group a lot of websites and Functions on a single server, rather than spinning up expensive virtual machines.
App Services are, of course, hosted on a virtual machine. There can be an advantage in selecting Linux when you create your App Service Plan. Linux virtual machines are a bit cheaper since you don't need to pay for a Windows License as part of the VM.
Other good PaaS examples are Azure Service Bus, Azure Event Grid, and Azure SQL.
Use Azure Functions
This is in the same area as the previous section. I still want to mention Azure Functions as a separate tip, though. You probably need Windows Service-like features as well as scheduled tasks. We have a lot of background processing and tasks, which we ran as Windows Services and Windows Scheduled Tasks on virtual machines in the past. Nowadays, all of this code has been migrated to Azure Functions.
Azure Functions are known as serverless code, meaning that you don't need to worry about servers at all. While this is almost true with websites on Azure too, you still have an App Service Plan, which includes one or more virtual machines. With Consumption-based Functions, Azure will automatically spin up one or more virtual machines in the region(s) you select when code needs to run. This means that you won't even have to pay for a single server when code isn't required to run. Functions for services and scheduled tasks are a great way to save cash.
A lot of resources on Azure provides auto-scaling. Especially if you use the PaaS options as already discussed. Auto-scaling means that you can configure Azure to scale available resources up and down, depending on parameters of your choice. A good example is App Services where you can scale up the number of web servers, depending on the current traffic. Terminating virtual machines when you don't need them, is a great way to save money on Azure.
I've seen it too many times at the larger companies I've worked with. A simple website would start with 5+ servers just in case. With auto-scaling, you are in a position that allows you to not plan too much ahead. I'm not talking about making bad architectural choices here, but more in terms of the number of servers you need. Start with something as simple as using the built-in scaling options to quickly add more or larger servers.
Use free tools in front of Azure
Azure provides tools for the entire stack, including DNS, CDN, SSL certificates, and more. In many cases, these tools will cost you hard-earned cash. Luckily, there are free options available that work great with Azure.
The one I want to mention here is Cloudflare. Cloudflare provides a lot of free tools like DNS and SSL certificates. When using Cloudflare in front of your public Azure resources, they will automatically renew your SSL certificates and provide you with DDoS protection. Everything without you having to pay a penny.
Host content elsewhere
It may seem obvious to host EVERYTHING on Azure once you have selected it as your cloud-platform of choice. But there's no reason not to combine it with something else. In the past, we had our blog and documentation site on Azure. This present day, both sites are hosted elsewhere. The documentation site is generated using the static site generator MkDocs and hosted for free on GitHub Pages. The blog is written in the amazing blogging platform Ghost and hosted on Digital Ocean. Digital Ocean provides very cheap virtual machines compared to Azure.
Buy a Microsoft Action Pack
Getting a good overview of prices from Microsoft can be quite a nightmare. You probably need some Visual Studio licenses and other Microsoft software alongside your Azure hosting. The best deal I have been able to find is the Microsoft Action Pack. It includes Visual Studio licenses for a much lower price than when purchased through MSDN. But even more important, it includes $100 worth of monthly Azure credits. Being priced below $500 yearly, the Azure credits you get with the Action Pack is worth more than the yearly price.
Apply for Microsoft for Startups
In the old days, Microsoft had a program called BizSpark. It was three years of free licenses and $100 worth of monthly Azure credits. As you can imagine, this was a very popular deal and we were a part of this for the first three years too. Sadly, Microsoft replaced BizSpark with the Microsoft for Startups program. While still being pretty awesome, it requires much more from you to get accepted. There doesn't seem to be a complete list of requirements available. But being a newly started company with external investor money available and being part of an incubator is a good starting point.
Get a CSP deal
Microsoft partnered with companies around the world as part of its Cloud Solution Provider program. When enrolling in this program, you will be matched with a local CSP and purchase your Azure resources from them. They again purchase the Azure resources from Microsoft and earn a commission when doing that. The advantage of purchasing resources through a CSP is that you will be able to get an Azure discount. The discount is an overall percentage of your bill. Which percentage you will be able to get, depends on your spending and if you help sell or push Microsoft products. In my experience, you shouldn't necessarily accept the first percentage offered by your CSP. It's a negotiation and they do of course want to earn as much as possible, like you want to save as much as possible.
One thing to be aware of before enrolling with a CSP is that you can no longer get support directly from Microsoft through the portal. Support will be done by your local CSP. That is, of course, part of how they earn some money being the CSP. But if you have Azure competencies in house, you are probably not looking to pay consultants to carry out common Azure maintenance. You have full access to the portal and can do everything yourself. But I have experiences Azure resources being down a couple of times, where my local CSP wanted to send me a bill to look into why it was happening. Another thing to be aware of is that you will not be able to access Cost Analysis in the Azure portal when part of a CSP deal. The local CSP provides a cost tool, but it isn't as good as the one in the Portal.
If you are looking for even more discount than the CSP deal provides, you should look into reserved instances. If you commit to using virtual machines for 1-3 years, there are good percentages (20%+) to save. The longer you commit, the more percentages. You can still scale virtual machines up and down, but you will need to get in contact with your CSP to do that.
Different pricing per region
For some reason, Azure provides different pricing per region. If the region you host in isn't important, you should use the Azure Pricing Calculator to check out different pricing in different regions. Even if you want to host in a specific part of the world, you still have a lot of regions available within a short distance. For example, Azure provides multiple data centers in both West and East US.
Monitoring your costs should probably be the first thing you do. I mention it last since that's also the least concrete advice. The Cost Analysis feature inside the Azure Portal is quite good and shows you on a resource level where you spend your money. As mentioned earlier, you have access to another cost tool if part of a CSP deal. Azure also provides some cost optimization recommendations inside the Portal. In my experience, they are not that useful but may work better with your type of usage so make sure to check it out.
Outside Azure, there are some cost analysis tools available. azure costs, ParkMyCloud Spot Cloud Analyzer, and Cloudyn are some of them. To be honest, I haven't tried any of them but plan to. Some of them provide limited free plans but most require you to pay. Maybe it can turn out a good investment?
elmah.io: Error logging and Uptime Monitoring for your web apps