Big data and data engineering interview questions with answers

Most data engineering interviews ask the same core questions in different words. In this lesson you learn how to answer any technical question (clarify, assume, solve, test, trade off), watch an answer being scored on a rubric, solve the classic top-N-per-group SQL question on real data, debug a slow Spark job aloud, run a 45-minute design round, and practise with a question bank of model answers.

Module 6 · Careers⏱ 40 minBeginner → AdvancedRuns in your browser (Python)3 real-time scenariosSQL practice for your PC9 practice problems
1 The story

Five rounds in two weeks

TiffinGo has opened the full-time data engineer role, and Kabir is one of 14 candidates shortlisted. The recruiter emails the loop: an online test, two technical rounds, a manager round and HR, spread over two weeks. Kabir knows the company’s pipelines better than any outsider, but he has never sat a real interview.

Online testSQL + Python60 minTechnical 1SQL, Python, Spark60 minTechnical 2Pipeline design60 minManagerProject deep-dive45 minHRFit and offer30 minTiffinGo · Data Engineer interview loop Each round tests something different: prepare for all five. myphatshala.in
Kabir

Sir, I’ve worked on these pipelines for months. Why am I nervous about the questions?

Arjun Sir

Because doing and explaining are different skills, Kabir. Interviews test whether you can reason out loud: clarify the question, state assumptions, solve step by step, and discuss trade-offs.

Riya

Are the questions very different at each company?

Arjun Sir

The wording changes, Riya, but the core is stable: SQL with joins and window functions, Python basics, big data concepts, Spark internals, Kafka, data modelling, pipeline design and your own project. This lesson collects the most common ones with model answers.

Kabir

Should I memorise the answers?

Arjun Sir

Understand them. Interviewers ask follow-ups: “why?”, “what if the data is ten times bigger?”, “what breaks first?” Today you’ll practise SQL questions on real data, watch how an interviewer scores an answer, handle a “why is this Spark job slow?” question and design a pipeline in 45 minutes.

2 Definition

The data engineering interview

Formal definition (write this in exams)

A technical interview for data engineering evaluates a candidate’s ability to query and transform data (SQL), write correct code (usually Python), explain distributed data processing and storage concepts, design reliable pipelines and platforms under constraints, and communicate decisions. A typical process includes an online assessment, one or more technical rounds, a design round, a project or managerial discussion and a behavioural/HR round, each assessed against a rubric of correctness, depth, trade-off reasoning and communication.

In simple words

Interviews check whether you can write SQL and Python correctly, explain how big data tools work and why, design a pipeline that won’t break, and talk clearly about your own work. Each round looks at one of these.

Words you’ll meet in this lesson

Online assessmentA timed test (SQL, Python, multiple choice) used to shortlist candidates.
Live codingSolving a problem while sharing your screen and explaining your thinking.
Design roundDesigning a pipeline or data platform for a scenario, discussing trade-offs.
RubricThe criteria an interviewer scores: correctness, depth, communication, trade-offs.
Follow-upA deeper question building on your answer: “what if the data were 10× bigger?”
Clarifying questionA question you ask before solving, to confirm requirements and edge cases.
STARSituation, Task, Action, Result: structure for behavioural answers.
Bar raiserAn interviewer from another team whose job is to keep the hiring standard high.

Interview preparation at three levels

Pick your level. New to this? Start at Beginner and climb.

Beginner Fresher: the must-knows

  • SQL: joins (inner, left, full, self), GROUP BY with HAVING, subqueries, window functions (ROW_NUMBER, RANK, DENSE_RANK, LAG, LEAD, running totals), deduplication.
  • Python: lists, dicts, sets, string handling, file reading, functions, exceptions, comprehensions, simple algorithms (counting, grouping, sorting).
  • Concepts: 5 Vs, batch vs streaming, OLTP vs OLAP, ETL vs ELT, data lake vs warehouse vs lakehouse, row vs columnar formats.
  • Your project: explain it in 2 minutes with architecture, scale, one hard problem and results.

Intermediate 1–3 years: depth and trade-offs

  • Spark: driver and executors, lazy evaluation, transformations vs actions, narrow vs wide, shuffles, partitions, broadcast joins, skew, caching, AQE.
  • Kafka and streaming: topics, partitions, offsets, consumer groups, delivery semantics, watermarks and late data.
  • Modelling and warehousing: star vs snowflake schema, facts and dimensions, slowly changing dimensions (SCD type 1 and 2), partitioning and clustering.
  • Pipelines: Airflow DAGs, idempotency, backfills, incremental loads, data quality checks, CDC.

