Data engineer interview questions on Spark usually cover lazy evaluation, narrow and wide transformations, shuffles, partitioning, broadcast joins, data skew and caching. Airflow questions test DAG design, idempotency, backfills and retries. Strong answers explain the concept in one line, then describe how you used or tuned it on a real pipeline.
Data engineering interviews have a pattern. The first ten minutes are SQL. Then the interviewer leans in and asks about Spark: why was that job slow, and what did you do about it? After that comes orchestration, usually Airflow, and a design question about a pipeline that has to be reliable at 3 in the morning when nobody is watching.
This guide covers 18 questions across Spark, Airflow and pipeline design, each with a short model answer you can say in under a minute. For the broader list, including SQL and data modelling, see our data engineer interview questions page.
Spark fundamentals: what do interviewers ask first?
1. What is lazy evaluation in Spark?
Transformations such as select, filter and join do not run immediately. Spark records them in a logical plan. Only when an action like count, collect or write is called does Spark optimise the whole plan and execute it. This lets the optimiser combine steps and push filters down before reading data.
2. What is the difference between narrow and wide transformations?
In a narrow transformation, such as filter or map, each output partition depends on one input partition, so no data moves between executors. A wide transformation, such as groupBy, join or distinct, needs data from many partitions, which triggers a shuffle across the network and creates a new stage. Shuffles are usually the most expensive part of a job.
3. What is the difference between repartition and coalesce?
repartition can increase or decrease the number of partitions and always performs a full shuffle, giving evenly sized partitions. coalesce only reduces partitions by merging existing ones without a full shuffle, so it is cheaper but can leave partitions uneven. Use coalesce before writing to cut down on small files, and repartition when you need balance or want to partition by a column.
4. What are the driver and executors?
The driver runs your main program, builds the plan and schedules tasks. Executors run on worker nodes and do the actual processing on partitions. A common mistake is calling collect on a large DataFrame, which pulls all the data into the driver and can cause an out of memory error.
5. DataFrame or RDD, which do you use and why?
DataFrames for almost everything. They go through the Catalyst optimiser and the Tungsten execution engine, so Spark can reorder operations and use efficient memory formats. RDDs give low level control but no query optimisation. I would only reach for an RDD for unusual, unstructured processing.
6. Why is reduceByKey preferred over groupByKey?
On RDDs, reduceByKey combines values on each partition before the shuffle, so far less data crosses the network. groupByKey ships every value for a key to one place, which uses more memory and can fail on large keys. With DataFrames, groupBy followed by an aggregation already does partial aggregation for you.
How do you answer Spark performance questions?
7. What is a broadcast join, and when do you use it?
When one side of a join is small, Spark can send a full copy of it to every executor, so the large table does not need to shuffle. Spark does this automatically for tables under the spark.sql.autoBroadcastJoinThreshold setting, which defaults to 10 MB, and you can force it with a hint. Do not broadcast something large, or executors run out of memory.
8. What is data skew, and how do you fix it?
Skew is when a few keys hold most of the rows, so a handful of tasks run far longer than the rest. You spot it in the Spark UI when one task in a stage takes much longer than the median. Fixes include broadcasting the smaller side, enabling Adaptive Query Execution so Spark splits skewed partitions in sort merge joins, filtering out null or junk keys, or salting the hot key.
9. When do you use cache or persist?
When the same DataFrame is reused by more than one action, for example a cleaned dataset that feeds three aggregations. cache uses the default storage level, which for DataFrames is memory and disk. persist lets you choose the level. Unpersist when you are done, and do not cache data that is used only once.
10. How do you handle the small files problem?
Too many small files slow down reads and stress the metastore or object store. Reduce partitions before writing with coalesce or repartition, avoid partitioning by a high cardinality column, and run periodic compaction. Table formats like Delta Lake and Apache Iceberg provide compaction commands for this.
A worked example: fixing a slow join
Interviewers love to ask you to walk through a fix. Here is the kind of code worth knowing by heart. First, a broadcast join for a small lookup table:
from pyspark.sql import functions as F joined = orders.join(F.broadcast(countries), "country_code")
Second, salting when one customer_id holds a large share of orders and both tables are too big to broadcast. You add a random salt to the large side and copy the small side once per salt value:
N = 10 orders_s = orders.withColumn("salt", (F.rand() * N).cast("int")) salts = spark.range(N).withColumnRenamed("id", "salt") customers_s = customers.crossJoin(salts) joined = orders_s.join(customers_s, ["customer_id", "salt"])
The hot key is now spread across ten partitions instead of one. The cost is that the customers side grows ten times, so pick the smallest salt count that removes the long tail. On Spark 3, try AQE skew join handling first, because it needs no code changes.
Airflow interview questions for data engineers
11. What are a DAG, a task, an operator and a sensor?
A DAG is a workflow of tasks with dependencies and no cycles, plus a schedule. A task is one unit of work in that DAG. An operator is the template that defines what a task does, such as running Python, a SQL query or a Spark submit. A sensor is a special operator that waits for a condition, like a file landing in S3.
12. Why should Airflow tasks be idempotent?
Tasks get retried, backfilled and rerun by hand. If running a task twice for the same date double-loads data, every retry becomes an incident. Make tasks idempotent by writing to a partition for that run's data interval and overwriting it, or by using merge or upsert logic instead of plain inserts.
13. What are catchup and backfill?
Each DAG run covers a data interval, identified by its logical date. With catchup set to true, Airflow creates runs for every missed interval between the start date and now when the DAG is turned on. Backfill is running a DAG for a chosen historical range on purpose, for example after fixing a bug. Most teams set catchup to false and backfill deliberately.
with DAG("daily_sales", start_date=datetime(2026, 1, 1), schedule="@daily", catchup=False, default_args={"retries": 2}) as dag: extract = PythonOperator(task_id="extract", python_callable=extract_sales) load = PythonOperator(task_id="load", python_callable=load_sales) extract >> load
14. What is XCom, and what should you not use it for?
XCom lets tasks pass small values to each other, such as a file path, a row count or a batch id. It is stored in the Airflow metadata database by default, so it is not meant for datasets. Pass a reference to the data in storage, not the data itself.
15. How do you stop long sensors from blocking worker slots?
Run sensors in reschedule mode, which frees the slot between checks, or use deferrable operators, which hand the waiting to the triggerer process. Always set a timeout so a missing file fails clearly instead of waiting forever.
Pipeline design questions
16. How do you build an incremental load? Track a high water mark, such as the latest updated_at value or a change data capture offset, and pull only newer records each run. Allow an overlap window for late updates and make the write a merge so reprocessing is safe.
17. What is a slowly changing dimension type 2? It keeps history by closing the old row with an end date or current flag and inserting a new row when an attribute changes, so reports can show what was true at any point in time.
18. Where do you add data quality checks? After ingestion for schema and row counts, after transformation for nulls, duplicates and valid ranges, and before publishing for business rules. A failed check should stop the downstream task and alert someone, not silently pass bad data.
Design questions often grow into a whiteboard discussion. Our system design interview basics guide covers how to structure that conversation: requirements first, then data flow, then failure handling.
How do you explain a Spark fix in the interview?
The question is usually "Tell me about a performance problem you solved." Interviewers want symptom, diagnosis, fix and result. Here is how Karthik, a data engineer at a retail analytics company, says it:
Our nightly sales job started missing its window after we onboarded a big marketplace client. In the Spark UI, one stage had a single task running far longer than the others, which pointed to skew on seller_id. That client's seller id held a huge share of the rows. I turned on AQE skew handling first, which helped but was not enough, so I salted that join with ten buckets and broadcast a small lookup table we were also joining. In my project, the job went back to finishing well inside the window, and I added a row count check so we would catch similar growth early.
Notice it names the tool used to diagnose, tries the simple fix first and ends with prevention. Use your own numbers, rounded honestly.
How should you prepare for the Spark round?
Run a small PySpark job locally and open the Spark UI. Seeing stages and shuffles once makes your answers concrete.
Prepare two real stories: one performance fix and one pipeline failure you handled.
Know your project's numbers: data volume per day, cluster size and run time.
Practise saying each answer above in under a minute.
A timed mock interview shows quickly which answers run long or skip the diagnosis step. On the day, some candidates use the Interview Copilot for technical interviews to see short prompts drawn from their own resume. Follow each employer's interview rules and use it to express your real experience. If you have just joined a new data team, Job Support for Python can help with real tickets and code reviews in your first 90 days.
Ready to practise? Try InterviewPlan AI free with 5 live minutes and 100 AI credits, no card needed, and rehearse your Spark stories until they sound like the engineer you already are.
Frequently asked questions
Is PySpark enough for a data engineer interview, or do I need Scala?
For most roles in India and remote teams, PySpark is enough, since the DataFrame API and optimiser are the same. Some companies with older codebases ask for Scala. Check the job description, and be ready to explain concepts like shuffles and partitioning regardless of language.
What is the most common Spark interview question?
Questions on shuffles and joins come up most: narrow versus wide transformations, broadcast joins and how to handle data skew. Interviewers often follow up with a real scenario, such as a slow job, and ask how you would diagnose it using the Spark UI.
Do I need Airflow experience for a data engineer role?
Many roles list Airflow, but orchestration concepts transfer. If you have used Azure Data Factory, AWS Step Functions or cron, explain what you scheduled, how you handled retries and failures, and how you would map that to Airflow DAGs and tasks.
What does AQE do in Spark?
Adaptive Query Execution, enabled by default since Spark 3.2, re-optimises a query at runtime using statistics from completed stages. It can coalesce small shuffle partitions, switch a sort merge join to a broadcast join and split skewed partitions, often improving jobs without code changes.
How do I explain a pipeline failure without sounding careless?
Use a clear structure: what broke, how you found out, how you fixed it, and what you changed so it would not happen again. Focus on the prevention step, such as adding a data quality check, an alert or making a task idempotent. That shows ownership rather than blame.
