HomeInterview QuestionsWhat are some join strategies in Spark, and when i…

What are some join strategies in Spark, and when is each best used?

🟡 Medium Conceptual Junior level
2Times asked
Mar 2026Last seen
Mar 2026First seen

💡 Model Answer

Spark supports several join strategies: broadcast join, shuffle hash join, sort‑merge join, and shuffle group join. Broadcast join pushes a small DataFrame to all executors; use it when one side is below the broadcast threshold (≈10‑20 MB). Shuffle hash join hashes both sides and shuffles the data; it is efficient for medium‑sized joins where both sides fit comfortably in memory. Sort‑merge join sorts both sides on the join key and merges them; it is ideal for large, sorted datasets or when the data is already partitioned on the join key. Shuffle group join is a fallback for highly skewed joins; it groups by key and processes each group separately, reducing shuffle traffic. In practice, you would broadcast the small dimension table (e.g., a lookup table) against a large fact table, use shuffle hash for medium joins, sort‑merge for large sorted joins, and shuffle group for skewed data. The time complexity of broadcast is O(n), shuffle hash is O(n log n), and sort‑merge is also O(n log n). For example, joining a 5 MB user table with a 10 GB clickstream table would typically use a broadcast join to avoid shuffling the large dataset.

This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.

🎤 Get questions like this answered in real-time

Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.

Get Assisting AI — Starts at ₹500