Understanding How Distributed Engines Divide and Move Data
This lesson explains how Spark, Flink, Redshift and Athena spread work across many machines, which explains most performance problems and their fixes.
Learning outcomes
After completing this lesson, you will be able to:
- Describe how drivers, executors and partitions divide work.
- Reduce shuffles with broadcast joins and partitioning.
- Decide whether to scale up or scale out.
How distributed engines work
Engines such as Spark process data too large for one computer by splitting it into partitions, which executors on many nodes process in parallel. A driver process plans the job, divides it into tasks and coordinates the executors. Operations that need related rows together, such as joins, groupBy and sorts, cause a shuffle, moving data across the network between nodes; shuffles are often the slowest and most expensive part of a job.
When one key has far more rows than the others, the task that handles it runs much longer than the rest, and the whole job waits for this straggler; this is data skew. Engines are fault tolerant because they record how each partition was computed, its lineage, so a failed task is simply re-run. The following table summarises the concepts.
| Concept | Meaning |
|---|---|
| Partitions | Chunks of data processed in parallel by executors on many nodes |
| Driver | The process that plans the job and coordinates executors |
| Shuffle | Moving data across the network for joins, groupBy and sorts; expensive |
| Data skew | One key has far more rows, creating straggler tasks |
| Fault tolerance | Failed tasks are re-run from their lineage |
The following diagram shows the driver, the executors and a shuffle between two stages.

Distributed engine concepts
Reducing shuffles
A shuffle moves data between nodes so that related rows end up together, for example all rows with the same key for a join or aggregation. Shuffles involve writing data to disk, sending it across the network and reading it again, so they are usually the most expensive part of a distributed job, and reducing them is the main way to speed jobs up.
When one side of a join is small, such as a lookup table, a broadcast join sends a copy of it to every node, so the large table never moves. Filtering and aggregating before joining reduces the volume that has to be shuffled. When the same large join runs repeatedly, storing both tables partitioned or bucketed by the join key lets the engine skip the shuffle. Adaptive query execution in Spark adjusts the number of partitions and the join strategy at run time based on the actual data sizes, which fixes many shuffle problems automatically.
The following diagram compares a shuffle join with a broadcast join of a large table and a small table.

Reducing shuffles
Scaling up or out
Adding more machines, scaling out, speeds up a job only when its work can be divided among them. Some work cannot be divided. A single large file in a format that cannot be split, such as a gzip-compressed CSV, is read by one task. A single very frequent key, a hot key, sends most of the data to one task in a join or aggregation. Work done on the driver runs on one machine regardless of cluster size. In each case, adding executors adds cost but not speed, and the data layout or the code must change instead, for example by using splittable formats or by salting hot keys.
Conversely, work that is well partitioned scales almost linearly: twice the workers finish in about half the time for about the same total cost. That property makes serverless engines such as AWS Glue and EMR Serverless cost-effective for well-designed jobs.
Will more workers help?
Avoiding a shuffle with a broadcast join
A Glue job joins a 2 TB orders table with a 50 MB table of product categories. The Spark UI shows most of the run spent shuffling both tables across the network so that matching keys meet on the same executor. The fix broadcasts the small table to every executor, as follows.
from pyspark.sql.functions import broadcast
enriched = orders.join(broadcast(categories), "category_id")Each executor now joins its own partitions of orders with a local copy of the categories, and the 2 TB table is never moved. Adaptive query execution can make the same choice automatically when its statistics show the table is small enough.
A few tasks take much longer than all the others. What is the likely cause?
Show answer
Data skew: some keys hold far more data. Salting or repartitioning spreads it out.
Exam Tips
Remember for the exam
- Minimise shuffles, caused by joins, groupBy and sorts, for better performance.
- A small lookup table in a Spark join calls for a broadcast join.
- A few tasks taking much longer than the rest indicate data skew; use salting or repartitioning.
- Adaptive query execution adjusts joins and partitions at run time.
- More executors do not help when work is concentrated on one key, file or the driver.