Skip to content
About
Main content

Scenarios

Longer problems, like those in senior system design interviews. A strong answer estimates with numbers first, names the mechanism, then recommends a fix and says what it costs.

Try each one before you open the answer.
1A finance report is built from 30 tables across 14 pipeline steps, and the auditor wants assurance on revenue. Where do you put checks, and which ones gate?Show the answer

Placement

, and defects enter where authority changes: the partner files, the app events and the payment file (ingress), and the finance table itself (egress). Test the transformation steps with fixtures in CI instead of re-scanning at every hop: with 200 million rows and 6-minute scans, 14 hops cost 84 minutes, while 5 boundary scans cost 30.

Gates

  • and volume on each input, the guard against absence, with volume baselines conditioned on the weekday.
  • A median price per category compared with yesterday, which catches unit changes such as rupees to paise.
  • At egress, against the payment provider, as an independent authority.

Level

The finance report blocks on failure, since late is cheaper than wrong; publish the rate by region. needs spare capacity to catch up afterwards, about 1.5 times the stop time at 60% utilization.

Be honest

The of any suite cannot be measured; only the independent comparison partly escapes that.

Read moreTrust boundariesFreshness and volumeThe reference moves outsideWhat is unresolved

2The data-quality alert channel sends 40 alerts a day, everyone ignores it, and a real incident was missed last week. Fix the programme.Show the answer

Diagnose with arithmetic

Count the checks. With 12,000 of them at a false-positive rate of 0.001 each, by construction; at 0.01, 120. is designed in, not a failure of discipline.

Plan

  1. Choose a small set of gates that may page, say 40, by impact on .
  2. Demote the rest to dashboard signals.
  3. Replace significance tests with against business thresholds.
  4. Condition volume baselines on seasonality.
  5. Require an owner and a reason for every check, so a firing check can be judged: every expectation ages.
  6. Measure by recording a verdict on each alert for a month.

Also

Each of these choices gives something up. And confirm that freshness and volume checks are gates, since the missed incident may well have been empty output.

Read moreAlert fatigue is arithmeticSignificance testing is the wrong toolA gate is a check with authority

3Orders and customers are loaded by separate pipelines, and the check that every order has a customer raises false alarms. Design a fix, and say what you give up.Show the answer

Diagnose

The difference in load timing sets a floor on false alarms. With orders loaded every 10 minutes and customers hourly, a first order can wait about 50 minutes for its customer row.

Options

  • A pinned snapshot of both tables: exact, but validates a state hours old, and needs versioned reads.
  • Allowed lateness, say 70 minutes: simplest; defects in the newest 70 minutes are noticed 70 minutes late, which is when they are cheapest to fix anyway.
  • A pending state: nothing is lost, but you run a second pipeline, with a backlog and an owner.

Recommend

Start with , paired with an inferred "unknown customer" member so late arrivals are counted rather than lost; consider a only for the finance gate.

The limit

The check can never be better than the synchronization of its inputs.

Read moreAsynchrony makes a false-alarm floorThe inferred member

4A pipeline fails a quality check on 0.1% of rows every day. Do you publish the rest? Walk through the decision.Show the answer

Estimate the bias

Ask whether the failures are random. For example: 1,000 of 100,000 orders are quarantined, averaging ₹1,950 against ₹450 for the rest. The published average is ₹450 against a true ₹465, 3.2% low, and 4.2% of revenue is missing, from 1% of rows. If failures correlate with region, app version or order size, the remainder is biased.

Decide per consumer

  • Finance: block, or publish with the quarantined share of revenue shown if it exceeds a threshold such as 1%.
  • A dashboard: quarantine, and show the rate along every dimension it uses.
  • A recommendation feed: warn, and keep serving the previous data.

Operations

Quarantined records soon become impossible to reprocess as schemas and code move on, so set a review deadline of a few weeks and treat older ones as an archive.

Say aloud

There is no settled definition of whether such a run "succeeded", and almost no dataset publishes its completeness in a form consumers can read.

Read moreQuarantine: a quiet biasThe dead-letter queue and the poison pill

