1.2 Driver, Executors, and Cluster Managers

Key Takeaways

  • The Driver process executes the user's main() program, initializes the SparkSession, constructs the Directed Acyclic Graph (DAG), coordinates task scheduling, and hosts the Spark Web UI on port 4040.

  • Executors are dedicated worker JVM processes that execute individual task threads, store cached partitions in their local BlockManager, and transmit periodic heartbeats (default every 10s) back to the Driver.

  • Worker nodes are physical or virtual host machines; each worker can host one or more Executor JVMs, where task concurrency normally equals allocated cores divided by spark.task.cpus (default 1), subject to other resource requirements.

  • In YARN Client mode, the Driver runs locally on the submitter's machine outside the cluster, whereas in Cluster mode, the Driver runs remotely within an ApplicationMaster container on a worker node.

  • Databricks managed compute handles cluster lifecycle, dynamic node provisioning, and autoscaling across interactive All-Purpose clusters and automated Job clusters.

Last updated: October 2026

Apache Spark is a distributed computing engine engineered to process large-scale datasets across clusters of commodity or cloud-based machines. At the core of Spark's architecture is a centralized master-worker model. A single coordinator process—the Driver—collaborates with a cluster manager to launch, monitor, and assign computation to worker processes known as Executors.

Understanding how compute resources are divided, how the Driver communicates with Executors, and how various cluster managers allocate hardware is foundational knowledge for any Spark developer and a frequent focus of certification exam questions.


The Master-Worker Architecture

A Spark application operates as an independent set of processes running on a cluster. The architecture decouples the high-level orchestration of compute from the low-level execution of data tasks:

  1. The Driver Node (Master): Translates user code into execution plans, delegates tasks, and tracks overall application health.
  2. The Cluster Manager: Allocates cluster resources (CPU, RAM) across applications; it does not plan Spark SQL queries.
  3. Executor Nodes (Workers): Execute assigned tasks in parallel, persist cached data partitions in memory, and report status back to the Driver.
+-------------------------------------------------------------------------+
|                              DRIVER NODE                                |
|  +-----------------------+     +------------------+                     |
|  | SparkSession / Plan   | --> | DAGScheduler     |                     |
|  +-----------------------+     +------------------+                     |
|             |                            |                              |
|             v                            v                              |
|  +-----------------------+     +------------------+                     |
|  | Spark Web UI (:4040)  |     | TaskScheduler    |                     |
|  +-----------------------+     +------------------+                     |
+-------------------------------------------------------------------------+
                                     | Tasks & Heartbeats
       +-----------------------------+-----------------------------+
       |                                                           |
       v                                                           v
+------------------------------+            +------------------------------+
|     EXECUTOR 1 (Worker)      |            |     EXECUTOR 2 (Worker)      |
|  +------------------------+  |            |  +------------------------+  |
|  | Task Execution Slots   |  |            |  | Task Execution Slots   |  |
|  | [Core 1]  [Core 2]     |  |            |  | [Core 1]  [Core 2]     |  |
|  +------------------------+  |            |  +------------------------+  |
|  +------------------------+  |            |  +------------------------+  |
|  | BlockManager (Cache)   |  |            |  | BlockManager (Cache)   |  |
|  +------------------------+  |            |  +------------------------+  |
+------------------------------+            +------------------------------+

The Driver Node: The Orchestration Center

The Driver is the brain of the Spark application. When you launch a PySpark script or interactive notebook, the Driver process is instantiated to run your main() method.

