Move the small input, not the large one
How replicating a small join input avoids shuffling the larger input, and how to select and verify this strategy using input sizes, worker memory, and Spark execution plans. · associate
A join needs matching keys to meet. A shuffle join can repartition both inputs by the join key, moving rows between workers. A broadcast join instead replicates one input to the participating executors, the Spark processes that run tasks. Each executor can then join its existing partitions of the other input locally.
For a supported equality join, Spark can use a broadcast hash join. The small input is the build side: Spark builds an in-memory hash table from it. Tasks scan partitions of the large probe side and look up matching keys. For example, broadcasting a country-code reference table avoids redistributing a large event dataset by country. Broadcasting still transfers data; it avoids the larger input's join-key shuffle, not every network transfer or every shuffle in the query.
This can also avoid concentrating a frequent join key in one shuffled partition. It does not rebalance partitions that were already oversized or fix skew in a later aggregation. The benefit depends on the large input already having reasonably balanced partitions.
| Property | Shuffle join | Broadcast hash join |
|---|---|---|
| Data movement | Repartition by join key | Replicate build input |
| Large input | May move between workers | Probe existing partitions |
| Small input | Partitioned for matching | Complete local lookup |
| Main concern | Shuffle cost and skew | Replicated memory use |