Sub topic 18
A team workflow that works
This chapter pulls the earlier pieces into one repeatable workflow. It assumes you can already work with notebooks, widgets, Git folders, branches, and basic Git commands, and that you have a Git account with a provider Databricks supports.
The goal
A good team workflow keeps three things apart: where you experiment, where you review, and where production code runs. Git is the thread that connects them.
The recommended flow
- Each developer clones the shared repository into a personal Git folder.
- The developer creates a feature branch, such as
feature/clean-orders. - The developer edits notebooks and modules in the Git folder and tests them on development compute.
- The developer commits and pushes the branch, then opens a pull request in the Git provider.
- A teammate reviews the pull request. Merging into
mainis the approval step. - Automated deployment, for example with Databricks Asset Bundles, publishes the merged code as a job.
- The production job reads its code from a known Git reference, not from someone's personal folder.
Habits that prevent common problems
- Work on a branch, never directly on
main. Pushing tomainskips review. - Pull before you start work, and commit small changes often. Small commits make merge conflicts rare and easy to fix.
- Keep one person per branch where you can. Two people editing the same notebook on the same branch is the usual cause of conflicts.
- Put shared logic in Python modules and import it. Keep notebooks thin, so they mostly call functions and show results.
- Give every notebook that runs as a job its inputs through widgets, with safe defaults. Jobs then pass values such as
run_datewithout code changes. - Avoid hard-coded paths, secrets, and user names. Use widgets, job parameters, and a secret manager.
- Use
dbutils.notebook.runor job tasks for steps that should run separately, and%runonly for small shared setup. - Treat the personal Git folder as a workspace for development only. Do not point production jobs at it.
Choosing a job source
| Option | Code comes from | Good for |
|---|---|---|
| Workspace path | A folder in the workspace | Quick tests |
| Git source | A branch, tag, or commit in the remote | Production jobs |
A job that uses a Git source runs exactly what was reviewed. Pinning a tag or commit also makes a run reproducible, so you can tell later which code produced a result.
Putting it together
Suppose you fix a bug in the orders notebook. You pull main, create feature/fix-orders, change the notebook, and test it with a small run_date. You commit, push, and open a pull request. After review and merge, the deployment updates the job. The next scheduled run uses the merged code, with no manual copying.
Exercise
Why should a production job read its notebook from a Git source such as main or a tag, instead of from a developer's personal Git folder?
Show answer
A personal Git folder can hold uncommitted or unreviewed edits, and its owner can change it at any time. A Git source runs only code that was committed and reviewed, and a pinned tag or commit makes each run reproducible.
Exercise
Name two habits that reduce merge conflicts on a team.
Show answer
Work on separate feature branches (one person per branch), and pull often while committing small changes. Moving shared logic into modules also keeps notebooks small, so fewer people edit the same file.