Spark internals
31 in-depth lessons. How Spark executes your batch jobs, the configs that change it, and what is new in Spark 4.0. Every lesson ends with a quick check.
Bronze
Module 1: Your first Spark session
Run Spark locally and say who does what in an application.
- Run Spark on your laptop · Bronze · 7 min read. Set up a real Spark session in minutes, with Delta Lake, Iceberg or Spark Connect, for the hands-on labs.
- Driver, executors and the cluster manager · Bronze · 7 min read. Who plans the work, who does it, and who hands out the machines in a Spark application.
Module 2: How a job runs
Trace an action through jobs, stages, tasks and partitions.
- Transformations vs actions · Bronze · 6 min read. Why nothing runs until you call an action, and what lazy evaluation buys Spark.
- RDDs, DataFrames and Datasets · Bronze · 5 min read. The three Spark APIs, what Catalyst can and cannot optimise, and when an RDD still makes sense.
- Why DataFrames are faster than RDDs · Bronze · 8 min read. Column pruning, pushdown, no Python round trip, Tungsten rows and code generation: five reasons, and how one lambda switches them off.
- Partitions · Bronze · 7 min read. The unit of parallelism in Spark: where partitions come from and why their number matters.
- Jobs, stages and tasks · Bronze · 7 min read. How one action becomes a DAG of stages split at shuffles, and how to read it in the Spark UI.
Silver
Module 3: Shuffles and joins
Spot every shuffle in a job and choose how a join runs.
- Narrow vs wide transformations · Silver · 6 min read. Which operations move data across the network, and why the shuffle is the most expensive step.
- Shuffle partitions · Silver · 5 min read. The default of 200 shuffle partitions, and how to size them for your data.
- Join strategies · Silver · 8 min read. Broadcast hash, shuffle hash, sort-merge and nested loop joins: how Spark picks one, and how to steer it.
- Join hints and slow non-equi joins · Silver · 6 min read. Steer the join strategy with hints, rewrite a join that fell back to a nested loop, and check what Spark really ran.
- Broadcast joins · Silver · 6 min read. Ship a small table to every executor and skip the shuffle, and when broadcasting backfires.
Module 4: Memory and resources
Cache the right things and size a cluster to the workload.
- Caching and persistence · Silver · 6 min read. cache(), persist() and storage levels: when caching speeds a job up and when it hurts.
- Broadcast variables and accumulators · Silver · 7 min read. Why driver variables never change inside tasks, and the two shared variables Spark offers instead.
- Dynamic allocation · Silver · 6 min read. Add and remove executors with the workload, and keep shuffle files safe while executors come and go.
Module 5: Self-tuning and file layout
Let AQE re-plan queries, and stop jobs writing tiny files.
- Adaptive Query Execution · Silver · 7 min read. Spark re-plans a running query from real statistics: coalescing, join switching and skew splitting.
- The small file problem · Silver · 8 min read. Why thousands of tiny files slow every read, how Spark jobs create them, and how to prevent and fix them.
Gold
Module 6: Skew
Find a hot key and spread it, by hand or with AQE.
- Data skew and salting · Gold · 8 min read. Why one task runs for an hour while the rest finish in seconds, and how salting spreads a hot key.
- AQE skew-join handling · Gold · 6 min read. How Spark detects oversized partitions in sort-merge joins and splits them automatically.
Module 7: Under the hood
Read a physical plan and explain spills, fetch failures and serializers.
- Catalyst and physical plans · Gold · 6 min read. Read explain() output: parsed, analyzed and optimized plans, and the physical plan Spark runs.
- The memory model · Gold · 7 min read. Execution vs storage memory, overhead, and what really causes spills and out-of-memory errors.
- Shuffle internals · Gold · 8 min read. Map output files, block fetches, fetch failures and the external shuffle service.
- How aggregations execute · Gold · 7 min read. Partial and final aggregation, hash vs sort aggregation, and why COUNT(DISTINCT) costs more.
- Serialization: Java, Kryo, Tungsten and Arrow · Gold · 7 min read. Where Spark serializes data and code, and which serializer matters for RDDs, DataFrames and Python.
Module 8: Layout tricks
Skip partitions at runtime and pre-shuffle tables with buckets.
- Dynamic partition pruning · Gold · 6 min read. Skip whole partitions of a fact table at runtime using a filter on the dimension it joins to.
- Bucketing · Gold · 6 min read. Pre-shuffle tables into buckets so joins and aggregations on the key skip the shuffle.
Module 9: Spark 4
Explain what Spark 4 changes: Connect, ANSI mode, VARIANT, pipe SQL and Python data sources.
- Spark Connect · Gold · 5 min read. A thin client that talks to a remote Spark server over gRPC, and what it changes for applications.
- ANSI mode by default · Gold · 5 min read. Spark 4.0 turns ANSI SQL on: overflows and invalid casts now raise errors instead of returning null.
- The VARIANT type · Gold · 6 min read. Store and query semi-structured JSON efficiently without declaring a schema up front.
- SQL pipe syntax · Gold · 5 min read. Write SQL top to bottom with the |> operator, in the order the query actually runs.
- Python Data Source API · Gold · 6 min read. Write custom batch and streaming readers and writers for Spark in pure Python.