Where Spark performance actually lives. Learn what a partition is and how many the data wants, why the shuffle is the most expensive thing Spark does and how to make it cheaper, when caching a DataFrame pays and when it just wastes memory, and how a single hot key like JFK turns one task into the whole job — then tune the zone-hour job end to end.
Welcome to Partitions, Shuffles & Caching, the fifth module — where Spark tuning stops being about the query and starts being about the machine underneath it. Module 4 ended on the one thing it could not optimize away: the group-by’s Exchange, the shuffle that aggregating by key genuinely requires. It left you with a sharper question than “how do I avoid this shuffle?” — namely, “how big is it, and can I make it cheaper?” That question is where real Spark performance lives, and answering it means understanding the three levers this module is named for.
The first is the partition — the unit of parallelism, one task per partition. How many partitions your data is split into decides how many cores can work at once, how much scheduling overhead you pay, and how big each shuffle piece is; you’ll learn to see the count, control it with repartition and coalesce, and recognize when there are too few or too many. The second is the shuffle itself — the moment Spark regroups rows across partitions for a wide operation like a group-by or a join. It writes files, moves them across the network, and reads them back, which is why it is the single most expensive thing Spark does, and why every Exchange in a plan is worth its own attention. The third is caching — the answer to Spark’s lazy recomputation, where a DataFrame used by three actions is computed three times unless you tell Spark to hold it. You’ll measure exactly when cache() turns that into a one-time cost and when it just fills memory for a workload that never reuses anything.
Then the module confronts the failure mode that quietly ruins otherwise-tuned jobs: skew. When one key is far bigger than the rest — and CityFlow has a perfect example in JFK Airport’s 429,745 trips — one shuffle partition swells, one task runs long after all the others have finished, and the whole stage waits for that single straggler. You’ll diagnose it on the real data and weigh the honest mitigations, including the ones Spark’s adaptive execution already applies for you. The guided project brings it together, tuning the zone-hour job’s physical execution knob by measured knob while proving the answer never changes: still 240,917 buckets, 9,554,757 trips, $256,692,373.14. Start with Lesson 1, where a partition turns out to be the most important number in a Spark job that nobody looks at.
Complete all 5 lessons to finish the Partitions, Shuffles & Caching module.