The Real Broadcast Ceiling
Concepts covered: Broadcast Join
spark.sql.autoBroadcastJoinThreshold accepts any number of bytes, and F.broadcast accepts any DataFrame. Neither checks whether the cluster can carry what it asks for. The real limit comes from where a broadcast's bytes have to sit, and in practice it lands between 1 and 2GB of decoded rows, far below the hard cap Spark itself enforces.
- 8GB
- 300s
Where a broadcast's bytes sit
- Small side read tasks (source, executors)
- Driver collects rows (transform, driver)
- Driver builds hash table (transform, driver)
- Copy on executor 1 (storage, executor memory)
- Copy on executor 2 (storage, executor memory)
- Copy on executor 40 (storage, executor memory)
- Large side tasks probe (consumer, executors)
- Small side read tasks -> Driver collects rows
- Driver collects rows -> Driver builds hash table
- Driver builds hash table -> Copy on executor 1
- Driver builds hash table -> Copy on executor 2
- Driver builds hash table -> Copy on executor 40
- Copy on executor 1 -> Large side tasks probe
- Copy on executor 2 -> Large side tasks probe
- Copy on executor 40 -> Large side tasks probe
Every step holds the whole table. The driver receives each row of the small side as a task result, so the collected bytes count against spark.driver.maxResultSize, which defaults to 1GB. They must also fit in the driver's own memory, which is 1GB too unless --driver-memory raises it. The driver then builds the hash table while still holding the rows it came from. Each executor keeps its own complete copy while its tasks run, in the same memory those tasks use.
A 1.5GB dimension on 40 executors
| Where | What it holds | Size |
|---|---|---|
| Driver, collecting | Every row of the dimension | 1.5GB |
| Driver, building | The rows plus the hash table built from them | About 3GB at the peak |
| Each executor | One full copy of the hash table | 1.5GB |
| All 40 executors | 40 copies | 60GB of memory |
| Network | One copy delivered to each executor | 60GB moved |
Compare that with the shuffle it replaces. If the large side is 200GB, a sort-merge join moves about 201.5GB through the shuffle, so this broadcast still moves fewer bytes. At 1.5GB the limit that bites is memory: the driver needs about 3GB free at one moment, and every executor gives up 1.5GB to a table that stays resident while its tasks run. Make the dimension 6GB and the bytes turn against it as well: 240GB of copies against a shuffle of roughly 206GB, plus a 6GB build on a single machine.
Disk bytes and memory bytes
The threshold compares an estimate built from file sizes, and files are compressed and encoded. A Parquet table can grow several times over when decoded into rows, so 300MB on disk can become more than 1GB of hash table. Raising the threshold to 2GB lets through tables whose decoded size nobody has checked. The number that gives a broadcast's real size is the data size the Spark UI reports for its broadcast exchange, covered in the next section.
- A broadcast that is too big
- The driver runs out of memory while collecting or building, and the query fails
- Collected rows pass spark.driver.maxResultSize, and the job is aborted
- The build outlasts spark.sql.broadcastTimeout, and the query fails
- A sort-merge join that is too big
- Stages take longer as more bytes cross the shuffle
- Each task handles only its own partition of each side
- Growth usually costs time before it costs the job
Why the ceiling sits at 1 to 2GB
Under around 1GB of decoded rows, a broadcast fits a driver given a few GB of memory, stays inside a raised spark.driver.maxResultSize, and costs each executor a small slice of its memory. Between 1 and 2GB it runs on a cluster configured for it and fails on one that is not, and a small error in the assumed size tips it over. Past 2GB, the build on one driver and the copy on every executor leave the job one memory shortfall away from failing, and on wide clusters the copies rival the shuffle they replace, as the 6GB case showed. Setting the threshold to 5GB does not move the ceiling: the driver and executors still have to hold whatever it lets through.
- Do
- Measure a broadcast as decoded rows from a real run, not as files on disk
- Keep each broadcast under around 1GB
- Raise driver memory and maxResultSize together for a broadcast near 1GB
- Avoid
- Set the threshold to gigabytes to rescue one slow join
- Treat a file's size on disk as the size of its hash table
- Leave a hint on a dimension that grows every month without checking it again
A dimension is 900MB of Parquet on disk. To make it broadcast, someone sets the threshold to 1GB. What is the main risk?
- Decoded into rows it can be several times 900MB, which the driver and every executor must hold
- None, since the 900MB estimate is under 1GB and Spark has confirmed the table fits
- The large side is shuffled anyway, so the broadcast doubles the network traffic
- Spark refuses the broadcast, since 900MB is over its hard cap on broadcast size
A broadcast either fits everywhere it has to be or fails the query, so the size worth knowing is the one measured from a real run. The next section reads the plan to find out what Spark decided.
About this lesson
This section is part of the Joins: Intermediate lesson on DataDriven, the home of data engineering. Lessons cover SQL, Python, Spark, data modeling and pipeline architecture, and each section pairs its explanation with worked examples and practice you run as you go.