Batch or Stream?: Intermediate
What you will be able to do
The Decision Framework
| Factor | Favors Batch | Favors Streaming |
|---|---|---|
| Latency SLA | > 1 hour acceptable | < 5 minutes required |
| Data Volume | Bounded datasets, periodic loads | Unbounded, continuous arrival |
| Processing Complexity | Complex multi-pass joins, ML training | Filters, aggregations, enrichment |
| Cost Tolerance | Tight budget, shared cluster | Budget for always-on infra |
- ▸A common prompt: "Design a fraud detection pipeline" - the latency SLA is milliseconds, this is streaming. Say that immediately.
- ▸Another common prompt: "Build a driver earnings report" - daily aggregation, this is batch. Don't overcomplicate it.
- ▸The trap: both involve high volume, but latency requirements are totally different. The interviewer wants to see you anchor on latency, not volume.
- Fraud detection (ms latency)
- Real-time pricing/surge
- Live operational alerts
- Session-based personalization
- Daily financial reports
- ML model training
- Historical analytics
- Data warehouse loads
Lambda Architecture in Practice
Lambda architecture: the speed layer serves approximate results now; the batch layer reprocesses everything for correctness; the serving layer merges both. The cost is two codepaths for the same business logic.
- ▸The speed layer and batch layer WILL disagree temporarily - that's by design. Say this.
- ▸Convergence means: once batch reprocesses, both layers produce identical results
- ▸Red flag: if your streaming logic diverges from your batch logic, convergence breaks permanently
- ▸Senior signal: mention that many teams use the same processing code for both layers to prevent drift
- Low-latency results available immediately
- Batch layer guarantees correctness
- Can reprocess full history
- Tolerates streaming failures gracefully
- Two codepaths to maintain
- Merge logic adds complexity
- Higher infrastructure cost
- Risk of divergent results
Watermarks, Windows, Late Arrivals
- ▸You compute hourly_revenue for 2-3 PM = $10,000
- ▸A $500 transaction from 2:45 PM arrives at 3:20 PM
- ▸If the window is already closed, that $500 is lost from the aggregate
- ▸Downstream dashboards now show $10,000 - permanently wrong
- ▸With a 30-minute allowed lateness, the window stays open and the $500 is included. State this tradeoff explicitly.
| Window Type | Use Case | Late Data Behavior |
|---|---|---|
| Tumbling (fixed) | Hourly aggregates | Late events miss the window boundary |
| Sliding (overlapping) | Moving averages | Late events can update multiple windows |
| Session (gap-based) | User sessions | Late events can extend or merge sessions |
Spark Structured Streaming vs Flink
- Latency floor ~100ms (typically 1-10s)
- Familiar Spark API and ecosystem
- Easier for teams already using Spark batch
- Simpler state management
- True per-event, sub-millisecond latency
- Advanced windowing and event-time processing
- Better for complex stateful computations
- More powerful exactly-once guarantees
| Consideration | Spark Structured Streaming | Apache Flink |
|---|---|---|
| Latency | 100ms - 10s typical | < 10ms per event |
| State Backend | HDFS / RocksDB state store | Native RocksDB, incremental checkpoints |
| Learning Curve | Low if team knows Spark | Steeper, different programming model |
| Windowing | Basic tumbling/sliding | Advanced: session, custom triggers |
| Ecosystem | Delta Lake, MLlib, managed Spark platforms | Kafka tightly integrated, Flink SQL |
- ▸80% of 'streaming' use cases in production run on micro-batch with 1-60 second triggers
- ▸True per-event streaming is reserved for fraud detection, real-time bidding, and operational alerting
- ▸If your use case tolerates 10-second latency, micro-batch is dramatically simpler to operate. Say this.
Exactly-Once, Offsets, Checkpoints
| Guarantee | Behavior | Use Case |
|---|---|---|
| At-most-once | Process event, then commit offset. Lost events on failure. | Logs, metrics where some loss is acceptable |
| At-least-once | Commit offset after processing. Duplicates on failure. | Most pipelines - deduplicate downstream |
| Exactly-once | Atomic commit of offset + output. No loss, no duplicates. | Financial transactions, billing |
- ▸Flink snapshots all operator state to durable storage at checkpoint intervals
- ▸On failure, the job restarts from the last successful checkpoint
- ▸Default checkpoint interval: 10 seconds - the interviewer may ask you to tune this
- ▸Checkpoint duration should be << checkpoint interval, or you create backpressure
> The interviewer says: "Design a pipeline for our payments product. We need fraud scoring on each transaction and a daily earnings report for merchants. The PM says everything should be real-time." You have a whiteboard and about fifteen minutes, and every follow-up will probe late data, framework choice, and what happens when the job crashes.
enable_auto_commit=False with manual offset commit after the sink write, and Flink checkpoints whose duration stays well under the interval so checkpointing does not become its own backpressure.COALESCE plus CASE serving-layer merge expresses; sharing processing code across both layers is what prevents permanent drift.enable_auto_commit=False so offsets commit only after the sink write succeeds.The architecture decision that defines your pipeline
- Category
- Pipeline Architecture
- Difficulty
- intermediate
- Duration
- 35 minutes
- Challenges
- 2 hands-on challenges
Topics covered: When Would You Use Streaming?, Design for Both Batch and Stream, What About Late Data?, Micro-batch or True Streaming?, How Do You Handle Failures?
Lesson Sections
- When Would You Use Streaming? (concepts: Batch vs Streaming)
The Decision Framework The interviewer wants to hear a number, not a vibe. Your first sentence should be: "What's the latency SLA?" Not "do we want real-time" - that's a wish, not a requirement. If they say "daily is fine," you just eliminated streaming from the conversation. That's a senior signal - you saved six months of unnecessary infrastructure. There are exactly four factors that drive the batch-vs-stream decision. Your answer should walk through all four. Miss any one of them and the int
- Design for Both Batch and Stream (concepts: Lambda Architecture)
Lambda Architecture in Practice Here's the reality the interviewer is testing: production data platforms almost always need both batch and streaming. Batch gives you correctness. Streaming gives you speed. The question is how you merge them without creating a maintenance nightmare. Your answer should acknowledge both sides and then explain the merge strategy. The Lambda architecture formalized this pattern: a speed layer (streaming) serves approximate results immediately, while a batch layer rep
- What About Late Data? (concepts: Late-Arriving Data)
Watermarks, Windows, Late Arrivals This is the #1 follow-up question after you propose a streaming architecture. Interviewers commonly ask some version of: "A user clicks at 11:59 PM but the event arrives at 12:03 AM. Which day does it belong to?" If you've already closed the daily window at midnight, you've got a problem. The interviewer wants to hear three words: watermark, allowed lateness, dead-letter. Start your answer here: a watermark is the system's estimate of "how far behind is the lat
- Micro-batch or True Streaming? (concepts: Micro-Batch vs True Streaming)
Spark Structured Streaming vs Flink The interviewer is testing whether you pick a framework based on requirements or based on resume keywords. "Streaming" is a spectrum, not a binary. On one end, Spark Structured Streaming processes data in small batches (micro-batches) with a latency floor around 100 milliseconds. On the other end, Apache Flink processes each event individually. Your answer should match the framework to the SLA, not to your personal preference. The trigger interval in Spark SS
- How Do You Handle Failures? (concepts: Idempotency)
Exactly-Once, Offsets, Checkpoints Every streaming system will fail. The interviewer knows this. The question isn't whether failures happen - it's whether your pipeline produces correct results when they do. Your answer framework: start with delivery guarantees, then explain offset management, then describe your idempotency strategy. Hit all three and you've covered the full rubric. The interviewer wants to hear that at-least-once is the production default. Not exactly-once. The trap is answerin