Top 25 Apache Spark & PySpark Interview Questions (2026): Broadcast Joins, Data Skew, Catalyst & OOM Debugging
Master the exact distributed execution internals, shuffle optimization, Adaptive Query Execution (AQE), and Out-Of-Memory troubleshooting questions asked in ₹18–35 LPA Data Engineering rounds.

- Data Engineering panels rarely ask basic DataFrame syntax; they test what happens under the hood when a 2TB PySpark job hangs at 99% or crashes with `java.lang.OutOfMemoryError`.
- You must clearly distinguish Driver OOM (caused by `.collect()`, `.toPandas()`, or broadcasting an oversized table) from Executor OOM (caused by skewed partitions, wide shuffles, or excessive concurrency per executor).
- Mastering three optimization techniques—Broadcast Hash Joins, Salted Keys / Spark 3+ Adaptive Query Execution (AQE), and `repartition()` vs `coalesce()`—will help you clear 90% of senior Spark architecture rounds.
1. The Execution Hierarchy Every Candidate Must Draw: Application → Job → Stage → Task
When you submit a PySpark script on Databricks or AWS EMR, the Catalyst Optimizer compiles your logical DataFrame operations into a physical DAG. Every Action (`.count()`, `.write.parquet()`, `.collect()`) triggers a **Spark Job**. Every Wide Transformation (`groupBy`, `join`, `repartition`, `distinct`) introduces a network **Shuffle Boundary**, splitting the Job into separate **Stages**. Inside each Stage, one **Task** runs sequentially per DataFrame partition on an Executor core.
2. The 5 High-Stakes Production Spark Scenarios Tested in Interviews
Use this production troubleshooting matrix to structure crisp, senior-level answers:
| Production Symptom | Underlying Root Cause | Exact Interview Answer & Fix |
|---|---|---|
| Job hangs at 199/200 tasks completed for 45 minutes | Data Skew — a single partition key (e.g., `NULL` or `guest_user`) holds 60% of rows | Filter out `NULL` keys before joining, enable Spark 3+ `spark.sql.adaptive.skewJoin.enabled=true`, or apply key salting (`concat(key, '_', rand(0, 10))`). |
| `OutOfMemoryError: Java heap space` on the Driver node | Calling `df.collect()` or `df.toPandas()` on millions of rows, or broadcasting a table >8GB | Never `.collect()` large DataFrames to the Driver; write directly to S3/Delta Lake from executors (`df.write.format('delta')`). |
| `OutOfMemoryError` or `Container killed by YARN/K8s` on an Executor | Huge shuffle partition skew, exploding 1-to-many join, or Python UDF memory overhead | Replace Python UDFs with native `pyspark.sql.functions`, tune `spark.sql.shuffle.partitions` (or enable AQE coalescing), and increase `spark.executor.memoryOverhead`. |
| Slow Join between a 1TB Fact table and a 40MB Dimension table | Default Sort-Merge Join shuffles both the 1TB and 40MB tables across the network | Use `F.broadcast(dim_df)` to trigger a Broadcast Hash Join—eliminating the 1TB network shuffle completely. |
| Thousands of tiny 50KB Parquet files written to AWS S3 ('Small File Problem') | Writing a DataFrame with 2,000 partitions when total data volume is only 100MB | Run `df.coalesce(4)` before writing (avoids full shuffle) or run Delta Lake `OPTIMIZE` compaction. |
3. Classic Follow-Up: `repartition(n)` vs `coalesce(n)`
`repartition(n)` performs a full network shuffle to create `n` equally sized partitions (can increase or decrease partition count, ideal before heavy transformations). `coalesce(n)` merges existing partitions locally on the same executor without a full shuffle (can only decrease partition count, ideal right before writing final Parquet/Delta files to S3).
Frequently Asked Questions
Why are Python UDFs slow in PySpark, and what should I use instead?
Standard Python `@udf` functions force Spark's JVM executor to serialize every row into a separate Python subprocess via Py4J, destroying Catalyst optimization and vectorization. Always prefer built-in `pyspark.sql.functions` (which run natively inside the JVM) or Pandas Vectorized UDFs (`@pandas_udf` using Apache Arrow).
Where can I practice PySpark on Databricks and AWS with real datasets?
In Module 2 & Module 3 of Uncorp's Data Engineering Master Program, you write and optimize production PySpark pipelines on Databricks and AWS Glue.
Naitik Tailor & Uncorp Engineering Faculty
Founder & Principal Engineering Mentors (12+ Yrs Enterprise Experience) · VIT CSE '21 · Symbiosis MBA '24 · Ex-Delhivery & Ex-Aditya Birla Capital
Continue Reading in This Topic Cluster
All 73 Guides
How Production Lakehouse Pipelines Work: PySpark, Apache Airflow, Kafka & dbt Architecture
Walk through a real-world enterprise data architecture—from Kafka event ingestion and S3 Bronze storage to PySpark Silver transformations, dbt Gold marts, and Airflow orchestration.

dbt (data build tool) + Apache Airflow in Production: Incremental Models, SCD Type 2 Snapshots & DAG Orchestration
How modern data teams combine Apache Airflow scheduling with dbt SQL transformations, automated schema testing, and Slowly Changing Dimension (SCD Type 2) history tracking.

How to Choose the Best Data Engineering Course in 2026: UNCORP vs Data Vidhya vs Codebasics vs Scaler
Compare curriculum depth (SQL, Python, PySpark on Databricks, Airflow, Kafka, dbt, AWS Lakehouse), hands-on projects, modular pricing, and 1-on-1 architect mock interviews.

