Media

Azure Durable Functions: Building Resilient, Stateful Workflows in the Cloud

In our recent tech session, we explored how Azure Durable Functions can be used to build resilient, stateful, serverless workflows, with a practical demo of a real-time SQL Server integration app.

This post captures the key insights from that session, including architecture concepts, implementation details, cost considerations, and a Q&A discussion from the team.

What Are Durable Functions?

Azure Durable Functions is an extension of Azure Functions that allows you to write stateful workflows in a serverless environment.

At a high level:

  • It’s a Function App
  • It uses a Microsoft NuGet extension package
  • Deployment is the same as a normal function app
  • It introduces three core components:
    • Orchestrations
    • Activities
    • Entity Functions

Durable Functions solve one major limitation of traditional serverless: Stateless execution.

With Durable Functions, workflows can pause, resume, retry, and survive infrastructure failures, without you writing complex state management logic.

Serverless Microservices vs Container-Based Microservices

There’s often debate between:

  • Azure Container Apps
  • Kubernetes
  • Azure Functions (Function-as-a-Service)

A common misconception is that:

“If it’s not containerized, it’s not a microservice.”

That’s not true.

A microservice does not need to be a container. Azure Functions can:

  • Run serverless
  • Be containerized
  • Run inside Azure Container Apps

Why Choose Azure Functions?

  • Auto event-driven
  • Auto-scales (including scale-to-zero on consumption plan)
  • No infrastructure management
  • Rapid time-to-market
  • Built-in retries
  • Queue-backed execution
  • Very cost effective

Microsoft manages the infrastructure, making it largely a no-ops deployment model compared to Kubernetes.

The Big Advantage: Resilience to VM Recycling

In cloud environments, VMs recycle. They crash. They restart.

If you’re running a long workflow:

  • What happens if the VM dies halfway?

With Durable Functions:

  • State is persisted automatically
  • Work resumes from the exact point it left off
  • You don’t write recovery logic

The framework:

  • Stores checkpoints
  • Replays orchestration logic deterministically
  • Restores execution from storage

This is one of the strongest value propositions of Durable Functions.

Core Components Explained

1. Activity Functions

Activities are the “workers.”

They:

  • Perform actual work
  • Can do I/O
  • Can call HTTP endpoints
  • Can use randomness
  • Are a unit of retry

Example:
If sending 100 emails:

  • Each email should be an activity
  • If failure occurs at email #57
  • Retry resumes from #57, not from #1

2. Orchestrations

The orchestrator coordinates activities.

It:

  • Controls workflow logic
  • Stores checkpoints
  • Must be deterministic
  • Can call:
    • Activities
    • Other orchestrations (sub-orchestrations)

Important constraints:
You cannot use:

  • Now
  • Random numbers
  • Direct I/O
  • New GUIDs

Instead, you must use replay-safe APIs from the orchestration context.

The reason? Orchestrators replay execution to rebuild state.

3. Entity Functions

Entity Functions manage custom state.

They:

  • Store application-specific state
  • Expose operations
  • Use efficient signaling (gRPC under the hood)

They can be called:

  • From the orchestration
  • From activities
  • From outside using the Durable Client

Cost Efficiency: Why Durable Functions Are Powerful

One of the most important architectural insights discussed:

When a Durable Function awaits something:

  • It drops a queue message
  • The app goes to sleep
  • You do NOT pay while it waits

In contrast:

  • A normal function keeps CPU alive
  • You continue paying

For long-running workflows, this is significantly more cost-effective.

Case studies show serverless solutions reducing operational costs by 40–60% compared to Kubernetes workloads.

Demo Use Case: Real-Time SQL Server Integration

Azure Durable Functions Demo

Goal:

Integrate SQL Server data changes to a downstream system in real time.

How It Works

  1. SQL Change Tracking enabled on database and tables
  2. SQL Trigger Function detects changes
  3. Function posts changes to external API
  4. Built-in retries (5 retries, 1-minute interval)
  5. If retries fail → Durable Orchestration starts
  6. Orchestration:
    • Checks lease tables
    • Resets retry counters
    • Extends retry window up to 168 hours
    • Sends notification after 10 orchestration retries

