Sub topic 1
How a Databricks Cluster Is Built
Prerequisites
We assume you know Spark jobs, stages, tasks, partitions, and shuffles. You should also know how to run a Databricks notebook or job and understand cloud virtual machine pricing.
Driver, workers, and executors
A Databricks cluster has one driver node and one or more worker nodes. The driver runs your application, builds the execution plan, schedules tasks, and tracks progress. Each worker provides compute resources for running the work.
Spark executors run on the workers. An executor uses memory and CPU cores to process tasks. The number of available cores is therefore a rough measure of the cluster's task capacity. More workers usually provide more executors and more concurrent task slots, although the exact layout depends on the selected node type and runtime configuration.
Matching the cluster to the workload
Choose capacity based on the workload's limiting resource:
- ETL with large shuffles often needs balanced CPU, memory, and network bandwidth.
- Interactive SQL benefits from enough cores for concurrent queries and fast startup.
- Machine learning may need large memory, local storage, or GPUs.
- Streaming jobs need stable, continuously available capacity. Frequent worker changes can disrupt processing and make latency less predictable.
A small cluster can be cheaper but may queue tasks or spill data to disk. An oversized cluster can leave cores idle while still charging for them.
> The driver is part of the cluster's cost and can become a bottleneck. A larger worker fleet does not fix driver-heavy code, such as collecting a large result to the notebook.
Choosing node types and instance families
Cloud providers offer instance families with different resource ratios. Use memory-optimized nodes when data structures or joins need substantial RAM. Use compute-optimized nodes for CPU-heavy transformations. Use storage-optimized nodes when local disk and shuffle performance dominate. Use GPU nodes only when the libraries and workload can use GPUs.
| Workload constraint | Suitable starting family |
|---|---|
| Large in-memory joins | Memory optimized |
| CPU-heavy transformations | Compute optimized |
| Large shuffle or local-data workload | Storage optimized |
| GPU-supported training or inference | GPU |
Cores, memory, and partitions
A starting size should provide enough memory for the largest tasks and enough cores to process available partitions concurrently. Too few partitions leave cores idle. Too many tiny partitions add scheduling overhead.
total_cores = spark.sparkContext.defaultParallelism
shuffle_partitions = spark.conf.get("spark.sql.shuffle.partitions")
print(total_cores, shuffle_partitions)Use these values as signals, not guarantees. Check task duration, executor memory pressure, and spill metrics in the Spark UI.
What a cluster costs: DBUs and infrastructure
Databricks charges DBUs, or Databricks Units, for the platform workload. The cloud provider separately charges for the driver and worker virtual machines, attached storage, and sometimes network transfer. A cluster that runs twice as long can cost more even if its hourly rate is lower.
Exercise
Why can adding workers fail to improve a job?
Show answer
The job may have too few partitions, a driver bottleneck, insufficiently parallel stages, or a different limiting resource such as memory or network bandwidth.