fbpx

Azure Functions

Azure Functions is a serverless compute service that lets you execute code in the cloud in response to a pre-defined trigger or an event without having to worry about the infrastructure or running a complete application. Functions when used effectively can make the development productive as it supports many languages like C#, Java, JavaScript, Python etc.., This allows the developers to write solutions based on requirement for example a complete application built with Java Backend can be complimented with JavaScript or Python built functions which execute simple piece of code like sending an email in response to an event or execute a periodic job that backs up the master database for archival. This piece of code scales automatically on the cloud and you pay based on consumption in the form of millisecond execution time. This reduces the overall cost and removes the overhead of this functionality from the main application. Functions can also be integrated with OAuth providers like Azure AD, Facebook, Google, Twitter and Microsoft Account.

Azure Function Triggers

HTTP Trigger

Execute the code by invoking a HTTP Request. This is mostly suitable for building external API’s which perform specific task with unpredictable scalability. Ex: sending confirmation/verification emails to all registered users of an application.

Timer Trigger

Execute the code for clean up or other batch tasks on a predefined timer/schedule. This can be useful in scenarios to perform automatic backup/archival of important master data/customer database periodically silently without any manual intervention.

Cosmos DB Trigger

Execute the code when a new document is inserted or updated in the collections in a NoSQL Cosmos DB database. This is particularly useful to perform post processing of Cosmos DB record insertion or perform a task like aggregation of record values to create a new record in a different Cosmos DB collection.

Blob Trigger

Process Azure storage blobs when they are added to containers. This can be useful when we are using Blob storage to store static resources like images. They can be compressed and stored for better storage efficiency.

Queue Trigger

Respond to messages as they arrive in Azure Storage Queue. This can be used in Queue based systems to process an incoming queue message and perform actions like sending push notifications to mobile users by fetching meaningful context from the queue message.

Event Grid Trigger

We can respond to events which are delivered to Event Grid subscription which includes filtering. Practical for building event-based architectures.

Event Hub Trigger

Respond to events delivered to an Azure Event Hub. This is useful in automating application workflows and application instrumentation in IoT scenarios.

Durable Functions

It is an extension to Azure Functions which can help us perform stateful execution of code in a serverless compute environment. The extension lets us define stateful workflows with a definite input and output by writing orchestrator functions and stateful entities using the Azure programming model. Azure manages everything behind the scenes like extension states, checkpoints and restarts allowing the developers to focus only on the logic. This is synonymous to Step Functions in AWS.

Commonly used Application Patterns for Durable Functions:

Function Chaining

As can be seen in the above image, we can chain Functions to execute in specific order concisely. Here, the output of one function is acting as an input to the subsequent function. We also have the flexibility to implement control flows by using imperative coding constructs. Control flow semantics like conditionals and loops, try/catch and finally blocks can be implemented in this pattern.

Fan-Out / Fan-In

In this pattern, we executed multiple functions in parallel and then wait for all the functions to finish. Often, some aggregation work is done on the results that are returned from the functions. Fan Out can be easily achieved by sending out multiple messages to a single queue. Fan In can be challenging in a normal function as we need to write the code to track when queue triggered functions end and store their output.

Menu