Data Pipeline Architecture and Design Questions
End-to-end design of data pipelines: source-to-sink flow, staging layers, idempotency, backfills, and reprocessing. Covers choosing between batch and streaming stages, decoupling ingestion from transformation, and designing for evolvability. The foundational systems-design skill for a data engineering interview.
A single stream of database change events needs to reach several very different downstream systems: a cache, a search index, and a warehouse. How would you fan that out, and what has to be true for each downstream system to stay consistent with the source?
Sample Answer
Direct answer
Publish the change stream once, through change-data-capture (CDC, a technique that captures row-level inserts, updates, and deletes from a source database as a stream of events) into a single durable, ordered log partitioned by primary key, and let the cache, the search index, and the warehouse each consume that log independently through their own idempotent apply logic. Consistency here does not mean all three agree at every instant; it means each one correctly converges to the source state once it has processed everything up to some point, at a staleness bound that fits what that system is actually used for.
Structured elaboration
One producer, many independent consumers. Capturing the change stream once and fanning it out through a shared log avoids coupling the three downstream systems to each other or to the source's write path; a slow search indexer never blocks the cache, and a cache outage never blocks the warehouse load.
Ordering is per-key, not global. Partitioning the log by primary key keeps every event for a given row in order relative to each other, which is the guarantee that actually matters. There is no practical way to guarantee a single global order across every row in the table at this scale, and none of the three downstreams need one.
What has to be true for each downstream, and why it's different:
| Downstream | What "consistent" means for it | How it stays that way |
|---|---|---|
| Cache | Serves live reads, so staleness has to be small; only the latest value per key matters, not history | Apply as a conditional write: only overwrite if the incoming event's version is newer than what's stored, so an out-of-order redelivery can't roll a key backward |
| Search index | Tolerates a few seconds to minutes of lag; needs the latest document state, not full history | Apply as an upsert keyed by document id with the same newer-than-stored version check; deletes become tombstones rather than silent removals |
| Warehouse | Tolerates minutes to hours of lag; often needs the full history of changes, not just the latest state | Apply every event, deduplicated by a stable event identifier or offset, typically in batches rather than continuously |
Idempotency is not optional for any of them. Because delivery from the log is normally at-least-once (a consumer can see the same event again after a restart or a retry), every downstream apply logic has to be safe to run twice, which is why the version or offset check matters more than the transport's own guarantees.
Schema tolerance matters as much as ordering. A column added upstream should be ignorable by a consumer that doesn't know about it yet; a column removed upstream should degrade to a default rather than break parsing. A consumer that can't tolerate either will silently drop or misparse records the moment the source schema changes, which is a common and quiet way "consistency" breaks in practice.
Eventual is not the same as guaranteed. Because each consumer applies independently and can lag or briefly misbehave, every downstream needs its own periodic reconciliation, comparing row counts or checksums against the source, rather than trusting the stream to have delivered everything correctly forever.
Worked example
Suppose the change log has 12 partitions and the source sustains 6,000 change events per second, evenly spread, so each partition carries:
126,000=500 events/sec per partitionIf the search-index consumer degrades and can only index 400 events per second per partition, each partition accumulates a backlog of:
500−400=100 events/secAfter 5 minutes (300 seconds) of that degraded rate, each partition has queued:
100×300=30,000 eventsAt the degraded processing rate of 400 events/sec, working through that backlog takes:
40030,000=75 secondsSo at that moment the search index is roughly 75 seconds behind the source, and the gap keeps growing as long as the consumer stays degraded, which is exactly the kind of staleness number a team would want on a dashboard for this specific downstream, since 75 seconds might be fine for search but would already be a problem for the cache.
flowchart LR
A[Source database] --> B[CDC capture]
B --> C[Partitioned log, keyed by primary key]
C --> D[Cache sink]
C --> E[Search index sink]
C --> F[Warehouse sink]
D --> G[Reconciliation vs source]
E --> G
F --> G
Trade-offs & pitfalls
- Treating "consistency" as one uniform target across all three sinks is the most common wrong turn: a warehouse can tolerate hours of lag, a cache serving live reads cannot tolerate more than seconds without visibly confusing users.
- Writing to all three sinks synchronously from the source, instead of fanning out from one shared log, couples the source's write latency and availability to the slowest downstream and removes any ability to retry one sink in isolation.
- A schema change is the most common cause of a silent consistency break; a consumer that isn't tolerant of an added or removed field can drop or misparse records with no visible error.
- Assuming ordering holds across the whole stream, rather than just per key, leads to logic that quietly breaks the first time two different keys' events are legitimately processed out of relative order.
- Skipping periodic reconciliation because "the stream should be reliable" is how silent drift goes unnoticed for weeks; every downstream needs an independent way to detect that it no longer matches the source.
Bad data occasionally reaches an executive dashboard before anyone notices. Design a data-quality strategy for this pipeline so that stops happening, without slowing down every normal run.
Sample Answer
Direct answer
Put the validation gate immediately before the point the dashboard actually reads from, not just at ingestion, and split checks into two tiers: cheap, structural checks (schema, row count, null rate) that block promotion synchronously because they are fast enough to never skip, and expensive, statistical checks (distribution drift, cross-source reconciliation) that run asynchronously and only block when they cross a hard severity threshold. That tiering is what lets every normal run stay fast while still catching the rare bad one.
Structured elaboration
Placement matters as much as the checks themselves. A check that runs somewhere upstream in the pipeline, but not immediately before promotion to what the dashboard reads, can be bypassed by any path that skips that stage: a manual hotfix, a one-off reload. The gate has to sit at the boundary between internal pipeline state and what is allowed to be read externally, typically a staging table or view that only gets promoted after passing.
| Tier | Examples | Cost | Placement |
|---|---|---|---|
| Structural (blocking) | schema match, row count within expected range, null rate under threshold, primary-key uniqueness | cheap, roughly constant-time via metadata or a count query | synchronous, blocks promotion |
| Statistical (advisory, escalating to blocking) | distribution drift versus a trailing baseline, cross-source reconciliation totals | requires scanning or aggregating the data | runs asynchronously; blocks only past a hard severity threshold, otherwise flags for review without holding up promotion |
Severity-based routing: not every failed check should halt the pipeline or page someone. Classify checks as hard-fail (never publish, a negative revenue figure) versus soft-fail (publish but annotate the dashboard and route to on-call for review), so a borderline, plausible-but-flagged check does not hold every normal run hostage the way a hard-fail check should.
Circuit breaker for the gate itself: if the last several promotions have failed validation, or the gate errors out, fail safe by continuing to serve the last known-good snapshot rather than either blocking indefinitely or letting unvalidated data through by default.
Worked example
A daily automated report pipeline extracts, aggregates, and then runs structural checks before promoting to the reporting table that feeds an automated email summary. Trailing 7-day average row count is 120,000 rows/day; the structural check allows a plus-or-minus 10% band:
120,000×1.10=132,000120,000×0.90=108,000
A run producing 40,000 rows, a 67% drop, falls far outside [108,000, 132,000], so it is held automatically and the email summary is not sent; the pipeline owner is alerted with the specific failed check, and last night's report keeps serving as the current version until someone resolves it. No human has to eyeball the report first to catch this kind of failure.
flowchart LR
source --> aggregate
aggregate --> structural{structural checks}
structural -->|pass| staging
structural -->|fail| hold["hold + alert owner"]
staging --> statcheck["async statistical checks"]
statcheck -->|severe| hold
statcheck -->|ok or advisory| promote
promote --> dashboard
hold --> lastgood["serve last known-good"]
lastgood --> dashboard
Trade-offs & pitfalls
Making every check synchronous and blocking would slow down every normal run to catch a rare bad one, exactly the cost the question is asking to avoid; tiering by cost, not removing checks, is the actual fix. Routing every failed check to a page burns out on-call and trains people to ignore alerts, the same alert-fatigue failure mode as over-notifying on any correction policy. A gate that only lives at ingestion misses corruption introduced by a later transformation step; the check has to sit right before the path the dashboard actually reads, or a later bug slips through untouched.
What is medallion (bronze/silver/gold) layering in a data pipeline, and what job does each layer do?
Sample Answer
Direct answer
Medallion layering organizes a lakehouse into three progressively refined storage layers: bronze holds raw data exactly as it arrived, append-only and unvalidated; silver holds cleaned, deduplicated, and conformed data still close to the source's row-level grain; and gold holds business-level aggregates and marts shaped for direct consumption by dashboards and analysts. Each layer's job is to isolate a different kind of change, source format drift, cleaning-logic bugs, business-definition changes, so fixing one kind of problem only requires reprocessing from the layer below it, not re-ingesting from the original source.
Structured elaboration
Bronze (raw). Ingested as-is from the source, whatever format it arrives in, append-only, tagged with ingestion metadata (source, timestamp, batch identifier), with no business logic applied. Its job is to be the durable, replayable record of exactly what arrived, so that if a downstream bug is found months later, it can be reprocessed without hitting the source system again.
Silver (cleaned and conformed). Parses and validates bronze, deduplicates, standardizes types and null handling, applies a schema, joins to reference or dimension data, and resolves late-arriving or out-of-order records. Still roughly one row per source record. Its job is to give every downstream consumer one trusted version of what the data means, instead of every team re-implementing its own cleaning logic against raw bronze.
Gold (curated, business-level). Aggregates and denormalizes silver into tables shaped for a specific consumption pattern, a business intelligence dashboard, an ML feature set. Its job is to encode business definitions, what counts as an active user, how revenue is recognized, in one governed place rather than scattered across every consumer's own query.
Why layer at all. Each layer isolates a distinct failure or change domain. A source schema change only requires a bronze or silver fix, not a full re-ingest. A redefinition of a business metric only touches gold, not the whole history underneath it. Reprocessing a layer replays from the layer directly below it, which is what makes iterative fixes cheap instead of full-pipeline reruns.
flowchart LR
S[Source systems] --> Br[Bronze: raw, append-only]
Br --> Si[Silver: cleaned, deduped, conformed]
Si --> Go[Gold: business aggregates and marts]
Go --> BI[Dashboards / BI tools]
Br -.reprocess.-> Si
Si -.reprocess.-> Go
Worked example
A source system emits 50 million raw events per day into bronze, roughly 2 KB per event, appended without filtering:
50,000,000×2 KB=100,000,000 KB≈100 GB/day (bronze)Silver deduplicates retries (say 2% of events are duplicate deliveries) and joins to a customer dimension:
50,000,000×(1−0.02)=49,000,000 unique, typed events 49,000,000×500 B≈24.5 GB (silver, columnar-compressed)Gold aggregates this down to one row per customer per day. If 3,000,000 distinct customers were active that day, gold's daily table has 3,000,000 rows. A dashboard that queried silver directly on every refresh, at roughly 50 bytes per aggregate row it actually needs, would scan far more than necessary:
3,000,000×50 B24.5×109 B≈163× more bytes scanned than gold requiresThat ratio is the concrete reason gold exists as its own layer rather than letting every dashboard query silver directly.
Trade-offs & pitfalls
Skipping silver and going straight from bronze to gold means every gold table re-implements its own cleaning and deduplication logic, so three marts built by three teams can quietly disagree on something as basic as how many customers were active on a given day, because their bespoke cleaning diverged. Over-layering, adding a fourth or fifth stage without a distinct kind of change to isolate, adds storage and pipeline hops without buying anything; the right number of layers is however many genuinely different failure domains exist, not a mandatory three. Bronze must stay genuinely raw and immutable: the moment "a little cleaning" is quietly applied on the way into bronze for convenience, the replay guarantee that is the entire point of the layer is lost.
You discover an upstream bug corrupted a key metric for the last 90 days. Design a backfill to correct the historical data without breaking the dashboards and reports that are actively being used right now.
Sample Answer
Direct answer
Recompute the corrected 90 days into a separate staging area using the fixed transform logic, verify the staged output against the current live data with automated checks, then swap the corrected partitions into place atomically, one bounded time window at a time, so dashboards keep reading a consistent, even if briefly stale, version throughout and never see a half-recomputed state.
Structured elaboration
Why staging plus atomic swap, not in-place correction
Correcting rows in place while dashboards are live means any query that runs mid-correction sees a mix of old and new values for the same metric, which is worse than being uniformly wrong. Writing the corrected 90 days to new, parallel storage and only swapping the read pointer once a whole window is verified keeps every read consistent: either the old, known-wrong-but-internally-consistent version, or the new, corrected-and-verified version, never a blend of both.
Windowing the backfill
Recompute in bounded time chunks rather than all 90 days at once. Each chunk gets verified and swapped independently, so a defect found partway through does not block chunks already verified, and a bug in the fix itself is caught on one small chunk before it has been applied to all 90 days.
Determinism is a precondition, not a nice-to-have
Before touching real data, confirm the corrected transform is deterministic: recomputing the same input window twice, same code, same raw input, must produce identical output. This matters just as much when the corrected logic is a code-driven feature transform feeding a model as when it is a simple metric aggregation: either way, running the backfill twice or out of order must not silently recompute the same window into two different results. If the fix relies on anything time-dependent or order-sensitive, such as a default that reads the current time, or an aggregation whose result depends on processing order, running the backfill twice or out of order produces different corrected values, which defeats the audit trail this whole design is trying to establish. Confirm reproducibility on one chunk before running the rest.
Verification before swap
Compare staged output to current live output for the same window on row counts, key aggregate totals (with the specific corrected metric expected to differ and every other metric expected to match exactly), and referential completeness, checking that the fix introduced no orphaned keys. Only swap a chunk once its verification passes; a failed chunk stays on the old, wrong data until investigated, without blocking chunks that already passed.
Communication as part of the design
Since dashboards stay live throughout, tell stakeholders which historical dates are still on the old, known-wrong numbers and which have already swapped to corrected values, so nobody draws a conclusion from a number mid-flight.
flowchart LR
Raw[Raw immutable source] --> Fix[Corrected transform logic]
Fix --> Staging[(Staging: recomputed partitions)]
Staging --> Verify{Verification checks pass?}
Verify -- Yes --> Swap[Atomic partition swap]
Verify -- No --> Retry[Investigate and re-run]
Swap --> Live[(Live tables: dashboards keep reading)]
Worked example
Assume the corrupted metric is computed from roughly 50 million source rows per day:
50,000,000 rows/day×90 days=4.5 billion rows to recompute
Chunking the backfill into 7-day windows:
90 days÷7 days/batch=12.86⇒13 batches (last one partial, 6 days)
which puts roughly
13 batches4.5×109 rows≈346 million rows per batch
a size the verification step needs to run against once per batch, thirteen times total, rather than once against the full 4.5 billion rows, which is what makes an early bug in the fix cheap to catch instead of expensive.
Trade-offs & pitfalls
- Correcting live tables in place, even for "just one column," is not atomic from a concurrent reader's point of view unless the store guarantees it, and most analytical stores do not at the row level during a bulk update.
- Running all 90 days as one giant job means a bug discovered on day 60 requires redoing all 90, instead of redoing one already-isolated chunk.
- Smaller chunks catch problems earlier and reduce blast radius but add coordination overhead (more swap events, more verification runs); chunk size should track how much the fix is trusted, not a fixed default.
- Skipping the determinism check because the fix "looks simple" is a common wrong turn; a fix that is not reproducible turns the audit trail, what changed, why, and by how much, into something nobody can reconstruct later.
A pipeline produces several kinds of metrics: some feed financial reporting, others feed an approximate usage dashboard. Would you engineer exactly-once delivery everywhere, or only for some of these outputs? How do you decide, and what does it cost you where you don't?
Sample Answer
Direct answer
No: exactly-once delivery should be reserved for outputs where a duplicated or dropped event has real cost, financial reporting, billing, anything reconciled against an external source of truth, and skipped for outputs whose entire premise is being approximate, like a usage dashboard. The mechanics needed to guarantee exactly-once, idempotent or transactional sinks, checkpointed state, coordinated commits, cost throughput, latency, and operational complexity that buy nothing for a metric nobody is reconciling row by row.
Structured elaboration
The decision criterion. Ask whether the output is reconciled against something external, money, a contractual commitment, a compliance obligation. If yes, it needs exactly-once, or more precisely, at-least-once delivery paired with an idempotent sink, since true exactly-once delivery across a network doesn't really exist; what's achievable is at-least-once delivery combined with processing that behaves as if it were exactly-once. If the output is inherently approximate, or its own consumers already tolerate noise (a live "users active now" counter), at-least-once, or even best-effort delivery that drops under backpressure, is enough.
What exactly-once costs where you pay for it. Stateful checkpointing overhead, transactional or two-phase-commit sinks, and coordination between the stream processor's state and the sink's commit all add latency and reduce the maximum achievable throughput compared with a simpler at-least-once path.
What skipping it saves where you don't pay for it. Simpler at-least-once consumers, higher achievable throughput per unit of compute, and less operational surface, no transactional sink to keep healthy, because a slightly wrong dashboard number self-corrects on the next refresh and nobody downstream audits it row by row.
The cost of skipping it, made concrete. A duplicate or dropped event produces a bounded, usually small, percentage error in the approximate metric. That error has to be genuinely tolerable to the actual consumer, a rounding-scale display number, not a per-transaction financial line, for the trade to be sound. If the "approximate" dashboard has quietly become an input to a real financial decision, the trade was wrong regardless of how it was originally designed.
Ingestion technology selection. Which message bus is chosen constrains which guarantee is cheap to get, and interacts directly with each path's latency and ordering requirements. A bus with transactional producers and consumers and log compaction makes exactly-once-equivalent delivery straightforward for the financial path. A lighter at-least-once bus, or even a loss-tolerant, fire-and-forget transport for extremely high-volume telemetry, is the right, cheaper choice for the approximate path. Choosing one bus for both paths means either over-paying for guarantees the dashboard never needed, or under-provisioning the ordering and durability the financial path actually requires.
Worked example
Two output streams: financial (order revenue, about 50,000 events/day) and a usage dashboard (page-view pings, about 500,000,000 events/day). The financial path applies an idempotent-sink pattern keyed on order identifier; at 50,000 events/day the per-event bookkeeping overhead is cheap in absolute terms regardless of its per-event cost, because the volume is tiny.
Applying that same per-event dedupe pattern to the dashboard path would mean:
50,000500,000,000=10,000× the per-event bookkeeping work of the financial pathfor a number that's displayed rounded to the nearest thousand anyway. If the dashboard's display tolerates being off by up to 0.1%, that tolerance is:
500,000,000×0.001=500,000 events of slack per daywhich is far larger than the duplicate or drop rate an ordinary at-least-once pipeline actually produces (network-retry duplicate rates are typically a small fraction of a percent, well inside that budget). Paying the exactly-once tax on 10,000 times the event volume would buy correctness inside a margin nobody would ever notice.
Trade-offs & pitfalls
The common wrong turn is applying one delivery-semantics decision to the whole pipeline instead of per output: either over-engineering, exactly-once everywhere, paying an unnecessary latency and throughput cost on the high-volume approximate path, or under-engineering, at-least-once everywhere, silently double-counting revenue. Another pitfall is assuming "approximate is fine" without ever checking who actually consumes that number today; dashboards have a way of quietly becoming real decision inputs over time without anyone updating their delivery guarantees to match. Finally, "exactly-once" is used loosely enough that teams sometimes assume the message bus alone provides it and skip building the idempotent processing layer that's actually doing the work, then get duplicates in production the first time a consumer restarts mid-batch.
Unlock Full Question Bank
Get access to all 38 Data Pipeline Architecture and Design interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.