The Join Problem
What you will be able to do
The Broadcast Question
Why the shape matters
- ▸A large fact table joined to a small lookup or dimension.
- ▸The complaint is slowness, and the default join shuffles both sides.
- ▸Shuffling the big side is the cost; the small side is your way out.
What they do in the first seconds
Why this exact question
When both sides are large
It reveals whether you have moved data
Tag each side, big or small
The small side wears disguises
Is One Side Small Enough
Either answer moves you forward
The exchange, rehearsed
- "I would broadcast the small table."
- Commits before knowing the size
- Sounds like a memorized reflex
- No way to justify the choice
- "How big is the lookup side?"
- Makes the size the deciding factor
- Shows you know broadcast has a limit
- Sets up the reasoning that follows
Small in bytes, not rows
A concrete number
Ask in bytes, not rows, because the two diverge badly. 50,000 rows of integers and short strings is a couple of megabytes and trivially broadcastable. The same 50,000 rows with a text blob per row can be hundreds of megabytes. The row count barely moved; the broadcast decision completely changed.
How you ask matters
The habit scales upward
How Broadcast Skips It
Contrast with the default
Put numbers on the trade
Broadcast ships the small side everywhere; the big side never moves.
The threshold to know
The threshold works on an estimate
Why the duplication is worth it
- ▸Broadcast copies the small table to every executor.
- ▸Each executor joins its local big-table partitions against that copy.
- ▸The big table never shuffles, which is where the cost was.
- ▸Spark auto-broadcasts under ~10MB; above that, you force it.
Say it as a chain
Broadcast With No Size
Always attach the size
The push-back, in full
- Tie broadcast to the small side's size every single time you say it.
- Lead with the cost you are avoiding: the shuffle of the big table.
- If you do not know the small side's size, ask for it before recommending broadcast.
- Don't say broadcast and stop; the reasoning is the answer, not the word.
- Don't broadcast a side you have not confirmed is small; that is the staff-level disaster.
- Don't reach for adding executors or memory; this is a data-movement problem, not a resource one.
The resource-problem sibling
The over-explainer
The one habit to keep
Confirming It Broadcast
What the plan shows
Why a hint can silently fail
| In the explain() plan | What it means |
|---|---|
| BroadcastHashJoin | Spark broadcast the small side; the big side did not shuffle |
| BroadcastExchange | The small side is being shipped to every executor |
| SortMergeJoin | No broadcast; both sides shuffled by key |
| Exchange (two of them) | A full shuffle of both sides, the slow default |
Verification is a senior signal
The UI as the second check
Close the loop
> An interviewer says: we join a billion-row events table to a small lookup of a few thousand country codes, and the job is slow. Why, and how would you fix it?
The broadcast question. Reach for it, and say why in one breath.
- Category
- Spark
- Difficulty
- beginner
- Duration
- 15 minutes
- Challenges
- 2 hands-on challenges
Topics covered: The Broadcast Question, Is One Side Small Enough, How Broadcast Skips It, Broadcast With No Size, Confirming It Broadcast
Lesson Sections
- The Broadcast Question (concepts: paBroadcastJoin)
When an interviewer describes joining a large table to a small one and asks why it is slow, they have handed you a pattern with a known answer. The shape is unmistakable once you have seen it: a big fact table, a small lookup or dimension, a join between them, and a complaint that it takes too long. That shape is the cue, and the cue points at one technique. Your job in the first few seconds is to recognize the shape, not to start guessing at random causes. Why the shape matters Here is why the
- Is One Side Small Enough (concepts: paBroadcastJoin)
The strongest opening move is a question, not an answer. Before you commit to broadcast, ask how big the small side actually is. Something like: is the lookup table small enough to fit in memory on every executor? That one question does 3 things at once. It shows you know broadcast depends on size, it gets you the number you need to justify the choice, and it keeps you from blurting a technique that might not apply. Either answer moves you forward If the interviewer says the lookup is a few mega
- How Broadcast Skips It (concepts: paBroadcastJoin)
Now the substance. A broadcast join works by sending a full copy of the small table to every executor in the cluster. Once each executor has the whole small table in memory, it can join its local slice of the big table against that copy without any of the big table moving. The large table stays exactly where it already lives, spread across the cluster, and each machine does its part of the join in place. There is no shuffle of the big side at all. Contrast with the default Contrast that with the
- Broadcast With No Size (concepts: paBroadcastJoin)
The trap that catches junior candidates here is shallow confidence. They hear join is slow, they say broadcast it, and they stop. The word is right, but with nothing behind it the answer reads as a memorized trick rather than understanding. An interviewer who hears broadcast with no size reasoning will often push back precisely to see whether you know why, and a candidate who cannot connect broadcast to the small side falls apart under that push. Always attach the size The fix is a rule you appl
- Confirming It Broadcast (concepts: paBroadcastJoin)
After you recommend broadcast, the natural follow-up is how you would know it actually happened. This is a fair question, because Spark does not always broadcast even when you think it should, and a strong engineer verifies rather than assumes. The answer is the explain method, which prints the physical plan Spark intends to run, and the thing to look for is a node called BroadcastHashJoin. What the plan shows When you call explain on the join and the plan shows a BroadcastHashJoin, with a Broad