6 guides
How to answer Apache Spark interview questions
Almost every Spark performance question is really a question about the shuffle: when it happens, what it costs and how to avoid it. Get that story straight and repartition, broadcast joins, skew and AQE all become easy to explain. Each guide is short enough to say out loud in an interview.
- What is the difference between repartition and coalesce in Spark?repartition does a full shuffle and can raise or lower the number of partitions, giving evenly sized ones. coalesce only lowers the number by merging existing partitions without a full shuffle, so it's cheaper but can leave partitions uneven.Beginner
- What are narrow and wide transformations in Spark?In a narrow transformation each output partition depends on one input partition, so no data moves between executors. A wide transformation needs data from many partitions, which causes a shuffle and starts a new stage.Beginner
- What is the difference between cache() and persist() in Spark?cache() is persist() with the default storage level, MEMORY_AND_DISK_DESER for DataFrames. persist() lets you choose the level, such as memory only or memory and disk. Both are lazy: the data is stored the first time an action computes it.Beginner
- What is a broadcast join in Spark, and when should you use it?A broadcast join sends a full copy of the small table to every executor, so the large table is joined where it sits without being shuffled. Spark does it automatically below spark.sql.autoBroadcastJoinThreshold, 10 MB by default.Intermediate
- What is Adaptive Query Execution in Spark?Adaptive Query Execution re-optimizes a query while it runs, using real statistics from finished shuffle stages. It coalesces small shuffle partitions, switches sort-merge joins to broadcast joins, and splits skewed partitions. It is on by default since Spark 3.2.Intermediate
- How do you handle data skew in Spark?Skew is when a few keys hold most of the rows, so a few tasks run far longer than the rest. Find it in the Spark UI, then fix it with AQE's skew join handling, broadcasting the small side, salting hot keys or handling null keys separately.Experienced