Uncorp
Log In
Data Engineering3 min readUpdated 2026-10-26

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.

Naitik Tailor & Uncorp Engineering Faculty
Apache Spark & PySpark Distributed Data Engineering Architecture Vector Illustration
TL;DR — Key Engineering & Career Takeaways
  • 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 PySpark Bottlenecks, Root Causes & Architectural Fixes
Production SymptomUnderlying Root CauseExact Interview Answer & Fix
Job hangs at 199/200 tasks completed for 45 minutesData Skew — a single partition key (e.g., `NULL` or `guest_user`) holds 60% of rowsFilter 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 nodeCalling `df.collect()` or `df.toPandas()` on millions of rows, or broadcasting a table >8GBNever `.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 ExecutorHuge shuffle partition skew, exploding 1-to-many join, or Python UDF memory overheadReplace 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 tableDefault Sort-Merge Join shuffles both the 1TB and 40MB tables across the networkUse `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 100MBRun `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.

Written & Reviewed By Uncorp Engineering Faculty

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

About Uncorp

Continue Reading in This Topic Cluster

All 73 Guides