Sub topic 1
What Asset Bundles are and why to use them
A Databricks Asset Bundle is a project that describes your Databricks work as files. The files hold your code (notebooks, Python files, SQL) and YAML configuration for the jobs, pipelines, and other resources that run that code. You keep all of it in Git, and the Databricks CLI deploys it to a workspace. This chapter covers the working model, how bundles compare with other approaches, and where they tend to go wrong.
Prerequisites
This chapter assumes you already have:
- Basic familiarity with the Databricks workspace, notebooks, and jobs.
- Working knowledge of YAML syntax, including indentation, lists, and mappings.
- Basic Git and command-line usage.
- A Databricks workspace where you can create jobs.
You don't need to install anything yet. The next chapter covers installing the CLI and authenticating.
The problem bundles solve
Most teams start by building jobs in the workspace UI. You create a job, pick a notebook, choose a cluster, and add a schedule. This works for one job in one workspace. It breaks down as the project grows:
- No history. Nobody can see who changed a job's cluster size, or when.
- No review. A change to a production job takes effect when someone clicks Save, not when a teammate approves a pull request.
- Manual copies. To get from dev to prod, you recreate the job by hand and hope you remember every setting.
- Drift. The dev job and the prod job slowly differ in ways nobody intended.
- No clean teardown. When a project ends, its jobs, folders, and pipelines remain scattered around the workspace.
This approach is called infrastructure as code. You write down the desired state of your resources in text files, and a tool makes the real environment match. Because the files are text, Git gives you history, review, and rollback for free. Bundles apply this approach to Databricks resources.
The working model
A bundle has three parts that work together.
- Source files. Notebooks, Python modules, SQL files, and tests, as in any code project.
- Configuration. A
databricks.ymlfile at the bundle root, plus optional files it includes. It declares the bundle's name, its resources (jobs, pipelines, and so on), and its targets. - The CLI. The
databricks bundlecommands read the configuration, check it, and apply it to a workspace.
A minimal bundle with one job looks like this:
bundle:
name: my_project
resources:
jobs:
hello_job:
name: hello_job
job_clusters:
- job_cluster_key: main
new_cluster:
spark_version: 15.4.x-scala2.12
node_type_id: <a-node-type-available-in-your-cloud>
num_workers: 1
tasks:
- task_key: hello
job_cluster_key: main
notebook_task:
notebook_path: ./src/hello.py
targets:
dev:
mode: development
default: true
workspace:
host: https://<your-dev-workspace-url>Each top-level key has a role:
| Key | Role |
|---|---|
| `bundle` | Names the bundle. The name is part of the deployment path and the deployment state. |
| `resources` | Declares the Databricks objects the bundle owns. Here, one job. |
| `targets` | Names the environments (dev, prod) and what differs between them. |
The notebook path is relative to the file that declares it. Running databricks bundle deploy uploads src/hello.py to the workspace and creates a job that points at the uploaded copy.
What a deploy does
A deploy is a comparison between what the configuration says and what the bundle has already created in that target. The CLI records what it deployed. On the next deploy it works out what to create, update, or delete.
The block above is only a placeholder fence marker. The real diagram follows.
Three consequences follow from this model:
- Deploys are repeatable. Running the same deploy twice leaves the workspace in the same state. The second run changes nothing.
- The files are the source of truth. If you edit a bundle-managed job in the UI, your next deploy overwrites that edit. Make changes in the YAML and deploy.
- Removal is part of the model. If you delete a job from the YAML and deploy, the CLI removes the deployed job. If you want everything gone,
databricks bundle destroyremoves the resources and files for that target.
One bundle, several environments
The targets section is what lets one set of files serve both dev and prod. A target can override the workspace host, variable values, and the identity the resources run as. Targets also have a mode:
developmentmode is for iteration. The CLI prefixes resource names with a marker that includes your username, so your copy of a job doesn't collide with a teammate's. It also pauses schedules and triggers, so a deploy doesn't start unattended runs.productionmode is stricter. It validates that the configuration is safe for a shared environment, for example by checking that the deployment doesn't live under a personal user folder and that a run identity is set where required.
Later chapters cover targets, variables, and run_as in detail. For now, remember that environment differences live in the targets section. They don't live in duplicated job definitions.
How bundles compare with other approaches
Bundles aren't the only way to manage Databricks resources. The right choice depends on what you deploy and who deploys it.
| Approach | Strengths | Weaknesses |
|---|---|---|
| Workspace UI | Fast to start, good for exploration | No history, review, or repeatability |
| REST API or SDK scripts | Full control, any language | You write the diffing, ordering, and cleanup logic yourself |
| Terraform with the Databricks provider | Manages workspaces, networking, and account-level objects as well as jobs | More general than a project deploy needs. Code and config deploy separately |
| Databricks Asset Bundles | Code and resource config deploy together. Built-in dev and prod targets. Templates and CI/CD support | Focused on project-level resources. Not meant for account or workspace provisioning |
| `dbx` (older tool) | Was an early project-deploy tool | Superseded by bundles. New projects should use bundles |
A common split is to use Terraform for platform setup (workspaces, networking, catalogs, service principals) and bundles for what teams build inside it (jobs, pipelines, and their code). The two don't conflict.
What bundles can manage
Bundles describe more than jobs. Depending on your CLI version, resources include:
- Jobs and their tasks, clusters, schedules, and parameters.
- Pipelines (declarative data pipelines, formerly Delta Live Tables).
- MLflow experiments and registered models.
- Model serving endpoints.
- Unity Catalog schemas and volumes.
- Dashboards.
The set grows with new CLI releases, so check the documentation for your version. Running databricks bundle validate with a resource type your CLI doesn't know produces a warning or error. If so, update the CLI first.
Common errors and gotchas
Editing deployed resources in the UI. The next deploy discards the change. If a hotfix in the UI is unavoidable, copy it back into the YAML afterwards.
Wrong notebook paths. Paths are relative to the YAML file that contains them. A job defined in resources/daily_etl.yml needs ../src/ingest.py, but the same job inside the root databricks.yml needs ./src/ingest.py. A wrong path usually shows up at deploy or run time, not at YAML parse time.
Cloud-specific values in shared config. A node_type_id that exists on one cloud doesn't exist on another. Put it behind a variable so each target can set its own.
Hard-coded hosts and identities. Putting a workspace URL or a personal username in a place every target shares sends dev deploys to prod, or the reverse. Keep these in targets.
Forgetting which target you deployed. If you omit -t, the CLI uses the target marked default: true. That is convenient in dev. In prod pipelines, always pass -t explicitly.
Treating development mode as production. Development mode pauses schedules by design. If a scheduled job isn't running after a dev deploy, this is the likely reason.
When bundles are a good fit
Use bundles when:
- Your project has code and resources that should version together.
- You need the same project in more than one environment.
- You want changes reviewed in pull requests and deployed by automation.
- More than one person works on the same jobs.
Think twice when you are only exploring data in a notebook, or when the thing you manage is workspace infrastructure rather than a project. In both cases a different tool fits better.
Where this leads
The rest of the tutorial builds the workflow step by step. You install the CLI and authenticate, write databricks.yml, define a job, add dev and prod targets, parameterize with variables, and run the validate, deploy, and run commands. After that come templates, includes, permissions, artifacts, cleanup, and CI/CD.
Exercise
A teammate fixes a failing bundle-managed job by changing its cluster size in the workspace UI. Two days later the job fails again with the original problem. What most likely happened, and what should the teammate have done?
Show answer
Someone ran databricks bundle deploy, and the deploy applied the cluster size from the YAML, overwriting the UI edit. The YAML is the source of truth for bundle-managed resources. The teammate should have changed the cluster size in the bundle's YAML, opened a pull request, and deployed from there.
Exercise
Your bundle has dev (mode: development) and prod targets. After deploying to dev, your scheduled job doesn't run at its scheduled time. Name the likely cause and one thing you can check in the workspace.
Show answer
Development mode pauses schedules and triggers on deployed jobs, so no unattended runs start. In the workspace, open the job and check that its schedule is shown as paused. Also look for the development-mode prefix on the job name, which includes your username.
Exercise
Give two reasons to use bundles instead of a script that calls the Jobs REST API, and one case where Terraform fits better.
Show answer
Bundles deploy code and resource configuration together, and they track what they deployed, so the CLI handles diffing, updates, and cleanup that a script must implement itself. They also provide built-in dev and prod targets. Terraform fits better for platform setup such as workspaces, networking, or account-level objects, which a project-level bundle isn't meant to manage.