From notebooks to a pipeline that runs itself
ShopKart's pipeline works, but someone has to click βRunβ every morning. Let's split it into three notebooks and let Databricks run them at 6 AM daily, in order, retrying on hiccups and emailing us if something breaks.
shopkart/
βββ databricks.yml β the job, as code (a bundle)
βββ notebooks/
β βββ 01_bronze.py β Auto Loader into bronze (lesson 7)
β βββ 02_silver.py β clean + MERGE + SCD2 (lesson 6)
β βββ 03_gold.py β daily_city_revenue
βββ tests/
βββ test_transforms.py β unit tests for cleaning functionsβ°Trigger
Every day 06:00 IST, or when new files arrive
π₯bronze
01_bronze
π₯silver
02_silver Β· retries: 2
π₯gold
03_gold
π§Alert
Email on failure
Parameters: no more hard-coded dates
In lesson 6 we wrote run_date = "2026-11-18". In a job, it becomes a parameter:
# Creates an input box when run by hand; the job fills it automatically.
dbutils.widgets.text("run_date", "2026-11-18")
run_date = dbutils.widgets.get("run_date")
# Secrets: never hard-code passwords
api_key = dbutils.secrets.get(scope="shopkart", key="payments_api_key")
# ... the silver code from lesson 6, using run_date ...
# Optional: pass a value to the next task
dbutils.jobs.taskValues.set(key="silver_rows", value=spark.table("shopkart.silver.orders").count())The job as code: Declarative Automation Bundles
Bundles were called Databricks Asset Bundles until March 2026, and you'll still see that name in many tutorials. Only the name changed: the databricks bundle commands and the databricks.yml file work exactly as before.
bundle:
name: shopkart
resources:
jobs:
shopkart_daily:
name: shopkart-daily
schedule:
quartz_cron_expression: "0 0 6 * * ?" # 06:00 every day
timezone_id: Asia/Kolkata
parameters:
- name: run_date
default: "{{job.start_time.iso_date}}" # today's date, filled at run time
email_notifications:
on_failure:
- [email protected]
tasks:
- task_key: bronze
notebook_task:
notebook_path: ./notebooks/01_bronze.py
- task_key: silver
depends_on:
- task_key: bronze
max_retries: 2
notebook_task:
notebook_path: ./notebooks/02_silver.py
- task_key: gold
depends_on:
- task_key: silver
notebook_task:
notebook_path: ./notebooks/03_gold.py
targets:
dev:
mode: development # prefixes names, pauses schedules: safe to experiment
default: true
prod:
mode: productionNo compute is listed, so the tasks run on serverless compute (where enabled). For classic compute you'd add a job_clusters section and a job_cluster_key per task.
# check the bundle for mistakes$databricks bundle validate# deploy to your dev workspace (the default target)$databricks bundle deploy -t dev# run the job now$databricks bundle run shopkart_daily -t dev# CI/CD deploys to production after tests pass$databricks bundle deploy -t prod
Task types and triggers
| Task type | Runs |
|---|---|
| Notebook | A notebook (most common) |
| Python script / wheel | Packaged Python code |
| SQL | A query, file or alert on a SQL warehouse |
| Pipeline | A Lakeflow Declarative Pipeline (lesson 9) |
| dbt | A dbt project |
| If/else condition | Branch on a value |
| For each | Run a task once per item in a list (e.g. per country) |
| Run job | Trigger another job |
| Trigger | Starts the job when... |
|---|---|
| Scheduled | A cron time is reached |
| File arrival | New files land in a volume or external location |
| Table update | Source tables are updated |
| Continuous | Always running; restarts immediately |
| Manual / API | Someone clicks Run or calls the REST API |
Making jobs reliable
- Retries for temporary failures, which only works if tasks are idempotent (lesson 6).
- Timeouts so a stuck task doesn't burn money all night.
- Alerts on failure (email, Slack, PagerDuty), and on duration over a threshold.
- Repair run: after a failure, re-run only the failed task and those after it.
- Run as a service principal in prod, not your personal account.
- Job compute or serverless, never an all-purpose cluster.
CI/CD in one picture
πΏFeature branch
Develop in a Git folder, deploy bundle to dev
πPull request
Code review + unit tests + bundle validate
π§ͺStaging
CI deploys, runs integration tests
πProduction
CI deploys with a service principal
Unit tests: put transformations in plain Python functions (input DataFrame β output DataFrame) and test them with pytest and a small SparkSession, just like we tested this course's code.
π― Interview questions on this topic
Try to answer out loud first, then tap to check.
Q1How do you schedule a notebook in Databricks?Fresher+
Q2How do you pass parameters between tasks?1β3 yrs+
Q3A daily job failed at the gold step. What do you do?1β3 yrs+
Q4How do you implement CI/CD for Databricks?1β3 yrs+
Q5Databricks Jobs vs Airflow?3+ yrs+
Q6How do you backfill a month of data?3+ yrs+
Key takeaways
- βJobs turn notebooks into an automated, monitored pipeline.
- βParameters and idempotent tasks make retries, repairs and backfills safe.
- βDeclarative Automation Bundles bring jobs into Git and CI/CD.
- βProduction: serverless or job compute, service principals, alerts and timeouts.
Frequently asked questions
What is a Databricks job?
A job runs one or more tasks (notebooks, Python scripts, SQL, pipelines, dbt and more) on a schedule or trigger, with dependencies between tasks, parameters, retries, alerts and run history. Databricks now calls jobs Lakeflow Jobs; you may also see the older name Workflows.
How do I pass a date into a notebook?
Define a job parameter (for example run_date) and read it in the notebook with dbutils.widgets.get("run_date"). Dynamic values like {{job.start_time.iso_date}} fill it automatically on each run.
What are Declarative Automation Bundles (Databricks Asset Bundles)?
Declarative Automation Bundles, called Databricks Asset Bundles until March 2026, are a way to define jobs, pipelines and their code as files in Git (a databricks.yml), then validate and deploy them to dev, staging and prod with the Databricks CLI. It's Databricks' standard approach to CI/CD.
Can Databricks jobs replace Airflow?
For pipelines that live inside Databricks, often yes: jobs support dependencies, conditions, loops, file-arrival and table-update triggers. Teams with many non-Databricks systems still use Airflow, which can trigger Databricks jobs.
How do I keep passwords out of notebooks?
Store them in a secret scope and read them with dbutils.secrets.get(scope, key). Values are redacted if printed. Never hard-code credentials or commit them to Git.
π§ Quick check: jobs and workflows
1. Silver must run only after bronze succeeds. You use...
2. Which compute should a scheduled job use?
3. Where do job settings live in a CI/CD setup?
4. A task fails because the network blipped. What helps most?
Checking your accessβ¦