Sub topic 3
Using Spot Instances Safely
Assume you know Spark jobs, partitions, Databricks clusters, and cloud on-demand versus spot pricing. This chapter focuses on cost controls and sizing decisions after you understand basic cluster architecture.
Using spot instances safely
Spot instances cost less because the cloud provider can reclaim them. Use them for workers when Spark can retry interrupted tasks. Keep the driver on demand because losing it can interrupt the whole cluster. Configure fallback capacity:
{
"cluster_name": "etl-spot",
"spark_version": "15.4.x-scala2.12",
"node_type_id": "i3.xlarge",
"autoscale": {
"min_workers": 2,
"max_workers": 8
},
"aws_attributes": {
"first_on_demand": 1,
"availability": "SPOT_WITH_FALLBACK"
},
"autotermination_minutes": 30
}Spot capacity can disappear during a run. Avoid it for workloads with strict completion deadlines unless the fallback and retry behavior meet your service target.
Instance pools to shorten startup
An instance pool keeps ready-to-use cloud instances available. A new cluster can start from the pool instead of waiting for instance allocation. Pools help interactive users and jobs that start often. They also keep idle capacity, so set a suitable minimum idle size.
Enforcing limits with cluster policies
A cluster policy restricts configuration values. Use it to cap worker counts, require approved node types, and bound idle time. For example, allow at most eight workers and require auto-termination between 10 and 120 minutes. Policies prevent accidental oversized clusters while leaving teams some choice.
Photon and the runtime engine setting
Photon is Databricks’ native vectorized execution engine. It often improves SQL and DataFrame workloads that scan, filter, join, or aggregate data. Test it with representative jobs. Unsupported or poorly matched operations may see little improvement, so compare runtime and cost rather than assuming a faster engine is always cheaper.
Reading utilization in the Spark UI and metrics
Use the Spark UI to inspect task duration, shuffle volume, spill, and input size. Cluster metrics show CPU, memory, disk, and network pressure.
Tuning with a measure-and-adjust loop
Record runtime, cost, peak workers, executor utilization, and failures. Change one variable, such as worker bounds or node family. Run a representative workload again. Keep the change only when it improves the target metric without creating failures or unacceptable cost.
Serverless compute
Serverless compute lets Databricks manage infrastructure and much of the sizing. It suits variable SQL and BI workloads where fast startup and low administration matter. Use manually configured clusters when you need specialized GPUs, custom libraries, predictable infrastructure, or direct spot-instance controls.
Exercise
Why keep the driver on an on-demand instance when workers use spot instances?
Show answer
Losing the driver can stop the entire cluster, while Spark can usually retry tasks lost when a worker is reclaimed.