The scenario round

Part of the free LogicWiz Data Engineering course, Module 18: Interview rounds. The SQL and Python run in the app, on real Postgres and real Python in the browser.

It is the scenario round. No editor this time. The interviewer leans back and says: "Finance says yesterday's revenue on the dashboard is 8% too high. What do you do?" There is no query to remember. They want to see how you think when something is broken in production, and whether you would fix the data as well as the code. One structure turns a scary open question into seven calm steps.

You'll learn to

  • Answer any incident question with one seven-step structure
  • Write the queries behind the answer: duplicates, reconciliation, missing rows
  • Make a load safe to rerun with MERGE, a lookback or delete-then-insert
  • Handle the senior scenarios: stream state, write conflicts, a full CDC slot

Learn

How the round runs

The interviewer describes something going wrong. Revenue is too high. A table has duplicates. A nightly job that took 40 minutes now takes four hours. You are graded on how you reason, not on knowing the answer in advance.

Weak answers jump to a cause ("it must be duplicates") or to a fix ("rerun it"). Strong answers say the structure out loud, ask for evidence at each step, and end with what stops it happening again.

Interviewers often add a twist halfway, such as "the source has no updated_at". So keep each step short, and be ready to go back one.

The structure has seven steps. Here it is on the question from the scene.

Seven steps, on "revenue is 8% too high"

The seven steps of an incident answer, symptom, scope, root cause, fix, recovery, validation and prevention, lit one at a time, each with the sentence a candidate would say for the revenue question.

  1. Symptom. Restate it with numbers: "The dashboard shows June revenue 8% above the finance ledger, since Tuesday."

  2. Scope. Narrow it: which table, which dates, which rows. "Only 3 June is off. Every other day reconciles."

  3. Root cause. Evidence, not a guess: "COUNT(*) is 7 above COUNT(DISTINCT order_id). The retry file was loaded twice."

  4. Fix. Change the code so it cannot happen again: "Load with MERGE on order_id instead of an append."

  5. Recovery. Repair the data that is already wrong: "Rebuild 3 June with delete-then-insert, and tell finance which reports changed."

  6. Validation. Prove it: "Counts and revenue now reconcile with the source for 1 to 14 June."

  7. Prevention. A guard for next time: "A uniqueness test on order_id that fails the job, and a volume alert."

Each step lights one box, and the caption is what you would say. Recovery is the step most candidates forget: fixing the code leaves last week's wrong numbers in place.

The causes behind most scenarios

Five causes explain most of what you will be asked:

  • Duplicates. A retry or a rerun appended the same batch. Cure: a load that is safe to rerun (MERGE on a key, delete-then-insert of a date partition, overwrite).
  • Missing rows. A failed or partial load, an inner join that dropped rows, a filter on the wrong date. Cure: reconcile and backfill.
  • Late data. Rows stamped before the watermark arrive after the run. Cure: a lookback window, and reprocessing recent days.
  • No updated_at. Compare today's snapshot with yesterday's, or read changes from the database log (CDC).
  • A slow job. More data, a skewed key, a join that fans out on duplicated keys, many small files, or a filter that stopped pruning partitions. Ask what changed.

From symptom to evidence to cause

A graph from three symptoms (wrong totals, a job much slower, a stream falling behind) through the first piece of evidence to check for each, to the cause that evidence points at.

Read it left to right: what the user reports, the first thing you check, the cause it usually points at. Say the middle column out loud before any fix. It is the evidence step interviewers score, and it decides between causes that look the same from the dashboard.

The senior scenarios: streams, lakehouses and CDC

SymptomFirst evidenceCauseFix and recovery
Batch time and memory of a stream grow every hournumRowsTotal of the state operator rises every batch; no withWatermark in the queryan aggregation or dropDuplicates with no watermark keeps all stateadd a watermark; if the state schema must change, start a new checkpoint and backfill from bronze
Nightly MERGE fails with ConcurrentAppendExceptiona backfill wrote the same Delta table at the same timeboth read and rewrote overlapping partitionsput the date range in the MERGE condition so reads do not overlap, or run them one after the other; retry
The shop's Postgres disk fillspgreplicationslots: an inactive slot, retained WAL growinga stopped CDC connectorrestart and drain, or drop the slot and re-snapshot; set maxslotwalkeepsize
Lag rises on 2 of 12 partitions onlytwo --describe samples: those offsets frozena stuck consumer, or hot keys on those partitionsrestart that member; check key distribution; add partitions only if all of them lag
Events missing after a broker failedproducer acks=1, or min.insync.replicas=1acknowledged by a leader that died before followers copied itacks=all, min.insync.replicas=2, replication factor 3; replay from the source
A stage fails with FetchFailedExceptionan executor was lost just beforeits shuffle files went with it, often after a memory killfix the memory cause; an external shuffle service keeps the files

