Sub topic 3
Choosing Node Types and Instance Families
This chapter assumes you know the driver and worker roles in a Databricks cluster, basic Spark concepts (jobs, stages, tasks, partitions, shuffles), and the difference between on-demand and spot virtual machines. Examples use AWS instance names. Azure and Google Cloud offer equivalent families under different names.
Why the node type matters
Every cluster is built from virtual machines. The node type is the machine shape you pick for them. It fixes the ratio of CPU cores, memory, local storage, and network bandwidth that each node provides. Adding workers multiplies that ratio. It does not change it.
If a job runs out of memory on a node type with 8 GB of RAM per core, adding more nodes of the same type will not help each task. Each task still gets the same slice of memory. The node type is therefore the first sizing decision, and the worker count comes after it.
In the cluster specification, the node type is the node_type_id field. By default, workers and the driver use the same type. You can set driver_node_type_id to give the driver a different one.
The main instance families
Cloud providers group instance types into families. Each family favors one resource. The table shows the AWS families you meet most often on Databricks.
| Family type | AWS examples | What it favors | Typical Databricks use |
|---|---|---|---|
| General purpose | m5, m6i | Balanced CPU and memory | Mixed workloads, a safe default |
| Compute optimized | c5, c6i | More cores per GB of memory | CPU-heavy transformations, light shuffles |
| Memory optimized | r5, r6i | More memory per core | Wide joins, aggregations, caching, large ML feature sets |
| Storage optimized | i3, i4i | Fast local NVMe SSDs | Shuffle-heavy ETL, Delta cache, spill-heavy jobs |
| GPU accelerated | g4dn, g5, p3 | GPUs with CPU and memory | Deep learning training and inference |
Instance names encode the family, generation, and size. In i3.xlarge, i3 is the family and generation, and xlarge is the size within that family. Larger sizes in the same family keep roughly the same ratio of cores to memory. They scale everything up together.
Matching a family to the bottleneck
Pick the family by finding what limits your job. The Spark UI and cluster metrics show this (see the monitoring chapter). These are the common patterns.
- Memory-bound. Tasks spill to disk, executors are lost to out-of-memory errors, or garbage collection time is a large share of task time. Choose a memory-optimized family such as
r5orr6i. - Compute-bound. CPU utilization stays near 100% across workers, and tasks have little spill. This is common for complex expressions, UDFs, and compression. Choose a compute-optimized family such as
c5. - Storage-bound. The job shuffles heavily or rereads the same files. Local disk speed becomes the limit. Choose a storage-optimized family such as
i3. These instances also support the disk cache, which keeps remote data on local SSDs for repeated reads. - GPU workloads. Deep learning needs GPUs. Pick a GPU family and a Databricks Runtime for Machine Learning with GPU support. GPU nodes cost much more per hour, so use them only when the library actually uses the GPU.
If you cannot tell which resource is the limit, start with general purpose or storage optimized and measure. A wrong guess is cheap to fix, and a measured choice is better than a guess.
Driver and worker node choices
The driver and workers do different work, so they can need different shapes.
- The driver coordinates the job and holds results from
collect(),toPandas(), and broadcast variables. A job that pulls large results to the driver needs a driver with more memory than its workers. - Workers run the tasks. Choose their type by the bottleneck above.
- A job that only writes data from workers to storage rarely needs a large driver.
The driver is a single point of failure for the cluster. If it is lost, the running job fails. This matters for the spot instance decision covered in a later chapter.
Many small nodes or a few large ones
For the same total cores and memory, you can use many small nodes or a few large ones. Neither wins in every case.
| Choice | Advantages | Drawbacks |
|---|---|---|
| Fewer, larger nodes | Less network traffic during shuffles, because more data stays on one machine. Fewer machines to start and manage. | A single node loss removes a large share of capacity. Scaling steps are coarse. |
| More, smaller nodes | Finer scaling. A lost node costs less work. | More shuffle data crosses the network. More per-node overhead. |
Shuffle-heavy jobs usually favor fewer, larger nodes. Jobs that scale up and down often, or that run on spot capacity, favor smaller nodes because the loss of one node does less damage.
Photon and node type
Photon is the Databricks native vectorized query engine. It runs on a limited set of instance families, and it changes the DBU price per node. Check that your chosen instance type is supported before you enable it. The engine setting is covered in its own chapter.
Checking what you chose
After you create a cluster, you can confirm what Spark received. This notebook cell prints the node count and the cores the executors offer. It uses only the Spark status tracker, so it runs in any notebook.
sc = spark.sparkContext
executors = sc._jsc.sc().statusTracker().getExecutorInfos()
# The list includes the driver, so subtract one for the worker count.
executor_count = len(executors) - 1
print(f"Workers (executors, excluding driver): {executor_count}")
print(f"Default parallelism (approx. total cores): {sc.defaultParallelism}")
if executor_count > 0:
print(f"Approx. cores per worker: {sc.defaultParallelism / executor_count:.1f}")The cores per worker value should match the vCPU count of your chosen node type. If it does not, the cluster may be using a different type than you expected, or several executors may share a node.
A cluster specification with separate driver and worker types
This specification uses a memory-optimized driver and storage-optimized workers. Use it when a job collects sizeable results but does shuffle-heavy work on the workers.
{
"cluster_name": "etl-mixed-nodes",
"spark_version": "15.4.x-scala2.12",
"node_type_id": "i3.xlarge",
"driver_node_type_id": "r5.2xlarge",
"num_workers": 4,
"autotermination_minutes": 30
}Common mistakes
- Scaling out to fix a memory problem. More workers of the same type do not give each task more memory. Change the family or size instead, or reduce the data per partition.
- Choosing by price alone. A cheaper node that spills to disk can make the job slower and the total bill higher.
- Using GPU nodes for CPU work. Unless the library uses the GPU, the extra cost buys nothing.
- Oversizing the driver by default. A large driver costs the same DBUs as a worker of that size for the whole run. Raise it only when results or broadcasts need it.
- Ignoring Photon support. An unsupported instance type means the cluster cannot use the engine you planned for.
Exercise
A job joins two large tables. The Spark UI shows many tasks spilling to disk, and CPU utilization on the workers is around 40%. A teammate suggests doubling the number of workers of the current general purpose type. What do you recommend instead, and why?
Show answer
Move to a memory-optimized family such as r5 or r6i. The spill shows the job is memory-bound, and the low CPU use shows cores are not the limit. Doubling the same node type keeps the same memory per core, so each task would still spill. A memory-optimized type gives each task more memory, which removes the spill without paying for idle cores.
Exercise
A job calls toPandas() on a large result and fails with an out-of-memory error on the driver. The workers show no memory pressure. Which setting do you change?
Show answer
Set drivernodetypeid to a larger or memory-optimized type, such as r5.2xlarge, and leave the worker nodetype_id as it is. The failure is on the driver, so changing the worker type or count does not help. You could also avoid collecting the full result to the driver.