All five rounds of the loop, end to end — SQL, data modeling, ETL and pipeline design, Spark internals and tuning, PySpark, streaming, Snowflake, AWS and the cloud stack, DevOps and MLOps, the system design round that filters senior candidates, the behavioral round that quietly decides offers, and the agentic AI round now showing up in data and platform loops — calibrated to the Indian market: product companies, GCCs, fintech, and FAANG-India.
Most data-engineering interviews test the same spine, whatever the job title on the door: can you write correct SQL under a little pressure, can you model data so it survives change, do you understand what actually happens when a distributed job runs — and can you reason about cost, failure, and recovery like someone who has been paged at 2 a.m. The tools rotate; the reasoning doesn't.
The loop itself is remarkably standardised: five to seven rounds drawn from five domains — SQL, coding, data modeling, pipeline design, and behavioral. What changes between companies is the weighting and which round does the filtering, which is why there's a playbook for each of the top payers. What changes between levels is how much judgement the room expects on top of a working answer.
This guide is built around that spine. It goes deepest exactly where interviews do — the shuffle, Spark's execution model, and performance tuning get three full chapters — because "rewrite it with a broadcast join and explain why" is the question that most often decides the loop. Every chapter pairs a tight explanation with a simulator for the parts you understand faster by turning a dial, worked code you could say out loud, and the interview angle: what they're really probing and what a senior answer sounds like.
Chapters 13 to 16 cover the newer conversation: agentic AI. What makes a system an agent, how tool calling and the agent loop actually work, the harness around the model, RAG and MCP, how to evaluate and trace agents, how to secure them against prompt injection, and the agentic system design round. It's written for data engineers, because most of what makes an agent production-grade (idempotency, checkpoints, contracts, lineage, data-quality gates) is work you already know how to do.
Chapters 17 to 22 cover the platform underneath: Docker and Kubernetes from first principles, EKS and EMR on AWS, Kafka internals and operations, a casebook of production deployment and pipeline failures with their fixes, and the engineering articles from Uber, LinkedIn, Netflix, Airbnb, DoorDash and Pinterest that interviewers expect you to know.
Read it front to back to build the model, or jump to the question bank to drill, and the cheat sheets the night before. Numbers in the simulators are illustrative — shaped to build intuition, not to quote in production.
Try one
The single most important idea in big data is the shuffle — moving records across the network so that every row with the same key lands on the same machine. It's what makes GROUP BY, JOIN, and reduceByKey work, and it's the first thing to blame when a job is slow. Watch keys get routed to their owning partition, then turn on a map-side combine and watch the network traffic drop.
Figure 0.1. Twenty-four records across four map partitions, shuffled so each key lands on one reducer. A map-side combine pre-aggregates locally, so far fewer records cross the wire. Illustrative numbers.
A data-engineering loop is usually four or five conversations wearing different hats. Knowing which hat is on tells you what "good" means in that room.
A SQL screen. Live queries against a small schema — joins, aggregation, window functions, a dedup or a top-N. They are watching whether correct SQL is muscle memory, and whether you notice the NULL and duplicate traps before they do.
A data-modeling / design round. "Model clickstream for analytics." "How would you handle a customer who changes address?" They want grain, keys, slowly-changing dimensions, and the trade-offs you'd make — not a memorized diagram.
A distributed-systems / Spark round. Narrow vs wide transformations, what a shuffle costs, why a job is slow, how you'd fix skew. This is where seniority shows most clearly, and where this guide spends the most time.
A coding round (often PySpark). Implement sessionization, deduplicate keeping the latest, or "optimize this job." Clean, correct, and able to explain the physical plan you just caused.
Platform / behavioral. Orchestration, CI/CD, testing, an incident you owned. Idempotency, backfills, and blast radius are the words they're listening for.
The through-line
Almost every technical question reduces to one of three anxieties: is it correct (NULLs, duplicates, grain), will it scale (shuffle, skew, partitioning), and what happens when it breaks (idempotency, backfills, recovery). When a question feels open-ended, answer along those three axes and you'll sound like someone who has run things in production.
The Indian loop, specifically
Everything above holds for India loops, with four local realities. Screens are usually HackerRank/HackerEarth OAs or platform interviews, and a referral moves your resume further than any portal. If you are crossing from services to product, reframe your experience as problems owned, not tickets closed — the pipeline I owned, the incident I handled, the cost I cut — because that translation is the actual interview. GCC loops speak Azure, product loops speak AWS; know one deeply and map to the other. And your notice period is a negotiating variable from the first recruiter call — have your buyout number ready.
0.2
What senior answers sound like
The gap between a mid and a senior answer is rarely a fact. It's the reflexes wrapped around the fact.
Lead with the trade-off, not the term. "I'd use merge-on-read because writes are frequent and I can schedule compaction" beats naming the feature. Every real answer has a cost; name it before they ask.
Reach for numbers. "That shuffles ~200GB, so at a few hundred MB per task that's roughly a thousand tasks" shows you think in resources, not vibes. Rough is fine; order-of-magnitude reasoning is the skill.
State assumptions out loud. Data volume, cardinality, freshness SLA, batch vs streaming. The interviewer is often waiting to see whether you'll ask.
Know the failure mode. For any design, "here's how this breaks and how I'd know" is the sentence that ends the debate.
Say "it depends" — then resolve it. The phrase is only strong if you immediately name what it depends on and pick a branch.
Throughout the guide, callouts like the one below flag exactly what a question is probing.
Interview angle
When you're asked "how would you make this faster?", never jump to a config flag. Walk the pipeline: how much data moves, where the shuffle is, whether there's skew, whether the join could be a broadcast. The flag (spark.sql.shuffle.partitions, autoBroadcastJoinThreshold) is the last sentence, after the reasoning — not the first.
0.3
How to use this guide
The chapters build in the order interviews probe: SQL (1), data modeling (2), big-data fundamentals (3), then three chapters on Spark — the execution engine (4), performance tuning (5), and the PySpark coding round (6) — then Snowflake & the cloud stack (7) and DevOps & MLOps (8).
Every chapter has the same rhythm: prose you can read on a train, a simulator for the mechanical parts, worked examples in SQL or PySpark, and interview-angle callouts. Two appendices back the chapters: a question bank of the questions themselves with model answers you can rehearse, and cheat sheets — the dense tables (join strategies, window frames, SCD types, warehouse sizes) worth a last glance before you walk in.
Press / anywhere to search every section. Your place is remembered, so "Continue reading" picks up where you left off. Now, chapter 1.
SQL screens rarely test exotic syntax. They test whether you can be trusted with the three things that quietly produce wrong numbers: join fan-out, NULL semantics, and the difference between filtering rows and filtering groups.
Know your joins by what they keep. An INNER JOIN keeps only matches. A LEFT JOIN keeps every left row and pads the right with NULLs when there's no match — which is exactly why the next trap bites.
The classic gotcha
A LEFT JOIN followed by a WHERE on the right table silently becomes an inner join — the WHERE throws away the NULL-padded non-matches. If you meant "keep everyone, and tell me about their orders", the condition belongs in the ON clause, not the WHERE. Getting this right on the whiteboard is a strong senior signal.
NULL is not a value; it's the absence of one.NULL = NULL is not true, it's NULL. So x NOT IN (subquery) returns nothing the moment the subquery contains a single NULL — a bug that has shipped in a thousand pipelines. Prefer NOT EXISTS, which handles NULLs correctly. And remember COUNT(*) counts rows while COUNT(col) skips NULLs — a difference interviewers love.
Semi- and anti-joins are the vocabulary for "does a match exist" without fan-out. EXISTS / IN is a semi-join (keep left rows that have a match, once); NOT EXISTS is an anti-join (keep left rows with no match). Reaching for these instead of a JOIN + DISTINCT shows you understand why the join would have duplicated rows in the first place.
Interview angle
"What's the difference between WHERE and HAVING?" is really "do you know the logical order of operations?" WHERE filters rows before grouping; HAVING filters groups after aggregation. You can't reference COUNT(*) in WHERE, and filtering in HAVING what you could have filtered in WHERE needlessly aggregates rows you'll discard. §1.4 makes the whole order concrete.
1.2
Window functions
If one topic separates people who "know SQL" from people who use it daily, it's window functions. A window function computes across a set of rows related to the current row — without collapsing them the way GROUP BY does. You keep every row and gain a new column computed over its window.
The anatomy is always the same: func() OVER (PARTITION BY … ORDER BY … frame). PARTITION BY splits rows into independent groups; ORDER BY ranks within each; the frame (for aggregates) says how many surrounding rows to include. Play with the pieces:
Figure 1.2. Eight employees across two departments. Switch the function and watch how ROW_NUMBER, RANK, and DENSE_RANK treat the salary tie differently, and how running totals and LAG read within each partition. Illustrative numbers.
The three ranking functions are a favorite because the tie exposes whether you truly know them: ROW_NUMBER gives every row a distinct number (ties broken arbitrarily), RANK gives ties the same number and then skips (1,2,2,4), and DENSE_RANK ties without skipping (1,2,2,3). "Second-highest salary" is a DENSE_RANK() = 2 problem, and knowing why it isn't RANK when there are ties is the whole point of the question.
Frames matter for running aggregates. ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW is a running total; the default frame when you supply ORDER BY is RANGE, which behaves differently around ties — a subtle bug when duplicate order values collapse into one frame. When precision matters, specify ROWS explicitly.
1.3
Patterns they actually ask
A handful of shapes cover most SQL rounds. Recognize the shape and the query writes itself.
Deduplicate, keeping the latest. The canonical ROW_NUMBER pattern — number rows within each key by recency, keep number 1:
WITH ranked AS (
SELECT *,
ROW_NUMBER() OVER (
PARTITION BY user_id
ORDER BY updated_at DESC) AS rn
FROM events)
SELECT * FROM ranked WHERE rn = 1; -- one row per user, newest wins
Top-N per group. Same engine, different filter: ROW_NUMBER() OVER (PARTITION BY category ORDER BY sales DESC) then WHERE rn <= 3. If you want ties included at the boundary, swap to RANK.
Gaps and islands. The one that looks scary and is really a trick: to collapse consecutive runs (of logins, of active days), subtract a ROW_NUMBER from the value itself — consecutive rows share a constant difference, which becomes a group key.
-- consecutive active days collapse into one "island"SELECT user_id, MIN(d) AS start_day, MAX(d) AS end_day
FROM (
SELECT user_id, d,
d - ROW_NUMBER() OVER (
PARTITION BY user_id ORDER BY d) AS grp
FROM activity)
GROUP BY user_id, grp;
Pivoting with conditional aggregation — SUM(CASE WHEN month = 'Jan' THEN amt END) — and running totals with a windowed SUM round out the set. If you can produce these five without hesitation, you'll clear most SQL screens.
Interview angle
When handed a SQL problem, say the shape before you type: "this is a top-N-per-group, so a windowed ROW_NUMBER with a filter." Narrating the pattern proves it's recognition, not luck — and if you've mis-read the problem, the interviewer corrects you before you've written twenty lines.
1.4
The logical execution order
SQL is written SELECT … FROM … WHERE … but it is not evaluated in that order. Almost every "why can't I reference this alias here?" and "why is my WHERE rejecting my window function?" question dissolves once you internalize the real order. Step through it:
Figure 1.4. The logical evaluation order of a query, with row counts at each stage. FROM/JOIN build the row set, WHERE filters rows, GROUP BY collapses them, HAVING filters groups, SELECT computes columns, and only then do ORDER BY and LIMIT run. Illustrative numbers.
Two consequences fall straight out of the order and are asked constantly. You can't use a SELECT alias in WHERE — WHERE runs before SELECT computes it — but you can use it in ORDER BY, which runs after. And window functions can't appear in WHERE, because they're computed in the SELECT phase, after WHERE has already filtered; that's precisely why the dedup and top-N patterns wrap the window in a subquery or CTE and filter in the outer query.
The same order explains why WHERE is cheaper than HAVING for row-level filters: filtering early means fewer rows to group. Push filters down as far as the logic allows — the query planner does this for you when it can, but writing it correctly makes your intent unambiguous.
Every modeling question starts in the same place, and candidates who skip it get lost: what is one row? That's the grain — the precise meaning of a single record in a table. "One row per order line." "One row per user per day." Declaring the grain first is the single highest-leverage habit in modeling, because keys, aggregations, and joins all follow from it, and mixing grains in one table is how double-counting bugs are born.
Facts are the measurements — the rows you sum and count. They're tall, narrow, and mostly numeric: an order, a click, a payment, with foreign keys and additive measures (amount, quantity). Dimensions are the context you slice by — customer, product, date, store — wide, descriptive, and comparatively few rows. The fact says what happened; the dimensions say who, what, where, when.
Facts come in three flavors worth naming in an interview: transaction (one row per event, the default), periodic snapshot (one row per entity per period — daily balances), and accumulating snapshot (one row per process instance, updated as it moves through milestones — an order's ordered/shipped/delivered timestamps). And watch for measures that don't sum across every dimension: a bank balance is semi-additive (you can add balances across accounts but not across days), and a ratio is non-additive. Naming that distinction unprompted marks you as someone who has been burned by it.
Interview angle
"Model X for analytics" is a grain question in disguise. Answer in order: grain ("one row per …"), then the facts (the measures), then the dimensions (the slice-by context), then how the dimensions handle change (§2.3). That sequence is the senior answer — most candidates jump to tables and tangle the grain.
2.2
Star schema, and one big table
The star schema is the default analytical shape: a central fact table surrounded by dimension tables, each joined by a foreign key. It's called a star because the diagram looks like one. Its virtue is that it matches how people query — "revenue (fact) by region (dim) and month (dim)" — and BI tools understand it natively. A snowflake schema normalizes dimensions further into sub-tables; usually not worth the extra joins.
The modern counter-move is the wide table, or "one big table" (OBT): pre-join the facts and dimensions into one denormalized table so queries never join at all. Columnar engines (Snowflake, BigQuery, Spark on Parquet) only read the columns a query touches, so the width is cheap and the missing joins are fast. Toggle between the two shapes:
Figure 2.2. The same sale, modeled as a star (fact + dimension tables joined by keys) and as one wide denormalized row. Star keeps dimensions in one place and small; OBT trades storage and update-complexity for zero-join reads. Illustrative.
The trade-off is exactly the classic one. Star: dimensions live in one place, so a product rename is a one-row update, and storage is lean — but every query joins. OBT: reads are join-free and dead simple for analysts — but a product rename must be restated across millions of fact rows, and the table balloons. The honest interview answer: star (or a Kimball-style dimensional model) as the warehouse core for its maintainability, materialized wide tables on top for the hot query paths. It's not either/or; it's layers.
2.3
Slowly changing dimensions
Dimensions change — a customer moves, a product is recategorized — and how you record that change is the most-asked modeling question there is. These are slowly changing dimensions (SCD), and the "types" are just policies for what to do when an attribute changes. Watch the same customer move from Pune to Bengaluru under each:
Figure 2.3. Customer 42 relocates. Type 1 overwrites (history lost), Type 2 adds a new versioned row (full history), Type 3 keeps a "previous" column (one step of history). Illustrative.
Type 1 overwrites the old value — simple, but history is gone, so a report of "sales by region last year" silently moves last year's sales to the new region. Type 2 is the workhorse: close the old row and insert a new version, with valid_from / valid_to dates and often an is_current flag and a surrogate key per version. History is preserved, and a fact joins to whichever version was current at the time of the event. Type 3 keeps a single "previous value" column — cheap, but only remembers one hop.
Type 2 is where the real interview lives, because the fact join is subtle: you join on the natural key and the event timestamp between valid_from and valid_to — an "as-of" join. And you maintain it with a MERGE:
MERGE INTO dim_customer t
USING staged_updates s
ON t.customer_id = s.customer_id AND t.is_current = trueWHEN MATCHED AND t.city <> s.city THEN-- attribute changedUPDATE SET t.is_current = false, t.valid_to = s.effective_date
WHEN NOT MATCHED THEN-- brand-new or the new versionINSERT (customer_id, city, valid_from, valid_to, is_current)
VALUES (s.customer_id, s.city, s.effective_date, null, true);
(Type 2 via MERGE usually takes two passes — one to expire the current row, one to insert the new version — which many engines express as a multi-clause merge or two statements. The idea to convey is the close-and-insert, not the exact dialect.)
Interview angle
"A customer changes their address — how do you store it?" is a direct SCD-type question. Don't just say "Type 2." Say why: "if analytics needs point-in-time correctness — what region was this customer in when they bought — I need Type 2 so facts join to the version valid at event time. If we only ever care about the current address, Type 1 is fine and cheaper." Tying the choice to a query requirement is the senior move.
2.4
Keys, and modeling for change
A natural key comes from the business (an email, an order number). A surrogate key is a meaningless integer or hash the warehouse assigns. Dimensional models lean on surrogate keys for a specific reason: with SCD Type 2, one natural customer maps to many rows over time, so facts must reference the surrogate key of the specific version current at event time. Surrogates also insulate you from messy or changing source keys and keep fact-table joins as fast integer comparisons.
A conformed dimension is one shared consistently across fact tables — the same dim_date and dim_customer used by orders, returns, and support tickets — so metrics line up across the business and you can compare them on the same axes. Building conformed dimensions is what makes a warehouse feel coherent rather than a pile of unrelated tables.
Two edge cases interviewers use to probe depth. Late-arriving dimensions: a fact shows up referencing a dimension member you haven't loaded yet — you insert a placeholder ("inferred member") and enrich it when the real record lands, so the fact isn't dropped. Late-arriving facts: an event arrives days late and, under SCD Type 2, must join to the dimension version that was current back then, not now — which only works because Type 2 kept the history. Both are really the same lesson: model so that time is a first-class citizen, because data never arrives in a tidy order.
Classic ETL extracts from the source, transforms in a separate compute tier, and loads the finished result into the warehouse. ELT flips the last two: land the raw data first, then transform it inside the warehouse. The industry moved to ELT for a mundane reason — columnar warehouse compute got cheap and elastic enough that transforming in place beat transforming in flight, and keeping the raw landing zone means you can re-derive everything when the business logic turns out to be wrong. Which it always does.
That's the answer interviewers want when they ask "ETL or ELT?" — not a definition, but the trade-off. ELT costs you storage and warehouse cycles and lets messy data in the door; it buys you replayability, because the transform is just code you can re-run against raw data you still have. ETL keeps the warehouse clean and is still right when the transform needs a library the warehouse can't run, when you must drop PII before it ever lands, or when the source is so large that filtering in flight saves real money.
Either way, mature pipelines land in layers, and the vocabulary is worth having: bronze (raw, immutable, append-only, partitioned by load date — an exact record of what the source said), silver (cleaned, deduplicated, typed, conformed — one row per real-world thing), gold (business aggregates and marts the analysts actually query). Databricks calls it the medallion architecture; Kimball-era shops call it staging/core/marts. Same idea: never transform in one hop, and never overwrite the evidence.
The layering is what makes incidents survivable. When a transform bug corrupts gold, you fix the code and rebuild from silver. When silver is wrong, you rebuild from bronze. When bronze is wrong, you genuinely have lost data — which is exactly why bronze is immutable and nobody writes business logic into it.
The through-line
Every layer boundary is a place you can restart from. Design so the expensive, irreversible thing (capturing the source) happens once, and everything downstream is a pure function you can re-run.
Interview angle
"Walk me through a pipeline you've built." Structure the answer as source → landing → cleaning → serving, and name what makes each hop re-runnable. Candidates who list tools ("Airflow, Spark, Snowflake") sound junior; candidates who describe layers and restart points sound like they've been paged.
3.2
Extraction: full, incremental, CDC
How you get data out of the source is the decision that constrains everything downstream, and it comes down to three strategies with very different costs.
Full snapshot. Read the whole table every run. Dead simple, trivially idempotent (you replace everything), and it catches deletes for free. It stops working when the table gets big — you burn source load and pipeline time re-reading rows that didn't change.
Incremental by watermark. Keep a high-water mark — the max updated_at or an auto-increment id from the last successful run — and pull only rows past it. Cheap and simple, but it has two well-known holes: it cannot see hard deletes (a deleted row simply stops appearing, and your target keeps it forever), and it silently misses rows if the source doesn't reliably bump updated_at on every write. Overlap the window slightly (re-pull the last few hours) so rows committed out of order aren't skipped — which is safe precisely because your load is idempotent.
Change data capture. Read the database's own replication log — Postgres WAL, MySQL binlog, typically via Debezium — and stream every insert, update, and delete as an event. CDC captures deletes correctly, imposes almost no query load on the source, and gives you near-real-time freshness with ordering you can trust (log sequence number, not wall-clock time). The cost is operational: you're running connectors, handling schema changes in the stream, managing offsets, and dealing with the initial snapshot-plus-catch-up dance.
The tell
Ask about deletes. A candidate who picks watermark incremental without asking whether the source hard-deletes has just designed a pipeline whose row counts drift from the source forever — and reconciliation questions are a favorite follow-up.
Interview angle
"How would you ingest this table?" is never answered with a tool. Profile the source out loud first: how big, how often does it change, does it have a reliable updated_at, does it hard-delete, can I get log access, how fresh does the consumer need it? The strategy falls out of those answers — and saying so is the signal.
3.3
Loading: append, overwrite, merge
Pipelines get retried. Tasks fail halfway, someone reruns yesterday, a backfill sweeps a month. So the only load pattern that survives production is one where running it twice equals running it once — idempotency. There are three write patterns, and only two of them are safe.
Append is the unsafe one. A rerun writes the same rows again and your counts double. It's fine only for genuinely immutable event logs where you dedupe downstream on an event id.
Overwrite the partition. Write date=2026-08-30 by replacing that partition, not adding to it. A rerun replaces the same partition with the same content, so it converges. This is the default for date-partitioned batch pipelines, and the sentence to have ready is: "I partition by event date and overwrite the partition, so retries and backfills are safe by construction."
Merge (upsert). Match on a business key and update or insert. This is what you use when rows change in place, and it's how CDC lands in the warehouse. The trap interviewers probe: if your source can deliver the same key more than once in a batch, the MERGE is ambiguous and most engines will error or pick arbitrarily. Deduplicate to one row per key first — usually the latest version by log sequence or update time.
MERGE INTO silver.customers t
USING (
SELECT * FROM (
SELECT *, ROW_NUMBER() OVER (
PARTITION BY customer_id ORDER BY lsn DESC) AS rn
FROM bronze.customer_changes
WHERE load_date = '2026-08-30'
) WHERE rn = 1 -- one row per key, latest wins
) s
ON t.customer_id = s.customer_id
WHEN MATCHED AND s.op = 'DELETE'THEN DELETEWHEN MATCHED THEN UPDATE SET *
WHEN NOT MATCHED AND s.op <> 'DELETE'THEN INSERT *
Interview angle
"Your job failed halfway through and you reran it — what happens?" The strong answer names the write pattern, not the orchestrator's retry setting. Say which unit you replace (the partition, or the key), and why a second run converges to the same state.
3.4
Schema drift and data contracts
Sources change without telling you. A product team adds a field, renames a column, widens an integer to a string because someone started writing "N/A" into it. That's schema drift, and it's the most common cause of a pipeline that ran green for months and then quietly produced garbage.
Changes are not equally dangerous, and saying so is the senior move. Additive changes (a new nullable column) are safe — old readers ignore them. Widening a type (int → bigint, adding an enum value) is usually safe. Narrowing or renaming is breaking: consumers reference a name or expect a range that no longer holds. This is exactly the compatibility model behind Avro/Protobuf schema registries, and naming forward- versus backward-compatibility is a strong signal.
The two policies you choose between: schema-on-read with auto-merge (accept whatever arrives, add new columns automatically) keeps the pipeline running but lets bad data in silently; a strict data contract (a declared schema the producer agrees to, validated at the boundary) fails fast and loudly, which is better than fast and wrong. Most real systems do both: auto-merge additive changes at bronze so nothing is lost, and enforce the contract at the silver boundary so breaking changes stop there instead of reaching the CFO's dashboard.
A data contract is more than a schema, and if you can say this part you're ahead of most candidates: it also carries semantics (what the field means), quality guarantees (this is never null, this is unique), freshness SLAs, and an owner — a human who gets paged. The point is to move the failure from "analyst notices numbers look weird three weeks later" to "producer's CI fails on the pull request."
Interview angle
"The upstream team added a column and your job broke — what do you do?" Don't answer with the hotfix. Classify the change (additive/widening/breaking), say where it should have been caught, and propose the contract at the boundary. Then mention the human part: schema changes are a communication failure before they're a technical one.
3.5
Late data, reprocessing, and reconciliation
Data does not arrive in order. A mobile client buffers events offline for two days; a source system posts backdated corrections; an upstream job reruns and restates a week. If your pipeline treats "the day's partition" as final the moment the clock rolls over, all of that lands nowhere.
The standard batch answer is a rolling reprocessing window: every run recomputes not just yesterday but the last N days (7 to 14 is typical), using merge or partition-overwrite so recomputation is free of duplicates. You pick N from measurement — look at the actual distribution of event_time versus load_time and cover the tail you care about. Anything later than N is caught by a periodic full restatement, or accepted as known drift.
Note what makes this possible: partitioning by event time, not ingestion time. If you partition by when the row arrived, a late event lands in today's partition and your "sales on August 30" answer changes depending on when you ask. Partitioning by event time keeps history stable and makes the correction land in the right day — the same reason streaming systems key windows off event time (§8.2).
Reconciliation is the part candidates forget. A pipeline that runs green isn't a pipeline that's correct. Compare row counts and summed measures against the source on a schedule, and alert on drift — this is how you catch the watermark that's been silently skipping rows for a month. When an interviewer asks how you'd know your pipeline is right, "we reconcile counts and control totals back to the source daily" is a far better answer than "we have retries."
Interview angle
Late data is the most reliable follow-up in the ETL round because it separates people who've operated pipelines from people who've built greenfield ones. Have a number ready — "we reprocessed a rolling 7 days because 99.5% of our late events landed inside that window" — since a measured window beats an arbitrary one.
Distributed data processing exists for one blunt reason: the data no longer fits — in memory, on a disk, or in the time budget of a single machine. Once you accept many machines, three facts govern everything that follows, and every performance question in this guide is a consequence of them.
Partitioning. The data is split into chunks, and each machine works on its own chunk in parallel. Throughput scales with the number of partitions — until one of the next two facts stops you.
The network is the enemy. Reading local data is fast; sending data between machines is slow. Every expensive operation in big data is expensive because it moves data across the network. Hold onto this — it explains the shuffle, joins, and skew all at once.
Partial failure is normal. With hundreds of machines, something is always failing. Frameworks survive this by tracking lineage — the recipe to recompute any lost chunk — rather than by never failing.
These three give the two hard problems of the field. Data movement: minimize what crosses the network (partition well, pre-aggregate, broadcast small tables). Data skew: parallelism only helps if the chunks are even — one machine with ten times the data makes the other ninety-nine wait. Nearly every "why is my Spark job slow" answer is one of these two wearing a costume.
4.2
From MapReduce to the DAG
The original model was MapReduce: a map step transforms records independently in parallel, a shuffle groups them by key across the network, and a reduce step aggregates each group. It's still the right mental model for what happens under the hood — map is per-record and cheap, reduce needs the shuffle and is where the cost lives.
MapReduce's fatal flaw was that every step wrote its full output to disk before the next could start, so a multi-step job hammered disk between every stage. Spark's key insight was to keep intermediate data in memory and to model the whole job as a DAG — a directed acyclic graph of transformations — that it can optimize as a unit before running anything. Same map/shuffle/reduce physics; far less disk, and a planner that sees the whole computation.
Two ideas from that DAG matter for interviews and recur through the Spark chapters. First, lazy evaluation: Spark records transformations without executing them, then plans and runs only when an action forces a result (§5.2) — which is what lets it optimize across steps. Second, lineage: because the DAG is the recipe for every partition, a lost partition is recomputed from its inputs rather than checkpointed, which is how Spark tolerates machine failure for free.
The distinction that matters
Transformations split into narrow (each output partition depends on one input partition — map, filter; no data moves) and wide (each output partition depends on many input partitions — groupBy, join, distinct; a shuffle happens). Chains of narrow transformations fuse into a single stage; every wide transformation forces a new stage and a shuffle between them. "Narrow vs wide" is the vocabulary for the entire Spark performance conversation.
4.3
The shuffle
The shuffle is the beating heart of distributed processing and the number-one interview topic in this whole chapter. Whenever an operation needs all records with the same key together — GROUP BY, JOIN, reduceByKey, distinct, ORDER BY — but those records are scattered across machines, the framework must physically move them so each key lands on one machine. That movement is the shuffle.
Mechanically: each map task partitions its output by hash(key) % numPartitions and writes one file per target partition to local disk; each reduce task then fetches its partition's files from every map task across the network, and merges them. Watch keys route to their owning partition, then turn on a map-side combine:
Figure 3.3. Records partitioned by key across four map tasks are shuffled so each key lands on its owning reducer. A map-side combine (Spark's reduceByKey) pre-aggregates locally, so far fewer records cross the network. Illustrative numbers.
The shuffle is expensive on every axis at once — it writes to disk (spill), serializes records, and sends them across the network, then reads and merges on the other side. So the entire performance game is: shuffle less, and shuffle evenly. Shuffle less by pre-aggregating map-side (reduceByKey beats groupByKey precisely because it combines before the network), by broadcasting small tables to avoid the shuffle entirely (§6.2), and by not shuffling data you'll throw away (filter first). Shuffle evenly by fixing skew (§6.3) so one reducer doesn't get all the rows.
Interview angle
"Why is reduceByKey better than groupByKey?" — because groupByKey shuffles every record to the reducer and aggregates there, while reduceByKey combines values map-side first, so only one partial-aggregate per key per partition crosses the wire. Same result, a fraction of the network traffic. Drop the combine toggle in the simulator to see the count jump. This one answer signals that you understand the shuffle, not just its name.
4.4
Batch, streaming, and exactly-once
Batch processes a bounded dataset — all of yesterday's orders — and finishes. Streaming processes an unbounded flow — orders as they happen — and never finishes. The deep difference isn't speed; it's that a stream has no "end," so anything that needs completeness (a daily total, a join across sources) has to reckon with time and lateness explicitly.
That forces three concepts interviewers probe. Event time vs processing time: when the event happened vs when your system saw it — they differ because of network delays and retries, and correct aggregations key off event time. Windowing: since the stream never ends, you aggregate over finite windows (tumbling, sliding, session). Watermarks: a moving threshold that says "I'll wait this long for late data, then finalize the window and drop stragglers" — the knob that trades latency against completeness. (§7.3 makes these concrete in Structured Streaming.)
Then the delivery-guarantee question, asked in nearly every streaming interview. At-most-once: may lose data, never duplicates. At-least-once: never loses data, may duplicate (retries). Exactly-once: the effect is as if each record were processed once — the gold standard, achieved not by magic but by idempotent writes or transactional sinks plus checkpointed offsets, so a replay after failure doesn't double-count. The honest framing: true end-to-end exactly-once requires cooperation from the sink; absent that, you engineer effectively-once with idempotency and dedup keys.
Interview angle
"How do you get exactly-once?" The strong answer names the mechanism, not the buzzword: checkpoint the source offsets with the output atomically, and make the sink idempotent (upsert on a business key) or transactional (two-phase commit). Then the failure story closes itself — "on replay, re-processing the same offsets produces the same keys, and the idempotent write collapses the duplicate." That's §4.1's "what happens when it breaks," applied to streams.
Before tuning Spark you have to see it. A Spark application is one driver coordinating many executors, and almost every performance question maps to some piece of this picture. Click through it:
Figure 4.1. One driver, several executors, each with cores and a fixed memory pool. Tasks are the unit of work; a core runs one task at a time. Illustrative configuration.
The driver runs your main, builds the DAG, and schedules tasks — it does not process the data, but it does collect results, so collect() on a huge dataset OOMs the driver, a favorite gotcha. Each executor is a JVM on a worker node with a set of cores and a fixed memory pool; it runs tasks and caches data. A core is a slot that runs one task at a time, so an executor with 4 cores runs 4 tasks in parallel. A partition is processed by exactly one task — which is the hinge of the whole model: number of tasks that can run at once = total executor cores, and total work = number of partitions. If you have 200 partitions and 50 cores, the work runs in 4 waves.
This is why "how many partitions?" and "how much executor memory?" are the two levers everything else pulls on. Too few partitions and cores sit idle; too many and scheduling overhead dominates; too little memory per task and the job spills or dies. Chapter 5 tunes all of it — but only because this anatomy makes the trade-offs concrete.
5.2
Lazy evaluation
Spark does nothing when you call filter, select, or join. Those are transformations — they just extend the DAG, the recipe. Only an action — count, collect, write, show — forces Spark to actually plan and run. Step through what happens when the action finally fires:
Figure 4.2. Transformations queue lazily; the action triggers Catalyst to parse, analyze, optimize, and pick a physical plan, which is then split into stages and run. Illustrative.
Laziness is not a quirk; it's the whole optimization strategy. Because Spark sees the entire chain before running anything, its Catalyst optimizer can push filters down to the scan (read less), prune unused columns, collapse adjacent projections, and reorder joins — optimizations impossible if each step ran the instant you wrote it. The cost is a debugging surprise: an error in your filter doesn't surface until the count three lines later, because that's when it ran.
The practical consequences show up constantly. Every action re-runs the whole lineage — calling count() then collect() on the same DataFrame reads the source twice unless you cache() (§6.4). And df.explain() prints the physical plan without running the job, which is the single best habit for a Spark interview: "I'd check explain() to confirm the filter pushed down and the join is a broadcast" is a sentence that lands.
Interview angle
"What's the difference between a transformation and an action?" — transformations are lazy and build the DAG (they return another DataFrame); actions trigger execution (they return a value to the driver or write output). The follow-up is always "name some": narrow transformations map/filter/select, wide ones groupBy/join/distinct; actions count/collect/write/take. Then volunteer the consequence — "so multiple actions re-scan unless I cache" — to show you know why it matters.
5.3
Jobs, stages, and tasks
When an action runs, Spark builds a three-level hierarchy that you'll read constantly in the Spark UI. Understanding it is what turns "the job is slow" into "stage 3 is skewed." Build a pipeline and watch it split:
Figure 4.3. A pipeline splits into stages at every shuffle boundary. Broadcasting the small side of the join removes its shuffle — and therefore a whole stage. Illustrative.
The hierarchy is exact. One job per action. Each job splits into stages at every shuffle boundary — a stage is a run of narrow transformations that can execute without moving data, so a new wide transformation ends one stage and starts the next. Each stage runs as a set of tasks, one task per partition, executed in parallel across the cluster's cores. So: actions → jobs, shuffles → stage boundaries, partitions → tasks. Read the Spark UI through that lens and it stops being noise.
This is why reducing shuffles reduces stages, and why broadcasting the small side of a join (§6.2) is such a win — it converts a shuffle join into a shuffle-free one, deleting a stage boundary and the network traffic with it. Flip the broadcast toggle in the simulator and watch a stage disappear. When you can say "this job has three stages because there are two shuffles," you're reading Spark the way its authors intended.
5.4
Memory, and why jobs spill
An executor's memory is not one bucket. Spark's unified memory splits the usable heap between execution memory (for shuffles, joins, sorts, aggregations — the scratch space of computation) and storage memory (for cached/persisted data). They share a pool and borrow from each other: cached blocks can be evicted to make room for a big shuffle, but active execution memory can't be evicted mid-task. There's also a slice of user memory for your objects and a fixed reserved sliver.
When a task needs more execution memory than it can get, it doesn't (usually) crash — it spills to disk: sorts and hash tables overflow to local disk and are merged back, trading speed for survival. A little spill is fine; heavy spill is a top cause of slow jobs, and it almost always traces back to partitions that are too large (so each task's working set doesn't fit) or skew (so one task's does not while others' do). The fix is more, smaller, even partitions — which is exactly chapter 5.
An OutOfMemoryError is the harder failure, and interviewers ask where it strikes. On the executor: a single partition too big to process, a giant groupByKey, or a skewed key — fix with more partitions or skew handling. On the driver: collect() pulling a large result back, or a broadcast bigger than the driver can build — fix by not collecting, or lowering the broadcast threshold. Naming which side OOM'd and why is the difference between guessing and diagnosing.
Common cause
The default spark.sql.shuffle.partitions = 200 is a fixed number regardless of your data size. On 2TB of shuffle it means 10GB per task — instant spill or OOM. On 200MB it means a thousand tiny tasks and pure scheduling overhead. "It's a static default that rarely fits your data; I'd set it so each task handles ~128–200MB, or lean on AQE to coalesce" is the answer that shows you've actually tuned Spark.
5.5
Adaptive Query Execution
For years Spark planned a query once, up front, using estimates — and estimates about data it hadn't read yet were often wrong, which is how you got 200 shuffle partitions on 50MB of data. Adaptive Query Execution (AQE), on by default since Spark 3.2, fixes this by re-planning at runtime: at each shuffle boundary it looks at the actual statistics of the data just produced and adjusts the rest of the plan. It's the highest-leverage "free" performance feature in modern Spark, and a very common interview topic.
Three things AQE does, all worth naming. Coalesce shuffle partitions: it merges the default 200 partitions down to a sensible number based on real output size, curing the small-partition problem automatically. Switch join strategies: if a table turns out to be small enough after filtering, AQE flips a planned sort-merge join into a broadcast join at runtime. Handle skew: it detects oversized partitions and splits them into smaller sub-partitions so one straggler task doesn't hold up the stage (§6.3).
The senior framing is that AQE doesn't make tuning obsolete — it makes the common cases self-correcting, so your attention goes to the structural choices it can't make for you: the data layout, the partitioning key, whether a join should be a broadcast by design. "AQE will coalesce my partitions and catch runtime skew, so I focus on the things it can't see" is exactly the balance an interviewer wants to hear.
Partition count is the master dial of Spark performance, because a partition is a task and a task needs a core (§5.1). Get it wrong in either direction and you pay. Move the sliders and read the verdict:
Figure 5.1. Shuffle data divided by partition count gives per-task size; that size against cluster cores gives the number of waves. The target is even tasks of roughly 128–200MB. Illustrative.
Too few partitions: each task's slice is huge, so tasks spill or OOM, and you can't use all your cores (10 partitions can't fill 50 cores — 40 sit idle). Too many: each task is trivial, and the fixed per-task overhead — scheduling, serialization, launch — dominates the actual work; a million-task job spends its life in bookkeeping. The sweet spot is tasks of roughly 128–200MB, and enough of them to be a small multiple of your total cores so the waves are full and even.
The tools to reach it: repartition(n) does a full shuffle to exactly n even partitions (use when increasing partitions or redistributing skew); coalesce(n) merges partitions without a full shuffle (cheap, but only for reducing count, and it can leave partitions uneven). "Repartition to increase or rebalance, coalesce to shrink cheaply after a heavy filter" is the crisp distinction interviewers want — plus the note that AQE (§5.5) now coalesces shuffle partitions for you automatically.
Interview angle
"repartition vs coalesce?" — repartition triggers a full shuffle and can both increase and decrease partitions, producing even sizes; coalesce avoids a full shuffle by merging existing partitions, only decreases, and may leave them uneven. The tell of a senior answer is the when: "after a big filter that leaves 500 sparse partitions, I coalesce to avoid a needless shuffle; to fix skew or go wider, I repartition."
6.2
Choosing a join
Joins are where shuffles are born and where the biggest wins hide. Spark picks a physical strategy based on the sizes of the two sides; understanding the choice lets you force the right one. Set the table sizes and see what Spark does:
Figure 5.2. When one side is under the broadcast threshold, Spark ships it to every executor and skips the shuffle entirely. When both sides are large, it shuffles both and sort-merges. Illustrative.
Broadcast hash join (BHJ): if one table is small enough (under spark.sql.autoBroadcastJoinThreshold, 10MB by default), Spark sends a full copy to every executor and joins locally — no shuffle of the big table at all. This is the single most impactful join optimization: a large fact joined to a small dimension should almost always be a broadcast. Sort-merge join (SMJ): when both sides are large, Spark shuffles both by the join key, sorts each partition, and merges — correct at any scale, but two shuffles' worth of network and disk. (A shuffle-hash join is a third, rarer option.)
You can force a broadcast with a hint — broadcast(dim_df) or /*+ BROADCAST(d) */ — when you know a table is small but Spark's estimate is stale. But the failure mode is sharp and interviewers test it: broadcast a table that's too big and the driver OOMs building it, or every executor blows its memory holding the copy. Broadcast is for genuinely small tables (dimensions, lookups) — up to low hundreds of MB with tuning, not multi-GB.
Interview angle
"You're joining a 1TB fact table to a 5MB country lookup and it's slow — what's wrong?" The answer they want: the small table probably isn't being broadcast (maybe it's read as a large number of files, or the estimate is off), so Spark is shuffling a terabyte needlessly. Force it with broadcast() and the shuffle vanishes. Bonus points for "I'd confirm in explain() that it says BroadcastHashJoin, not SortMergeJoin."
6.3
Data skew
Parallelism only helps if the work is even. Skew is when one key (or a few) has vastly more rows than the rest, so after the shuffle one task gets a mountain and the others get molehills — and the whole stage waits for that one straggler. It's the most common cause of "99% of tasks finished in seconds, the last one ran for an hour." Crank the skew and apply the fix:
Figure 5.3. A single hot key overwhelms one task. Salting spreads that key across many tasks by appending a random suffix, so the load evens out and the stage finishes in the time of the slowest balanced task. Illustrative.
You diagnose skew in the Spark UI: one task in a stage with a duration and shuffle-read size far above the median. The classic causes are a NULL or default value that dominates a join key, or a genuine power-law (one enormous customer). The fixes, in order of preference: let AQE skew join handling split the hot partition automatically (often enough on its own now); salt the key — append a random suffix (key + "_" + rand(0..n)) to the hot side and explode the other side to match, so one key becomes n keys spread across n tasks; broadcast the other side if it's small enough to sidestep the shuffle entirely; or filter and handle the hot key separately.
Interview angle
"One task runs forever while the rest finish — what's happening and how do you fix it?" Name it as skew, explain the mechanism (one key's rows all hash to one partition/task after the shuffle), then give the ladder: check if AQE skew handling is on, salt the hot key to spread it, or broadcast the other side. Mentioning that a NULL join key is a frequent hidden culprit — because all NULLs hash together — is the detail that signals real experience.
6.4
Caching and persistence
Because every action re-runs the full lineage (§5.2), a DataFrame used more than once is recomputed each time — reading the source and redoing every transformation. Caching breaks that: cache() or persist() materializes the DataFrame after its first computation so later actions reuse it. The rule is simple and interviewers want it stated as a rule: cache only what you reuse — an iterative algorithm, a cleaned DataFrame feeding several outputs, a lookup hit repeatedly. Caching something used once wastes memory you could have given to execution.
cache() is just persist(MEMORY_AND_DISK) — the sensible default that keeps blocks in memory and spills the overflow to disk rather than recomputing. Other storage levels trade memory for CPU or resilience: MEMORY_ONLY (fastest, but recomputes what doesn't fit), DISK_ONLY, and _SER variants that store serialized bytes (smaller, more CPU to read). And caching is itself lazy — the data isn't stored until the next action materializes it. Call unpersist() when you're done to free the memory for the rest of the job.
Cache vs checkpoint
A subtle senior distinction: caching keeps the data and the lineage (if a cached block is lost, Spark recomputes it from the DAG), so it's for speed. Checkpointing writes to reliable storage and truncates the lineage — useful in very long iterative jobs where the DAG itself grows unwieldy or where you want to survive executor loss without recomputation. Most tuning is caching; checkpointing is the rarer, heavier tool.
6.5
UDFs, Arrow, and a tuning checklist
One PySpark-specific trap is asked in nearly every interview: Python UDFs are slow, and you should know exactly why. A plain Python UDF forces Spark to serialize each row out of the JVM, ship it to a Python worker process, run your function, and serialize the result back — row by row — and it's a black box to Catalyst, so no pushdown or optimization crosses it. The order of preference is therefore: built-in Spark SQL functions first (they run in the JVM and optimize), then pandas UDFs (vectorized, Arrow-based) which move data in columnar Arrow batches and run on whole vectors — often an order of magnitude faster than a row-at-a-time UDF — and only a plain Python UDF as the last resort for logic that truly can't be expressed otherwise.
That single rule — avoid Python UDFs; prefer native functions, then vectorized pandas UDFs — earns real credit, because it shows you understand the JVM/Python boundary that defines PySpark's performance. Everything else assembles into a checklist you can recite when asked "how do you tune a Spark job?":
Shuffle less. Broadcast small tables, reduceByKey over groupByKey, avoid needless distinct/re-partitions.
Shuffle evenly. Right-size partitions (~128–200MB), fix skew (salt / AQE), keep tasks a small multiple of cores.
Reuse work. Cache what you read more than once; unpersist when done.
Right-code it. Native functions > pandas UDFs > Python UDFs; DataFrames over RDDs so Catalyst can optimize.
Verify. Read explain() and the Spark UI — confirm pushdown, broadcast, and even task times rather than guessing.
Interview angle
"Walk me through tuning a slow Spark job" is an invitation to show a method, not a grab-bag. Go in order — how much data is read, where the shuffles are, whether joins broadcast, whether tasks are even, what's cached, whether any Python UDFs are in the path — and end with "and I'd confirm each in explain() and the UI." Structure beats trivia; this checklist is the structure.
The PySpark round rewards fluency with the DataFrame API and the reflex to explain the physical plan you just caused. Two warm-ups appear constantly; they're the SQL patterns of §1.3 in DataFrame form.
Deduplicate, keeping the latest. Window by key, order by recency, keep row 1:
from pyspark.sql import Window, functions as F
w = Window.partitionBy("user_id").orderBy(F.col("updated_at").desc())
latest = (events
.withColumn("rn", F.row_number().over(w))
.filter(F.col("rn") == 1)
.drop("rn")) # one row per user, newest wins
Say out loud: "the window forces a shuffle by user_id, so I'd watch for skew if a few users dominate." That one sentence turns a coding answer into a systems answer.
Top-N per group. Identical machinery, boundary filter instead of equality:
w = Window.partitionBy("category").orderBy(F.col("sales").desc())
top3 = (products
.withColumn("rk", F.row_number().over(w))
.filter(F.col("rk") <= 3)) # swap to F.rank() to include ties
If the group count is huge and N is small, mention the optimization: a partial top-N per input partition before the shuffle cuts what crosses the wire — the same "combine map-side" instinct from §4.3.
7.2
Harder drills: sessionization
Sessionization is the classic "harder" PySpark problem: group a user's events into sessions, where a new session starts after a gap of inactivity (say 30 minutes). It tests windows, lag, a cumulative sum, and whether you can compose them — exactly the skills a real pipeline needs.
The trick is a two-window pattern. First, mark where each session begins by comparing each event to the previous one with lag; then take a running sum of those markers to assign a session id:
from pyspark.sql import Window, functions as F
GAP = 30 * 60# 30 minutes, in seconds
w = Window.partitionBy("user_id").orderBy("event_ts")
sessions = (events
# seconds since this user's previous event
.withColumn("prev_ts", F.lag("event_ts").over(w))
.withColumn("gap", F.col("event_ts") - F.col("prev_ts"))
# 1 when a new session starts (first event, or gap too big)
.withColumn("is_new",
((F.col("prev_ts").isNull()) | (F.col("gap") > GAP)).cast("int"))
# running sum of starts = a session id, per user
.withColumn("session_id",
F.sum("is_new").over(w.rowsBetween(Window.unboundedPreceding, 0))))
The pattern generalizes — the same "flag a boundary, cumulative-sum into a group id" idea solves gaps-and-islands, trip segmentation, and streak counting. Naming that it's the DataFrame twin of the §1.3 SQL trick shows you see the shape beneath the syntax.
Interview angle
After you write it, volunteer the performance note: "every step here rides one window partitioned by user_id, so it's a single shuffle by user — good, unless one user has millions of events, in which case I'd watch that partition for skew." Interviewers give sessionization precisely to see whether you'll connect the elegant code to the physical shuffle underneath.
7.3
Structured Streaming
Spark's streaming API treats a stream as an unbounded table that grows, and you write almost the same DataFrame code as batch — the engine incrementalizes it. The interview-relevant pieces are the ones unique to unbounded data: watermarks, windows, and output modes (the §4.4 concepts, made concrete).
counts = (stream
.withWatermark("event_ts", "10 minutes") # wait up to 10 min for late data
.groupBy(
F.window("event_ts", "5 minutes"), # tumbling 5-min windows"country")
.count())
query = (counts.writeStream
.outputMode("append") # emit a window once its watermark passes
.option("checkpointLocation", "s3://…/ckpt") # offsets + state → exactly-once
.toTable("country_counts"))
The watermark is the key knob: it bounds how long the engine keeps window state waiting for stragglers, then finalizes and drops later arrivals — trading latency for completeness. Output modes decide what's emitted each trigger: append (only new, finalized rows — needs a watermark for aggregations), update (rows that changed this trigger), complete (the entire result table every time — only for aggregations, and only when the result is small). And the checkpoint is non-negotiable: it persists source offsets and aggregation state so a restart resumes exactly where it stopped — the mechanism behind the exactly-once story from §4.4.
Interview angle
"How does Structured Streaming avoid double-counting on failure?" — the checkpoint stores the input offsets together with the state, and the sink is idempotent or transactional, so on restart it re-reads from the last committed offset and re-produces the same output without duplicates. Watermarks are the other half of the answer: they let aggregations finalize and bound state so it doesn't grow forever.
7.4
"Optimize this job"
A staple: they show you a working-but-slow script and ask you to make it faster. The skill is diagnosing along §6.5's axes rather than randomly changing flags. Here's the "before" and the reasoning:
# BEFORE — correct, but slow
big = spark.read.parquet("s3://events/") # 2 TB
dim = spark.read.parquet("s3://country_dim/") # 4 MB
j = big.join(dim, "country_code") # shuffles 2 TB (!)
res = j.groupBy("country_name").agg(F.sum("amount"))
res.filter(F.col("country_name") == "India").show() # filter AFTER the work
Three problems, each a chapter: the 4MB dimension isn't broadcast, so a terabyte shuffles needlessly (§6.2); the filter runs after the join and aggregation, so we process everything to keep one country (§1.4 / read-less); and there's no column pruning. The "after":
# AFTER — same result, a fraction of the work
big = spark.read.parquet("s3://events/").select("country_code", "amount")
dim = spark.read.parquet("s3://country_dim/")
res = (big
.join(F.broadcast(dim), "country_code") # no shuffle of the 2 TB side
.filter(F.col("country_name") == "India") # pushdown-friendly, early
.groupBy("country_name").agg(F.sum("amount")))
res.show()
Broadcasting deletes the big shuffle; filtering early (and selecting only needed columns) shrinks what's read and moved. The closing line that wins the round: "I'd run explain() to confirm it now shows BroadcastHashJoin and the filter pushed into the scan, and check the UI for even task times." Method, then verification — never a lone flag.
Batch pipelines read a dataset that sits still. Streaming systems read a log that never ends, and almost everything strange about them follows from that one difference. Kafka is the log most interviews assume, so its model is worth being precise about.
A topic is split into partitions, and a partition is an append-only ordered sequence of records. Producers pick a partition by hashing the record key. Consumers read at their own pace, tracking an offset — a position in the partition — which they commit so they can resume after a restart. Nothing is deleted on read; retention is by time or size, which is why you can replay history simply by rewinding the offset.
Two consequences carry most of the interview weight. First, ordering is guaranteed only within a partition, never across a topic. If you need all events for one user processed in order, they must share a key so they hash to the same partition. Ask any candidate "how do you guarantee ordering?" and the answer "key by entity id" separates the ones who've used Kafka from the ones who've read about it.
Second, in a consumer group each partition is consumed by exactly one consumer. That's how you scale out — but it also caps you: with 12 partitions, a 13th consumer sits idle. Partition count is a capacity decision made up front and awkward to change later, because increasing it rehashes keys to new partitions and breaks per-key ordering across the boundary.
The metric that matters
Consumer lag — latest produced offset minus committed offset — is the single number you watch. Flat lag means you're keeping up; steadily growing lag means your consumers are slower than the producers and you have minutes before the SLA breaks.
Interview angle
"Your consumer lag is growing — debug it." Walk the chain: is it more input (traffic spike, upstream backfill), slower processing (a bad deploy, an external call in the hot path, GC), or fewer working consumers (a crash-loop, or a rebalance storm)? Then the fixes, in order: scale consumers up to the partition count, make the processing cheaper, and only then add partitions.
8.2
Event time, windows, and watermarks
Event time is when the thing happened; processing time is when your system saw it. They diverge because of buffering, retries, network delays, and phones that were in a tunnel. Correct aggregations key off event time — otherwise "sales in the 9 a.m. hour" changes depending on when you run the query, which is not an acceptable property for a metric.
Because the stream never ends, you aggregate over windows: tumbling (fixed, non-overlapping — hourly counts), sliding (fixed size, overlapping — a 5-minute count updated every minute), and session (dynamic, closed by a gap of inactivity — the streaming version of the sessionization problem in §7.2).
That raises the only genuinely hard question in streaming: when is a window done? You can't wait forever, and you can't close instantly or you'll drop the stragglers. The answer is a watermark — the system's assertion that it has probably seen everything up to event time T. Typically watermark = (max event time seen) − (allowed lateness). When the watermark passes the end of a window, the window fires and its state is released.
Which makes allowed lateness a straight trade-off, and naming it as one is the senior signal: a long watermark delay means you catch more late events but results are stale and state is held longer; a short delay gives fresh results and lean state but drops more stragglers. Well-run systems don't discard late arrivals silently — they route them to a side output or a repair path, so the count of dropped-late events is a metric someone can actually look at.
Interview angle
"What happens to an event that arrives an hour late?" The complete answer has three parts: whether the watermark has already passed its window (fires or drops), what you do with it if it's dropped (side output, dead-letter, or a batch repair job), and how you'd pick the lateness bound (measure the arrival-delay distribution, don't guess).
8.3
Delivery semantics and exactly-once
Failures are certain, so the real question is what a replay does to your output. The three semantics are just three orderings of "process" and "commit the offset."
At-most-once: commit the offset first, then process. A crash in between loses the record. Almost never acceptable for data that matters.
At-least-once: process first, commit after. A crash between the two means the record is reprocessed on restart — you never lose data, but you can duplicate it. This is the honest default for most systems.
Exactly-once is the one candidates over-claim. It is not a checkbox; it requires the offset and the output to move atomically. There are exactly two ways to get there, and knowing both is the point of the question. Either the sink is transactional — a two-phase commit tied to checkpoints, which is what Flink and Kafka transactions do — or the sink is idempotent: you write with a deterministic key so replaying produces the same row rather than a second one. The second is far more common in data engineering, because a MERGE on a stable event id collapses the duplicate (§3.3).
The honest framing to say out loud: exactly-once is a property of the whole path, not of the stream processor. Flink can give you exactly-once state, but if it writes to a sink that can't participate in a transaction and can't dedupe, you have at-least-once with extra steps. When the sink can't cooperate, you engineer effectively-once — at-least-once delivery plus a dedupe key — and say so plainly.
Interview angle
Claiming "we had exactly-once" without naming the mechanism is a red flag interviewers actively listen for. Name it: "checkpointed offsets plus a transactional sink," or "at-least-once with idempotent upserts on event_id." The second is not a weaker answer — it's the one most production systems actually run.
8.4
Operating a stream, and picking an engine
Backpressure is what happens when a downstream operator can't keep up: buffers fill, the pressure propagates upstream, and ingestion slows. It's a feature, not a bug — the alternative is unbounded memory growth and a crash. Flink propagates it naturally through its network stack; Spark Structured Streaming bounds intake per micro-batch (maxOffsetsPerTrigger). Either way the visible symptom is rising consumer lag, and the cure is the same triage as any slow stage: find the expensive operator, remove the per-record external call, or scale the parallelism.
State is the thing that quietly kills long-running streaming jobs. Windows, joins, and deduplication all hold keyed state, and state that never expires grows without bound until checkpoints take minutes and recovery takes hours. Every stateful operator needs a retention story — watermark-driven cleanup for windows, explicit TTL for dedupe caches. "How do you keep state bounded?" is a question that filters people who have run a streaming job for more than a week.
Streaming joins deserve one caution. Stream-to-stream joins need both sides buffered within a time bound, so they're expensive and require watermarks on both inputs. Stream-to-table joins (enrich an event from a slowly changing dimension) are cheaper and far more common — and the correctness question interviewers like is which version of the dimension you join to: the one current now, or the one current at event time (§2.3).
On engines, have an opinion and a reason. Flink is true per-event streaming with rich state and timers, the lowest latency, and the default at real-time-heavy shops. Spark Structured Streaming is micro-batch: latency in the hundreds of milliseconds to seconds, but it reuses the DataFrame API and the cluster you already run, which makes it the pragmatic choice when the team is already on Spark. Kafka Streams is a library embedded in your service, not a cluster — right for simple per-event transforms inside an application. The wrong answer is naming a favorite; the right one is tying the choice to latency requirement, state complexity, and what the team already operates.
Interview angle
"Should this be batch or streaming?" is usually a trap worth failing loudly. Streaming costs you always-on infrastructure, state management, and much harder debugging. If the consumer is a dashboard someone reads each morning, batch is the correct engineering answer, and saying so demonstrates judgment rather than enthusiasm.
Contents · Chapter 9 · Snowflake & the cloud stack
9.1
Snowflake architecture
Snowflake's whole design follows from one decision: separate storage from compute. Data lives once in cloud object storage; independent compute clusters (virtual warehouses) read it without owning it. That's why many teams can query the same data at once without fighting for resources, and why you scale compute up for a heavy job and back down without touching the data. Three layers: storage (the data), compute (warehouses), and a cloud services layer (the brain — metadata, query planning, security, transactions).
Underneath, Snowflake stores tables as immutable micro-partitions — small (~50–500MB uncompressed) columnar chunks, created automatically, each carrying metadata about the range of values it holds. Queries get fast through pruning: the services layer reads the min/max metadata and skips every micro-partition that can't contain matching rows — the same idea as Parquet/Iceberg stats pruning, done automatically. How well it prunes depends on clustering — how well-sorted the data is on your filter columns. Toggle clustering and watch pruning change:
Figure 7.1. A range filter against micro-partitions. When data is well-clustered on the filter column, matching rows sit in a few partitions and the rest are pruned; when it's scattered, nearly every partition must be scanned. Illustrative.
This is the core Snowflake performance lever and a common question: a well-clustered table prunes aggressively and scans little; a poorly-clustered one on the same filter scans almost everything. For large tables whose natural load order doesn't match query filters, a clustering key tells Snowflake to keep the data organized on those columns. The parallel to Spark is exact — layout is destiny; pruning is only as good as the correlation between filters and physical order.
9.2
Warehouses and cost
Snowflake bills credits per second that a warehouse runs, and the size sets the burn rate: each T-shirt size doubles the compute and the credit rate (XS = 1 credit/hr, S = 2, M = 4, L = 8, and up). This makes cost reasoning delightfully concrete — and interviewers ask whether you'll scale up or out. Explore it:
Figure 7.2. Doubling warehouse size doubles the credit rate but only speeds up the parallelizable part of the work — so the cost of a single query is roughly flat until the serial fraction dominates, where bigger stops helping. Illustrative.
Because size doubles both speed and price, a perfectly parallel query costs about the same in total credits on any size — it just finishes faster on a bigger one (you pay for fewer seconds at a higher rate). So the honest guidance: scale up (bigger warehouse) for a single heavy, complex query that spills or sorts a lot; scale out (a multi-cluster warehouse that adds more same-size clusters) for many concurrent users, where the problem is queuing, not any one query's size. Add auto-suspend (stop when idle so you stop paying) and the near-instant result cache (an identical query within 24h returns free), and you have Snowflake's cost-control story.
Interview angle
"Scale up or scale out?" — up for one big query (more memory/CPU so it doesn't spill), out for concurrency (more clusters so users don't queue). The nuance that impresses: "because doubling size doubles both speed and rate, sizing up rarely changes the credit cost of a parallel query — it buys latency, not savings — so I size to avoid spilling, enable auto-suspend, and lean on the result and metadata caches to actually cut spend."
9.3
Time travel, clones, streams & tasks
Four Snowflake features come up because they solve real pipeline problems. Time Travel queries a table as it was up to N days ago (AT (OFFSET => -3600) or a timestamp) — undo a bad load, audit a change, recover a dropped table. It's distinct from Fail-safe, a non-configurable 7-day Snowflake-managed recovery window after Time Travel expires; a favorite gotcha is knowing you can self-serve Time Travel but must call support for Fail-safe.
Zero-copy cloning (CREATE TABLE dev CLONE prod) makes an instant, storage-free copy — it only duplicates metadata pointers to the existing micro-partitions, and new storage is used only as the clone diverges. This is how teams spin up full-size dev/test environments from production in seconds without paying for a second copy; explaining why it's free (shared immutable micro-partitions, copy-on-write) is the senior beat.
Streams and Tasks are Snowflake's native CDC-and-schedule pair. A Stream tracks row-level changes to a table (a change-data-capture cursor: what's been inserted/updated/deleted since you last read it); a Task runs SQL on a schedule or dependency. Together — a Task that consumes a Stream and MERGEs changes downstream — they build incremental pipelines entirely inside Snowflake, no external orchestrator required. Pair that with Snowpipe (continuous micro-batch file ingestion) and you can describe an end-to-end near-real-time load without leaving the platform.
9.4
Managed data integration
Most enterprises — and nearly every GCC — run at least one managed integration platform alongside their code: a visual environment where pipelines are DAGs of pre-built connectors (pull from a SaaS API, map fields, land in the warehouse), scheduled or triggered, with retries and error views out of the box. The vendors rotate; the pattern doesn't, and in an interview you should talk about the pattern, not the product.
Where low-code integration genuinely wins: many SaaS and database sources with standard extract-and-load needs, mixed-skill teams, and connector maintenance you'd rather outsource — the vendor absorbs every upstream API change so your team doesn't. Time-to-first-pipeline is hours, not sprints, and for the long tail of "get Salesforce into the warehouse daily" that's the right trade.
Where it strains: complex transformation logic trapped in a GUI instead of version-controlled code, weak diff/review/test workflows compared to a git repo, per-connector or per-row pricing that scales badly, and debugging that ends at the vendor's black box. The mature pattern is a split: managed connectors for extraction and loading, code (SQL/dbt/Spark) for transformation — which is exactly the ELT boundary from §3.1.
Whatever the tool, the operational questions are identical to hand-rolled pipelines, and interviewers use them to check you ran the thing rather than clicked around it: how does it track incremental state (and what happens when you reset it), what happens to failed records (retry, dead-letter, or silent drop), is a rerun idempotent (§3.3), and how do schema changes surface (§3.4)?
Interview angle
"You've used a low-code integration tool — why should we hire you to write pipelines in code?" Answer with the split: connectors bought you speed on extraction, while the logic that mattered lived in versioned, tested SQL — and name a moment you migrated a pipeline from GUI to code when it outgrew the tool. That story lands as judgement, not tool loyalty.
9.5
The cloud stack: AWS, Azure, GCP
Indian loops are cloud-specific in a predictable way: AWS dominates product companies and Amazon itself asks its own stack by name; Azure dominates GCCs and banks; GCP shows up at startups and analytics-heavy shops. You need one stack in production depth and the other two at mapping level — because the services are the same six ideas wearing different names.
The lake is object storage. S3 (ADLS Gen2, GCS) plus Parquet plus a table format is the lake; everything else reads from it. The interview questions here are partitioning layout, the small-files problem, and lifecycle tiering for cost.
Two ways to run Spark. Glue is serverless Spark with a built-in catalog — zero cluster management, less control, priced per DPU-hour. EMR is the managed cluster — full control over versions, instance types, and spot usage, more to operate. The Amazon-flavored question is exactly this trade-off: Glue for scheduled ETL a small team owns; EMR when you need custom configs, long-running clusters, or cost engineering at scale. (Azure: Databricks or Synapse Spark. GCP: Dataproc, or skip Spark and let BigQuery do the work.)
Two ways to run SQL. Athena queries S3 in place — serverless, per-TB-scanned, perfect for ad-hoc reads on the lake; costs explode if you scan unpartitioned raw data, which is the gotcha they probe. Redshift is the provisioned warehouse for concurrent BI: know distribution keys (collocate join keys to avoid data moving between nodes) and sort keys (skip blocks on range filters), because "how do you make this Redshift join fast" is a standard Amazon India question. (Azure: Synapse. GCP: BigQuery, where the same ideas surface as partitioning and clustering.)
Streams and orchestration. Kinesis is the managed Kafka-shaped log (shards ≈ partitions, same ordering-per-shard and consumer-scaling logic from §8.1); MSK is literal managed Kafka when you need the ecosystem. Airflow appears as managed MWAA (Azure: ADF for movement + orchestration; GCP: Composer). Lambda glues events together but has a hard 15-minute limit — proposing it for heavy transforms is a known red flag; it's for triggers, not for Spark's job.
The mapping trick
Answer in problems first, services second: "we need a log, a processor, a lake, a warehouse, an orchestrator" — then name the vendor's word for each. That works in an AWS loop, an Azure GCC loop, and a GCP loop without re-learning anything. The full three-cloud mapping table is in the cheat sheets.
Interview angle
Amazon interviewers ask their stack by name, and honesty beats bluffing everywhere: "I've run Glue and Redshift in production; Kinesis I know at the architecture level" survives follow-ups, while claiming all of them invites the follow-up that ends the loop. If your production depth is Azure (common in GCC roles), say so and map fluently — that's a pass.
Data pipelines are software, and the platform round checks whether you treat them that way. CI/CD for data is the same idea as for any code — automate test and deploy — with data-specific tests bolted on. A healthy pipeline lives in version control, gets tested on every change, and deploys through environments (dev → staging → prod) without hand-editing anything in production.
What makes it data CI/CD is the extra test layer. Beyond unit tests on transformation logic (run Spark locally on tiny fixtures and assert the output), you add data-quality tests — schema/contract checks (did an upstream column change type?), row-count and null-rate assertions, referential and uniqueness checks — as gates in the pipeline itself, so bad data fails the run instead of silently corrupting downstream tables. Frameworks like Great Expectations or dbt tests formalize this, but the concept is what's tested.
The other data-specific piece is environment isolation without copying petabytes: dev and staging need production-like data, which is exactly what Snowflake zero-copy clones (§9.3) or Iceberg branch/tag features provide instantly and cheaply. And secrets — database creds, API keys, cloud tokens — never live in code or config; they come from a secrets manager (Vault, cloud KMS, the orchestrator's secret store) injected at runtime. "Creds in a vault, referenced by name, rotated centrally" is the one-line answer to the secrets question.
Write-Audit-Publish
A pattern worth naming: WAP — write new data to a staging branch/table, audit it with quality checks, and only publish (atomically swap it into the production table) if the checks pass. On open table formats (Iceberg branches) or with staging tables, this makes "never expose unvalidated data" a structural guarantee rather than a hope — the data-engineering version of a deploy gate.
10.2
Orchestration: idempotency & backfills
An orchestrator (Airflow, Dagster, native schedulers) runs your pipeline as a DAG of tasks with dependencies, schedules, and retries. Two concepts dominate the interview because they're what separates a pipeline that recovers from one that corrupts: idempotency and backfills. Fail a day and watch what happens:
Figure 8.2. A daily pipeline where one day fails. Downstream days block until it's fixed; a backfill re-runs the failed day (and dependents), and because the tasks are idempotent, the rerun overwrites cleanly instead of double-writing. Illustrative.
Idempotency means running a task twice produces the same result as running it once — the single most important property in orchestration, because tasks will be retried after failures and backfilled after fixes. You achieve it by making writes overwrite a specific partition rather than append (write date=2026-08-30 by replacing that partition, so a rerun replaces it again rather than duplicating), or by upserting on a key. The anti-pattern interviewers listen for is a blind INSERT/append: rerun it and you've double-counted. "I partition by date and overwrite the partition, so retries and backfills are safe" is the answer that signals production scars.
Backfilling is re-running the pipeline for past dates — to fix a bug, load history, or recover from an outage. It only works cleanly because the tasks are idempotent (rerun overwrites) and parameterized by the run date rather than hardcoded to "today" — a task that reads {{ ds }} / an execution-date parameter can be pointed at any historical date. The two ideas are joined at the hip: idempotency is what makes backfills safe, and date-parameterization is what makes them possible.
Interview angle
"How do you make a pipeline safe to retry and backfill?" Give the pair: idempotent writes (overwrite the target partition or upsert on a key, never blind-append) and date-parameterized tasks (the run reads its logical date, so it can be re-pointed at any day). Then close with the failure story: "a retried or backfilled run replaces its partition, so there's no double-counting — the run is a pure function of its date." That framing is catnip to a platform interviewer.
10.3
MLOps: the pipeline past the model
For a data engineer, MLOps is mostly data engineering with a model on the end — the questions are about the pipeline and its failure modes, not the math. The lifecycle to know: features → training → a registry → serving → monitoring, with feedback loops. Your job is the plumbing that makes it reproducible and reliable.
The concept interviewers reach for first is training-serving skew: the model was trained on features computed one way (a batch Spark job over historical data) but served features computed another way (a real-time path), and the mismatch quietly wrecks accuracy in production. The canonical fix is a feature store — compute each feature once and serve the same values to both training (offline) and serving (online), guaranteeing consistency. Being able to name skew and give the feature-store fix is a strong signal in any ML-adjacent DE interview.
The rest assembles quickly. A model registry versions trained models with their metadata and stage (staging/production), so you know exactly what's deployed and can roll back. Drift monitoring watches whether the live input distribution or the model's accuracy has moved away from training — because a model silently degrades as the world changes, and nothing errors; you have to look. And deployment safety mirrors software: champion/challenger or canary rollouts (send a slice of traffic to the new model, compare, promote if better) so a bad model doesn't take down predictions for everyone.
Interview angle
"What's training-serving skew and how do you prevent it?" — it's when features differ between training and inference (different code paths or timing), degrading the model in production without any error surfacing. Prevent it with a feature store that computes features once and serves identical values to both sides. Bonus: "and I'd monitor input drift, because even with no skew, the world shifts and accuracy decays silently."
10.4
Observability and the 2 a.m. page
The final round is often behavioral-technical: "tell me about a pipeline incident." What they're testing is whether you think about data in production — not just does the job run, but is the data right, fresh, and trustworthy. The vocabulary is data observability, usually framed as a few pillars: freshness (is the data up to date?), volume (did row counts suddenly drop or spike?), schema (did a column change or disappear?), quality/distribution (are values in range, null rates stable?), and lineage (if this table is wrong, what upstream caused it and what downstream is affected?).
The senior instinct is that a job succeeding is not the same as the data being correct — the pipeline can run green while an upstream source silently sends half the rows. So you alert on the data, not just the task status: a freshness SLA breach, an anomalous row count, a null-rate spike, a schema change. And you frame incidents by blast radius — lineage tells you every downstream table and dashboard affected, so you can communicate impact and prioritize the fix.
When you tell the incident story, use the arc that shows maturity: detect (an alert fired — ideally a data-quality alert, not an angry Slack from an analyst), diagnose (lineage traced it to an upstream schema change), mitigate (roll back with time travel / re-run the last good partition), fix and prevent (add the schema-contract test that would have caught it in CI). Detect → diagnose → mitigate → prevent, with a prevention that closes the loop, is the answer that ends the interview well — and it's the same "what happens when it breaks" thread from §0.1, all the way through.
Candidates report the same thing across companies: the pipeline design round is the filter. SQL and coding rounds are the ones people over-prepare and they carry the least weight above mid-level, because correctness there is table stakes. The design round is open-ended, and open-endedness is exactly what reveals whether you've operated systems or only built them.
It is not a backend system design interview with bigger numbers. The failure modes are different: you're optimizing for throughput, correctness, and analytical access patterns rather than request latency and transactional APIs, and your system has to serve analysts, ML engineers, and compliance simultaneously. Nobody asks you to design Twitter. They ask you to design something their company already runs.
The most consistently reported rejection reason is worth stating bluntly: naming tools instead of reasoning about the problem. A candidate who opens with "I'd use Kafka, Spark, and Snowflake" has answered nothing. A candidate who opens with "before I pick anything — what's the volume, how fresh does this need to be, and who's consuming it?" has already passed the first hidden checkpoint.
Use the whole hour deliberately. The rough budget below is what strong candidates converge on, and following it visibly ("let me spend a few minutes on requirements first") is itself a signal of having done this before.
Interview angle
The interviewer is a collaborator, not an examiner. Say your assumptions out loud and invite correction — "I'm assuming we don't need sub-second freshness; tell me if that's wrong." Rigidity when they change a requirement is a documented fail; adapting the design cleanly is a documented pass.
11.2
Requirements and the envelope
Start by pinning down what the system must do and what it must be. Functional: what questions does this data answer, and who asks them? Non-functional: volume, freshness SLA, query latency, retention, correctness guarantee, and budget. The freshness number does more architectural work than anything else in the room — "the dashboard is read each morning" and "the pricing engine reads this in under a second" are two entirely different systems.
Then do the arithmetic out loud. Back-of-envelope numbers anchor every later decision and take ninety seconds: events per day × bytes per event = daily volume; divide by 86,400 for average events per second; multiply by 5–10× for peak. A design that has been sized is a design you can defend, and it prevents the classic mistake of proposing a streaming architecture for 40 MB a day or a single Postgres box for 4 TB.
Two conversions worth memorizing so you can do this without a calculator: 1 KB × 1 million = 1 GB, and anything per-day divided by ~100,000 gives you roughly the per-second rate (86,400 seconds, rounded for arithmetic you can do in your head). Round aggressively — nobody is checking your multiplication, they're checking whether you reason in orders of magnitude.
Interview angle
State the peak-to-average ratio explicitly. Systems are sized for peak, not average, and candidates who design for the daily total quietly build something that falls over every evening at 8 p.m. Saying "5× peak, so I'll size the ingestion for 60k events/sec" is a small sentence that reads as production experience.
11.3
The reference architecture
Almost every data design answer decomposes into four layers, and having this spine means you're never blank in front of a whiteboard: ingest → process → store → serve, with orchestration and observability running across all of them.
Ingest. How does data arrive? Event streams land in a log (Kafka/Kinesis/Pub-Sub) that buffers, decouples producers from consumers, and lets you replay. Databases arrive by CDC or batch extract (§3.2). Third-party APIs arrive by scheduled pull, and you should mention rate limits and pagination if that's the source.
Process. Batch (Spark on a schedule) or stream (Flink / Structured Streaming), decided by the freshness requirement, not by taste. Say where transformation happens and what the layering is — raw landing, cleaned, aggregated (§3.1).
Store. Object storage in an open columnar format (Parquet) under a table format (Iceberg/Delta) is the default lake answer; a warehouse (Snowflake/BigQuery/Redshift) is the default analytics answer; the two increasingly converge. Name your partitioning scheme and the small-files problem — thousands of tiny files from a streaming writer will destroy read performance until compaction runs, and interviewers love that detail because only people who've hit it mention it.
Serve. BI tools query the warehouse; low-latency application reads need a serving store (a key-value store, or an OLAP engine like Druid/Pinot/ClickHouse for sub-second aggregations); ML needs a feature store to keep training and serving consistent (§10.3).
Then the cross-cutting layer, which is where seniority shows: orchestration with retries and backfills (§10.2), data quality checks at the boundaries, lineage so you can answer "what breaks if this changes," and access control and PII handling — regulated environments will ask, and volunteering it scores.
Lambda, Kappa, and not over-reaching
If you propose both a streaming path and a batch path over the same data (a lambda architecture), name the cost: two implementations of the same business logic that drift apart. The modern preference is one path — stream with replay from the log, or batch with a short interval — and reaching for two only when the requirements genuinely demand it.
Interview angle
Draw the four boxes before you name a single technology. Then fill them in, justifying each with a requirement you elicited. This ordering — problem first, tools second — is the single most-cited difference between the candidates who pass this round and the ones who don't.
11.4
Worked example: clickstream analytics
"Design a pipeline that ingests click events and powers both a real-time dashboard and next-day reporting" is the most frequently reported prompt in the round. The Indian variants are the same problem in local clothing — live cricket-match concurrency at a streaming platform, UPI payment events at a fintech, a Big Billion Days order spike at a marketplace — same shape, with an even harsher peak-to-average ratio. Here's the shape of a strong answer.
Requirements. 2 billion events/day, ~1 KB each — so ~2 TB/day, ~23k events/sec average, call it 100k+ at peak. The dashboard needs freshness in seconds; the reporting tables need to be correct and stable, not fast. Retention: 90 days hot, years cold. That split — one consumer wants fast, one wants right — is the actual design problem, and naming it early is most of the answer.
Ingest. Producers write to a partitioned Kafka topic keyed by user id so per-user ordering holds (§8.1). The log is the buffer and the replay mechanism; everything downstream is a consumer of it.
Two consumers, one source of truth. A stream job maintains windowed aggregates for the dashboard — approximate is acceptable, latency is not — writing to an OLAP store. Separately, a sink writes raw events to the lake as Parquet partitioned by event date, and a batch job builds the corrected, deduplicated tables with a rolling reprocessing window for late arrivals (§3.5). The dashboard's numbers and the report's numbers will differ slightly during the day; say that out loud and explain that the batch table is the system of record.
The deep dives they'll push on. Duplicates: producers retry, so dedupe on a client-generated event id — MERGE in batch, keyed state with TTL in the stream (§8.3). Late events: watermark with bounded lateness for the stream, a rolling window for batch. Small files: the streaming writer produces many tiny files, so run compaction. Backfill: replay from the log if within retention, otherwise re-derive from the raw lake partitions — which is why you wrote them. Schema evolution: a registry with compatibility rules at the producer boundary (§3.4). Cost: partition pruning, tiering cold data to cheaper storage, and not sizing the stream cluster for peak when the log can absorb bursts.
Interview angle
Close by naming what you'd monitor and what you'd do differently at 10× scale. "I'd alert on consumer lag, freshness, and daily row-count deviation; at 10× I'd revisit partition count and consider pre-aggregating at ingest." Ending on operations rather than architecture is what a senior answer sounds like.
The behavioral round rarely wins you the offer. It very often loses it — and data engineers under-prepare for it more than any other discipline, because it feels unrelated to the craft. It isn't. Data engineering is the job where you find out something is wrong before the business does, argue with the team that broke it, and decide at 2 a.m. whether to hold the release or ship known-bad numbers. Those are behavioral questions with technical content.
How it's weighted varies, and knowing the variation is worth real points. Amazon evaluates Leadership Principles in every round, not just one, and adds a Bar Raiser from outside the team with veto power — expect them to drill into a single story's details until you either have them or don't. Netflix runs a dedicated culture conversation about judgment and independence rather than STAR trivia. Google screens "Googleyness," where the fatal patterns are bluster about knowledge you lack and rigidity under pushback. Meta blends it in: there's often no standalone behavioral round because ownership and product sense are assessed inside the technical ones.
The universal failure is the vague story. "We had data quality issues, so we improved our monitoring" is not an answer — it has no stakes, no decision, and no number. The fix isn't charisma; it's preparation. Write the stories down before the loop, out loud, timed.
Interview angle
Ask your recruiter what the behavioral round evaluates against. At most large companies the rubric is public (LPs, Googleyness, the Netflix memo), and mapping your stories to their named values before the call is free signal that costs an hour.
12.2
Story architecture
Use STAR — Situation, Task, Action, Result — but the version that works for engineers adds two things most candidates omit.
Scale and numbers. "A pipeline was slow" is a shrug. "A nightly job processing 4 TB had crept from 40 minutes to 6 hours and was breaking the 7 a.m. SLA" is a situation an interviewer can picture. Every story should carry at least one number in the situation and one in the result — rows, terabytes, hours, dollars, percentage, incident count.
The decision and its alternative. The interesting part is never what you did; it's what you chose not to do and why. "I could have thrown a bigger cluster at it, which would have cost about 3× and hidden the real problem — the skewed join — so I salted the key instead and cut runtime to 25 minutes." That sentence demonstrates ownership, cost awareness, and technical depth in one breath.
Keep each story to about two minutes spoken, with detail held in reserve for follow-ups rather than front-loaded. Close with a reflection when it fits — what you'd do differently, or what you changed permanently as a result ("we added a row-count reconciliation check that has caught two silent failures since"). A story that ends in a durable improvement reads as an engineer who compounds.
On the mistake question
"Tell me about a time you were wrong" is asked in almost every senior loop, and the failure mode is the disguised humblebrag ("I care too much about quality"). Pick a real mistake with real consequences, own it without hedging, and spend most of the answer on the correction and the systemic fix. Interviewers are calibrating whether you can be told you're wrong — which matters more in a data role than in most.
Interview angle
Interviewers dig. Expect three layers of "why did you do it that way?" on the same story, so pick examples you actually lived. Borrowed or embellished stories collapse at the second follow-up, and that collapse is the thing a Bar Raiser is specifically listening for.
12.3
The six stories every DE loop asks for
Across reported loops the same six themes recur, in different wording. Prepare one strong story for each and you can answer roughly ninety percent of what's asked, since most questions are these in disguise.
1 · The incident. Something broke in production and you owned it. Detection, blast radius, the call you made under pressure, the fix, the prevention. This is the single most-asked DE behavioral story.
2 · The data quality catch. You found numbers that were wrong — ideally before the business did — traced the root cause, and closed the hole. Reconciliation, a failed check, an alert you'd built.
3 · The disagreement. You pushed back on a stakeholder or another engineer. The point isn't winning; it's showing you can disagree with data, escalate appropriately, and commit to the decision even when it goes against you.
4 · Ambiguity. The requirements were unclear or contradictory and you made progress anyway — narrowed scope, shipped something small, validated, iterated.
5 · Influence without authority. You got another team to change something — a schema, a contract, a producer behavior — with no power to compel them. Data engineers live downstream of everyone, so this comes up constantly.
6 · The trade-off you'd defend. You chose speed over elegance, or correctness over deadline, and can articulate the cost you accepted and why it was right for that moment.
Below, map your own stories against the themes and the follow-ups each one attracts. Gaps in the grid are exactly where a loop will find you.
Interview angle
One story can serve several themes if you tell it from different angles — the same incident can be ownership, disagreement, or the mistake, depending on which part you foreground. But don't reuse one story for a whole loop; interviewers compare notes afterward, and a candidate with a single anecdote reads as thin.
12.4
Your questions, and the offer
The questions you ask are scored, whether or not anyone says so. Generic ones ("what's the culture like?") are neutral at best. Questions that reveal you think like an owner do real work: What breaks most often, and who gets paged? How do you know when a dataset is wrong — is there a check, or does someone notice? What's the split between building new pipelines and maintaining old ones? What does the data platform look like a year from now?
They also serve you. A team that can't answer "how do you know when data is wrong" is a team where you'll spend your first year firefighting, and the interview is the last moment you can find that out cheaply.
On compensation, the Indian market has one dominant lever: company type. Product companies pay two to three times what services pay at the same experience, which means moving tiers moves comp more than any promotion or negotiation inside a tier. The 2026 shape, roughly: senior DEs in the broad market land ₹28–42L; product companies and GCCs run ₹18–45L; fintech pays a streaming premium; and FAANG-India plus the top product companies reach ₹45–80L+ on RSU-heavy packages. Decompose every offer into fixed, variable, and ESOP — CTC is a marketing number, and unlisted-company ESOPs deserve a hard discount. Full bands are on the company playbooks page.
Three practical notes. Give a range only after you understand the level, since the same title spans very different bands. Treat the notice period as part of the deal — 60–90 days is standard in India, buyouts exist, and asking for a joining bonus that covers the buyout is normal, not cheeky. And when you get the offer, the highest-leverage question isn't about money — it's which team you're joining, because the difference between a mature platform and a firefighting one determines what your next two years look like.
Interview angle
Have two questions ready that only apply to that company — something from their engineering blog, their open-source stack, or a scale problem their product implies. It's the cheapest possible demonstration that you prepared, and interviewers remember it when they write feedback.
The word "agent" gets stuck on anything that calls a model, so interviewers start here to see if you can draw the line precisely. The line is about who decides the next step. In a workflow your code decides: fetch, then summarise, then email. That stays true even if every step calls an LLM; that is an AI workflow, and the model is just a component. In an agent the model decides at runtime: it looks at what the last tool returned and chooses which tool to call next, with what arguments, or whether to stop.
Everything else in the vocabulary hangs off that loop. A tool is a function the model may request; your code executes it. The harness is the code around the model: the loop, the tool registry, limits, retries, logging, approvals. State is everything about this run; memory is state that outlives a run. An agentic system mixes the two: deterministic workflows with small agentic pockets, wrapped in guardrails. Most good production systems look like that.
Step through the same question with both designs. Watch who picks the next action, and what each design costs on two different days.
Figure 13.1. The workflow always runs the same four checks; the agent stops early when one finding explains the problem, and takes a different path when the cause is different. Token counts are illustrative.
Read the trade-off off the readout. The workflow is cheaper in model calls, perfectly repeatable and easy to test, but it runs every check every time and needs new code for every new failure mode. The agent adapts to what it finds, at the price of determinism, latency and a context that grows with every step. That is the whole design question: pay for model-driven control only where the path genuinely depends on what you discover.
Interview angle
"Is this an agent?" Answer with the test, not a feeling: does the model's output choose the control flow at runtime? Then volunteer the cost of saying yes: non-determinism, harder testing, variable latency and spend. A senior answer adds where you'd draw the boundary in a real system: detection, arithmetic and anything with side effects stay in code; only the investigation, where the next query depends on the last result, goes to the model.
13.2
Tool calling, step by step
The model never runs anything. It can only emit text, and with tool calling that text is a structured request: a tool name and JSON arguments. Between "the model decides to query the warehouse" and "the model sees the rows", your code does five things: parse the request, validate the arguments against the tool's schema, authorise it for this user, execute it with your own credentials and a timeout, and append the result as a new message tied to the call's id. Then you call the model again with the whole conversation, because the API is stateless.
def run(task, max_steps=8):
messages = [{"role": "user", "content": task}]
for step in range(max_steps):
reply = llm(messages, tools=SCHEMAS) # model picks: tool call(s) or an answer
messages.append(reply.as_message()) # the call must be in history before its resultifnot reply.tool_calls:
return reply.text
for call in reply.tool_calls: # models can ask for several at once
result = execute(call.name, call.args) # validate, authorise, run, never raise
messages.append(tool_result(call.id, result))
raise StepLimit(max_steps)
Three details separate working loops from demos. Errors are observations: an unknown tool or a bad date format goes back to the model as a tool result it can correct, not an exception that kills the run; infrastructure failures (timeouts, 503s) are retried by the harness first. Results must be small: return an aggregate, the top 20 rows or a summary, never 40,000 rows, because every byte rides along on every later call. And every call id gets an answer, including parallel calls, or the provider rejects the next request.
Interview angle
"An LLM needs to query Snowflake. What happens between deciding and seeing the result?" List the five steps above and land the point that matters: all authority lives in the harness. The model holds no credentials and touches no database; your code runs the query with a read-only role, a row limit and a timeout. That one sentence sets up every security answer later in the loop.
13.3
Structured output you can trust
Your pipeline needs {"cause": "schema_drift", "table": "orders"}, not a paragraph. There are two ways to get it. Many providers can constrain decoding to a JSON Schema, masking any token that would break the grammar, which guarantees the syntax. Or you ask for JSON and parse it. Either way you still validate the semantics: valid JSON can name a table that doesn't exist, put a confidence of 1.7, or cite evidence no tool ever returned.
The data engineer's frame fits exactly: treat model output like an upstream feed with a data contract. Define the schema in code (Pydantic is the common choice), validate every response, and on failure run a bounded repair loop: send the exact validation error back and ask again, at most twice, then fail loudly with a typed error. Use temperature near zero for extraction work, and version the prompt like code, with its hash recorded on every run, so you can tell which prompt produced which output.
class Incident(BaseModel):
table: str
cause: Literal["late_source", "schema_drift", "bad_join", "unknown"]
confidence: float = Field(ge=0, le=1)
evidence_call_ids: list[str] = Field(min_length=1) # must point at real tool resultsfor attempt in range(3):
raw = llm(messages)
try:
return Incident.model_validate_json(raw)
except ValidationError as e:
messages += [assistant(raw), user(f"Invalid: {e.errors()[:3]}. Return corrected JSON only.")]
raise OutputContractError("no valid output after repairs")
Interview angle
"If the provider guarantees schema-valid JSON, why validate?" Because the guarantee is syntax, not truth. The checks that matter are business rules: the table exists, the enum is allowed, and every cited evidence id appears in this run's tool results. That last check alone removes most fabricated citations, and it's cheap.
13.4
Tokens, context and cost
A chat API is stateless: every request carries the entire conversation, including every tool result so far. So an agent's call at step 10 re-reads steps 1 to 9, and input tokens grow every step. Total cost across a run grows roughly with the square of the number of steps when tool results are large. Long contexts also hurt quality: facts buried in a long, noisy context are recalled less reliably than facts near the start or end.
Figure 13.2. Each bar is one model call's input. Bigger tool results and more steps compound. Prompt caching discounts a repeated, unchanged prefix; trimming old results shrinks what is resent. Prices and the cache discount are illustrative; check your provider's.
The levers, in order of impact: return less from tools (aggregate in SQL, not in the prompt); fewer steps (better tool design beats a smarter model); prompt caching on the stable prefix of system prompt and tool definitions, which providers bill at a discount and serve faster; compaction, which summarises old results but keeps their ids so citations still resolve; and model routing, sending easy sub-tasks to a small model. Pin model versions, too: an alias that silently moves to a newer model is a production change you didn't ship.
Interview angle
"Your agent is slow and expensive. What do you do?" Measure first, from traces: which span dominates, model calls or tools? Then reach for the levers above, in that order. Explaining why step 10 costs more than step 1, because the whole history is resent, is the detail that shows you've run one in production rather than read about it.
A loop that works in a notebook becomes a production system when you wrap it in a harness: a small, reusable engine that owns the loop, the tool registry, the limits and the record of what happened. The model becomes one swappable dependency. Agent SDKs and frameworks are largely this, plus adapters for each provider, so building one yourself once is the fastest way to understand what they do for you.
Its job is to make every way a run can end explicit. A run returns a typed result with a status (ok, max_steps, budget, denied, waiting_approval, error) rather than throwing. Stop conditions live in code: a step cap, a cost budget checked before every model call, a wall-clock timeout, and loop detection that rejects a repeated identical call. Errors are classified: retryable (429, 5xx, timeouts) get backoff with jitter in the harness; model-correctable (bad arguments, unknown id) go back to the model; terminal (auth failures, policy denials) end the run.
One idea transfers straight from data engineering: idempotency. A tool call that times out may have succeeded on the other side, and a blind retry can create two maintenance tickets or two refunds. Side-effecting tools take an idempotency key (run id + tool + argument hash) that the backend deduplicates, exactly like a MERGE keyed on a natural key makes a pipeline rerun safe.
Interview angle
"Where do you enforce 'never spend more than 50 cents a run'?" In the harness, before every model call. A prompt instruction is advisory, the model can't see its own spend, and a billing alert fires after the money is gone. The general principle the interviewer wants: anything that must hold is code on the path, not text in the prompt.
14.2
RAG for data engineers
Retrieval-augmented generation answers questions from documents the model was never trained on: find the few most relevant passages, put them in the context, and require the answer to cite them. Strip away the vocabulary and the left half of RAG is an ETL pipeline: extract documents, transform them into chunks with metadata, load them into an index, and keep it fresh. That is where most RAG systems actually fail, and where a data engineer is strongest.
The decisions an interviewer probes, in pipeline order: chunking that respects structure (sections, tables, runbook steps) instead of fixed character windows; metadata on every chunk (source, owner, version, effective date, access group) so you can filter before you rank; hybrid retrieval, keyword search such as BM25 for exact identifiers like error codes and table names, fused with vector search for paraphrase; a reranker over the top candidates; then a small, de-duplicated, token-budgeted context where each passage carries an id the answer must cite, and where "not found" is an allowed answer.
Evaluate the two halves separately. Retrieval: a labelled set of questions with the passages that answer them, scored with recall@k and MRR. Generation: is the answer faithful to the retrieved text, and are its citations real? When an answer is wrong, the first question is which half failed: if the right passage never came back, no prompt will fix it. Agentic RAG turns search into a tool, so the model decides whether to retrieve, rewrites the query when results are weak, and stops when the evidence is enough, under a search budget the harness enforces.
Interview angle
"Design RAG over our internal runbooks." Lead with the ingestion pipeline (incremental re-indexing on change, deletes propagated, document permissions carried into metadata and enforced at query time), then retrieval, then evaluation. Two details score: stale and superseded documents are the classic wrong-answer source, so filter by version and date; and retrieved text is untrusted input, so it must never be able to trigger tools on its own (§15.3).
14.3
MCP: the Model Context Protocol
Without a standard, every AI application writes its own integration to every system: N apps times M tools. MCP makes it N plus M. A tool provider writes one MCP server; any MCP client (built into a host application such as an IDE, a chat app or your own harness) can discover and call it. Under the hood it is JSON-RPC 2.0 over a transport: stdio for a local server process, or HTTP for a remote one, where the spec defines OAuth-based authorization.
A server exposes three kinds of capability, and who controls each one matters. Tools are chosen by the model (run a query, open a ticket). Resources are attached by the application as context (a table's schema, a runbook). Prompts are templates a user invokes. The client first negotiates capabilities with initialize, lists what's available, then calls. Click through one session:
Figure 14.1. One MCP session over stdio, message by message. Tool errors come back as a normal result flagged isError, so the model can read and recover; protocol errors use JSON-RPC error codes. Payloads trimmed for readability.
What MCP does not give you is trust. It standardises connectivity, not authorization or safety. A server's tool descriptions and results are text that reaches the model, so a malicious or compromised server can inject instructions; a tool inherits whatever credentials you hand it. Production rules: pin and review server versions, run servers with least privilege and no access to secrets they don't need, keep read and write tools on separate servers with separate credentials, and put approvals for risky tools in your harness, not in the server.
Interview angle
"Why MCP instead of just calling our APIs?" Discovery and reuse: one server serves every MCP-capable host, and tool definitions live with the system they describe. Then say the honest cost: another process and network hop, a new security surface, and a spec that is still evolving. "MCP is a connection standard, not a security boundary" is the line that signals you've thought about it.
14.4
Memory, state and checkpoints
"Just put everything in the context window" fails for the reasons in §13.4: cost and latency grow every call, quality degrades on long noisy contexts, stale facts linger, secrets ride along, and a crash loses it all. Separate the kinds of memory instead. Working memory is the context you build for this call. Task state is the run's progress: plan, step, evidence gathered, pending approvals, stored as structured data, not prose. Long-term memory is what outlives runs: past incidents and their resolutions, user preferences, stored in a database and retrieved only when relevant.
Checkpointing is the data engineer's familiar friend. After every step, write the run's state durably (Postgres, keyed by run id, with a schema version). If the worker dies, another resumes from the last checkpoint, and because completed tool results are in the state, they are not re-executed. Save after the tool result is recorded, atomically; save before, and a crash between "executed" and "recorded" means a side effect runs twice. Graph-based orchestration frameworks call this persistence; it is the same idea as a streaming job's checkpoint and offset commit.
Interview angle
"A run waits two hours for a human approval and the worker restarts. What must be persisted?" Messages, step counter, every completed tool result keyed by call id, the pending action and its argument hash, usage so far, and the prompt and model versions. Then the property that matters: resume is deterministic with respect to side effects that already happened.
"I tried five questions and it looks better" is how agent projects drift. An eval is a test set with ground truth: scenarios (input plus the environment state the tools will see), the expected outcome, and graders. Grade at three levels: tools on their own, with ordinary unit tests; the trajectory (did it call the tools it had to, avoid forbidden ones, finish within a step budget?); and the outcome (right root cause, right number, citations that resolve). Record steps, tokens, cost, latency and failure rate on every run, because a "better" agent that costs four times as much may not be better.
Prefer programmatic graders: an enum compared to the truth, a number within tolerance, a set of required tool calls. Use an LLM as judge only for free text, give it the ground truth and a rubric, and check its agreement with your own labels on a sample before trusting it; judges favour longer answers and can be fooled by confident ones. Then the statistics. Model outputs vary between runs, so repeat each scenario, compare versions on the same scenarios (paired), and report a range, not a point. Feel how small evals fool you:
Figure 15.1. Two agent versions with known true success rates, each evaluated on n scenarios, repeated 1,000 times. "Looks better" counts experiments where B simply scored higher; "convincing" counts those where a two-proportion test at 95% agrees. Simulated, with a fixed seed.
Keep a held-out split you never read while tuning prompts, or you will overfit to your own eval exactly as you would to a test set. Run a fast subset on every pull request as a regression gate, and the full suite nightly against pinned and current model versions, so a provider-side model update shows up as a chart, not a customer complaint.
Interview angle
"How do you know your change made the agent better?" Fixed scenario set with ground truth, repeated trials, paired comparison with confidence intervals, slices by difficulty, a held-out split, and every result tagged with model, prompt hash and git sha. Mention that safety metrics such as forbidden tool calls are gates with near-zero tolerance, not numbers you average away.
15.2
Tracing: debugging a run
You cannot debug what you can't replay. Instrument every run as a trace: one span for the run, a child span for each model call (model, prompt hash, input and output tokens, latency) and each tool call (name, argument hash, status, latency). OpenTelemetry is the vendor-neutral standard, and it has semantic conventions for generative-AI spans, though those are still evolving. Most LLM observability tools ingest the same shape.
The debugging loop production teams use: find the failed run, open its trace, and find the first divergence from the path you'd expect. Then classify the cause: a tool returned the wrong thing, retrieval missed the passage, the model reasoned badly from good evidence, the harness cut it off (budget, loop detection), or the data itself was wrong. Count causes across 20 or 50 failures and fix the biggest class first. Record-and-replay (re-running with recorded tool outputs) turns a one-off failure into a reproducible test case. Redact PII and secrets before anything reaches the trace store.
Interview angle
"An agent failed once and never again. How do you debug it?" Traces with full model and tool input and output, replay from the recorded tool results, then aggregate: one failure is an anecdote, a Pareto chart of 50 classified failures is a roadmap. And observability must be non-blocking: if the tracing backend is down, the agent keeps working.
15.3
Prompt injection and defense in depth
An agent reads text it didn't write: tickets, table comments, documents, web pages, tool results. Anyone who controls that text can hide instructions in it, and models sometimes follow them. That is indirect prompt injection, and no system prompt reliably prevents it. The dangerous combination is an agent with access to private data, exposure to untrusted content and a way to send data out or take actions. Remove any one leg and most attacks lose their payoff.
So security is designed around a fooled model, not a perfect one. Switch the controls on and watch which attacks they stop:
Figure 15.2. Each attack succeeds unless at least one control that covers it is on. None of the controls depend on the model noticing the attack. Scenarios are illustrative.
The controls map onto things a data engineer already does. Least privilege: a read-only warehouse role, row limits, and only the tools this task needs. Authorise every call by user and arguments (which tenant, which tables), not just by tool name. Secrets stay in the harness, never in prompts. Egress allowlists so a fooled agent can't send data to an arbitrary URL. Human approval for anything destructive or financial. Budgets against runaway loops. And test it: keep an attack suite in your evals, with the forbidden-call count as a gate.
Interview angle
"How would you prevent prompt injection?" The honest answer is that you contain it rather than prevent it. Treat all model input from tools and documents as untrusted data, assume the model will sometimes obey it, and make sure what it can do when fooled is limited by least privilege, authorization, egress control and approvals. Then answer the follow-up before it's asked: "What if it has production access and a user asks for something malicious?" It can only do what the policy layer allows.
15.4
Human in the loop
Not every action deserves the same autonomy. Classify tools by risk and let the harness enforce it: reads run on their own; low-risk actions (draft a report, post to an internal channel) run with logging; high-risk actions (rerun a production backfill, drop a partition, change a setpoint, move money) require a person. Classify by reversibility, blast radius and who is affected, and default to the higher tier when unsure.
Approval is a pause, not a pop-up. The run checkpoints, records the exact pending action, notifies the approver with the evidence, and stops. When the person decides, a worker resumes from the checkpoint. The approval is bound to that exact action: a single-use, expiring token derived from a hash of the run id, tool and arguments, so approving "backfill 3 days" can never authorise "backfill 300". After executing, verify by reading back the system state, because models report intentions as facts.
Interview angle
"Why bind approval to the arguments rather than approving the plan?" Plans are vague, arguments can change after approval, and injected text can swap the action. Then name the opposite failure: approval fatigue. If every read asks for a click, people approve without reading, so keep the high-risk set small and show approvers exactly what will change.
The design round for AI systems rewards restraint. Interviewers have seen many candidates reach for a multi-agent framework before asking what the task needs, and the quickest way to stand out is to show you'd ship the simplest thing that works. Start with a ladder and climb only as far as the problem forces you: plain code, then a single LLM call inside a workflow (classify, extract, summarise), then a workflow with an agentic step, then a single agent with tools, and only then several agents.
Four questions decide the rung. Is the path known in advance? If you can draw the control flow, write it as a workflow. Does the next step depend on what the last one found? That is the agent's job. What does a wrong answer cost, and can you verify it? High-stakes steps need deterministic code or a human. What are the latency and cost budgets? An agent's spend varies per request; a workflow's doesn't. Detection, arithmetic, scheduling and anything with side effects almost always stay in code.
Interview angle
"When would you NOT use an agent?" When the path is enumerable, when latency or cost must be bounded, when correctness must be exact, or when a deterministic baseline already meets the bar. Naming the baseline you'd build first, and the metric that would justify moving up the ladder, is what makes the answer senior.
16.2
The reference architecture
Most production agent systems converge on the same shape, and almost every box is something a data engineer has built before. Agent runs take seconds to minutes, so they run as background jobs, never inside a request handler.
The API returns a run id and the client polls or streams progress. Workers take a lease on a run and heartbeat, so a crashed worker's run is picked up by another and resumes from its checkpoint (§14.4). Tools are split by trust: read-only servers with read-only credentials, action tools behind the policy engine and approvals (§15.4). Every model and tool call is a span. The eval suite runs in CI exactly like data-quality tests do, and a regression blocks the deploy.
Interview angle
"A worker crashes mid-run, after a side-effecting tool executed. What guarantees correctness?" Leases and heartbeats so the run is reclaimed, checkpoints that record completed tool results atomically, idempotency keys at the tool backend, and resume logic that skips calls that already have results. Design for at-least-once execution and make each step idempotent, the same answer you'd give for a pipeline.
16.3
Worked example: a pipeline-incident agent
Prompt: "Design an agent that helps the on-call data engineer when a dashboard metric looks wrong." It's a good DE-flavoured agent problem because the investigation genuinely branches: the cause could be a late source file, schema drift, a failed or partial load, a bad join fan-out, or a real business change, and each one is confirmed by different evidence.
Requirements first. Who uses it (the on-call engineer, not end users); what it may do (investigate and recommend; any rerun or backfill needs approval); latency (a useful first answer within a couple of minutes); and the bar (it must cite the evidence for every claim, and say "unknown" rather than guess). Detection stays deterministic: existing freshness and data-quality checks fire the trigger. Investigation is the agentic pocket, with narrow read-only tools: get_pipeline_runs(dag, since), get_source_freshness(source), run_dq_checks(table), get_schema_changes(table, since), compare_metric(metric, day, baseline_days), search_runbooks(query). Each returns a compact summary, never raw rows.
Output is a typed incident report: cause from an enum, confidence, evidence ids, blast radius (downstream tables and dashboards from lineage), and a recommended action. Actions such as trigger_backfill(dag, start, end) live on a separate, approval-gated tool with an idempotency key. Evaluation: replay past incidents from your incident log as scenarios with known root causes, and inject synthetic failures into a staging copy; measure root-cause accuracy, forbidden-call count, steps, time-to-first-answer and cost. Rollout: shadow mode first (the agent writes its report next to the human's), then suggestions, then approval-gated actions, gated on the eval numbers.
Interview angle
Strong candidates spend the first third of the round on requirements and the trust boundary, not the prompt. Volunteer the failure modes before you're asked: the agent blames the wrong upstream table (catch it with evidence-citation checks), loops on a flaky tool (step and budget caps), or a ticket comment contains an injected instruction (no write tools without approval). Ending on a shadow-mode rollout with a measured bar shows you'd ship it safely.
16.4
Multi-agent: when it earns its keep
Multi-agent designs are not automatically better. Each extra agent adds model calls, latency, cost and another hand-off where information gets lost. The patterns are worth knowing: a router classifies a request and sends it to one specialist; a supervisor splits a task, delegates parts and combines the results; specialists can run in parallel or in sequence (and a fixed sequence is usually just a workflow).
Split only for a reason you can name and measure. Context isolation: a specialist digs through noisy logs and returns a compact finding, keeping the supervisor's context clean. Parallelism: independent investigations run at once. Different permissions: a read-only analyst and an approval-gated operator. Different models: a cheap model for triage, a strong one for synthesis. Hand-offs must be structured evidence objects with ids, not prose summaries, and every sub-task must be self-contained. Then prove it: run the single-agent baseline and the multi-agent version on the same eval set and compare accuracy, p95 latency and cost.
Interview angle
"Why use a multi-agent architecture here?" Give one specific, measurable reason, acknowledge the cost, and mention the baseline you'd compare against. "Because agents collaborate like a team" is the answer that loses the round; "because the log analysis needs its own 100k-token context and the evals showed the split cut wrong answers without raising p95 latency" is the one that wins it.
A container is not a small virtual machine. It is an ordinary Linux process that the kernel isolates in two ways. Namespaces limit what it can see: its own process tree (PID), network stack, mount table, hostname and users. cgroups limit what it can use: CPU time, memory, I/O and the number of processes. There is no second kernel. Every container on a host shares the host's kernel, which is why containers start in milliseconds, and why a kernel bug or a privileged container is a host-level problem.
An image is the filesystem that process starts from: a stack of read-only layers, each one the diff produced by one Dockerfile instruction, plus metadata (entrypoint, env, user, exposed ports). A running container adds one thin writable layer on top (copy-on-write). Layers are content-addressed by hash, so two images built on the same base share those bytes on disk and in the registry. A registry (ECR, Docker Hub, GHCR) stores images by repository:tag, and every tag points at an immutable digest (sha256:…).
The vocabulary interviewers expect: Docker is the tooling (CLI, build engine BuildKit, daemon). containerd is the runtime daemon that actually manages containers, and runc is the low-level tool that creates the namespaces and cgroups. The OCI specs standardise the image format and runtime, which is why an image built by Docker runs unchanged on Kubernetes, which talks to containerd directly and hasn't used the Docker daemon since dockershim was removed in 1.24.
Interview angle
"Container vs VM?" Answer with the mechanism: a VM virtualises hardware and boots its own kernel, a container is a process with namespaces and cgroups on a shared kernel. Then give the consequence each way: containers are lighter and start faster; VMs give a stronger isolation boundary, which is why multi-tenant platforms (Fargate, Lambda) put each tenant's containers inside a micro-VM.
17.2
Writing a production Dockerfile
Three rules carry most of the weight. Order for the cache: Docker reuses a layer only if that instruction and every one before it is unchanged, so copy the dependency manifest and install dependencies before copying source code. Otherwise every one-line code change reinstalls every package. Build in one stage, ship in another: a multi-stage build compiles or installs with the full toolchain, then copies only the result into a slim runtime image. Run as a non-root user with an explicit USER.
# syntax=docker/dockerfile:1FROM python:3.12-slim AS build
WORKDIR /app
COPY requirements.txt . # manifest first: this layer stays cachedRUN pip install --no-cache-dir --prefix=/install -r requirements.txt
FROM python:3.12-slim
RUN useradd --uid 10001 app
COPY --from=build /install /usr/local
WORKDIR /app
COPY src/ ./src/ # code last: changes oftenUSER 10001
ENTRYPOINT ["python", "-m", "src.job"] # exec form: python is PID 1 and gets SIGTERM
Pin what you depend on. FROM python:3.12-slim can change under you when the tag is re-pushed; for builds you must reproduce, pin the digest (python:3.12-slim@sha256:…) and let a bot such as Renovate or Dependabot propose updates. Deploy by digest or by an immutable tag (the git SHA), never by latest, because latest makes "what is running in production?" unanswerable and makes rollback a guess.
Add a .dockerignore (exclude .git, virtualenvs, data files, .env). Without one, the whole directory is sent as build context: slow builds, bloated layers, and secrets copied into the image by a careless COPY . ..
Interview angle
"Your image is 2.4 GB and builds take 12 minutes. What do you do?" Check the instruction order for cache busting, add a .dockerignore, move to multi-stage with a slim or distroless base, combine apt-get update && install && rm -rf /var/lib/apt/lists/* into one RUN (a file deleted in a later layer still ships in the earlier one), and use a BuildKit cache mount for the package manager. Then measure with docker history or dive to see which layer is heavy.
17.3
Runtime: PID 1, signals and memory
PID 1 is special. The first process in a container's PID namespace doesn't get the kernel's default signal handlers, so a SIGTERM it doesn't explicitly handle is ignored. It also has to reap zombie children. Two common mistakes follow. The shell formCMD python job.py runs /bin/sh -c "python job.py", so the shell is PID 1 and usually doesn't forward SIGTERM to Python. A wrapper script that ends in python job.py without exec does the same. The symptom: every deploy or scale-down waits the full grace period (30 s on Kubernetes), then the process is SIGKILLed mid-write. Fix: exec form, exec in wrapper scripts, or a tiny init (tini, docker run --init) that forwards signals and reaps zombies. Then actually handle SIGTERM: stop taking work, finish or checkpoint in-flight work, commit offsets, exit.
Memory limits are enforced by the kernel. When a container's cgroup exceeds its memory limit, the kernel's OOM killer kills a process in it. The container exits with code 137 (128 + signal 9) and Kubernetes reports OOMKilled. There's no stack trace and often no log line, because the process didn't get a chance to write one. The memory that counts includes page cache from files the process writes and off-heap allocations, not only the heap.
Runtimes must know about the limit. Modern JVMs (since 10, backported to 8u191) read cgroup limits, but the default max heap is 25% of the container's memory, which wastes memory in a dedicated container. Set -XX:MaxRAMPercentage=70 or so, leaving room for metaspace, threads, direct buffers and native libraries. Python and Node don't size themselves to the container at all: a pandas job reading a 3 GB file into a 2 GiB container is simply killed. For CPU, os.cpu_count() returns the host's cores, not the container's quota, so thread pools sized from it oversubscribe the quota and get throttled.
The classic gotcha
Exit code 137 is a kill signal, not necessarily memory. Check the reason: OOMKilled means the memory limit; otherwise something sent SIGKILL, usually the orchestrator after the grace period expired because the app ignored SIGTERM. Exit 143 (128 + 15) means the process exited cleanly on SIGTERM, which is what you want.
17.4
Tricky cases and security
"exec format error". The image was built for a different CPU architecture: built on an Apple-silicon laptop (arm64) and run on x86 nodes, or the reverse on Graviton. Build multi-arch images with docker buildx build --platform linux/amd64,linux/arm64, and check the manifest with docker buildx imagetools inspect.
Secrets in layers. An ARG or ENV holding a token, or a COPY of a credentials file that a later layer deletes, is still readable by anyone who can pull the image (docker history, or extract the layer tarball). Use BuildKit secret mounts (RUN --mount=type=secret,id=pip_token …) at build time, and inject runtime secrets from the orchestrator (Kubernetes Secrets, preferably synced from a secrets manager), never baked into the image.
"Works on my machine" differences. Timezone and locale (the slim image is UTC with no locale, so date parsing changes), CA certificates missing on scratch or distroless images (TLS fails), DNS (Alpine's musl resolver behaves differently from glibc and some Python wheels don't exist for musl), and file permissions when the container runs as a different UID than the volume owner.
Disk fills up on the host. Container stdout logs with no rotation, dangling images from CI builds, and data written into the writable layer instead of a volume. In Kubernetes this becomes ephemeral-storage eviction: the kubelet evicts pods when the node's disk crosses its threshold.
Supply chain. Scan images in CI (Trivy, Grype, ECR scanning) and fail on critical CVEs with a fix available. Use minimal bases (distroless, Chainguard, -slim) so there's less to patch. Sign images (cosign) and verify signatures at admission if you need provenance. Drop Linux capabilities, use a read-only root filesystem, and never run --privileged or mount /var/run/docker.sock into an application container: either is effectively root on the host.
Interview angle
"A container works locally but crashes on the cluster with no logs." Walk the list in order: exit code and reason (137 OOM, or architecture mismatch giving exec format error), the image digest actually deployed versus the one you tested, environment and secrets that exist locally but not on the cluster, the non-root user unable to write to its working directory, and a read-only root filesystem.
Contents · Chapter 18 · Kubernetes, beginning to depth
18.1
The control loop and the objects
Kubernetes is a database of desired state plus a set of controllers that continuously make reality match it. You never tell it "start three containers". You write "there should be three replicas of this pod" to the API server, and a controller notices there are two and creates one. The same reconcile loop (observe, compare, act, repeat) runs everywhere in the system, which is why it heals itself and why it's eventually consistent: a change you apply is a request, not an instant fact.
The control plane: the API server (the only component that talks to storage, and the front door for everything), etcd (the consistent key-value store holding all state), the scheduler (assigns unscheduled pods to nodes) and the controller manager (runs the built-in reconcile loops). Each node runs the kubelet (makes the pods assigned to this node actually run, via containerd), kube-proxy or an eBPF replacement (implements Service routing) and a CNI plugin (gives each pod an IP).
The objects you'll use, from small to large:
Object
What it is
Use it for
Pod
One or more containers sharing a network namespace and volumes; the unit of scheduling
Never directly in production: a bare pod isn't recreated if its node dies
Deployment
Manages ReplicaSets to keep N identical, interchangeable pods, with rolling updates
Stateless services, APIs, stream consumers
StatefulSet
Pods with stable names (kafka-0), stable per-pod volumes and ordered rollout
Kafka, ZooKeeper, databases
DaemonSet
One pod per node
Log shippers, node exporters, CNI agents
Job / CronJob
Pods that run to completion, with retries; on a schedule
Batch ETL, backfills, dbt runs
Service
A stable virtual IP and DNS name in front of a changing set of pods selected by label
Anything another pod calls
Ingress / Gateway
HTTP routing from outside the cluster to Services
Public APIs, UIs
ConfigMap / Secret
Configuration and credentials mounted as files or env vars
Config that changes without rebuilding the image
PVC / PV
A claim for storage, bound to a volume (an EBS disk on AWS)
State that must survive pod restarts
Labels are the glue. A Service doesn't list pods; it selects every pod with app=orders-api. A Deployment owns pods through a label selector. Get a label wrong and traffic goes nowhere, with no error anywhere.
Interview angle
"What happens when you run kubectl apply -f deployment.yaml?" The API server authenticates, authorises and runs admission (mutating then validating webhooks), then persists to etcd. The Deployment controller creates a ReplicaSet; the ReplicaSet controller creates Pod objects with no node; the scheduler filters and scores nodes and binds each pod; the kubelet on that node sees the binding, pulls the image, sets up networking through CNI and starts the containers; once readiness passes, the pod's IP is added to the Service's EndpointSlices. Every step is a controller reacting to a change.
18.2
Requests, limits, QoS and probes
Every container should declare requests and usually limits, and they do different jobs. Requests are what the scheduler reserves: a pod is placed only on a node with enough unreserved capacity, and a CPU request becomes the container's weight when CPU is contended. Limits are what the kernel enforces at runtime. The two resources fail differently. Go over the CPU limit and the container is throttled: slowed down, never killed. Go over the memory limit and it's OOMKilled, because memory can't be taken back from a running process.
The combination sets the pod's QoS class, which decides who is evicted first when a node runs short of memory: Guaranteed (requests equal limits for every container), Burstable (some requests set) and BestEffort (nothing set; first to go). Common production practice: set memory request equal to memory limit so the pod can't be surprised by node pressure, set a CPU request, and think hard before setting a CPU limit. CPU limits throttle latency-sensitive services even when the node has idle cores, because the quota is enforced per 100 ms period: a burst of GC threads can use the whole period's quota in 20 ms and then stall for 80.
Probes tell Kubernetes about health, and confusing them causes outages. The readiness probe decides whether the pod receives traffic: failing it removes the pod from the Service but leaves it running. The liveness probe decides whether to restart the container. The startup probe holds off the other two until a slow-starting app is up. The dangerous pattern is a liveness probe that checks a dependency (database, Kafka): when the database blips, every pod fails liveness at once and Kubernetes restarts the entire fleet, turning a short dependency hiccup into a full outage. Liveness should answer only "is this process wedged?"; dependency checks belong in readiness, if anywhere.
The classic gotcha
A JVM service with a 10-second liveness timeout and no startup probe. Under load, startup takes 90 seconds, liveness fails at 30, the container restarts and starts again from scratch: CrashLoopBackOff under exactly the conditions where you need more pods. Add a startup probe with a generous failureThreshold × periodSeconds.
18.3
Networking, storage and config
Every pod gets its own IP, and every pod can reach every other pod without NAT. That's the Kubernetes network model; the CNI plugin implements it. Pod IPs are ephemeral, so clients use a Service: a stable ClusterIP and a DNS name (orders-api.payments.svc.cluster.local) that load-balances across the ready pods behind it. A headless Service (no ClusterIP) instead returns each pod's address, which is what StatefulSets like Kafka need so a client can reach kafka-2 specifically. NetworkPolicies restrict which pods may talk to which; without them, everything in the cluster can reach everything.
DNS is a quiet source of latency. Pod resolv.conf defaults to ndots:5 with several search domains, so a lookup for api.example.com (two dots) is first tried as api.example.com.payments.svc.cluster.local and three more suffixes before the real name: five or more queries per lookup, each doubled for IPv4 and IPv6. Under load this saturates CoreDNS and shows up as intermittent 5-second timeouts. Fixes: use fully qualified names with a trailing dot, lower ndots in the pod's dnsConfig, and run NodeLocal DNSCache.
Storage. A PersistentVolumeClaim asks for storage of a StorageClass (on EKS, an EBS gp3 volume through the EBS CSI driver). An EBS volume lives in one availability zone and attaches to one node at a time, so a pod with an EBS volume can only be rescheduled to a node in that zone. If that zone has no capacity, the pod stays Pending. Use volumeBindingMode: WaitForFirstConsumer so the volume is created in the zone where the pod lands, and keep spare capacity per zone for stateful workloads. Use EFS or S3 when many pods need shared data.
Config. ConfigMaps and Secrets mounted as files update in the pod eventually after you change them; mounted as env vars they never update until the pod restarts. Kubernetes Secrets are base64-encoded, not encrypted, unless envelope encryption with KMS is enabled; on AWS, store the source of truth in Secrets Manager and sync it in with the External Secrets Operator or the Secrets Store CSI driver.
Interview angle
"How does a request from pod A reach pod B through a Service?" Pod A resolves the Service name with CoreDNS and gets the ClusterIP. That IP doesn't belong to any machine: kube-proxy (iptables or IPVS rules) or an eBPF data plane like Cilium on A's node rewrites the destination to one of the ready pod IPs from the Service's EndpointSlices. The packet then travels over the CNI's pod network to B's node.
18.4
Deploying safely and debugging pods
A Deployment's rolling update replaces pods gradually, controlled by maxSurge (extra pods allowed above the desired count) and maxUnavailable (pods allowed below it). It only moves on when new pods pass readiness, so a bad readiness probe either stalls the rollout (good) or lets a broken version through (if the probe checks nothing). kubectl rollout undo returns to the previous ReplicaSet. For riskier changes, use a canary (a small share of traffic to the new version, promoted on metrics, often with Argo Rollouts or Flagger) or blue/green (a full second copy, switched at once).
Graceful shutdown is where zero-downtime deploys usually fail. When a pod is deleted, two things happen in parallel: the kubelet sends SIGTERM, and the endpoint controller removes the pod from Services. If the app exits before every node's routing has caught up, in-flight requests hit a closed socket and clients see 502s. Add a short preStop sleep (5–10 s) so routing updates first, handle SIGTERM by draining, and set terminationGracePeriodSeconds longer than your slowest request or batch commit.
Protect capacity during maintenance with a PodDisruptionBudget (for example minAvailable: 2), which limits how many pods voluntary disruptions such as node drains and upgrades can evict at once. Scale with the HorizontalPodAutoscaler (more pods from CPU, memory or custom metrics such as Kafka consumer lag, often through KEDA) and the node autoscaler (Cluster Autoscaler or Karpenter adds nodes when pods are Pending).
The classic gotcha
A PDB with maxUnavailable: 0, or minAvailable equal to the replica count, can never be satisfied. Node drains hang forever and a cluster upgrade stalls halfway with mixed node versions. The same happens when a single-replica Deployment has minAvailable: 1. Every PDB must allow at least one disruption.
Interview angle
"A deploy just went out and error rates are up. What do you do?" Roll back first (kubectl rollout undo or revert in GitOps), confirm the error rate recovers, then investigate with the evidence you preserved: the diff between the two ReplicaSets, events, logs from the new pods and the image digest. Mitigation before diagnosis is the answer that signals production experience.
Amazon EKS is managed Kubernetes. AWS runs the control plane (API servers and etcd across three availability zones, patched and backed up for you) and charges a per-cluster hourly fee. You run the data plane, in one of four ways: managed node groups (EC2 Auto Scaling groups that EKS creates and can roll during upgrades), self-managed nodes, Fargate (a micro-VM per pod; no nodes to manage, but no DaemonSets, no GPUs and slower starts), or EKS Auto Mode, where AWS also manages nodes, the CNI, storage drivers and the load balancer controller.
Karpenter is the node autoscaler most EKS teams now use instead of Cluster Autoscaler. Cluster Autoscaler grows pre-defined node groups; Karpenter looks at Pending pods and launches whichever EC2 instance types fit them best, across Spot and On-Demand, and consolidates underused nodes. That flexibility is what makes Spot workable for Spark executors and stream workers.
Networking: the VPC CNI. By default, every pod gets a real VPC IP address from the node's subnet, attached through the node's elastic network interfaces. Pods are first-class on the VPC (security groups, flow logs, no overlay), but it has two sharp edges. Subnet exhaustion: a /24 has about 250 usable addresses, and each node pre-allocates a warm pool of IPs, so a busy cluster runs out of addresses long before it runs out of CPU, and new pods sit in ContainerCreating with "failed to assign an IP address". Max pods per node is capped by the instance type's ENI and IP limits, so a small instance holds far fewer pods than its CPU could. Fixes: plan large subnets up front (or add a secondary CIDR such as 100.64.0.0/10 for pods), enable prefix delegation (a /28 per ENI slot), and tune WARM_IP_TARGET.
Identity: two directions.Who can use the cluster: IAM principals are mapped to Kubernetes RBAC through access entries, which replaced the old aws-auth ConfigMap (a single YAML file where one bad edit could lock every admin out of the cluster). What pods can do in AWS: EKS Pod Identity or the older IRSA (IAM roles for service accounts) give each service account its own IAM role, with temporary credentials. The anti-pattern is giving the node's instance role S3 and DynamoDB access, because then every pod on that node inherits it.
Interview angle
"Pods are stuck in ContainerCreating on EKS but the nodes have free CPU." Describe the pod: if the event says it can't assign an IP, it's subnet or ENI exhaustion in the VPC CNI. Check free IPs in the node subnets and the instance type's max pods. Fix with prefix delegation or a secondary CIDR, and say you'd add an alarm on available subnet IPs so it's caught before it pages.
19.2
EKS upgrades without an outage
Kubernetes ships a minor version roughly every four months, and EKS supports each one for about 14 months of standard support, followed by a paid extended-support period. Upgrades are therefore routine, frequent and impossible to skip: the control plane moves one minor version at a time, and nodes can lag the control plane only by a limited skew. A team that ignores upgrades eventually faces several back-to-back jumps or a large extended-support bill.
The safe order:
1Read the changelog for removed APIsScan manifests and Helm charts with pluto or kubent; check EKS upgrade insights. A removed API version makes later deploys fail.
2Upgrade a non-production cluster firstRun real workloads on it for days, including a node drain, and test the add-ons you depend on.
3Upgrade the control planeEKS does this in place. Your workloads keep running; the API is briefly less available.
5Roll the nodesCordon and drain old nodes in batches; PDBs pace the evictions. Or use a blue/green node group and move workloads over.
What actually breaks: removed API versions (deploy pipelines fail after the upgrade, not during it); PDBs that block drains; add-ons pinned to old versions; webhooks whose backing pods are down, which makes the API server reject every create or update they intercept; and implicit dependencies on behaviour that changed, such as node labels, as in the Reddit outage in §21.4. Many teams sidestep in-place risk with blue/green clusters: build a new cluster at the new version, shift traffic gradually, delete the old one. That needs GitOps (Argo CD or Flux) so the second cluster is reproducible from Git rather than from memory.
Interview angle
"How do you upgrade a production EKS cluster?" Give the order above, then the two strategies (in-place with node-group rolls, or blue/green clusters) and when you'd pick each. Mention API deprecation scanning and PDBs by name. Saying "I'd click upgrade in the console" without a staging cluster or a rollback story is the answer that loses.
19.3
EMR: three ways to run Spark on AWS
Amazon EMR runs open-source big-data engines (Spark, Hive, Trino, Flink, HBase) with AWS-tuned builds and S3 integration. It comes in three deployment shapes, and choosing between them is a common design question.
Option
What you manage
Pick it when
Watch out for
EMR on EC2
Clusters of EC2 instances running YARN; you size and configure them
Long-running or heavy clusters, custom config, HBase, maximum control and Spot savings
Idle clusters cost money; you tune YARN and Spark yourself
EMR Serverless
Only the application and job; AWS provisions workers per job
Spiky or infrequent batch jobs; small teams with no cluster ops
Less tuning control; cold start; cost per job can exceed a well-packed cluster
EMR on EKS
Spark pods on your EKS cluster, with EMR's runtime
You already run EKS and want one compute pool and one ops model for services and Spark
You need Kubernetes expertise; shuffle on ephemeral pods; executor pod startup
On EMR on EC2, a cluster has three node types. The primary node runs the YARN ResourceManager and HDFS NameNode; lose it and the cluster is gone unless you configured three primaries. Core nodes run executors and store HDFS blocks, so losing one loses data and shrinking them is slow. Task nodes run executors only and store nothing. Put Spot on task nodes, keep core nodes on On-Demand, and use instance fleets with several instance types so a Spot shortage in one type doesn't stall the job. Use S3 (not HDFS) as the durable store, and treat clusters as disposable: one transient cluster per pipeline, created by the orchestrator, terminated on completion.
Interview angle
"EMR on EC2, Serverless, or on EKS?" Start from workload shape and team: steady heavy batch with tuning needs points to EC2 with Spot task fleets; bursty jobs and no platform team point to Serverless; an organisation already standardised on EKS points to EMR on EKS. Pinterest's move of its Spark platform from Hadoop to EKS (§22.3) is a good story to cite.
19.4
EMR failure cases and fixes
"Container killed by YARN for exceeding memory limits. 10.4 GB of 10 GB physical memory used. Consider boosting spark.executor.memoryOverhead." YARN sizes each executor container as heap plus overhead (by default the larger of 384 MB or 10% of executor memory). Overhead covers off-heap allocations: Python worker processes in PySpark, Arrow buffers for pandas UDFs, netty shuffle buffers. PySpark jobs exceed it routinely. Raise spark.executor.memoryOverhead (or set spark.executor.pyspark.memory), use fewer cores per executor so fewer Python workers share it, and fix the skewed partition that's usually the real cause (Chapter 6).
Executors lost on Spot reclaim, then FetchFailedException. When a Spot node is reclaimed, its executors die, and so do the shuffle files they wrote; downstream stages fail to fetch them and recompute whole stages. Enable Spark's graceful decommissioning so shuffle blocks migrate when the two-minute interruption notice arrives, keep shuffle-heavy stages on On-Demand, or use a remote shuffle service so shuffle data outlives executors.
S3 503 "Slow Down". S3 scales request rate per prefix (about 3,500 writes and 5,500 reads per second per prefix), and a job with thousands of tasks writing to one partition prefix hits it. Spread writes across prefixes, cut the number of output files (repartition before writing), and raise EMRFS retry settings. The deeper fix is fewer, larger files, which also fixes read performance.
Cluster stuck in "Starting" or terminates with VALIDATION_ERROR or BOOTSTRAP_FAILURE. A bootstrap action failed (a pip install that hits an unreachable mirror is the classic), the subnet has no free IPs or the requested instance type has no capacity in that AZ, or the IAM roles lack permissions. Bake dependencies into a custom AMI or a container image instead of installing them at boot, and give instance fleets several instance types and subnets.
Disk full on core nodes. Shuffle spill and YARN logs fill local disks, nodes are marked unhealthy, YARN stops scheduling on them and the job crawls. Size EBS volumes for shuffle, reduce spill (more partitions, less skew) and ship logs to S3.
Idle clusters. A long-running cluster no one uses is the most common EMR cost incident. Set an auto-termination idle timeout on every cluster and use managed scaling so the cluster shrinks between jobs.
The classic gotcha
Managed scaling removes a core node while it holds the only replica of some HDFS blocks, or while jobs still need intermediate data stored there, and the job fails. Keep the core node count fixed and small, scale only task nodes, and keep durable data in S3.
§8.1 introduced the log: topics split into partitions, each an append-only, ordered sequence of records addressed by offset. This chapter goes underneath. On disk, each partition is a directory of segments: a .log file of record batches plus an offset index and a time index. Only the newest (active) segment is written to. Retention deletes or compacts whole closed segments, which is why a topic with retention.ms of one hour can keep data much longer if a segment takes a day to fill (segment.ms and segment.bytes control rolling). Reads are fast because they're sequential and served from the OS page cache, and the broker sends bytes from page cache to socket without copying them through the JVM.
Replication. Each partition has one leader and replication.factor − 1followers on other brokers, ideally in other racks or AZs (broker.rack). Producers and consumers talk to the leader (consumers can read from a nearby follower with rack-aware fetching). Followers pull from the leader. The in-sync replicas (ISR) are the replicas that have caught up within replica.lag.time.max.ms. The high watermark is the highest offset copied to every ISR member, and consumers only see records below it, so a consumer never reads something that could vanish in a leader failover.
Durability is three settings working together.replication.factor=3, min.insync.replicas=2 and producer acks=all. With those, a write is acknowledged only once at least two replicas have it, so any single broker can die without losing acknowledged data. If the ISR shrinks below 2, producers with acks=all get NotEnoughReplicas errors: Kafka chooses unavailability over silent loss. unclean.leader.election.enable=false (the default) keeps that promise by refusing to elect an out-of-sync replica as leader.
Metadata: KRaft. Kafka used to keep cluster metadata in ZooKeeper. KRaft moves it into an internal Raft-replicated log run by a quorum of controller nodes, which makes failover faster and supports far more partitions. Kafka 4.0 removed ZooKeeper mode entirely, so a ZooKeeper cluster must migrate to KRaft on 3.x before upgrading.
Interview angle
"How do you guarantee no data loss in Kafka?" Say the three settings and what each covers, then the trade-off: with min.insync.replicas=2 on RF 3, losing two brokers blocks writes to affected partitions. Then go past the broker: the producer needs retries with idempotence, and the consumer must commit offsets only after processing (§20.3). Loss usually happens at the edges, not inside Kafka.
20.2
Producers: batching, ordering and idempotence
A producer picks the partition from the key (a hash of the key modulo the partition count; no key spreads records across partitions in sticky batches), buffers records per partition and sends a batch when it reaches batch.size or linger.ms expires. Raising linger.ms from 0 to 5–20 ms and enabling compression (lz4 or zstd) usually multiplies throughput for a few milliseconds of latency, because compression works on whole batches.
Ordering is per partition only, and only for records with the same key landing on the same partition. Two traps follow. First, adding partitions changes the key-to-partition mapping, so after an increase, new events for a key go to a different partition than old ones and per-key order across that moment is lost. Pick the partition count up front for keyed topics. Second, retries could reorder batches when several are in flight, which is why the idempotent producer exists.
Idempotence (enable.idempotence=true, the default since Kafka 3.0) gives each producer an id and each batch a sequence number per partition. The broker drops duplicates from retries and rejects out-of-order sequences, so retries can't create duplicates or reorder, even with up to five requests in flight. It covers one producer session against one partition. Transactions (transactional.id) extend that to atomic writes across partitions plus the consumer's offset commit: consume, process, produce and commit offsets as one unit, which is the basis of Kafka Streams' and Flink's exactly-once (§8.3). Consumers must read with isolation.level=read_committed to skip aborted writes.
# a durable, high-throughput producer
acks=all
enable.idempotence=true
max.in.flight.requests.per.connection=5 # <= 5 keeps ordering with idempotence
linger.ms=10
batch.size=131072
compression.type=zstd
delivery.timeout.ms=120000 # total time to keep retrying before failing the send
The classic gotcha
Calling producer.send() and never checking the result. Sends are asynchronous; an error after retries are exhausted arrives on the callback or future. If the app ignores it, or exits without flush(), buffered records are silently lost. Always handle the callback, and flush or close the producer on shutdown.
20.3
Consumers: groups, rebalances and commits
Consumers in the same group split a topic's partitions between them: each partition goes to exactly one consumer in the group, so the partition count is the maximum useful parallelism. A consumer's progress is its committed offset per partition, stored in the internal __consumer_offsets topic. When it restarts, it resumes from the committed offset, and when you commit decides your delivery semantics.
Rebalances reassign partitions when a consumer joins, leaves or is presumed dead. A consumer is presumed dead if it misses heartbeats for session.timeout.ms, or if it doesn't call poll() within max.poll.interval.ms (five minutes by default). The second causes the infamous rebalance storm: a batch takes longer than the poll interval to process, the consumer is kicked out, its partitions move, the new owner reprocesses the uncommitted batch, also takes too long, and the group never makes progress. Fix it by lowering max.poll.records, making processing faster, or raising max.poll.interval.ms.
The classic eager rebalance protocol stops every consumer in the group while partitions move. Three improvements reduce the pain: the cooperative sticky assignor moves only the partitions that must change; static membership (group.instance.id) lets a restarting pod reclaim its partitions without a rebalance, which makes rolling deploys on Kubernetes much calmer; and the newer consumer group protocol (KIP-848) moves assignment to the broker and makes rebalances incremental by default.
Consumer lag is the gap between the latest offset and the committed offset, per partition. It's the most important streaming health metric: rising lag means the consumers can't keep up. Alert on lag expressed as time (how old the oldest unprocessed record is), not raw message count, since a count means different things on different topics. Scale consumers up to the partition count, then speed up processing; past that, only more partitions help.
Interview angle
"Consumers keep rebalancing and lag grows. What's happening?" Ask for the logs first: "member left the group because poll timeout expired" points to max.poll.interval.ms and slow processing; heartbeat timeouts point to GC pauses or CPU throttling (a Kubernetes CPU limit, §18.2); rebalances at every deploy point to missing static membership. Each has a different fix.
20.4
Operating Kafka: design and edge cases
Partition count. Enough for target consumer parallelism and throughput (a partition handles on the order of 10 MB/s comfortably; measure on your hardware), with headroom, because increasing it later breaks key ordering. Not wildly more: every partition costs file handles, memory, and leader-election and recovery time.
Hot partitions. One key carries a large share of traffic (a giant merchant, a bot user, a null key that every bad record shares), so one partition, one broker and one consumer saturate while the others idle. Detect it with per-partition byte rates and per-partition lag. Fix it by salting the key (merchant_id + random(0..N)), accepting the loss of strict per-key order, or by routing known heavy keys to a dedicated topic.
Poison pills. One record that can't be deserialised or processed blocks its partition forever if the consumer retries in place. Uber's answer, now standard, is a ladder of retry topics with growing delays and a final dead letter queue (§22.1): failed records move aside, the partition keeps flowing, and the DLQ is monitored and replayed after a fix.
Schemas. Use a schema registry with Avro or Protobuf and enforce a compatibility mode (usually BACKWARD) on each subject, so a producer can't deploy a breaking change such as removing a required field or changing a type. That's the streaming version of the schema-drift problem in Chapter 3.
Compaction.cleanup.policy=compact keeps the latest record per key, and a record with a null value (a tombstone) deletes the key after delete.retention.ms. It's the right store for changelogs and CDC state. Edge cases: compaction never touches the active segment, so "latest only" is eventual; and consumers that are offline longer than delete.retention.ms can miss tombstones and keep deleted keys forever.
Running it. Managed (Amazon MSK, Confluent Cloud) removes broker operations; self-managed on Kubernetes uses an operator such as Strimzi, StatefulSets, a PDB that allows one broker down, and rack awareness mapped to AZs. Tiered storage (KIP-405, which Uber drove upstream) moves older segments to object storage, so brokers keep only recent data on local disk, recover faster and decouple retention from disk size. Cross-region replication uses MirrorMaker 2 or Uber's uReplicator design; plan for offset translation on failover because offsets differ between clusters.
Interview angle
"Design the Kafka topic for ride events." Give the key (ride_id, for per-ride order), partition count from throughput and consumer parallelism with headroom, RF 3 with min.insync.replicas=2 across AZs, retention from the replay window you need, the schema and its compatibility rule, the DLQ path, and the lag alert. Ending with how you'd replay after a bad deploy (reset the group's offsets to a timestamp) shows you've operated one.
Contents · Chapter 21 · Production failures casebook
21.1
How to handle a production incident
Interviewers ask about failures because they show judgement under pressure better than any design question. The structure they're listening for is always the same, whatever broke.
1Detect and declareAn alert or a user report. Name an incident lead and open one channel. Write a timeline as you go.
2Size the blast radiusWho and what is affected: one pipeline or every consumer, one region or all, data delayed or data wrong.
3Mitigate before you diagnoseRoll back the last change, fail over, pause the pipeline so it stops writing bad data, scale up. Stop the bleeding first.
4Find the root causeUse the evidence you preserved: diffs, events, logs, metrics around the first bad minute. Ask "what changed?".
5Repair the dataBackfill or reprocess the affected window, idempotently (§10.2). Tell downstream owners what was wrong and when it was fixed.
6Blameless postmortemTimeline, root cause and contributing factors, what went well, and owned, dated action items that stop the whole class of failure.
Two habits separate senior answers. "What changed?" comes first, because most incidents follow a deploy, a config change, a dependency upgrade or a data change upstream. And for data, wrong is worse than late: if a pipeline is writing incorrect numbers, pausing it and letting a dashboard go stale is usually the right call, because bad data spreads into downstream tables, models and decisions, and every copy has to be found and repaired.
Interview angle
"Tell me about a production failure you handled." Use the six steps as your outline, with numbers: how it was detected and how long that took, the blast radius, the mitigation and time to mitigate, the root cause in one sentence, the data repair, and the one action item that prevents the class of failure. End with what you'd do differently. That last part is what the interviewer is really scoring.
21.2
Deployment and installation failures
The failures you'll actually meet when shipping to Kubernetes, EKS and Helm, by symptom. The first column is what you see; the fix column lists the usual causes in order of likelihood.
Symptom
Likely cause
Fix
ImagePullBackOff
Wrong tag or digest; no pull permission (ECR policy, node role, expired pull secret); image built for the wrong architecture is a different error but often found here
kubectl describe pod shows the registry error. Check the image exists, the node or service account can pull it, and the registry is reachable from private subnets (VPC endpoints or NAT)
CrashLoopBackOff
App exits at startup: missing env var or secret, bad config, failed DB connection, liveness probe killing a slow start
kubectl logs --previous for the crashed container; check exit code; add a startup probe
CreateContainerConfigError
A referenced Secret or ConfigMap, or a key in it, doesn't exist in that namespace
Create it, or fix the name and key; deploy config before the workload in your pipeline
Pending
No node fits the requests; node selector, affinity or taint with no match; PVC in a zone with no capacity; IP exhaustion
Events on the pod say which. Lower requests, fix selectors and tolerations, check the autoscaler's logs
OOMKilled (exit 137)
Memory limit below real peak use; memory leak; JVM heap sized to the node, not the container
Measure peak, raise the limit with headroom, set MaxRAMPercentage, profile the leak
Running but 503 / no endpoints
Service selector doesn't match pod labels; readiness probe failing; wrong targetPort
kubectl get endpointslices; compare labels; test the readiness path from inside the pod
502s during every deploy
Pods exit before load balancers and kube-proxy stop routing to them
preStop sleep, handle SIGTERM by draining, longer grace period (§18.4)
"failed calling webhook"
An admission webhook's service is down (or its certificate expired), and its failurePolicy: Fail blocks creates cluster-wide
Restore the webhook's pods or temporarily delete the webhook configuration; run webhooks with several replicas and exclude system namespaces
Helm: "another operation is in progress"
A previous release was interrupted and left in pending-upgrade or pending-install
helm history, then helm rollback to the last good revision; use --atomic and --timeout in CI
"no matches for kind … in version …"
The manifest uses an API version the cluster removed, or a CRD isn't installed yet
Update the apiVersion; install CRDs before the charts that use them; scan with pluto before upgrades
Terraform: state lock / drift
A crashed run holds the lock; someone changed resources by hand
Confirm no run is active, then force-unlock; run plan to see drift and bring the change into code
Nodes NotReady after a change
Kubelet or CNI broken by an AMI or OS update; disk or memory pressure; expired node certificates
Describe the node; check kubelet and CNI logs; roll back the AMI; stagger OS updates
TLS errors everywhere at once
An expired certificate (ingress, webhook, internal CA, Kafka listeners)
Renew; then automate it (cert-manager) and alert 30 days before expiry
The classic gotcha
A database migration bundled into the app's startup. Ten replicas start at once, all try to migrate, one takes a lock, the others hang on it, fail their startup probes and restart, and the deploy never finishes. Run migrations once as a separate Job (or a Helm pre-upgrade hook) and make them backward-compatible with the running version, so the old and new pods can share the schema during the rollout.
21.3
Data pipeline and Kafka failures
Symptom
Root cause
Solution
Data missing after consumer deploy
New consumer group id with auto.offset.reset=latest: it started at the end and skipped everything produced while it was down
Reset the group's offsets to a timestamp before the gap and reprocess; set earliest for new groups that must not lose data
Duplicates after a restart
Processed records, crashed before committing; at-least-once delivery working as designed
Make the sink idempotent: upsert or MERGE on a key, or dedup on an event id
Lag grows, then rebalance storm
Processing per poll exceeds max.poll.interval.ms; or GC pauses or CPU throttling miss heartbeats
Smaller max.poll.records, faster processing, static membership; remove CPU limits from consumers
One partition lags, others fine
Hot key or poison-pill record blocking the partition
Salt hot keys; retry topics and a DLQ for bad records
Consumers fail after producer deploy
Incompatible schema change (field removed, type changed)
Roll back the producer; enforce compatibility in the schema registry; CI check on schema changes
Producers fail with NotEnoughReplicas
ISR shrank below min.insync.replicas: broker down, disk full, network partition
Restore brokers or disk; never "fix" it by lowering durability settings in an incident without deciding the trade-off
Kafka disk full
Retention by size not set; a topic with far more traffic than planned; a compacted topic that can't compact
Add retention bytes, expand disks, move old data with tiered storage, alert on disk at 70%
Spark job that ran for a year now OOMs
Data grew or skew appeared: one key now dominates a join or groupBy
Hundreds of parallel tasks reading production with no limit
Read from a replica or snapshot export; limit concurrency with pools; run off-peak
Daily totals off twice a year
Daylight-saving shifts with local-time partitioning: a 23- or 25-hour day
Store and partition in UTC; convert to local time at the presentation layer
Rerun doubled yesterday's revenue
Load appends instead of overwriting the partition
Idempotent writes: overwrite the partition or MERGE on key (§10.2)
Warehouse bill spikes overnight
A query with a missing filter or a cross join, scheduled hourly; an auto-scaling warehouse with no cap
Resource monitors and budgets, query timeouts, cost alerts per pipeline
Interview angle
"After a deploy, a dashboard shows a dip for 40 minutes, then normal." Two different stories fit and you should name both: data delayed (lag during a rebalance, then catch-up, which fixes itself once late data lands if your windows allow it) or data lost (offsets reset to latest, which never fixes itself). Then say how you'd tell them apart: compare source counts with sink counts for the window, and check the consumer group's offset history.
21.4
Real postmortems worth knowing
Reddit, Pi Day 2023: a Kubernetes upgrade. Reddit upgraded a large, old cluster from Kubernetes 1.23 to 1.24 and the site went down for over five hours. Kubernetes 1.24 stopped applying the node-role.kubernetes.io/master label in favour of control-plane. Reddit's networking relied on route reflectors whose node selectors still matched the old label; the configuration lived nowhere in code, and the people who knew about it had left. With the label gone, the route reflectors disappeared and pod networking broke. Restoring the control plane from backup was considered but was untested and risky. Lessons: test upgrades on a cluster as old and odd as production, keep all configuration in code, rehearse restore procedures, and read the removed-behaviour notes, not just removed APIs. Reddit's postmortem.
Datadog, March 2023: an OS update in every region at once. A systemd security update was installed automatically on tens of thousands of Ubuntu 22.04 nodes during the same 06:00–07:00 UTC window in five regions. Restarting systemd-networkd deleted the routes managed by Cilium, the cluster's CNI, so the nodes dropped off the network. Freshly booted nodes didn't show the problem (the ordering differed at boot), which is why tests missed it. Full recovery and data backfill took about two days. Lessons: no change, including OS patches, should bypass staged rollout; identical schedules across regions defeat regional isolation; and test the "restart on a running node" path, not only fresh boots. Datadog's postmortem.
GitLab, January 2017: the wrong database. During a replication incident, an engineer ran a directory deletion on the primary database server instead of the secondary, removing about 300 GB of production data. Then it emerged that the backup methods didn't work as assumed: backups were failing silently and alerts went unseen. A six-hour-old staging snapshot saved most of the data. Lessons: a backup you haven't restored isn't a backup; make the prompt show which host you're on; and guard destructive commands. GitLab's postmortem.
Citing one of these when asked "how would you upgrade a cluster?" or "how do you know your backups work?" lands well, if you take the mechanism from it, not just the headline. "Reddit lost hours because a selector depended on a label 1.24 removed, so I'd grep our config for deprecated labels and test on a cluster built the same way as production" is the useful version.
Contents · Chapter 22 · Lessons from engineering blogs
22.1
Uber: the data platform and Kafka
Uber has published more about data infrastructure at scale than almost any other company, and its articles map directly onto interview questions. Read each one for the problem, the mechanism and the trade-off, not the scale numbers.
Uber's Big Data Platform: 100+ Petabytes with Minute Latency (2018). Four generations in one article. A Vertica warehouse fed by fragile, schema-less JSON ETL gave way to a Hadoop data lake (raw data ingested once, Parquet, Hive, Presto, Spark, a central schema service). That scaled, but data was a day stale, snapshot ingestion took over 20 hours on more than 1,000 executors, small files strained the HDFS NameNode, and HDFS plus Parquet couldn't update rows. The fix was Hudi: upserts and deletes on Parquet, plus incremental pulls of only the records changed since a checkpoint. Latency fell from 24 hours to under one hour. Use it for: "why lakehouse table formats exist" (Chapter 9), and "full snapshot versus incremental load".
Building Reliable Reprocessing and Dead Letter Queues with Kafka (2018). Because a consumer commits only after success, one failing message blocks its whole partition. Uber redefined success as reaching a conclusive result: a message that fails moves to a retry topic, then to retry topics with longer delays, and finally to a DLQ, where it can be inspected, purged or merged back once fixed. Use it for: poison pills and error handling in any streaming design (§20.4).
uReplicator: Uber's Robust Kafka Replicator (2016). MirrorMaker's consumer rebalances stalled cross-datacentre replication for 5–10 minutes at a time, adding a topic needed a restart, and auto-commit could lose data. Uber replaced group rebalancing with a Helix controller that assigns partitions to workers explicitly, and committed offsets only after the data was persisted at the destination. Use it for: why rebalances hurt (§20.3) and "commit after the side effect" as a general rule.
Chaperone: auditing Kafka end to end (2016). Messages are bucketed into 10-minute windows by event time, and each tier of the pipeline reports counts per window; comparing tiers shows where data was lost or duplicated, and how much. Use it for: "how would you know your pipeline is losing data?". Count reconciliation per window, per hop, is the answer.
Kafka Tiered Storage (2024). Local disks made retention expensive, because more retention meant more brokers with CPU and memory you didn't need. KIP-405 keeps recent segments local and older ones in object storage, with no client changes. Use it for: separating storage from compute, the same idea as Snowflake and lakehouses.
Real-time Data Infrastructure at Uber (SIGMOD 2021 paper). The whole real-time stack in one place: Kafka, Flink, Pinot, HDFS and Presto, with the requirements each serves (freshness, availability, consistency, cost) and where they conflict. The best single reading for a streaming system design round.
Interview angle
Cite an article as evidence for a design choice, not as a credential. "I'd put failing records on a retry topic with a delay and a DLQ, the pattern Uber published, so one bad record can't block a partition" is strong. "Uber uses Kafka" is not an argument.
22.2
LinkedIn, Netflix and Airbnb
The Log: What every software engineer should know about real-time data's unifying abstraction (Jay Kreps, LinkedIn, 2013). The essay behind Kafka. An append-only, ordered log is the common thread through database replication, data integration and stream processing: if every system consumes the same ordered log of changes, they all converge to the same state. It explains why LinkedIn replaced a tangle of point-to-point pipelines with one central log. Use it for: any question about CDC, event sourcing, or why Kafka is a log and not a queue.
Netflix Keystone (InfoQ coverage, 2018). Netflix's real-time platform routes trillions of events a day from Kafka into sinks such as S3 and Elasticsearch, and grew into a self-service stream processing platform on Flink where teams declare a pipeline and the platform runs it. Use it for: platform thinking: multi-tenant streaming, isolation between tenants, and making the common path self-service.
Data Quality at Airbnb (2020) and How Airbnb Built "Wall" to prevent data bugs. Data quality is treated as an ownership and process problem first: certified datasets with named owners, design reviews and enforced standards, then a shared check framework built into pipelines so a failing check stops bad data before it's published. Use it for: "how do you ensure data quality?", where the strong answer covers ownership, contracts and blocking checks, not just a testing library.
Interview angle
"Queue or log?" Kreps' essay gives the answer: a queue deletes a message once consumed and has one logical consumer per message; a log retains records in order and lets any number of consumers read independently, at their own pace, and replay. That retention and replay is what makes Kafka work as both a pipe and a source of truth.
22.3
DoorDash and Pinterest
DoorDash: from zero to a hundred billion events (QCon talk). DoorDash moved its real-time event processing from a mix of SQS and Kinesis to a unified platform on Kafka and Flink, with a proxy in front of Kafka so services and apps publish over a simple API without each embedding Kafka clients, and with self-service onboarding and schema enforcement. Use it for: "build versus buy versus consolidate" decisions, and why a producer proxy is useful at scale (one place for auth, schemas, batching and quotas).
Pinterest Moka: next-gen data processing (two parts) and the AWS write-up on its Spark logging and monitoring on EKS. Pinterest moved its Spark platform from Hadoop and YARN to Spark on Amazon EKS, with a batch scheduler (Apache YuniKorn) for queues and fairness, and rebuilt the things YARN used to give for free: job logs, history, metrics and resource isolation. Use it for: the "EMR or EKS for Spark?" question (§19.3), with real costs: you gain one compute platform and container images, and you take on scheduling, shuffle and observability work.
Interview angle
Both stories are migrations, and migrations are a favourite senior topic. The shape to describe: why the old system stopped fitting (with a measurable pain), how they ran old and new side by side, how they compared outputs before switching, and what they had to rebuild that the old platform did implicitly.
22.4
How to read and use an engineering blog
Company blogs are the best free source of production experience, but they're written to recruit and they describe the success, rarely the cost. Read each one with five questions and write the answers down in a few lines:
Question
Why it matters
What hurt?
The measurable pain that forced the change (latency, cost, incidents, toil). This is the part you'll reuse in interviews.
What's the mechanism?
The one idea that removed the pain: incremental upserts, retry topics, explicit partition assignment.
What did it cost?
New components to run, new failure modes, lost guarantees (Hudi's write amplification, salted keys losing order).
Would it apply at 1/100th the scale?
Most companies don't need Uber's solution. Knowing when not to copy it is a senior signal.
What's the open-source or managed equivalent today?
Hudi, Iceberg and Delta; KIP-405 tiered storage; MSK; EMR on EKS. Articles age; the ideas don't.
Good places to keep reading: the engineering blogs of Uber, Netflix, Airbnb, LinkedIn, DoorDash, Pinterest, Lyft, Spotify, Shopify, Stripe and Cloudflare; public postmortems (Cloudflare and GitLab write unusually detailed ones); the Kubernetes Failure Stories collection; and papers from VLDB and SIGMOD industry tracks, where these companies publish the deeper versions.
Interview angle
"What's an interesting engineering article you've read recently?" Prepare two, answered with the five questions above, in about a minute each: the problem, the mechanism, the trade-off, and whether you'd do the same at your company's scale. That turns a culture question into a technical one you control.
The Indian DE market splits into four tiers — FAANG-India, product companies and unicorns, GCCs, and services — and the loops differ more than the syllabus does. Same five domains everywhere: SQL, coding, modeling, pipeline design, behavioral. What changes is the weighting, the stack vocabulary (AWS at product companies, Azure at GCCs), and which round quietly does the filtering. Pick a company to see its shape, its distinctive round, and the trap candidates report falling into.
What every loop shares
Reported structure is remarkably consistent: 5–7 rounds over 3–6 weeks, built from the same five domains.
Stage
Typically
What's really tested
Recruiter screen
15–30 min
Level, logistics, comp range — plus, at good companies, a preview of the loop
Technical screen
45–60 min
SQL and Python data manipulation under time pressure
Take-home (~1 in 4)
2–8 hrs
Code you'd defend in review: structure, tests, README
Onsite: SQL
45–60 min
Windows, dedup, gaps-and-islands — and explaining why your version is cheaper
Onsite: modeling
45–60 min
Grain, star schema, SCDs. Frequently called the make-or-break round
Onsite: pipeline design
60 min
The senior filter: requirements, trade-offs, failure modes
Onsite: behavioral
45 min
Ownership, incidents, disagreement — where offers are lost
What gets people rejected
The reported rejection reasons repeat across companies, and almost none of them are "didn't know the syntax."
Pattern
Sounds like
Say instead
Naming tools, not solving problems
"I'd use Kafka, Spark and Snowflake"
"What's the volume and freshness requirement? That decides batch vs stream."
No failure modes
A design with only the happy path
Backfill, late data, schema change, partial failure, cost
Ignoring idempotency
"The orchestrator retries it"
"I overwrite the partition, so a rerun converges"
Rigidity under pushback
Defending v1 after the requirement changes
"That changes things — I'd move the aggregation upstream"
Vague behavioral stories
"We improved our monitoring"
A number, a decision, an alternative rejected
Bluffing a stack
"I know all the major services"
"I've run BigQuery and Dataflow in production; Bigtable I've only read about"
Tickets, not ownership
"I worked on the ingestion module"
"The pipeline I owned end-to-end — and the incident I took at 2 a.m."
Compensation in India, roughly
Total compensation (CTC), INR lakhs per annum, 2026 public aggregators. Orientation, not precision — decompose any offer into fixed / variable / ESOP before comparing.
Segment
Band (₹ LPA)
Note
Entry (0–2 yrs), broad market
7–14
Top of band is product-company offers; services anchor the bottom
Mid (3–5 yrs), broad market
16–26
The fastest-doubling stretch — this is when to move
Senior (6+ yrs), broad market
28–42
Product employer + a premium skill takes the top quartile
Streaming-heavy stacks pay a 20–35% specialist premium
FAANG-India & top product, senior
45–80+
RSU/ESOP-heavy; Flipkart DE median ≈ ₹28L with senior packages far above
IT services data practices
5–14
Volume entry point; product pays 2–3× at the same experience
Four things the band tables never say. Company type is the dominant lever — moving from services to product moves comp more than two promotions. CTC is not in-hand: ask for the fixed/variable/ESOP split, and discount unlisted-company ESOPs hard. Bengaluru anchors the bands (Hyderabad and Pune close behind); remote roles benchmark to the employer, not your city. And the notice period is part of the negotiation — 60–90 days is standard, buyouts exist, and a joining bonus that covers the buyout is a normal ask. Verify against a live aggregator before you quote a number at anyone.
The questions themselves, grouped by chapter, each with a model answer you can rehearse out loud. The strong version of every answer leads with the trade-off and names the failure mode — not just the term.
SQL
What's the difference between WHERE and HAVING?SQL
WHERE filters individual rows before grouping; HAVING filters groups after aggregation. So you can't reference COUNT(*) in WHERE (it doesn't exist yet), and you should push any row-level condition into WHERE so there are fewer rows to aggregate. It falls straight out of the logical execution order (§1.4).
Find the second-highest salary.SQL
Use DENSE_RANK() OVER (ORDER BY salary DESC) and filter for rank = 2. It must be DENSE_RANK, not RANK or ROW_NUMBER: if the top salary is tied, RANK skips 2 entirely and ROW_NUMBER would call one of the tied top earners "second." Naming why the other two fail is the point of the question.
A LEFT JOIN returned fewer rows than the left table. Why?SQL
Almost certainly a WHERE condition on the right table, which turns the outer join into an inner one by discarding the NULL-padded non-matches. If you want to keep all left rows, the right-table condition belongs in the ON clause, not WHERE.
COUNT(*) vs COUNT(column) vs COUNT(DISTINCT column)?SQL
COUNT(*) counts rows. COUNT(col) counts rows where col is not NULL. COUNT(DISTINCT col) counts distinct non-NULL values. The NULL-skipping of COUNT(col) is the trap — it silently under-counts if the column has NULLs.
Why can NOT IN return no rows unexpectedly?SQL
Because NULL breaks it: if the subquery inside NOT IN returns even one NULL, the whole predicate evaluates to NULL (never true) and you get an empty result. NOT EXISTS handles NULLs correctly and is the safer default. This is one of the most common silent-bug questions.
ROW_NUMBER vs RANK vs DENSE_RANK?SQL · windows
On a tie: ROW_NUMBER gives distinct numbers arbitrarily (1,2,3,4); RANK ties and skips (1,2,2,4); DENSE_RANK ties without skipping (1,2,2,3). Pick by intent — dedup uses ROW_NUMBER, "Nth distinct value" uses DENSE_RANK, competition-style ranking uses RANK.
SQL patterns
Longest streak of consecutive login days per user.gaps & islands
The pattern with no keyword: gaps and islands. Dedupe to the real grain first (one row per user-day), number the rows, subtract the row number from the date — consecutive days yield a constant, and that constant is the streak id.
WITH days AS (
SELECT DISTINCT user_id, CAST(login_at AS DATE) AS d
FROM logins
), numbered AS (
SELECT user_id, d,
ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY d) AS rn
FROM days
)
SELECT user_id, MIN(d) AS start, MAX(d) AS finish, COUNT(*) AS len
FROM numbered
GROUP BY user_id, d - rn * INTERVAL '1 day'
ORDER BY len DESC;
Why it works: within a run, the date and the row number advance in lockstep, so their difference is constant; every gap breaks the constant. Senior touches: dedupe first (multiple logins per day wreck the trick), and ask whether ties at the max length should all be returned.
Top 3 products by revenue per category.top-N per group
Rank inside the partition, filter outside — a window result can only be filtered in an outer query (or with QUALIFY where supported).
WITH ranked AS (
SELECT category, product_id, SUM(revenue) AS rev,
DENSE_RANK() OVER (PARTITION BY category
ORDER BY SUM(revenue) DESC) AS rnk
FROM sales GROUP BY category, product_id
)
SELECT * FROM ranked WHERE rnk <= 3;
The follow-up is always the ranking-function choice: ROW_NUMBER gives exactly N rows and breaks ties arbitrarily; RANK skips positions after ties; DENSE_RANK does not. Say which the business wants — "top 3 including ties" is DENSE_RANK — and you have answered the real question.
7-day rolling revenue per marketplace.window frames
SELECT marketplace_id, dt, revenue,
SUM(revenue) OVER (PARTITION BY marketplace_id ORDER BY dt
ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) AS rev_7d
FROM daily_revenue;
The trap is the frame: ROWS counts rows, not days. If dates can be missing, six preceding rows might span three weeks. The senior move is to say so unprompted and densify first — generate a date spine (calendar table or recursive CTE), left-join revenue onto it with COALESCE(revenue, 0), then apply the frame. Mentioning that RANGE frames on dates are engine-inconsistent is a bonus.
D1/D7 retention by signup cohort.retention
SELECT u.signup_date,
COUNT(DISTINCT u.user_id) AS cohort,
COUNT(DISTINCT CASE WHEN e.d = u.signup_date + 1
THEN u.user_id END) * 1.0 / COUNT(DISTINCT u.user_id) AS d1,
COUNT(DISTINCT CASE WHEN e.d = u.signup_date + 7
THEN u.user_id END) * 1.0 / COUNT(DISTINCT u.user_id) AS d7
FROM users u
LEFT JOIN (SELECT DISTINCT user_id, CAST(event_ts AS DATE) AS d
FROM events) e ON e.user_id = u.user_id
GROUP BY u.signup_date;
Three things they listen for: LEFT JOIN so zero-retention cohorts still appear, DISTINCT on both sides so multi-event users count once, and a clarifying question about the definition — "returned on exactly day 1, or within 1 day?" — because that changes the predicate from = to BETWEEN.
Delete duplicate rows, keep one per email.dedup
DELETE FROM users
WHERE id NOT IN (
SELECT MIN(id) FROM users GROUP BY email
);
-- or, warehouse-style, rebuild instead of delete:
CREATE OR REPLACE TABLE users AS
SELECT * FROM users
QUALIFY ROW_NUMBER() OVER (PARTITION BY email ORDER BY id) = 1;
The interview is in the follow-ups: which row to keep is a business rule (lowest id? latest updated_at?), a warehouse rebuild is safer and faster than a row-by-row DELETE at scale, and preventing recurrence — a unique constraint or a MERGE-based load (§3.3) — is the answer that upgrades you from query-writer to pipeline owner.
Data modeling
What is the "grain" of a table and why declare it first?modeling
The grain is what one row means — "one row per order line," "one per user per day." Declaring it first is the highest-leverage modeling habit because keys, aggregations, and joins all follow from it, and mixing grains in one table is how double-counting bugs are born.
A customer changes their address. How do you store it?modeling · SCD
An SCD question. If analytics needs point-in-time correctness (what region was this customer in when they bought), use Type 2: close the old row, insert a new version with valid_from/valid_to, and join facts to the version valid at event time. If only the current value matters, Type 1 (overwrite) is fine and cheaper. Tie the choice to a query requirement.
Star schema vs one big (denormalized) table?modeling
Star keeps dimensions in one place — a rename is a one-row update, storage is lean — but every query joins. OBT pre-joins everything for zero-join, analyst-friendly reads, at the cost of storage and expensive restatements when a dimension changes. Real answer: star as the maintainable core, materialized wide tables on the hot query paths. Layers, not either/or.
Surrogate key vs natural key — why do dimensional models use surrogates?modeling · keys
A natural key comes from the business (email, order no.); a surrogate is a meaningless integer/hash the warehouse assigns. Dimensional models need surrogates because SCD Type 2 maps one natural customer to many versioned rows, so facts must reference the surrogate of the specific version current at event time — plus surrogates insulate you from messy/changing source keys and keep joins fast integer comparisons.
What is a conformed dimension?modeling
A dimension shared consistently across multiple fact tables — the same dim_date/dim_customer used by orders, returns, and tickets — so metrics line up across the business and can be compared on the same axes. Conformed dimensions are what make a warehouse coherent instead of a pile of unrelated tables.
How do you handle late-arriving data?modeling
Late-arriving dimension: insert a placeholder ("inferred member") so the fact isn't dropped, then enrich it when the real record lands. Late-arriving fact: under SCD Type 2, join it to the dimension version that was current back then, not now — which works only because Type 2 kept history. Both say the same thing: model time as a first-class citizen.
Big data fundamentals
What is a shuffle and why is it expensive?big data
A shuffle physically moves records across the network so all rows with the same key land on one machine — needed by GROUP BY, JOIN, distinct, ORDER BY. It's expensive on every axis: it writes to local disk (spill), serializes records, sends them over the network, then reads and merges. The whole performance game is: shuffle less, and shuffle evenly.
Why is reduceByKey better than groupByKey?big data
groupByKey shuffles every record to the reducer and aggregates there; reduceByKey combines values map-side first, so only one partial aggregate per key per partition crosses the wire. Same result, a fraction of the network traffic — the map-side combine is the whole difference.
Narrow vs wide transformations?big data · Spark
Narrow: each output partition depends on one input partition (map, filter) — no data moves, and chains fuse into one stage. Wide: each output partition depends on many inputs (groupBy, join, distinct) — a shuffle happens and a new stage begins. It's the vocabulary for the entire Spark performance conversation.
What does "exactly-once" really require?big data · streaming
Not magic — checkpoint the source offsets together with the output atomically, and make the sink idempotent (upsert on a business key) or transactional. Then a replay after failure re-processes the same offsets, produces the same keys, and the idempotent write collapses the duplicate. True end-to-end exactly-once needs the sink's cooperation; otherwise you engineer effectively-once with dedup keys.
Event time vs processing time?big data · streaming
Event time is when the event happened; processing time is when your system saw it. They differ because of network delays and retries, and correct aggregations key off event time. Handling the gap needs windows (finite aggregations over an unbounded stream) and watermarks (how long to wait for late data before finalizing).
Spark engine
Driver vs executor?Spark
The driver runs your main, builds the DAG, and schedules tasks — it coordinates but doesn't process data, though it collects results (so collect() on a huge dataset OOMs it). Executors are JVMs on worker nodes with cores and memory that actually run tasks and cache data. Cores = parallel task slots; a partition is processed by one task.
Transformation vs action?Spark
Transformations are lazy — they extend the DAG and return another DataFrame (map, filter, join). Actions trigger execution and return a value or write output (count, collect, write, show). The consequence worth volunteering: every action re-runs the full lineage, so multiple actions re-scan the source unless you cache.
Explain jobs, stages, and tasks.Spark
One job per action. Each job splits into stages at every shuffle boundary (a stage is a run of narrow transformations). Each stage runs as tasks, one per partition, in parallel across cores. So: actions→jobs, shuffles→stage boundaries, partitions→tasks. Reducing shuffles reduces stages.
What operations cause a shuffle?Spark
The wide transformations: groupBy/groupByKey, join (unless broadcast), distinct, repartition, reduceByKey, and sorting/orderBy. Anything that needs records grouped or ordered by key across the whole dataset. Narrow ops (map, filter, select, union) don't.
A Spark job OOMs. How do you reason about it?Spark · memory
First ask which side. Executor OOM: a partition too big, a giant groupByKey, or skew — fix with more/smaller/even partitions or skew handling. Driver OOM: collect() pulling a large result back, or a broadcast too big to build — fix by not collecting or lowering the broadcast threshold. Naming the side is the difference between diagnosing and guessing.
What is Adaptive Query Execution (AQE)?Spark
Runtime re-planning (default since 3.2): at each shuffle boundary Spark reads the actual statistics and adjusts the rest of the plan. It coalesces the default 200 shuffle partitions to a sensible number, switches a sort-merge join to a broadcast when a side turns out small, and splits skewed partitions. It makes the common cases self-correcting so you focus on structural choices it can't make.
Spark performance
repartition vs coalesce?Spark · perf
repartition(n) does a full shuffle to exactly n even partitions and can increase or decrease count. coalesce(n) merges partitions without a full shuffle, only decreases, and may leave them uneven. The tell: "after a heavy filter that leaves 500 sparse partitions I coalesce; to fix skew or go wider I repartition."
When would you use a broadcast join, and when does it backfire?Spark · perf
Use it when one side is small (a dimension/lookup, under ~10MB by default): Spark ships a copy to every executor and skips shuffling the big table entirely — the biggest single join win. It backfires when the "small" table isn't: broadcasting something too large OOMs the driver building it or the executors holding it. Broadcast is for genuinely small tables only.
One task runs for an hour while the rest finish in seconds. Fix it.Spark · perf
Data skew — one key's rows all hash to one partition/task after the shuffle. Ladder of fixes: enable AQE skew-join handling (splits the hot partition automatically), salt the hot key (append a random suffix so one key spreads across many tasks), or broadcast the other side to skip the shuffle. A NULL join key is a frequent hidden culprit because all NULLs hash together.
Cache vs checkpoint?Spark · perf
Caching keeps the data and the lineage (a lost block is recomputed from the DAG) — it's for speed, on DataFrames you reuse. Checkpointing writes to reliable storage and truncates the lineage — for very long iterative jobs where the DAG grows unwieldy or you want to survive executor loss without recomputation. Most tuning is caching.
What's wrong with spark.sql.shuffle.partitions = 200?Spark · perf
It's a fixed default regardless of data size. On 2TB of shuffle that's 10GB per task (spill/OOM); on 200MB it's a thousand trivial tasks (pure overhead). Set it so each task handles ~128–200MB, or rely on AQE to coalesce shuffle partitions automatically.
Why are Python UDFs slow in PySpark?Spark · perf
A plain Python UDF serializes each row out of the JVM to a Python worker, runs your function, and serializes back — row by row — and it's a black box to Catalyst, so no pushdown crosses it. Prefer built-in Spark SQL functions (run in the JVM, optimize), then vectorized pandas/Arrow UDFs (columnar batches, often 10× faster), and plain Python UDFs only as a last resort.
PySpark coding round
Keep only the latest record per key.dedupe
from pyspark.sql import Window, functions as F
w = Window.partitionBy("order_id").orderBy(F.col("updated_at").desc())
latest = (df.withColumn("rn", F.row_number().over(w))
.filter("rn = 1").drop("rn"))
The probe: why not dropDuplicates(["order_id"])? Because it keeps an arbitrary row, not the latest — it has no ordering. Saying that one sentence is usually the pass/fail moment of the question. This window is also the merge-dedupe from §3.3 in DataFrame clothing.
Three senior touches: dot-paths for structs but explode for arrays (and explode_outer so parents with empty arrays survive); a corrupt-record column instead of letting bad rows vanish; and stating that explode multiplies row count — the fan-out matters downstream. This is Flipkart's machine-coding round almost verbatim.
Sessionize a clickstream: new session after 30 idle minutes.sessions
Same island trick as SQL: flag the boundaries with lag, running-sum the flags into ids. Name the assumption (gap threshold is a product decision) and the streaming version (§8.2 session windows do this with watermarks) to show you know where this pattern lives in production.
Word count — why do they still ask it?fundamentals
Because it is the smallest program that contains a shuffle. The real question is the follow-up: which step is the wide transformation (groupBy), what crosses the network (partial counts, thanks to map-side combine), and how many output partitions there are (spark.sql.shuffle.partitions). Answer the plumbing, not just the code.
Spark, under stress
Executor OOM at 2 a.m. — walk me through the diagnosis.debugging
Ranked by base rate: skew — one task's partition is 100× the median (Spark UI, sorted task table, max vs median); fan-out — a join or explode multiplied rows mid-stage; too few partitions — data grew but the partition count did not, so each task now exceeds memory; driver-side — a collect() or an oversized broadcast. The order of inspection: Spark UI stage view first, then the query plan, then configs — touching spark.executor.memory before looking at the UI is the junior tell, because doubling memory on a skewed key just moves the OOM an hour later.
Execution vs storage memory — why does it matter?memory model
Unified memory: one pool shared between execution (shuffle, sort, join hash tables) and storage (cache). They borrow from each other, but execution can evict cached blocks while cache cannot evict running execution. Practical consequences: an over-cached application starves its own joins and spills; "memory used" in the UI conflates the two; and the fix for a spilling job is often to uncache something, not to add memory. That one sentence separates people who read the docs from people who fought the thing.
What does AQE actually do at runtime?AQE
Three re-plans using real statistics at stage boundaries (§5.5): coalesces tiny post-shuffle partitions to a sensible count, switches join strategy to broadcast when a side turns out small, and splits skewed partitions in sort-merge joins. What it does not fix: a bad initial partition count on read, an exploding UDF, under-provisioned executors, or skew in aggregations. So the senior answer to "do I still need to tune?" is yes — AQE fixes the plan mid-flight, not the physics.
How do you size executors for a job?tuning
Start from the classic heuristic: ~4–5 cores per executor (more and HDFS/S3 client throughput degrades, fewer and JVM overhead dominates), memory to match the data per task with ~10% overhead headroom, executor count from cluster capacity minus one core/node for the OS. Then say the senior part: the heuristic is a starting point — the real signal is the Spark UI after one run (spill? idle cores? GC time?), and on modern platforms dynamic allocation plus AQE means you tune the partition count and let the platform breathe. Quoting exact magic numbers with confidence is the junior tell; describing the feedback loop is the senior one.
Snowflake
What are micro-partitions and how does pruning work?Snowflake
Snowflake stores tables as immutable ~50–500MB columnar micro-partitions, each carrying min/max metadata per column. Queries prune by reading that metadata and skipping any partition that can't contain matching rows — automatic, no indexes. How well it prunes depends on clustering (how sorted the data is on your filter columns); a clustering key helps large tables whose load order doesn't match query filters.
Scale up or scale out in Snowflake?Snowflake · cost
Up (bigger warehouse) for a single heavy query that spills/sorts a lot — more memory and CPU. Out (multi-cluster warehouse) for many concurrent users where the problem is queuing, not any one query. Nuance: doubling size doubles both speed and credit rate, so sizing up buys latency, not savings, on a parallel query — size to avoid spilling, use auto-suspend, and lean on the result cache to actually cut spend.
Time Travel vs Fail-safe?Snowflake
Time Travel lets you query or restore a table as of up to N days ago (configurable, up to 90 on higher editions) — undo a bad load, recover a dropped table. Fail-safe is a non-configurable 7-day Snowflake-managed recovery window after Time Travel expires, accessible only via support. The gotcha: Time Travel is self-serve; Fail-safe is not.
How does zero-copy cloning work and why is it instant?Snowflake
CREATE TABLE dev CLONE prod duplicates only metadata pointers to the existing immutable micro-partitions — no data is copied, so it's instant and free at creation. New storage is consumed only as the clone diverges (copy-on-write). It's how you spin up full-size dev/test from production in seconds without paying for a second copy.
What are Streams and Tasks?Snowflake
A Stream is a change-data-capture cursor on a table (what's been inserted/updated/deleted since you last read it); a Task runs SQL on a schedule or dependency. A Task that consumes a Stream and MERGEs the changes downstream builds incremental pipelines entirely inside Snowflake — pair with Snowpipe for continuous file ingestion and you have near-real-time loads with no external orchestrator.
Data integration & cloud
When is a low-code integration tool the right call?integration
When the problem is many standard sources with extract-and-load needs: the vendor maintains the connectors, absorbs upstream API changes, and gives retries and error views for free. It stops being right when transformation logic grows — GUIs version and test badly — so the mature pattern is managed connectors for EL, versioned code (SQL/dbt/Spark) for T. Answering with that split, rather than a tool name, is what reads as senior.
Glue or EMR for a Spark workload?AWS
Glue for serverless, scheduled ETL a small team owns — no clusters to manage, catalog built in, pay per DPU-hour. EMR when you need control: specific Spark versions, custom configs, long-running or massive jobs, spot-instance cost engineering. The trade is operational burden versus control and unit cost at scale. Bonus point: either way the data lives in S3, so you can change the compute decision later.
Athena or Redshift?AWS
Athena is serverless SQL over S3, priced per TB scanned — ideal for ad-hoc queries on the lake, and cheap only if the data is partitioned and columnar; scanning raw unpartitioned JSON is the classic bill shock. Redshift is the provisioned warehouse for concurrent, repeated BI workloads. In Redshift, name distribution keys (collocate the join key so rows don't move between nodes) and sort keys (skip blocks on range filters) — that pair is the standard follow-up.
Kinesis or Kafka (MSK)?AWS · streaming
Same log abstraction: shards are partitions, ordering holds per shard, consumers scale to shard count (§8.1). Kinesis is fully managed and integrates natively with Lambda/Firehose — least ops. MSK is real Kafka when you need the ecosystem: connectors, exact client semantics, cross-cloud portability. If the team already speaks Kafka, MSK; if you want AWS to own it, Kinesis.
Map the AWS stack to Azure and GCP.cloud
Six ideas, three vocabularies. Lake: S3 / ADLS Gen2 / GCS. Warehouse: Redshift / Synapse / BigQuery. Spark: Glue·EMR / Databricks·Synapse Spark / Dataproc. Log: Kinesis·MSK / Event Hubs / Pub-Sub. Orchestrator: MWAA·Step Functions / ADF / Composer. Serverless SQL: Athena / Synapse serverless / BigQuery itself. Answer in problems first, then the vendor's noun — it works in any loop, and it matters in India where product companies run AWS and GCCs run Azure.
Why not do the heavy transform in Lambda?AWS
Hard 15-minute timeout, memory capped, no shuffle — Lambda is event glue (trigger on S3 arrival, route, notify), not a data processor. Proposing it for joins over TBs is a known red flag. The senior answer names the boundary: Lambda triggers the Glue/EMR job; Spark does the work.
DevOps & MLOps
What is idempotency and how do you achieve it in a pipeline?DevOps
Running a task twice produces the same result as once — essential because tasks get retried and backfilled. Achieve it by overwriting a specific partition (write date=X by replacing that partition) or upserting on a key, never a blind append. "I partition by date and overwrite the partition, so retries and backfills are safe" is the answer.
How do you make a pipeline safe to backfill?DevOps
Two joined ideas: idempotent writes (overwrite the target partition or upsert, so a rerun replaces rather than duplicates) and date-parameterized tasks (the run reads its logical date via {{ ds }}, so it can be pointed at any historical day). Idempotency makes backfills safe; date-parameterization makes them possible.
What is training-serving skew and how do you prevent it?MLOps
When features are computed differently for training (a batch job) than for serving (a real-time path), the mismatch silently degrades the model in production with no error. Prevent it with a feature store that computes each feature once and serves identical values to both offline training and online serving. Also monitor input drift, since the world shifts even without skew.
What are the pillars of data observability?DevOps · data quality
Freshness (is it up to date?), volume (did row counts drop/spike?), schema (did a column change?), quality/distribution (values in range, null rates stable?), and lineage (upstream cause, downstream blast radius). The core instinct: a job succeeding isn't the same as the data being correct, so you alert on the data, not just task status.
What is the Write-Audit-Publish pattern?DevOps
Write new data to a staging branch/table, audit it with quality checks, and only publish (atomically swap into production) if the checks pass. On Iceberg branches or with staging tables it makes "never expose unvalidated data" structural rather than hopeful — the data-engineering version of a deploy gate.
ETL & pipeline design
ETL or ELT — which and why?ETL
ELT is the modern default: land raw data first, transform inside the warehouse. It won because columnar compute got cheap and elastic, and keeping raw data means you can re-derive everything when the business logic turns out to be wrong. ETL still wins when the transform needs libraries the warehouse can't run, when PII must be dropped before landing, or when filtering in flight saves real money at the source.
How do you choose between full load, incremental, and CDC?ETL
Profile the source first: size, change rate, whether it has a trustworthy updated_at, whether it hard-deletes, and whether you can read the replication log. Full snapshot is simplest and catches deletes but doesn't scale. Watermark incremental is cheap but blind to hard deletes and fragile if the source doesn't bump its timestamp. CDC captures deletes, barely loads the source, and gives log-order guarantees — at the cost of running connectors and handling schema changes in the stream.
Your incremental load silently drifts from the source. Why?ETL
Two classic causes. Hard deletes: a watermark only sees rows that exist, so deleted rows live in your target forever. And unbumped timestamps: if the source updates a row without touching updated_at, you never pick it up. Fix with periodic full reconciliation of counts and control totals, an overlapping extraction window, or moving to CDC. The meta-answer: green pipelines are not correct pipelines.
What is the bronze/silver/gold (medallion) layering for?ETL
Bronze is raw and immutable (exactly what the source said, partitioned by load date), silver is cleaned/typed/deduplicated, gold is business aggregates. The point isn't tidiness — it's restart points. A transform bug in gold is fixed by rebuilding from silver; bad silver is rebuilt from bronze. The expensive, irreversible step (capturing the source) happens once and everything downstream is a re-runnable function.
How do you handle schema drift from an upstream team?ETL · contracts
Classify the change first: additive (new nullable column) and widening are backward-compatible; renames, drops, and narrowing are breaking. Then place the policy: auto-merge additive changes at the raw layer so nothing is lost, and enforce a data contract at the cleaned-layer boundary so breaking changes fail loudly instead of silently nulling a dashboard. A contract carries schema plus semantics, quality guarantees, freshness SLA, and a named owner.
How do you handle late-arriving data in batch?ETL
A rolling reprocessing window: every run recomputes the last N days (7–14 typical) using merge or partition-overwrite, so recomputation can't duplicate. Pick N by measuring the actual event_time-vs-load_time distribution rather than guessing. Critically, partition by event time, not ingestion time — otherwise a late event lands in today's partition and history changes depending on when you ask.
How would you deduplicate billions of records?ETL
In batch: ROW_NUMBER() OVER (PARTITION BY dedup_key ORDER BY version DESC) and keep rn = 1, where the key is a stable event id and the ordering is a log sequence number or update timestamp. In streaming: keyed state holding seen ids with a TTL, because unbounded dedupe state is what kills long-running jobs. If approximate is acceptable at extreme scale, a Bloom filter trades a small false-positive rate for a fraction of the memory.
How do you know a pipeline is correct, not just green?ETL · quality
Reconcile against the source on a schedule — row counts and summed control totals — and alert on drift. Layer that with boundary checks (nulls, uniqueness, referential integrity, freshness) split into hard-fail versus warn, so a bad load blocks publication rather than reaching a dashboard. Task success only proves the code ran; it says nothing about whether the numbers are right.
Streaming
How does Kafka guarantee ordering?streaming
Only within a partition, never across a topic. Records are routed to partitions by hashing the key, so if you need all events for one entity in order, key by that entity's id. Within a consumer group each partition is read by exactly one consumer, which means parallelism is capped at the partition count — consumers beyond that sit idle.
Consumer lag is climbing. Walk me through it.streaming
Lag is latest produced offset minus committed offset, so it grows for three reasons: more input (traffic spike or an upstream backfill replaying), slower processing (bad deploy, an external call in the hot path, GC pauses), or fewer effective consumers (crash loop, rebalance storm). Fix in that order — scale consumers up to the partition count, make per-record work cheaper, then add partitions, remembering that repartitioning breaks per-key ordering across the change.
What is a watermark?streaming
The system's assertion that it has probably seen all events up to event time T — typically max-event-time-seen minus an allowed lateness. When the watermark passes a window's end, the window fires and its state is freed. It's a pure trade-off: longer lateness catches more stragglers but delays results and holds state; shorter is fresher and leaner but drops more. Don't drop silently — side-output late events and track the count.
How do you keep streaming state bounded?streaming
Every stateful operator needs a retention story or the job dies slowly: checkpoints stretch to minutes, recovery to hours. Windows are cleaned by the watermark; dedupe caches need an explicit TTL; stream-stream joins need a bounded join window on both sides. This is the question that separates people who've run a streaming job for a week from people who've run one for a year.
Flink or Spark Structured Streaming?streaming
Flink is true per-event streaming with rich keyed state and timers, giving the lowest latency — the default where real-time is the product. Spark Structured Streaming is micro-batch (sub-second to seconds) but reuses the DataFrame API and the cluster you already run, which makes it pragmatic for Spark shops. Kafka Streams is a library inside your service, not a cluster. Tie the choice to latency requirement, state complexity, and what the team can actually operate.
Should this be batch or streaming?streaming · design
Decided by the consumer's freshness requirement, not by preference. Streaming costs always-on infrastructure, state management, and much harder debugging. If the consumer is a dashboard read each morning, batch is the correct engineering answer — and saying so demonstrates judgement. Reach for streaming when a decision is made on the data in seconds: pricing, fraud, dispatch, alerting.
System design
How do you approach an open-ended pipeline design question?design
Five phases in roughly sixty minutes: requirements (~8 min — volume, freshness SLA, consumers, retention, budget), back-of-envelope sizing (~4), high-level architecture as ingest → process → store → serve (~15), deep dives on failure modes (~20), and trade-offs plus operations (~8). The most-cited rejection reason is opening with tool names before eliciting a single requirement.
Design a real-time clickstream analytics pipeline.design
Size it first (2B events/day × 1KB ≈ 2TB/day, ~23k/sec average, 100k+ peak). Note the real tension: the dashboard wants fast, the reporting tables want right. Producers → partitioned Kafka keyed by user id. Two consumers off one log: a stream job maintaining windowed aggregates into an OLAP store, and a sink writing raw Parquet to the lake, from which a batch job builds corrected tables with a rolling late-data window. Then the deep dives: dedupe on client event id, watermarks, compaction for small files, replay-from-log for backfill, a schema registry, and tiering for cost.
What's the small-files problem?design
Streaming writers and over-partitioned batch jobs emit thousands of tiny files. Every file costs a metadata lookup and an open, so query planning and scan time collapse even though total bytes are small. Fix with a compaction job that rewrites small files into ~128MB–1GB targets, coarser partitioning, and coalesce before writing. Mentioning it unprompted in a design round signals you've operated a lake.
Lambda or Kappa architecture?design
Lambda runs parallel batch and streaming paths over the same data; its real cost is two implementations of the same business logic that inevitably drift. Kappa runs one streaming path and replays the log for reprocessing. The modern preference is a single path — stream with replay, or batch on a short interval — reaching for two only when requirements genuinely demand both a fast approximate answer and a slow exact one. If you propose both, name which one is the system of record.
Scenario drills
A job that took 40 minutes now takes 6 hours. Nothing changed. Go.scenario
"Nothing changed" is always false — find what did. In order: the data (volume growth, a skewed hot key appearing, an upstream repartition producing millions of small files — same bytes, 100× the tasks); the plan (a broadcast join silently flipping to sort-merge because a table crossed the threshold; stale statistics); the platform (cluster contention, spot loss, a quietly-changed config). Method beats guesses: pull up the Spark UI for both runs, diff stage durations, and say what you would compare. Naming small-files and the broadcast flip covers the two most common real causes.
A stakeholder says the dashboard numbers are wrong.scenario
First, make "wrong" precise: which metric, which date range, wrong compared to what? Then reproduce at the lowest layer — run the metric query yourself against the mart, then walk lineage upstream (mart → staging → raw) comparing counts and sums at each hop until the divergence appears. The usual suspects, in order: timezone boundaries (their report is IST, the pipeline is UTC), duplicates from a replay, a join that quietly fans out, late data that arrived after their snapshot. Communicate while diagnosing — an ETA and a "here is what I have ruled out" beats silence — and finish with the prevention: a reconciliation check (§3.5) at the hop that lied.
Backfill two years of data without breaking prod.scenario
Plan before code: run on isolated compute (separate cluster/warehouse so the daily SLA is untouched), process partition by partition with idempotent MERGE writes so any failure resumes instead of restarting, throttle against the source and the warehouse, and verify as you go — counts and control totals per partition against the source, not one giant check at the end. Mention the dual-write question (does new data keep flowing while you backfill? land both, reconcile at the boundary date) and cost (two years of reprocessing is a real bill — estimate it first). This is §10.2's idempotency argument as a story.
Duplicates appeared in a production dashboard overnight.scenario
Two questions locate it: where (raw already has dupes → upstream replay/at-least-once delivery; raw clean but mart dirty → your load or a fan-out join) and since when (one day → a rerun double-appended; growing over weeks → a key assumption broke). Immediate fix: dedupe the affected partitions with the ROW_NUMBER pattern and restate the dashboard. Real fix: make the load idempotent — MERGE on the business key instead of append — and add a uniqueness check that pages before the CEO sees it. Saying "the bug is that a rerun was ever unsafe" is the senior close.
You must cut the platform bill 30% this quarter.scenario
Measure first: cost per pipeline/warehouse/table, because 20% of jobs are 80% of spend and intuition lies. Then the ranked levers: kill zombies (jobs nobody reads — ask who consumes each expensive output); full-refresh → incremental (§3.2, usually the single biggest cut); right-size and auto-suspend compute (idle warehouses, oversized clusters, spot for fault-tolerant batch); storage lifecycle (compress, tier old partitions to cold storage); fix the top 3 worst queries (partition pruning beats cluster upgrades). Close with the guardrail: publish cost per pipeline so it stays visible — one-off cleanups regress in a quarter.
Upstream added a column and renamed another. Your pipeline is failing. What now — and how do you prevent round two?scenario
Now: stop the bleed (pause the load so you do not write garbage), map old→new column explicitly for the rename, deploy, then reprocess the failed window idempotently. Additions are non-breaking if your pipeline selects columns explicitly — SELECT * is why it broke. Prevention is the real answer: explicit column lists, a schema check at ingestion that quarantines unknown shapes instead of crashing (§3.4), and a conversation upstream — a data contract, even an informal one, that renames get a deprecation window. The story ends with the org fix, not the code fix.
Behavioral
Tell me about a time a pipeline broke in production.behavioral
The most-asked DE behavioral question. Structure: how you detected it (an alert you'd built beats "an analyst told us"), the blast radius, the call you made under pressure, the fix, and the durable prevention. Carry a number in the situation and one in the result. End on the systemic change — "we added a row-count reconciliation that has caught two silent failures since" — because a story ending in a permanent improvement reads as an engineer who compounds.
Tell me about a time you were wrong.behavioral
Asked in nearly every senior loop, and the failure mode is the disguised humblebrag ("I care too much about quality"). Pick a real mistake with real consequences, own it without hedging, and spend most of the answer on the correction and the systemic fix. Interviewers are calibrating whether you can be told you're wrong — which matters more in data roles, where being confidently wrong propagates downstream.
Tell me about disagreeing with a stakeholder.behavioral
The point is not winning. Show that you disagreed with evidence rather than opinion, escalated proportionately, and committed to the outcome even when it went against you. For data engineers the strongest version involves defending correctness against a deadline — you flagged that the numbers weren't ready, quantified the risk of shipping anyway, and either held the release or shipped with explicit caveats and a fix date.
What should I ask the interviewer?behavioral
Ask what reveals the job: what breaks most often and who gets paged; how you'd know a dataset is wrong; the split between building new pipelines and maintaining old ones; what the platform looks like in a year. These score as owner-thinking — and they protect you, because a team that can't answer "how do you know when data is wrong" is a team where year one is firefighting.
Agentic AI · foundations
What's the difference between a workflow and an agent?agents
Who decides the next step. In a workflow, code decides the control flow at design time, even if every step calls an LLM. In an agent, the model's output chooses the next action at runtime (which tool, which arguments, or stop) based on what earlier tools returned. Then give the trade-off: the agent adapts to what it finds, at the cost of determinism, testability, latency and predictable spend (§13.1).
Walk me through one iteration of an agent loop.agents
Call the model with the full message history and the tool schemas. If it returns tool calls: append its message, then for each call validate the arguments, authorise, execute with a timeout, and append a result tied to the call id. If it returns text, stop. Around the loop: a step cap, a cost budget, loop detection and a typed result status (§13.2).
Does the model execute the tool?agents
No. It emits a structured request; the harness parses, validates, authorises and executes it with the harness's own credentials, then returns the result as a message. That's why all authority, and so all security, lives in the harness, not in the prompt.
Why validate output if the provider guarantees schema-valid JSON?LLM engineering
The guarantee is syntax, not truth. Valid JSON can name a table that doesn't exist, use an out-of-range value, or cite evidence that no tool returned. Validate business rules in code, check that cited ids exist in this run's tool results, and run a bounded repair loop that sends the exact error back (§13.3).
Why does step 10 of an agent run cost more than step 1?LLM engineering
The API is stateless, so every call resends the entire conversation, including every earlier tool result. Input tokens grow each step and total cost grows roughly quadratically with steps when results are large. Fixes: smaller tool results, fewer steps, prompt caching on the stable prefix, compaction that keeps evidence ids, and routing easy steps to smaller models (§13.4).
Temperature 0 gave different answers on two runs. Why?LLM engineering
Temperature 0 is near-deterministic, not guaranteed. Batched GPU inference can reorder floating-point operations, tiny logit differences flip near-ties, and providers may route requests to different hardware or model snapshots. Consequence: pin model versions and repeat trials in evals.
How would you reduce agent latency?LLM engineering
Measure from traces first, then: fewer steps through better tool design, run independent tool calls in parallel, smaller tool outputs, prompt caching, a smaller model for routing and extraction, streaming the final answer for perceived latency, and avoiding the model entirely for steps code can do.
Agentic AI · harness, RAG & MCP
What does an agent harness do?harness
It owns everything around the model: the loop, tool registry and schemas, validation, policy and approvals, retries with backoff, timeouts, step and cost limits, loop detection, state and checkpoints, token and cost accounting, and tracing. It returns a typed result for every way a run can end. The model is one swappable dependency (§14.1).
Which errors should the harness retry, and which go to the model?harness
Retry transient infrastructure errors (429, 5xx, timeouts) in the harness with exponential backoff and jitter. Return model-correctable errors (invalid arguments, unknown id, unknown tool) to the model as tool results so it can fix them. Never retry auth failures or policy denials. And never blindly retry a side-effecting call without an idempotency key.
A timed-out tool call created two tickets. What happened?harness
The first call succeeded on the server but the reply was lost, so the harness retried and duplicated the side effect. Fix with an idempotency key (run id + tool + argument hash) that the backend deduplicates, read-before-write checks, and a policy that high-risk tools are not retried blindly. Same idea as making a pipeline rerun safe with a keyed MERGE.
Your RAG answer is wrong. Retrieval or generation?RAG
Look at the retrieved passages. If none contains the answer, retrieval failed: measure recall@k on a labelled query set and fix chunking, metadata filters or hybrid search. If the evidence was there but the answer ignored or contradicted it, generation failed: measure faithfulness and citation validity. Evaluate the two halves separately (§14.2).
Why hybrid search instead of vectors alone?RAG
Vector search handles paraphrase but is weak on exact identifiers such as error codes, table names and ticket numbers; keyword search (BM25) is the opposite. Fusing the two (for example with reciprocal rank fusion) and reranking the top candidates covers both kinds of query.
Why use MCP?MCP
It replaces N apps times M bespoke integrations with N plus M: a tool provider writes one server, and any MCP-capable host can discover and call it over JSON-RPC (stdio locally, HTTP remotely). Tools are model-controlled, resources application-controlled, prompts user-controlled. Caveats: an extra process and hop, an evolving spec, and it standardises connectivity, not trust (§14.3).
Is an MCP server a security boundary?MCP · security
No. Its tool descriptions and results reach the model, so a malicious or compromised server can inject instructions, and its tools carry whatever credentials you give them. Pin and review server versions, run them with least privilege, separate read and write servers, and enforce approvals in your harness.
Why not just keep everything in the context window?memory
Cost and latency grow with every call, quality drops on long noisy contexts, stale facts persist, secrets and PII ride along, and nothing survives a crash. Keep structured task state and checkpoints in a database, retrieve long-term memory only when relevant, and build each call's context from what the step needs (§14.4).
Agentic AI · evals, security & design
How do you evaluate an agent?evals
A scenario set with ground truth, graded at three levels: tools (unit tests), trajectory (required and forbidden calls, steps), and outcome (correct answer, valid citations). Track latency, tokens, cost and failure rate too. Programmatic graders first, a calibrated LLM judge only for free text (§15.1).
Version B scored 84% vs A's 80% on 50 scenarios. Is B better?evals
Not shown yet. At n=50 the standard error of an 80% rate is about 5.7 points, so a 4-point gap is well inside the noise. Repeat trials, add scenarios, compare paired on the same scenarios, and report confidence intervals. And check the held-out split, not only the one you tuned on.
What are the risks of LLM-as-judge?evals
Bias toward longer or more confident answers, position bias, self-preference, run-to-run variance, and drift when the judge model changes. Give it ground truth and a rubric, use it only where programmatic grading can't work, and measure its agreement with human labels before trusting it.
How do production engineers debug a failed agent run?observability
Open the trace (run span with child spans for every model and tool call), find the first divergence from the expected path, classify the cause (tool, retrieval, model reasoning, harness, data), replay with recorded tool outputs to reproduce, then aggregate classified failures and fix the largest class (§15.2).
How would you prevent prompt injection?security
You contain it rather than prevent it. Treat tool results and documents as untrusted data, assume the model will sometimes follow injected text, and limit what it can do when fooled: least-privilege tools and read-only credentials, per-call authorization by user and arguments, secrets kept out of context, egress allowlists, approvals for risky actions, budgets, and an attack suite in CI (§15.3).
Why shouldn't every tool be exposed to the model?security
Every exposed tool is something an injected instruction can drive (excessive agency), more tools lower tool-selection accuracy and bloat every request, and broad tools widen the blast radius. Expose the minimum set per task, read-only by default, with write tools gated.
Your agent has production access and a user gives it a malicious instruction. What happens?security
Exactly what the policy layer allows, which is why it's designed for this case. The model has no credentials of its own; every call is authorised by user, tool and arguments; destructive and financial actions need an out-of-band approval bound to the exact action; everything is logged. Social engineering of the model shouldn't be able to bypass controls that live outside it.
How do you design human approval for risky actions?HITL
Risk tiers enforced in code: reads autonomous, low-risk logged, high-risk approved. Approval pauses the run with a checkpoint, shows the approver the exact action and evidence, and issues a single-use expiring token bound to a hash of run, tool and arguments. Resume executes only the matching action, then verifies by reading back state (§15.4).
When would you NOT use an agent?design
When the path is known, latency or cost must be bounded, results must be exactly reproducible, or a deterministic baseline already meets the bar. Climb the ladder only as far as needed: code, single LLM call, workflow with an agentic step, single agent, multi-agent (§16.1).
When is a multi-agent architecture justified?design
When there's a nameable, measurable reason: context isolation, parallel independent work, different permissions, or different models per step. Pass structured evidence between agents, not prose. Then compare against a single-agent baseline on the same evals for accuracy, p95 latency and cost; often the single agent wins (§16.4).
Docker & containers
Container vs virtual machine?Docker
A VM virtualises hardware and boots its own kernel. A container is an ordinary process on the shared host kernel, isolated by namespaces (what it can see) and limited by cgroups (what it can use). Containers are lighter and start in milliseconds; VMs give a stronger isolation boundary, which is why multi-tenant platforms wrap containers in micro-VMs (§17.1).
Why does my container take 30 seconds to stop?Docker
PID 1 isn't handling SIGTERM. Usually the shell form of CMD or a wrapper script without exec makes sh PID 1, and it doesn't forward the signal, so the orchestrator waits the grace period and sends SIGKILL. Use the exec form or exec, add tini, and handle SIGTERM in the app (§17.3).
Exit code 137 vs 143?Docker
137 = 128 + 9: killed by SIGKILL, either the OOM killer (Kubernetes shows OOMKilled) or a forced kill after the grace period. 143 = 128 + 15: the process exited on SIGTERM, a clean shutdown.
How do you make Docker builds fast and images small?Docker
Order instructions so dependencies install before code is copied (cache reuse), add a .dockerignore, use multi-stage builds with a slim or distroless runtime base, clean package caches in the same RUN that created them, and use BuildKit cache mounts. Measure layers with docker history or dive (§17.2).
How do you keep secrets out of images?Docker
Never pass them via ARG, ENV or COPY: every layer is readable by anyone who can pull the image, even if a later layer deletes the file. Use BuildKit --mount=type=secret for build-time secrets, and inject runtime secrets from the orchestrator, synced from a secrets manager.
Kubernetes
What happens after kubectl apply on a Deployment?K8s
API server: authenticate, authorise, admission webhooks, persist to etcd. Deployment controller creates a ReplicaSet; ReplicaSet controller creates Pods; scheduler binds each to a node; kubelet pulls the image and starts containers through containerd with CNI networking; after readiness passes, the pod joins the Service's EndpointSlices. Each step is a controller reconciling desired state (§18.1).
Requests vs limits?K8s
Requests are what the scheduler reserves and the CPU weight under contention. Limits are enforced by the kernel at runtime: over the CPU limit you're throttled; over the memory limit you're OOMKilled. Common practice: memory request = limit, a CPU request, and often no CPU limit for latency-sensitive services (§18.2).
What are the QoS classes and why do they matter?K8s
Guaranteed (requests equal limits for every resource), Burstable (some requests) and BestEffort (none). Under node memory pressure the kubelet evicts BestEffort first, then Burstable pods using more than they requested, and Guaranteed last.
Liveness vs readiness vs startup probes?K8s
Readiness controls traffic (fail it and you're removed from the Service). Liveness controls restarts. Startup delays the other two for slow starters. Never check dependencies in liveness: a database blip would restart every pod at once (§18.2).
How do you get zero-downtime deploys?K8s
Rolling update with sensible maxSurge/maxUnavailable, a readiness probe that means "can serve", a preStop sleep so routing removes the pod before it stops, SIGTERM handling that drains in-flight work, a grace period longer than the slowest request, and a PDB so maintenance can't take too many pods at once (§18.4).
Intermittent 5-second DNS timeouts in the cluster?K8s
The ndots:5 default turns each external lookup into several search-domain queries (for A and AAAA), overloading CoreDNS and, on older kernels, hitting conntrack races. Use fully qualified names with a trailing dot, lower ndots, scale CoreDNS and run NodeLocal DNSCache (§18.3).
Deployment or StatefulSet for Kafka?K8s
StatefulSet: brokers need stable identities (kafka-0), their own persistent volumes that follow them across restarts, a headless Service so clients can reach a specific broker, and ordered rolling restarts. In practice, use an operator such as Strimzi, which manages the StatefulSets for you.
EKS & EMR
Pods stuck in ContainerCreating on EKS with free CPU?EKS
Usually VPC CNI IP exhaustion: every pod takes a real VPC IP, and the subnet or the instance's ENI limit has run out. Check the pod events and free subnet IPs. Fix with prefix delegation, a secondary CIDR for pods, or larger subnets, and alarm on available IPs (§19.1).
How should pods get AWS permissions?EKS
Per service account, through EKS Pod Identity or IRSA, so each workload gets its own least-privilege role with temporary credentials. Not through the node's instance role, which every pod on the node would inherit.
How do you upgrade an EKS cluster safely?EKS
Scan for removed APIs, upgrade a staging cluster first, then control plane (one minor version), then add-ons, then roll nodes with PDBs pacing drains, or build a new cluster and shift traffic (blue/green) with GitOps. Watch for webhooks, pinned add-ons and behaviour changes such as removed labels (§19.2).
EMR on EC2, EMR Serverless or EMR on EKS?EMR
EC2: steady heavy batch, full tuning control, Spot task fleets. Serverless: spiky or infrequent jobs, no cluster ops. On EKS: you already run EKS and want one compute platform. State the trade-off each way (§19.3).
"Container killed by YARN for exceeding memory limits." Fix?EMR
Off-heap use exceeded spark.executor.memoryOverhead, typical in PySpark (Python workers, Arrow buffers). Raise overhead or set spark.executor.pyspark.memory, use fewer cores per executor, and fix the skewed partition that usually triggers it (§19.4).
How do you use Spot safely on EMR?EMR
Spot only on task nodes (no HDFS data), core and primary on On-Demand, instance fleets with several instance types and AZs, graceful decommissioning so shuffle data migrates on interruption, and S3 as the durable store.
Kafka in depth
What do acks=all and min.insync.replicas do together?Kafka
With RF 3, min.insync.replicas=2 and acks=all, a write is acknowledged only after at least two in-sync replicas have it, so one broker can fail without losing acknowledged data. If the ISR drops below 2, writes fail with NotEnoughReplicas rather than risk loss (§20.1).
What is the high watermark?Kafka
The highest offset replicated to all in-sync replicas. Consumers only read below it, so they never see a record that a leader failover could erase.
What does the idempotent producer guarantee, and what doesn't it?Kafka
No duplicates or reordering from retries, per partition, within one producer session (producer id plus sequence numbers). It doesn't cover a producer restart re-sending application data, or writes across partitions; transactions cover those (§20.2).
Why is adding partitions to a keyed topic risky?Kafka
The partition is hash(key) mod partition count, so new records for a key may land on a different partition than its old ones, breaking per-key ordering across the change and any state partitioned by key downstream.
Consumers keep rebalancing. Causes?Kafka
Processing a poll's records takes longer than max.poll.interval.ms; missed heartbeats from GC pauses or CPU throttling; rebalances on every deploy without static membership. Fixes: smaller max.poll.records, faster processing, cooperative sticky assignor, group.instance.id (§20.3).
When should a consumer commit offsets?Kafka
After the side effect is durable. Committing before processing gives at-most-once (a crash loses records); after gives at-least-once (a crash duplicates). Pair after-commit with an idempotent sink for effectively-once results.
How do you handle a poison-pill message?Kafka
Don't retry in place, which blocks the partition. Route failures to retry topics with increasing delays and finally a dead letter queue, monitor the DLQ, and replay after fixing, the pattern Uber published (§22.1).
One partition lags while others are fine. Why?Kafka
A hot key concentrating traffic on that partition, a poison pill blocking it, or a slow consumer instance that owns it. Check per-partition bytes in and lag; salt hot keys, DLQ bad records, replace the slow instance.
Log compaction: what are the edge cases?Kafka
It keeps the latest record per key, but never compacts the active segment, so older values linger. Tombstones (null values) delete keys after delete.retention.ms; a consumer offline longer than that misses the delete.
What did KRaft change?Kafka
Cluster metadata moved from ZooKeeper into a Raft-replicated log run by controller nodes: faster failover, more partitions, one system to run. Kafka 4.0 removed ZooKeeper support, so ZooKeeper clusters migrate to KRaft on 3.x first.
Production failures
A deploy raised error rates. First move?incident
Roll back, confirm recovery, then investigate with preserved evidence. Mitigation before diagnosis (§21.1).
A new consumer deploy and now data is missing. Why?incident
Likely a new group id with auto.offset.reset=latest: it began at the end of the topic and skipped the gap. Reset offsets to a timestamp before the gap and reprocess into an idempotent sink (§21.3).
Every deploy causes a burst of 502s. Why?incident
Pods stop before load balancers and kube-proxy stop routing to them, because SIGTERM and endpoint removal happen in parallel. Add a preStop sleep, drain on SIGTERM, and tune the load balancer's deregistration delay.
Why must database migrations not run in app startup?incident
All replicas race to migrate; one holds the lock, the rest hang, fail probes and restart, and the rollout never completes. Run migrations once as a Job or a pre-upgrade hook, written to be compatible with both old and new app versions.
Tell me about a well-known Kubernetes outage.incident
Reddit's Pi Day 2023: the 1.24 upgrade stopped applying the node-role.kubernetes.io/master label, the route reflectors' selectors still targeted it, the config wasn't in code, and pod networking failed for over five hours. Lessons: config in code, staging that matches production, rehearsed restores (§21.4).
The dense tables worth a last glance before you walk in. Everything here is explained in the chapters; this is the compressed version for the night before.
SQL logical execution order
Written SELECT…FROM…WHERE, but evaluated in this order — which is why aliases and window functions aren't usable in WHERE. (§1.4)
#
Clause
Does
1
FROM / JOIN
Build and combine the row set
2
WHERE
Filter rows (no aggregates, no aliases)
3
GROUP BY
Collapse rows into groups
4
HAVING
Filter groups (aggregates allowed)
5
SELECT
Compute columns, aliases, window functions
6
ORDER BY
Sort (aliases usable here)
7
LIMIT
Take the top N
Ranking & window frames
How the three ranking functions treat a tie, plus the frame you'll actually specify. (§1.2)
Function
On a tie
Use for
ROW_NUMBER
1,2,3,4 (arbitrary)
Dedup, top-N-per-group
RANK
1,2,2,4 (skips)
Competition ranking
DENSE_RANK
1,2,2,3 (no skip)
Nth distinct value
Running total
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
Cumulative sum
Default frame
RANGE (ties share a frame — specify ROWS for precision)
Beware around duplicates
Slowly changing dimensions
Policies for what to do when a dimension attribute changes. (§2.3)
Type
Behavior
History
Use when
Type 1
Overwrite the value
None
Only current value matters
Type 2
New versioned row + valid_from/to, is_current
Full
Point-in-time correctness
Type 3
Add a "previous value" column
One hop
Track a single prior value
Narrow vs wide transformations
Wide = shuffle = new stage. This is the vocabulary for the whole Spark performance conversation. (§4.2)
Narrow (no shuffle)
Wide (shuffle)
map, filter, select
groupBy, reduceByKey
flatMap, union
join (unless broadcast)
withColumn, cast
distinct, orderBy, repartition
Fuse into one stage
Force a new stage boundary
Join strategies
Spark picks by side sizes; force with broadcast() when the estimate is stale. (§6.2)
Strategy
When
Shuffle?
Watch out
Broadcast hash (BHJ)
One side < ~10MB
No (big side)
Broadcasting too big → OOM
Sort-merge (SMJ)
Both sides large
Yes (both)
Two shuffles + sort
Shuffle hash (SHJ)
One side fits in memory, no sort
Yes
Rarer; memory-heavy
repartition vs coalesce
The most-asked partition-tuning distinction. (§6.1)
repartition(n)
coalesce(n)
Shuffle
Full shuffle
No full shuffle
Direction
Increase or decrease
Decrease only
Result
Even partitions
May be uneven
Use for
Widen, rebalance, fix skew
Shrink cheaply after a filter
Spark tuning knobs
The configs and defaults that come up in tuning questions. (§5–5)
Config / idea
Default
Note
spark.sql.shuffle.partitions
200
Static; aim ~128–200MB/task or let AQE coalesce
autoBroadcastJoinThreshold
10MB
Below this, a side is auto-broadcast
AQE
On (3.2+)
Coalesces partitions, switches joins, splits skew
Target task size
—
~128–200MB, a small multiple of total cores
UDF preference
—
Native > pandas/Arrow UDF > Python UDF
Cache default
MEMORY_AND_DISK
cache() = this; cache only what you reuse
Where OOM strikes
Name the side first — it's the difference between diagnosing and guessing. (§5.4)
Side
Cause
Fix
Executor
Partition too big, giant groupByKey, skew
More/smaller/even partitions, salt, AQE
Driver
collect() of large result, broadcast too big
Don't collect; lower broadcast threshold
Snowflake warehouse sizes
Each size doubles compute and credit rate — so a parallel query costs ~the same, just finishes faster. (§9.2)
Size
Credits / hr
Relative compute
X-Small
1
1×
Small
2
2×
Medium
4
4×
Large
8
8×
X-Large
16
16×
2XL … 4XL
32 … 128
doubles each step
Streaming output modes
What's emitted each trigger, and when each is legal. (§7.3)
Mode
Emits
Notes
Append
Only new finalized rows
Aggregations need a watermark
Update
Rows changed this trigger
Good for upsert sinks
Complete
Entire result table
Aggregations only; small results
Extraction strategies
Profile the source, then pick. The deletes column is the one candidates forget. (§3.2)
Strategy
Source load
Catches deletes
Use when
Full snapshot
High
Yes
Small tables; no reliable change column
Watermark incremental
Low
No
Large table, trustworthy updated_at, no hard deletes
CDC (log-based)
Minimal
Yes
Deletes matter, freshness matters, you have log access
Incremental + periodic full
Medium
Periodically
Too big to snapshot nightly, no CDC available
Load patterns and idempotency
Running twice must equal running once. Only two of these qualify. (§3.3)
Pattern
Rerun result
Use for
Append
Duplicates
Immutable event logs deduped downstream
Overwrite partition
Converges
Date-partitioned batch — the default
Merge / upsert on key
Converges
Rows that change in place; CDC landing
Merge trap
Ambiguous / errors
Duplicate keys in one batch — dedupe to one row per key first
Schema change compatibility
Classify before you react — additive and widening are safe, the rest are breaking. (§3.4)
Change
Compatible?
What happens if unguarded
Add nullable column
Safe
Old readers ignore it
Widen type (int → bigint)
Safe
Values still fit
Rename column
Breaking
Old column goes all-NULL beside a new one
Narrow type
Breaking
Uncastable values silently become NULL
Drop column
Breaking
Every downstream reference nulls out
Streaming semantics
Three orderings of "process" and "commit the offset." (§8.3)
Semantic
Mechanism
On replay
At-most-once
Commit offset, then process
Data lost
At-least-once
Process, then commit offset
Duplicates
Exactly-once
Atomic offset + output (2-phase commit)
Correct — needs a transactional sink
Effectively-once
At-least-once + idempotent upsert on a key
Correct — what most systems actually run
Kafka quick facts
The five that come up in nearly every streaming round. (§8.1)
Concept
The fact
Ordering
Guaranteed within a partition only — key by entity id
Consumer group
One partition → exactly one consumer; extra consumers idle
Parallelism ceiling
Capped by partition count, set up front
Consumer lag
Latest offset − committed offset; the metric to alert on
Replay
Rewind the offset — retention is by time/size, not by read
The design round, in sixty minutes
Budget it out loud. Most candidates overspend on the architecture box. (§11.1)