Introduction To Serverless Computing Using Azure Functions

In most of our previous articles, we have learnt the following different Azure COMPUTE options that could be used for hosting different type of Web Applications like Websites, Web APIs etc.

App Services

This is a PaaS (Platform as a Service) Service where developers need not worry much about maintaining and upgrading the software and security patches of the Virtual Machines. Microsoft would take care of such details. As a developer, we just need to focus on the application code and business requirements. Please go through the Azure App Service: Create Web App from Visual Studio article to learn more about Azure App Services.

Cloud Services

Cloud Services is another PaaS service where developers (or IT guys) need to take care of provisioning the VM instances. Microsoft is responsible for software upgrades and security patches etc. Please go through the Azure Cloud Services – Introduction to learn more about Cloud services.

Virtual Machines

Virtual Machines are IaaS (Infrastructure as a Service) Service offered by Microsoft, where developers (or It guys) are completely responsible for everything, right from provisioning to maintenance of the software and any other upgrades.

Web Jobs

Web Jobs could be used for hosting the background jobs related to any application. The Web jobs run in the context of App Service Plan. If you host the App Services and Web Jobs in a same App Service Plan, then both the Web App and the Web Jobs would share the resources of the App Service plan.

All the above options provide great services for different requirements. In this article, we will learn about another Azure COMPUTE option named Azure Functions.

Overview

Before discussing much about Azure Functions, let's briefly discuss about a few of the pain points of the above Azure Compute options when we plan to host components (Web APIs, background jobs etc.) in them.

In most of the above Azure Compute options, (if we use any of them for our production needs where at least one instance should be running all the time), we will end up paying for at least one VM that gets provisioned for our requirements irrespective of whether we use it or not.

We need to either manually or auto-scale the infra based on the traffic that our applications get.

For most of the above Compute options, developer needs to develop the complete codebase including the plumbing code of accessing the Azure Services like Blobs, databases etc.

Introduction to Serverless Computing and Azure Functions

The name “Serverless” might be a bit confusing. People might think that there would be no Servers that host the Azure Functions. Of Course, there are Servers (Virtual Machine instances) that are responsible for hosting the Azure Functions and will scale automatically based on the traffic that the Azure Functions would receive.

As a developer, you don’t need to worry about patching and upgrading the Operating Systemsor .NET Frameworks etc. You don’t even need to worry about scaling (or even auto-scaling for that matter) the instances (you would have to do in case of all other Azure Compute options). Scaling is abstracted from you in case of Azure Functions.

Benefits of Azure Functions

Given are few of the benefits that one would get using Azure Functions.

Quick development and deployment of small components to Azure Functions. As a developer, you don’t need to write the boiler plate code related to using the Azure services.

You can directly code your functions right from your Azure Management Portal.

You pay only for the execution minutes of your applications.

Azure Functions Pricing Model

As discussed earlier, you only pay for the execution minutes by using the “Consumption Plan”. Below are the two different pricing models that Azure Function supports.

Consumption plan

This plan is based on the Executions and resource consumption. It also has a free monthly free of 1 million requests and 4,00,000 GB-s (Gigabyte seconds) of resource consumption per month. For more information about the calculations, please refer Functions Pricing. In most of the cases, you would choose this plan to make sure that your bill is low.

App Service Plan

Regular plan which would be billed based on the pricing tier that you have chosen for your applications. Please refer to the Features of the Azure App Service Plan for more details about the features. You would choose this only in the case where you already have few applications that you might think that the same App Service plan is suffice even for hosting the Azure Functions.