Home › Interview Questions › What is the difference between repartition and coa…

What is the difference between repartition and coalesce in Spark, and when would you use each?

🟡 Medium Conceptual Junior level
1Times asked
Jul 2026Last seen
Jul 2026First seen

💡 Model Answer

Repartition and coalesce are both used to change the number of partitions in a Spark DataFrame or RDD. Repartition performs a full shuffle of the data across all partitions, which can increase or decrease the number of partitions and results in a balanced distribution. It is useful when you need more parallelism or when you want to redistribute data after a filter that skews the data. Coalesce, on the other hand, only reduces the number of partitions and does not shuffle data; it simply merges existing partitions. This is efficient for reducing partitions after a filter or when you want to avoid the cost of a shuffle. Use repartition when you need to increase partitions or balance data, and use coalesce when you only need to reduce partitions without incurring a shuffle.

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