Sub topic 5
All-purpose clusters for interactive work
This chapter assumes you know the Databricks workspace and notebooks, and basic Spark terms such as driver and executor. It also assumes you understand pay-as-you-go cloud billing and can read JSON.
What an all-purpose cluster is
An all-purpose cluster is a classic compute resource that you create and keep running so people can attach notebooks to it. It is built for interactive work: exploring data, developing code, and running ad hoc queries. Several users can attach to the same cluster, and it stays up until someone terminates it or it shuts itself down.
Two traits define it:
- Lifecycle. It exists independently of any one notebook run. You start it, use it for hours, and it terminates after a period of inactivity.
- Sharing. Many notebooks and users can use one cluster at the same time, and they share its driver and workers.
Because the cluster stays up between commands, you pay for it while it sits idle. Most of the configuration decisions in this chapter exist to limit that idle spend.
Creating a cluster with the Clusters API
You can create an all-purpose cluster in the UI or by calling the Clusters API (POST /api/2.1/clusters/create). The request body below shows the settings that matter most.
{
"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"
}The node_type_id shown is an AWS example. Azure and GCP use different instance names.
| Field | What it controls |
|---|---|
| `spark_version` | The Databricks Runtime version installed on the nodes |
| `node_type_id` | The virtual machine type used for the driver and workers |
| `autoscale` | The minimum and maximum number of workers Databricks may run |
| `autotermination_minutes` | How long the cluster may be inactive before it shuts down |
| `data_security_mode` | The access mode. `USER_ISOLATION` is standard access mode |
Settings that matter for interactive use
Autoscaling
With autoscale, Databricks adds workers when a workload needs more capacity and removes them when it needs less. In the example, the cluster runs between 1 and 4 workers. This suits interactive work because load is uneven: a heavy query is followed by minutes of reading results. A fixed num_workers is the alternative when you want predictable capacity.
Auto termination
autotermination_minutes is the most important cost control on an all-purpose cluster. The cluster shuts down after that many minutes with no activity. A shorter value saves money but means more waiting for restarts. If you set it too long, or disable it, a forgotten cluster keeps billing.
Access mode
The data_security_mode field decides how users are isolated and whether Unity Catalog governance applies. Standard access mode (USER_ISOLATION) lets multiple users share the cluster while Unity Catalog permissions are enforced for each of them. Choose it for shared team clusters that read governed data.
The diagram is intentionally omitted here in favor of the lifecycle summary below.
Lifecycle of an all-purpose cluster
A terminated cluster keeps its configuration, so you can restart it later. Starting takes a few minutes while the cloud provider supplies virtual machines.
Common errors
- Leaving auto termination off. The cluster bills around the clock even when nobody uses it.
- Using one large cluster for everything. Heavy jobs slow interactive users, and you pay interactive prices for scheduled work. Scheduled work belongs on job compute, covered in the next chapter.
- Expecting a restart to preserve state. Terminating a cluster clears variables and cached data in running notebooks. Save results to tables or files.
- Picking an access mode that does not match your governance need. Check the mode before you share a cluster with people who have different data permissions.
Exercise
A team shares one all-purpose cluster during working hours, but the cloud bill shows it running all weekend. Which setting would have prevented this, and what trade-off comes with a shorter value?
Show answer
autotermination_minutes. A shorter value shuts the cluster down sooner after the last activity and so reduces idle cost. The trade-off is that users wait a few minutes for the cluster to restart when they return.