Introducing a new way to review your PRs.

Read the announcement

bruin-data / bruin

Build data pipelines with SQL and Python, ingest data from different sources, add quality checks, and build end-to-end flows.

View on GitHub

21 documents · Updated Nov 20, 2026

docs / pipeline-orchestration

Pipeline orchestration

Bruin turns one or more pipeline definitions into a run-ready workload. It builds the pipeline model, applies shared settings and variants, links local dependencies, filters the requested scope, and hands a dependency-aware graph to the scheduler. The pipeline specification describes the user-facing model. The execution runtime describes what happens after orchestration.

Pipeline model

Pipeline definition

A pipeline is the top-level plan for related work. It gives the plan its identity, schedule, shared defaults, variables, variant choices, and run controls. Its assets are the named units that Bruin can select for execution.

An asset is one unit of work with an identity, type, executable or definition source, target settings, and upstream declarations. It can also carry quality checks, hooks, metadata, and run limits. The pipeline builder keeps these concerns in one model so later selection and execution use the same asset view.

References: pkg/…/pipeline.go• L1381-1427 pkg/…/pipeline.go• L2338-2375 pkg/…/yaml.go• L431-472 pkg/…/yaml.go• L545-707

Asset dependencies

An asset dependency describes an upstream input for an asset. When the upstream name matches an asset in the loaded pipeline, Bruin links both sides of the local graph. A URI outside the pipeline can still describe lineage or an input, but it does not create a local scheduling edge.

Full dependencies control order. Symbolic dependencies describe a relationship without blocking execution. This lets a pipeline keep useful context without requiring Bruin to schedule an unavailable upstream asset. The last, first, and any modes carry cross-pipeline evaluation rules for the orchestrator; inside one pipeline they act as full dependencies.

Some asset types express an input through parameters instead of depends. For an inference asset, input_asset is added as a full local dependency before the builder links the graph. The builder rejects a missing or self-referencing input and avoids adding a duplicate when the same dependency is already declared.

flowchart LR
    source[Local upstream asset] --> transform[Downstream asset]
    external[External URI] -. lineage or input .-> transform
    symbolic[Symbolic asset link] -. non-blocking .-> transform

References: pkg/…/pipeline.go• L1651-1665 pkg/…/pipeline.go• L1810-1852 pkg/…/pipeline.go• L3185-3201 pkg/…/pipeline.go• L3230-3253 pkg/…/yaml.go• L45-223 pkg/…/scheduler.go• L795-833 pkg/…/pipeline_test.go• L514-580

Pipeline construction

Definition loading

Pipeline construction starts with a pipeline or asset path. Bruin resolves the pipeline definition, reads its shared settings, and loads supported asset definitions from the task directories. It then groups assets by type and name so later steps can select and connect them.

The builder can return one pipeline view or a fully materialized pipeline for each declared variant. A normal build requires a selected variant when the definition declares variants. The plural builder discovers the declared variants and returns one ready pipeline per variant, so callers can use the same entry point for both variant and non-variant pipelines.

YAML asset definitions become the same asset model as comment-based definitions. Comment-based assets can use inline fields or an embedded YAML block while keeping the executable body separate from the definition. Dependency modes are normalized while they enter the model, and unknown modes use the safe full-dependency behavior. Platform-specific settings remain part of the asset model and can also come from pipeline defaults.

References: pkg/…/pipeline.go• L3057-3227 pkg/…/pipeline.go• L3298-3342 pkg/…/pipeline.go• L3354-3369 pkg/…/comment.go• L42-142 pkg/…/comment.go• L188-229 pkg/…/yaml.go• L45-223 pkg/…/yaml.go• L431-452 pkg/…/yaml.go• L481-687

Variable context

Pipeline variables provide named values with defaults and optional type rules. Bruin uses their current values to render build-time identity and structure fields, while the same context can flow to the runtime renderer for fields that need run-time data.

Variants are named sets of variable overrides. Bruin checks that each override names a declared variable and has a compatible basic type before it builds the variant. Schema diagnostics check variable schemas and defaults as advisory messages; they use a local schema definition and do not change the schemas or values used by live jobs.

References: pkg/…/variables.go• L14-124 pkg/…/variables_schema.go• L11-56 pkg/…/variant.go• L13-61 pkg/…/variant.go• L128-193 pkg/…/pipeline.go• L2397-2439

Effective asset configuration

The builder creates an effective asset before scheduling. Shared pipeline defaults fill missing asset values while explicit asset values remain in control. This produces one consistent view for selection, validation, connection use, and execution.