Advanced Senior: design and ownership

  • System design: requirements, estimates, architecture, storage and processing choices, failure handling, cost and governance, in a structured 45 minutes.
  • Distributed systems: CAP, consistency, replication, exactly-once end to end, schema evolution, small-files problems.
  • Operations: SLAs, observability, on-call, incident post-mortems, cost optimisation.
  • Leadership: design reviews, mentoring, disagreeing constructively, data contracts across teams.

Exam tip: For any interview question: clarify (inputs, scale, edge cases), state assumptions, answer step by step, give a small example, then add trade-offs or limits. This structure also earns full marks in long-answer exam questions.

3 Types and ways to use it

Interview rounds and what they test

RoundWhat is testedHow to prepare
Online assessmentSQL queries, Python problems, MCQs on conceptsDaily SQL practice; timed Python problems on lists, dicts, strings
Technical: SQL and codingJoins, window functions, deduplication; Python data handlingSolve aloud; test with edge cases (NULLs, ties, empty input)
Technical: big data conceptsSpark internals, Kafka, file formats, partitioning, warehousesExplain each concept with a picture and an example from your project
Design roundAn end-to-end pipeline or platform for a scenarioPractise a fixed structure: requirements → estimates → design → failures → cost
Project / manager roundOwnership, depth, decisions, collaborationPrepare a 2-minute project story and 5 STAR stories
HR roundMotivation, expectations, notice period, culture fitResearch the company; be honest and specific

What interviewers score

Correctness

Does the query or code give the right answer, including edge cases such as NULLs, ties and duplicates?

Right

Depth

Can you explain why it works and what happens underneath (shuffles, partitions, offsets)?

Why

Trade-offs

Do you compare options and pick one for stated reasons (cost, latency, simplicity)?

Judgement

Communication

Do you clarify, think aloud, structure the answer and accept hints well?

Clarity

When stuck, say what you know and reason towards the rest: “I haven’t used Iceberg, but it is a table format like Delta, so I’d expect snapshots and ACID commits…”. Interviewers reward honest reasoning far more than confident guessing.

4 Step by step

How to answer any technical question

  1. Clarify the question

    “Top orders per city: should ties share a rank? Should duplicate rows count once? Any date range?”

    Two or three clarifying questions show care and often reveal the edge case the interviewer is waiting for.
  2. State assumptions and scale

    “I’ll assume order_id is unique after deduplication, and the table has around 10 crore rows partitioned by date.”

    Assumptions make your answer checkable and set up good follow-ups.
  3. Solve simply first

    rows = [("Pune", 900), ("Pune", 450), ("Pune", 320), ("Thane", 610)]
    best = {}
    for city, amt in rows:
        best[city] = max(best.get(city, 0), amt)
    print(best)
    {'Pune': 900, 'Thane': 610}
    Get a correct, simple solution, then improve it. A working brute-force answer beats an unfinished clever one.
  4. Test with edge cases

    Walk through NULL amounts, ties, a city with one order and an empty table. Fix anything that breaks.

    Interviewers note whether you test without being asked.
  5. Discuss scale and trade-offs

    “On 10 crore rows I’d filter by date partition first; in Spark, this window needs a shuffle by city, and a hot city could cause skew.”

    Connecting a small answer to big data behaviour is what separates data engineers from general developers.
  6. Summarise

    End with one sentence: what you did, its complexity or cost, and what you’d do with more time.

    A clean summary leaves a strong final impression.
5 See it happen

One answer: what Kabir says, and how it is scored

Step through the six frames. Left: Kabir’s answer. Right: the interviewer’s rubric.

What Kabir says, and what the interviewer notes 6 steps
What you see Interviewer: “What is a shuffle in Spark,and why should we care?”Kabir: “Before I answer, may I relate it to aGROUP BY on our orders table?”“A shuffle moves rows between executors sothat rows with the same key end up together.GROUP BY city needs all Pune rows in one place.”“It writes to disk and sends data over thenetwork, so it’s often the slowest stage.In our job it was 70% of the runtime.”“To reduce it: filter and select columns early,broadcast small tables in joins, fix skewed keys,and tune spark.sql.shuffle.partitions or use AQE.”“So: necessary for wide operations, expensive,and the first place I look when a job is slow.” myphatshala.in
Behind the screen CorrectnessDepthTrade-offsCommunicationA core Spark question. Strong answers relate it to real work.CorrectnessDepthTrade-offsCommunicationAsking to anchor on an example: good communication.CorrectnessDepthTrade-offsCommunicationCorrect definition with a concrete example.CorrectnessDepthTrade-offsCommunicationExplains why it is costly, with a real number: depth.CorrectnessDepthTrade-offsCommunicationSeveral ways to reduce it, each with a reason: trade-offs.CorrectnessDepthTrade-offsCommunicationClear summary. Likely a “strong hire” signal for this question. myphatshala.in
6 Real-world use

