Sub topic 2
Job Clusters, Serverless Compute, and Cluster Scaling
Prerequisites: You should know basic Databricks notebooks, Spark drivers and executors, and JSON.
Job clusters for scheduled and automated work
A job cluster is temporary compute created for a job run. It starts when the run needs it and is terminated after the run finishes. This lifecycle prevents an unused cluster from running between scheduled executions.
A job can use one cluster for several tasks. The job_cluster_key connects each task to the declared cluster.
{
"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"
}
}
]
}Job clusters suit scheduled production work because each run gets a clean environment. All-purpose clusters suit interactive development because users start, share, and reuse them. Reusing an all-purpose cluster can be convenient, but forgetting to stop it can create idle costs.
Serverless compute for notebooks and jobs
Serverless compute is managed compute that Databricks starts and operates for you. You do not select virtual machine types, Spark worker counts, or cluster startup settings. Availability depends on your workspace, cloud, region, and enabled features.
For a serverless job, omit cluster settings from the task. When serverless jobs are enabled, Databricks supplies the compute:
{
"name": "nightly-etl-serverless",
"tasks": [
{
"task_key": "ingest",
"notebook_task": {
"notebook_path": "/Workspace/Users/[email protected]/ingest"
}
}
]
}Autoscaling and auto termination
Autoscaling changes the number of workers as demand changes. Set a minimum for baseline capacity and a maximum to limit resource use. Auto termination stops an idle all-purpose cluster after a configured number of minutes.
Autoscaling reduces idle workers, but it cannot remove the cost of a busy workload. Auto termination protects against forgotten interactive sessions. Choose limits from observed workload behavior, then monitor queue time, utilization, and failed runs.
Exercise
Which compute is the best default for a nightly notebook pipeline that needs a clean environment for every run?
Show answer
A job cluster. It is created for the run and terminated afterward. Use serverless instead when its supported features and governance requirements match the pipeline.