If you have 4 executors each with 16GB of memory, how would you allocate memory for a broadcast join?
💡 Model Answer
Broadcast joins in Spark require the smaller dataset to be sent to all executors as a broadcast variable. The memory needed for the broadcast variable is allocated on the driver, not on the executors. With 4 executors each having 16 GB, you first decide how many executors you will actually launch (e.g., 4). You then set spark.executor.memory to a value that leaves enough headroom for overhead and shuffle. A typical configuration might be spark.executor.memory=12 GB and spark.executor.memoryOverhead=2 GB, giving 14 GB per executor and leaving 2 GB for OS and other processes. The driver should have enough memory to hold the broadcast variable; you can set spark.driver.memory=4 GB or higher depending on the broadcast size. You also set spark.sql.autoBroadcastJoinThreshold to a value that matches the size of the smaller table (e.g., 10 MB). If the broadcast variable is larger than this threshold, Spark will fall back to a shuffle join. By carefully allocating executor memory and driver memory, you ensure that the broadcast join does not cause out‑of‑memory errors while still benefiting from the low‑latency join.
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