Real-time scenarios and a question bank

Three live scenarios: a SQL round with real query output (from the program below), a “why is this Spark job slow?” question, and an advanced 45-minute design round. Then a question bank with model answers.

Real-time scenario 1

The SQL round: top 2 orders per city

The results come from the program in “Run it on your PC” below, which runs five classic SQL questions on a small orders table. Watch the most common window-function question solved step by step.

SQL interview 5 steps
Animated example -- Top 2 orders per city-- Clarify: ties? duplicates?result“Top 2 orders per city.” Kabir first asks:do ties share a rank? Are there duplicate rows?SELECT DISTINCT order_id, city, amountFROM ordersresult8 rows → 7O2 was loaded twiceStep 1: remove the duplicate O2 rowthat a retry loaded twice.DENSE_RANK() OVER ( PARTITION BY city ORDER BY amount DESC) AS rnkresultPune O6 900 1Pune O2 450 2Pune O1 320 3Thane O3 610 1Thane O5 610 1Step 2: rank within each city.DENSE_RANK gives ties the same rank.SELECT ... FROM (...)WHERE rnk <= 2ORDER BY city, rnkresultNashik O7 200 1Pune O6 900 1Pune O2 450 2Thane O3 610 1Thane O5 610 1Step 3: keep ranks 1 and 2. Thane has a tie,so both 610 orders are rank 1.-- ROW_NUMBER: exactly 2-- RANK: 1,1,3 (gaps)-- DENSE_RANK: 1,1,2resultknow all threeand when to useeach oneFollow-up: “What if you used ROW_NUMBER?”Each ranking function treats ties differently. myphatshala.in
Real-time scenario 2

“Why is this Spark job slow?”

This is one of the most common data engineering interview questions. Strong candidates don’t guess; they describe how they would find evidence. Watch the reasoning.

Spark troubleshooting 5 steps
Animated example Stage 4 tasks (seconds), from the Spark UItask 140task 242task 338task 441task 539task 643task 740task 82400“The nightly job went from 20 min to an hour.Why?” Kabir opens the Spark UI first.Stage 4 tasks (seconds), from the Spark UItask 140task 242task 338task 441task 539task 643task 740task 82400One task takes 2,400 s while others take 40 s.Classic sign of data skew.Stage 4 tasks (seconds), from the Spark UItask 140task 242task 338task 441task 539task 643task 740task 82400Check key counts: a test merchant ID has30% of all rows, all sent to one partition.Stage 4 tasks (seconds), from the Spark UItask 160task 262task 358task 461task 559task 663task 760task 864Fixes: filter test data, salt the hot key, orenable AQE skew-join handling.Stage 4 tasks (seconds), from the Spark UItask 160task 262task 358task 461task 559task 663task 760task 864Stage now ~64 s. Answer structure: symptom →evidence → cause → fix → prevention. myphatshala.in
Real-time scenario 3 · advanced

A 45-minute pipeline design round

Design rounds reward structure more than buzzwords. Watch how Kabir spends 45 minutes on a real-time order analytics design.

System design 5 steps
Animated example 0–5 minRequirements5–10Estimates10–25Architecture25–35Failures35–45CostDashboard within 1 minute · 3 years historyexact daily revenue for finance · 6 cities“Design real-time order analytics for TiffinGo.”Ask: latency? users? history? correctness needs?0–5 minRequirements5–10Estimates10–25Architecture25–35Failures35–45Cost50,00,000 ÷ 86,400 ≈ 58 per second× 5 lunch peak ≈ 300 per secondEstimate: 50 lakh orders/day ≈ 58/s avg,~300/s peak at lunch; ~5 GB/day of events.0–5 minRequirements5–10Estimates10–25Architecture25–35Failures35–45CostAppeventsKafkaSparkstreamingDeltalakeBIArchitecture: events → Kafka → Spark streaming→ Delta bronze/silver/gold → dashboards.0–5 minRequirements5–10Estimates10–25Architecture25–35Failures35–45CostAppeventsKafkaSparkstreamingDeltalakeBIFailures: idempotent writes, checkpoints, lateevents via watermarks, nightly batch reconciliation.0–5 minRequirements5–10Estimates10–25Architecture25–35Failures35–45CostAppeventsKafkaSparkstreamingDeltalakeBICost and governance: partitions, auto-scaling,PII masking, owners, quality checks. Summarise. myphatshala.in

Question bank with model answers

Open each question only after answering it aloud yourself. Model answers are short; in an interview, add an example from your own work.

SQL

Difference between WHERE and HAVING?

