Performance & Scaling
Comprehensive guide to optimizing Elsa Workflows for high-throughput scenarios, covering commit strategies, state persistence tuning, observability, and performance best practices.
Executive Summary
This guide covers performance optimization techniques for Elsa Workflows 3.x, focusing on workflow state persistence, commit strategies, observability, and tuning for high-throughput scenarios. These optimizations are essential for production deployments handling large volumes of workflow executions.
Key Performance Considerations
State Persistence: Control when and how workflow state is persisted to the database
Commit Strategies: Choose optimal commit points to balance durability and throughput
Observability: Monitor performance with built-in tracing and custom metrics
Resource Management: Tune database connections, locks, and scheduling
Workflow Commit Strategies
Elsa Workflows provides a flexible commit strategy system that controls when workflow state is persisted during execution. This is critical for balancing durability against performance.
Understanding Commit Strategies
A commit strategy determines when the workflow engine persists workflow instance state to the database. More frequent commits increase durability (less work lost on failure) but decrease throughput (more database writes). Less frequent commits improve throughput but may lose more work on failure.
Code References:
src/modules/Elsa.Workflows.Core/CommitStates/Extensions/ModuleExtensions.cs- Registration extensionssrc/modules/Elsa.Workflows.Core/CommitStates/CommitStrategiesFeature.cs- Feature configurationsrc/modules/Elsa.Workflows.Core/Features/WorkflowsFeature.cs- WorkflowsFeature integration
Registering Commit Strategies
Use the UseCommitStrategies extension method on WorkflowsFeature to configure commit strategies:
Built-in Commit Strategies
Elsa provides the following built-in commit strategies in src/modules/Elsa.Workflows.Core/CommitStates/Strategies/Workflows/:
WorkflowExecutingWorkflowStrategy
Commits when workflow starts
Capture initial state before execution
WorkflowExecutedWorkflowStrategy
Commits when workflow completes
Minimal commits, highest throughput
ActivityExecutingWorkflowStrategy
Commits before each activity
Maximum durability, lower throughput
ActivityExecutedWorkflowStrategy
Commits after each activity
Balance of durability and visibility
PeriodicWorkflowStrategy
Commits at regular time intervals
Predictable commit timing
Code Reference: src/modules/Elsa.Workflows.Core/CommitStates/Strategies/Workflows/PeriodicWorkflowStrategy.cs
Selecting a Strategy Per Workflow
You can configure a specific commit strategy for individual workflows using WorkflowOptions.CommitStrategyName:
Programmatic (Core):
Code Reference: src/modules/Elsa.Workflows.Core/Models/WorkflowOptions.cs
Via API Client:
Code Reference: src/clients/Elsa.Api.Client/Resources/WorkflowDefinitions/Models/WorkflowOptions.cs
Via Elsa Studio:
In Elsa Studio, you can set the commit strategy in the workflow definition settings under the "Advanced" or "Options" tab.
Custom Commit Strategy: Commit Every N Activities
Elsa does not include a built-in "commit every N activities" strategy, but you can implement a custom IWorkflowCommitStrategy. Here's a minimal outline:
Registration:
Note: This is a simplified outline. The
AddStrategy<T>method registers a customIWorkflowCommitStrategywith the DI container. A production implementation should handle edge cases like workflow completion, suspension, and error states.
Observability and Monitoring
Built-in Tracing with Elsa.OpenTelemetry
Elsa provides built-in OpenTelemetry integration through the Elsa.OpenTelemetry module, which automatically instruments workflow execution with traces and spans.
Configuration:
What's Traced:
Workflow execution spans (start, complete, fault)
Activity execution spans (per activity)
Bookmark creation and resumption
HTTP workflow triggers
User-Defined Metrics
For custom performance metrics beyond built-in tracing, you can implement your own metrics collection:
Important Distinction:
Built-in tracing (Elsa.OpenTelemetry) provides distributed tracing for debugging and understanding execution flow
User-defined metrics are for custom performance monitoring, alerting, and capacity planning
Performance Tuning Best Practices
1. Choose the Right Commit Strategy
High throughput, short-lived workflows
WorkflowExecutedWorkflowStrategy
Long-running workflows with many activities
PeriodicWorkflowStrategy (e.g., every 30s)
Critical workflows requiring durability
ActivityExecutedWorkflowStrategy
Development/debugging
ActivityExecutingWorkflowStrategy
2. Database Optimization
Connection Pooling: Ensure adequate connection pool size for concurrent workflows
Indexes: Verify indexes on workflow instance and bookmark tables
Batching: Consider batch operations for bulk workflow management
3. Reduce Lock Contention
For clustered deployments, minimize lock contention:
Use workflow correlation IDs effectively to distribute load
Consider workflow partitioning strategies
Monitor lock acquisition times
See Clustering Guide for detailed distributed locking configuration.
4. Scheduler Optimization
For workflows with timers and delays:
Configure appropriate Quartz thread pool sizes
Use database-backed job store for clustering
Monitor scheduler queue depth
See examples/throughput-tuning.md for detailed tuning examples.
Key Configuration Reference
Code Reference: src/modules/Elsa/Features/ElsaFeature.cs
UseCommitStrategies()
Register commit strategies
None (must be configured)
WorkflowOptions.CommitStrategyName
Select strategy per workflow
Inherits from default
UseDistributedRuntime()
Enable distributed execution
Disabled
UseQuartzScheduler()
Use Quartz for scheduling
Default scheduler
Related Documentation
Throughput Tuning Examples - Practical tuning scenarios
Source File References - elsa-core file paths
Clustering Guide - Distributed deployment
Log Persistence - Activity log optimization
Retention - Data retention policies
Last Updated: 2025-11-28
Last updated