Sub topic 1
The compute landscape in Databricks
Prerequisites
This chapter assumes you have the following background:
- You can open a Databricks workspace, create a notebook, and run a cell.
- You know the basic Spark vocabulary: a driver coordinates work, executors run tasks, and a job is split into stages and tasks.
- You understand virtual machines and pay-as-you-go cloud billing.
- You can read a short JSON document.
You do not need to have created a cluster before. This chapter is the map for the rest of the tutorial. Later chapters cover each compute type, its settings, and its cost in detail.
What "compute" means in Databricks
In Databricks, compute is the set of machines that run your code. A notebook cell, a scheduled job, a SQL query, and a Delta Live Tables pipeline all need compute before they can do any work. Your data does not live on that compute. It lives in cloud object storage, such as S3, ADLS, or GCS. Compute reads from storage, processes the data, and writes results back.
This separation has two practical effects:
- You can shut compute down without losing data.
- You can run several pieces of compute against the same data at the same time.
Because compute is the part you pay for while it runs, most decisions in this tutorial come down to one question: which kind of compute should run this work, and for how long?
The three kinds of compute for notebooks and pipelines
This tutorial covers three kinds of compute. Each one answers the questions "who creates it", "who can share it", "when does it stop", and "who manages the machines" differently.
| Property | All-purpose cluster | Job cluster | Serverless compute |
|---|---|---|---|
| Typical use | Interactive development and exploration | Scheduled or triggered production runs | Notebooks and jobs where you do not want to manage clusters |
| Created by | A user, through the UI, CLI, or API | The Jobs service, when a run starts | Databricks, on demand |
| Lifecycle | Stays up until terminated manually or by the idle timeout | Created at run start, terminated at run end | Managed by Databricks, with no cluster for you to start or stop |
| Sharing | Many users and notebooks can attach | Used only by the tasks of that job run | Isolated per workload |
| You choose | Node type, runtime version, workers, access mode | The same settings, defined in the job | Little or none of those settings |
| Where machines run | Your cloud account | Your cloud account | Databricks-managed infrastructure |
The rest of this section describes each type in a little more detail.
All-purpose clusters
An all-purpose cluster is a long-lived cluster that people attach notebooks to. You create it, it starts, and it keeps running until you terminate it or its idle timeout fires. Several people can attach at once, so it suits shared development and exploration. It also costs money for as long as it is running, even when nobody is running a command. The idle timeout, called auto termination, is the main guard against that waste.
Job clusters
A job cluster exists only for one run of a job. The Jobs service creates it when the run starts and terminates it when the run finishes. Nobody attaches to it interactively, and no one has to remember to shut it down. Because each run begins with a fresh cluster, runs do not interfere with each other, and you pay only for the time the work needs plus the start-up time.
Serverless compute
With serverless compute, Databricks provides and manages the machines. You do not choose a node type, runtime version, or worker count. Compute is allocated when you run work and released afterwards. Start-up is typically much faster than for classic clusters, because Databricks keeps capacity ready. Serverless is available for notebooks, jobs, and SQL warehouses, subject to workspace and region support.
Classic compute is the collective name for all-purpose and job clusters, because their virtual machines run in your own cloud account. Serverless machines run in an account Databricks controls.
Other compute you will meet
Databricks has other compute types, which this tutorial mentions only to place them on the map:
- SQL warehouses run SQL queries and power dashboards and BI tools. They can be classic, pro, or serverless.
- Pipelines for Delta Live Tables and Lakeflow declarative pipelines run on their own managed compute.
- Model serving endpoints host machine learning models for real-time requests.
If your work is SQL analytics served to many concurrent users, a SQL warehouse is usually the better fit than a cluster. The remaining chapters focus on clusters and serverless compute for notebooks and jobs.
How the compute types relate
The diagram shows how the work you want to run maps onto the three compute types.
The arrows show typical choices, not rules. You can run a scheduled job on an all-purpose cluster, and you can develop interactively on serverless compute. Doing so is usually more expensive in the first case and less configurable in the second. A later chapter gives a full decision framework.
What a single compute resource is made of
Every classic cluster has the same basic shape. One driver node runs the Spark driver and coordinates the work. Zero or more worker nodes run executors that process data in parallel. A Databricks Runtime, which is a Databricks-built image of Spark plus libraries, runs on every node. You pick the node type, which is the VM size, and the runtime version when you create the cluster.
Serverless hides this structure. Spark still runs underneath, but you do not see or size the driver and workers.
The next chapters cover the driver, workers, and runtime in detail.
Two settings that shape every compute decision
Two settings change behavior and cost for every classic cluster. You will see them in many examples.
Access mode
Access mode controls who can use the cluster and which security model applies to the code on it. It determines whether the cluster can enforce Unity Catalog permissions, which is the governance layer for data in Databricks. The two modes you will meet most often are:
- Standard (API value
USER_ISOLATION): multiple users can share the cluster, and Unity Catalog permissions are enforced. - Dedicated (API value
SINGLE_USER): one user or group owns the cluster, and it supports workloads that need more language and library freedom.
Serverless compute is always governed by Unity Catalog, so you do not choose an access mode for it.
Lifetime control
A classic cluster bills while its virtual machines run. Two features control how much it runs:
- Autoscaling adds and removes workers between a minimum and a maximum as load changes.
- Auto termination shuts the cluster down after a set number of idle minutes.
A job cluster does not need auto termination, because it ends with the run.
A first look at the configuration
Here is the request body that creates an all-purpose cluster through the Clusters API (POST /api/2.1/clusters/create). The node type shown is an AWS example. Azure and GCP use different names.
{
"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"
}Read it field by field:
spark_versionselects the Databricks Runtime.node_type_idselects the VM size for the nodes.autoscalelets the cluster run between 1 and 4 workers.autotermination_minutesstops the cluster after 60 idle minutes.data_security_modeset toUSER_ISOLATIONis standard access mode.
Now compare it with a serverless job. This definition names no cluster at all:
{
"name": "nightly-etl-serverless",
"tasks": [
{
"task_key": "ingest",
"notebook_task": {
"notebook_path": "/Workspace/Users/[email protected]/ingest"
}
}
]
}In a workspace where serverless compute for jobs is enabled, a notebook task that names no cluster runs on serverless compute. There is no node type, runtime version, or worker count to choose. The difference in size between these two documents is a fair summary of the trade: classic compute gives you control and asks you to make decisions, while serverless makes the decisions for you.
How cost differs across the three types
Billing is covered in its own chapter, but you need the outline now. Databricks usage is measured in DBUs, or Databricks Units, which are a unit of processing capability per hour. The rate per DBU depends on the compute type and your plan.
- Classic compute (all-purpose and job): you pay DBUs to Databricks, and you separately pay your cloud provider for the VMs, disks, and network. Two bills combine into the total.
- Serverless compute: the DBU rate includes the infrastructure, so you receive one charge from Databricks for the compute.
All-purpose DBU rates are higher than job compute rates for comparable hardware. Running scheduled production work on an all-purpose cluster therefore costs more than the same work on a job cluster.
Common mistakes at this stage
- Leaving all-purpose clusters running. Without a sensible auto termination value, an idle cluster keeps billing. Set one when you create the cluster.
- Running production schedules on all-purpose clusters. This costs more per DBU and lets interactive activity interfere with the job.
- Assuming serverless is available everywhere. Serverless needs to be enabled in your account and supported in your region. Jobs fall back to classic compute settings when it is not.
- Expecting cluster-level control on serverless. You cannot pick node types or install arbitrary cluster-scoped settings. Check the serverless limitations before you migrate a workload that depends on them.
- Confusing compute with storage. Terminating a cluster does not delete your tables or files. Data written to the cluster's local disks does disappear.
What comes next
The following chapters take the pieces in order. First the structure of a cluster, then runtime and access modes, then each compute type in depth. After that come autoscaling, cost, policies, pools, and defining compute as code. The tutorial ends with a decision framework for choosing compute, and with monitoring and troubleshooting.
Exercise
A team runs a notebook every night at 02:00 on an all-purpose cluster that stays up all day. Name two ways their compute choice could be improved, and the main benefit of each.
Show answer
Option 1: move the notebook to a job cluster. The cluster exists only for the run, and job compute has a lower DBU rate than all-purpose compute, so the team pays less and avoids interference from interactive users. Option 2: run it as a serverless job. There is no cluster to configure, start, or stop, and start-up is fast. Either option also removes the cost of an idle cluster between runs. If the team keeps the all-purpose cluster for development, a shorter auto termination timeout reduces the idle spend.
Exercise
In the Clusters API body shown in this chapter, which field enforces Unity Catalog permissions on a shared cluster, and which field limits idle spend?
Show answer
data_security_mode set to USER_ISOLATION (standard access mode) enforces Unity Catalog permissions for multiple users on a shared cluster. autotermination_minutes, set to 60 in the example, shuts the cluster down after 60 idle minutes and so limits idle spend.
Exercise
A job definition contains a notebook task and no cluster settings. Under what condition does it run on serverless compute, and what settings do you no longer choose?
Show answer
It runs on serverless compute in a workspace where serverless compute for jobs is enabled. You no longer choose a node type, a runtime version, or a worker count.