WHERE filters rows before grouping; HAVING filters groups after aggregation, so it can use aggregates like COUNT(*) > 1.

ROW_NUMBER vs RANK vs DENSE_RANK?

For ties on 610, 610, 450: ROW_NUMBER gives 1, 2, 3 (arbitrary order for ties); RANK gives 1, 1, 3 (gaps); DENSE_RANK gives 1, 1, 2 (no gaps).

How do you remove duplicate rows but keep one?

Use ROW_NUMBER() OVER (PARTITION BY the key columns ORDER BY a tiebreaker such as load time DESC) and keep rows where the number is 1; or SELECT DISTINCT when entire rows are identical.

INNER vs LEFT vs FULL OUTER JOIN?

INNER keeps matching rows only; LEFT keeps all rows from the left table with NULLs where there is no match; FULL OUTER keeps all rows from both sides.

What happens to NULLs in COUNT, SUM and joins?

COUNT(column) and SUM ignore NULLs, COUNT(*) counts rows; NULL never equals NULL, so NULL keys don’t match in joins unless handled explicitly.

How would you find the second highest salary?

SELECT MAX(salary) FROM t WHERE salary < (SELECT MAX(salary) FROM t), or DENSE_RANK() and filter rank = 2. Ask how ties should be handled.

Python

List vs tuple vs set vs dict?

List: ordered, mutable. Tuple: ordered, immutable (usable as a dict key). Set: unordered unique items with fast membership. Dict: key-value pairs with fast lookup by key.

How do you read a 20 GB file that doesn’t fit in memory?

Stream it line by line or in chunks (a for loop over the file, pandas read_csv with chunksize, or pyarrow batches), process each chunk and aggregate; or use Spark or DuckDB.

What is a generator and why use it in data pipelines?

A function that yields values one at a time with yield, keeping memory low because items are produced lazily, ideal for streaming through large files or API pages.

How do you handle errors in a pipeline script?

Catch specific exceptions, log context (file, row, ID), retry transient errors with backoff, send bad records to a quarantine location and fail loudly on unexpected errors rather than silently continuing.

Count word frequency in a text file.

Use collections.Counter over words from each line: Counter(w for line in f for w in line.lower().split()).most_common(10).

Big data concepts

Explain the 5 Vs.

Volume (size), Velocity (speed of arrival), Variety (structured, semi-structured, unstructured), Veracity (quality and trust) and Value (business benefit). Give an example for each from a real system.

ETL vs ELT?

ETL transforms data before loading into the target; ELT loads raw data first and transforms inside a scalable warehouse or lakehouse, which is common in the cloud because storage is cheap and engines are powerful.

Data lake vs data warehouse vs lakehouse?

A lake stores raw files of any type cheaply; a warehouse stores structured, modelled data for fast SQL; a lakehouse adds table formats (Delta, Iceberg, Hudi) to lake storage for ACID transactions, schema enforcement and warehouse-like performance.

Why are columnar formats like Parquet faster for analytics?

Queries read only the needed columns, similar values compress well, and min/max statistics let engines skip row groups, so far less data is read.

What is partitioning and what is the small-files problem?

Partitioning splits data by a column (often date) so queries skip irrelevant folders. Too many tiny files, from over-partitioning or frequent small writes, slow down listing and reading; fix with compaction and sensible partition choices.

Explain the CAP theorem.

During a network partition a distributed system must choose between consistency (every read sees the latest write) and availability (every request gets a response). Payments favour consistency; feeds and counters often favour availability.

Spark

Driver vs executor?

The driver plans the job and schedules tasks; executors on worker nodes run tasks on partitions and hold cached data.

Transformations vs actions; what is lazy evaluation?

Transformations (select, filter, join) build a plan; actions (count, write, collect) trigger execution. Laziness lets Spark optimise the whole plan, for example pushing filters down.

Narrow vs wide transformations?

Narrow ones (map, filter) work within a partition; wide ones (groupBy, join, distinct) need a shuffle to bring rows with the same key together.

repartition vs coalesce?

repartition does a full shuffle to any number of partitions with even sizes; coalesce reduces partitions by merging without a full shuffle, cheaper but possibly uneven.

What is a broadcast join?

Sending a small table to every executor so the big table can be joined without shuffling it. Useful when one side fits comfortably in memory.

How do you handle data skew?

Find hot keys in the Spark UI and key counts, then filter bad keys, salt hot keys, broadcast the small side, or enable adaptive query execution’s skew handling.

cache vs persist?

cache stores a DataFrame in memory (default storage level); persist lets you choose levels such as memory and disk. Use it only when the result is reused several times, and unpersist after.

Kafka and streaming

Topic, partition, offset, consumer group?

