Getting started with Azure Functions: Introduction to serverless computing and Azure Functions

Nicholas Guantai
6 min readFeb 13, 2023

--

Introduction

In recent years, cloud computing has revolutionized the way businesses and developers build and run applications. Serverless computing is a key part of this revolution, offering an event-driven platform that allows you to build, deploy, and run applications with ease without worrying about the underlying infrastructure.

This beginner’s guide is designed to help you get started with azure functions. The article assumes you have prior knowledge and/or experience with cloud computing specifically azure. We also assume you have knowledge and experience with basic software development. In this article, we will cover what is serverless computing, what are azure functions and why you need them, and finally the key concepts of azure functions. In a later article, we will explore how to build and deploy azure functions.

What is serverless computing and why should you care?

Serverless computing is a way of building and running applications without having to manage the underlying infrastructure. What does this mean? It means instead of provisioning and managing onsite or cloud servers to run your code, you can deploy your code to the cloud, and the cloud provider (such as Microsoft Azure, Amazon web services, or Google cloud) takes care of the infrastructure, scaling, and security while you take care of the actual code.

Imagine you have a small website that only gets a few visitors a day. With serverless computing, you can write a piece of code (known as a function) that runs every time someone visits your website. The cloud provider takes care of the underlying resources such as the server on which your code runs as well as issues such as security and scaling for your small website.

Despite the many advantages of serverless computing, it is not suited to every use case. There are cases where you need to have control of the resources on which your software runs and in such instances, serverless is not the best option.

What are Azure Functions?

Azure Functions is a serverless computing service offered by Microsoft as part of its Azure cloud platform. Azure functions allow developers to build and run event-driven, scalable, and dynamic applications using their preferred programming language. Let’s explore this statement further.

What do we mean by event-driven? This means that your application is designed to listen to events of some kind and respond accordingly. Events that your application could listen and respond to include;

  • User actions — For example user completes registration, a user completes an order, etc. Your serverless application would listen to such events and respond accordingly for example by sending a welcome email in the case of user registration.
  • Change in data — You could design your application to perform some operations when data changes.
  • Timer events — You can also set up your application to perform a specific task at a specific time.
  • The arrival of a message — Azure functions can also be used to listen and respond to messages from other applications or services.

What is the meaning of scalable? Scalability refers to the ability of your application to handle an increasing amount of work. In our previous example where we had a small website that receives only a handful of visitors each day, suppose the website became popular and started receiving thousands of visitors each day. If you are managing the application infrastructure either on the cloud or onsite, you have to handle scaling the servers yourself. If the application is serverless, your cloud provider, Microsoft in the case of azure functions will automatically scale your application to handle the increased load.

Azure functions allow your application to be dynamic by responding to real-time changes or events. When an event occurs, such as the arrival of a message in a queue or a change in data in a database, the corresponding function is triggered and executed. This allows for real-time processing and reaction to events, making it possible to build highly reactive, flexible, and dynamic applications.

Key concepts in Azure Functions

When building an azure function, there are a few key concepts that you need to understand:

A Function is the basic building block of serverless computing. Think of the function as a standalone application that consists of several components:

  1. Code — the code is the logic that runs when a function is triggered. It could be written in a variety of programming languages including C#, Java, JavaScript, and others. The code should be designed to handle a specific task or process and should be triggered by a specific event.
  2. Trigger — triggers are events that initiate the execution of a function. For example, an HTTP request, a message in a queue, or a change in data in a database can all be triggers. When a trigger occurs, the corresponding function is executed.
  3. Binding — Bindings provide a way to connect functions to external data sources, such as databases, storage accounts, or queues. Bindings handle the details of connecting to the data source, sending or receiving data, and formatting the data, making it easier for the code to interact with the data.

For example, consider an application that processes incoming orders. The code for the function could be written to take an incoming order, update the order status in the database, send a notification to the customer, and update the inventory management system. The trigger for this function could be a message in a queue that contains new orders. The bindings could be used to connect the function to the database, the queue, and the inventory management system, allowing the code to interact with the data in each of these sources.

Azure Functions Use cases

Azure Functions are a versatile solution that can be used in a variety of scenarios. Here are some common use cases for Azure Functions:

  1. Lightweight Web APIs: Functions can be used to build web APIs that respond to HTTP requests, providing a serverless solution for building RESTful APIs.
  2. Background processing: Functions can be used to run background tasks, such as processing data, sending emails, or generating reports. Functions can be triggered by events, such as messages in queues, making it easy to process data as it becomes available.
  3. Image and file processing: Functions can be used to process images and files, such as resizing images, compressing files, and transcoding video. Functions can be triggered by events such as new files being uploaded to storage, enabling you to process data as it becomes available.
  4. Automation: Functions can be used to automate routine tasks, such as backups, provisioning, and deployments. Functions can be triggered by events, such as changes in configuration, making it easy to automate complex processes.
  5. Scheduled Tasks — For example database cleanup.

When not to use Azure Functions?

While Azure Functions can be a great solution for many types of applications, there are some situations where it might not be the best choice:

  1. Azure functions are not a replacement for Web APIs. Replacing an API with a bunch of Azure function apps may increase your cost of development, maintenance, and compute.
  2. Applications with large data sets: Functions are designed for processing small amounts of data in a single execution, and may not be suitable for applications that need to handle large data sets.
  3. Applications with long-running processes: Functions are designed for short-lived, stateless operations, and may not be well-suited for applications that require long-running processes.
  4. Applications with complex dependencies: Functions are designed to be a simple and easy-to-use platform, but may not be the best choice for applications with complex dependencies or complex configurations.
  5. Applications with strict compliance requirements: Functions may not meet the strict compliance requirements of some industries, such as financial services or healthcare.

In these cases, other Azure services, such as Azure Virtual Machines, Azure App Service, or Azure Kubernetes Service, maybe a better fit for your application needs. It’s important to carefully evaluate your requirements and consider all available options to determine the best solution for your needs.

In conclusion, Azure Functions is a powerful platform for building serverless applications that are event-driven, scalable, and flexible. Whether you’re looking to build lightweight web APIs, process data in the background, or automate routine tasks, Functions provides a cost-effective and efficient solution. With its ability to run code in response to events, integrate with other Azure services, and scale dynamically, Functions makes it possible to build applications that are highly reactive and dynamic, meeting the needs of your business as it evolves over time. If you’re new to Azure Functions, this article provides a solid foundation to help you get started, and we encourage you to explore the platform further to see all of the great things that you can do with it.

Resources

Azure Functions' official documentation

--

--

Nicholas Guantai
Nicholas Guantai

No responses yet