Function Chaining with Durable Functions
  • 17 Sep 2020
  • 1 Minute To Read
  • Contributors
  • Print
  • Comments
  • Share
  • Dark
    Light

Function Chaining with Durable Functions

  • Print
  • Comments
  • Share
  • Dark
    Light

#ServerlessTips - Azure Functions
Author: Steef-Jan Wiggers Azure MVP

Durable Functions are an extension of Azure Functions and are a continuation of the open-source Durable Task Framework. With Durable Functions, you can write stateful functions, i.e. workflow and stateful entities (see Tip Durable Function Entities).

A durable function is a good fit when you need to write a complex orchestration. For instance, when you chain functions together to support a multi-step process (workflow), you wish to automate. Or when you want to break a long-running task into multiple shorter ones to prevent running into execution time-outs.

Earlier in the first version of Azure Functions of other services, you could create some queues. The first function (F1) would drop messages into a queue, the second function (F2) would pick it up, and drop it to another queue, where a third function (F3) would pick it up and so on.

12

With the above solution (diagram), you will be facing much overhead by managing all the queues. And how do you keep track of the relationship between all these functions? Furthermore, when you want to add some error handling, it makes the solution more complicated, because of compensating actions and persistence of state.

However, Durable Functions orchestrators are capable of error-handling structures you as a developer are used to such as try-catch blocks and self-document the relationship between activity functions. Below you can see how the code for this scenario would look like with an orchestrator function. Note that since the activity functions’ return values, these are stored as a local state, and maintained for you as part of the execution history.

13

The orchestration trigger provides a context object, which allows you to call other functions. You call these other functions by name and provide data as input, and then you wait for some results. Hence, the orchestration function offers a way of how you can do sequential function calling.

More details on Durable Function, how they work and compare to other services such as Logic Apps and Flow, see the CloudTalks: Building Workflow Solution with Microsoft Azure and Cloud recording.

Was This Article Helpful?