Databricks courseLesson 6 of 13
Databricks course · Lesson 6 of 13
Lakeflow Jobs: Orchestrating Pipelines on Databricks
Build production pipelines with Lakeflow Jobs: task graphs, parameters and task values, If/else and For each tasks, retries, triggers, repair runs and monitoring run history.
On this page
- Tasks and dependencies
- Defining a job as code
- Passing values: parameters, task values and dynamic references
- Control flow: If/else, For each, retries and timeouts
- Triggers: time-based or data-driven
- When a run fails: repair, do not restart
- Monitoring run history
- Run as a service principal
- Common mistakes
- Interview angle
- Key takeaway
Lakeflow Jobs (formerly Databricks Workflows) is the orchestrator built into Databricks. A job is a graph of tasks: notebooks, Python scripts or wheels, SQL queries and files, declarative pipelines, dbt projects, JARs, or other jobs. Lakeflow Jobs runs them in dependency order on the compute you choose, retries failures, starts runs on a schedule or when data arrives, and keeps a history of every run. For pipelines that live entirely on Databricks it replaces an external orchestrator such as Airflow; for estates that span many systems, Airflow can trigger Databricks jobs instead.
Tasks and dependencies
Each task has a key, a type, its compute and a list of tasks it depends on. Tasks with no dependency between them run in parallel. A typical daily pipeline looks like this:
ingest_orders ──┐
├── build_silver ── build_gold ── refresh_dashboard
ingest_customers┘ └── notify_on_failure (Run if: at least one failed)
By default a task runs only when all its upstream tasks succeeded. The Run if setting changes that, which is how you add cleanup or alerting branches:
| Run if | Runs when |
|---|---|
| All succeeded (default) | Every upstream task succeeded |
| At least one succeeded | Any upstream task succeeded |
| None failed | No upstream task failed (some may be skipped) |
| All done | Every upstream task finished, whatever the result |
| At least one failed | Any upstream task failed |
| All failed | Every upstream task failed |
A disabled task is skipped at run time but keeps its settings and history, which is useful when a step is temporarily broken.
Defining a job as code
You can build jobs in the UI, but production jobs belong in Git. With Declarative Automation Bundles (formerly Databricks Asset Bundles) a job is a YAML resource. This one runs two notebooks on serverless compute every day at 02:00 UTC, with retries and a timeout:
resources:
jobs:
daily_orders:
name: daily_orders
schedule:
quartz_cron_expression: "0 0 2 * * ?"
timezone_id: UTC
parameters:
- name: run_date
default: "{{job.start_time.iso_date}}"
email_notifications:
on_failure: [[email protected]]
tasks:
- task_key: ingest_orders
notebook_task:
notebook_path: ../src/ingest_orders.py
max_retries: 2
min_retry_interval_millis: 60000
timeout_seconds: 3600
- task_key: build_silver
depends_on:
- task_key: ingest_orders
notebook_task:
notebook_path: ../src/build_silver.py
No cluster is declared, so the tasks run on serverless compute. The CI/CD lesson shows how bundles are structured and deployed; the important habit is that the job definition is reviewed and deployed like code.
Passing values: parameters, task values and dynamic references
- Job parameters are key-value pairs set for the whole job, with defaults you can override per run. Every task can read them.
- Task values let one task publish a small result for later tasks, for example a row count or a status:
# In task "ingest_orders"
rows = spark.table("main.bronze.orders").count()
dbutils.jobs.taskValues.set(key="row_count", value=rows)
- Dynamic value references insert run-time values into settings with double braces:
{{job.parameters.run_date}},{{job.start_time.iso_date}},{{job.run_id}}, or another task’s value with{{tasks.ingest_orders.values.row_count}}.
Pass a date as a parameter instead of calling current_date() inside the notebook. Then a rerun for a past day is just a run with a different parameter, which makes backfills and repairs safe.
Control flow: If/else, For each, retries and timeouts
If/else tasks branch on a comparison of a job parameter, a task value or a dynamic value, using ==, !=, >, >=, < or <=. A common use is skipping the expensive steps when nothing arrived:
- task_key: has_new_rows
depends_on:
- task_key: ingest_orders
condition_task:
op: GREATER_THAN
left: "{{tasks.ingest_orders.values.row_count}}"
right: "0"
- task_key: build_silver
depends_on:
- task_key: has_new_rows
outcome: "true"
notebook_task:
notebook_path: ../src/build_silver.py
For each tasks run a nested task once per input, such as once per country or per source table, passing each item as {{input}}, with a concurrency limit so the loop does not overwhelm a source system.
Retries re-run a failed task up to a set number of times, with a minimum wait between attempts. They suit transient failures (a throttled API, a lost spot instance); they do not fix bad code or bad data, so keep the count small. Some features expect retries, for example a Structured Streaming job that stops after a schema change and resumes on restart.
Timeouts stop a task that hangs, and maximum concurrent runs (one by default) prevents two runs of the same job from writing the same tables at once.
Triggers: time-based or data-driven
| Trigger | Starts a run when | Good for |
|---|---|---|
| Scheduled | A cron schedule fires | Reports and loads with a fixed deadline |
| File arrival | New files land in a monitored Unity Catalog volume or external location | Partners dropping files at unpredictable times |
| Table update | Monitored source tables are updated | Downstream jobs that should follow upstream data, not the clock |
| Continuous | The previous run ends (a new run starts immediately) | Always-on streaming jobs |
| Job completion (Beta) | Upstream jobs finish with a matching result | Chaining jobs owned by different teams |
| None | Someone clicks Run now, or the API or another orchestrator calls it | Ad hoc and externally orchestrated runs |
The choice is between time-based and data-driven starts. A schedule is simple and predictable but either runs before data is ready or wastes time waiting for it; file arrival and table update triggers run when there is something to process. A common design is a table update trigger as the main start with a scheduled trigger as a backstop, which multiple triggers per job (in Beta) allow.
When a run fails: repair, do not restart
Open the job’s Runs tab: the matrix view shows each task’s result across recent runs, so a task that has started failing or slowing down stands out. Click the failed task to see its output, error and compute details.
After fixing the cause, use Repair run instead of starting a new run. A repair re-runs only the failed and skipped tasks and the tasks that depend on them, with the job’s current settings, and lets you override parameters for the repair. Two cautions:
- A repaired task starts from the beginning. If it wrote half its output before failing, a non-idempotent write (a plain append) will duplicate data. Write with
MERGE,replaceWhereor overwrite-by-partition so re-running is safe. - Repair needs a job with two or more tasks; a single-task job is simply run again.
The same actions exist outside the UI: databricks jobs run-now, databricks jobs repair-run and databricks jobs get-run in the CLI, and matching Jobs API endpoints, which is how CI pipelines and external orchestrators drive jobs.
Monitoring run history
- Compare the duration of recent runs in the run history; a job that slowly gets longer usually has a growing table, a new skew or a lost optimisation.
- Use failure notifications (email, Slack, Teams or webhooks) per job and per task, and duration warnings for runs that exceed an expected time.
- For many jobs, query the
system.lakeflowsystem tables instead of clicking through the UI: they hold job, task and run records you can turn into a failure-rate or duration dashboard.
Run as a service principal
Production jobs should run as a service principal, not as the engineer who created them. The job then keeps working when that person leaves, and its permissions can be limited to exactly the tables it needs. The owner and the run-as identity are separate settings on the job.
Common mistakes
- One giant notebook as one task. Split stages into tasks so failures are isolated, retried and repaired separately.
- Hard-coding today’s date. Use a parameter so backfills and repairs process the intended day.
- Non-idempotent writes. Repairs and retries re-run whole tasks; appends without keys duplicate data.
- High retry counts hiding real failures. Two retries for transient errors is plenty; alert on the rest.
- Personal run-as identities in production. Use a service principal.
Interview angle
“How would you design a daily pipeline on Databricks?” Describe a job with ingest, transform and publish tasks; data-driven triggers where possible; parameters for the processing date; idempotent MERGE writes; two retries with alerts; repair runs for recovery; and a service principal as the run-as identity. Mention how the job is deployed from Git, not edited in the UI.
Key takeaway
Model the pipeline as small tasks with explicit dependencies, pass dates and results through parameters and task values, start runs when data is ready, and make every task safe to re-run so that retries and repairs fix failures instead of duplicating data.
Progress is saved in this browser only. No account needed.

