Distributed Processing Concepts
Understand partitioning, parallelism, shuffles, data locality and fault tolerance, the ideas behind MapReduce, Spark and every distributed engine.
Intermediate · about 4 hours · difficulty 3/5
Learn first: Object Storage, Partitioning and Data Lake Layout, Query Plans, Indexes and Performance
Before writing Spark code, understand what any distributed engine is doing. These concepts explain almost every performance problem you will debug.
Splitting the work
- Data is divided into partitions; each partition is processed by a task on a worker in parallel.
- Narrow operations (filter, map, select) work on each partition independently.
- Wide operations (groupBy, join, distinct, orderBy) need rows with the same key on the same machine, so data is redistributed across the network: a shuffle. Shuffles are the main cost in big data jobs.
MapReduce, briefly
The original Hadoop model: map (emit key-value pairs), shuffle (group by key), reduce (aggregate). Spark generalised this with in-memory processing and a richer API. You do not need to write MapReduce, but the mental model helps.
Skew
If one key has far more rows than others (one huge seller on Diwali, or a NULL key), one task does most of the work while others sit idle. Skew is the most common cause of a job stuck at 199 of 200 tasks.
Fault tolerance
Machines fail. Engines track lineage (how each partition was computed) so a lost partition can be recomputed, and write intermediate shuffle data to disk.
Scale up vs scale out
One big machine with DuckDB often beats a small cluster for data under a few hundred GB. Distributed systems add overhead; use them when the data or deadline really requires it.
Pitfalls
- Reaching for Spark for a 2 GB file.
- Assuming more machines always means faster; shuffles and skew can make it slower.
You are ready to move on when you can look at a pipeline (filter, join, group by, sort) and say which steps shuffle, where skew might hit, and whether it even needs a cluster.
Key concepts
- Partitions and tasks
- Narrow vs wide transformations
- Shuffles
- Data skew
- MapReduce model
- Lineage and fault tolerance
- Scale up vs scale out
- Hadoop HDFS and YARN history
Mini project
Write a word count in plain Python that simulates map, shuffle and reduce across four 'workers' (lists). Then introduce a skewed key and show how the work distribution changes.
Check yourself
Why does a groupBy cause a shuffle while a filter does not?
Free resources
- Spark cluster mode overview (Apache Spark)
- MapReduce (Wikipedia)
- Data Engineering Zoomcamp (batch module) (DataTalksClub)