A topic is a named stream; partitions split it for parallelism and ordering within a partition; an offset is a message’s position; consumers in a group share partitions, so each message is processed by one consumer in the group.

At-most-once, at-least-once, exactly-once?

At-most-once may lose messages; at-least-once may duplicate them; exactly-once means each message affects results once, achieved with idempotent producers, transactions or idempotent sinks plus checkpoints.

What are watermarks?

A threshold for how late event-time data may arrive; events older than the watermark are dropped or handled separately so windowed state can be finalised and freed.

How does Kafka keep messages in order?

Order is guaranteed only within a partition, so events that must stay ordered (for example, for one order ID) use the same key, which maps to the same partition.

Batch or streaming for a daily finance report?

Batch: it needs complete, reconciled data once a day. Streaming fits fraud alerts or live dashboards where seconds matter.

Data modelling and pipelines

Star vs snowflake schema?

A star schema has a central fact table joined directly to denormalised dimension tables; a snowflake normalises dimensions into more tables. Star is simpler and faster for BI.

What is a slowly changing dimension type 2?

A dimension that keeps history by inserting a new row with valid_from/valid_to (or is_current) when an attribute such as a customer’s city changes, instead of overwriting it (type 1).

What makes a pipeline idempotent?

Running it twice for the same input gives the same result: overwrite a date partition or MERGE on keys instead of blindly appending.

Full load vs incremental load vs CDC?

Full reloads everything; incremental loads only new or changed rows using a watermark column; CDC reads the database’s change log to capture inserts, updates and deletes reliably.

What is a backfill?

Re-running a pipeline for past dates, for example after a bug fix or a new column. Airflow supports it when tasks are parameterised by date and idempotent.

Behavioural and HR

Tell me about a time something broke in production.

Use STAR: the situation (dashboard 100× wrong), your task, the actions (traced lineage, found a unit change, fixed and backfilled, added a check and a contract) and the result, plus what you learnt.

Tell me about a disagreement with a teammate.

Show that you listened, used data or a small experiment to decide, and kept the relationship good. Avoid blaming.

Why data engineering?

Connect a real experience (building a pipeline others relied on) to what you enjoy: reliable systems, scale and enabling decisions.

Where do you see yourself in a few years?

Be honest and role-related: deeper expertise in streaming or platforms, owning systems end to end, mentoring others.

7 Run the code

Practise SQL interview questions in your browser

Python’s built-in sqlite3 runs real SQL. The program creates a small orders table with a duplicate row and answers a classic question. Then try the challenges: deduplication, ranking functions, running totals, LAG and a Python counting question.

import sqlite3
db = sqlite3.connect(":memory:")
db.executescript("""
CREATE TABLE orders (order_id TEXT, city TEXT, amount INT);
INSERT INTO orders VALUES ('O1','Pune',320), ('O2','Pune',450), ('O3','Thane',610),
  ('O4','Pune',150), ('O5','Thane',610), ('O6','Pune',900), ('O2','Pune',450);
""")
# Q: total revenue per city, counting each order once
sql = """SELECT city, SUM(amount) FROM (SELECT DISTINCT * FROM orders)
         GROUP BY city ORDER BY city"""
for row in db.execute(sql):
    print(row)
('Pune', 1820) ('Thane', 1220)
  • sql = """SELECT city, SUM(amount) FROM (SELECT DISTINCT * FROM orders)Deduplicate first: O2 was loaded twice and would inflate Pune’s total.
  • db = sqlite3.connect(":memory:")An in-memory database: nothing to install, perfect for practice.

Run it on your PC: five classic SQL interview questions

This program builds an orders table (with a duplicate row, as real data often has) and runs five classic questions: second highest amount, duplicates, top 2 per city with ties, a running total and customers active on several days. Try writing each query yourself before reading the solution. Save it as sql_interview.py.

Second highest, duplicates, top-N, running total, repeat customers

"""Five classic data engineering SQL interview questions, solved and run
on a small orders table with SQLite (built into Python, nothing to install)."""
import sqlite3

db = sqlite3.connect(":memory:")
db.executescript("""
CREATE TABLE orders (order_id TEXT, customer TEXT, city TEXT, amount INTEGER, order_date TEXT);
INSERT INTO orders VALUES
 ('O1','Asha','Pune',320,'2026-10-01'), ('O2','Ravi','Pune',450,'2026-10-01'),
 ('O3','Meera','Thane',610,'2026-10-02'), ('O4','Asha','Pune',150,'2026-10-02'),
 ('O5','Kiran','Thane',610,'2026-10-03'), ('O6','Ravi','Pune',900,'2026-10-03'),
 ('O7','Zoya','Nashik',200,'2026-10-03'), ('O2','Ravi','Pune',450,'2026-10-01');
