Guidelines to understand durable functions with .Net Core, C# and Stateful Serverless

Author image By Tejas Patel  |  Saturday, February 25, 2023 06:10 PM  |  5 min read  |   1172

Guidelines to understand durable functions with .Net Core, C# and Stateful Serverless

What are Durable Functions?

Durable Functions are an extension of Azure functions that allows writing stateful functions in a serverless compute environment. Create a reliable stateful workflow by enabling durable functions using Azure Functions. Create a workflow with serverless functions, managing errors, and running activities in a parallel way. The functions allow managing state, checkpoints, and restarts for you. Using this, you can have long-running functions and have stated that remember your workflow.

What is the supported language for Durable function?

  • JavaScript: It support version 2.x of Azure functions. It needs 1.7.0 for Durable function extension
  • C#: It comes with both precompiled class libraries and C# script
  • Python: It requires the 1.8.5 version for durable functions extension
  • F#: It has precompiled class libraries and supports F# only if it supports 1.x of Azure function.

Let’s take an example to understand better,

You have to manage a model which divides into different checkpoints. Each point is closer to one step as you move. Let’s say there’s a game where you want to load a bunch of various resources when everything is loaded and ready. It will look like a workflow that enables you to specify something along with the flow. We can observe different architect patterns with different flows, isn’t it?

If you think this must be expensive, then you’re wrong. The model of payment will work very closely with Azure function. You can pay for the function if only you use it. So sounds impressive, right? Let’s begin with the article as to how the durable functions work and its necessary explanation.

There are a few concepts that we need to consider before dealing with durable functions. Let’s take a run over those.

  • Orchestrator Function: We define the workflow and set up with what happened in it. What activities we need to carry out and what’s done in it.
  • Activity Function: To work with Orchestrator function, activity function is a basic unit to consider. The activity functions can have as many activities it needs to add. You can give descriptive names as per your choice and can represent the flow your way.
  • Client Functions: If you want to trigger functions, then client functions are the new instance of an Orchestrator. These functions are an entry point from which an instance is created and works on Durable Orchestrator functions.

 If this still confused you, let get into another form for better understanding…

Taking another example, say as order processing where order process with the following tasks:

  • Check the inventory
  • Charge the Customer
  • Creating a Shipment

.NET Core

Source: dev.to

Check the above image to see how the client functions and how the order created. Typically, it’s an HTTP endpoint where we hit from an application. The second thing we can do is start the function of an instance of orchestration by using instance id (a unique reference to specific flow). Later the next thing we carry out is by checking the inventory, charging the customer, and next creating a shipment.

How durable functions work with .Net core and stateful serverless?

To move on with technical functions, the first thing that comes is with Orchestration which usually is asynchronous, so we don’t have an idea when does it finish. So, to overcome this issue, we have to pay the running cost for its durable functions and save the state. Here when the orchestration functions work hard, the orchestrator wakes up and re-executes the entire function from start to local state rebuild up.

Don’t worry about re-running during replay as the code will call its function and consult the execution history of current orchestration. If the function has already executed, it replays that function, and the code continues to run. If this sounds better, then continue until the function code is finished and schedule new async work.

Few guidelines to understand how to learn the functions

The best way to learn is to build something simple. By using the VS code, we can install and make the process easy to go.

How to create a project?

Open the command palette and type COMMAND + SHIFT + P

Create a new project by choosing a language. If we select C# while creating a new project, then the list of choices are as follows:

  • DurableFunctionsOrchestration
  • HttpTrigger
  • BlobTrigger
  • IoTHubTrigger
  • QueueTrigger
  • ServiceBusQueueTrigger
  • ServiceBusTopicTrigger
  • TimerTrigger

Choose Durable Functions Orchestration. Next choose the storage account by selecting the Subscription, storage account, and Resource group. Also, you need to save the state of function somewhere for later recovery.

Note: The below codes taken techcommunity site

Check how your project will look alike:

.Net Core

Here in the program, there is a method named as FunctionName(“orchestration”) and parameter context as IDurableOrchestrationContext. The context calls callActivitivitySync() and names as Orchestration_Hello to pass the string.

Orchestration_Hello

Here, the below function is an activity function. The function can do a lot of things and take a database along with HTTP requests.

.Net Core

Debugging

Check the debugging flow and how to start up with a durable function from the VS code and its breakpoints.

Debugging

Until the orchestrator done thoroughly, the function will carry on its activity.

HttpStart Response

For HttpStart response, we have to end up producing the point as we have in URL, which follows like below:

HttpStart Response

This the code we constructed:

constructed

Wrap Up:

If you’re looking to use durable functions, then you can hire ASP.Net Core Development team to create a project. There is a lot more to learn about the durable functions, and we have covered most of them over here.

They are moving on with an announcement done by Microsoft that has bought significant technological trends where Pro ASP.Net Core MVC 2 is one of the tools that has evaluated to improve the productivity and development process. The technologies will be accessible to developers and can use in their current work. These Pro ASP.Net Core MVC 2 tools will work as low barriers to entry-level, and so you can consider it in your future projects. I hope this post was informative and easy to understand.

Guidelines to understand durable functions with .Net Core, C# and Stateful Serverless

Contact us

 

 


Author image

Tejas Patel

Tejas Patel is a Co-Founder of Concetto Labs and he have 18+ years of technical experience in building high quality and scalable Web & Mobile Applications.

Why Our Client Love Us?

Our integrity and process focuses largely on providing every customer the best recommendations for their respective business. Our clients become recurring customers because we always go beyond their expectations to deliver the best solutions.

about-us-strategies

We brainstorm a lot!

Because brainstorming leads to new thoughts & ideas. We believe in discussing & bridging the gap leading to nicer suggestions & application.

about-us-strategies

Believe in Innovation!

Innovation is like Jugaad. It only comes when you give it a try. We believe that extraordinary things come with innovation which help you stand & lead in the crowd.

about-us-strategies

Creative Developers!

Our developers are always keen to develop creative ideas. There is “NEVER a NO.” They have an eye on the market facts, thus develop in the latest on going environment.

about-us-strategies

Value for Money!

We understand the value of money & thus with a modular approach serve you the best quote for your application & web services. The features we promise, we deliver. #notohiddencosts

Trusted By