"Believe in yourself! Have faith in your abilities! Without a humble but reasonable confidence in your own powers you cannot be successful or happy."
- Norman Vincent Peale
This is an era of buzzwords. The moment we become familiar with one buzzword, another emerges and we start chasing it again. It started with cloud computing, DevOps, and now serverless computing.
This chapter introduces some of the fundamental concepts and terminology to give the reader a baseline understanding of cloud computing, cloud service models, and cloud deployment models. We will also understand what functions are and get acquainted with some of the related concepts of Microsoft Azure.
We will use a free trial of Azure Functions to get familiar with it. We will execute the sample function of printing Hello World!
using Azure Functions.
The following are the topics that we will cover in this chapter:
- An overview of serverless architectures
- Why functions?
- An overview of Microsoft Azure services
- Azure App Services versus Azure Functions versus AWS Lambda
Since the introduction of cloud computing, we have usedThe Blind Men and an Elephant story for different technology evolutions and trends. It becomes easier to convey that there is no clear definition of it and based on experience we define it differently based on our wisdom. There may not be any drastic difference but the view might be different. Reality is one, though wise men speak of it variously.
Let's understand serverless architecture by taking the story of blind men and an elephant:

According to this story of The Blind Men and an Elephant, the blind men decide to define an elephant by touching it and then come to their own conclusions:
- The first person placed his hand upon the elephant's trunk and said, "It feels like ... a thick snake"
- The second person placed his hand upon the elephant's ears and said, "It feels like ... a kind of fan"
- The third person placed his hand upon the elephant's legs and said, "It feels like ... a tree-trunk"
- The fourth person placed his hand upon the elephant's body and said, "It feels like ... a wall"
- The fifth person placed his hand upon the elephant's tail and said, "It feels like ... a rope"
- The sixth person placed his hand upon the elephant's tusks and said, "It feels like ... a spear"
So, there are different perspectives, but the elephant remains the same. There are many perspectives, views, and definitions available for serverless architectures or serverless computing.
Let's understand serverless architecture with respect to the evolution of computing:

Based on the pattern of usage, the use of an on-premise resource evolved into the use of to serverless computing.
Change is a step-by-step process to evolve and make the existing practices more effective with enhancements. If we can find a pattern, then change/evolution is a driving force behind all path-breaking innovations. Similarly, cloud computing is a disruptive innovation in the field of infrastructure in Information Technology.
George Bernard Shaw was wise enough to say that:
"Progress is impossible without change, and those who cannot change their minds cannot change anything."
This is very appropriate for cloud computing and its adoption in the small, medium, or even large organization.
Let's understand what cloud computing is! It is no longer the elephant in the room. There are many good definitions available in the market, but I will explain what I understand and what I have experienced.
Cloud computing is a kind of system that provides on-demand and agile resources in a pay-as-you-go billing model, multitenant, or dedicated computing resource such as compute, storage, and network. As per NIST definitions, cloud computing comes with four cloud deployment models and three cloud service models as given in the following diagram:

Cloud deployment models define the way resources are deployed in the environment such as on-premise and exclusively for a specific organization, that is, a private cloud; or cloud resources that are accessible to all organizations and individuals over the internet, that is, a public cloud; or cloud resources that are accessible to a specific set of organizations that share similar interests or requirements, that is, a community cloud; or cloud resources that combine two or more cloud deployment models that is known as a hybrid cloud.
There are three cloud service models that define the way cloud resources are made available to users.
Infrastructure as a Service (IaaS): Cloud resources can be Infrastructure as a Service (IaaS), where the user is responsible for managing and maintaining resources/virtual machine starting, from package installation to security configuration and from upgrading packages to configuring resources for high availability as well.
Platform as a Service (PaaS): In PaaS, the cloud service provider gives flexibility to choose configuration and the user is only responsible for configuration and some troubleshooting options and monitoring options are made available by the cloud service provider.
Software as a Service (SaaS): In SaaS, the complete application is made available by the cloud service provider, where the responsibility of IaaS and PaaS remains with the cloud service provider. The user has to only use it and not worry about provisioning, monitoring, and managing the resources.
Cloud computing has few characteristics defined by NIST, which are noteworthy such as multitenancy, pay-as-you-use (similar to electricity or gas connection), on-demand self-service, resource pooling for better utilization of resources, rapid elasticity for scaling up and scaling down resources based on usage in an automated manner, and measured service for billing.
In the last few years, usage of different cloud deployment models has varied based on use cases and priorities of different organizations. Initially, a public cloud was used for noncritical applications, while a private cloud was utilized for business-critical applications, where security was a major concern. Hybrid cloud usage evolved over time with experiments, experience, and confidence in the services provided by cloud service providers.
As usual in a normal traditional environment for infrastructure management, installation, configuration, and monitoring, it was easier to adopt IaaS as there is complete control. Over time, organizations realized the pain or work behind the management of resources available in the cloud and the cost of managing resources in the cloud as the efforts are the same in managing resources considering security configurations and other configurations.
Hence, PaaS is getting popular day by day with the evolvement of Platform as a Service. PaaS has matured over the years and the scope is much wider and the services allow us to configure different programming languages such as .Net, Java, PHP, Python, and Ruby.
The following is a diagram representing different Cloud Service Models:

