Many applications need to execute tasks that take more than a few seconds or depend on multiple external services. For example, an order-processing application might need to validate an order, reserve inventory, collect payment, generate an invoice, and notify the customer. If one step fails, the application must know where the process stopped and how to continue without repeating completed work.
Building this type of workflow with ordinary Azure Functions can become complicated. Each function invocation is independent, and developers must manage state, retries, timeouts, and communication between functions.
Durable Functions solves this problem by providing a framework for long-running, stateful workflows. With the Go worker for Azure Functions, developers can now implement orchestrations and activities using Go.
Go support on Azure Functions is generally available on the Flex Consumption plan. The Durable Functions integration uses the middleware/durabletask package, which connects the Go worker to the Durable Task extension.
This article explains how durable workflows work in Go, how to configure the required packages, and how to build an order-processing workflow with orchestration and activities.
Understanding Durable Workflows
A durable workflow is a process that can maintain its progress even when an application instance restarts or an individual function execution ends.
Instead of keeping the entire workflow in application memory, Durable Functions stores execution history and uses that history to continue the process when another execution is required.
A durable workflow has three important components.
Orchestrator
The orchestrator defines the workflow. It decides which activity should execute, in what order, and what should happen when an activity succeeds or fails.
For example, an order orchestrator might execute these operations:
Validate the order.
Reserve inventory.
Process the payment.
Generate the invoice.
Send an order confirmation.
The orchestrator coordinates the operations but should not directly perform external operations such as database updates or HTTP requests.
Activity
An activity performs the actual business operation. It can communicate with databases, call external APIs, update records, or send notifications.
Activities are executed independently from the orchestrator's replay logic. This makes them the right place for operations that produce external side effects.
Durable State
Durable Functions records the workflow history, including scheduled activities and their results. If the worker restarts, the orchestration can be replayed using the saved history.
This approach avoids depending on an application's local memory to remember which steps have completed.
How Durable Functions Works With the Go Worker
The Go worker provides a code-first programming model for Azure Functions. Developers register functions directly in Go code rather than manually creating function.json files.
Durable workflow support is provided through the middleware/durabletask package.
The architecture has three main parts:
The Azure Functions host manages triggers, function execution, and durable state.
The Go worker executes orchestrators and activities.
The Durable Task extension manages orchestration history, scheduling, and dispatch.
The Go worker uses the durabletask-go programming model for orchestrator and activity logic. The Azure Functions middleware connects that programming model to the Functions host.
An important detail is that the Go worker acts as a replay engine. The Functions host owns the durable execution state, while the worker executes orchestration logic against the history supplied by the host.
This separation allows a workflow to continue even when an individual worker process is restarted.
Prerequisites
Before creating a Go Durable Functions application, prepare the development environment.
The main requirements are:
Go 1.25 or later for the current Durable middleware dependency.
Azure Functions Core Tools version 4.12 or later.
Azure CLI version 2.87.0 or later when using the documented resource creation and deployment workflow.
Azure Functions Go worker SDK.
Durable Task middleware package.
A supported Azure Functions Flex Consumption environment for deployment.
Go applications run on Linux x64 in Azure Flex Consumption. The Go worker packaging process targets Linux x64 and requires CGO to be disabled for the documented deployment workflow.
The Durable middleware also requires a Durable Task extension version 3.15.0 or later.
Creating a Go Azure Functions Project
Start by creating a project directory and initializing a Go module.
mkdir GoDurableWorkflow
cd GoDurableWorkflow
go mod init example.com/godurableworkflowInstall the Azure Functions Go worker:
go get github.com/azure/azure-functions-golang-workerThe Durable middleware and its underlying task SDK are included through the worker's Durable package dependencies.
A basic project structure looks like this:
GoDurableWorkflow/
│
├── main.go
├── go.mod
├── go.sum
├── host.json
└── local.settings.jsonThe main.go file contains the application entry point, orchestrator, activities, and HTTP starter function.
Configuring Durable Functions
The host.json file must enable the extension bundle containing a Durable Task extension that recognizes the Go worker's native runtime.
For the current Go middleware integration, the documented configuration is:
{
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle.Experimental",
"version": "[4.7.0, 5.0.0)"
},
"extensions": {
"durableTask": {
"hubName": "OrderProcessingHub"
}
}
}The extension bundle requirement is important. Without a Durable Task extension version that recognizes the native Go worker runtime, durable bindings might not work correctly.
The hubName identifies the task hub used to store and coordinate workflow execution. Use a separate task hub for environments that need isolated workflow state.
Azure Storage is the default backend for this configuration. During local development, Azurite can provide the required storage services.
Building an Order Processing Workflow
Consider an application that receives an order through an HTTP endpoint. The application must validate the order, reserve inventory, and process payment.
Instead of executing everything inside the HTTP request, the application starts a durable orchestration. The orchestrator calls activities in the required order and records their results.
The following example demonstrates the main structure.
package main
import (
"context"
"encoding/json"
"fmt"
"net/http"
"github.com/azure/azure-functions-golang-worker/sdk"
"github.com/azure/azure-functions-golang-worker/worker"
"github.com/azure/azure-functions-golang-worker/middleware/durabletask"
"github.com/microsoft/durabletask-go/api"
"github.com/microsoft/durabletask-go/task"
)
type Order struct {
OrderID string `json:"orderId"`
Amount int `json:"amount"`
}
func ValidateOrder(
ctx task.ActivityContext,
) (any, error) {
var order Order
if err := ctx.GetInput(&order); err != nil {
return nil, err
}
if order.OrderID == "" || order.Amount <= 0 {
return nil, fmt.Errorf("invalid order")
}
return order, nil
}
func ReserveInventory(
ctx task.ActivityContext,
) (any, error) {
var order Order
if err := ctx.GetInput(&order); err != nil {
return nil, err
}
// Replace this example with an inventory service call.
return true, nil
}
func ProcessPayment(
ctx task.ActivityContext,
) (any, error) {
var order Order
if err := ctx.GetInput(&order); err != nil {
return nil, err
}
// Replace this example with a payment provider integration.
return map[string]string{
"orderId": order.OrderID,
"status": "payment-approved",
}, nil
}
func OrderOrchestrator(
ctx *task.OrchestrationContext,
) (any, error) {
var order Order
if err := ctx.GetInput(&order); err != nil {
return nil, err
}
var validated Order
err := ctx.CallActivity(
"ValidateOrder",
task.WithActivityInput(order),
).Await(&validated)
if err != nil {
return nil, err
}
var reserved bool
err = ctx.CallActivity(
"ReserveInventory",
task.WithActivityInput(validated),
).Await(&reserved)
if err != nil {
return nil, err
}
if !reserved {
return nil, fmt.Errorf("inventory unavailable")
}
var paymentResult map[string]string
err = ctx.CallActivity(
"ProcessPayment",
task.WithActivityInput(validated),
).Await(&paymentResult)
if err != nil {
return nil, err
}
return paymentResult, nil
}
func StartOrder(
w http.ResponseWriter,
r *http.Request,
) {
var order Order
if err := json.NewDecoder(r.Body).Decode(&order); err != nil {
http.Error(
w,
"Invalid request",
http.StatusBadRequest,
)
return
}
client, ok := durabletask.ClientFromContext(r.Context())
if !ok {
http.Error(
w,
"Durable client unavailable",
http.StatusInternalServerError,
)
return
}
id, err := client.ScheduleNewOrchestration(
r.Context(),
"OrderOrchestrator",
api.WithInput(order),
)
if err != nil {
http.Error(
w,
"Unable to start workflow",
http.StatusInternalServerError,
)
return
}
if err := client.WriteCheckStatusResponse(
w,
r,
string(id),
); err != nil {
http.Error(
w,
"Unable to create status response",
http.StatusInternalServerError,
)
return
}
}
func main() {
app := sdk.FunctionApp()
durable := durabletask.Middleware()
durable.Orchestrator(
"OrderOrchestrator",
OrderOrchestrator,
)
durable.Activity(
"ValidateOrder",
ValidateOrder,
)
durable.Activity(
"ReserveInventory",
ReserveInventory,
)
durable.Activity(
"ProcessPayment",
ProcessPayment,
)
app.Use(durable)
app.HTTP(
"startOrder",
StartOrder,
sdk.WithMethods("POST"),
sdk.WithAuth("function"),
durabletask.ClientInput(),
)
worker.Start(app)
}This example demonstrates the orchestration structure. The inventory and payment activities contain placeholder logic and must be connected to real services before being used in an application.
The HTTP starter receives the order, obtains the durable management client from the invocation context, and schedules the orchestration. The management client is made available through durabletask.ClientInput().
The status response provides the client with URLs for checking the orchestration state. This is useful because the HTTP request does not need to remain open while the entire workflow executes.
Understanding Orchestration Replay
One of the most important concepts in Durable Functions is replay.
Suppose an order workflow completes the validation and inventory reservation activities, but the worker restarts before the payment activity finishes.
When the orchestration runs again, the Durable Task engine uses its stored history to reconstruct the previous execution. It does not need to repeat successful activity operations simply because the orchestrator function is executing again.
However, this behavior requires deterministic orchestration code.
Avoid performing direct HTTP requests, database writes, random number generation, or reading the current system time inside an orchestrator. These operations can produce different results during replay.
Put such operations inside activities instead.
For example, payment processing belongs inside ProcessPayment, not directly inside OrderOrchestrator.
Running the Application Locally
For local development, configure the worker runtime as native in local.settings.json.
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "native"
}
}Start Azurite before running the application if you are using local Azure Storage.
Then start the Functions host:
func startCore Tools builds the Go application and starts the Functions host. The host communicates with the Go worker through its native worker protocol.
Send a POST request to the starter endpoint:
curl -X POST \
http://localhost:7071/api/startOrder \
-H "Content-Type: application/json" \
-d '{
"orderId": "ORD-1001",
"amount": 2500
}'The response contains orchestration management information. Use the returned status URL to check whether the workflow is pending, running, completed, or failed.
Choosing a Durable Storage Backend
Azure Functions Durable workflows can use Azure Storage as the default backend. The Go middleware also documents integration with Durable Task Scheduler.
The application code can remain the same when changing the backend. The storage configuration changes in host.json.
For Durable Task Scheduler, configure the storage provider:
{
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle.Experimental",
"version": "[4.7.0, 5.0.0)"
},
"extensions": {
"durableTask": {
"hubName": "OrderProcessingHub",
"storageProvider": {
"type": "azureManaged",
"connectionStringName": "DURABLE_TASK_SCHEDULER_CONNECTION_STRING"
}
}
}
}The application setting should contain the scheduler endpoint and task hub information:
Endpoint=https://<scheduler>.<region>.durabletask.io;Authentication=DefaultAzure;TaskHub=<hub>For managed identity authentication, assign the Durable Task Data Contributor role to the application's identity on the scheduler resource.
Choose the backend based on the application's operational requirements, deployment environment, and monitoring needs. Validate the selected backend with the exact worker and extension versions used by the application before production deployment.
Best Practices for Durable Go Workflows
Durable workflows are useful for long-running business processes, but they require careful implementation.
Keep orchestrator functions deterministic. Put external operations inside activities.
Make activities idempotent because an activity can be delivered more than once under failure and retry conditions.
Use meaningful activity names and orchestration names so execution history is easier to understand.
Keep orchestration inputs and outputs reasonably small. Store large documents in Blob Storage and pass references when appropriate.
Handle activity failures explicitly. Use retry policies for temporary failures such as network timeouts and service throttling.
Keep secrets in application settings or a managed secret service.
Monitor workflow status and activity failures instead of relying only on application logs.
Also remember that Durable Entities are not currently supported by the Go Azure Functions middleware. If the application depends on entity-based state management, review this limitation before choosing the Go integration.
Advantages and Limitations
Using Durable workflows with Go provides several benefits:
Developers can build long-running workflows using Go.
Workflow state is maintained outside the worker process.
Activities can be executed independently and coordinated through orchestrators.
Failed or interrupted workflows can continue using their saved execution history.
Existing Go skills and standard Go modules can be used in serverless applications.
There are also limitations:
Go hosting is currently limited to Linux Flex Consumption.
The Durable middleware requires Durable Task extension version 3.15.0 or later.
Durable Entities are not supported by the current Azure Functions Go middleware.
Extended sessions are not supported for this worker integration.
The underlying Go Durable Task SDK and some integration capabilities have their own version and compatibility requirements.
Summary
Durable workflows bring stateful execution capabilities to Go applications running on Azure Functions. Developers can define orchestrators and activities using Go, while the Functions host and Durable Task extension manage workflow state, scheduling, and recovery.
The middleware/durabletask package provides the integration between the native Go worker and the Durable Task programming model. This makes it possible to build processes such as order handling, payment workflows, document processing, and multi-step integrations without managing workflow state manually.
For successful implementation, focus on deterministic orchestrators, idempotent activities, correct extension configuration, and reliable monitoring. These practices help build workflows that can recover from failures and continue processing without losing their execution history.


Join the conversation! Your thoughts help the community grow.