Primary Driver Responsibilities

  • Maintaining Application State and Session: The Driver instantiates and maintains the SparkSession (or SparkContext in legacy code), which serves as the unified entry point for reading data, executing SQL queries, and configuring runtime properties.
  • Formulating the Execution Plan (DAG): When transformations are chained, the Driver does not immediately compute rows. Instead, it records them into a logical plan and compiles them into a Directed Acyclic Graph (DAG) of stages and tasks.
  • Task Scheduling and Dispatch: The Driver hosts two critical internal schedulers:
    • DAGScheduler: Divides the RDD dependency graph produced by the chosen physical plan into stages at shuffle boundaries.
    • TaskScheduler: Accepts TaskSets from the DAGScheduler and dispatches individual tasks to Executors based on data locality.
  • Serving the Spark Web UI: By default, the Driver binds to port 4040 (e.g., http://<driver-ip>:4040) to serve an interactive Web UI displaying active and completed jobs, stages, storage memory usage, environment variables, and executor health.
  • Collecting Results: When an action such as collect() or take() is executed, the Driver coordinates the retrieval of partition results from Executors over the network and brings them into its local memory.

Single Point of Failure (SPOF)

In standard cluster environments, the Driver represents a single point of failure. If the Driver process runs out of memory or crashes, all associated Executors are terminated by the cluster manager, and the Spark application immediately fails.


Executor Nodes: Distributed Execution Engines

Executors are worker processes running within their own Java Virtual Machine (JVM) instances across the cluster's worker nodes. Executors belong to one application and can remain for its lifetime. Dynamic allocation, when enabled, can add or remove them as demand changes.

Primary Executor Responsibilities

  • Running Assigned Tasks: An Executor receives serialized task instructions from the Driver's TaskScheduler, deserializes the code, and executes it against local data partitions across multi-threaded task slots.
  • Managing In-Memory Storage (BlockManager): Each Executor includes an internal BlockManager that caches DataFrames/RDDs in local memory or spills them to disk when df.cache() or df.persist() is invoked.
  • Managing Shuffle Output Files: When wide transformations require data repartitioning, Executors write intermediate shuffle partition files to their local disk storage so downstream stages can fetch them.
  • Transmitting Heartbeats: Executors communicate back to the Driver via periodic heartbeats (default spark.executor.heartbeatInterval is 10 seconds), reporting task completion metrics, memory utilization, and liveness. If the Driver does not receive a heartbeat within spark.network.timeout (default 120 seconds), the Executor is marked dead and its tasks are rescheduled.

Worker Nodes vs. Executors: Resource Allocation

A critical distinction on the exam is the difference between a Worker Node and an Executor:

  • Worker Node: A physical computer or virtual machine (e.g., an AWS EC2 instance or Azure VM) attached to the cluster.
  • Executor: A distinct JVM process running inside a Worker Node.

A single Worker Node can host multiple Executor JVMs depending on hardware configuration. Compute capacity is determined by three key configuration settings:

SettingDescriptionDefault / Recommended
spark.executor.instancesTotal number of executor processes launched across the cluster.Dynamic allocation or fixed count
spark.executor.coresNumber of concurrent task slots (CPU threads) per executor JVM.Workload-dependent; check concurrent task memory
spark.executor.memoryHeap memory allocated to each individual executor JVM.E.g., 8g or 16g depending on instance size
spark.driver.memoryHeap memory allocated specifically to the Driver JVM process.E.g., 4g to avoid driver OOM on result collections

Tip

Size executors from measurements. More cores increase concurrent task memory demand; fewer, larger executors may reduce duplicated broadcast data. There is no universal five-core optimum. Compare task throughput, GC time, spill, resource requests, and cluster-manager limits.


Driver vs. Executor Comparison

Architectural DimensionDriver NodeExecutor Node
Primary RoleCentral coordination, planning, and task schedulingParallel task execution and partition data caching
Runtime ProcessSingle master JVM process running the user applicationMultiple distributed worker JVM processes
Failure ConsequenceFatal: Crashes the entire Spark applicationResilient: Driver reschedules failed tasks on surviving executors
Memory ResponsibilityHouses broadcast variables, collect results, and DAG planHouses execution memory (shuffles/joins) and storage memory (caching)
Web UI HostingServes the Spark Web UI (default port 4040)Does not host UI; exposes block metrics to Driver via heartbeats
ScalabilityFixed at 1 process per applicationHorizontally scalable via static allocation or dynamic scaling

Cluster Managers and Deployment Modes

Apache Spark relies on an external Cluster Manager to acquire physical machines and allocate JVM containers. Common cluster managers and managed deployment environments include:

  1. Standalone: Spark's built-in cluster manager. Simple to deploy, featuring a dedicated Standalone Master and Worker daemons.
  2. Apache YARN: The standard Hadoop resource manager consisting of a centralized ResourceManager and per-node NodeManager daemons.
  3. Kubernetes (K8s): Cloud-native container orchestration. The Driver runs in a K8s Driver Pod, which directly invokes the Kubernetes API server to spawn Executor Pods on demand.
  4. Databricks Managed Compute: Fully managed enterprise compute architecture. Databricks automates cloud VM provisioning, runtime patching, and fine-grained autoscaling across All-Purpose Clusters (interactive collaborative development) and Job Clusters (automated production ETL pipelines).

Deployment Modes: Client vs. Cluster

When submitting a Spark application via spark-submit, the --deploy-mode flag determines where the Driver process physically executes:

# Submitting in cluster mode
spark-submit \
  --master yarn \
  --deploy-mode cluster \
  --executor-memory 4g \
  --executor-cores 4 \
  my_etl_script.py
Deployment ModeDriver Physical LocationNetwork Proximity to WorkersCommon Use Case
Client ModeRuns locally on the client/submitting machine outside the clusterDriver must remain reachable; shuffle data primarily moves between executorsInteractive classic PySpark applications; managed notebooks have platform-specific placement
Cluster ModeRuns inside the cluster; for YARN, in the ApplicationMaster containerColocated / Low network latency within high-speed cluster fabricScheduled production ETL jobs, headless pipeline execution

Important

Exam Trap: In Client Mode, if the client-side driver process terminates, the application loses its coordinator. A terminal disconnect alone does not necessarily terminate a separately supervised process. In Cluster Mode, the submitter can disconnect immediately after dispatching; the cluster manager supervises the Driver on a worker node until job completion.


Initializing SparkSession in PySpark

In modern Spark (versions 2.0 through 3.x+), the SparkSession provides a single unified entry point to DataFrame and SQL functionality, replacing the legacy SparkContext, SQLContext, and HiveContext.

from pyspark.sql import SparkSession

# Instantiate the unified SparkSession entry point on the Driver
spark = SparkSession.builder \
    .appName("ProductionDataPipeline") \
    .config("spark.executor.instances", "4") \
    .config("spark.executor.cores", "4") \
    .config("spark.executor.memory", "8g") \
    .config("spark.driver.memory", "4g") \
    .config("spark.sql.shuffle.partitions", "200") \
    .getOrCreate()

# Accessing underlying SparkContext if low-level RDD APIs are required
sc = spark.sparkContext
print(f"Spark App ID: {sc.applicationId}")
print(f"Spark Master: {sc.master}")

These requests apply when a new application is launched and the deployment supports them. An existing session may be reused; deployment properties cannot resize an already running driver. Set driver heap and executor resources in spark-submit or the platform compute configuration before launch. With four four-core executors, default task CPU requests permit up to 16 concurrent tasks.

Test Your Knowledge

Which of the following responsibilities belongs exclusively to the Spark Driver, rather than an Executor?

A

Writing shuffle map output files to local executor disk and sending heartbeats every 10 seconds

B

Executing individual task threads and storing partitioned data blocks in the local BlockManager

C

Formulating the Directed Acyclic Graph (DAG), scheduling tasks, and serving the Spark Web UI

D

Managing worker node operating system processes and allocating hardware memory slices to JVM containers

Test Your Knowledge

A data engineer submits a Spark application to an Apache YARN cluster using client deployment mode. Where does the Spark Driver process execute, and what happens if the client-side driver process is terminated?

A

The Driver runs inside the ApplicationMaster container on a worker node; if the terminal disconnects, the job continues uninterrupted.

B

The Driver runs across all executor JVMs redundantly; if the terminal disconnects, a new worker node is elected as the driver.

C

The Driver runs inside the YARN ResourceManager; if the terminal disconnects, execution is paused until the client re-authenticates.

D

The Driver runs locally on the client machine outside the YARN cluster; if that client-side driver process is terminated, the application fails.

Test Your Knowledge

When configuring a Spark cluster, with spark.task.cpus=1 and no other resource limits, what is the usual relationship between executor cores and concurrent tasks?

A

With spark.task.cpus=1 and no additional limiting resource requests, each allocated executor core normally supplies one concurrent task slot.

B

Each executor core is capable of executing multiple shuffle stages simultaneously using asynchronous threads.

C

Executor cores determine the total number of worker nodes that the cluster manager can launch in parallel.

D

A minimum of four executor cores must be allocated to a single partition before any task can begin execution.

Sections you finish are checked off in the contents.