Sub topic 18
A team workflow that works
This chapter assumes you know the earlier material: notebooks, widgets, %run and dbutils.notebook.run, Git folders, branches, commits, merge conflicts, and jobs that read from Git. It combines those pieces into one workflow a team can follow.
The goal of a workflow
A workflow answers four questions for every change:
- Where do I edit it?
- Who reviews it?
- How does it reach production?
- What does production run?
Without agreed answers, teams drift into familiar problems. People edit notebooks in a shared folder, nobody can tell which version a job ran, and fixes made in production never reach the repository.
The rule that fixes most of these problems is that the remote Git repository is the source of truth. The workspace is a place to develop and run code. It is not where the canonical copy lives.
The shape of the workflow
The workflow separates three places, each with a different purpose.
| Place | Purpose | Who edits it |
|---|---|---|
| Personal Git folder | Development on a feature branch | One person |
| Remote repository | Review, history, source of truth | Everyone, through pull requests |
| Production deployment | Scheduled jobs running reviewed code | Automation only |
Step 1: Develop in a personal Git folder
Each developer clones the repository into their own Git folder, normally under their user folder. Nobody edits the same Git folder at the same time. Two people editing one folder is the common cause of surprise overwrites and confusing merge conflicts.
Start every piece of work from an up-to-date main, then create a branch:
git checkout main
git pull
git checkout -b feature/clean-ordersIn the workspace you do the same thing from the Git dialog: pull, then create a branch. Name branches after the work, such as feature/clean-orders or fix/null-customer-id.
Keep branches short. A branch that lives for two weeks accumulates conflicts. A branch that lives for one or two days usually merges cleanly.
Step 2: Write notebooks that can be reviewed
A reviewer sees the notebook as a source file, as covered in the chapter on the notebook source format. This affects how you write:
- Keep cells small and focused. Each
# COMMAND ----------separator marks a boundary, and short cells give readable diffs. - Clear output before committing. Large outputs add noise. Many teams treat output in committed notebooks as a mistake unless the notebook is a report.
- Use widgets for anything that changes between runs. Dates, environments, and table names belong in parameters, not in edited code.
- Move logic into modules. Notebooks should orchestrate. Functions that need testing belong in
.pyfiles.
A well-structured notebook looks like this:
# Databricks notebook source
dbutils.widgets.text("run_date", "2026-01-01", "Run date")
run_date = dbutils.widgets.get("run_date")
# COMMAND ----------
from orders.cleaning import drop_invalid_orders
raw = spark.read.table("raw.orders").where(f"order_date = '{run_date}'")
clean = drop_invalid_orders(raw)
clean.write.mode("overwrite").saveAsTable("silver.orders")The cleaning function lives in orders/cleaning.py in the same repository. It can be tested on its own, and a reviewer can read its diff without scrolling through notebook cells.
Step 3: Commit, push, and open a pull request
Commit often on your branch, with messages that describe the change. Push at the end of each work session so the work is backed up and visible.
git add -A
git commit -m "Drop orders with null customer id"
git push -u origin feature/clean-ordersThen open a pull request in your Git provider, not in Databricks. Databricks handles the editing and the Git operations. Review happens in the provider, where comments, approvals, and branch protection rules live.
Set up branch protection on main:
- Require at least one approving review.
- Require automated checks to pass before merging.
- Block direct pushes to
main.
This is the control that keeps production code reviewed.
Step 4: Automate checks
A pull request is more useful when a machine has already examined it. Typical checks, run by your provider's CI system, include:
- Unit tests for the Python modules.
- A linter or formatter check.
- A bundle validation, if you use Databricks Asset Bundles.
databricks bundle validate -t devValidation catches malformed configuration before a human spends time reviewing it. Keep the checks quick, because slow checks tempt people to skip them.
Step 5: Deploy from main, not from a person
Production should run code that was merged to main. There are two common approaches, and the right choice depends on how much your team wants to automate.
| Approach | How it works | Strengths | Weaknesses |
|---|---|---|---|
| Job with a Git source | The job's notebook task points at the repository and a branch, tag, or commit. The run fetches that version. | Simple. No deploy step. | The job definition lives separately from the code. Pointing at a branch means the code changes when the branch moves. |
| Databricks Asset Bundles | Jobs and other resources are defined in YAML in the repository, and a pipeline deploys them. | Job definitions are reviewed with the code. Dev and prod targets are consistent. | More setup. Requires CI and a service principal. |
If you use a job with a Git source, prefer a tag or commit for production when you need an exact, reproducible version. A branch reference is convenient but changes whenever someone merges.
If you use bundles, the deploy pipeline typically runs these commands on merge to main:
databricks bundle validate -t prod
databricks bundle deploy -t prodRun production jobs as a service principal, not as a person. Jobs owned by a person break when that person leaves or loses access. A service principal is an identity for automation, and it needs its own Git credential if the job reads from Git.
Step 6: Never edit production directly
A production Git folder, if you have one, should be read-only in practice. Give most people only view or run permission, and let automation do the updates. If someone fixes a bug directly in production, the fix is lost the next time the folder is updated from Git, or it creates a conflict.
Urgent fixes follow the same path, only faster: branch from main, make the fix, get a quick review, merge, deploy.
Common failure modes
- Uncommitted work in a shared folder. A pull then fails or conflicts. Fix: keep personal folders personal and commit before pulling.
- Stale branches. Merge or pull
maininto your branch regularly. - Credentials tied to one person. Jobs fail when a personal access token expires. Fix: use service principals and rotate tokens on a schedule.
- Secrets in notebooks. Anything committed stays in Git history. Use Databricks secrets and read them with
dbutils.secrets.get. - Hardcoded paths and table names. Code that only works in one environment cannot be promoted. Pass environment through widgets or bundle variables.
Putting it together
A team using this workflow follows one loop. Pull main, branch, develop in a personal Git folder, commit and push, open a pull request, pass review and checks, merge, and let automation deploy. Every production run can then be traced to a merged commit that someone reviewed.
Exercise
A teammate edits a notebook directly in the production Git folder to fix a bug. The next scheduled update from main overwrites the fix. Which two parts of the workflow were skipped, and what should the teammate have done?
Show answer
The change skipped the feature branch and the pull request review, so it never reached the remote repository, which is the source of truth. The teammate should have branched from main in a personal Git folder, committed and pushed the fix, opened a pull request, and let it merge and deploy through automation.
Exercise
Your production job uses a Git source that points at the main branch. A merge at 09:00 changes the code, and the 09:05 run behaves differently from yesterday's. What option would give you an exact, reproducible version, and what is its cost?
Show answer
Point the job at a tag or a specific commit instead of the branch. The cost is that you must update the reference to release each new version, which is why many teams automate that step with Databricks Asset Bundles.