It is a familiar 3 a.m. question: the nightly job turned red, but nobody can say which table is now stale, which step was skipped, and which output was silently half-written. Generic task runners answer “did the function return?” They do not answer “is this dataset fresh, and what depends on it?” That gap is exactly the pain Dagster was built to close.

Dagster reframes orchestration around software-defined assets. Instead of describing the tasks you run, you describe the data you produce and let the framework work out what must execute. A function decorated with @asset declares an artifact, its metadata, and its dependencies; the run is a consequence of that declaration rather than the thing you hand-maintain. That inversion is small enough to fit on a slide and large enough to reshape how a data platform evolves.

This tour follows the real code in the default master branch of the Dagster monorepo, commit 89e61af. The core package lives under python_modules/dagster/dagster/, and this walk stays close to the files that matter: the decorators that author definitions, the definition objects they build, the planner that compiles them, the runtime that executes them, and the instance that remembers everything.

Dagster overview: decorators feed definitions, definitions are compiled into an execution plan, and the runtime writes results into the DagsterInstance managed by the scheduler

The overview graph: the authoring decorators build definition objects, the planner turns a definition into an ExecutionPlan through resolved step inputs, and the runtime records every step into the DagsterInstance that the scheduler also drives.

Reading the overview from left to right:

Dagster detail graph: authoring decorators, definition objects, graph composition, the execution planner with step inputs, the runtime, the instance and the scheduler

The detail graph splits the same journey into seven layers, from the decorators through graph composition and step-input resolution to the scheduler daemon and the instance reference that points at real storage.

The Two Programmer Surfaces

Dagster deliberately exposes two authoring surfaces and then collapses them. The asset surface is declarative: you name the thing you produce. The op surface is imperative: you describe a computation. The magic is that assets are implemented as ops, so the runtime only ever has to execute one kind of node.

Consider the asset decorator. In asset_decorator.py, the public asset function is the third definition in the file, at line 159, after two @overload stubs that exist purely to give type checkers the right signatures. The real implementation accepts a compute_fn and a long list of keyword parameters and ends up delegating to a shared builder. A neighbouring source_asset_decorator.py produces assets that are observed rather than computed, which is how external tables enter the model without pretending Dagster owns them.

The op decorator sits one level down. At op_decorator.py:156 the op function builds an OpDefinition, and the class itself is declared in op_definition.py:65 in a deliberately compact 638-line file. An OpDefinition carries input definitions, output definitions, a compute function and a bag of configuration. Everything you can do with an asset ultimately becomes some number of ops with inputs and outputs, which is why the executor never needs a second code path.

The job and graph decorators complete the authoring layer. job, at job_decorator.py:147, and graph, at graph_decorator.py:126, are cousins: a graph is a reusable composition of ops, and a job is a graph promoted to something with a configuration surface and an execution target. JobDefinition at job_definition.py:105 runs to 1577 lines because it owns execution-time configuration, resource binding and the bridge to the planner. GraphDefinition at graph_definition.py:127 is 1195 lines and focuses on topology — inputs, outputs and the nodes between them.

That layering is the reason the rest of this tour has a clean spine. Authoring is loud and ergonomic; definitions are explicit data; everything downstream treats them as a graph to be compiled.

From Definitions to an Execution Plan

This is where Dagster stops looking like a decorator library and starts looking like a compiler. The _PlanBuilder at plan.py:92 is the heart of it, in a file that stretches to 1425 lines. Its job is to take a JobDefinition, walk its nodes, resolve every edge, and emit an ExecutionPlan — the class at plan.py:664 that the run worker actually consumes.

The algorithm is a topological walk. plan.py imports toposort from dagster._core.utils at line 74, and the builder uses the job’s nodes_in_topological_order (referenced at line 167) so that upstream steps are always planned before the steps that depend on them. The core routine, _build_from_sorted_nodes at line 214, walks that ordering and constructs a list of steps. Each step becomes an IExecutionStep, the interface declared at step.py:54. Because dependencies are resolved in topological order, the plan is a flat, ordered structure rather than a recursive tree — cheap to serialize and cheap to schedule.

The hard part is inputs. A step’s input can come from an upstream output, from a configuration file, from a default value, from a resource, or from a value stored by the asset system. Dagster models this with StepInputSource, declared at inputs.py:70 in an 874-line file. There are eight concrete subclasses in that module, among them FromStepOutput at line 278, which is the one you meet most often: it means “read the value that the step producing handle X wrote.” FromLoadableAsset, FromConfig, FromDefaultValue and the FromMultipleSources family cover the rest. The planner’s job is to decide, for every input of every step, which of these sources applies, and to fail loudly at plan time if none does.

