Sub topic 13
Choosing the right compute for a workload
This chapter assumes you know the basics of the Databricks workspace and notebooks, Spark's driver and executor model, and pay-as-you-go cloud billing. It also assumes you have read the earlier chapters on all-purpose clusters, job clusters, serverless compute, and the DBU cost model. Here you combine them into a decision you can apply to a real workload.
The three questions that decide most cases
Most choices come down to three questions.
- Who or what starts the work? A person typing in a notebook is interactive. A schedule, trigger, or pipeline is automated.
- How long must the compute stay up? Interactive sessions have unpredictable idle gaps. Automated runs have a known start and end.
- How much control do you need? Classic compute lets you choose node types, runtime versions, libraries, and init scripts. Serverless removes those choices.
Comparing the options
| Factor | All-purpose cluster | Job cluster | Serverless compute |
|---|---|---|---|
| Lifecycle | Created manually, stays up until terminated | Created at run start, terminated at run end | Managed by Databricks, no cluster to start or stop |
| Sharing | Shared by several users (standard access mode) | Used by one job run | Not shared as a cluster you manage |
| Start time | Minutes if cold, none if already running | Minutes on every run (less with a pool) | Typically seconds |
| Configuration control | Full | Full | Limited |
| Cost profile | Pays while idle until auto termination | Pays only while the run executes | Billed on usage, with no separate cloud VM bill |
A decision flow
Applying the framework
Development and exploration
Use an all-purpose cluster when you need a specific runtime, custom libraries, or init scripts. Set autoscaling and a short auto termination period so an idle cluster stops billing. Use serverless notebook compute when your workspace supports it and you want to skip cluster setup.
Scheduled production
Use a job cluster or serverless for scheduled work. Do not run production schedules on an all-purpose cluster. It costs more per DBU than job compute, and other users' activity can compete with your run for resources.
For a job that needs no special configuration, the simplest definition names no cluster at all. In a workspace with serverless compute for jobs enabled, this runs on serverless:
{
"name": "nightly-etl-serverless",
"tasks": [
{
"task_key": "ingest",
"notebook_task": {
"notebook_path": "/Workspace/Users/[email protected]/ingest"
}
}
]
}If you need a particular node type, runtime, or library setup, declare a job cluster instead and attach tasks with job_cluster_key.
Ad hoc and bursty work
Occasional queries and short experiments suit serverless. You avoid paying for an idle cluster and avoid waiting for one to start.
Common mistakes
- Leaving auto termination off on an all-purpose cluster, so it bills overnight.
- Running scheduled jobs on all-purpose compute because that is where the notebook was developed.
- Assuming serverless is always cheaper. A steady, long-running job on well-sized classic compute can cost less than the same job on serverless. Compare actual DBU and infrastructure charges for your workload.
- Ignoring governance. Whatever you pick, confirm that its access mode supports your Unity Catalog requirements.
Exercise
A team runs a notebook every night at 02:00. It takes 20 minutes, needs no custom libraries, and runs in a workspace where serverless compute for jobs is enabled. Which compute do you choose, and why not the all-purpose cluster they use for development?
Show answer
Choose serverless job compute, defined by a task that names no cluster. The work is scheduled, short, and needs no special configuration, so there is no reason to keep or start a cluster. A job cluster is also reasonable if they want to control the runtime or node type. The all-purpose cluster is a poor choice because it either idles until auto termination after the run or sits up all night, and it carries a higher DBU rate than job compute.