The same seven steps, with deeper evidence. A senior answer names the metric or the system table to read, not only the cause.

Reconcile: totals first

SELECT
  (SELECT COUNT(DISTINCT o.order_id)
   FROM orders AS o JOIN order_items AS oi ON oi.order_id = o.order_id
   WHERE o.status <> 'cancelled') AS src_orders,
  (SELECT COUNT(*) FROM dw_sales) AS dw_orders,
  (SELECT SUM(oi.qty * oi.unit_price)
   FROM orders AS o JOIN order_items AS oi ON oi.order_id = o.order_id
   WHERE o.status <> 'cancelled') AS src_amount,
  (SELECT SUM(amount) FROM dw_sales) AS dw_amount;

The scope step, as a query. Compare the source with the warehouse on a count and a sum. Here dw_sales was loaded from the store's database, then a failed load lost two orders and a retry loaded one twice.

Drill down: total, then day, then key

LevelSourceWarehouseWhat it tells you
Total70 orders, $8,449.7369 rows, $8,257.02something is wrong, but one row hides two problems
By day7 June: 4 orders7 June: 2 rowstwo orders lost on 7 June
By day9 June: 6 orders9 June: 7 rowsone order loaded twice on 9 June
By keyorders 1036 and 1040no rowsthe missing keys, found with NOT EXISTS

Read it top to bottom, from the total down to single keys. A difference of one row was really two missing orders and one duplicate cancelling out. Always drill down until each difference has a key.

A tiny pipeline you can run twice in append, delete-then-insert or merge mode, watching the revenue total double in append mode and stay right in the other two.

The most common root cause, to play with. Run the load twice in append mode and watch revenue double. Then switch to replace or merge: that switch is your "fix" step.

Interviewers listen for evidence words: "I would compare COUNT(*) with COUNT(DISTINCT key)", "I would reconcile by day, then by key". Name the pattern that makes the load safe to rerun (MERGE on a business key, delete-then-insert of a partition) and say why a rerun is now safe. When a job has slowed down, start with "what changed?": data volume, code, cluster or source.

The trap: stopping at the code fix. The bug that loaded the retry twice is fixed. But last week's dashboards still show the wrong numbers, and the people who used them do not know. Say how you will repair the past (a backfill, or a rerun of the affected dates), how you will prove it (reconcile again), and who you will tell.

Remember: symptom, scope, root cause, fix, recovery, validation, prevention. Evidence before every claim.

Next is rapid-fire theory: short questions, and thirty seconds for each answer.

In one line

Answer an incident in seven steps, symptom, scope, root cause, fix, recovery, validation and prevention, back each step with a query, and make the load safe to rerun.

Interview corner

The dashboard shows revenue 8% higher than finance. Walk me through it.

I would confirm the symptom with numbers, then scope it by comparing source and warehouse totals by day to find which dates differ. On those dates I check COUNT(*) against COUNT(DISTINCT order_id) and drill down to the keys. Once I have the cause (say a retried batch appended twice), I fix the load to MERGE on the key, rebuild the affected dates, reconcile again, tell the dashboard users, and add a uniqueness test so the job fails before anyone sees doubled numbers.

How do you make a pipeline safe to rerun?

Make every write idempotent: MERGE or upsert on a business key, or delete-then-insert (overwrite) the partition the run is responsible for, inside a transaction. Never plain-append a batch that might be replayed. Then a retry, a backfill or a manual rerun leaves the same result as one run.

A Structured Streaming job's batch duration keeps growing over days. How do you investigate?

I read the query's progress events: if inputRowsPerSecond is flat while processedRowsPerSecond falls, the work per batch is growing. Then I look at stateOperators: a numRowsTotal that rises every batch, with no watermark in eventTime, means the aggregation or dedup keeps state forever. The fix is a watermark sized to how late events really arrive, possibly the RocksDB state store if the state is legitimately large. If the change alters the state schema, I start from a new checkpoint and backfill from bronze, then add an alert on state rows per batch.

A job that took 40 minutes now takes 4 hours. What do you check?

First, what changed: input volume, the code, the cluster, or the data shape. Then I look at the output row count (2 million rows out becoming 30 million means a join fans out on duplicated keys), the stage's task table for a max task far above the median with far more shuffle read (skew), spill and GC time (partitions too big for task memory), the number of input files (small files), and whether the scan still shows partition filters. I fix the cause rather than adding machines, and I keep the before and after stage times as proof.