Sub topic 11
Spot instances, instance selection, and pools
This chapter covers three ways to lower the cloud infrastructure part of a Databricks bill: spot instances, instance selection, and pools. It assumes you know how DBU charges and cloud charges combine, how job clusters differ from all-purpose clusters, and how to read cluster JSON. The examples use AWS. Azure and Google Cloud have equivalent settings under different names.
Why infrastructure cost is a separate lever
Databricks bills DBUs, and the cloud provider bills the virtual machines separately. Spot instances and instance choice change only the provider's charge. They do not change the DBU rate. Billing system tables show DBUs, so these savings appear in your cloud bill and not in system.billing.usage.
Spot instances
A spot instance is spare cloud capacity sold at a steep discount. The provider can reclaim it with short notice. When that happens, Spark loses the executors on that node and reschedules the work, which can slow a job but usually does not fail it.
On AWS you control this with aws_attributes:
{
"job_clusters": [
{
"job_cluster_key": "etl_cluster",
"new_cluster": {
"spark_version": "15.4.x-scala2.12",
"node_type_id": "i3.xlarge",
"autoscale": { "min_workers": 2, "max_workers": 6 },
"aws_attributes": { "availability": "SPOT_WITH_FALLBACK", "first_on_demand": 1 },
"custom_tags": { "team": "data-eng", "env": "prod" }
}
}
]
}SPOT_WITH_FALLBACKrequests spot nodes and falls back to on-demand nodes if spot capacity is unavailable.first_on_demand: 1makes the first node on-demand. That node is the driver, so a reclaimed spot node cannot take down the whole job.- The
custom_tagsstill apply, so attribution is unaffected.
Spot suits retry-tolerant batch work such as ETL and backfills. It is a poor fit for jobs with strict deadlines, long single-stage shuffles, or interactive sessions where a lost node is visible to a user.
Instance selection
The node type sets both the VM price and the capacity per node. Choose it by workload profile:
| Workload profile | Instance family | Reason |
|---|---|---|
| Heavy shuffles, caching, or joins | Memory optimized | Avoids spilling to disk |
| Scans and transformations of large files | Storage optimized (local NVMe) | Fast local cache and spill |
| Light transforms, CPU-bound code | General purpose or compute optimized | Cheapest per core |
| Model training with GPUs | GPU instances | Only when the code uses GPUs |
Check the Spark UI before changing types. If tasks spill to disk, move to more memory. If CPU is low and memory is idle, move to a smaller node. A larger node costs more per hour but may finish sooner, so compare cost per completed run, not cost per hour.
Newer instance generations often give better performance at a similar price. Test one before standardizing on it.
Pools
A pool is a set of idle, ready-to-use instances. Clusters that attach to a pool start faster because they skip VM provisioning.
Idle pool instances cost nothing in DBUs, but the cloud provider still charges for the VM while it sits idle. The relevant settings are:
min_idle_instanceskeeps a number of instances warm. Each one costs money continuously, so set it to 0 unless startup time matters.idle_instance_autotermination_minutesreleases idle instances after the delay.max_capacitycaps the total instances the pool can hold.
Pools help most when many short jobs start often, because provisioning time is a large share of each run. For a few long jobs, they add little. Nodes in a pool share the pool's instance type and availability setting, so create separate pools for spot and on-demand needs.
Common errors
- Running the driver on spot capacity, which makes jobs fail on a single reclaim.
- Setting a high
min_idle_instancesand forgetting it, which creates a constant cloud charge with no work behind it. - Choosing an instance type from price per hour alone.
- Expecting spot savings to show up in DBU reports.
Exercise
A nightly ETL job runs on a job cluster with all nodes on-demand and takes 40 minutes. It can be rerun safely if it fails. Which aws_attributes change reduces cost with the least risk, and why does the cost saving not appear in system.billing.usage?
Show answer
Set availability to SPOT_WITH_FALLBACK with first_on_demand set to 1. Workers use discounted spot capacity, the driver stays on-demand, and the job falls back to on-demand nodes if spot is unavailable. The saving is on the cloud provider's VM charge. system.billing.usage records only DBUs, which are unchanged, so the saving appears in the cloud bill.