Skip to main content
InterviewHubPRO
Section Overview
Q18

Question 18 of 50

Part 2: Core Architecture & Implementation (Mid-Level)

36%
Apache Spark Big Data (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)

What are Spark's Join Strategies (Broadcast Hash Join vs Sort-Merge Join vs Shuffle Hash Join)?

senior LevelSystem Design

In Simple Words:

  1. Broadcast Hash Join (BHJ): If one table is small (< 10 MB default, configurable via spark.sql.autoBroadcastJoinThreshold), Spark broadcasts the small table to all executors and performs an in-memory hash join with zero shuffle. Fastest join!
  2. Sort-Merge Join (SMJ - Default for large tables): Shuffles both tables on the join key, sorts each partition, and merges matching keys sequentially. Handles arbitrary table sizes without memory overflow.
  3. Shuffle Hash Join: Shuffles both tables and builds an in-memory hash table for each partition. Used when tables are medium-sized and sorting is expensive.