# Distributed Processing Concepts

> Understand partitioning, parallelism, shuffles, data locality and fault tolerance, the ideas behind MapReduce, Spark and every distributed engine. Free notes,...

Canonical: https://www.internhack.in/roadmaps/tracks/data-engineer/distributed-processing
Last updated: 2026-11-28

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](https://www.internhack.in/roadmaps/tracks/data-engineer/object-storage-layout), [Query Plans, Indexes and Performance](https://www.internhack.in/roadmaps/tracks/data-engineer/query-plans)

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](https://spark.apache.org/docs/latest/cluster-overview.html) (Apache Spark)
- [MapReduce](https://en.wikipedia.org/wiki/MapReduce) (Wikipedia)
- [Data Engineering Zoomcamp (batch module)](https://github.com/DataTalksClub/data-engineering-zoomcamp) (DataTalksClub)

Previous: [Object Storage, Partitioning and Data Lake Layout](https://www.internhack.in/roadmaps/tracks/data-engineer/object-storage-layout) · Next: [Spark Architecture and Execution Model](https://www.internhack.in/roadmaps/tracks/data-engineer/spark-architecture)

## More in Batch Processing with Apache Spark

- [Distributed Processing Concepts](https://www.internhack.in/roadmaps/tracks/data-engineer/distributed-processing)
- [Spark Architecture and Execution Model](https://www.internhack.in/roadmaps/tracks/data-engineer/spark-architecture)
- [PySpark DataFrames](https://www.internhack.in/roadmaps/tracks/data-engineer/pyspark-dataframes)
- [Joins and Shuffles in Spark](https://www.internhack.in/roadmaps/tracks/data-engineer/spark-joins)
- [Spark Performance Tuning and Operations](https://www.internhack.in/roadmaps/tracks/data-engineer/spark-tuning)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Data Engineer Roadmap](https://www.internhack.in/roadmaps/tracks/data-engineer)
