Skip to content
Petkir Blog
XLinkedinBluesky

Azure Durable Functions with .NET 8 Isolated

Code, Azure3 min read

What is an Azure Function?

Azure Functions are a serverless compute service provided by Microsoft Azure. They allow developers to execute small pieces of code (functions) in the cloud without having to worry about managing servers. Azure Functions provide scalability, reliability, and are designed to respond to various triggers, such as HTTP requests, messages in a queue, or events in other Azure services.

With Azure Functions, you only pay for the execution time of the code and resources consumed during the function's runtime, making it a cost-effective solution for building event-driven applications.

Why Durable Functions?

While Azure Functions are great for lightweight, stateless operations, there are scenarios where you may need to manage long-running workflows and maintain state. For such use cases, Durable Functions come into play.

Durable Functions are an extension of Azure Functions that allow you to:

  • Define workflows in code using Orchestrator Functions.
  • Maintain the state of these workflows across long periods of time, even after the function is unloaded from memory.
  • Handle complex scenarios such as chaining multiple functions, fan-out/fan-in patterns, human intervention workflows, and retries on failures.

Durable Functions provide built-in support for managing workflow state and offer fault tolerance, making them an excellent choice for applications that involve long-running processes.

Why Isolated Mode in .NET 8 (and not In-Process)?

Starting from .NET 8, Azure Functions encourage using the Isolated Process model instead of the traditional In-Process model.

Here's why:

  1. Decoupling from Host: The isolated model runs your function app in a separate process from the Azure Functions runtime, offering better isolation between your code and the platform. This allows more flexibility, as you can choose the .NET version you want independently of the host runtime.

  2. End of Life (EOL) for In-Process: Microsoft has announced that the In-Process model for Azure Functions will be deprecated and won't be supported in future versions. This means staying on the in-process model ties you to older runtimes that won't receive updates, making the Isolated Process model a future-proof option.

  3. Custom Middleware and Dependency Injection: The isolated model gives you more control over the request pipeline, allowing the use of custom middleware, dependency injection (DI), and other features that are more in line with traditional ASP.NET Core applications.

Simple Sample: Azure Durable Function in .NET 8 Isolated

Here’s a simple example of a Durable Function in .NET 8 Isolated Mode:

DurableFunctionExample.cs

using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;
using System.Net;
using System.Threading.Tasks;
public class DurableFunctionExample
{
private readonly ILogger _logger;
public DurableFunctionExample(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<DurableFunctionExample>();
}
[Function("DurableHttpStart")]
public async Task<HttpResponseData> HttpStart(
[HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req,
[DurableClient] DurableTaskClient client)
{
var instanceId = await client.StartNewAsync(nameof(RunOrchestrator), null);
_logger.LogInformation($"Started orchestration with ID = '{instanceId}'.");
var response = req.CreateResponse(HttpStatusCode.OK);
await response.WriteStringAsync($"Orchestration started with ID: {instanceId}");
return response;
}
[Function("RunOrchestrator")]
public async Task RunOrchestrator([DurableOrchestrationTrigger] IDurableOrchestrationContext context)
{
var output = await context.CallActivityAsync<string>(nameof(SayHello), "World");
_logger.LogInformation($"Orchestration output: {output}");
}
[Function("SayHello")]
public string SayHello([ActivityTrigger] string name)
{
return $"Hello, {name}!";
}
}

Program.cs

using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Azure.Functions.Worker.Extensions.DurableTask;
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureLogging(logging =>
{
logging.AddConsole();
})
.Build();
host.Run();
### Key Points:
1. **HttpStart Function**: Triggered via an HTTP request to start the orchestration.
2. **RunOrchestrator Function**: The orchestrator function that manages the workflow.
3. **SayHello Function**: A simple activity function that is invoked within the orchestration.
In this example, the HTTP-triggered function kicks off a durable orchestration that calls the SayHello activity.
### Conclusion
Moving to Azure Durable Functions with **.NET 8** Isolated is a smart choice for building long-running, scalable workflows.
The isolated process model decouples your code from the runtime, future-proofs your apps, and provides more flexibility for configuration and middleware.
With this setup, you’re set to build more resilient, maintainable, and future-ready applications.