Key Features Implemented

  • Server-side column filtering
  • Client-side additional column filtering
  • Custom retry strategy
  • Exponential retry intervals
  • Configurable retry limits
  • Notification orchestration
  • State stored in:
    • Instances table
    • History table
    • Storage queues

VM Crash Simulation

During the session:

  • A VM crash was simulated
  • Memory was wiped
  • Application restarted

Result:
The orchestration resumed automatically.
No custom recovery logic was written.

Durable Functions vs Logic Apps

Feature Durable Functions Logic Apps
Cost
Lower
Higher
Performance
High
Moderate
Scaling
Elastic, up to 200 VMs
Managed but connector-limited
Customization
Full C# control
Connector-driven
Developer Experience
Code-first, Git, unit testing
Drag-and-drop UI
Best For
Complex workflows
Rapid integration prototyping

Logic Apps are great for low-code scenarios.
Durable Functions provide deeper control and performance.

Q&A From the Session

Would this work for data aggregation instead of Databricks/Airflow?

Yes. Durable Functions are well-suited for aggregation workflows where external orchestration tools are not required.

When should you NOT use Durable Functions?

For very simple CRUD operations:

  • Single database update
  • Simple API call

A normal function or API call is sufficient.

Durable Functions shine when:

  • There are retries
  • There are workflows
  • There are long-running processes
  • External dependencies may fail

If a multi-step workflow crashes, does it restart?

No.

It resumes exactly where it left off.

This is automatic, no developer recovery code required.

How does it detect new SQL data?

By enabling SQL Change Tracking.

It:

  • Tracks inserts and updates
  • Does not function as an audit log
  • Ensures downstream systems receive the latest data

How do costs compare to normal Azure Functions?

For workflows:

  • Durable Functions are more cost-effective
  • Because they go to sleep between awaits

Normal Functions:

  • Keep CPU alive
  • Continue billing

How is this different from Hangfire?

Hangfire also provides background processing and retries.

However, Durable Functions:

  • Are cloud-native
  • Scale automatically across VMs
  • Persist workflow state in Azure Storage
  • Provide distributed locking
  • Support orchestration patterns and sub-workflows

They’re designed for elastic, distributed, serverless environments.

How do AI agents integrate with Durable Functions?

This wasn’t fully explored during the session. However, AI could theoretically:

  • Generate workflow definitions
  • Trigger orchestrations
  • Drive dynamic workflows

This remains an area for further exploration.

Real-World Use Cases

  • Long-running API retry logic
  • Email retry workflows (e.g., SendGrid 429 handling)
  • SQL-to-API integration
  • Distributed locking
  • Event-driven aggregation
  • Complex dynamic workflow engines
  • Risk model execution pipelines

Durable Functions are not just about retries.

They are about:

  • Resilient cloud-native workflows
  • State management without infrastructure burden
  • Massive horizontal scaling
  • Cost-efficient long-running processes
  • Automatic recovery from VM crashes

For teams building modern, event-driven systems in Azure, Durable Functions provide a powerful orchestration engine without the complexity of Kubernetes or external workflow platforms.

If you’d like to explore this further or discuss how this pattern could apply to your architecture, feel free to reach out to our team.

About the Presenter

Andre Maree is a Senior Developer at CyberPro Consulting with a strong focus on building scalable cloud solutions and modern application architectures. In this session, Andre shared practical insights into Azure Durable Functions, explaining how they can be used to build resilient, stateful workflows in a serverless environment.

Drawing from hands-on development experience, Andre demonstrated how Durable Functions can be applied to real-world scenarios such as SQL Server data integration, extended retry strategies, and workflow orchestration, highlighting both the architectural concepts and the practical implementation.

We can help you grow your business

Consultants
0 +
separator01.jpg

Driven by a commitment to client satisfaction, collaboration, and cutting-edge solutions. 

Years Experience

0 +
separator01.jpg

Delivering excellence through decades of expertise, innovation, and trusted solutions.

Contact us

Copyright 2024 CyberPro Consulting. All rights reserved. Gauteng Contact: 011 656 3394, Western Cape Contact: 021 551 0936