SPARK Reference Guide
Revision Time: 10 mins

Interview Revision Guide Reference

Quick revision overview of Apache Spark internals, configurations, and core features.

Spark Architecture & Coordinator Role

Spark operates in a Master/Worker model. The Driver coordinates execution while Workers host Executors running tasks.

ComponentResponsibilitiesExecution Lifecycle
Driver NodeCreates SparkSession, builds logical DAG, compiles stages, schedules tasks.Single master process per app.
Cluster ManagerAllocates resource container blocks (YARN, Kubernetes, Standalone).Manages clusters globally.
ExecutorsStores partition blocks in RAM memory, runs physical compute tasks.Launches on worker hosts.
Job -> Stage -> Task Hierarchy

How Spark translates user actions into physical distributed tasks.

  • Action: Triggers a new Spark Job execution (e.g. count, show, write).
  • Stage: Job is divided into Stages at Shuffle boundaries (wide transformations).
  • Task: Smallest unit of work, running inside an executor thread on one partition block.
Catalyst Query Optimizer Workflow

Catalyst compiles DataFrame query expressions into highly optimized physical execution instructions.

Optimization PhaseInputCore Output
1. AnalysisUnresolved Logical PlanResolved Logical Plan (Schema Catalog mapped)
2. Logical OptimizationResolved Logical PlanOptimized Logical Plan (Filter pushdowns, projections limit)
3. Physical PlanningOptimized Logical PlanCHEAPEST physical plans selected for executor JVMs
Narrow vs Wide Transformations

The primary divider of latency in Spark workloads.

PropertyNarrow TransformationWide Transformation
DefinitionOne input partition maps to exactly one output partition.Multiple input partitions contribute to output partitions.
Network ShuffleNo shuffle required. Tasks run locally in parallel.Forced network shuffle. Writes blocks to local disks.
Examplesselect(), filter(), map(), union()groupBy(), join(), distinct(), repartition()
Cache vs Persist Storage Levels

Saving intermediate DataFrame structures in RAM.

MethodDefault Storage LevelCustomization Scope
cache()MEMORY_AND_DISKNo configuration. Hardcoded storage helper.
persist()MEMORY_AND_DISKAccepts Custom StorageLevel objects (MEMORY_ONLY, DISK_ONLY, etc.)
Repartition vs Coalesce

Modifying partition sizes in a running application.

Aspectrepartition()coalesce()
Size ChangeCan increase or decrease partition numbers.Can only decrease partition numbers.
Shuffle StageForced full network shuffle.No shuffle stage created. Merges local blocks.
Best Use CaseBalancing skewed partition sizes prior to joins.Shrinking output files count right before writes.
Adaptive Query Execution (AQE)

Dynamic optimization features enabled in Spark 3+.

  • Dynamic Partition Coalescing: Shrinks empty post-shuffle partitions automatically to save task overhead.
  • Dynamic Join Switch: Converts SortMergeJoin dynamically into Broadcast Hash Joins if runtime partition is small.
  • Dynamic Skew Join Tuning: Detects skewed keys and splits partitions to prevent straggler tasks.