Introducing a new way to review your PRs.

Read the announcement

elsa-workflows / elsa-core

The Workflow Engine for .NET

View on GitHub

32 documents · Updated Oct 7, 2026

docs / persistence

Persistence architecture

Elsa persistence gives workflow management and runtime services durable storage without tying their contracts to one database. Application features start with memory stores and can replace them with provider features. The current production path is the EF Core provider family, while Persistence vNext defines a newer provider-neutral model for future use.

Persistence boundary

Stored workflow data

Elsa separates the data that describes a workflow from the data that records its execution. Workflow definitions hold the design and versions that management services publish and query. Workflow instances hold the live state that the runtime must load, update, and recover.

Runtime state supports the next execution step. It includes bookmarks that wait for external input, triggers that start workflows, queues and dead-letter records that manage pending work, and execution records that describe what ran. Supporting platform data extends the same boundary to tenants, identity, labels, alterations, and key-value data.

Data areaPurposeMain consumers
Workflow definitionsStore workflow designs and their versionsWorkflow management and runtime definition lookup
Workflow instancesStore durable execution state and instance metadataRuntime execution, recovery, and management queries
Runtime recordsStore triggers, bookmarks, queues, dead letters, and execution logsDispatch, resume, scheduling, and execution history
Platform dataStore tenant, identity, label, alteration, and key-value informationHost services and optional Elsa features

References: src/…/IWorkflowDefinitionStore.cs• L8-19 src/…/IWorkflowInstanceStore.cs• L9-21 src/…/IBookmarkStore.cs• L7-18 src/…/ITriggerStore.cs• L9-20

Provider contracts

Persistence contracts describe the operations that a feature needs. A store can find records through a filter, return pages or summaries, save or replace records, and delete records. The contract carries these needs across memory, EF Core, and future providers.

The workflow runtime uses separate contracts for different work patterns. A bookmark store supports waiting and resumption. A trigger store supports trigger replacement and lookup. Log stores support ordered history and cleanup. This separation lets a provider optimize each data shape without changing the runtime that uses it.

References: src/…/IWorkflowDefinitionStore.cs• L31-67 src/…/IWorkflowInstanceStore.cs• L23-64 src/…/ITriggerStore.cs• L20-58 src/…/IWorkflowExecutionLogStore.cs• L11-52

Storage selection

Memory stores

The workflow management and runtime features start with in-memory store implementations. These defaults make a host usable without a database, but their data is local to the process and does not provide durable state across restarts or shared state across nodes.

Feature configuration exposes a store factory rather than making the feature depend on a concrete database. A persistence provider changes that factory during application setup and registers the matching implementation with dependency injection.

References: src/…/WorkflowDefinitionsFeature.cs• L9-22 src/…/WorkflowInstancesFeature.cs• L9-22 src/…/WorkflowRuntimeFeature.cs• L82-110 src/…/WorkflowDefinitionPersistenceFeature.cs• L19-32

EF Core provider family

The established provider family maps Elsa contracts to relational databases through Entity Framework Core (EF Core). Shared persistence services handle context creation, tenant behavior, and schema updates. Database packages supply the connection setup and migrations for SQLite, SQL Server, PostgreSQL, MySQL, and Oracle.

Management persistence and runtime persistence are separate choices. A host can use the same database for both areas or give each area its own connection. Read EF Core persistence providers for the provider matrix, shared settings, tenant rules, and migration model.

References: src/…/PersistenceFeatureBase.cs• L13-67 src/…/WorkflowManagementPersistenceFeature.cs• L9-47 src/…/WorkflowRuntimePersistenceFeature.cs• L12-55 src/…/SqliteProvidersExtensions.cs• L20-74

Extension providers

The persistence boundary also supports extension providers for Dapper and MongoDB. These providers let an application keep the same workflow and runtime contracts while choosing a relational access path based on Dapper or a document database based on MongoDB. Their scope and setup differ from the established EF Core family, so read Dapper and MongoDB providers before selecting one.

References: src/…/Elsa.Persistence.Dapper src/…/Elsa.Persistence.MongoDb

Application wiring

Application code selects storage at the feature boundary. The host enables a persistence family for management and runtime, then selects a concrete database or document provider through that family's setup. The resulting registrations replace the stores owned by those features, so other platform areas can keep their own defaults or provider choices.

The selection flow is:

flowchart LR
    A[Application feature setup] --> B[Persistence feature]
    B --> C[Provider choice]
    C --> D[Dependency injection registrations]
    D --> E[Management and runtime stores]
    E --> F[Durable workflow data]

For example, the reference host configures management and runtime independently with UseEntityFrameworkCore and UseSqlite in src/…/Program.cs.

References: src/…/Program.cs• L58-101 src/…/Extensions.cs• L8-35 src/…/Extensions.cs• L10-19

Workflow persistence

Management data

Management persistence is the durable home for workflow definitions and instances. Definition stores support version lookup, filtered queries, paging, summaries, and save or delete operations. Instance stores provide the matching lifecycle for running and completed workflow instances.

The management services use these contracts to publish definitions and manage instances. The runtime then uses the stored definition and instance data while it dispatches or resumes work. Read workflow management for the authoring and version flow.

References: src/…/IWorkflowDefinitionStore.cs• L107-162 src/…/IWorkflowInstanceStore.cs• L132-180 src/…/WorkflowInstancePersistenceFeature.cs• L9-27

Runtime data

Runtime persistence keeps the information needed to find and continue work. Bookmarks connect external events to waiting activities. Triggers connect incoming stimuli to workflow definitions. Queues and dead-letter records protect pending work from loss, while execution logs provide a record of workflow and activity progress.

