Skip to main content
Data Engineering

Apache Spark Tutorial with Examples.

Apache Spark tutorial covering the core architecture: RDDs, DAG execution, shuffles, Spark SQL and cluster tuning, with real job output.

Architecture at a glance

Click any box to open the lesson that teaches it

Spark architecture at a glance

spark-submit → driver (DAG + Catalyst) → cluster manager → executors

Spark architecture at a glance spark-submit launches the driver, which hosts the SparkSession and a DAG scheduler that turns one action into a job, stages split wherever a shuffle must happen, and tasks, one per partition. Catalyst rewrites the plan with predicate pushdown, column pruning and join selection before anything runs. The driver asks a cluster manager — YARN, Kubernetes, or standalone — for resources, which launches the executors that run tasks and hold cached data in a unified memory pool. A bottom strip covers the shuffle cost between stages, predicate pushdown to data sources, the Spark UI, memory failures, and deployment modes. spark-submit launch Driver SparkSessionDAG scheduler Cluster manager YARN · K8s · standalone Executors tasks · cache& memory pools Inside the driver SparkSession entry point DAG scheduler job → stages → tasks Catalyst optimizer Inside an executor Cache & memory unified pool Tasks one per partition tasks Shuffle, data & observability Shuffle Predicate pushdown Spark UI Memory & spill Deployment
How it fits together (6 steps)
  1. spark-submit launches the driver, which hosts your SparkSession and builds the plan — no cluster work happens in the driver itself.
  2. The driver's DAG scheduler turns one action into a job, splits it into stages wherever a shuffle must happen, and splits each stage into one task per partition.
  3. Catalyst rewrites that plan before it runs — pushing filters down to the data source, pruning columns, and choosing a join strategy — the same optimizer whether the query was written as SQL or as DataFrame calls.
  4. The driver asks the cluster manager (YARN, Kubernetes, or Spark's own standalone mode) for resources, which launches the executors that actually run tasks and hold cached data in a unified memory pool shared between caching and execution.
  5. A shuffle between stages is the expensive part — reduceByKey combines values on each partition before the shuffle, while groupByKey moves every value across the network, a five-times difference for the same result.
  6. When a job is slow, the Spark UI's Jobs, Stages, and SQL tabs show what actually happened, and most failures are one of the memory problems in driver OOM, executor OOM, or disk spill.

Beginner

Start here — no prior experience needed

3 lessons

Intermediate

For developers with core concepts down

2 lessons

Advanced

Production-grade patterns for experienced engineers

1 lesson

Also part of Apache Spark

Taught in other topics. Each link opens the lesson in its home topic.

8 lessons
pyspark advanced
5 min read

Run the same DataFrame code over an unbounded stream — with windows, watermarks, checkpoints, and output modes that decide what you compute.

pyspark intermediate
5 min read

Assemble feature vectors, chain them into a Pipeline with a classifier, and evaluate the fitted model with AUC and accuracy on held-out data.

pyspark beginner
5 min read

Install PySpark, start a SparkSession, build a DataFrame, and see why nothing runs until you call an action.

pyspark beginner
5 min read

Add, rename, and reshape columns with withColumn, when/otherwise, and the functions module — and see why chaining withColumn in a loop is a trap.

pyspark beginner
5 min read

Group, aggregate, and pivot — then read the query plan to see the shuffle that groupBy introduces and why it dominates the job's runtime.

pyspark intermediate
5 min read

Work through every join type, then compare a shuffle join against a broadcast join on the same data and read the difference in the query plan.

pyspark advanced
5 min read

Trace one query from DataFrame to tasks, see where stage boundaries come from, and prove that caching changes the plan rather than just the timing.

pyspark advanced
5 min read

Diagnose and fix the four things that actually make Spark jobs slow — skew, small files, spill, and wasted shuffles — measuring each one.