Getting Started With Durable Functions

Introduction

This is a series of articles to get our hands dirty with Durable Functions and their patterns in detail.

It will cover the following things,

  • What are Durable Functions?
  • Supported languages
  • Application Patterns
  • Hands-on Lab – Create a durable function in C#
  • Hands-on Lab – Deploy durable function on Azure

What are Durable Functions?

  • Durable Function is an extension of Azure Functions that lets you write stateful functions in a serverless compute environment.
  • The extension lets you define stateful workflows by writing orchestrator functions and stateful entities by writing entity functions using the Azure Functions programming model.
  • Behind the scenes, the extension manages state, checkpoints, and restarts for you, allowing you to focus on your business logic.
  • The primary use case for Durable Functions is simplifying the complex, stateful coordination requirements in serverless applications

Supported languages

  • C#: precompiled class libraries and C# script.
  • JavaScript: supported only for version 2.x of the Azure Functions runtime.
  • Python: requires version 2.3.1 of the Durable Functions extension, or a later version.
  • F#: F# script is only supported for version 1.x of the Azure Functions runtime.
  • PowerShell: Supported only for version 3.x of the Azure Functions runtime and PowerShell 7

Application patterns

The following application patterns can benefit from Durable Functions:

  • Function chaining
  • Fan-out/fan-in
  • Async HTTP APIs
  • Monitoring
  • Human interaction
  • Aggregator (stateful entities)

Pre-requisites

These are pre-requisites to start working on durable functions

  • An Azure pay-as-you-go account enabled
  • Install Visual Studio 2019
  • Install Azure Storage Emulator

Hands-on Lab – Create a durable function in C#

Steps to be followed,

Open VS 2019 and create a project.

Choose the Azure function template and create a directory.

Getting Started With Durable Functions

Choose durable functions orchestration template.

Getting Started With Durable Functions

Once the application has been created, we can see three functions,

  • Function1 – Main functionality function which internally calls Function1_Hello multiple times and returns the result.
  • Function1_Hello – Intermediate function gets called from Function1 multiple times, responsible for manipulating the input and generate output.
  • Function1_HttpStart – Function in the form of HTTP trigger which is responsible for initiating Function1 and gather the response.

Getting Started With Durable Functions

Run (F5) the application and see all the functions that have been listed here.

Getting Started With Durable Functions

Copy the URL of Function1_HttpStart and run it in the browser.

Getting Started With Durable Functions

Copy the URL of statusQueryGetUri (GET URLK) and run it in the browser.

Getting Started With Durable Functions

Here, you can see the response from Function1 which got instantiated from Function1_HttpStart with the desired output.

Hands-on Lab – Deploy durable function on Azure

Steps to be followed,

Right-click on the function and click on publish and choose target as Azure.

Getting Started With Durable Functions

Choose an option as Azure function app (Windows).

Getting Started With Durable Functions

Create/choose the new/existing resource group and resource for azure function deployment.

Getting Started With Durable Functions

Click on Finish and let it get published and once published, go to the Azure portal and test the function app using the steps which we did above while creating durable functions.

This is a basic example of orchestration calling the same function multiple times.

There are multiple patterns that represent the use-cases of durable functions, stay tuned for the next series of articles to get the hang of it.

Happy learning!


Similar Articles