Introduction to serverless and Azure functions

light What is serverless computing?

Serverless is also known as Function as a Service (FaaS).

In a nutshell:

  1. Serverless architecture makes use of third-party services. They might, for example, run your code on managed, ephemeral containers in a FaaS platform (Azure functions).

  2. Servers are still used to run your applications. But in this case, your cloud provider takes care of the management, provisioning and scaling (Microsoft Azure in this case).

This allows you to focus on the code and deploy when ready, while your provider takes care of the infrastructure.

Some of the advantages of serverless are:

  • They are scalable: not only this scales automatically based on the increase and decrease in usage but also is highly available.

  • It can save you money: you pay only for the usage (number of executions) instead of for having a server running 24/7.

The following infographic provides more details about serverless:

serverless infographic

Good use cases

Some good use cases for serverless are:

  • Image and video processing: you can couple Azure functions with Azure Blob Storage and use a storage trigger for your function. Then your function can do the processing asynchronously.

  • Internet of Things: IoT applications can generate a lot of data through the sensors. You can use functions to process the data in a scalable manner.

  • Data pipelines: you can integrate multiple services to build scalable data pipelines.

faas Azure functions and serverless

FaaS allows you to run self-contained code snippets called functions in the cloud. Your functions are idle until particular events trigger them. Functions are self-contained, small, short-lived, and single-purpose. They disappear after execution - hence why they are called ephemeral.

Functions are very versatile - you can use a variety of triggers to call your function and execute your code. They can be set so that they always run the same task or to run specific tasks based on inputs.

Microsoft Azure’s FaaS is called Azure Functions. This FaaS already supports multiple programming languages:

Functions languages

So we are going to take advantage of the Python support for this tutorial.

Azure provides three main plans for functions, which will determine the kind of instances used, execution times and pricing.

For more details, check the Azure functions consumption plans docs.

Note

Since serverless functions are meant to be stateless, the resources inside the function will disappear once the code had finished executing (or the timeout is reached).