The runtime also uses a commit boundary when a provider supports it. This boundary lets related state changes be persisted as one unit when the selected provider can provide that guarantee. Read workflow runtime for dispatch, recovery, and distributed runtime behavior.

References: src/…/WorkflowRuntimePersistenceFeature.cs• L23-55 src/…/IBookmarkStore.cs• L13-49 src/…/IWorkflowExecutionLogStore.cs• L14-52 src/…/IActivityExecutionStore.cs• L11-81

Tenant scope and schema lifecycle

The EF Core path applies the current tenant to tenant-scoped records and filters reads by that tenant. This keeps one database usable by multiple tenants while leaving explicitly tenant-agnostic data visible where required.

Each EF Core data area has a schema model and provider migration history. Persistence features can apply pending migrations during startup, or an application can disable startup migration when a separate deployment process owns schema changes.

References: src/…/PersistenceFeatureBase.cs• L21-67 src/…/TenantAwareDbContextFactory.cs• L8-36 src/…/RunMigrationsStartupTask.cs• L10-28

Persistence vNext

Schema manifests and physicalization

Persistence vNext is a next-generation stack that separates a module's data description from the database form. A schema provider declares storage units, fields, keys, and indexes. A catalog combines those declarations, and a provider planner turns the result into a relational or document plan. A document store then materializes and serves the plan.

This model aims to let module authors describe storage once. Database-specific packages handle the physical form for relational databases or MongoDB. Startup materialization can create or update the selected provider structures before the application uses them.

The main flow is:

flowchart LR
    A[Module schema providers] --> B[Schema catalog]
    B --> C[Provider planner]
    C --> D[Relational or document plan]
    D --> E[Document store]
    E --> F[Materialized storage]

Read Persistence vNext for the stack's schema, provider, and rollout details.

References: src/…/IPersistenceSchemaProvider.cs• L1-6 src/…/IPersistenceSchemaPlanner.cs• L1-6 src/…/IDocumentStore.cs• L1-14 src/…/DefaultPersistenceSchemaCatalog.cs• L7-25 src/…/PersistenceVNextStartupTask.cs• L16-50

Adoption boundary

Persistence vNext does not replace every specialized runtime store by default. Metadata-shaped data fits its document and index model more easily than ordered append or queue workloads. Queue data still needs lease, retry, visibility-timeout, and dead-letter behavior. Ordered logs still need append, retention, and replay evidence.

The runtime evaluator uses provider tests and representative benchmarks as the gate for moving a store. This keeps a new storage path from changing runtime behavior before it proves the required query, concurrency, and recovery guarantees.

References: src/…/WorkflowRuntimePersistenceEvaluator.cs• L3-59 src/…/IDocumentStore.cs• L5-13 src/…/RuntimeEntityPersistenceSchemaProvider.cs• L7-62

Change checklist

When these files or sections are changed, remember to consider these:

  • When a store contract changes, update every provider that replaces its feature factory and preserve the filter, paging, save, delete, and concurrency behavior expected by its consumers.
  • When workflow definition or instance state changes, check both management persistence and the runtime recovery paths that load that state.
  • When a runtime record changes, check queue, bookmark, trigger, log, and commit behavior as separate contracts rather than assuming one store change covers all of them.
  • When a provider changes, keep its connection setup, model rules, migration history, tenant behavior, and startup registration aligned.
  • When a new Persistence vNext schema is added, keep storage-unit names and indexes unique across providers and confirm that materialization is safe for concurrent application startup.

Important failure modes

TriggerConsequenceGuard
The host leaves the default memory stores in a multi-node or restart-sensitive deploymentWorkflow definitions, instances, bookmarks, and triggers are not durable or sharedSelect a durable provider for every data area that must survive restart or cross node boundaries.
Management and runtime use different databases without an intentional data boundaryThe runtime can fail to find the definitions or instances that management savedConfigure and document the relationship between the management and runtime stores.
A provider replaces only part of a feature's store setSome runtime state remains process-local while other state is durableReview the full feature registration when selecting a provider.
Tenant filtering or save-time tenant assignment is lostOne tenant can read or create records belonging to another tenantPreserve tenant-aware context creation and both read and write tenant rules.
Startup materialization or migration lacks database access or schema rightsThe application cannot create or update the structures needed by its storesCheck provider access, schema rights, migration ownership, and concurrent-start behavior.
A queue or ordered log is moved to a generic provider without evidenceRetries, leases, ordering, retention, or replay can change under loadRequire provider contract tests and representative benchmarks before adoption.

Key files

FileWhy to read it
src/…/IWorkflowDefinitionStore.csDefines the contract for durable workflow definitions and their versions.
src/…/IWorkflowInstanceStore.csDefines the contract for durable workflow instance state and queries.
src/…/WorkflowRuntimeFeature.csShows the runtime store boundaries that providers can replace.
src/…/PersistenceFeatureBase.csShows the shared boundary for EF Core provider registration, tenant handling, and migrations.
src/…/WorkflowManagementPersistenceFeature.csShows how one EF Core management setup covers definition and instance persistence.
src/…/WorkflowRuntimePersistenceFeature.csShows how EF Core connects runtime contracts and optional commit transactions.
src/…/SqliteProvidersExtensions.csShows how an application selects a concrete database provider.
src/…/Program.csShows the application-level selection of management and runtime persistence.
src/modules/Elsa.Persistence.Dapper/Entry point for the Dapper persistence provider family.
src/modules/Elsa.Persistence.MongoDb/Entry point for the MongoDB persistence provider family.
src/…/DefaultPersistenceSchemaCatalog.csShows how vNext combines module schema declarations.
src/…/PersistenceVNextStartupTask.csShows the vNext startup materialization boundary.
src/…/WorkflowRuntimePersistenceEvaluator.csShows the evidence gate for moving runtime workloads to vNext.