5Design duplicate-customer detection for 20 million records from three systems.Show the answer

Cost first

All pairs ≈ n² / 2 = 2 × 10¹⁴ comparisons; at a million a second, about 6.3 years on one core. Blocking is required.

Design

Several independent blocking passes (postcode area, phone prefix, phonetic surname), keeping candidates near a billion pairs per pass (20 million records in 200,000 blocks of 100 give 4,950 pairs each). A that scores name, address and phone. Clustering that avoids plain transitive closure: require two independent signals, and cap cluster size, sending clusters above 20 to review.

Store the result as an overlay

Map (source, source ID) to an entity ID, with the version of the matching rules, so a wrong merge can be undone. It costs storage, and a on every read.

Evaluate

Recall is capped by blocking, so measure it on a labelled sample; measure precision by reviewing a sample of merges. Watch for collapse when thresholds are loosened.

Read moreFuzzy dedup: a two-stage filterRecall is capped by the cheap stageThe two errors are not equal

6The warehouse and the payment provider disagree on monthly revenue by 0.1%, across 800 million rows. Find the cause, and prevent it.Show the answer

Do not diff everything

Climb the ladder: daily row counts; sums per day and region; a per partition (a sum of 64-bit hashes of normalized rows, with exact decimals, not XOR); a Merkle-tree walk inside the partitions that differ; then a cell-by-cell diff of the few rows left.

Estimate

Locating d = 40 differences among n = 10⁸ rows costs about , instead of moving 80 GB.

Pitfalls

Canonical form: rounding hides sub-paisa errors, so state the rule. Floating-point sums depend on order, so use decimals. The source keeps changing, so compare both sides at a common cut, such as a .

Blame and prevention

A difference does not say who is wrong: designate the provider as the for settled amounts. If the gap comes from writing to both systems separately, replace that with a single writer and derive the other from its log; the audit then becomes a weekly check.

Read moreThe ladder is a searchThree implementation constraintsThe common cutCross-system audits

7The product team wants a machine-learning anomaly detector to catch all unknown data problems. Evaluate the idea.Show the answer

What it cannot do

It detects deviation from the history of the metrics you chose. It cannot see defects that were always present, or that do not move a monitored aggregate; trained on dirty history, it learns the defect as normal.

What it adds

Thresholds set automatically, at a scale people cannot manage (thousands of seasonal bands). But it inherits the arithmetic of : more monitors, more false alarms.

Recommend

Use it to set thresholds on a limited set of high-value series; keep human-owned gates for absence and finance; add comparisons against independent sources for recall; and measure precision by recording verdicts.

Be clear

The recall of any validation system cannot be measured, by its structure.

Read moreLearned monitorsDerived expectations

8How many rows must you sample to catch a currency defect that affects 1 row in 100,000, when each affected row is worth 50,000 times a normal one?Show the answer

Estimate

= 3.0 ÷ 10⁻⁵ = 300,000 rows for 95% confidence; for 99% (−ln 0.01 = 4.6), 460,000. A uniform sample is costly and nearly useless for a rare but expensive defect.

Better

Sample by value (): weight rows by how much money they carry, and check the top ones; if a few thousand rows hold most of the money, check them all. by source or currency field, so a rare global defect becomes common within one stratum.

Best

A cheap rule on every record: the currency must be in the allowed set, and the amount within that currency's usual range. It costs nothing at parse time and beats sampling for this defect.

Read moreSampling: cheapest where it is weakestTwo escapes

9Design a feature store for 50 features and 2 million entities, with online reads under 10 ms.Show the answer

Design

One definition per feature; an offline store (columnar, append-only, with valid and availability times) for training; an online key-value store (one row per entity) for serving.

Choose the write path

SQL feeding both stores is simple but allows timing skew. Computing once in the path and writing to both closes it, but loses batch SQL as the language for definitions.

Monitor

The difference in freshness between the stores, paging above a threshold (for example 15 minutes).

Residual risk

in the input distribution needs separate monitoring.

Read moreWhat a feature store isWhy the guarantee is weaker than claimed