A Comprehensive List of Tips for Saving Money on your Microsoft Azure Costs in 2020
Tags: azure, devops
Published: 2020-06-11 14:48:17

Ideas that would help all Azure Cloud customers from freelance developers to small to mid-size companies on reducing operational costs

## Table Of Contents
  * [Introduction](#Introduction)
  * [Types Of Cloud Services And Their Pricing Models](#Types Of Cloud Services)
    * [IaaS - Infrastructure as a Service](#IaaS)
    * [PaaS - Platform as a Service](#PaaS)
    * [SaaS - Software as a Service](#SaaS)
  * [Technical Recommendations](#Technical Recommendations)
    * [1- Subscription, Resource Groups and Tagging for Cost Management](#t1)
    * [2- Virtual Machines](#t2)
    * [3- Azure Free Offerings](#t3)
    * [4- Infrastructure as Code Parameterize Cost Components](#t4)
    * [5- Make Sure You Are Paying the Right Prices](#t5)
    * [6- Cost Analysis Tool is Your Friend](#t6)
  * [Organisational Recommendations](#Organisational Recommendations)
    * [7- Cost Saving via Automation and DevOps](#t7)
    * [8- Migrate to PaaS or Container Based Workloads](#t7)
    * [9- Use Linux and and Open Source Frameworks](#t7)
    * [10- Consider SaaS in Your Architecture, Don’t Reinvent the Wheel](#t7)
    * [11- Pick Your Azure Region Wisely](#t7)
  * [Conclusion](#Conclusion)


## Introduction  <a name="Introduction"></a>

Keeping operations costs in check was always an organisational goal for all kinds of businesses. Whether smallest micro businesses or large scale businesses, without a proper plan cloud bills can pile up and in no time you might think yourself, do we really get the value for the $ X amount we are paying each month to our cloud provider. Although it was always a concern, due to COVID-19 and it's implications to global economy optimizing costs for businesses is even more important during this phase.

I will provide some tips in this article that either I've picked up over the years, or just common sense but sometimes forgotten or just pushed back into the backlog for someone to 'never' pickup. Although this article is targeting specifically Microsoft Azure Cloud platform, tips here can be applied to other cloud providers like, AWS or GCP where pricing structure for the service is similar.

> __Disclaimer__: Tips I will provide are targeted for cost optimization. How to achieve similar organisational goals with less money spent. By nature, like all things in engineering by saving money in some cases you will be shifting away from best practices. For these cases, I will point out the drawbacks with that relevant cost saving tip.

## Types Of Cloud Services And Their Pricing Models <a name="Types Of Cloud Services"></a>

In order to understand how we can reduce our Azure costs, first of all let's breakdown how cloud providers in our case Azure calculates costs and charges you accordingly. You have probably heard about IaaS(Infrastructure as a Service), PaaS(Platform as a Service) and SaaS(Software as a Service).

Let's have a look at what they are, with a short explanation of them and how are they priced. Please know that, these categorizations are actually not fitting the modern cloud services today perfectly as there are new models evolving every day, for now though just know that they are not exclusive to each other and most of the time these types of services either run on or with, integrates to, or require one or more of each other to form a fully functional end to end solution together.  

### IaaS - Infrastructure as a Service <a name="IaaS"></a>

Virtualized Compute, Storage and Networking infrastructure hosted by the cloud provider. Some good examples for an IaaS in Azure are Azure Virtual Machines, Storage Accounts, Virtual Network and Load Balancers. You have the ownership and flexibility to customize it as much as you want within the boundaries of the cloud provider.


<!-- Image: What is IaaS -->

<!-- Dev.to Format -->
 ![what-is-iaas](https://dev-to-uploads.s3.amazonaws.com/i/bcx9sf7hyrq5v5qol09h.png)
<figcaption>What is IaaS? - ImageSource: <a href="https://azure.microsoft.com/en-in/overview/what-is-iaas/">https://azure.microsoft.com/en-in/overview/what-is-iaas/</a> </figcaption>

#### How do you get charged for IaaS ?

- per vCPUs active (only while running where applicable like Virtual Machines)
- Networking Throughput
- Network: Public IP Address allocation (Static or Dynamic)
- Storage CRUD Operations (Create,Read, Update, Delete)
- Storage charge for amount of data stored in GBs.
- Software Licensing Costs (either BYOL or Pay-as-you-Go model)

### PaaS - Platform as a Service

An extendible platform hosted and managed by the cloud provider. Good examples of PaaS services in Azure are, Azure App Services (Web Apps and Function Apps), Azure SQL, CosmosDB (No-SQL). These services by themselves only provide a platform for developers to develop their applications. Out of the box, they have no value, but they are building blocks for micro services based cloud architectures today.

<!-- Image: What is PaaS -->
<!-- Dev.To Format -->
![what-is-paas](https://dev-to-uploads.s3.amazonaws.com/i/nlusjfkakiqhh9jbqmch.png)
<figcaption>What is PaaS? - ImageSource: <a href="https://azure.microsoft.com/en-in/overview/what-is-paas/">https://azure.microsoft.com/en-in/overview/what-is-paas/</a> </figcaption>

#### How do you get charged for PaaS ?  

- Pricing Tiers that consist a matrix of feature sets below. 
  - Power/Capacity: Usually a bundled metric value that is formulated based on Compute, Storage and   Network performance capacity. Some examples to these are [ACU for Virtual Machines and AppServices(Azure Compute Unit)](https://docs.microsoft.com/en-us/azure/virtual-machines/acu), [DTU for Azure SQL Databases(Database Transaction Unit)](https://docs.microsoft.com/en-us/azure/azure-sql/database/service-tiers-dtu#single-database-dtu-and-storage-limits), [RU for Cosmos DB (Request Unit)](https://docs.microsoft.com/en-us/azure/cosmos-db/request-units)
  - SLAs (Uptime, Redundancy, Availability)
  - Extra features (Custom Domain hostname, TLS/SSL bindings, Automated backups, Staging Slots)      - Level of Infrastructure Isolation you are getting within the Azure Stack. Bear in mind though, Isolated in this context means you are getting dedicated virtual infrastructure inside an Azure DataCenter. There are security benefits with this and actually in some compliance cases it's a strict requirement to use isolated tier's of PaaS.
- Stamp: The management fee and other supporting infrastructure costs for the Cloud provider to allocate a resource to you. Usually this is waived if you are on any tier which is shared infrastructure (non isolated tiers), the patching, networking, default DNS and internet routing and all of those cloud convinience are profitable as long as you share hardware, hence some resources has a flat fee accompanied to it. 

### SaaS - Software as a Service

Hosted and Managed Software solutions that requires minimum Admin effort as possible. Very good examples for SaaS are [Microsoft 365 (formerly known as Office 365)](https://www.microsoft.com/en-au/microsoft-365/explore-microsoft-365-for-home), [Azure DevOps Services](https://azure.microsoft.com/en-us/services/devops/)

__Office 365__ provides business operations tools for collaboration either in regular day to day operations such as e-mail, identity management, file-sharing , instant messaging etc.

__Azure DevOps Services__, provides an all in one solution for technology organisations, from project management, source code management, CI/CD pipeline automation, artifact repositories and more. 

SaaS solutions are by nature mostly hosted for the management and core functionality planes, however some of them can make use of your own compute resources via agents.

<!-- Image: What is SaaS -->
<!-- Dev.to Format -->
![what-is-paas](https://dev-to-uploads.s3.amazonaws.com/i/k7cf32lgh3xigzpm5eut.png)
<figcaption>What is SaaS? - ImageSource: <a href="https://azure.microsoft.com/en-in/overview/what-is-saas/">https://azure.microsoft.com/en-in/overview/what-is-saas/</a> </figcaption>

#### How do you get charged for SaaS ?

- Subscription based model charged per number of users
- Subscription Feature Level  

Now that we've seen how are we getting charged, the recommendations below will make sense more, and you would be able to understand why it provides a cost saving.

## Technical Recommendations  <a name="Technical Recommendations"></a>

### 1- Subscription, Resource Groups and Tagging for Cost Management <a name="t1"></a>

#### Azure Subscriptions

Subscription is the billing scope for Azure. You are receiving invoices from Azure per Subscription you have with them. It is also the top-level security domain for accessing resources.  

In Azure an Azure AD directory can be shared by multiple Azure subscriptions so you can divide down your payment scoped into subscriptions. The structure should be based on your security boundaries in terms of who gets access where and also how to do you want to track costs.  

One sample structure can be:  

| Subscription No | Subscription Name       |
|-----------------|-------------------------|
|        1        | IT Operations           |
|        2        | Project 1 - Development |
|        3        | Project 1 - Test        |
|        4        | Project 1- Staging      |
|        5        | Project 1 - Production  |
|        6        | Project 2 - Development |
|        7        | .... |
|        8        | .... |

The structure should meet your own security boundaries and cost analysis scope.  

What this type of structure will allow you to do is:  

- Easily identify how much of your Azure cost is for IT operations and Development Operations.  
- Provide both security and cost management layers in different phases of of the Software Delivery Lifecycle.
  You can tell how much each particular stage is costing you in general.  

#### Resource Groups

Resource groups are logical container for Azure resources, they are also the next level of scope in terms of security and cost analysis.  

You should ideally have a naming convention that works for you that is repeatable and consistent amongst the company as much as possible. This would allow for easier automation via tokens and patterns.  

Some things you may consider putting in your naming convention are: short code for Projects, Name, Stage, Geographical region, service name / function served within the project.  

So you can come up with something like: __"{Project}-{Stage}-{Location}-{Service}"__.  
There is a limit on how long you can name a resource group so choose some abbreviations for above fields. An example may be __mert-dev-aus-web__, __mert-dev-aus-sql__, __mert-dev-aus-ops__ and if we deploy our WebApplication to __-web__ and our sql database to __-sql__ and lastly our monitoring assets to __-ops__ resource groups, then we can identify exactly that component of our project is responsible for the overall cost.  

Identifying the redundant costs are the first step to reduce the costs and getting some quick wins.  

#### Tags

Tags are metadata you can assign to your resources to be able to give them more context than their resource name alone. These tags can also help you create advanced reports on your costs analysis. Tags can also be targeted to filter a group of resource we can target to either stop/deallocate or scale down to save costs in an automated fashion.  

Make sure you apply appropriate tags to your resources, while creating your Infrastructure as Code templates. 

### 2- Virtual Machines  <a name="t2"></a>

#### Right Size and Right Region your Virtual Machines

Azure VMs comes in different sizes and pricing families, watch your metrics and see if you are really utilizing the compute power of your virtual machine.  

#### Consider B-Series VMs

B-series stands for burstable series, and designed for workload that doesn't require full performance of it's CPU power with occasional high loads. Study your patterns and see where ever you can use B-series VMs as they work with a accumulating credit and burn on load mechanism they are providing cost savings by design compared to other dedicated vCPU capacity virtual machine families.  

#### Use an Automated Start-Stop Solution

This is critical and if you are not doing anything to reduce your cloud bills you should do this. Virtual Machines that are not used out of business hours should be kept in stopped (deallocated) state for them to stop the vCPU costs.  

If you have no auto-shutdown solution in-place the moment, just this tip will save you a significant amount.  

Let's have a look at the numbers, let's say you have 1 VM that costs 1 unit per hour. There is 720 hours in a month, and without anything your bill will be 720 unit a month.

Just by automatically shutting down the VMs over the weekends you are saving 248 hours. Your monthly billed hours for this Virtual Machine will be reduce by %34.5 imagine you are reducing 8 full days and some time from Friday afternoon and Monday mornings.  

Let's also shutdown all the VMs that is not needed out of business hours such as a build agent. You may have a dedicated agent to run your nightly jobs but you may be able to turn off all the rest of the agents outside of the business hours. If we keep a VM on for 10 hours (2 hour buffer for Time Savings). In a month you will have %65.5 reduction compared to 720 hours billed.  

Let's look at numbers again in the table below:

| Virtual Machine Daily Availability Requirement |          Automated Start Stop Solution Implemented          | Hours Saved | Number of Hours Running/Month |  Monthly Total Hours Billed | Savings |
|:----------------------------------------------:|:-----------------------------------------------------------:|:-----------:|-------------------------------|:-------------:|-----------|
| Always Running - 24 Hours                      | None                                                        | 0           | 720                           |720            | 0         |
| Only Needed During WeekDays - 24 hours         | Stop on Friday UTC 08:00 and Start on Monday UTC 22:00      | 248         | 472                           | 472           | %34.5     |
| Only Needed During Weekdays for 10 hours       | Monday to Friday --> Start at UTC 22:00 , Stop at UTC 08:00 | 472         | 248                           |248            | %65.5     |

As you can see it's imperative to make use of pay as much as you use model of cloud computing, the savings are too big to ignore.  
##### Things to Consider

There are some things to consider while implementing a Auto Start Stop solution.

- Make sure services you want your Virtual Machine to run can start automatically without any problems. If you need to manually fix the machines each time they start, then it's actually counter productive. One way to make sure you achieve this state is to provision and configure your Virtual Machines with Infrastructure as Code and Configuration as Code tools from the start, this would force you to have system that can be fully automated.

- Make sure it's safe to shutdown your VMs for managed resource groups such as an Azure Kubernetes Cluster. You don't want to put your cluster in an inconsistent state. Your best case for these type of services is to treat them as disposable and destroy re-provision them in an automated fashion when needed.

- Treat your automation project as another software project, you should have a proper verification mechanism in-place such as notifications and alerts, test your automation workflow continuously with automated tests to make sure you are not causing any blockers to the business.

##### Solutions you can use

###### Azure MarketPlace Start/Stop VMs during off-hours Solution

Lucky for you, Azure already provides a solution for you, free of charge. It is an all-in-one solution that provides notifications and logging.  

Click [here](https://azuremarketplace.microsoft.com/en-us/marketplace/apps/Microsoft.StartStopVMSolution) to go to solution's marketplace page.  

<!-- Image: Azure-Market-Place-Start-Stop.png -->
<!-- Dev.to Format -->
![Azure-Market-Place-Start-Stop](https://dev-to-uploads.s3.amazonaws.com/i/ur6dc4clbg8mztrsl1xq.png)
<figcaption>Azure MarketPlace Start/Stop VMs during off-hours Solution</figcaption>

<!-- Image: Azure-Market-Place-Start-Stop-Reviews.png -->
<!-- Dev.to Format -->
![Azure-Market-Place-Start-Stop-Reviews](https://dev-to-uploads.s3.amazonaws.com/i/v6i0hsfo0tubrffwmg0w.png)
<figcaption>Azure MarketPlace Start/Stop VMs during off-hours Solution Reviews</figcaption>

But as all solutions there is no one size fits all. As you can see from the reviews, this solution still requires some initial setup and it allows for limited functionality out of the box. Make sure you have some knowledge on Azure Automation account so you can configure and tweak this solution as per your needs. I had tweaked this solution to work as Monday Start and Friday Stop type of schedule in the past, so I know it is possible.

###### Write your Own Serverless Automation with Azure Functions

Did you know that you can now run PowerShell Core on Azure Functions? Yes you can, It was in preview for a time but now it's generally available. That means you have access to PowerShell Az module inside the Azure Function runtime that opens a door for all types of Azure automation solutions.  

There is already a solution you can find here: [https://serverlesslibrary.net/sample/24000d65-f927-4f6a-bdcc-e20b112e8fa9](https://serverlesslibrary.net/sample/24000d65-f927-4f6a-bdcc-e20b112e8fa9)  

You can use this solution as a baseline and develop your own custom one; add logging and monitoring components and you can have your own solution that fits your needs exactly.  

Obviously PowerShell is not your only option here regarding programming language, you can pick any language you are comfortable with and still achieve the same automation via Azure SDK.  

#### Snapshot Virtual Machine Hard Disks

Sometimes, there are some virtual machines I've seen that that is only needed every once in a while. Even after stopping your Virtual Machine, there is still things you can reduce costs even more. Managed Disks costs more than Disk Snapshots. If you are only going to need a Virtual Machine not too frequently consider converting it's disk to a disk snapshot and deleting the disk afterwards. You can then create a disk from the snapshot attach it to the Virtual Machine and run it as before.  

Click [here](https://docs.microsoft.com/en-us/azure/virtual-machines/windows/managed-disks-overview#managed-disk-snapshots) to read more on __Azure Managed Disk Snapshots__  

#### Don't use Virtual Machines

Ok, I understand that you need Virtual Machines, but question is do you really? Above all of the costs, Virtual Machines adds to overall admin effort to maintain systems, they are harder to scale efficiently as increments are larger.  

Instead, investigate if you can opt-out for PaaS services, or if you can containerize the services that runs on the Virtual Machines. Migrating workloads to containers is a guaranteed way to perform same functions with less hardware due to it's unique virtualization design, where containers share the Operating System kernel.

### 3- Azure Free Offerings  <a name="t3"></a>

One problem with PaaS services are, for some of them you can't really stop or deallocate your resources fully to save yourself from costs completely. Instead what you can do is make use of free tiers of these PaaS service.  

#### App Service Plan Free Tier

You know you can change your App Service Plan to a free plan. This plan allows for 1 hours daily vCPU time and most basic functionality but we are not really interested in it's features, in this case we are mostly interested that, it's free.  

There are some limitations of Azure App Service Plan Free Tier. Free tier doesn't support, custom domains, staging slots, 64-bit workers and Always Running setting.  

I know that is a bit of a restriction but the app services can be downscaled and upscale to standard and premium tiers by power of automation. I don't suggest downscaling all your App Service plans to F1 but again this is a cost saving practice that should be used for stale resources.

#### Azure SQL Free Tier

Did you know that Azure SQL had a free tier, almost same as the Basic tier. You can use this tier for your development and proof of concept databases.

<!-- Image: Azure-SQL-Free-Tier.png -->
<!-- Dev.to Format -->
![Azure-SQL-Free-Tier](https://dev-to-uploads.s3.amazonaws.com/i/ee7r6j8cx1ino4f8nmb9.png)
<figcaption>Azure SQL Free Tier</figcaption>

#### Azure Cosmos DB Free Tier

Microsoft recently made a Cosmos Database Free tier available.  

> Azure Cosmos DB free tier makes it easy to get started, develop and test your applications, or even run small production workloads for free. You'll get the first 400 RU/s and 5 GB of storage in the account free. You can also create a shared throughput database with 25 containers that share 400 RU/s at the database level, all covered by free tier.

You can read more [here](https://docs.microsoft.com/en-us/azure/cosmos-db/optimize-dev-test#azure-cosmos-db-free-tier).

#### Azure Static Web Apps (Public Preview)

Azure recently launched a new service in public preview called Azure Static Web Apps. This is a great solution for developing JavaScript web applications as it takes care of automated build and deploy upon a push to your designated branch. The service automatically takes care of the CDN endpoint setup and give you a control dashboard that allows you to manage all aspect of your website like custom domains, deployments, staging environment and a linked function app where you can add backend APIs.

It is designed to work with Github Actions hence only supports Github hosted git repositories. During previews, it's completely free but I believe there will be some sort of free tier after the preview as there are major competitors to Azure that provides this service for free.  

<!-- Image: static-apps-overview.png -->
<!-- Dev.to Format -->
![Static Web Apps](https://dev-to-uploads.s3.amazonaws.com/i/rmu7najd347ncossj063.png)
<figcaption>Static Web Apps - ImageSource: <a href="https://azure.microsoft.com/en-in/overview/what-is-saas/">https://docs.microsoft.com/en-us/azure/static-web-apps/overview/</a> </figcaption>

To read more on __Azure Static Web Apps__, [click here](https://docs.microsoft.com/en-us/azure/static-web-apps/overview).  

#### Azure DevOps for Hosted CI/CD

What about CI/CD? Azure's answer to CI/CD is actually just a feature set of Azure DevOps Services. You can start using Azure DevOps in free tier and get benefit of all it's functionality. Free tier is great for small start-ups, freelancers, students and for any professional for their personal pet projects..

Paid or free, organisations still takes advantage of the free usage quotas. If you are using Azure, Azure DevOps is the best tool for CI/CD integration.  

> Q: Can I use Azure DevOps for free?
>
> A: Yes. You can use Azure DevOps up to the free tier limits for your organization, listed as follows:
> - Five Azure DevOps users (Basic)
> - Free tier of Microsoft-hosted CI/CD (one concurrent job, up to 30 hours per month)
> - 2GB of Azure Artifacts storage
> - One self-hosted CI/CD concurrent job
> - 20,000 virtual user minutes of cloud-based load testing

Source: [https://docs.microsoft.com/en-us/azure/devops/organizations/billing/billing-faq?view=azure-devops&tabs=new-nav#q-can-i-use-azure-devops-for-free](https://docs.microsoft.com/en-us/azure/devops/organizations/billing/billing-faq?view=azure-devops&tabs=new-nav#q-can-i-use-azure-devops-for-free)

##### More Than 5 Users? Take Advantage of Your Visual Studio Subscription Benefits

For organisations who needs more than 5 users, if you are purchasing Visual Studio Subscriptions for your developers, make sure you are making use of their Azure DevOps benefits. You may be paying both for Visual Studio Subscription and Azure DevOps add-on user fee.  

To see if you are eligible for Azure DevOps benefits through your Visual Studio Subscription, [read more here.](https://docs.microsoft.com/en-us/visualstudio/subscriptions/vs-azure-devops)  

Also make sure you make use of the 5 free users wisely. Some high level stakeholders might have enough features for what they intend to do on Azure DevOps with __Stakeholder__ access level, which is free and unlimited. For example some non-engineering business side users might just need access to see some dashboards or project boards, __Stakeholder__level access should be enough for them. Use your free quota on project contributor staff.  

##### Azure Credits for Visual Studio Subscriptions

Each level of Visual Studio subscription also comes with monthly Azure credits, where subscription user can initiate an Azure subscription that will be loaded with credits depending on the Visual Studio subscription.  

These subscriptions can be used for Proof of Concept implementations and Load testing scenarios without worrying about costs. The value of credit is subject to change, but as of writing this one can get from $50-$150 according to [Microsoft documentation.](https://docs.microsoft.com/en-au/visualstudio/subscriptions/vs-azure#eligibility)

##### Practice Efficient CI/CD

30 hours to use for build and release pipelines in Azure DevOps, pretty sweet deal right? Well not if you are not practicing efficient CI(Continuos Integration)/CD(Continuos Delivery).  

You need to follow one DevOps rule of thumb to minimize redundant workload for your pipeline agents which is __"Build Once Deploy Many".__

- Manage your automated build/CI pipeline triggers wisely, you don't want to build more than you need.  
- Enable __"Batch changes while a build is in progress"__ option to reduce number of CI build you are performing.
- Make sure you adhere to Build Once Deploy Many guideline, you should not be needing more than one version of your build artifact, every other environment parameter should be configurable via configuration.
- Break down your solution into smaller repositories, build and publish them to an artifact feed such as as NuGet or Yarn, you can then reference and consume your artifacts via this artifact feed. This would save you from not building a humongous solution each time, instead you will have modular building blocks.  

#### Azure Always Free Services

You can find the full list of services that are labeled as __"Always Free"__ in Azure, click [here](https://azure.microsoft.com/en-us/free/free-account-faq/) to find the full list.

There are couple of things to consider to make the most out of these free quotas:

- Learn what network operations free and what type of them are billed. Choose your resource locations within the same Azure region to make the most out of free network quota
- There is a free ingestion and retention limit for Log Analytics Workspaces. You have the first 5GB for free, you can set a daily ingestion threshold for your Dev/Test loads to never exceed free quota.
- Application Insights is similar to Log Analytics Workspaces, learn how much of usage is free and force yourself to stay under those limits by enforcing daily ingestion quotas.

### 4- Infrastructure as Code Parameterize Cost Components <a name="t4"></a>

I know I've talked about Infrastructure as Code couple of times by now, but it's so important it needs it's own section. here are some key points you would like to make sure you are doing to make sure you are setting up yourself for success.  

#### Conditional Resources

You don't need same level of uptime, logging level and other features configured exactly the same for all stages of your environments. For example audit logging for some services would be only required for Production workloads, so no need to deploy those extra costs to anywhere but Production.  

Use the logical functionalities of the tool of your choosing and make some of the resources only deployed conditionally based on parameters to avoid deploying unnecessary infrastructure or integration in environments that is not needed.

ARM Templates has __conditions__ you can use to achieve the described outcome above. To learn more about the conditions in ARM templates, please click [here](https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/template-tutorial-use-conditions).

#### SKUs and Pricing Tiers In Your Infrastructure Code

Make sure you don't hard code these cost defining values to you can change them quickly either in your code or override them in your CI/CD pipeline as needed.

#### Tagging

This is very critical, as tagging is the best way to filter certain resources easily. Make sure to add tagging to your Infrastructure code so you can use them later on during your cost reduction efforts.  

By help of tags:  

- You can generate tag based Cost Analysis reports that would be normally unavailable with preset grouping options
- You can define uptime requirements that can be later on targeted by auto start stop scripts. By using tags, you can keep your automation logic universal and define behaviour based on tags. This way, if you follow a tag pattern you wouldn't have to update your automation schedule as it will scale out with tags. 
- Sometimes, some of the resources are only needed for a certain amount of time, it's hard to keep track of them manually. Instead you can tag your resources with an expiry date and scan your resources nightly to remove to be expired resources. This would ensure you keep a lean and minimum possible infrastructure footprint.  

### 5- Make Sure You Are Paying the Right Prices <a name="t5"></a>

#### Partner up with Microsoft

If you are dedicated in your Azure usage, if you are sure you are not going anywhere else and you have a significant amount of usage, maybe it's time to look into a commercial licensing agreement with Microsoft.

You can see all list of offers [here.](https://www.microsoft.com/en-us/Licensing/licensing-programs/licensing-programs)
You will get access to locked-in prices, which are cheaper than Pay as you Go prices.  

#### Consider Azure Reservations

You can save up to %72 on your costs with Azure Reservations. Azure offers 1 year and 3 year reservation options for various resources. You will need to make payments upfront to gain these big discounts.

Check out the full list of resource types you can use Azure Reservations with and relevant details [here.](https://docs.microsoft.com/en-us/azure/cost-management-billing/reservations/save-compute-costs-reservations#charges-covered-by-reservation).

Azure Advisor automatically gives you recommendations for Virtual Machine reservations based on your usage. To determine how to calculate reservations for other types of resource, please refer [here.](https://docs.microsoft.com/en-us/azure/cost-management-billing/reservations/determine-reservation-purchase)

### 6- Cost Analysis Tool is Your Friend <a name="t6"></a>

If it's the first time you are looking at your Azure bill, you are most likely confused. The resources are billed by different meter types which are not to easy to figure our from the get go.  

Learn how to use this tool, and try to understand how your Azure resource configuration reflects on your monthly bills. You can use different views and filtered graphs to deep dive on your Azure spendings. 

I urge everyone to read their [documentation](https://docs.microsoft.com/en-us/azure/cost-management-billing/costs/quick-acm-cost-analysis) to get a good understanding of Azure billing concepts. 

You can also set budgets for Subscription or Resource group scopes with alert notifications on certain thresholds. Make sure you make use of them to avoid unexpected surprises.

## Organisational Recommendations <a name="Organisational Recommendations"></a>

### 7- Cost Saving via Automation and DevOps <a name="t7"></a>

#### Embedded DevOps Model & Continuos Collaboration

- Make your whole team practice DevOps, Developers should also think about cost component while developing applications as well as operations of their service.
- COGS (Cost of Goods Sold) should be considered in all aspects of the service being delivered. Lean structure should be followed from service software architecture, tooling & technology selection, pipeline and long term operations. Aim for simple, precise and scalable processes. Think overall integration while planning for any piece of workflow in your software delivery lifecycle.
- Promote transparency in your organisation to break down silos, use collaboration tools like Office 365, Jira/Confluence, Azure DevOps to document for tracking your projects but most importantly you make everyone else in the company to able to see a trace of the project steps. Make wikis, repositories, pipelines everything readable to everyone so the knowledge can flow through the company with ease. This level of harmonious culture or pursuit of it should eventually manifest itself as improved efficiency in overall operations hence cost reductions.

#### Infrastructure as Code and Automation

- Start using, Infrastructure as Code to complement and assist your LEAN, efficient Azure footprint. Automate your infrastructure provisioning and configuration to the point that you can create your whole infrastructure as fast as Azure can provision them. This would allow you to destroy them when needed without any consequences.
- Don't invest in active Disaster Recovery compute resources that are sitting idle for an active passive failover type DR plan. This is not cloud way of doing things. Make sure you pick an enough redundancy level for your Production data tier, but don't keep and idle DR compute resources. Unless you need an absolute 7/24/365 uptime, you can plan provisioning a new DR environment in a new Azure region via your CI/CD pipelines. Plan how to recover your data and point new compute resources to your data in case of a major outage.  

#### Separate your IT Operations from Development Operations

- Define clear separations between your Business IT Infrastructure Operations and your Development and Production Infrastructure Operations. The systems you use for developing and hosting your software should be as detached as your IT Infrastructure as possible. Although, there is definitely a huge overlap, the methodologies DevOps practice is using to develop, test and deploy infrastructure as different an traditional IT department and this is normal. However, having these two team sharing services or integrating a development service to a IT managed resource would cause inefficiency and delay. Try to bring the overlap to a minimum and make sure your software development practice can operate in sovereignty.

### 8- Migrate to PaaS or Container Based Workloads <a name="t8"></a>

You can't really be efficient on cloud, without taking full advantage of cloud. Containers are very lightweight way of packaging your applications with all dependencies and this should definitely be considered going forward for reducing overall compute power needed to run your services.

You should also consider PaaS, especially serverless modelled PaaS services. The serverless compute model is definitely great for running our code in cloud, however what's new is now it's becoming more available for database services. By decoupling persistent data storage component and attaching to this data via a dynamic compute resource. This would bring great costs savings for random accessed services as you would only be charged as much as you use your database instead of paying a flat monthly fee.  

These are just some examples, cloud products and services evolves everyday, so make sure you are up to speed and making use of the most advantageous architecture and technology stack that fits your needs.  

### 9- Use Linux and and Open Source Frameworks <a name="t9"></a>

Consider eliminating Windows from your application infrastructure wherever possible to avoid licensing costs. Most of the frameworks today are open source and cross-platform.  
Even Microsoft's own baby, .NET Core is cross-platform, meaning you can run it on Linux.  

So I would recommend using Linux to avoid Windows Operating System licensing costs. If you are following Microsoft, lately they showed a great effort to both support Linux on Azure and making collaborating with Linux distribution publishers such as Canonical (Ubuntu)

#### Use Let's Encrypt to get your SSL Certificate's for Free for your Non Production Environments

If you want to use custom domain, you also need to bring your own SSL certificate. Let's Encrypt allows you to provision publicly trusted SSL certificates for free. Let's Encrypt makes the domain validation via couple of methods which are all programmatically, due to this automated validation certificates are provisioned for 90 days validity, and you can't get wildcard certificates.

There are multiple ways to automate this SSL certificate renewal which effectively takes care of the SSL certificate costs for most use cases.

### 10- Consider SaaS in Your Architecture, Don't Reinvent the Wheel <a name="t10"></a>

If you are in need of a particular service like Identity Access Management or a very good CRM, it may be better to look at options like market leader SaaS providers Auth0 and Salesforce. If there is product that does something you need for cheaper, there is no need to building it in house. Don't try to do everything in house, people are the most important assets so try to lower long term efforts wherever possible. Using an external provider for a complex component like identity access management, would lift the burden on your development team so they can focus better on developing what actually matters for your business.  

### 11- Pick Your Azure Region Wisely <a name="t11"></a>

If your product is used by customers globally, you are most likely going to have different legal liabilities against your user's privacy. If you are starting a new project, I would recommend picking the most restrictive region and using a CDN (Content Delivery Network) to efficiently distribute your content globally.  

For example, until a product is profitable you may want to start with a European region to be compliant with GDPR. GDPR is more restrictive and mostly adopted for data privacy by the rest of the countries, so it may be wise to start from there and that scale out to other regions as you grow.

## Conclusion <a name="Conclusion"></a>

I hope this article helped readers to better understand how Azure pricing works in general for the most commonly used services and how to minimize operational costs as much as possible. During COVID-19 health crisis a lot of countries applied lock downs, which in return affected businesses and economies. A lot of people were made redundant to keeping businesses afloat. The tips I've mentioned in this article can save you from thousands of dollars every month which may just been an oversight or simple lack of knowledge.