Data engineering interview questions: Set 5 (Senior)
Set 5: 30 senior data engineering interview questions with explanations, on SQL, data modelling, Spark, Kafka, lakehouse, pipelines, data quality, cloud and…
There are 3 customers. Customer 1 has a paid order, customer 2 has a refunded order, and customer 3 has no orders. The query uses a LEFT JOIN to keep every customer. How many rows does it return? SQL · Medium
SELECT c.id FROM customers c LEFT JOIN orders o ON o.customer_id = c.id WHERE o.status = 'paid';- 3
- 2
- 1
- 0
Column
xholds 10, 20 and NULL. What does this return? SQL · MediumSELECT AVG(x), SUM(x) / COUNT(*) FROM t;- 10, 10
- 15, 15
- 15, 10
- NULL, 10
You must track each order through placed, paid, shipped and delivered, and report how long each step takes. Which kind of fact table fits? Data modelling · Medium
- A transaction fact table: one row per status event
- A periodic snapshot: one row per order per day
- An accumulating snapshot: one row per order, with a date column per step, updated as the order moves on
- A factless fact table
Parquet files cannot be edited in place. You update one row in a Delta Lake or Iceberg table. What happens to the data files? Storage & formats · Medium
- The row is changed inside its Parquet file
- The file holding the row is rewritten (or a small delete file is added), and a new commit points to the result
- The whole table is rewritten
- Nothing until the next compaction
Producers send single events to Kafka. You want compact messages and safe schema changes, enforced by a schema registry. Which format fits best? Storage & formats · Medium
- Parquet
- Avro
- CSV
- ORC
A Python UDF that upper-cases a column makes a PySpark job ten times slower than the built-in
F.upper. Why? Spark · Medium- Python UDFs run only on the driver
- Each row is sent from the JVM to a Python process and back, and Spark’s optimiser cannot see inside the UDF
- UDFs turn off caching
- UDFs always cause a shuffle
You fixed a bug in a daily Airflow DAG and must recompute the last 90 days without overloading the warehouse. What do you do? Pipelines & orchestration · Medium
- Move start_date back 90 days and turn catchup on
- Run a backfill for those 90 dates with a low max_active_runs (say 3)
- Trigger 90 manual runs at the same time
- Change the SQL to process all 90 days in one run
A Python script parses and transforms 10 million JSON records, which keeps the CPU busy. You run it with 8 threads on an 8-core machine, and it is no faster than with 1 thread. Why, and what helps? Python · Medium
- The machine needs more memory
- Python’s global interpreter lock (GIL) lets only one thread run Python code at a time; use multiple processes instead
- Threads only work on Linux
- JSON parsing cannot be parallelised at all
A database password was committed to a Git repository a week ago. A teammate deletes it in a new commit. Is that enough? Governance & security · Medium
- Yes, the file no longer contains it
- No: it is still in the Git history and any clones; rotate the password now, then move secrets to a secret manager
- Yes, as long as the repository is private
- No, but renaming the repository fixes it
Table
ahas ids 1, 2 and 3. Tablebhas ids 1 and NULL. You want the ids of a that are not in b. What does this return? SQL · HardSELECT COUNT(*) FROM a WHERE id NOT IN (SELECT id FROM b);- 2
- 3
- An error
- 0
An account has a payment of 10 on day 1, and two payments of 5 and 7 on day 2. What running totals does this return, in day order? SQL · Hard
SELECT day, amount, SUM(amount) OVER (ORDER BY day) AS running FROM payments;- 10, 15, 22
- 10, 17, 22
- 22, 22, 22
- 10, 22, 22
Salaries are 300, 300 and 200. Both queries try to find the second highest salary. What do they return? SQL · Hard
-- Query 1 SELECT MAX(salary) FROM emp WHERE salary < (SELECT MAX(salary) FROM emp); -- Query 2 SELECT salary FROM emp ORDER BY salary DESC LIMIT 1 OFFSET 1;- 200 and 200
- 300 and 300
- 200 and 300
- 300 and 200
The DataFrame has rows for 50 countries, spread randomly.
repartition(10)splits it into 10 chunks, andpartitionBy("country")writes one folder per country. At most, how many files can this create? Spark · Harddf.repartition(10) \ .write.partitionBy("country") \ .parquet(path)- 10
- 50
- 200
- 500
You add a broadcast hint for a dimension table that is 3 GB as Parquet on disk. The job now fails with the driver out of memory. Why? Spark · Hard
- The driver collects the whole table first, and in memory it is several times larger than the compressed Parquet
- Executors lack local disk for the broadcast
- Broadcast joins only work below 10 MB
- Adaptive query execution turns the hint into a shuffle join
To write one output file, you add
.coalesce(1)right after a largegroupBy().agg(). The aggregation itself now runs as one very slow task. Why? Spark · Hard- coalesce(1) merges partitions without a shuffle, so the stage computing the aggregation runs as a single task
- coalesce(1) turns off adaptive query execution
- coalesce(1) forces a broadcast join
- Writing one file means the driver does the work
A Spark streaming query writes each micro-batch to a database with plain INSERTs inside
foreachBatch. A batch crashes right after the INSERT commits, and the query restarts. What happens? Streaming & Kafka · Hard- The checkpoint already marks the batch as done, so it is skipped
- Kafka rolls back the offsets, so nothing is duplicated
- The batch runs again with the same batch id, and the rows are inserted twice
- The query cannot restart from that checkpoint
A Kafka topic has 6 partitions. To process it faster, you grow the consumer group from 6 consumers to 12. Throughput does not change. Why? Streaming & Kafka · Hard
- Brokers throttle groups larger than 6
- Rebalancing never finishes with 12 consumers
- The consumers need a larger fetch size
- Each partition goes to only one consumer in a group, so 6 consumers have nothing to read
A stream counts events in 5-minute windows by event time. The watermark is "latest event time seen minus 10 minutes", and append mode writes a window only once the watermark has passed its end. When is the count for the 12:00–12:05 window written? Streaming & Kafka · Hard
- At 12:05 by the clock
- After 10 minutes of clock time
- In a micro-batch after the stream has seen an event later than 12:15
- Only when the query stops
The orders fact table has one row per order with
total_amount. The product team now wants revenue by product category. What is the right fix? Data modelling · Hard- Join orders to products through a bridge table and sum total_amount
- Store the categories as an array column on each order
- Add an order-line fact table with one row per product in each order, holding that line’s amount
- Split total_amount evenly across the products in the order
The customer dimension is SCD Type 2: each change adds a row with valid-from and valid-to dates. A sale made on 3 March arrives on 10 March, after the customer’s change on 5 March was loaded. Which customer row should the sale point to? Data modelling · Hard
- The current row
- The row that was valid on 3 March
- The customer’s first row
- None for now; fix it in a later run
A streaming job has left a Delta table with millions of small files, and queries spend most of their time planning. Which command fixes the small files? Storage & formats · Hard
- VACUUM
- ANALYZE TABLE
- OPTIMIZE (compaction)
- Adding executors
A daily job builds each event date’s partition at 02:00 the next morning. About 3% of events arrive up to two days late and never make it into the reports. What is the most robust fix? Pipelines & orchestration · Hard
- Append late events to today’s partition
- Run each date two days later
- On every run, rebuild the last three days’ partitions with an overwrite
- Drop events that arrive late
A batch job writes Parquet files straight into the folder readers query. It crashes halfway, and readers see half of the new data. How do you prevent this? Pipelines & orchestration · Hard
- Retry the job until it succeeds
- Write smaller files
- Add executors so it finishes faster
- Write to a staging location and publish in one atomic step, such as a table-format commit
A dedup step keeps one row per order:
ROW_NUMBER() OVER (PARTITION BY order_id ORDER BY updated_at DESC) = 1. Rerunning the job on the same data gives slightly different totals each time. Why? Data quality · Hard- ROW_NUMBER is approximate on large tables
- The window needs a frame clause
- Shuffle partitions change between runs
- Some orders have two versions with the same updated_at, so which one gets row 1 is arbitrary
Upstream renames
amounttoamount_usd. Your pipeline reads withSELECT *and schema merging, keeps running without errors, andamountis NULL for every new row. What would have stopped this? Data quality · Hard- A uniqueness test on order_id
- A data contract: explicit columns, a schema check that fails the run, and a not-null test on amount
- Turning on schema merging everywhere
- More retries
A 50 TB events table is partitioned by
user_id, which has 10 million distinct values. What goes wrong? System design · Hard- Queries filtering by user become slower than on an unpartitioned table
- Millions of folders of tiny files overwhelm the catalog and file listing
- The table can no longer be compressed
- Nothing; high-cardinality partition keys are best
A clickstream of 2 TB per day must be queryable within 5 minutes of each event, and kept for 3 years at low cost. Which design fits? System design · Hard
- Insert every event as a row in Postgres
- Keep all events in Kafka forever and query the topic
- Stream from Kafka into a lakehouse table on object storage in small micro-batches, with regular compaction
- Export to the warehouse once a night
BigQuery charges by bytes scanned. Your bill tripled. Analysts run
SELECT * ... WHERE event_date = ...on a 20 TB events table that is not partitioned, and some addLIMIT 100to save money. What actually cuts the cost? Cloud · Hard- Adding LIMIT 100 to every query
- Buying more compute capacity
- Partitioning the table by event_date, clustering it, and selecting only the needed columns
- Exporting the table to CSV
Spot (preemptible) machines cost about 70% less but can be taken back by the cloud at any time. Running Spark on them, jobs sometimes fail when nodes disappear. How do you make this safe? Cloud · Hard
- Run the driver on spot too, to save more
- Keep the driver on regular (on-demand) machines, run executors on spot, and rely on task retries with idempotent output
- Turn off task retries so failures show quickly
- Use one very large spot machine instead of many small ones
A pipeline builds one small function per column in a loop. What does this print? Python · Hard
fns = [lambda: c for c in ["a", "b", "c"]] print([f() for f in fns])- ['a', 'b', 'c']
- ['c', 'c', 'c']
- ['a', 'a', 'a']
- An error
Other sets
- Set 1 · Junior: 30 questions (15 easy, 12 medium, 3 hard), free
- Set 2 · Junior: 30 questions (14 easy, 13 medium, 3 hard), paid
- Set 3 · Mid-level: 30 questions (7 easy, 16 medium, 7 hard), free
- Set 4 · Mid-level: 30 questions (6 easy, 17 medium, 7 hard), paid
- Set 6 · Senior: 30 questions (0 easy, 9 medium, 21 hard), paid