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.
Explain the difference between at-most-once, at-least-once, and exactly-once delivery in a data pipeline. Why is true exactly-once end-to-end so hard to actually achieve?
Sample Answer
Direct answer
At-most-once delivers each event zero or one times, never retrying on an uncertain outcome, so failures can silently drop data; at-least-once retries until delivery is confirmed, so events arrive one or more times and consumers must tolerate duplicates; exactly-once means every event is reflected in the result precisely once, with neither loss nor duplication. True end-to-end exactly-once is hard because it requires every hop between producer and final sink to agree, atomically, on whether a given unit of work has already taken effect, and real pipelines are built from independent components that do not share one transaction.
Structured elaboration
The three guarantees
| Guarantee | What can go wrong | Typical mechanism | Consumer burden |
|---|---|---|---|
| At-most-once | Silent data loss on failure | No retry on an uncertain outcome | Must tolerate gaps, but never duplicates |
| At-least-once | Duplicates on retry | Retry until acknowledged | Must be idempotent to avoid double-counting |
| Exactly-once | Neither, in principle | At-least-once delivery plus idempotent application, coordinated hop by hop | None, if the guarantee genuinely holds end to end |
Why exactly-once is hard to actually get end to end
In practice it is "effectively-once," built from at-least-once delivery (never silently drop, always retry on doubt) plus idempotent processing at the consumer, so a duplicate delivery has no additional effect. A literal single-delivery guarantee, with no retries and no duplicates ever occurring anywhere, is not achievable across an unreliable network; the achievable guarantee is that duplicates never MATTER, not that they never happen. Each hop, producer to broker, broker to processor, processor to sink, has its own failure and acknowledgment model, so getting a coordinated guarantee across all of them means either every hop supports the same commit protocol, which is rare outside a single vendor's tightly integrated stack, or idempotency has to be built explicitly at whichever hop lacks it. The hardest case is the last hop, to a sink outside the pipeline's control, such as a third-party system with no concept of the pipeline's delivery semantics; a shared transaction cannot be imposed on a system that does not participate in one, so exactly-once there always reduces to at-least-once delivery plus an idempotent write at the sink.
The practical takeaway
Most production pipelines that describe themselves as exactly-once mean this composed guarantee, at-least-once delivery deduplicated by a stable key at whichever hop needs it, not a literal single-delivery promise. Designing for it means finding the hop with the weakest native guarantee and adding idempotency there, rather than trying to make the whole chain transactional.
Worked example
An order event travels from a producer through a message broker to a stream processor and then to an external payment application. The broker can guarantee at-least-once delivery to the processor through offset commits after processing. The processor can deduplicate internally using a stable order identifier. But the payment application is a third party; if the processor's call to it times out, the processor cannot tell whether the payment was already charged or not. The only real exactly-once guarantee left available at that last hop is the payment application itself supporting an idempotency key, so it deduplicates repeat calls carrying the same key, which is a property of the external system, not something the pipeline can impose.
Trade-offs & pitfalls
- Advertising "exactly-once" for the whole system when it is only true up to a boundary the pipeline does not control, such as a downstream application without idempotency support, overstates the guarantee.
- Choosing at-most-once for cost or simplicity where a dropped event is actually expensive, such as a billing event, when at-least-once plus a dedupe key would have been just as simple to build, is a costly shortcut.
- At-least-once plus idempotent consumers is usually cheaper and more robust to build than coordinating true distributed transactions across every hop, but it pushes real design work onto every consumer, which is easy to underestimate.
- Treating exactly-once as a checkbox a messaging system provides, rather than an end-to-end property that depends on the weakest hop, including hops outside the pipeline's control, is the most common wrong turn.
What is a dead-letter queue, and what problem does it actually solve for a pipeline that has to keep moving even when a few records fail?
Sample Answer
Direct answer
A dead-letter queue (DLQ) is a separate holding queue where a pipeline puts a record it couldn't successfully process, instead of blocking the whole run on it, silently dropping it, or crashing. It solves the problem of a pipeline needing to keep moving for the overwhelming majority of records that are fine, without losing the small number that aren't.
Structured elaboration
Why this is needed at all. Without somewhere to put a bad record, a processing stage has only two options when it hits one: stop everything until a human intervenes, which halts every good record queued behind it too, or silently skip and drop the bad one, losing it without a trace. Both are worse than isolating it.
What actually goes into it. Not just the failed record itself, but enough context to act on it later: the original payload, the reason it failed, when it failed, and how many times it was tried before landing here.
What a dead-letter queue is not. It is not a fix, and it is not the same as an error log. A queue nobody ever reads or reprocesses is functionally the same as silently dropping records, just with extra storage cost attached.
What has to exist alongside it for it to actually work. A way to notice it's growing, so a genuine upstream break doesn't go unnoticed for days, and a way to get corrected records back into the main flow. Without both, isolating the failure doesn't actually solve anything, it just relocates the problem.
Worked example
A pipeline processes 10,000 records in a run, and 7 of them fail parsing because of a malformed field:
10,0007=0.07%Without a dead-letter queue, the pipeline either stops the entire run of 10,000 records for those 7, or silently proceeds with the other 9,993 and nobody ever learns the 7 existed. With a dead-letter queue, the 9,993 good records finish normally, and the 7 are isolated along with their failure reasons, so someone can look at exactly those 7 without slowing down the other 99.93 percent of the batch.
Trade-offs & pitfalls
- A dead-letter queue with no monitoring on its growth rate can hide a real, ongoing upstream problem for a long time; a slow trickle and a growing crisis look identical if nobody's watching the rate.
- A dead-letter queue with no path back into the main flow is a graveyard, not a safety valve; isolating failures only pays off if corrected records can actually rejoin the pipeline.
- Using it as a catch-all for any exception, including genuine bugs in the pipeline's own logic, can mask defects that should fail loudly during development instead of quietly accumulating in production.
- It's built for isolating a minority of individually bad records; a systemic failure hitting most or all records calls for stopping the pipeline entirely, not queuing everything that comes through.
You inherit one large ETL job that does ingestion, transformation, and several downstream loads in a single deployable unit. Would you break it apart into smaller independently-deployable stages, and how would you decide where the boundaries go?
Sample Answer
Direct answer
Yes, in general break the monolith apart, but only along boundaries where two sides genuinely have different owners, different release cadences, or different failure domains, not just wherever the code happens to have a function boundary. The cut should define a bounded data product, its own schema, service-level agreement (SLA), and consumer contract, rather than an arbitrary step lifted straight out of the existing code.
Structured elaboration
Finding the boundaries. Map every output the job produces and who consumes it. Group outputs and the logic that produces them by business domain and ownership. Then look for genuinely low-coupling seams in the dependency graph, a stage whose output is read-only and consumed independently downstream is a good cut point; a stage that shares mutable intermediate state with its neighbor is not.
Deciding whether to split at all. Split when pieces need independent deploy cadence (one team ships fixes weekly, another monthly, and coupling them means blocking each other), independent scaling (one stage is bursty and compute-heavy, another is light and constant), or different failure tolerance (a non-critical report should not be able to block a financial load sharing its deployable unit). Splitting adds real cost, more dependency edges, more contracts to keep compatible, so it needs one of these reasons, not just "smaller files."
Organization-scale framing. Once more than one team is involved, the decision is as much about ownership as architecture. Each independently deployable stage needs a single accountable owner and a versioned contract other teams can build against without reading that owner's source. Skipping this just relocates the coupling from explicit code dependencies to undocumented cross-team assumptions, which is worse because it stays invisible until it breaks in production.
Undocumented, legacy-codebase framing. When the monolith has no documentation and thin test coverage, the current code structure cannot be trusted as evidence of the real data dependencies, a function boundary may exist for reasons that have nothing to do with what actually depends on what. The practical approach is to instrument the existing job first, log every table or file it reads and writes per code region, to reconstruct an empirical dependency graph, and treat that observed graph, not the module layout, as the source of truth for where a cut is safe.
Migration mechanics. Extract one bounded piece as a new stage and run it in shadow, in parallel, not yet consumed, alongside the intact monolith. Validate its output against the monolith's using partition-level checksums or keyed aggregates over a defined window. Cut consumers over only after that window is clean, and keep the old code path as a fallback until the new stage has been trusted in production.
Worked example
The monolith produces twelve downstream tables across three domains: orders (five tables, needing hourly refresh for an operations dashboard), customers (four tables), and inventory (three tables, daily refresh is sufficient):
5+4+3=12 downstream tables across three candidate boundariesOrders is the strongest candidate to extract first: it has both a distinct consumer (hourly ops dashboard) and a distinct cadence from the other two domains. The cutover bar for its shadow run should be defined in advance rather than judged by eyeball: for example, zero row-count and keyed-aggregate mismatches across three consecutive daily partitions, where any prior deltas are fully explained by the source's own known late-arrival window (say, at most two hours past a partition boundary). A threshold defined and checked this way, not "it looked right in a spot check," is what makes the decision to cut consumers over defensible.
Trade-offs & pitfalls
Splitting too finely, one stage per table, multiplies the number of contracts and DAG (directed acyclic graph) edges to maintain, and every edge is a place ordering or schema assumptions can silently drift apart. Splitting too coarsely, keeping unrelated domains in one deployable unit, means a slow query or bug in inventory logic can delay the orders load that operations depends on hourly. A common wrong turn is cutting consumers over before the shadow-run validation window has covered a full business cycle, such as month-end close, so an edge case like a backfill scenario only surfaces after cutover. Another pitfall is treating "no test coverage" as a reason to delay indefinitely, rather than building the checksum and shadow-run harness that substitutes for the tests that don't exist.
| Signal | Split? | Why |
|---|---|---|
| Different teams, different release cadence | Yes | Coupling blocks independent shipping |
| Shared mutable intermediate state between stages | No, not yet | Splitting here just moves the coupling into a contract that's harder to enforce |
| One stage bursty/compute-heavy, another light and constant | Yes | Independent scaling needs |
| Only a stylistic function boundary, same owner, same cadence | No | Adds orchestration cost with no organizational payoff |
Compare lambda architecture and kappa architecture. What operational complexity does each carry, and when would you actually choose one over the other?
Sample Answer
Direct answer
Lambda architecture runs two parallel pipelines: a batch layer that recomputes accurate results over full history and a speed layer that serves fast, approximate updates, reconciled at the serving layer. Kappa architecture runs a single stream-processing pipeline and treats reprocessing as replaying the same durable event log through the same code. Lambda buys mature batch tooling and easier correctness reasoning at the cost of maintaining two codepaths; Kappa buys one codebase at the cost of needing a stream engine mature enough to handle replay, state, and reproducible reprocessing on its own.
Structured elaboration
Operational complexity, side by side
| Dimension | Lambda | Kappa |
|---|---|---|
| Codepaths to maintain | Two (batch and speed), often different frameworks | One |
| Reprocessing mechanism | Re-run the batch job over history, reconcile with the speed layer | Replay the durable log through the same stream job |
| Risk of logic drift | High: batch and speed layers can silently diverge | Low: same code path, no second implementation |
| Infrastructure to operate | Batch scheduler, stream processor, and a merge or serving layer | Stream processor plus a durable, replayable log |
| Where correctness is proven | The batch layer is the eventual source of truth | The stream job itself must guarantee correctness, since there is no separate recompute to fall back on |
When the complexity actually tips the decision
Choose Kappa when a mature stream engine is already trusted, a single codebase is a real priority, and the log's retention and replay story is solid enough to treat backfill and normal processing as the same code path. Choose Lambda when heavyweight, well-audited batch logic (complex joins or aggregations that are painful to express as streaming state) needs to sit alongside a fast approximate path, and the reconciliation cost of two layers is acceptable. A pragmatic middle ground is a single logical transformation, expressed once, that runs in a streaming mode for low latency and in a batch replay mode for backfills using the same code, which captures most of Kappa's benefit without requiring the stream engine to handle every correctness case unaided.
flowchart TB
subgraph Lambda["Lambda architecture"]
L1[Event source] --> L2[Batch layer: full recompute]
L1 --> L3[Speed layer: incremental]
L2 --> L4[Serving layer: merge]
L3 --> L4
end
subgraph Kappa["Kappa architecture"]
K1[Durable event log] --> K2[Stream processor]
K2 --> K3[Serving layer]
K1 -. replay .-> K2
end
Worked example
A recommendation service needs online features updated sub-minute for scoring, while the model itself is retrained nightly on a full day's history, two different freshness requirements sitting side by side. Under Lambda, the natural mapping is a speed layer producing sub-minute online features and a nightly batch layer producing the training dataset, kept consistent only by discipline in sharing the same feature definitions across both. Under Kappa, the same stream job produces the sub-minute features continuously, and the nightly training set is materialized by replaying (or windowing) that same log up to the training cutoff. The operational complexity difference does not disappear here: Kappa still needs the stream job to correctly express the nightly aggregation window, and Lambda still needs discipline to stop the two feature-computation paths from drifting apart.
Trade-offs & pitfalls
- Picking Kappa without a stream engine that actually supports efficient, reproducible replay inherits the hardest part of streaming with none of batch's safety net.
- Picking Lambda and letting the two layers' business logic diverge over time, a bug fix landing in one but not the other, is the single most common Lambda failure.
- Kappa's "one codebase" claim only holds if reprocessing genuinely reuses the production job; a separate backfill script written on the side quietly rebuilds Lambda without calling it that.
- This is less a technology choice than a bet on whether the team can keep one stream codebase correct under replay, versus whether it can tolerate and actively reconcile two codebases.
One task in the middle of a multi-stage pipeline fails after some downstream tasks have already started consuming its incomplete output. How would you design the dependencies and retries so that failure doesn't cascade or corrupt what's already been produced?
Sample Answer
Direct answer
The fix is to make the failing task's output atomic and let its true completion, not a schedule offset, be the only signal downstream tasks act on: write to a staging location and only publish a completion marker once the full output is verified, and make the task idempotent so a retry reprocesses the same unit of work rather than compounding on whatever partial state exists. Anything downstream that already consumed the incomplete output before the failure was caught gets invalidated and rerun once the upstream retry succeeds, rather than being trusted as-is.
Structured elaboration
Atomic writes. The failing task should never let a partial write be visible to consumers. Write to a staging path, then publish a single completion marker (a manifest with expected file count and a checksum, or an explicit success flag) only after the full output is confirmed. Nothing downstream should read from anywhere except the promoted, marker-confirmed location.
Completion-gated dependencies, not schedule-gated. The DAG (directed acyclic graph)'s dependency edge should be "did the upstream task instance report success," evaluated against the true completeness check above, not "has some amount of time passed" or "does a file exist." A soft signal like row count greater than zero reintroduces the same race under a different name; the marker has to assert the expected count or checksum actually matches.
Idempotency of the retry. When the failing task retries, it must reprocess the exact same unit deterministically (the same partition, same key range) and overwrite its staging output wholesale rather than append to it, so a retry after a partial failure doesn't leave duplicate or half-old, half-new shards behind.
Containing already-consumed corruption. Since some downstream task already started reading the incomplete output before the failure surfaced, the design needs a reconciliation check: after the upstream retry finally succeeds, compare what the downstream task actually consumed against what the upstream task actually produced. A mismatch invalidates the downstream result and triggers its own rerun, rather than leaving stale output silently in place.
Blast-radius containment. Structure the DAG so a single failed partition or key range only forces reprocessing of that same partition downstream, not the entire pipeline; retries should be scoped to the smallest reprocessable unit, not "start over from the top."
Retry policy by failure class. Transient failures (timeouts, brief unavailability) get bounded retries with backoff. Non-transient failures (a schema violation, a poison record) should fail fast and page a human instead of retrying, since retrying a fundamentally broken input just delays the inevitable and can mask the real problem.
Worked example
Stage A writes a daily partition in ten shard files; stage B aggregates once A finishes. A crashes after writing 6 of the expected 10 shards:
shards written=6,shards expected=10,6=10Because A writes to a staging path and only promotes via a single manifest ("shards = 10, checksum = X") on success, those 6 partial shards are never promoted, so B's completion-gated trigger never fires for that partition; B simply never reads them. On retry, A reprocesses the whole partition idempotently, overwriting the staging directory rather than appending to it, so the retry cannot leave stray duplicates from the earlier partial attempt.
Now suppose a bypass (a manual override, or a bug in the gating logic) let B start early anyway, and B consumed only the 4 shards that existed at that moment. Once A's retry completes and publishes its final manifest (10 shards produced), a reconciliation check compares what B actually consumed against what A actually produced:
shards B consumed=4,shards A produced (final)=10,4=10The mismatch automatically marks B's output stale and triggers a B rerun against the now-complete A output, rather than leaving B's undercounted result available to be queried.
Trade-offs & pitfalls
Completion-gated triggers add latency compared to a naive early start: B waits for the full manifest even on days when 9 of 10 shards would have been fine. That latency is the price of correctness and is usually worth it; treating "mostly done" as "done" is exactly the bug being fixed. A common wrong turn is retrying the entire DAG from the top instead of just the failed task and its safely-reprocessable descendants, which wastes compute and, if any upstream write isn't actually idempotent, can create new duplicates rather than fixing the original ones. Another pitfall is over-decoupling into many small gated stages: each additional gate is one more thing to monitor and one more place a manifest check can itself have a bug, so the granularity of what gets a completion marker should match the actual unit that needs to be atomic and reprocessable, not be maximized for its own sake.
Unlock Full Question Bank
Get access to all 17 Data Pipeline Architecture and Design interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.