Module · 5 lessons

SparkSession, RDDs & Lazy Evaluation

Why reading 160 MB 'finished' in milliseconds while counting it took real time: Spark builds plans instead of executing lines. Learn transformations vs actions, meet the RDD layer underneath DataFrames and measure why Catalyst beats hand-rolled code, read the DAG of jobs, stages, and tasks, and see what immutability and lineage buy — all on the real taxi quarter.

At a glance

Level
Intermediate
Lessons
5 lessons
Time to complete
1 week
Cost
Free forever · no sign-up

Welcome to SparkSession, RDDs & Lazy Evaluation, the second module — and the explanation Module 1 owed you. Twice in that module something strange happened and was deferred: reading the entire 160 MB quarter “completed” in about fifty milliseconds, while a mere count of the same data took half a second and spawned jobs, stages, and tasks. A pandas user’s instincts run exactly the other way — reading is the expensive part, counting is instant. The inversion has one cause, and it is the most important idea in Spark: nothing runs until an action demands a result. A line like df.filter(...) doesn’t filter anything; it appends a step to a plan. Spark is not an eager library that executes your lines — it is a compiler that collects them, optimizes the whole program, and executes it only when you ask for an answer.

That single design choice is where almost everything you’ll use in this course comes from. Because Spark sees the whole plan before running it, the optimizer can prune nineteen columns to three and push filters into the file scan — Module 1 watched it do both, unasked. Because a DataFrame is immutable and remembers the lineage of transformations that produced it, Spark can recompute a lost piece of work from source instead of replicating everything — its fault-tolerance story on a real cluster. And because the plan compiles down to RDDs — the raw distributed collections underneath — you can drop a level and see exactly what the DataFrame API is saving you, in measured seconds, by keeping your logic where the optimizer can see it.

Across five lessons you’ll time both halves of the lazy bargain, hand-roll a job on RDDs and measure it against Catalyst, learn to read the DAG — one action becoming jobs, stages split at shuffles, one task per partition, with Spark 4’s adaptive execution reshaping the plan mid-flight — and close with a guided project that traces a single real aggregation end to end, predictions written down before the run and checked against what the engine actually did. Start with Lesson 1, where the same pipeline is timed twice: once as a plan, once as work.

Lessons in this module

1 Transformations vs Actions Solve Module 1's deferred mystery by timing both halves of Spark's lazy bargain on the real 9.5M-row quarter: building a five-step pipeline takes 73 ms, executing it takes 2.31 s — and asking twice makes Spark run the whole thing twice. 2 RDDs Underneath Drop below the DataFrame API to the RDD layer it compiles to: hand-roll January's per-zone trip count with Python lambdas and measure it at 7.93 s against Catalyst's 0.15 s — a 51.4x gap explained row by row at the JVM-to-Python bridge. 3 The DAG: Jobs, Stages, Tasks Learn to predict a Spark job's shape before running it: classify narrow vs wide transformations, tag real work with setJobGroup, and read true anatomy from sc.statusTracker() — a JFK filter-count that becomes 2 jobs and 21 scheduled tasks, a no-op write proving the narrow pipeline is one 10-task stage, and a two-shuffle quarter leaderboard that adaptive execution re-cuts into 4 jobs, 44 tasks scheduled, only 13 run. 4 Immutability & Lineage Prove that every Spark transformation returns a new DataFrame — filter 2,964,624 January trips down to 145,240 and recount the original, unchanged — then print the actual lineage tree behind a five-step quarter report and measure what a recipe-based engine really costs: a narrow pipeline pays a full rescan per action (0.53 s, then 0.36 s), while the report cross-checks Course 1 to the cent at $256,692,373.14. 5 Guided Project: Trace One Job End to End Predict a real Spark job's shape before it runs — 2 jobs, 21 scheduled tasks, 11 actually executed — then verify every prediction against the status tracker and the answer against Course 1's ground truth: 9,554,757 trips and $256,692,373.14 to the cent.
Achievement

Complete all 5 lessons to finish the SparkSession, RDDs & Lazy Evaluation module.

Start module
Sponsor

Keep DATATWEETS free. Help fund practical data, AI, and engineering lessons for learners worldwide.

Buy Me a Coffee at ko-fi.com