March 8, 2026
15 PySpark Interview Questions Every Data Engineer Should Practice
Hands-On PySpark Concepts and Coding Questions Asked in Data Engineering Interviews

By Ankur Gupta
3 min read
PySpark has become one of the most important technologies in modern data engineering. It is widely used for building scalable ETL pipelines, processing large datasets, and performing distributed data transformations.
Because of its importance in large-scale data systems, PySpark questions frequently appear in technical interviews for data engineering roles.
Most interviewers are not only interested in theory. They want to evaluate how well you understand distributed processing concepts and practical PySpark operations.
In this article, we will go through 15 commonly asked PySpark interview questions that every data engineer should practice.
1. What is PySpark?
PySpark is the Python API for Apache Spark, a distributed computing framework used for processing large datasets efficiently across clusters.
It allows developers to write Spark applications using Python while leveraging Spark's powerful distributed processing engine.
2. What is the Difference Between Transformations and Actions?
In Spark, operations are categorized into transformations and actions.
Transformations
- Create a new DataFrame or RDD
- Are lazily evaluated
- Do not execute immediately
Examples:
select()
filter()
groupBy()
withColumn()select()
filter()
groupBy()
withColumn()Actions
- Trigger execution of transformations
- Return results or write output
Examples:
show()
count()
collect()
write()show()
count()
collect()
write()Spark executes transformations only when an action is called.
3. What is Lazy Evaluation in Spark?
Lazy evaluation means Spark does not execute transformations immediately.
Instead, it builds a logical execution plan (DAG) and runs it only when an action is triggered.
Benefits include:
- optimization of execution plans
- reduced data movement
- improved performance
4. What is the Difference Between RDD, DataFrame, and Dataset?
RDD (Resilient Distributed Dataset) Low-level distributed data structure with full control but less optimization.
DataFrame Structured distributed data with schema and better performance due to Spark SQL optimizations.
Dataset Type-safe distributed collection mainly used in Scala and Java.
In PySpark, DataFrames are the most commonly used abstraction.
5. What is Repartition vs Coalesce?
Both methods change the number of partitions.
Repartition
- increases or decreases partitions
- performs full shuffle
- used for better parallelism
Example:
df.repartition(10)df.repartition(10)Coalesce
- reduces partitions only
- avoids full shuffle
- more efficient when decreasing partitions
Example:
df.coalesce(2)df.coalesce(2)6. What is a Broadcast Join?
A broadcast join distributes a small dataset to all worker nodes.
This prevents expensive shuffle operations.
Example:
from pyspark.sql.functions import broadcast
result = large_df.join(broadcast(small_df), "id")from pyspark.sql.functions import broadcast
result = large_df.join(broadcast(small_df), "id")Broadcast joins significantly improve performance when joining a large dataset with a small one.
7. What is Data Skew?
Data skew occurs when some keys contain significantly more records than others.
This causes uneven workload distribution across partitions and slows down Spark jobs.
Example scenario:
customer_id 1001 appears 1 million times
others appear only a few timescustomer_id 1001 appears 1 million times
others appear only a few timesHandling skew is important for efficient distributed processing.
8. How Can You Handle Data Skew in Spark?
Common techniques include:
- broadcasting small datasets
- salting keys
- repartitioning data
- filtering unnecessary records
These approaches help distribute workload more evenly.
9. What is the Difference Between Narrow and Wide Transformations?
Narrow Transformations
Data does not move between partitions.
Examples:
filter()
map()
select()filter()
map()
select()Wide Transformations
Data is shuffled between partitions.
Examples:
groupBy()
join()
distinct()groupBy()
join()
distinct()Wide transformations are more expensive due to network shuffling.
10. What is Caching in Spark?
Caching stores a DataFrame in memory so it can be reused without recomputation.
Example:
df.cache()df.cache()This improves performance when the same dataset is used multiple times.
11. What is Persist in Spark?
Persist works similarly to cache but allows different storage levels.
Example:
from pyspark import StorageLevel
df.persist(StorageLevel.MEMORY_AND_DISK)from pyspark import StorageLevel
df.persist(StorageLevel.MEMORY_AND_DISK)This is useful when datasets are too large to fit entirely in memory.
12. How Do You Remove Duplicate Rows in PySpark?
Use the dropDuplicates() function.
Example:
df.dropDuplicates(["user_id"])df.dropDuplicates(["user_id"])This removes duplicate records based on specific columns.
13. How Do You Add a New Column in PySpark?
Use the withColumn() method.
Example:
from pyspark.sql.functions import col
df = df.withColumn("tax", col("amount") * 0.18)from pyspark.sql.functions import col
df = df.withColumn("tax", col("amount") * 0.18)This creates a new column based on existing values.
14. How Do You Filter Rows in PySpark?
Use the filter() or where() method.
Example:
df.filter(df.amount > 100)df.filter(df.amount > 100)Filtering helps reduce dataset size before performing heavy operations.
15. How Do You Read and Write Data in PySpark?
Reading a file:
df = spark.read.csv("data.csv", header=True, inferSchema=True)df = spark.read.csv("data.csv", header=True, inferSchema=True)Writing data:
df.write.parquet("output_path")df.write.parquet("output_path")Columnar formats such as Parquet are preferred for better performance.
Final Thoughts
PySpark interviews often focus on distributed data processing concepts and practical transformations.
Understanding how Spark executes operations, manages partitions, and optimizes performance is essential for both interviews and real-world data engineering work.
Practicing these questions will help you build confidence in PySpark and prepare you for technical interviews in modern data engineering roles.