Driver, Executors, Cores, and Memory
Databricks Spark Developer Associate · Lesson 2 of 18 · 9:01
YouTube loads only after you press play. This chapter opens at its timestamp in the full course. Watch on YouTube ↗
Learning with these videos? Subscribe for new courses and exam-style questions.
Subscribe on YouTube (opens in a new tab)In this lesson
Prepare for the Databricks Certified Associate Developer for Apache Spark exam. In this lesson: the driver, the cluster manager (Standalone, YARN, or Kubernetes) and the executors, cores and task slots, and unified memory with the driver and executor settings. Includes three original practice questions.
Study notes
The text of this lesson, to read at your own pace. Information as of November 2026.
Where does the code run?
Coralpeak's first Spark job reads a month of game events, and the team wonders where the code actually runs. Part of it runs on one machine, and the rest is spread over many others, and knowing which part runs where explains most errors and most tuning advice. This lesson covers the driver, the cluster manager, the executors, cores, and memory.
The driver
A Spark application has one driver program and a set of executors. The driver runs your main program, creates the SparkSession, turns your code into a plan, and splits the work into tasks that it schedules on the executors. It must stay reachable by the executors for the whole life of the application, so it should run close to them, on the same network. And the results that you bring back with an action, like collect, land in the memory of the driver.
Cluster manager and executors
The cluster manager allocates resources across applications: Spark can use its own standalone manager, Hadoop YARN, or Kubernetes, and Databricks manages this part for you. Worker nodes are the machines of the cluster that run application code. On the workers, each application gets its own executors: processes that run tasks, and keep data in memory or on disk, like cached partitions. Executors stay up for the whole application, and report back to the driver. And because each application has its own executors, two applications cannot share data, unless they write it to external storage.
Cores and tasks
Each executor has a number of cores, and each core runs one task at a time, so the cores are the slots for tasks. A task processes one partition, so a cluster with ten executors of eight cores each runs eighty tasks at once. When there are fewer partitions than cores, some cores sit idle, and the Spark tuning guide suggests two to three tasks per core. So more cores mean more tasks in parallel, as long as there are enough partitions to keep them busy.
Memory
Memory is set separately for the driver and for each executor, with the driver memory and executor memory settings. Inside an executor, Spark uses one unified region for two needs: execution memory, for shuffles, joins, sorts, and aggregations, and storage memory, for cached data. By default, this region takes sixty percent of the heap, after three hundred megabytes are set aside, and half of it is protected for cached data. Execution can evict cached blocks down to that protected part, while storage can never evict execution. And on the driver, a separate limit, the max result size, one gigabyte by default, stops an action from bringing back too much data.
Recap
Let's recap. The driver runs your program, plans the work, schedules tasks, and receives the results of actions. The cluster manager, standalone, YARN, or Kubernetes, allocates resources on the worker nodes. Executors run tasks and keep data for one application, for as long as it lives. Each core runs one task at a time, and each task processes one partition. And executor memory is one unified region for execution and storage, while the driver limits the size of results.
Quick checks for this lesson
The 3 questions of this lesson, as plain text. The button above runs them with shuffled choices and the reason behind every choice.
A notebook calls collect on a DataFrame of two billion events, and the job fails with out of memory. Where did the memory run out?
- In the cluster manager
- On every executor, which keeps a full copy
- On the driver, which receives every row
- On the worker that stores the most partitions
Show the answer
On the driver, which receives every row
Collect brings every row back to the driver, so the whole result must fit in the driver's memory. “In the cluster manager” is wrong, since the cluster manager only allocates resources, and never holds the data. “On every executor, which keeps a full copy” is wrong, since each executor holds only its own partitions, never a copy of the whole result. And “On the worker that stores the most partitions” is wrong, since collect moves the rows away from the workers, into the driver.
The cluster has four executors with eight cores each, and a stage has sixteen partitions. How many tasks run at the same time?
- Sixteen, and the other sixteen cores sit idle
- Thirty-two, one for every core
- Four, one for each executor
- Eight, all on the first executor
Show the answer
Sixteen, and the other sixteen cores sit idle
A task processes one partition, so sixteen partitions give sixteen tasks, and half of the thirty two cores have nothing to do. “Thirty-two, one for every core” is wrong, since there are only sixteen tasks to run, whatever the number of cores. “Four, one for each executor” is wrong, since an executor runs as many tasks at once as it has cores, not just one. And “Eight, all on the first executor” is wrong, since every executor takes tasks, not only the first one.
Coralpeak caches a large DataFrame, then a join needs more execution memory than is free. What does Spark do?
- It fails the join at once with an out of memory error
- It doubles the memory of the executor
- It moves the cached data to the driver
- It evicts cached blocks, down to the protected share
Show the answer
It evicts cached blocks, down to the protected share
Execution can take memory from storage by evicting cached blocks, until storage falls to its protected share. “It fails the join at once with an out of memory error” is wrong, since Spark first takes memory from the cache, and can also spill to disk, before it fails. “It doubles the memory of the executor” is wrong, since the memory of an executor is fixed when it starts. And “It moves the cached data to the driver” is wrong, since cached data never moves to the driver.