Databricks Module 7: Jobs, Orchestration, and Deploying with Git and Bundles
Introduction
Notebooks are great for development, but production work must run on a schedule, in order, and with alerts. Lakeflow Jobs (formerly Databricks Workflows) is the built-in orchestrator. This module builds a multi-task job, makes it configurable, and introduces deploying it from source control.
Prerequisites
- Module 6 completed
Step-by-Step Guide
Step 1: Create a job with several tasks
A job is a set of tasks with dependencies. A task can run a notebook, a Python script or wheel, SQL, a pipeline update, or another job. Define the order by making one task depend on another. Run tasks on job compute, which starts for the run and shuts down afterward, or on serverless compute, and avoid all-purpose clusters for scheduled work because they cost more.
Job: daily_orders
task 1: ingest_orders (notebook) Auto Loader into orders_bronze
task 2: run_pipeline (pipeline update) bronze -> silver -> gold depends on 1
task 3: publish_report (SQL) refresh dashboard tables depends on 2Step 2: Pass parameters with widgets
Parameters make one notebook reusable across dates and environments. Define a widget in the notebook and set its value from the job's parameters. Read it with dbutils.widgets.get.
dbutils.widgets.text("run_date", "")
dbutils.widgets.text("catalog", "lab")
run_date = dbutils.widgets.get("run_date")
catalog = dbutils.widgets.get("catalog")
df = spark.table(catalog + ".sales.orders_silver").filter("date(ingested_at) = '" + run_date + "'")
print(df.count())Step 3: Schedule, retry, and alert
Add a schedule with a cron expression and a time zone, or trigger runs when files arrive. Configure retries for transient failures, a timeout so a stuck task cannot run forever, and email or webhook notifications on failure. Keep tasks idempotent so a retry or a rerun for the same date gives the same result, for example by overwriting a date's partition or using MERGE.
Schedule 0 30 1 * * ? (Quartz cron: every day at 01:30)
Retries 1-2 on each task
Timeout set a maximum run time
Notify on failure -> team email or webhookStep 4: Keep code in Git
Do not develop only in the workspace. Connect a Git provider with Git folders, work on branches, review changes with pull requests, and run jobs from a specific branch or tag so production runs reviewed code. Move shared logic out of notebooks into Python modules that you can test.
Step 5: Deploy with Databricks Asset Bundles
Asset Bundles let you describe jobs, pipelines, and other resources as YAML files in your repository and deploy the same definition to dev and prod with one command. That makes environments consistent and changes reviewable. Check the current name and command reference, since tooling evolves.
# databricks.yml (simplified)
bundle:
name: orders_project
resources:
jobs:
daily_orders:
name: daily_orders
tasks:
- task_key: ingest_orders
notebook_task:
notebook_path: ./notebooks/ingest_orders.py
targets:
dev:
mode: development
default: true
prod:
mode: production
# deploy and run
# databricks bundle validate
# databricks bundle deploy -t dev
# databricks bundle run daily_orders -t devFAQs
- Job compute or serverless?
- Serverless compute starts quickly and needs no tuning, which suits many jobs. Classic job clusters give you control over machine types and libraries and can be cheaper for heavy, predictable work. Compare cost and startup time for your workload.
Summary
Build jobs from dependent tasks on job or serverless compute, parameterize with widgets, schedule with retries and alerts, keep code in Git, and deploy repeatably with Asset Bundles.
Related tutorials
- Databricks Module 8: SQL Warehouses, Performance, Cost, and a First Look at MLflow
- Databricks Module 6: Declarative Pipelines and the Medallion Architecture
- Databricks Module 5: Ingesting Files with Auto Loader and COPY INTO
- Databricks Module 4: Unity Catalog, Volumes, and Governance
- Databricks Module 3: Delta Lake Tables, MERGE, and Time Travel
Comments
Log in or create a free account to join the discussion.