""")

questions = {
    "Q1. Second highest order amount (handles ties)":
        "SELECT MAX(amount) FROM orders WHERE amount < (SELECT MAX(amount) FROM orders)",
    "Q2. Find duplicate order_ids":
        "SELECT order_id, COUNT(*) AS n FROM orders GROUP BY order_id HAVING COUNT(*) > 1",
    "Q3. Top 2 orders per city (window function, ties share a rank)":
        """SELECT city, order_id, amount, rnk FROM (
             SELECT DISTINCT order_id, city, amount,
                    DENSE_RANK() OVER (PARTITION BY city ORDER BY amount DESC) AS rnk
             FROM orders) WHERE rnk <= 2 ORDER BY city, rnk""",
    "Q4. Running total of revenue by day":
        """SELECT order_date, SUM(amount) AS day_total,
                  SUM(SUM(amount)) OVER (ORDER BY order_date) AS running_total
           FROM (SELECT DISTINCT * FROM orders) GROUP BY order_date ORDER BY order_date""",
    "Q5. Customers who ordered on 2 or more different days":
        """SELECT customer, COUNT(DISTINCT order_date) AS days FROM orders
           GROUP BY customer HAVING COUNT(DISTINCT order_date) >= 2""",
}
for title, sql in questions.items():
    print(title)
    for row in db.execute(sql):
        print("   ", row)

# In a terminal:  python sql_interview.py
Q1. Second highest order amount (handles ties) (610,) Q2. Find duplicate order_ids ('O2', 2) Q3. Top 2 orders per city (window function, ties share a rank) ('Nashik', 'O7', 200, 1) ('Pune', 'O6', 900, 1) ('Pune', 'O2', 450, 2) ('Thane', 'O3', 610, 1) ('Thane', 'O5', 610, 1) Q4. Running total of revenue by day ('2026-10-01', 770, 770) ('2026-10-02', 760, 1530) ('2026-10-03', 1710, 3240) Q5. Customers who ordered on 2 or more different days ('Asha', 2) ('Ravi', 2)

Recorded from a real run with Python 3.13 and its built-in SQLite (window functions need SQLite 3.25 or newer, included in all recent Python versions). The same SQL works in PostgreSQL, Spark SQL, BigQuery and most warehouses with small changes.

8 Line by line

Deduplicating records, step by step

A favourite interview task in Python: keep the latest record per order ID. Watch the dictionary keep only the newest version of each order.

Worked examples: real problems, solved and traced in memory

Four interview problems across SQL, Python and Spark thinking. Each runs live and is traced.

Example 1BeginnerPython · strings

Is it a palindrome? (ignore case and spaces)

Problem statement

A common warm-up in online tests. Check whether a phrase reads the same forwards and backwards, ignoring case and spaces.

Input
"Nitin", "Data Engineer"
Expected output
Nitin -> True
Data Engineer -> False

Approach

  1. Lower-case and remove spaces.
  2. Compare the string with its reverse.
  3. Test both examples.

Solution: run it live

What happens in memory, step by step

Recorded from a real Python run: press Next to execute one line at a time. Watch variables change in each frame, and lists and dictionaries (numbered #1, #2 …) fill up as objects.

Example 2IntermediateSQL · consecutive days

Customers who ordered on consecutive days

Problem statement

Using LAG, find customers who placed orders on two consecutive days.

Input
(customer, day number)
Expected output
[('Asha',), ('Zoya',)]

Approach

  1. Deduplicate to one row per customer per day.
  2. LAG(day) over each customer’s days gives the previous day.
  3. Keep rows where day − previous = 1.

Solution: run it live

What happens in memory, step by step

Recorded from a real Python run: press Next to execute one line at a time. Watch variables change in each frame, and lists and dictionaries (numbered #1, #2 …) fill up as objects.

Example 3IntermediatePython · grouping

Average order value per city without pandas

Problem statement

Given (city, amount) pairs, compute the average per city using only the standard library, as many interviews require.

Input
5 (city, amount) pairs
Expected output
{'Pune': 556.7, 'Thane': 405.0}

Approach

  1. Keep a running sum and count per city in dictionaries.
  2. Divide at the end.
  3. Round for display.

Solution: run it live

What happens in memory, step by step

Recorded from a real Python run: press Next to execute one line at a time. Watch variables change in each frame, and lists and dictionaries (numbered #1, #2 …) fill up as objects.

Example 4AdvancedSpark thinking · skew

Detect a skewed key before the job runs

Problem statement

Before a big join, sample the keys. Flag any key holding more than 10% of rows, and estimate how many salt buckets would bring it to about the average partition size.

Input
key counts, 50 partitions
Expected output
M001: 30% of rows -> salt into 15 buckets
TEST: 60% of rows -> salt into 30 buckets

Approach

  1. Total rows and each key’s share.
  2. Flag keys above 10%.
  3. Salt buckets ≈ key rows ÷ average rows per partition.

Solution: run it live

What happens in memory, step by step

Recorded from a real Python run: press Next to execute one line at a time. Watch variables change in each frame, and lists and dictionaries (numbered #1, #2 …) fill up as objects.

9 Quiz and revision

Check yourself

Quick revision

Lesson 6.3 in one screen

  • Answer structure: clarify → assume → solve simply → test edge cases → scale and trade-offs → summarise.
  • SQL must-knows: joins, WHERE vs HAVING, dedup with ROW_NUMBER, ROW_NUMBER/RANK/DENSE_RANK, LAG/LEAD, running totals.
  • Python: dicts/sets/Counter, chunked file reading, generators, error handling, no-pandas grouping.
  • Spark: driver/executors, lazy evaluation, narrow vs wide, shuffles, broadcast joins, skew, repartition vs coalesce.
  • Kafka: partitions, offsets, consumer groups, ordering per key, delivery semantics, watermarks.
  • Modelling: star schema, facts/dimensions, SCD 1 vs 2; pipelines: idempotent, incremental, CDC, backfills.
  • Design rounds: requirements, estimates, architecture, failures, cost and governance; STAR for behavioural.

Interview and viva questions

What are the most common data engineering interview questions?

SQL problems with joins, aggregation and window functions (top-N per group, duplicates, running totals); Python data-handling questions; concepts such as ETL vs ELT, data lake vs warehouse, Parquet and partitioning; Spark questions on shuffles, partitions, joins and skew; Kafka basics; data modelling with star schemas and slowly changing dimensions; a pipeline design scenario; and questions about your projects and behaviour.

How should I prepare for a data engineering interview in 30 days?

Practise SQL daily (window functions especially), revise Python data structures and file handling, review Spark and Kafka concepts with diagrams, practise two or three design scenarios with a fixed structure, prepare a two-minute project story and five STAR stories, and do mock interviews where you explain your thinking aloud.

What Spark questions are asked in interviews?

Typical questions cover the driver and executors, lazy evaluation, transformations and actions, narrow and wide dependencies, shuffles, partitioning and repartition versus coalesce, broadcast joins, handling data skew, caching, adaptive query execution, file formats and debugging slow or failing jobs using the Spark UI.

How do I answer a system design question for data pipelines?

Clarify requirements (latency, volume, history, correctness, consumers), estimate scale with simple arithmetic, propose an architecture from ingestion to storage, processing and serving, explain failure handling (retries, idempotency, late data, reconciliation), and discuss cost, security and governance, ending with a short summary and possible improvements.

What if I don’t know the answer to an interview question?

Say so honestly, then reason from what you do know, relate it to a similar tool or concept, and describe how you would find out. Interviewers value clear reasoning and honesty over confident guessing.

Practice problems

Interview-style problems in Python and SQL. The last two are business-flavoured design questions.

P1Easy

Reverse words

Print the words of "big data is fun" in reverse order.

Input
"big data is fun"
Expected output
fun is data big
Show solution and explanation
print(" ".join("big data is fun".split()[::-1]))
fun is data big

How it works: Split, reverse the list, join.

P2Easy

Second largest

Print the second largest distinct number in [5, 9, 9, 3, 7].

Input
list
Expected output
7
Show solution and explanation
print(sorted(set([5, 9, 9, 3, 7]))[-2])
7

How it works: Remove duplicates first so a tie for the maximum doesn’t count twice.

P3Easy

Count with HAVING

With SQLite, print the cities with more than 1 order from [Pune, Pune, Thane].

Input
3 rows
Expected output
[('Pune',)]
Show solution and explanation
import sqlite3
db = sqlite3.connect(":memory:")
db.executescript("CREATE TABLE o (c TEXT); INSERT INTO o VALUES ('Pune'),('Pune'),('Thane');")
print(db.execute("SELECT c FROM o GROUP BY c HAVING COUNT(*) > 1").fetchall())
[('Pune',)]

How it works: HAVING filters after grouping.

P4Medium

First non-repeating character

Print the first character that appears only once in "aabbcdc".

Input
"aabbcdc"
Expected output
d
Show solution and explanation
from collections import Counter
s = "aabbcdc"
c = Counter(s)
print(next(ch for ch in s if c[ch] == 1))
d

How it works: Count first, then scan in order.

P5Medium

Merge two sorted lists

Merge [1, 4, 7] and [2, 3, 8] into one sorted list without calling sort.

Input
two sorted lists
Expected output
[1, 2, 3, 4, 7, 8]
Show solution and explanation
a, b, out, i, j = [1, 4, 7], [2, 3, 8], [], 0, 0
while i < len(a) and j < len(b):
    if a[i] <= b[j]:
        out.append(a[i]); i += 1
    else:
        out.append(b[j]); j += 1
print(out + a[i:] + b[j:])
[1, 2, 3, 4, 7, 8]

How it works: The merge step of merge sort; external sorting in big data works the same way.

P6Advanced

Latest status per order

From [("O1",1,"placed"),("O1",3,"delivered"),("O1",2,"shipped")], print the status with the highest version.

Input
versioned records
Expected output
delivered
Show solution and explanation
r = [("O1", 1, "placed"), ("O1", 3, "delivered"), ("O1", 2, "shipped")]
print(max(r, key=lambda x: x[1])[2])
delivered

How it works: The same logic as ROW_NUMBER() ... ORDER BY version DESC = 1, or a MERGE in a lakehouse.

P7Advanced

Sessionise clicks

Click times (minutes) [0, 5, 12, 50, 52, 120]. A new session starts after a gap over 30. Print the number of sessions.

Input
times
Expected output
3
Show solution and explanation
t = [0, 5, 12, 50, 52, 120]
print(1 + sum(1 for a, b in zip(t, t[1:]) if b - a > 30))
3

How it works: Sessionisation is a common streaming and SQL interview problem (LAG + gap rule).

P8Business problem

Estimate for a design round

50 lakh orders a day, 2 KB each, kept 3 years, 3 copies. Print storage in TB.

Input
as given
Expected output
32.9 TB
Show solution and explanation
print(round(50e5 * 2e3 * 365 * 3 * 3 / 1e12, 1), "TB")
32.9 TB

How it works: Quick estimates like this anchor every design discussion.

P9Business problem

Peak throughput

Lunch (12–2 pm) carries 40% of 50 lakh daily orders. Print average orders per second in that window.

Input
40% in 2 hours
Expected output
278
Show solution and explanation
print(round(50e5 * 0.40 / (2 * 3600)))
278

How it works: Peak windows, not daily averages, decide capacity.

Real-world scenario questions (asked in company interviews)

More interview situations to practise. Say your answer aloud first, then open the model answer.

SQL · live codingFresher

“Find customers who ordered on consecutive days.”

An interviewer gives an orders table (customer, order_date) and asks for customers with orders on two consecutive days.

The interviewer is checking: can you use window functions beyond ranking?

Show a strong answer

Deduplicate to one row per customer per day, then use LAG(order_date) OVER (PARTITION BY customer ORDER BY order_date) and keep rows where the difference from the previous date is exactly one day. Mention edge cases: several orders on the same day, time zones, and performance (partition by date range on large tables).

Avoid: self-joining every row with every other row without explaining the cost.

Spark · concepts1–3 years

“Your Spark job fails with OutOfMemory.”

An executor fails with an out-of-memory error during a join.

The interviewer is checking: can you reason from symptoms to causes?

Show a strong answer
  • Check the Spark UI: which stage, how large are partitions, is one task much bigger (skew)?
  • Look for collect() or toPandas() pulling data to the driver.
  • Fixes: more partitions, broadcast only genuinely small tables, salt skewed keys, select fewer columns, avoid caching large unused data, increase executor memory as a last resort.

Avoid: immediately doubling memory without finding the cause.

System design1–3 years

“Design a daily sales pipeline from 200 stores.”

Each store uploads a CSV of sales every night. Head office needs a dashboard by 7 am.

The interviewer is checking: can you structure a batch design with failure handling?

Show a strong answer
  1. Requirements: ~200 files a night, sizes, 7 am SLA, late or missing files.
  2. Land raw files in object storage by date and store (bronze).
  3. Airflow DAG: sensor for files with a deadline, validation and quality checks, Spark or dbt into silver and gold, idempotent overwrite per date.
  4. Alerts for missing stores, quarantine for bad files, backfill support.
  5. Serve gold tables to the dashboard; document owners and definitions.

Avoid: jumping to Kafka and streaming for a once-a-day requirement.

BehaviouralFresher

“What is your biggest weakness?”

Asked in many HR and manager rounds.

The interviewer is checking: can you be honest and show growth?

Show a strong answer

Pick a real, non-critical weakness and show what you are doing about it: “I used to jump into coding before clarifying requirements. After a pipeline I built had to be redone, I now write a one-page design note and confirm it before starting.” Keep it short and specific.

Avoid: a disguised strength like “I work too hard”.