Connection choice follows the asset type when an asset has no explicit connection. Bruin checks the pipeline's named defaults in the asset type's platform priority order, then uses the standard default for the first supported platform when no named default exists. The built-in connection map includes platform defaults for supported source systems such as Odoo. Asset types with alternate platforms use their declared priority order.

Variants are named pipeline views. Bruin applies their variable overrides before asset construction. It then renders identity and structure fields such as pipeline names, asset names, dependencies, schedules, and platform settings for each materialized view. The builder links asset objects before this final rendering and rebuilds name lookup after rendered names change. Runtime template content stays available for the execution stage.

The build-time boundary matters for ClickHouse configuration. Its engine, sorting and physical key fields, index declarations, projection declarations, TTL, and settings can be inherited from pipeline defaults for native table assets. Explicit asset values win. The builder copies inherited collections so one materialized asset cannot change the pipeline defaults or another asset.

Table-format defaults apply only to asset types that support the selected format. This keeps a pipeline-wide table setting from changing unrelated asset types while allowing supported table assets to inherit it.

References: pkg/…/pipeline.go• L180-337 pkg/…/pipeline.go• L650-665 pkg/…/pipeline.go• L1057-1099 pkg/…/pipeline.go• L2501-2522 pkg/…/pipeline.go• L3070-3085 pkg/…/pipeline.go• L3177-3191 pkg/…/pipeline.go• L3207-3221 pkg/…/pipeline.go• L3409-3578 pkg/…/variant.go• L128-193 pkg/…/variant.go• L209-257 pkg/…/variant.go• L362-611 pkg/…/clickhouse_test.go• L182-409 pkg/…/variant_test.go• L203-405

Asset materialization

Materialization describes how an asset produces or updates its target. The selected policy and target platform determine the work that the runtime must perform. Full refresh and hooks can change that work while preserving the asset's declared target behavior. The execution runtime covers how the resulting work runs.

Data Vault policies are distinct materialization choices. Their refresh behavior remains part of the policy and must not be silently replaced by another policy when a platform lacks support. Hook wrapping keeps pre-work and post-work attached to the materialized workload, while dialect-aware declaration handling can preserve the order required by the target.

Asset persistence also keeps the definition readable and stable. Before writing an asset back, Bruin removes redundant values, duplicate upstreams, duplicate tags, and formatting noise. It omits settings inherited from pipeline defaults when the caller provides the pipeline context. Non-default upstream modes remain explicit in the saved definition, while the full mode keeps the short form.

References: pkg/…/pipeline.go• L648-657 pkg/…/pipeline.go• L1381-1427 pkg/…/pipeline.go• L1661-1725 pkg/…/pipeline.go• L1939-2037 pkg/…/materializer.go• L18-57 pkg/…/materializer.go• L85-177 pkg/…/hooks.go• L19-85 pkg/…/pipeline_test.go• L1379-1447

Workload selection

Selection sources

After Bruin builds the full pipeline view, it chooses the assets for the run. A workload is the set of task instances that remain eligible after the requested scope and later filters are applied.

Common selection sources include:

SelectionPurpose
Pipeline pathStart with the full pipeline.
Asset pathStart with one asset and optionally include its downstream work.
Multiple asset pathsStart with named assets from one pipeline.
Modified assetsStart with assets linked to files changed from the default branch.
TagStart with assets that have a tag.
SelectorMatch assets by name, tag, path, file, or fully qualified name.

Selectors can expand through the dependency graph. Graph operators add upstream or downstream assets, while union and intersection operators combine match sets.

References: cmd/run.go• L1019-1133 cmd/run.go• L2891-2904 pkg/…/selector.go• L30-52

Filtered workload

The run keeps task state while it narrows the workload. It marks work outside the selected scope as skipped, then applies inclusion, exclusion, task-type, disabled-asset, and streaming rules. This preserves a run summary that explains both runnable and non-runnable work.

The --only choice selects the main asset work, quality checks, or metadata push. Blocking checks can affect downstream work. Metadata push is optional and does not block downstream assets.

References: cmd/run.go• L3034-3204 pkg/…/scheduler.go• L233-287 pkg/…/scheduler.go• L665-745

Execution graph

Task instances

The scheduler expands each selected asset into task instances. The main instance represents the asset work. Quality checks and optional metadata push become separate instances so each role has its own state and dependency behavior.

The graph therefore carries more detail than the asset list. A check can be non-blocking, and metadata push does not prevent downstream asset work from starting. The scheduler can report these outcomes without treating every task as the same kind of work.

