Home › Guides › PySpark interview questions
Tech Explained · 2026PySpark Interview Questions 2026: 10 Real Questions, Model Answers and the Shuffle Behind Most of Them
PySpark interview questions cluster around four things: how Spark turns your code into stages, why a join broadcasts or spills, how you spot skew, and how you read a physical plan. The one number worth memorising is 200, the default for spark.sql.shuffle.partitions, because so many follow-up questions start there.
- Every answer bottoms out in the shuffle. Explain where data crosses the network and you can reason through unseen questions.
- Know four defaults cold. 200 shuffle partitions, a 10 MB broadcast threshold, AQE on since Spark 3.2.0, a skew factor of 5.
- Panels test diagnosis, not recall. A strong answer to "this job got slow" starts with the Spark UI, not executor memory.
-
Skip RDD trivia. Spend the hour on joins, window functions and reading
explain("formatted"). - One real job beats ten question lists. Find the longest task in a job you ran, then explain why.
Your nightly aggregation ran in four minutes on the dev lakehouse. In production it takes forty, one task sits at 98% for half an hour, and the log says only that a stage retried. That gap is what a PySpark round is about. Nobody checks whether you can write groupBy; they check what you say in the first ninety seconds in front of that job.
Keep one scenario running: a two-person data team at a mid-size Indian insurer, moving a nightly claims aggregation into a Spark notebook. 400 million claim rows, a hospital dimension of 60,000 rows, one hospital group generating 30% of claims.
What PySpark Interview Questions Actually Test in 2026
There are two kinds of round. The first is a vocabulary check run by a generalist: narrow versus wide, name three transformations. Be clear and fast and you pass. The second is run by someone paged at 2am by a Spark job: here is a plan, tell me what is wrong. That one decides your band, and memorised definitions collapse at the first follow-up.
Where to spend your PySpark prep hours
Weighted towards the questions that decide the offer, not the ones that decide the screen.
An editorial recommendation, not a measured sample. Checked 18 November 2026.
Ask which runtime the team uses, because it moves the answers. Microsoft Learn's Fabric runtime pages list Runtime 1.3 on Apache Spark 3.5.5 with Delta Lake 3.2, and Runtime 2.0 on Apache Spark 4.1, so a Fabric shop asks about OneLake paths rather than cluster sizing. 360DT's live Microsoft Fabric data engineering program runs its Spark work inside Fabric notebooks for that reason.
How Does PySpark Run Your Code? One Action, Two Stages, One Shuffle
Nothing runs when you call filter or withColumn; those build a logical plan. On an action such as write or count, Catalyst optimises the plan, picks physical operators, and splits the work wherever data must be redistributed. Each split point is a shuffle; each span between them is a stage.
The only diagram you need in the room
The partition count changes at the Exchange, not at the read.
Partition count is the documented default of 200. Checked 18 November 2026.
Questions 1 to 4: Partitions and Spark Shuffle Partitions
1. Your source folder has three parquet files. Why does the next stage show 200 tasks? The partition count after a wide transformation comes from spark.sql.shuffle.partitions, documented as 200 in the Apache Spark performance tuning guide, not from your input layout. Sensible on 400 million claim rows. On a 50,000 row lookup it means 200 tasks doing nothing much, and scheduling overhead wins.
df = spark.read.parquet("abfss://lake@onelake.dfs.fabric.microsoft.com/Files/claims/")
print(df.rdd.getNumPartitions()) # input partitions, from the file layout
agg = df.groupBy("hospital_id").sum("claim_amount")
print(agg.rdd.getNumPartitions()) # 200, from spark.sql.shuffle.partitions
spark.conf.set("spark.sql.shuffle.partitions", 32) # sane for a small table
2. Narrow or wide: which of these shuffles? filter, select and withColumn are narrow: each output row depends on one input row in one partition. groupBy, join, distinct, orderBy and any partitionBy window are wide, because rows sharing a key must land together. Narrow costs CPU, wide costs network, which is why one wide operation outweighs twenty narrow ones.
3. repartition or coalesce? repartition(n) shuffles fully and gives even partitions. coalesce(n) merges existing ones without a shuffle, which is cheap but keeps the imbalance. Use coalesce to turn 200 small output files into 8, repartition when the partitions are lopsided.
4. Does adaptive query execution make the 200 setting irrelevant? Nearly, and this separates people who read release notes from people who do not. AQE has been on by default since Apache Spark 3.2.0 and coalesces shuffle partitions at runtime from real output sizes. So 200 is where the planner starts and AQE collapses it. The setting still matters with AQE off, and when reading a plan before execution.
| Setting | Default | What it controls | When you touch it |
|---|---|---|---|
spark.sql.shuffle.partitions |
200 | Partitions after a wide transformation | Small tables, or AQE disabled |
spark.sql.adaptive.enabled |
true since Spark 3.2.0 | Rewrites the plan from runtime stats | Leave on, except to reproduce a plan |
spark.sql.autoBroadcastJoinThreshold |
10485760 bytes (10 MB) | Largest estimated table Spark will broadcast | Raise for a 40 MB dimension, -1 to force a shuffle join |
spark.sql.adaptive.skewJoin.skewedPartitionFactor |
5 | Multiple of median partition size that flags skew | Rarely. Use the threshold below |
spark.sql.adaptive.skewJoin.skewedPartitionThresholdInBytes |
256 MB | Size floor a partition must also cross | Lower it for small but lopsided partitions |
Those come from the Apache Spark performance tuning documentation and Databricks' AQE page, checked 18 November 2026. One wrinkle catches people who learned Spark on Databricks: its own setting, spark.databricks.adaptive.autoBroadcastJoinThreshold, defaults to 30 MB, not 10 MB. Quote 10 MB and add "in open-source Spark".
Questions 5 to 7: Broadcast Join in PySpark and Data Skew in Spark
5. When does Spark broadcast a join, and why did yours kill the driver? When one side's estimated size falls under spark.sql.autoBroadcastJoinThreshold, Spark collects that side to the driver and ships it to every executor, so the larger side never moves. The trap is that the threshold compares estimated in-memory size, not the parquet footprint, and compressed columnar data expands several times when deserialised. A dimension that looks like 40 MB on disk can arrive as hundreds of megabytes of objects in a driver given 4 GB.
6. So what do you change? In this order: read the estimated size in explain("formatted"), compare it with reality, then raise the threshold deliberately, pin the strategy with broadcast(df), or set it to -1 and accept a shuffle join. Driver memory is the last lever. Mention too that with AQE on, Spark can flip to a broadcast at runtime once it sees real output sizes.
7. How do you detect data skew in Spark, and fix it when AQE will not? Open the stage detail and read the task summary metrics: if max task duration is twenty times the median and max shuffle read matches that ratio, you have skew, while uniformly slow tasks mean a sizing or plan problem. AQE's skew handling fires only when a partition exceeds both skewedPartitionFactor times the median, documented as 5, and skewedPartitionThresholdInBytes, documented as 256 MB, so a lopsided 80 MB partition slips through. Then you salt.
from pyspark.sql import functions as F
SALT = 16
fact = fact.withColumn("salt", (F.rand() * SALT).cast("int"))
dim = dim.withColumn("salt", F.explode(F.array([F.lit(i) for i in range(SALT)])))
joined = (fact.join(dim, ["hospital_id", "salt"], "left")
.drop("salt"))
In the insurer job, the hospital group with 30% of claims puts 120 million rows behind one key, so one task gets a third of the data and 199 wait. Salting spreads it, but you made the dimension 16 times bigger to do it. Say that trade-off out loud, because the follow-up is always "what did that cost you". 60,000 rows becomes 960,000, which is nothing; 20 million would make salting the wrong tool.
- Salting everything. Salt the one hot key, not the whole join. Teams salt by default, double their dimension reads and wonder why the job got slower.
- Confusing a partitioned table with partitioned memory. Delta partition columns on disk and Spark's in-memory partitions share a word and nothing else.
Also read: What Is Apache Spark? How It Works, Spark vs Hadoop and Your First PySpark Job.
Questions 8 to 10: Reading Plans, Pushdown and the Query They Make You Write
8. Read this physical plan to me. Expect a trimmed plan on a whiteboard. Read it bottom up, because that is execution order.
== Physical Plan ==
AdaptiveSparkPlan isFinalPlan=false
+- HashAggregate(keys=[hospital_id#12], functions=[sum(claim_amount#15)])
+- Exchange hashpartitioning(hospital_id#12, 200), ENSURE_REQUIREMENTS
+- HashAggregate(keys=[hospital_id#12], functions=[partial_sum(claim_amount#15)])
+- FileScan parquet [hospital_id#12,claim_amount#15,dt#18]
PartitionFilters: [isnotnull(dt#18), (dt#18 >= 2026-10-01)]
PushedFilters: [IsNotNull(hospital_id)]
The scan touches only date partitions from 1 October onward, so pruning works. The partial_sum below the Exchange means Spark pre-aggregates inside each partition before shuffling, which is why a sum moves far less data than a collect_list. The Exchange is the only network hop, and isFinalPlan=false means the 200 you see may not be the 200 you get.
9. A filter that should remove 99% of rows made no difference to runtime. Why? It is probably not pushed down. The usual culprit is a Python user-defined function sitting between the scan and the predicate: Spark cannot see inside it, so it cannot reorder around it, and the filter runs after every row has been read and serialised into Python. Check PushedFilters in the plan. If your predicate is missing, move it before the UDF or go native.
10. Write me a query that keeps the latest row per key. It tests three things: that dropDuplicates returns an arbitrary row rather than the newest, that you reach for a window function, and that you know the window itself shuffles.
from pyspark.sql import functions as F
from pyspark.sql.window import Window
w = Window.partitionBy("claim_id").orderBy(F.col("updated_at").desc())
latest = (df.withColumn("rn", F.row_number().over(w))
.filter("rn = 1")
.drop("rn"))
Then add the sentence that earns the next question: "partitionBy means a shuffle on claim_id, so if one claim has a million versions this window is where the job stalls." Window functions carry the same weight in PL-300 work, which is why they sit in the SQL modules of a Power BI and SQL data analyst track.
The follow-up: four minutes in dev, forty in production
Not a memory question. Walk the ladder out loud: compare input row counts and PartitionFilters across the two runs, because usually dev read one day and production reads four hundred. Then diff the plans for a join that flipped from broadcast to sort-merge. Then check max versus median task duration. Executor sizing comes fourth.
| Symptom | Likely real cause | What you do |
|---|---|---|
| One task runs 40 minutes, 199 finish in 20 seconds | Key skew on the join or group column | Read the task summary, then salt the hot key |
| Driver out-of-memory right after a join | Broadcast of a table small on disk, large in memory | Compare the plan's estimate with the parquet footprint, then pin or disable it |
| Fast in dev, slow in production | Pruning that worked on one day and not on four hundred | Diff PartitionFilters and input row counts first |
Stage retries with FetchFailedException
|
Executors lost serving shuffle data, usually memory pressure | Shrink partition size, and check logs for container kills |
| A highly selective filter changes nothing | The predicate sits behind a Python UDF | Move the filter before the UDF, or use native functions |
Six Answers That Quietly Lose You the Offer
The six reflexes interviewers listen for
Reasonable-sounding sentences that say you have not debugged a real job.
"Spark is faster because it is in-memory"
From 2014, and it was about MapReduce writing to disk between steps. Spark spills constantly. Say "it avoids writing intermediate results between stages".
Stale marketing"I would increase the executor memory"
As a first move this says you treat Spark as a black box. Memory fixes a diagnosis, not slowness. Plan, stage detail, then resources.
Skipped diagnosis"I cache my DataFrames to speed things up"
Caching something read once costs memory and buys nothing. Name the condition: two or more actions, recomputation dearer than the memory.
Cargo cult"I repartition before every write"
A blanket repartition adds a full shuffle to every job. Usually you want coalesce to cut small files, or a repartition on the output column.
"I would write a UDF for that"
Python UDFs break pushdown and serialise every row across the JVM boundary. Native functions first, higher-order functions second, a UDF with a reason.
Performance taxConfidently wrong defaults
Guessing "1000 shuffle partitions" is worse than saying you would check. The documented values are 200 and 10 MB in open-source Spark.
AvoidableDefaults from the Apache Spark performance tuning documentation, checked 18 November 2026.
The part of this that is oversold
Plenty of data work has moved to SQL-first pipelines on Fabric, Databricks SQL and dbt, where you get asked about incremental models rather than shuffle partitions. If the posting says "analytics engineer" and lists dbt, the Spark round may be twenty minutes of politeness. Deep internals pay well in platform and streaming teams and much less in BI-adjacent roles. If your targets sit closer to deployment, a live MLOps engineering program or a cloud and DevOps track is the better buy.
Practise these PySpark answers on real Fabric notebooks, not flashcards
The Microsoft Fabric Data Engineer course covers Fabric data engineering for the DP-700 certification, with DP-900 fundamentals included. It runs live over 8 weeks with hands on projects, mentor support and placement guidance.
Explore the course
How to Prepare for PySpark Interview Questions in Two Weeks
You do not need two weeks of reading. You need one real job, the Spark UI, and the discipline to write down what you find.
- Days 1 to 4. Run one real aggregation. Find the longest stage, then its longest task, and note max versus median duration. Walk away able to finish "the slowest task was slow because".
-
Days 5 to 8. Run
explain("formatted")on a group-by and two joins, labelling every Exchange and pushed filter until you read a plan bottom up without hesitating. - Days 9 to 11. Break things on purpose. Set the broadcast threshold to -1 and watch the plan change, then build a skewed key and watch one task stretch.
- Days 12 to 14. Type the three snippets above cold, then rehearse the symptom table out loud against a timer until "the job got slow" has a 90 second answer.
One opinion, held firmly: with ten hours, spend seven in the Spark UI of a job you ran and three on question lists. People who have stared at a real task-duration histogram answer differently, and panels hear it. Skip RDD prep. If an interviewer spends five minutes on reduceByKey, that tells you more about their stack than about your gaps.
DP-700 maps most directly to this work, testing Fabric pipelines and lakehouse mechanics rather than algorithm trivia; the full certifications overview shows where it sits, and the same plan-reading instinct now turns up in the AI engineering track. In your position with a round next month, I would run that fortnight on one real job, keep the defaults table open while practising, and sit a free webinar first, because the cheapest way to learn whether Spark internals are your lane is watching someone debug a plan live.
Also read: Databricks Tutorial for Beginners 2026 for a free environment to run it in.
Related guides
- Data Engineer Salary in India 2026 what Spark-heavy roles pay once you clear the round.
- Microsoft Fabric vs Azure Synapse in 2026 pick the platform for your practice notebooks.
- Apache Flink in 2026 the streaming questions that follow "real time".
- Data Engineer vs Data Scientist in 2026 check you are targeting the role hiring near you.
- Data Engineer Jobs in Chennai 2026 which employers in one city ask Spark questions.
Frequently asked questions
What are the most common PySpark interview questions?
Narrow versus wide transformations, why the next stage has 200 tasks, repartition versus coalesce, when Spark broadcasts a join, how to detect and fix skew, how to read a physical plan, and a query that keeps the latest row per key.
Why is the default number of shuffle partitions 200?
It is a fixed default set long before adaptive query execution existed, documented as 200 for spark.sql.shuffle.partitions. It bears no relation to your data size, which is why it fits small tables badly. Since Spark 3.2.0 AQE coalesces those partitions at runtime, so the UI count is often lower.
How do I explain data skew in a Spark interview without sounding vague?
Give a number and a place to look. Compare max task duration and max shuffle read against the median in the stage detail; roughly twenty to one is skew, uniform slowness is not. Note that AQE intervenes only above both five times the median and 256 MB.
What is the difference between a broadcast join and a shuffle join in PySpark?
A broadcast join sends one whole side to every executor so the large side never crosses the network. A shuffle join, usually sort-merge, repartitions both sides by the join key. Spark picks broadcast when one side's estimated in-memory size is under the documented 10 MB open-source threshold, not its parquet size.
When does caching a DataFrame actually help?
When it feeds two or more separate actions and recomputing costs more than the memory it holds. Caching something read once is pure overhead, and caching something large pushes executors towards spilling. Check the Storage tab for the fraction cached, because half-cached gives you the cost without the benefit.
Do I need to learn RDDs for PySpark interviews in 2026?
Enough to say what an RDD is and that DataFrames add a schema and the Catalyst optimiser on top. Beyond that, time on reduceByKey is time not spent on joins, windows and plan reading.
How much PySpark do I need for the DP-700 certification?
Enough to build and transform lakehouse tables in Fabric notebooks: Delta reads and writes, joins, aggregations, window functions and basic optimisation. The exam leans towards Fabric workloads rather than Spark internals. Check the current skills outline on Microsoft Learn first.
Should I say "I do not know" in a PySpark interview?
Yes, if you follow it with where you would look. "I do not remember the exact default, but it is on the SQL performance tuning page and I would check before changing it" reads as professional. A confidently wrong number is the fastest way to lose an interviewer who debugs these jobs.
About this guide. 360 Digital Transformation is an Anthropic Partner and a Microsoft Authorized Training Partner. Other certification bodies, vendors and employers named here are not affiliated with us. Tools and versions change quickly; figures cited were checked on 18 November 2026.



