DEV Community

Kartik Anand
Kartik Anand

Posted on • Originally published at Medium on

Orchestration Pattern Meets Serverless (Durable Functions)

In the current digital transformation/micro-service era, orchestration pattern is another useful pattern that is used by lot of organizations for calling various services and then waiting for all services to complete before next step.

Azure Durable Functions is a great service to implement orchestration pattern. The function orchestrates and chains-together calls to other functions. Those functions can be any or a combination (Functions/Logic Apps/Web Api/Microservices).The durable function is resilient to reboots of VMs/Applications.

In my example, I have a service that calls 2 micro-services and waits for the results before moving to next step. This all is accomplished via single durable function that will call 2 services and then wait till it receives results back from 2 services and then it makes a call to the next service. Alternatively, this could be accomplished by creating multiple functions and Queues to coordinate the flow of data. The alternative flow will introduce unnecessary services and increase the overall management of services.

Here are some key advantages:

·Low Overhead

·Reliability

·Scalability

·Serverless

·Cost Saving

Key Source Code

var tasks = new Task[2];

tasks[0] = context.CallActivityAsync(“ZipCodeAPI”, “LA2”);

tasks[1] = context.CallActivityAsync(“LogicApp1”, “LA2”);

await Task.WhenAll(tasks); //Ensures Function waits for all chain functions to complete before moving to next step

[FunctionName(“ZipCodeAPI”)]

public static string GetZipCode([ActivityTrigger] string name, ILogger log)

{

HttpWebRequest rqst = (HttpWebRequest)HttpWebRequest.Create(_url);

rqst.Method = “POST”;

rqst.ContentType = “application/json”;

byte[] byteData = Encoding.UTF8.GetBytes(pJSON);

}

[FunctionName(“CountryCode”)]

public static string GetCountryCode([ActivityTrigger] string name, ILogger log)

{

HttpWebRequest rqst = (HttpWebRequest)HttpWebRequest.Create(_url);

rqst.Method = “POST”;

rqst.ContentType = “application/json”;

byte[] byteData = Encoding.UTF8.GetBytes(pJSON);

}

Top comments (0)