References: pkg/…/scheduler.go• L99-115 pkg/…/scheduler.go• L233-287 pkg/…/scheduler.go• L665-745

Dependency scheduling

The scheduler releases a task only after its blocking upstream instances reach a terminal state. Independent tasks can then run in parallel within worker and connection limits. A failed blocking task marks downstream work as upstream-failed, while a successful task can release the next eligible tasks.

The diagram shows how the dependency graph changes a selected task from pending work into runnable or blocked work.

flowchart TD
    pending[Pending task] --> ready{Blocking upstreams finished?}
    ready -- No --> pending
    ready -- Yes --> queued[Queued task]
    queued --> running[Running task]
    running --> success[Succeeded]
    running --> failure[Failed]
    failure --> blocked[Downstream upstream-failed]
    success --> next[Release eligible downstream tasks]

The execution runtime explains worker behavior, task execution, and result handling after this graph is ready.

References: pkg/…/scheduler.go• L940-1013 pkg/…/scheduler.go• L1127-1149

Run lifecycle

Run preparation

bruin run prepares the workload before it starts workers. It resolves the input, builds the effective pipeline, applies the run scope, checks limits and validity, and creates executors for the remaining asset types. This keeps definition and selection errors outside worker execution.

The result is a validated workload with the task state and dependency links needed by the scheduler.

References: cmd/run.go• L741-855 cmd/run.go• L1303-1399

Run state

Bruin records run state by asset and protects continuation with a pipeline compatibility hash. A --continue run can reuse completed work only when the saved plan still matches the current pipeline's name, asset identity, enabled state, and upstream links.

When the graph is compatible, completed work is skipped and failed or in-flight work returns to pending. A changed graph requires a new run instead of silently reusing an old plan.

References: pkg/…/pipeline.go• L2501-2522 pkg/…/scheduler.go• L1152-1213 cmd/run.go• L975-991

Change checklist

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

  • Asset identity changes can affect dependency links, selectors, direct asset arguments, and saved-run compatibility.
  • Dependency changes must preserve the difference between blocking full edges and non-blocking symbolic links.
  • Upstream mode changes must preserve cross-pipeline evaluation rules, local dependency ordering, and round-trip persistence. Unknown modes must keep the safe full-dependency fallback.
  • New asset types need a path through asset construction, connection resolution, workload selection, validation, and executor setup.
  • Connection mapping changes must preserve alternate platform support and explicit connection precedence. For asset types with alternates, keep the platform priority order aligned with default lookup.
  • Built-in default connection mappings must stay aligned with the platform keys used by asset and source connection discovery.
  • Inference asset changes must keep input_asset in the local graph and keep provider or column connection overrides aligned with connection discovery.
  • Pipeline defaults must continue to fill only missing asset values. They must not replace explicit asset settings.
  • Variable schema diagnostics must remain advisory, must not mutate live variable data, and must not load external schema references.
  • Variant changes must apply values before asset construction and keep rendered names and dependency values aligned with the linked asset graph.
  • Changes to templated fields must keep build-time identity rendering separate from runtime executable rendering.
  • Comment and YAML definition changes must keep metadata parsing separate from the executable body and preserve strict validation for embedded YAML.
  • ClickHouse table configuration changes must keep serialization, variant rendering, default inheritance, and explicit asset overrides aligned. Collection values must remain isolated between defaults and materialized assets.
  • Changes to materialization policies must preserve policy-specific refresh behavior. This includes Data Vault policies.
  • Changes to hooks must preserve pre-hook, main-work, and post-hook order. Declaration hoisting must remain optional and must fall back to the original script when it cannot transform the work.
  • Changes to checks or metadata push must preserve their task roles and downstream blocking rules.
  • Changes to filtering must keep selected work, skipped state, and scheduler pending state aligned.
  • Changes to compatibility inputs must preserve safe --continue behavior after graph changes.

Important failure modes

