What you will be able to do
- Name the role of the driver, the cluster manager, worker nodes and executors in a running Spark application
- Predict what happens to an application when its driver fails
- Work out how many tasks a cluster can run at once from its executor cores
- Explain why executor memory per core, rather than node count, decides whether a workload spills or runs out of memory
Key concept
Driver–executor division of labour — One driver process plans the application and hands out tasks. Executor processes on the worker nodes run those tasks and hold the data. Cores decide how many tasks run at once, and memory decides how much data those tasks can hold before spilling or failing.
1.The four parts of a Spark cluster
A Spark application is a set of processes on a cluster, and each process has one job. Your main program is the driver program. It creates the SparkContext, and the SparkContext coordinates everything else. The driver alone cannot run Spark work in parallel, so it needs help from two other parts.
The first is the cluster manager, an external service that hands out machines and resources. Spark can use its own Standalone manager, Hadoop YARN or Kubernetes. Spark does not care which one it gets, as long as it can acquire executor processes. The second is the set of worker nodes, which are the machines that can run application code. On each worker the application launches one or more executors. An executor is a process that runs tasks and keeps data in memory or on disk between them.
Startup follows a fixed order. The SparkContext connects to a cluster manager and Spark acquires executors on the cluster's nodes. Next it sends your application code, as JAR or Python files, to those executors. Finally the SparkContext sends tasks to the executors to run. How a job is split into those tasks is covered under the execution hierarchy.
| Component | Role |
|---|---|
| Driver program | Runs main(), creates the SparkContext and schedules the application's tasks |
| Cluster manager | External service that acquires resources on the cluster (Standalone, YARN, Kubernetes) |
| Worker node | Any node that can run application code in the cluster |
| Executor | Process on a worker node that runs tasks and keeps data in memory or disk storage |
| Task | A unit of work sent to one executor |
Executors belong to one application. Each application gets its own executor processes, and they stay up until that application ends. This keeps applications apart: each driver schedules only its own tasks, and tasks from different applications run in different JVMs. The cost is that two applications cannot share in-memory data unless one writes it to external storage first.
Databricks uses the same layout. A cluster there has one driver node and zero or more worker nodes, and each worker node runs exactly one executor. A cluster with zero workers can still run plain Python on the driver, but every Spark command fails because no executor exists to receive tasks. Where the driver process itself runs, inside or outside the cluster, is the subject of deploy modes.
Checkpoint 1 of 7· Match them up
Match each part of a Spark cluster to its role
Tap a term, then the definition that fits it.
The driver plans and schedules, and the cluster manager only allocates resources. Executors are processes that run tasks and hold data, and worker nodes are the machines that host them. A common exam trap is to mix up these roles, for example by saying the cluster manager schedules tasks.
“A process launched for an application on a worker node, that runs tasks and keeps data in memory or disk storage across them.”Source: spark.apache.org
2.What the driver does, and what happens when it fails
Every decision about the work is made by the driver. It interprets every command, plans each query and schedules tasks on the executors. Executors never decide what to run. They wait for tasks, run them and report back. For this reason the driver must accept connections from its executors for its whole lifetime, and it must be reachable over the network from the worker nodes.
When the driver dies, the application dies with it. The executors may still be healthy, but they have no scheduling role of their own. The cluster manager only hands out resources and does not plan stages. The executors were also launched for this application alone, so nothing else can take them over. Holding the SparkContext makes the driver a single point of coordination, and the healthy executors cannot keep the job going without it.
A busy driver causes a quieter failure. If the driver cannot hand out tasks fast enough, the executors sit idle while you keep paying for them. In the Spark UI this shows up as long gaps in the jobs timeline. The common causes are:
- too many streams, queries or threaded jobs running at the same time
- non-Spark code, such as a Python loop over native functions, which runs entirely on the driver
- many notebooks attached to the cluster, since the driver keeps state for each one
The fix depends on the cause. A larger driver helps when the driver is overloaded with coordination work. It does nothing for a Python loop, because that code never reaches the executors. In that case, rewrite the loop with Spark DataFrames or the pandas API on Spark so the work is spread across the executors.
Checkpoint 2 of 7· Check yourself
In the Spark UI, the jobs timeline shows long gaps and the executors sit idle. The notebook goes through its records in a Python for-loop that calls native Python functions. Which change will keep the executors busy?
Non-Spark code like a Python loop runs only on the driver and never reaches the executors. A bigger driver, more workers or more cores leave the executors just as idle. Rewriting the loop with Spark spreads the work across the executors.
“If the driver is busy running non-Spark code, a larger driver doesn't help the idle workers. Rewrite the code to use Spark”Source: docs.databricks.com
Checkpoint 3 of 7· Exam question
A cluster runs a single Spark application with one driver and three executors, each on a separate worker node. Partway through a long-running job, the driver process crashes due to an unrelated JVM issue on its host machine. What happens to the application?
Correct answer: A — The entire application terminates because the driver holds the SparkContext and coordinates all executors; losing it ends the job even though the executors are still healthy.
- A. Correct. The driver owns the SparkContext and is the single coordinator for scheduling and tracking the application's tasks; its loss ends the application regardless of executor health.
- B. Incorrect. Executors do not elect a replacement driver; there is no built-in leader-election mechanism among executor processes in standard Spark deployments.
- C. Incorrect. Losing the driver ends the whole application rather than triggering a selective stage restart, because the component that tracks stage state and dependencies is gone.
- D. Incorrect. Executors are not designed to continue as independent applications; they depend on the driver for task assignment and coordination and terminate along with it.
- E. Incorrect. A crashed driver process cannot be reattached to its original SparkContext; the application must be resubmitted rather than resumed from a paused state.
3.CPU cores are task slots
Each core given to an executor is one task slot. Spark maps task slots to available cores one to one, and an executor runs its tasks as threads, so an executor with 4 cores runs at most 4 tasks at a time. A job is divided into smaller sets of tasks called stages, which depend on each other, and any further tasks in a stage wait for a free slot. A stage ends only when its last task finishes, so a few long-running tasks leave the other cores idle.
The cores that count are the ones allocated to the executor, not the ones on the machine. Suppose a worker has 8 physical cores and its single executor was launched with 4. That executor runs 4 tasks at once, and the other 4 cores take no Spark tasks. Memory does not set the slot count, and the cluster manager does not reserve the extra cores for anything. They simply were not requested.
Add up the slots and you get the cluster's parallelism. The total number of cores across all executors sets the maximum number of tasks that can run at once. Five executors with 4 cores each give 20 slots. A stage of 200 tasks then runs in about ten waves of 20, however many machines those executors sit on. How many tasks a stage has depends on partitioning.
Slots are shared by everything running on the cluster. When several streaming queries run on one cluster, a stage from one query can fill every free slot, and the other queries have to wait. If queries need to run at the same time, the cluster needs enough cores for all of them.
Checkpoint 4 of 7· Check yourself
Two clusters have one executor per worker node. Cluster A has 2 workers, and each executor has 16 cores. Cluster B has 8 workers, and each executor has 4 cores. A stage has 64 tasks. How do the two clusters compare on this stage?
Each core allocated to an executor is one task slot, so the most tasks that can run at once is the total of executor cores. That total is 2 × 16 = 32 on Cluster A and 8 × 4 = 32 on Cluster B. The number of machines does not change the slot count, so 64 tasks take about two waves on either cluster.
“Total executor cores (compute): The total number of cores across all executors. This determines the maximum parallelism of a compute.”Source: docs.databricks.com
Checkpoint 5 of 7· Exam question
A team submits spark-submit --num-executors 5 --executor-cores 4 --executor-memory 16g job.py on a standalone cluster. Each worker node has 8 CPU cores and 32 GB RAM and hosts exactly one executor. A colleague asks why only 4 tasks from the current stage run at once on each executor, even though every worker has 8 cores physically available. What should you tell them?
Correct answer: A — Each executor's task-slot count equals --executor-cores, so this executor can only run 4 tasks concurrently regardless of the worker's total core count.
- A. Correct.
--executor-coressets the number of task slots an executor can run in parallel; only 4 were requested, so the extra physical cores on the worker sit idle for this application. - B. Incorrect. Spark's built-in shuffle service does not reserve a fixed pool of cores per executor, and this behavior is not how executor concurrency is limited.
- C. Incorrect. Executor memory governs how much data an executor can hold and process, not how many tasks run concurrently; that is controlled by the core count.
- D. Incorrect. Standalone mode does not impose a hidden half-core ceiling per executor; the executor simply runs as many concurrent tasks as
--executor-coresspecifies. - E. Incorrect. The driver schedules tasks based on stage partitioning, but the number that can run simultaneously on a given executor is bounded by that executor's configured cores, not partition counts of unrelated RDDs.
4.Executor memory, driver memory and sizing a cluster
Executors do the memory-heavy work. Shuffles, joins, sorts and aggregations all use executor execution memory. When that memory runs low, Spark writes data to disk, which is called spill. Spill is slower but the job keeps going. If memory runs out completely, the executor fails: Spark removes it and retries its tasks, and after repeated failures the stage and the job fail. Local disk on each node absorbs spills during shuffles and also holds cached data. Storage levels are covered under caching.
Memory per core is what protects a task. All the tasks in an executor run as threads inside the same process and share its memory. Doubling the cores while keeping 4g doubles the number of tasks competing for that 4g, so each task gets half as much and out-of-memory errors become more likely. One way to check for a memory problem is to keep the cores and double the memory. A 4-core worker that moves from 16 GB to 32 GB has 8 GB per core instead of 4 GB. If the job then takes longer to fail, or stops failing, memory was the cause.
| Worker shape | Concurrent tasks | Memory per core |
|---|---|---|
| 4 cores, 16 GB | 4 | 4 GB |
| 4 cores, 32 GB | 4 | 8 GB |
| 16 cores, 128 GB | 16 | 8 GB |
The driver's memory goes on coordination and on whatever results you bring back to it. It does not process partitions. Its memory fills up when results are pulled onto it: collect() on a large DataFrame copies the whole result set into the driver and can crash it with an out-of-memory error. When many queries share a cluster, they also share the driver's CPU, memory and schedulers. In general executors do more memory-intensive work than the driver, so the driver can stay modest unless your code makes it hold data.
Size a cluster by its total cores and memory, not by how many nodes it has. Two workers with 16 cores and 128 GB each give the same compute and memory as eight workers with 4 cores and 32 GB each. Both have 32 slots and 256 GB. Choose between them by workload. A complex ETL job with joins across many tables does better on fewer, larger workers, because less data moves between machines during shuffles. Joins and aggregations are wide transformations: they need data from multiple partitions, so Spark shuffles it between executors. A simple ETL job that needs no wide transformations can use instances with less memory and storage. If you see heavy spill or out-of-memory errors, add memory to each instance rather than adding nodes of the same shape.
Checkpoint 6 of 7· Check yourself
An executor has 8 cores and 4g of memory. During a large join it keeps failing with out-of-memory errors and spilling heavily. Which change addresses the cause?
All tasks in an executor share its memory, so memory per core decides whether a task fits. Adding memory per instance raises that share. More cores at the same 4g cut each task's share, nodes of the same shape keep it the same, and the driver does not process partitions.
“If you observe significant spill to disk or OOM errors, increase the amount of memory available on your instances.”Source: docs.databricks.com
Checkpoint 7 of 7· Exam question
A job repeatedly fails with java.lang.OutOfMemoryError: Java heap space on the executors. The cluster has 10 worker nodes, each configured with --executor-cores 8 and --executor-memory 4g, with one executor per worker. Increasing --executor-cores to 16 without changing --executor-memory makes the failures worse. Why?
Correct answer: A — More cores let the executor run more concurrent tasks inside the same JVM heap, dividing the fixed 4g memory pool across more simultaneous tasks and shrinking each one's share.
- A. Correct. All task slots in an executor share the same 4g JVM heap; doubling the core count doubles the number of tasks that can run at once, so each task gets a smaller effective share of that fixed heap.
- B. Incorrect. Changing
--executor-coresdoes not automatically adjustspark.executor.memory; the two settings are configured independently. - C. Incorrect. Additional cores run additional task threads inside the same executor JVM; they do not spawn separate JVM processes each with their own heap.
- D. Incorrect. There is no cluster-manager-enforced heap cap tied to worker identity; the 4g figure comes directly from the
--executor-memorysetting applied to that executor. - E. Incorrect. Partition count is driven by the input data and any repartitioning calls, not by the number of cores assigned to an executor, and partitions do not each reserve a fixed heap buffer.
Sources
(8)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.https://spark.apache.org/docs/latest/cluster-overview.htmlSecondary source
“Each application gets its own executor processes, which stay up for the duration of the whole application and run tasks in multiple threads.”
↩︎ The four parts of a Spark cluster“An external service for acquiring resources on the cluster”
↩︎ The four parts of a Spark cluster“The driver program must listen for and accept incoming connections from its executors throughout its lifetime”
↩︎ What the driver does, and what happens when it fails“Each job gets divided into smaller sets of tasks called stages that depend on each other”
↩︎ CPU cores are task slots“A process launched for an application on a worker node, that runs tasks and keeps data in memory or disk storage across them.”
↩︎ Key concept“A process launched for an application on a worker node, that runs tasks and keeps data in memory or disk storage across them.”
↩︎ Checkpoint“Spark applications run as independent sets of processes on a cluster, coordinated by the SparkContext object in your main program (called the driver program).”
↩︎ Prediction - 2.https://docs.databricks.com/aws/en/sparkrOfficial docs
“Worker nodes run the Spark executors, one Spark executor per worker node.”
↩︎ The four parts of a Spark cluster - 3.https://docs.databricks.com/aws/en/compute/configureOfficial docs
“If the compute resource has zero workers, you can run non-Spark commands on the driver node, but Spark commands will fail.”
↩︎ The four parts of a Spark cluster - 4.https://docs.databricks.com/aws/en/optimizations/spark-ui-guide/spark-driver-overloadedOfficial docs
“It interprets every command, plans each query, and schedules tasks on the executors.”
↩︎ What the driver does, and what happens when it fails“When the driver is overloaded, it can't hand out work fast enough, so the executors sit idle while you still pay for them.”
↩︎ What the driver does, and what happens when it fails“If the driver is busy running non-Spark code, a larger driver doesn't help the idle workers.”
↩︎ Exam trap 3“If the driver is busy running non-Spark code, a larger driver doesn't help the idle workers. Rewrite the code to use Spark”
↩︎ Checkpoint - 5.
“Spark uses a 1:1 mapping between task slots and available cores.”
↩︎ CPU cores are task slots“to avoid materializing large result sets and causing out-of-memory (OOM) errors”
↩︎ Executor memory, driver memory and sizing a cluster“In general, executors might perform more memory-intensive operations than the driver node.”
↩︎ Executor memory, driver memory and sizing a cluster“Spark uses a 1:1 mapping between task slots and available cores.”
↩︎ Exam trap 1 - 6.
“Total executor cores (compute): The total number of cores across all executors. This determines the maximum parallelism of a compute.”
↩︎ CPU cores are task slots“Local disk is primarily used in the case of spills during shuffles and caching.”
↩︎ Executor memory, driver memory and sizing a cluster“has the same compute and memory as configuring compute with 8 workers, each with 4 cores and 32 GB of RAM.”
↩︎ Executor memory, driver memory and sizing a cluster“If you observe significant spill to disk or OOM errors, increase the amount of memory available on your instances.”
↩︎ Executor memory, driver memory and sizing a cluster“simple batch ETL jobs that don't require wide transformations, such as joins or aggregations”
↩︎ Executor memory, driver memory and sizing a cluster“processing requiring data from multiple partitions, leading to many shuffle operations”
↩︎ Executor memory, driver memory and sizing a cluster“has the same compute and memory as configuring compute with 8 workers, each with 4 cores and 32 GB of RAM.”
↩︎ Exam trap 4 - 7.
“The other cores sit idle while those tasks finish, which results in poor cluster utilization and longer jobs.”
↩︎ CPU cores are task slots“Spill happens when Spark runs low on execution memory, which Spark uses for shuffles, joins, sorts, and aggregations.”
↩︎ Executor memory, driver memory and sizing a cluster - 8.
“When executors run out of memory, Spark removes them and retries their tasks.”
↩︎ Executor memory, driver memory and sizing a cluster“That gives you 8 GB per core instead of 4 GB.”
↩︎ Executor memory, driver memory and sizing a cluster“The ratio of memory to cores matters, not the total memory.”
↩︎ Exam trap 2