Sub topic 13
Choosing the right compute for a workload
This chapter turns the earlier material on all-purpose clusters, job clusters, serverless compute, autoscaling and cost into a decision process. It assumes you know the driver and worker structure of a cluster, the idea of access modes, and that Databricks charges for DBUs (Databricks Units, a unit of processing capability billed per hour) on top of cloud infrastructure on classic compute. It also assumes you can read the JSON examples from the Jobs and Clusters APIs.
Start from the workload, not the product
Picking compute by habit ("we always use the big shared cluster") is the most common source of wasted spend and slow work. Four questions settle most decisions:
- Who is driving it? A person typing and rerunning cells, or a scheduler running unattended.
- How often does it run, and for how long? Constant use all day, short bursts, or one long run each night.
- What does it need that is non-standard? Custom libraries on the cluster, init scripts, a specific instance type, GPUs, or specific Spark configuration.
- What must be governed? Which Unity Catalog permissions apply, and whether several users share the compute.
Your answers map to a lifecycle (when the compute exists), a sharing model (who uses it), and a cost profile (what you pay while it exists).
The three options side by side
| Property | All-purpose cluster | Job cluster | Serverless compute |
|---|---|---|---|
| Lifecycle | Created by a user, stays up until terminated | Created when a run starts, deleted when it ends | Managed by Databricks, attached on demand |
| Sharing | Can be shared by several users and notebooks | Used by the tasks of one job run | Isolated per workload, no cluster to share |
| Start time | Minutes if cold | Minutes per run, reduced by pools | Typically seconds |
| You choose | Runtime, node type, size, policies | Runtime, node type, size, policies | Little or nothing, such as the environment version |
| Billing | DBUs plus cloud VMs, including idle time | DBUs plus cloud VMs, at a lower DBU rate than all-purpose | One DBU-based charge that includes infrastructure |
| Best for | Interactive development and exploration | Scheduled production pipelines | Ad hoc work and jobs with variable or spiky demand |
Two details in the table affect real decisions. First, an all-purpose cluster costs more per DBU than job compute, so running production pipelines on it costs more even if the hardware is identical. Second, serverless has no idle VM cost to you, but its per-DBU rate is higher because it covers the infrastructure Databricks runs for you. Check current rates for your cloud and region instead of relying on remembered numbers.
Decision flow
The following diagram encodes the framework the rest of the chapter explains.
Development: interactive work
During development, a person edits a cell, runs it, reads the result and thinks. Compute sits idle between runs, so two things matter most: fast start and low idle cost.
- Serverless notebook compute fits when you want to open a notebook and run immediately, and your code stays within serverless limits. There is nothing to terminate, and you pay while code runs.
- An all-purpose cluster fits when you need libraries installed at cluster level, init scripts, a particular runtime version, GPUs, or Spark settings serverless does not allow. It also fits a team working together for most of the day, since one warm cluster serves everyone.
If you use an all-purpose cluster, set autoscaling and a short auto termination period so it does not run overnight. The request body below uses a 60-minute idle shutdown and standard access mode.
{
"cluster_name": "team-interactive",
"spark_version": "15.4.x-scala2.12",
"node_type_id": "i3.xlarge",
"autoscale": {
"min_workers": 1,
"max_workers": 4
},
"autotermination_minutes": 60,
"data_security_mode": "USER_ISOLATION"
}Sixty minutes is a starting point. A cluster used in short bursts across a day may do better at 20 to 30 minutes, because every idle minute is paid VM time plus DBUs.
Access mode in the interactive case
The access mode decides who can use the cluster and how Unity Catalog permissions apply.
- Standard (
USER_ISOLATION): several users share the cluster, and Unity Catalog permissions are enforced per user. This is the usual choice for a team cluster. - Dedicated (
SINGLE_USER): assigned to one user or group. Choose it when the work needs capabilities that standard mode restricts.
Pick the most restrictive mode that still runs your code. Do not use dedicated mode only because it feels simpler. It moves you toward one cluster per person, which multiplies idle cost.
Production: scheduled and automated work
A nightly pipeline has no person waiting on it, runs on a schedule, and needs repeatable behavior. This is where job compute earns its place.
Job cluster
A job cluster exists only for the run. It starts, runs the tasks, and terminates, so there is no idle time to manage. Each run starts from the same definition, which gives you isolation between runs and a clean place to pin the runtime version. The definition below creates one cluster and attaches a task to it.
{
"name": "nightly-etl",
"job_clusters": [
{
"job_cluster_key": "etl_cluster",
"new_cluster": {
"spark_version": "15.4.x-scala2.12",
"node_type_id": "i3.xlarge",
"num_workers": 2,
"data_security_mode": "USER_ISOLATION"
}
}
],
"tasks": [
{
"task_key": "ingest",
"job_cluster_key": "etl_cluster",
"notebook_task": {
"notebook_path": "/Workspace/Users/[email protected]/ingest"
}
}
]
}Several tasks can share one job_cluster_key, so a multi-task job pays the startup cost once. Choose a job cluster when you need specific node types, init scripts, library control, or tuned Spark settings.
Serverless jobs
If the workspace has serverless compute for jobs enabled, a notebook task that names no cluster runs on serverless compute.
{
"name": "nightly-etl-serverless",
"tasks": [
{
"task_key": "ingest",
"notebook_task": {
"notebook_path": "/Workspace/Users/[email protected]/ingest"
}
}
]
}There is no node type, runtime version or worker count to choose. This suits jobs that run briefly or irregularly, where a classic cluster would spend much of its billed time starting up. It also suits teams that want to stop maintaining cluster definitions.
Weighing the cost
Cost depends on how much of the billed time does useful work. A rough comparison for a single job run:
- Classic job cluster: startup time (minutes) + run time, billed as VMs plus DBUs.
- Serverless: seconds of startup + run time, billed as DBUs only, at a higher rate.
For short jobs, startup is a large share of a classic run, so serverless often wins. For long, steady jobs, a tuned classic job cluster with well-chosen instances can cost less per run, because the infrastructure you pay for directly is cheaper than the serverless rate that bundles it. Measure rather than guess. Run the same job both ways for a week and compare billed usage.
Encoding the framework
The following Python function captures the decision flow as a testable rule set. It is a teaching aid, not an official Databricks tool, and a team can adapt the rules to its own policies.
def choose_compute(
interactive: bool,
needs_custom_config: bool,
steady_use_hours: float = 0.0,
) -> str:
"""Return a compute recommendation for a workload."""
if interactive:
if needs_custom_config or steady_use_hours >= 4:
return "all-purpose cluster"
return "serverless notebook compute"
if needs_custom_config:
return "job cluster"
return "serverless jobs compute"
cases = [
(True, False, 1.0),
(True, True, 0.0),
(True, False, 6.0),
(False, False, 0.0),
(False, True, 0.0),
]
for interactive, custom, hours in cases:
print(interactive, custom, hours, "->", choose_compute(interactive, custom, hours))The four-hour threshold is arbitrary. Replace it with a number from your own cost comparison.
Edge cases and common mistakes
- Running production jobs on an all-purpose cluster. It works, but you pay the higher DBU rate, and unrelated interactive work can compete for the same resources. Move scheduled jobs to job compute.
- Leaving auto termination off. The cluster bills VM and DBU charges until someone stops it. Cluster policies can enforce a maximum idle time.
- Assuming serverless runs everything. Serverless limits what you can configure. Init scripts, arbitrary instance types and some Spark settings are not available, and language and library support has limits that change over time. Check the current serverless documentation before migrating a workload.
- One cluster per person. Dedicated clusters for each analyst multiply idle cost. A shared standard-mode cluster with autoscaling usually costs less.
- Treating autoscaling as a guarantee of savings. Autoscaling reduces workers when load drops, but the driver keeps running, and a minimum of one worker is still billed.
- Ignoring startup time for chained jobs. Many tiny jobs, each with its own job cluster, spend most of their time starting. Combine them as tasks in one job on a shared job cluster, or use serverless.
Putting it together
A realistic team uses all three. Analysts explore data on serverless notebook compute, or on a shared standard-mode all-purpose cluster when they need custom libraries. Data engineers develop pipelines on an all-purpose cluster, then deploy them as jobs. Stable, tuned, long-running pipelines go to job clusters. Short or irregular jobs go to serverless. Reviewing billed usage every month shows which workloads to move.
Exercise
A nightly job runs for 6 minutes. Its classic job cluster takes about 5 minutes to start and needs no init scripts or special instance types. Which compute would you try first, and what would you compare before committing?
Show answer
Try serverless jobs compute first, because startup is nearly half of each billed classic run and the workload needs no custom configuration. Run the job both ways for a week and compare billed usage (DBUs plus cloud infrastructure for classic, DBUs for serverless), run time, and output. Keep the job cluster if the classic cost per run is lower and the extra startup time is acceptable.
Exercise
A team of eight analysts uses a cluster for about two hours each, spread across the working day. Each analyst currently has a dedicated all-purpose cluster with auto termination off. Name two changes that would reduce cost, and the access mode you would use.
Show answer
Replace the eight clusters with one shared all-purpose cluster in standard access mode (USER_ISOLATION) with autoscaling, or move the analysts to serverless notebook compute if their work fits serverless limits. Turn on auto termination with a short idle period, such as 20 to 30 minutes, so the compute stops between bursts of use.