Dagster instance and persistence
DagsterInstance is the runtime boundary through which Dagster accesses durable metadata and related services. It gives run execution, the webserver, and daemon processes one view of runs, events, assets, schedules, and local artifacts while allowing the persistence layer to change without changing those callers. For the wider runtime model, see Execution runtime, Run planning and execution, Resources and IO managers, and Events and observability.
Instance boundary
The instance joins persistence stores with services that coordinate work. Callers use the instance as the main boundary instead of coupling to a database or a file layout.
Instance responsibilities
DagsterInstance presents one system boundary for metadata access and runtime coordination. It owns or exposes the stores for run history, structured events, schedule state, and local artifacts. It also connects those stores to the run coordinator, run launcher, scheduler, compute log manager, and optional settings or secret services.
The boundary keeps related actions together. For example, deleting a run removes both its run record and its events. Event handling can update run state and notify listeners after the event reaches the event store. This lets the execution and control-plane systems observe the same state.
References: python_modules/…/instance.py• L68-128 python_modules/…/instance.py• L473-485 python_modules/…/event_methods.py• L289-321
Instance lifetimes
Dagster supports two instance lifetimes:
| Lifetime | Purpose | Persistence model |
|---|---|---|
| Persistent | Normal local or deployed operation | Reads configuration from DAGSTER_HOME and keeps metadata across processes and sessions |
| Ephemeral | Tests and short-lived execution | Uses mostly in-memory stores and temporary local artifacts |
DagsterInstance.local_temp() provides a persistent instance backed by a temporary directory. This is useful when a test needs real storage behavior without keeping data after the test. A persistent instance can also use an external database or another configured backend.
References: python_modules/…/instance.py• L241-296 python_modules/…/factory.py• L19-59 python_modules/…/factory.py• L62-125
Process boundary
An InstanceRef is the serializable description of an instance used when a process must reconstruct the same boundary. It records the configured classes and their settings rather than holding live database connections or service objects. A webserver, daemon, or run process can therefore load the same choices in its own process.
The instance loads some services lazily from the reference. This allows a process to inspect instance metadata without loading dependencies that it does not need, while still giving the execution process access to its configured launcher, coordinator, or compute log manager.
References: python_modules/…/ref.py• L192-221 python_modules/…/ref.py• L514-599 python_modules/…/factory.py• L136-170
Instance configuration
The instance configuration selects the persistence backends and the services that use them. The normal entry point is the dagster.yaml file in the directory named by the absolute DAGSTER_HOME path.
Configuration loading
When a persistent instance starts, Dagster checks DAGSTER_HOME, loads dagster.yaml, merges any supplied overrides, and validates the result against the instance schema. An unset, relative, missing, or non-directory DAGSTER_HOME prevents the normal persistent instance from loading. An empty or missing configuration file can still use the default local metadata layout, but the absence of a file produces a warning when DAGSTER_HOME is set.
Configuration can select storage, local artifacts, compute logs, scheduling, run coordination, run launching, retention, concurrency, retries, and other instance settings. These settings affect how the runtime operates, but they remain outside the run and event data contracts.
References: python_modules/…/factory.py• L62-98 python_modules/…/config.py• L37-63 python_modules/…/config.py• L523-613
Storage configuration modes
Dagster supports one unified storage choice or the older set of separate storage fields. The unified choice describes one DagsterStorage object that exposes run, event, and schedule stores. The separate fields are combined into a composite storage for compatibility.
The configuration loader rejects a file that mixes the unified storage field with run_storage, event_log_storage, or schedule_storage. This keeps all three metadata stores on one clear configuration path. The compatibility composite can also adapt an older DagsterStorage implementation so each modern store interface delegates to the corresponding legacy store.
References: python_modules/…/config.py• L98-124 python_modules/…/ref.py• L382-432 python_modules/…/base_storage.py• L10-34 python_modules/…/legacy_storage.py• L83-168
Local artifacts
Local artifact storage provides a base directory for files that are not metadata records. It supplies locations for compute-related files, run file artifacts, and schedule files. The path is part of the instance boundary, so code that needs a local file location does not need to know how the instance was configured.
The default local layout places general artifacts below the instance base directory and gives run files, schedules, and compute logs their own subdirectories. A custom artifact backend can replace this local path contract when the deployment needs another file system.
References: python_modules/…/root.py• L19-56 python_modules/…/storage_methods.py• L112-124 python_modules/…/ref.py• L27-45
Value storage
Value storage is the data plane for op outputs and asset values. An IO manager is the pluggable interface that writes an output and later loads it as an input. This is separate from instance metadata storage: the instance records what happened, while an IO manager stores the value that downstream work needs.
An IO manager can use a local file system, a cloud file system, or another data service. Its path rules include run and step identity for op outputs and asset identity for assets. Partitioned assets map partition keys to separate locations, and a manager can load several partitions as one input. The built-in file manager serializes values to files and reports their paths as output metadata.
Input managers cover the read side when an input needs a source other than an upstream output. Both manager types are resource definitions, so jobs can select them and provide resource-level or input/output-level configuration without changing the execution contract.
References: python_modules/…/io_manager.py• L35-45 python_modules/…/io_manager.py• L120-151 python_modules/…/input_manager.py• L22-35 python_modules/…/input_manager.py• L48-58 python_modules/…/upath_io_manager.py• L56-68 python_modules/…/upath_io_manager.py• L453-511 python_modules/…/fs_io_manager.py• L34-54
Persistence abstractions
Dagster separates the kinds of metadata it stores so that each store can support the queries and update patterns of its domain. The instance exposes these abstractions as one persistence surface.
Run storage
Run storage is the durable record of planned, active, and completed runs. It keeps each run's identity, status, configuration, selection, tags, partition target, and run lineage. It also holds job and execution-plan snapshots that let later processes refer to the exact definitions used for a run.
The run record is a serializable contract shared by execution, control, and query processes. Run status moves through lifecycle states such as queued, started, successful, failed, and canceled. Status events update the durable run view, while tags support links to schedules, sensors, backfills, partitions, retries, and run groups.
Run creation also persists the snapshots needed to reconstruct a job and its plan. Storage may expose a serialized run size limit. The instance and sensor paths can measure user-controlled run data before launch, but the storage backend remains the final authority when it accepts a run.
The same abstraction covers metadata needed by wider run control flows. These include partition backfills, daemon heartbeats, run grouping, and cursor state. The execution layer writes through this interface, while the webserver and daemons query it for run history and control decisions.
References: python_modules/…/dagster_run.py• L53-138 python_modules/…/dagster_run.py• L251-367 python_modules/…/run_domain.py• L236-263 python_modules/…/run_domain.py• L641-708 python_modules/…/run_methods.py• L247-295 python_modules/…/run_size.py• L1-54 python_modules/…/sql_run_storage.py• L115-163
Event log storage
Event log storage is the durable stream of structured events produced by runs and by instance-level actions. It supports reading a run's event history, watching new events, building run and step summaries, and querying events across the system.
The instance can write one event at a time or collect events into a bounded batch. A failed batch write falls back to individual writes. After storage, event handling can update run state and notify listeners. A backend that handles run events itself can keep that update inside its event write path; other backends use the instance's run storage bridge.
Readers use storage cursors and bounded pages so a backend-side query cap does not silently return only a prefix. Run-scoped readers advance their cursor until the store reports that no more records remain. Asset queries can also request indexed summary rows when they need the asset key, partition, run, timestamp, or storage id but not the serialized event payload.
The event store also maintains the indexed view used for asset and partition queries. Asset records, latest materializations, observations, materialization attempts, asset checks, freshness state, dynamic partitions, and concurrency state are therefore part of the event persistence boundary rather than a separate asset database. Storage backends can provide cached status data and specialized indexes to make these views fast.
SQL-backed event storage separates run-scoped access from cross-run index access. This supports run-level sharding while preserving one view for system-wide queries. When an asset event is stored, the backend records the event and updates the asset-related index and selected event tags. Run history and asset views can therefore use the same event source while supporting both run-local and cross-run queries.
References: python_modules/…/event_methods.py• L77-158 python_modules/…/event_methods.py• L204-321 python_modules/…/base.py• L218-257 python_modules/…/base.py• L277-412 python_modules/…/base.py• L444-505 python_modules/…/sql_event_log.py• L148-227 python_modules/…/sql_event_log.py• L243-417 python_modules/…/sql_event_log.py• L419-510
Schedule storage
Schedule storage keeps the control state for schedules and sensors. In Dagster, an instigator is a schedule or sensor that can request work. The store records each instigator's identity and status and keeps its evaluation ticks with their status and time.
The instance exposes this state through the scheduler boundary. Start, stop, and reset actions update the stored instigator state, while tick queries let daemons read recent evaluations by instigator or in batches when the backend supports that capability. A schedule and a sensor with the same name remain distinct through their stored instigator type.
The store also provides durable state for automated asset evaluation. Daemons use this data to resume checks, inspect past decisions, apply retention, and coordinate later run requests. The scheduler service performs the work; schedule storage preserves the state that makes that work repeatable across process restarts.
Schedule backends can retain older storage layouts while newer selector-based indexes are built. Required and optional data migrations mark completed indexes so normal reads can use the faster view without losing access to older records during an upgrade.
References: python_modules/…/scheduling_methods.py• L31-71 python_modules/…/scheduling_methods.py• L85-220 python_modules/…/base.py• L24-46 python_modules/…/base.py• L83-232 python_modules/…/sql_schedule_storage.py• L271-335
Asset persistence
Asset persistence gives the asset system a durable view of materialization and health over time. It answers which assets exist, when they were last materialized or observed, which partitions are materialized, and what asset checks or freshness evaluations report.
The instance routes these reads and writes to event log storage. Runless asset events use a reserved run identity so that an asset event can be recorded even when no job run owns it. This preserves one event query model for both run-owned and externally reported asset activity. Asset status can also use a storage-backed cache, while the event history remains the source for the underlying records.
Dynamic partitions use the same boundary. The store can list keys, check one key, answer bounded membership queries for a requested set of keys when the backend supports them, and apply add or delete requests. SQL-backed storage splits large membership queries into bounded groups. A backend without this capability uses the default full-definition read, while caching callers can load that definition once instead of repeating it for each batch.
For partitioned assets, the status cache stores a checkpointed view of materialized, failed, and in-progress subsets. The cache advances from the latest event position and checks related run status for unfinished materializations. If the partition definition changes or the backend cannot use the cache, the status is rebuilt from event and run data.
Asset operations also include wiping an asset or selected partitions. The instance removes the indexed history and reports an asset-wiped event, so downstream readers can distinguish a deliberate reset from an asset with no history.
References: python_modules/…/instance.py• L301-471 python_modules/…/instance.py• L602-670 python_modules/…/types.py• L121-204 python_modules/…/base.py• L67-158 python_modules/…/base.py• L511-575 python_modules/…/base.py• L692-737 python_modules/…/sql_event_log.py• L243-343 python_modules/…/sql_event_log.py• L737-745 python_modules/…/partition_status_cache.py• L72-109 python_modules/…/partition_status_cache.py• L274-377 python_modules/…/partition_status_cache.py• L380-493
Pluggable persistence backends
The persistence interfaces define the behavior that the runtime needs, while concrete backends choose where and how to store the data. Configuration rehydrates those concrete classes from their module, class, and config data.
Backend choices
The built-in choices cover local SQLite storage and external PostgreSQL or MySQL storage. A custom class can implement the storage interfaces when a deployment needs a different database, a service API, sharding, or another data system. Older backends can remain usable through adapter classes that expose the modern run, event, and schedule contracts.
| Choice | Role | Main effect |
|---|---|---|
| SQLite | Default local persistent backend | Keeps run, event, and schedule data under a configured base directory |
| PostgreSQL or MySQL | Shared database backend | Lets multiple Dagster processes use a common external metadata store |
| Custom | Deployment-specific backend | Supplies the same storage contracts through a user-selected class |
| In-memory | Ephemeral execution backend | Supports short-lived work without durable metadata |
The in-memory event backend is intended for ephemeral instances and tests. It supports event reads and watches for that short-lived process, but it is not a complete replacement for persistent instance storage in a real deployment.
References: python_modules/…/config.py• L248-264 python_modules/…/ref.py• L76-189 python_modules/…/sqlite_storage.py• L40-86 python_modules/…/factory.py• L37-59 python_modules/…/in_memory.py• L22-48 python_modules/…/in_memory.py• L87-114 python_modules/…/legacy_storage.py• L83-168 python_modules/…/legacy_storage.py• L170-205 python_modules/…/legacy_storage.py• L373-402
Unified SQLite storage
DagsterSqliteStorage is the default unified local backend. It presents the three persistence abstractions through one configured base directory while keeping their data domains separate. This gives the instance one storage choice without forcing run, event, and schedule queries into one interface.
External database backends follow the same unified idea or expose separate implementations that the compatibility layer can combine. The runtime depends on the abstract contracts, so changing backend choice does not change how callers read a run or query an asset.
References: python_modules/…/sqlite_storage.py• L24-64 python_modules/…/sqlite_storage.py• L88-136 python_modules/…/base_storage.py• L10-34 python_modules/…/legacy_storage.py• L83-168
Schema lifecycle
Persistent stores have a schema lifecycle as well as a data lifecycle. The instance can upgrade required storage schemas and rebuild event and asset indexes before normal use. Reindex and optimization steps improve query access without changing the high-level storage contracts.
The run, event, and schedule stores each report their schema state and support disposal. SQL event storage also carries a compatibility path for older SQLite and PostgreSQL event-log layouts. A deployment that changes the Dagster version or backend must treat storage upgrades as part of instance operations, not as a run-level action. Run and event data migrations record completed index work so an upgrade or reindex can resume without repeating work that already finished.
Event data migrations can rebuild asset-key rows and asset index columns from existing event records. They use stored migration markers so the work is repeatable and can be forced when an operator needs a rebuild.
Schedule storage follows the same lifecycle. Its required and optional data migrations track built indexes, and its backend can report whether those indexes are available before using batch reads or newer selector-based views.
References: python_modules/…/instance.py• L869-901 python_modules/…/storage_methods.py• L80-124 python_modules/…/base.py• L323-335 python_modules/…/base.py• L434-479 python_modules/…/sql_event_log.py• L724-745 python_modules/…/sql_event_log.py• L875-905 python_modules/…/migration.py• L22-38 python_modules/…/migration.py• L40-163 python_modules/…/base.py• L214-233 python_modules/…/sql_schedule_storage.py• L648-711
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the unified storage contract aligned with all three store accessors: run, event, and schedule storage.
- When changing event persistence, check both run-status updates and asset indexes because event handling can feed both views.
- When changing event batch writes or pagination, preserve cursor progress, page-cap handling, and the single-event fallback path.
- When changing run deletion or retention, preserve the relationship between run records and their event history.
- When adding a configurable backend, provide serializable class data and a config schema that can be rehydrated in another process.
- When changing run creation or size limits, keep the launch-time estimate and storage-time serialized measurement aligned.
- When changing schedule or automation state, check instigator type identity, selector-based reads, tick retention, and daemon restart behavior together.
- When changing schedule indexes or batch queries, keep the fallback path for older schedule tables consistent with the newer indexed path.
- When changing a persistent store schema, update the instance upgrade and reindex path for every affected store.
- When changing SQL event sharding or cross-run queries, keep run-scoped connections and the shared index view consistent.
- When changing asset event writes, keep asset index rows and indexed asset tags aligned with the source event record.
- When changing asset status caching, keep the cache cursor, partition definition identity, and run status lookup aligned.
- When changing dynamic partition membership queries, preserve the bounded-query capability flag, query key bounds, and loader fallback that avoids repeated full-definition reads.
- When changing asset wipe behavior, keep the removed index history and the reported asset-wiped event aligned.
- When changing run status or run tags, keep the serialized run record and queryable tag view consistent for readers that observe them across process boundaries.
- When changing a SQL migration base, preserve compatibility with existing event-log layouts and the one-way upgrade contract.
- When changing an IO manager's path rules, keep asset identity, partition identity, and safe path joining aligned across local and remote file systems.
- When changing value serialization, keep the writer and reader contract compatible for every IO manager that shares stored values.
- When changing instance artifact paths, keep the instance-local artifact contract separate from metadata storage and IO manager paths.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
DAGSTER_HOME is unset, relative, missing, or not a directory | A persistent instance cannot load | Set an existing absolute DAGSTER_HOME; use an ephemeral instance only for transient work |
storage is combined with legacy individual storage fields | Configuration validation fails before the instance loads | Choose the unified storage field or the separate legacy fields, not both |
| Schedule operations run without schedule storage or a scheduler | State reads or start/stop actions fail at the instance boundary | Configure the schedule store and scheduler for schedule or sensor control |
| A schedule or sensor reuses an identity with the wrong instigator type | The old state can block the new state or carry incompatible data | Replace the stored state when the requested instigator type differs |
| A run is removed without its event history | Run queries and event queries disagree about the run | Use the instance-level run deletion path so both stores are updated |
| A run request is much larger than the storage limit | Launch work is rejected when the run is persisted | Use the estimate as an early filter, then treat storage admission as final |
| A persistent backend is behind the required schema version | Reads or writes can fail, or indexes can be stale | Run the instance upgrade and reindex process before normal service |
| A schedule backend uses a selector or batch path before its index is built | Queries can fail or return incomplete state | Check backend capabilities and complete the required data migration |
| An event backend stores an asset event but does not update its asset index or tags | Asset queries and asset history do not match the event stream | Keep event insertion and asset-index updates in the backend's event write path |
| A storage service caps a page but the reader does not advance its cursor | Event or asset queries return incomplete data | Use storage cursors and continue until the page is shorter than the requested limit |
| Run-scoped event data and the cross-run index use different connection or cursor rules | Run history and system-wide queries can miss or duplicate records | Keep sharding rules explicit and preserve the shared index contract |
| A custom or legacy adapter does not support an abstract storage contract | A runtime feature fails only when its query or update path is used | Implement or delegate the required run, event, and schedule operations before selecting the backend |
| A run status update changes the serialized run but not its indexed status or tags | Control queries can make a run appear in the wrong lifecycle state | Update the run record and its query fields as one storage contract |
| A cached partition definition does not match the current definition | Asset partition status can be stale or invalid | Rebuild the cache when the definition identity changes |
| A backend cannot answer bounded dynamic partition membership but the caller repeats one query per batch | Partition checks load the full definition many times | Use the cache loader or the backend's bounded membership capability |
| A migration assumes only the current event-log layout | An existing SQLite or PostgreSQL instance cannot upgrade safely | Keep the base migration's legacy-layout checks and test the supported backend path |
| An IO manager writes an absolute or parent-traversal partition key as a raw path | A value can be written outside the configured base path or collide with another value | Escape unsafe path segments before joining partition keys to the base path |
| An IO manager writer and reader use different serialization or partition paths | Downstream inputs cannot load stored outputs | Treat the manager's write and read methods as one storage contract |
| A real instance uses only in-memory event storage | Metadata disappears with the process and UI or core features may not work | Use in-memory storage only for ephemeral instances and tests |
Key files
| File | Why to read it |
|---|---|
| python_modules/…/instance.py | Defines the instance boundary and its relationship to stores and runtime services |
| python_modules/…/factory.py | Shows how ephemeral, temporary, and configured instances are created |
| python_modules/…/config.py | Defines the instance configuration choices and validation rules |
| python_modules/…/ref.py | Explains serializable configuration and cross-process reconstruction |
| python_modules/…/types.py | Defines instance lifetime types and dynamic partition store behavior |
| python_modules/…/event_methods.py | Shows event storage, batching, run updates, and event subscribers at the instance boundary |
| python_modules/…/run_methods.py | Shows the instance facade for run creation, size limits, queries, and updates |
| python_modules/…/storage_methods.py | Shows instance-wide storage maintenance, artifact paths, and lifecycle actions |
| python_modules/…/scheduling_methods.py | Shows how the instance routes schedule and sensor control to the scheduler and schedule store |
| python_modules/…/asset_methods.py | Shows how the instance exposes asset state and runless asset events through event storage |
| python_modules/…/run_domain.py | Shows how run records and snapshots are assembled before persistence |
| python_modules/…/base_storage.py | Defines the unified storage contract |
| python_modules/…/dagster_run.py | Defines the serializable run state, lifecycle statuses, filters, tags, and run records |
| python_modules/…/run_size.py | Defines the shared run-size measurement used before and during storage admission |
| python_modules/…/base.py | Defines durable run history, snapshots, backfills, and daemon state |
| python_modules/…/sql_run_storage.py | Illustrates SQL run persistence, status updates, snapshots, and index maintenance |
| python_modules/…/base.py | Defines event streaming, paging, asset summary queries, partition state, and concurrency contracts |
| python_modules/…/sql_event_log.py | Shows how SQL event storage links run events with cross-run indexes, asset views, bounded partition membership, and data migrations |
| python_modules/…/in_memory.py | Illustrates the short-lived event backend used by ephemeral instances and tests |
| python_modules/…/migration.py | Shows how existing event records are re-read to build or refresh asset indexes |
| python_modules/…/partition_status_cache.py | Explains incremental asset partition status and its relation to event and run state |
| python_modules/…/base.py | Defines schedule, sensor, tick, and automation state persistence |
| python_modules/…/sql_schedule_storage.py | Illustrates SQL schedule state, tick queries, fallback layouts, and data migrations |
| python_modules/…/sqlite_storage.py | Illustrates a unified pluggable backend for local persistent operation |
| python_modules/…/legacy_storage.py | Shows the compatibility layer for composite and legacy storage backends |
| python_modules/…/io_manager.py | Defines the interface that stores outputs and loads downstream inputs |
| python_modules/…/input_manager.py | Defines input-only loading as a configurable resource boundary |
| python_modules/…/upath_io_manager.py | Explains asset and partition paths across local and remote file systems |
| python_modules/…/fs_io_manager.py | Illustrates the built-in serialized file value backend and instance-based default path |