Outputs are the mirror image. StepOutput at outputs.py:60 pairs a step handle with an output name and a type, and StepOutputHandle at line 155 gives it an identity that downstream steps can reference. This is why a Dagster plan can be validated before a single function runs: inputs and outputs are matched by handle at compile time, not discovered by trial and error at runtime.

The result is a genuinely inspectable artifact. You can print an ExecutionPlan, diff two of them, or assert on step keys in a test, because it is a data structure and not a live interpreter state. That property is what makes execute_in_process — a separate entry point that runs a job in the current process for tests — trustworthy.

Running a Plan: Steps, Outputs and Events

Execution begins from execute_plan.py, a compact 342-line orchestrator, and fans out to execute_step.py, the per-step worker. The orchestrator does not guess what can run; it asks the plan. active.py declares ActiveExecution at line 52, which tracks which steps are in flight and which have become ready as their upstream inputs resolve. This is the scheduler for a single run, distinct from the cron-oriented scheduler discussed later.

Context comes first. context_creation_job.py:78 declares ContextCreationData, which bundles the execution resources, the logging context and the instance that a run needs. Building this context is where resources are initialised, so a misconfigured database connection fails before any step runs, not halfway through.

The execution package also keeps cross-cutting concerns in their own small modules. retries.py holds retry policy, compute_logs.py captures standard output and error, and run_cancellation_thread.py watches for cancellation requests. None of these reshape the plan; they decorate how the orchestrator drives it, which keeps execute_plan.py focused on ordering rather than bookkeeping.

Inside a step, the worker executes the compute function, writes outputs through the handles the plan gave it, and emits events. The most important event for the asset model is AssetMaterialization, declared in events.py:474. It is a NamedTuple with five fields — asset_key, description, metadata, partition and tags — and it is the record that says “this asset produced a value.” Unlike a plain output, a materialization cannot be passed to another op; it is a fact about the world that the instance persists. That distinction is the whole reason asset freshness is queryable: materializations are durable history, while outputs are transient values flowing between steps.

Because every step reports through the same event channel, a run’s full story is reconstructable after the fact. You do not need application-level logging to know which asset was written; the framework already recorded it as structured data.

Where State Lives: Instance, Storage and Schedulers

DagsterInstance, declared at instance.py:69 in a 990-line module, is the single object that owns run storage, event-log storage and schedule storage. Whenever the runtime “records a run” or “emits an event,” the call ultimately lands here. The instance is also what makes local development and production feel similar: the same interface points at an in-memory store in a test, a SQLite file on a laptop, and a Postgres-backed store on a cluster.

The instance is described, not just instantiated. InstanceRef, declared at instance/ref.py:194, is a serializable pointer to the storage configuration, which is how a run on a remote worker knows which store to write to without carrying live connections across process boundaries.

Scheduling is the second consumer of the instance. The abstract Scheduler at scheduler.py:65 defines start_schedule, stop_schedule and reset_schedule, and the concrete DagsterDaemonScheduler at line 266 delegates the actual ticking to the daemon process. Each scheduled attempt produces a ScheduledExecutionResult, declared at scheduler/execution.py:9, which records whether the run launched, was skipped, or failed. The scheduler creates runs through the instance and targets a JobDefinition, closing the loop: the same definitions authored by decorators are the things cron fires.

If your team already reaches for Dask to fan work across workers, Dagster is the layer above it that owns materialization, metadata and scheduling semantics. If you have used Celery for background tasks, think of the instance as the durable history that Celery leaves to you to build. And if you have wired cron with APScheduler, the scheduler section above is the part that Dagster formalises so that a missed tick and a failed run are first-class, queryable states.

Honest Limits

Dagster is a large monorepo, and this tour follows one path through it. The definitions layer alone spans hundreds of files; connectors, integrations, the UI and the daemon live in their own packages, and some behaviour you see in production is spread across them. The line numbers cited here are pinned to commit 89e61af and will drift as the project evolves, so treat them as a map, not a contract.

The asset-centric model also asks you to think in data rather than tasks. That is a strength for a warehouse team and a tax for a team that genuinely just wants a cron wrapper around a script. The @op surface is the escape hatch, but adopting assets is where most of the value — and most of the learning curve — lives. The planner rewards that investment with inspectable plans and durable materializations, but it does not make the underlying data-model decisions for you. Those remain, correctly, yours.

Watch PyShine on YouTube

Contents