In plain English, PaaS provides an infrastructure as well as a runtime environment in combination to deploy an application. The difference is that the end user doesn't have control on the infrastructure while they can configure a runtime environment most of the time. Some service providers allow access to resources created in PaaS but not all. Features such as the ability to debug applications remotely and troubleshoot issues, up to some extent, are also provided. There are PaaS offerings, where you can have dedicated infrastructure resources for application deployment, but even in that case, control of the infrastructure is in the hands of cloud service providers.
Considering the definition of PaaS, everything is managed by the cloud service provider up to the runtime environment. For example, in the case of Java, we don't need to worry about which Java version will be installed and available to update the Java version, the web server version, and so on. Over the years, PaaS has gained its momentum and many organizations have realized that the lower the number of complexities, lesser will be the management overhead. PaaS offerings manage load balancer and high availability with little configuration and hence save lot of time and the architecture is clearer. We need to remember one thing: that most of the control lies with the cloud service provider and hence we do not have much to manage and cloud service providers have more control and they implement all best practices and standard patterns to fulfil the service level agreements (SLAs) attached with PaaS offering.
In short, those who know more about infrastructures and platforms, manage them efficiently, so we have less overhead.
Cloud service providers will handle all resource and version management of all the packages.
However, it means that it is the choice in terms of packages and other options lies with the service provider and not with the cloud consumers. Yes, cloud consumers' choices are considered based on market trends, so indirectly, users have their say in the services offered by the cloud service provider.
In a traditional environment, the infrastructure provisioning process takes place in a different manner than the acquisition of virtual machines in cloud subscription. Additionally, if there are any issues during the steps, then it takes more time in to and fro communication between different stakeholders. Let's visualize how the process workflow is executed in terms of a traditional model or in IaaS and then we will compare it with PaaS:

In the case of PaaS, the flow has fewer complications than the traditional or IaaS process to acquire resources as given as follows:

However, the approval process exists in the cloud environment too as the cost is associated with it and organizations can keep different sets of approval processes to create a virtual machine or to provision any PaaS offering such as email notification.
Having said that, there are many cloud service providers in the market that provide different types of services in an improved and innovative manner. Microsoft Azure is one of the leading cloud service providers available in the market. In the next section, we will explore some important concepts related to Microsoft Cloud to build a base of understanding on which we can kick off with Azure Functions.
Serverless is not actually serverless. It means that users only need to manage code/application and not servers. The server will be managed by the service provider. We as a user only pay when our code or function is executed in the serverless or in the server that is not managed by us. Scaling is based on the request and pricing differs based on the service provider. AWS Lambda and Azure Functions are two examples of serverless computing or Function as a Service (FaaS). AWS provides a pay-as-you-go billing model, while Microsoft Azure provides a consumption plan as well as an App Service plan for Azure Functions. We will cover this in detail in a comparison table later in the chapter.
The following are some of the benefits of serverless computing:
- Faster time to market as you can write code in the functions editor in the Azure portal and click on
Run
for execution - No need to worry about the infrastructure and provisioning resources
- Easy bindings to services and external services
- Create functions in multiple languages as supported by the cloud service provider
- Pay only for what you use
- More cost-effective than IaaS and PaaS
- No configuration is required to set up scaling in and scaling out policies
In the next section, we will cover an overview of the Azure Functions.
Yes, the immediate question can be what exactly is this Azure Function? In simple English, it is running a function in a cloud environment. It enables us to create a serverless application in a Microsoft Azure environment. Consider a scenario where we know the problem, we know the code that can fix the problem, and we don't want to worry about resources that execute this code. This is the easiest way to focus on logic and business and enhancing the scope of productivity. The biggest benefit is we only need to pay for what we use. Let's understand what exactly in terms of features are provided by the Azure Functions and Azure App Services:

