In this article, I am going to describe what are serverless applications and how are these developed. I will also introduce the concepts of serverless computing and how to deploy one using Azure Functions. This article is targeted towards most of the data professionals who want to gain some basic knowledge of serverless applications and the underlying architecture and cloud computing. In recent times, cloud computing has become one of the most important domains for many big organizations and it has thus become essential for all to have some basic information on the same.
Although there are multiple serverless offerings from Azure, in this article, we will cover only Azure Functions and the topics related to it. We will go through the languages supported by it, the authoring choices, how to test the function, how to monitor the logging, and how to set the authorization level of these functions, etc.
What are serverless applications
In the cloud computing world, it is often the case that the cloud provider provides the infrastructure necessary to run the applications to the users. The cloud provider takes care of all the headaches of running the server, dynamically managing the resources of the machine, etc. It also provides auto scalability, which means the serverless applications can be scaled based on the execution load they are exposed to. All these are done so that the user can solely focus on writing the code and leave worrying about these tasks to the cloud provider.
Serverless applications, also known as Function-as-a-Service or FaaS, is an offering from most of the enterprise cloud providers in which they allow the users to only write code and the infrastructure behind the scenes is managed by them. Users can write multiple functions to implement business logic and then can all these functions can be easily integrated to talk to each other. Such a system that involves the use of the above model is known as serverless architecture.
Let us now see some of the basic FaaS offerings from the enterprise cloud providers.
- Azure Functions, from Microsoft
- AWS Lambda, from Amazon Web Services (AWS)
- Google Cloud Functions, from Google
- OpenWhisk, an open-source cloud platform from Apache/IBM
- Fn Project, from Oracle
Although serverless architecture is the new boom, we need to be aware of the following two main concepts.
- These functions are stateless – which means the state of these applications is created when the execution starts and destroyed when the function has been executed successfully. There is no state information being store automatically about these functions. In case, the users need to store the state information, a separate storage system like a database can be used
- These functions are event-driven – this means that you need an event that occurs before executing these functions. An event can be anything like a REST API request, a message added to a queue, etc. The response from the event, also known as a trigger, can be used to fire the execution of a serverless application
Introduction to Azure Functions
Azure Functions is the serverless platform offered by Microsoft, using which developers can write complex business logic and execute these without having to worry about the underlying infrastructure. Along with Azure Functions, Microsoft also offers two other serverless platforms, namely Logic Apps, a simple visual workflow manager that enables users to schedule, automate, orchestrate tasks within Azure and Event Grid, a service which helps users manage to the route of events from source to destination within the Azure cloud:
Figure 1 – Introduction to Azure Functions (Source)
Azure Functions is the event-based serverless application framework which can automatically scale up and down based on the executions that are being triggered. This helps the developers and in turn the organizations to focus more on business logic and less DevOps time. This also helps less time for the organizations to ship these functions to the market as compared to other server-based applications. Azure Functions is ideal to write up any cron jobs, fetch data from an IoT device, get and transform data from any REST API, write data to Azure SQL Database or Cosmos DB, also mobile backends, etc.
As you can see in the figure above, Azure Functions is a combination of code and events. These functions are executed using triggers and also have bindings that help to run these events based on a pre-defined schedule, API calls, or any other file system triggers. To start with Azure Functions, all you need to do is to sign up for an Azure subscription by visiting https://portal.azure.com and then select Azure Functions.
Overview of AWS Lambda
Below are a few events which can be used to trigger a lambda function:
- When a table is updated in Amazon DynamoDB
- When messages arrive from Amazon Kinesis Stream
- When objects in AWS S3 are modified
- When notifications are sent from Amazon SNS (Simple Notification System)
- When messages are added to Amazon SQS (Simple Queue Service)
- When custom events are triggered by mobile apps, web apps, or any other service
Figure 2 – AWS Lambda (Source)
To begin writing code in AWS Lambda, you need to have a valid AWS account. You can sign up for AWS by visiting http://console.aws.amazon.com/ and use your email address to signup and start writing code with AWS Lambda.
Overview of Google Cloud Functions
Cloud Functions from Google are also an offering using which developers can build serverless applications. Google has been in providing options for cloud computing since early 2008, with the launch of its Google App Engine. However, the Cloud Functions are a pretty recent addition, only in the year 2017. Like AWS Lambda and Azure Functions, Cloud Functions also support an event-driven approach to start the executions of the functions:
Figure 3 – Google Cloud Functions (Source)
Few of the important use cases to begin with Cloud Functions are as follows:
- Process images and other data based on a pre-defined event
- Respond to events that are triggered via simple HTTP calls
- It can be used to build light-weight APIs
- It can be used as a backend for mobile applications, using Firebase as a database
- It can also be used to transform IoT data from live streams
In this article, we have seen what serverless applications are and the different cloud providers that offer us the ability to write code that can be deployed in the serverless frameworks they provide. Using such an architecture is beneficial for most of the developers as well as the organization as they can now focus more on the code and business logic and leave the infrastructure to the cloud provider. Also, these kinds of serverless applications are scalable on-demand, which means based on the load, they can add up resources, and when the load is less, it can easily free up the resources. This helps a lot to manage the pricing as the functions are charged only for the duration they are being executed and not for the entire time. Also, based on the resources being used, the pricing of the function may go up or down; however, it is cheaper than provisioning a full VM to deploy the function.
- Learn NoSQL in Azure: An overview of Azure Cosmos DB - June 16, 2021
- An overview of PGAdmin – PostgreSQL Management Tool - June 10, 2021
- Install and upgrade PostgreSQL to support Spatial Data - May 26, 2021