TriggerConsequenceGuard
Pipeline path has no supported definitionBruin cannot create the workload.Run from a pipeline root or from an asset inside a pipeline.
A variant pipeline has no selected variantA normal build cannot resolve one asset identity and graph.Select a variant or use the plural pipeline builder.
A variant override is unknown or has the wrong typeVariant validation stops pipeline construction.Use declared variable names and types.
A variable schema is invalid or its default does not matchAdvisory diagnostics report the problem and can hide an expected value contract.Fix the schema or default before relying on it.
A variable schema uses $refWarning validation skips schema and value checks for that variable.Keep warning-checked schemas self-contained and treat the diagnostic as a boundary.
A materialized variant has inconsistent rendered asset or dependency namesThe reported identity can diverge from the linked workload graph.Keep variant rendering aligned with asset names and dependency values.
An unknown upstream mode is accepted as a different scheduling ruleA dependency can lose its safe blocking behavior.Normalize unknown modes to full and preserve known non-full modes when persisting.
An asset type has no connection mapping or usable defaultThe asset cannot reach execution with a resolved connection.Set an explicit connection or define the matching pipeline default.
An alternate platform is checked in the wrong priority orderBruin can choose a lower-priority connection when the intended platform default exists.Keep alternate platform order aligned with the asset type's connection contract.
A selector matches no assetsThe run stops before scheduling.Check the selector against the materialized names, tags, paths, and graph.
An inference asset names a missing or itself as input_assetPipeline construction stops or the asset would have an invalid ordering edge.Keep input_asset equal to an existing, different asset name.
An inference provider or column override has no usable connectionThe inference work cannot be assigned its required provider connection.Set an explicit connection or define the provider's pipeline default.
A templated build-time field cannot renderVariant materialization stops before the workload is ready.Keep variant variables available and use values valid for the field.
A comment or embedded YAML definition is malformedThe asset is rejected before selection.Keep definition fields valid and keep embedded YAML indentation correct.
A ClickHouse table asset inherits a partial or shared mutable default incorrectlyThe target can lose table layout settings or one asset can change another asset's configuration.Preserve explicit values, copy inherited collections, and keep ClickHouse configuration serialization round-trippable.
A hook template cannot renderHook preparation stops before the workload can use the rendered hook.Keep hook variables available to the runtime renderer and inspect the reported hook position.
A hook or materialization contains a declaration that the target dialect must see firstThe target can reject the combined script.Use the dialect-aware declaration hoister. If hoisting fails, preserve the original script for the caller's fallback path.
A materialization strategy is unsupported for the asset type or platformThe workload cannot produce the required target safely.Keep the policy explicit and fail rather than silently substitute another strategy.
A blocking task failsDownstream task instances become upstream-failed.Inspect and resolve the first blocking failure before retrying downstream work.
Saved state does not match the current pipeline graph--continue refuses to resume.Start a new run after changing asset identity or dependencies.
A streaming asset enters a batch workloadBruin skips the asset because it has no finite completion point.Run the streaming asset with stream mode.
A platform cannot support a selected Data Vault policyThe materialization contract cannot be preserved safely.Keep the policy explicit and fail rather than silently substitute another strategy.

Key files

FileWhy to read it
pkg/…/pipeline.goDefines pipeline and asset state, builds materialized pipeline views, links local dependencies, resolves defaults and connections, persists definitions, and computes compatibility.
pkg/…/yaml.goMaps YAML asset definitions, including dependency modes and platform-specific settings, into the shared asset model.
pkg/…/comment.goMaps metadata written in source-file comments or embedded YAML into the shared asset model and validates embedded definitions.
pkg/…/variables.goDefines variable defaults, overrides, public schemas, and advisory schema diagnostics.
pkg/…/variables_schema.goDefines the local safety boundary for variable schema checks.
pkg/…/materializer.goApplies materialization policy, full-refresh behavior, and hook wrapping before execution.
pkg/…/hooks.goDefines how hook and materialization queries become ordered executable work and how declaration placement is handled for target dialects.
pkg/…/variant.goDefines variant validation and the boundary between build-time identity rendering and runtime rendering.
pkg/…/selector.goDefines asset matching and graph-aware selection.
pkg/…/clickhouse_test.goShows ClickHouse configuration round trips, default inheritance, explicit overrides, and native-table scope.
pkg/…/variant_test.goShows variant validation, build-time rendering, runtime template preservation, and visitor coverage for new templated fields.
pkg/…/pipeline_test.goShows the contract that inference inputs become local ordering edges, invalid inputs fail during construction, and persisted definitions retain upstream modes.
pkg/…/yaml_test.goShows accepted upstream evaluation modes, safe fallback for invalid values, and JSON round trips.
cmd/run.goConnects a run request to pipeline construction, scope filters, validation, and scheduler startup.
pkg/…/scheduler.goDefines task instances, dependency release, failure propagation, and saved run state.
docs/pipeline-specification.mdChild page for the pipeline and asset model that users define.
docs/execution-runtime.mdChild page for worker execution after orchestration prepares the workload.