Azure App Services (Web Apps, Mobile Apps), and Functions support different languages and frameworks, DevOps capabilities, scaling, load balancer and etc.
Azure Functions is a service provided by Microsoft for serverless computing. The Azure function is a combination of code plus events plus data. Azure Functions is open source and available on GitHub:
Let's see where Azure Functions is placed in Cloud Service Models in the following figure:

Azure Functions are similar to Azure Webjobs with some differences such as scaling policies, trigger events, and language support. We don't need to worry about infrastructure for execution of the piece of code or function. It is like a FaaS. We can execute Azure Functions in response to events as well.
The languages that are supported are C#, F#, Node.js, Python or PHP, batch, bash, or PowerShell.
There are two types of pricing plans available in the Azure Functions:
- Consumption plan: When we execute functions, Microsoft Azure provides all the resources. We don't need to worry about resource management, and we only pay for the time that our functions are executed. The consumption plan pricing includes a monthly free grant of 1 million requests and 400,000 GBs of resource consumption per month. Free grants apply to paid consumption subscriptions only.
- App Service plan: This executes functions just the way we execute Azure App Services. We can utilize the same App Service plan created for any application and execute Azure Functions on it without any extra cost.
Having App Service plan as the host for Azure Functions provides lots of benefits that are available with Azure App Services. We can utilize remote debugging, deployment slots, continuous deployment, vertical scaling and horizontal scaling, auto-scaling, and so on. If we use the Azure App Service, then it is a multitenant scenario. If we want to utilize a dedicated environment, then we can utilize the App Service Environment that is a dedicated service from Microsoft Azure, where we can host a function in a virtual network and configure network security groups (NSGs) for an enhanced level of security.
Triggers and bindings are the core of Azure Functions. It allows us to write a function to respond to events that occur in the Azure or other services. As the name suggests, trigger indicates how the function should be invoked and bindings are related to data. Azure Functions can have only one trigger associated with it. Bindings are the connection to the data from within the code available in the function. Unlike triggers, functions can have one or more input and output bindings.
The following table shows the triggers and bindings that are supported with Azure Functions:
Type | Service | Trigger* | Input | Output |
Schedule | Azure Functions | Yes | ||
HTTP (REST or Webhook) | Azure Functions | Yes | Yes** | |
Blob Storage | Azure Storage | Yes | Yes | Yes |
Events | Azure Event Hubs | Yes | Yes | |
Queues | Azure Storage | Yes | Yes | |
Queues and topics | Azure Service Bus | Yes | Yes | |
Storage tables | Azure Storage | Yes | Yes | |
SQL tables | Azure Mobile Apps | Yes | Yes | |
No-SQL DB | Azure DocumentDB | Yes | Yes | |
Push Notifications | Azure Notification Hubs | Yes | ||
Twilio SMS Text | Twilio | Yes | ||
SendGrid email | SendGrid | Yes |
Let's try to get to grips with Azure Functions quickly:
- Go to https://functions.azure.com/try.
- Select
Webhook + API
as a scenario and selectJavaScript
as the language. - Click on
Create this function
: - Select an auth provider.
- Select any suitable authentication method and sign in with it:
- Wait for few seconds until a free trial fo Azure Functions is ready:

- The sample script is ready for
Hello World!
:

- Click on
Test
on the right side of the browser window. InRequest body
, provide thename
:

- Click on
Run
and scroll down.
- See the
Output
andStatus
:

So, we have just executed the simple Hello World function. We will execute Azure Functions in a proper Azure subscription in later chapters.
The following are some of the benefits of Azure Functions:

Before we jump to Azure Functions, let's understand some basics of Microsoft Azure cloud. We will discuss the key components and services of Microsoft Azure in the next section.