Sub topic 12
Scheduling and orchestrating the flow with jobs
This chapter assumes you have built the bronze, silver, and gold steps from the earlier chapters, either as notebooks or as a declarative pipeline. It also assumes you know basic YAML. Each step runs fine by hand. A Databricks job runs them in order, on a schedule, and retries them when they fail.
What a job gives you
A job is a saved definition of one or more tasks. Each task runs a notebook, a SQL file, a Python script, or a pipeline update. Tasks declare dependencies, and Databricks builds the run order from them. A job also adds:
- A trigger: a cron schedule, a file arrival, or a manual run.
- Retries per task.
- Run history, logs, and failure notifications.
Mapping layers to tasks
The simplest design uses one task per layer. Silver waits for bronze, and gold waits for silver. If bronze fails, silver and gold do not run, so downstream tables never read half-loaded data.
Defining the job
You can click a job together in the Workflows UI. Defining it in a Databricks Asset Bundle keeps it in version control. This file defines the three-task job:
resources:
jobs:
orders_medallion:
name: orders-medallion
max_concurrent_runs: 1
schedule:
quartz_cron_expression: "0 0 * * * ?"
timezone_id: UTC
pause_status: UNPAUSED
email_notifications:
on_failure:
- [email protected]
tasks:
- task_key: bronze_ingest
notebook_task:
notebook_path: ../src/bronze_orders.py
max_retries: 2
min_retry_interval_millis: 60000
- task_key: silver_merge
depends_on:
- task_key: bronze_ingest
notebook_task:
notebook_path: ../src/silver_orders.sql
- task_key: gold_revenue
depends_on:
- task_key: silver_merge
notebook_task:
notebook_path: ../src/gold_daily_revenue.sqlThe cron expression uses Quartz syntax, so 0 0 * * * ? means the top of every hour. Setting max_concurrent_runs: 1 stops a slow run from overlapping with the next one. Two runs writing to the same silver table would otherwise compete.
If you built the layers as a declarative pipeline, replace the three tasks with a single pipeline_task that points at the pipeline. The pipeline resolves layer order itself, so the job only needs to trigger it.
Why reruns are safe
Retries and repair runs only work if each task can run twice without damage:
- Bronze uses Auto Loader with a checkpoint, so a retry skips files it already loaded.
- Silver uses
MERGEkeyed onorder_id, so a retry updates rows and does not duplicate them. - Gold uses
CREATE OR REPLACE TABLE, so a retry rebuilds the same result.
If a run fails at silver, use Repair run. It reruns only the failed task and the tasks after it, and it keeps the bronze result.
Choosing a trigger
| Trigger | Use it when |
|---|---|
| Scheduled (cron) | Consumers expect data at a fixed cadence, such as hourly dashboards |
| File arrival | Files land unpredictably and you want a run soon after they appear |
| Continuous | Latency must be seconds to minutes, and you accept always-on compute |
The bronze example uses trigger(availableNow=True), which processes everything new and then stops. This fits scheduled and file-arrival jobs, because the task ends and the next task can start.
Common errors
- Missing
depends_on. Tasks without it start in parallel, so silver can read bronze before it finishes. - Time zone mistakes. A schedule set in UTC runs at a different local hour after a daylight saving change.
- No failure alert. A silently failing job leaves gold stale with no visible error.
Exercise
The silvermerge task fails after bronzeingest succeeds. You fix the bug and want gold to update without re-ingesting files. What do you do, and why is it safe?
Show answer
Use Repair run on the failed job run. It reruns silvermerge and goldrevenue and skips bronzeingest, which already succeeded. It is safe because the MERGE is keyed on orderid and gold is rebuilt with CREATE OR REPLACE, so neither step produces duplicates.