Stream and Batch Processing
1. Executive Summary
Stream processing continuously transforms unbounded event streams with low latency; batch processing applies transformations to bounded datasets with high throughput and simpler fault tolerance. Modern data platforms rarely choose one exclusively—they implement unified engines (Apache Flink, Spark Structured Streaming) that expose similar APIs for both, while architectural patterns (Lambda, Kappa) describe how organizations combine speed and correctness layers.
Principal architects must reason about event time vs processing time, watermarks and late data, delivery semantics (at-most-once, at-least-once, exactly-once), and state management at scale. The interview-critical insight: exactly-once end-to-end requires cooperation between the processor, message broker, and sink—not a single checkbox in Flink configuration.
This chapter covers mechanisms, guarantees, failure modes, and production patterns for batch and stream pipelines powering analytics, fraud detection, and real-time features.
2. Why This Topic Matters
Every principal data architecture interview touches processing semantics:
- When stream vs batch? — Latency SLO, cost, correctness requirements.
- How handle late events? — Watermarks, allowed lateness, retractions.
- Exactly-once reality — Idempotent sinks, transactional commits, Kafka offsets.
- Lambda vs Kappa — Operational burden vs simplicity.
- Backpressure — What happens when sink slows.
Teams that confuse processing-time windows with event-time windows ship dashboards that drift from financial truth after outages or clock skew.
3. Problems Being Solved
| Problem | Processing approach |
|---|---|
| Daily reports on TB datasets | Batch (Spark, Hive, SQL warehouse) |
| Real-time fraud scoring | Stream (Flink, Kafka Streams) |
| Near-real-time metrics | Micro-batch or stream with short windows |
| Reprocessing history | Batch replay or Kappa re-read from log |
| Correct aggregations under disorder | Event-time + watermarks |
| Joining streams to reference data | Broadcast state, temporal joins, lookup tables |
Workload fit matrix
| Workload | Batch | Stream | Hybrid |
|---|---|---|---|
| Monthly regulatory report | ✓ | ||
| 200 ms fraud alert | ✓ | ||
| 5-minute sales dashboard | ✓ | micro-batch OK | |
| ML training on full history | ✓ | ||
| Sessionization | ✓ | ||
| Nightly dimension sync | ✓ | stream CDC optional |
4. Assumptions and System Model
| Assumption | Implication |
|---|---|
| Events are immutable facts | Corrections via compensating events or retractions |
| Clocks are not synchronized | Use event timestamps, not now() at processor |
| Brokers retain logs | Replay enables recovery and Kappa reprocessing |
| State fits or spills | RocksDB/state backend sizing for Flink |
| Sinks may not be transactional | End-to-end exactly-once needs idempotent design |
Safety: Correct aggregations within declared lateness bounds. Liveness: Progress requires consumer groups advancing; stuck watermarks block window closes.
5. Essential Terminology
| Term | Definition |
|---|---|
| Event time | Timestamp embedded in event payload |
| Processing time | Wall clock when processor observes event |
| Watermark | Lower bound on unseen event times in stream |
| Window | Bounded slice for aggregation (tumbling, sliding, session) |
| Allowed lateness | Grace period after watermark for late events |
| Checkpoint | Flink periodic consistent snapshot of state + offsets |
| Micro-batch | Spark Streaming divides stream into small batch jobs |
| Side output | Route late or invalid records to separate stream |
| Retraction | Update prior emission when late data changes result |
| Changelog stream | Table represented as insert/update/delete events |
6. Core Mechanism
6.1 Lambda architecture (historical pattern)
Figure 1: Lambda maintains separate speed (approximate) and batch (correct) paths merged at query time—high operational cost.
6.2 Unified stream processing
Figure 2: Single engine with durable log, checkpointed state, and transactional or idempotent sink.
6.3 Event-time windows and watermarks
Figure 3: Watermark advances with observed event times; late events handled per allowed lateness policy.
7. Step-by-Step Walkthrough
Walkthrough A: Spark batch ETL
- Airflow triggers nightly Spark job reading partitioned Parquet in lake.
- Transformations: join dimensions, aggregate daily revenue per region.
- Output written to gold table with partition
report_date. - Job commits table snapshot; downstream BI refreshes semantic layer.
- Failure mid-write: rerun job; idempotent overwrite on partition.
Walkthrough B: Flink event-time aggregation
- Job consumes
paymentstopic with event timestamppayment_ts. - Assign watermarks:
max_event_time - 5 secondsbounded out-of-orderness. - Tumbling 1-minute windows count transactions per merchant.
- Checkpoint every 60s to S3; Kafka offsets stored in checkpoint.
- Sink writes upserts to JDBC with primary key
(merchant_id, window_end).
Walkthrough C: End-to-end exactly-once (conceptual)
- Flink uses Kafka transactional producer per checkpoint epoch.
- Two-phase commit sink (e.g., JDBC XA or Iceberg commit) participates in checkpoint.
- On failure, restart from last completed checkpoint; uncommitted epoch aborted.
- Safety: no duplicate visible records. Cost: latency tied to checkpoint interval.
Walkthrough D: Kappa reprocessing
- Bug in aggregation logic discovered; fix deployed.
- Reset consumer offset to
T0or deploy new application version reading compacted topic from beginning. - Rebuild materialized view from immutable log—batch layer unnecessary.
- Requires sufficient Kafka retention or tiered storage archive.
Walkthrough E: Flink SQL over Kafka with upsert sink
CREATE TABLE orderswith Kafka source and upsert-kafka sink to compacted topic.- Changelog semantics:
+I,-U,+Urow kinds from CDC source. - Primary key defined on
order_id; state backend stores latest row per key. - Checkpoint aligns Kafka consumer offset with sink transactional write.
- Downstream batch job reads compacted topic as silver input—unified log contract.
Walkthrough F: Backpressure during Black Friday spike
- Traffic 8× baseline; Flink operator
busyTimeMsPerSecondhits ceiling. - Kafka consumer lag grows; autoscaler adds task managers (if configured).
- Gateway applies admission control on non-critical stream consumers.
- Batch reconciliation job runs hourly comparing stream aggregates to warehouse truth.
- Post-event review tunes parallelism, checkpoint interval, and max lag SLO.
Engine selection matrix (principal decision aid)
| Criterion | Prefer Flink | Prefer Spark |
|---|---|---|
| Sub-second event-time windows | ✓ | |
| Nightly 50 TB batch | ✓ | |
| Complex CEP patterns | ✓ | |
| Team skill: SQL batch only | ✓ | |
| Exactly-once to Iceberg sink | ✓ (connector maturity varies) | ✓ |
| ML feature batch + stream unity | ✓ (Structured Streaming) |
Document the choice in an ADR; revisit when latency SLO tightens or team skills shift.
8. Invariants and Guarantees
| Semantic | Guarantee |
|---|---|
| At-most-once | No duplicates; may lose messages |
| At-least-once | No loss; duplicates possible without dedup |
| Exactly-once (processor) | Checkpoint aligns state and source offsets |
| Exactly-once (end-to-end) | Requires transactional/idempotent sink |
Window correctness: Holds only if event timestamps trustworthy and lateness policy matches business rules.
9. Failure Scenarios
| Failure | Behavior | Mitigation |
|---|---|---|
| Task manager crash | Restart from checkpoint | HA Kafka; adequate checkpoint storage |
| Checkpoint timeout | Backpressure; lag grows | Scale parallelism; tune interval |
| Watermark stuck | Windows never close | Idle source watermark; processing-time fallback |
| State backend corruption | Job cannot restore | Remote checkpoints; backup strategy |
| Sink partial write | Duplicates on retry | Idempotent keys; transactional sink |
| Skewed key | Hot task bottleneck | Key salting; custom partitioner |
| Broker outage | Consumer pause | Multi-AZ cluster; mirror topics |
Scenario narrative
During network partition, Flink job falls behind; watermarks lag real time. Dashboard shows stale 1-minute counts while batch nightly job still correct. Operations must define which layer is source of truth per metric and alert on stream lag separately from batch SLA.
10. Performance Characteristics
| Dimension | Batch | Stream |
|---|---|---|
| Latency | Minutes–hours | Sub-second to minutes |
| Throughput | Very high per dollar | High with tuning |
| Fault tolerance | Recompute partition | Checkpoint restore |
| State access | Shuffle joins costly | Local keyed state fast |
| Operational complexity | Lower | Higher (watermarks, state) |
Micro-batch (Spark) trades latency for simpler fault model—often 100ms–seconds, not true sub-100ms.
11. Scalability Limits
- Keyed state size per operator—must fit RocksDB + memory or use external store.
- Kafka partition count bounds consumer parallelism.
- Shuffle-heavy joins on infinite streams require careful state TTL.
- Checkpoint duration must stay << interval at scale.
- Global windows without bounds—unbounded state; prohibited pattern.
12. Operational Considerations
- Monitor consumer lag, checkpoint duration, backpressure ratio, late event rate.
- Version savepoints before incompatible state schema changes.
- Document event-time field contract with producers; reject missing timestamps.
- Run chaos tests: kill task managers during peak load.
- Separate dev/staging topics; never test against production consumer groups.
- Align retention with reprocessing window for Kappa.
13. Security Considerations
- ACLs on Kafka topics per pipeline service account.
- Encrypt data in transit (TLS) and at rest on state/checkpoint storage.
- PII handling in stream—mask before wide replication.
- Secrets for sink credentials via vault, not job configs in git.
14. Cost Considerations
- Always-on Flink cluster vs scheduled Spark—stream costs continuous compute.
- Kafka retention for reprocessing—storage grows with retention × throughput.
- Checkpoint storage I/O on S3/GCS.
- Over-provisioned parallelism wastes vCPU; right-size with autoscaler where supported.
Extended failure scenario: Kafka broker rolling restart
During a planned Kafka broker restart, partition leaders migrate. Flink jobs with aligned checkpoint mode may pause checkpoint barriers until all operators acknowledge the new leader—checkpoint duration spikes from 30s to 4 minutes. Consumer lag appears healthy while checkpoint age breaches SLO. Mitigation: use unaligned checkpoints where supported, increase checkpoint.timeout, schedule broker maintenance during low-traffic windows, and alert on lastCheckpointDuration not just lag. Principal architects document this interaction in runbooks—streaming teams and Kafka admins often operate in silos until an incident connects them.
State backend sizing worked example (illustrative)
A sessionization job keyed by user_id with 24-hour session window retains ~50 million keys at peak. At 200 bytes per key state entry, RocksDB state ≈ 10 GB plus overhead—fits single task manager with 16 GB heap. At 10× traffic, state grows linearly unless TTL evicts idle sessions. Architecture review should mandate state TTL and managed RocksDB memory before production promotion. Embarrassingly parallel jobs without keyed state scale more predictably than session windows at billion-user scale.
Batch vs stream organizational boundary
Principal architects often mediate between data engineering (batch-first) and real-time engineering (stream-first) teams. A durable agreement: batch owns authoritative financial reconciliation; stream owns operational alerting and near-real-time features; disputes escalate via shared metric catalog with explicit source_of_truth tags. Without this, executives receive conflicting dashboards and teams optimize locally. Platform standards should include a messaging contract template mandating delivery semantics, schema registry linkage, and DLQ policy for every new topic.
15. Production Implementations
Case study: Real-time fraud + daily reconciliation (illustrative)
Business context
Payment processor needs <500ms fraud scoring and daily audited totals matching ledger.
Architecture
Flink job: event-time windows, rules + ML model via async I/O. Gold fraud decisions to Kafka decisions. Nightly Spark reconciles stream aggregates vs warehouse ledger; mismatch alerts.
Semantics
Stream: at-least-once to external API with idempotency keys. Warehouse sink: exactly-once via Iceberg two-phase commit on checkpoint.
Tradeoffs
| Choice | Tradeoff |
|---|---|
| Flink over Spark Streaming | Lower latency vs team familiarity |
| 5s watermark bound | Accuracy vs window close delay |
| Separate reconciliation | Ops burden vs trusting stream alone |
Interview lessons
Never claim exactly-once without naming sink cooperation; separate real-time approximate from batch authoritative when required.
16. Alternatives and Tradeoffs
| Pattern | Pros | Cons |
|---|---|---|
| Pure batch | Simple, cheap | High latency |
| Pure stream (Kappa) | Single path | Replay cost; stream complexity |
| Lambda | Speed + accuracy | Dual pipelines; merge bugs |
| Micro-batch | Middle ground | Not lowest latency |
| Materialized CDC | DB → stream without app changes | Transformation lag |
17. Common Misconceptions
| Misconception | Reality |
|---|---|
| "Flink exactly-once = end-to-end" | Sink must participate |
| "Processing time is good enough" | Out-of-order breaks correctness |
| "More partitions always faster" | Overhead; ordering per key |
| "Kappa eliminates batch" | Historical replay is batch-like |
| "Windows close at wall clock" | Close on watermark in event time |
18. Principal Architect Perspective
- Define delivery semantics per sink, not per platform slogan.
- Contract event timestamps at producer boundary.
- Prefer Kappa when log retention and team skill support it; avoid Lambda unless justified.
- Instrument lag and watermark age as first-class SLIs.
- Reconciliation jobs remain valuable for money-moving systems.
Operating playbook (first 90 days)
Days 1–30: Inventory all production topics and jobs; tag each with delivery semantic (at-most/at-least/exactly-once) and source_of_truth flag for downstream metrics. Deploy OpenLineage or equivalent on top three revenue-impacting pipelines first.
Days 31–60: Establish watermark and allowed-lateness policies per stream; document in data contracts. Run chaos test: kill Flink task manager during peak; measure recovery time vs SLO.
Days 61–90: Eliminate duplicate Lambda paths where Kappa replay is viable; or formalize reconciliation SQL with alerting threshold. Present FinOps report: streaming always-on cost vs batch savings realized.
Principal architects use this playbook to show operational maturity, not just diagram fluency.
19. Architecture Review Exercise
Scenario: Team uses processingTime windows for billing aggregates because "it's simpler."
Findings: Replay after outage double-counts or mis-assigns periods. Mandate event-time, idle watermarks, reconciliation batch, documented allowed lateness.
20. Whiteboard Explanation
"Batch processing reads a bounded dataset—tonight's partition—and recomputes outputs idempotently. Stream processing treats Kafka as an append-only log, maintaining keyed state and advancing watermarks from event timestamps to know when a time window is complete. Flink checkpoints snapshot operator state and Kafka offsets together so restart is consistent. Exactly-once to a database requires the sink to commit in the same transaction boundary as the checkpoint, or use idempotent upserts. Lambda ran fast and slow paths; most teams now prefer one log and one engine with replay for corrections."
Principal addendum: Draw delivery semantics as a chain: source → processor → sink. Weakest link defines end-to-end guarantee. Interviewers reward naming the sink explicitly—JDBC, Iceberg, HTTP API each differ. Mention reconciliation for money: stream for speed, batch for audit truth.
21. Interview Questions
- Event time vs processing time? — Payload timestamp vs observation time.
- What is a watermark? — Progress marker for event-time completeness.
- At-least-once vs exactly-once? — Duplicates vs coordinated commit.
- Lambda vs Kappa? — Dual path vs single log reprocessing.
- Flink checkpoint purpose? — Fault-tolerant consistent snapshot.
- Spark Structured Streaming model? — Micro-batch or continuous processing.
- Handle late data? — Allowed lateness, side outputs, retractions.
- Stateful operator example? — Sessionization, running aggregate.
- Backpressure? — Slow sink propagates pressure upstream.
- When prefer batch? — High latency tolerance, huge historical scans.
- Kafka partition ordering guarantee? — Per-partition order only.
- Idempotent sink pattern? — Primary key upsert with deterministic ID.
- Session window? — Gap-based dynamic windows.
- Reconciliation need? — Financial correctness independent of stream SLI.
Scoring rubric (principal)
| Dimension | Strong | Weak |
|---|---|---|
| Semantics | End-to-end sink discussion | "Exactly-once enabled" |
| Time model | Watermarks + lateness | Processing time only |
| Ops | Checkpoints, lag, savepoints | Ignores failure |
| Patterns | Kappa tradeoffs | Buzzwords only |
22. Interview Follow-Ups
- Design clickstream aggregation with 1% events 10 min late. — Watermark bound + allowed lateness + side output to correction topic.
- Checkpoint interval tradeoff. — Smaller = less replay, more overhead.
- Join stream to slowly changing dimension. — Temporal table join or broadcast with versioning.
- Prove at-least-once produces duplicates. — Retry after sink success before offset commit.
- Scale Flink job 10x. — Increase partitions, parallelism, state backend capacity.
Additional principal scenarios
Scenario: CFO asks whether stream processing can replace month-end batch close. Answer: Only if you prove byte-for-byte reconciliation over full history, document watermark/lateness bounds for every revenue metric, and accept always-on compute cost. Most regulated orgs keep batch authoritative with stream for operational visibility.
Scenario: Team proposes Flink on every microservice. Answer: Use streams for event backbone and derived views, not per-service stateful Flink unless latency requires it. Operational burden scales with job count.
Scenario: Exactly-once checkbox enabled but HTTP sink duplicates on retry. Answer: Name the gap—sink is at-least-once; add idempotency keys or transactional sink; update architecture diagram weakest-link annotation.
Principal architects should diagram the delivery semantic chain on every architecture review whiteboard—source, processor, sink—with explicit weakest link labeled.
22A. Production Low-Level Design (Interview + Game Day)
Kafka → Flink → Iceberg pipeline with checkpointed exactly-once. Production LLD and Game Day Standard.
Control vs data plane
| Plane | Components |
|---|---|
| Control | Flink JobManager, checkpoint coordinator, savepoint store, schema registry |
| Data | Kafka partitions, TaskManagers, state backend, transactional sinks |
Step-by-step EOS path:
| Step | Action | Semantic |
|---|---|---|
| 1 | Aligned checkpoint barriers | Consistent operator state |
| 2 | Offsets stored in checkpoint | Restart from consistent point |
| 3 | Kafka transactional producer epoch | Abort incomplete txn on failure |
| 4 | Iceberg two-phase commit sink | Visible only after checkpoint |
| 5 | HTTP sink (if any) | At-least-once + idempotency keys |
Pipeline contract
| Field | Value |
|---|---|
| Checkpoint interval | 60s (EOS visibility vs overhead) |
| Parallelism | = Kafka partition count (scale unit) |
| Watermark | event-time + allowed lateness 10m |
| Weakest link | Document per sink |
One SLO
Stream lag: consumer lag p99 < 30s; checkpoint duration p99 < 30s; failed checkpoint alert within 1 interval.
22B. Game Day Playbooks
| # | Drill | Inject | Detect | Mitigate | Verify |
|---|---|---|---|---|---|
| GD-1 | TaskManager OOM | Kill TM mid-checkpoint | Checkpoint failed metric | Scale memory; reduce state | Checkpoint succeeds next interval |
| GD-2 | Late event flood | Replay 10m late events | Side output volume spike | Tune allowed lateness | Gold metrics within SLA |
| GD-3 | Sink duplicate on retry | HTTP sink without idempotency | Duplicate rows in DB | Add idempotency keys | Reconciliation passes |
GD-1 — Checkpoint failure loop
23. Strong Answer Example
Question: "How do you achieve exactly-once processing with Kafka and Flink?"
Answer this as a 45-minute greenfield design using the PRACTICE framework. Below is how a strong student sounds aloud—separate pipeline EOS from end-to-end EOS, then name the sink as the weakest link.

Figure A: PRACTICE map — Problem → Requirements → Assumptions → Capacity → Topology → Invariants → Constraints → Evolution.
Student interview script (PRACTICE)
P — Problem framing
"We need exactly-once so failures and restarts don't double-apply business effects—fraud scores, ledger updates, order counts. Kafka alone is typically at-least-once to consumers; Flink's 'exactly-once' checkbox is not end-to-end by itself.
I'll design Kafka → Flink → sink and be explicit: exactly-once inside the Flink pipeline via checkpoints, and end-to-end only if the sink participates in the same commit epoch—or we use idempotent upserts.
Non-goals for v1: at-most-once fire-and-forget, and claiming EOS to a raw HTTP API without keys."
R — Requirements
| Type | Requirement |
|---|---|
| FR | Consume Kafka, stateful transforms (windows/keyed state), write results downstream |
| NFR | After crash/restart, no duplicate visible effects for EOS sinks; lag within SLO |
| Semantics | Document pipeline EOS vs end-to-end EOS per sink |
| Ops | Checkpoint duration/age alerts; savepoints for upgrades; reconciliation for money |
"I'll ask: sink is Kafka, Iceberg/JDBC, or external HTTP? Monetary? I'll assume Kafka out + one DB/lake sink, and call out HTTP as at-least-once + idempotency."
A — Assumptions (state aloud)
| Assumption | Why it matters |
|---|---|
| Flink checkpointing enabled (aligned or unaligned) | Consistent state + offset snapshot |
| Kafka source offsets stored in the checkpoint | Restart replays from consistent point |
| Kafka transactional producer / 2PC sink for Kafka→Kafka | Epoch commit/abort |
| Sink may not be transactional | Then EOS is effective via idempotency, not true 2PC |
| Checkpoint interval trades latency vs recovery | Visible EOS latency ≈ interval for transactional sinks |
"If they say 'enable exactly-once in Flink and Kafka guarantees no duplicates,' I'd correct: broker ≠ application EOS; sink decides."
C — Capacity (back-of-envelope)
Input rate (say) → 50K events/sec
Checkpoint interval → 30–60s (EOS visibility / commit cadence)
Checkpoint timeout → must exceed barrier alignment under load
State size → keyed state + timers; RocksDB on local SSD
Checkpoint storage → S3; duration grows with state + backpressure
Kafka partitions → bound parallelism (= consumer instances)
Consumer lag SLO → e.g. p99 lag < 30s; checkpoint age separate alert
Failure recovery → restore last complete checkpoint; abort uncommitted epoch
"I'd size for checkpoint duration under peak, not just lag—broker restarts can spike barrier alignment time."
T — Topology (draw this)

Figure B: Kafka source → Flink (state + checkpoints) → transactional/idempotent sink; weakest link labeled when sink can't 2PC.
Two layers of "exactly-once" (say aloud):
| Layer | What it means | Mechanism |
|---|---|---|
| Pipeline / Flink EOS | Operators don't double-apply state after restore | Checkpoint barriers; state + Kafka offsets snapshotted together |
| End-to-end EOS | Downstream never shows duplicates from retries | Sink pre-commit / commit with checkpoint epoch, or deterministic idempotent writes |

Figure C: Barrier → snapshot state+offsets → sink pre-commit → commit on success; failure aborts epoch and restores last complete checkpoint.
Protocol I'd walk on the whiteboard:
- JobManager injects checkpoint barrier into streams.
- Operators align (or unaligned mode), flush state to checkpoint storage.
- Snapshot includes Kafka consumer offsets for this epoch.
- Sink pre-commits transactional writes (Kafka TX producer, Iceberg commit, JDBC XA, …).
- Checkpoint completes → sink commits epoch → effects become visible.
- Crash before commit → restart from last complete checkpoint; abort uncommitted epoch → no duplicate visible records.
I — Invariants (safety)
"Non-negotiable:
- Offsets and state restore together—never commit Kafka offsets ahead of state.
- Uncommitted sink epochs abort on recovery—no partial publish.
- Idempotent business keys when sink can't do 2PC (
order_idupsert, deterministic doc IDs).- Per-partition Kafka order only—don't assume global order across keys.
- Name the weakest link on the architecture diagram every time."
C — Constraints (second C)
| Constraint | Design response |
|---|---|
| HTTP / webhook sink | At-least-once + idempotency keys; not true EOS |
| Checkpoint interval vs latency | Smaller interval → lower EOS lag, more overhead |
| Aligned checkpoints + Kafka rebalance | Duration spikes; unaligned / tune timeout; maintenance windows |
Kafka enable.idempotence alone | Producer EOS ≠ consumer/Flink/sink EOS |
| Money / ledgers | Stream approximate + batch reconciliation as authority |
| Upsert-kafka compacted topics | Effective EOS for keyed tables; understand compaction |
E — Evolution (prove + harden)
Phased delivery:
| Phase | Deliverable |
|---|---|
| M1 | Flink + Kafka source; checkpointing; at-least-once sink with metrics |
| M2 | EOS mode + Kafka transactional sink (or Iceberg 2PC) for critical path |
| M3 | Idempotent path for non-TX sinks; document semantic per topic |
| M4 | Lag + checkpoint duration/age SLOs; savepoint upgrade runbook |
| M5 | Nightly reconciliation vs warehouse for monetary aggregates |
Failure modes I'd mention:
| Failure | Mitigation |
|---|---|
| TaskManager crash | Restore last complete checkpoint; abort open TX epoch |
| Sink commit fails after pre-commit | Epoch abort; retry from checkpoint |
| Duplicate HTTP posts | Idempotency-Key / upsert; never claim EOS |
| Checkpoint too slow | Backpressure, state tuning, unaligned checkpoints |
| "EOS enabled" but wrong sink | Architecture review: label weakest link |
Observability: checkpoint_duration, checkpoint_age, consumer lag, sink commit failures, duplicate rate (where measurable), reconciliation diffs.
Closing line (interview)
"So: Flink checkpoints give exactly-once inside the pipeline by snapshotting operator state + Kafka offsets together. End-to-end needs the sink in the same 2PC epoch—Kafka transactional producer, Iceberg, JDBC XA—or idempotent upserts if it can't. I never say 'Flink exactly-once' without naming the sink. For money, I still run batch reconciliation."
Scoring signals
| Strong | Weak / red flag |
|---|---|
| Pipeline EOS vs end-to-end EOS | "Turn on exactly-once in config" |
| Checkpoint = state + offsets | Ignores offsets / state coupling |
| Sink 2PC or idempotency | "Kafka guarantees no duplicates" |
| Abort uncommitted epoch on failure | Assumes retries are always safe |
| Weakest-link callout | No sink discussion |
| Reconciliation for ledgers | Blind trust in stream totals |
Compact outline (if time-boxed to 2 minutes)
"Flink EOS: checkpoint barriers snapshot state + Kafka offsets. Sink must join the epoch—Kafka TX / Iceberg / XA—or use idempotent upserts. Crash → restore last complete checkpoint, abort open epoch. HTTP sink = at-least-once + keys. Document weakest link; reconcile money in batch."
24. Weak Answer Example
Question: "How do you achieve exactly-once processing with Kafka and Flink?"
"Enable exactly-once in Flink config and Kafka will guarantee no duplicates."
Why weak / red flags: No checkpoint explanation, ignores the sink, conflates broker producer idempotence with end-to-end application semantics.
25. Hands-On Exercise
- Run Kafka + Flink local; count events per key with event-time windows.
- Inject out-of-order events; observe watermark behavior.
- Kill task manager; verify recovery from checkpoint.
- Compare Spark batch vs Structured Streaming on same topic.
- Implement idempotent sink with duplicate inserts.
26. Knowledge Check
- Watermark indicates? (Lower bound on future event times.)
- Lambda speed layer role? (Low-latency approximate views.)
- Checkpoint contains? (State + source offsets.)
- Tumbling window? (Fixed non-overlapping intervals.)
- Kappa core idea? (Reprocess log for corrections.)
- Backpressure cause? (Downstream slower than upstream.)
- Event-time requires? (Trustworthy timestamps in payload.)
- At-least-once fix for duplicates? (Idempotent sink.)
- Session window defined by? (Inactivity gap.)
- Micro-batch engine example? (Spark Structured Streaming.)
27. Flashcards
| Front | Back |
|---|---|
| Event time | Timestamp in event data |
| Watermark | Event-time progress marker |
| Checkpoint | Flink consistent state snapshot |
| Lambda architecture | Separate speed and batch layers |
| Kappa architecture | Single stream log reprocessing |
| At-least-once | No loss; possible duplicates |
| Exactly-once | Coordinated commit; no duplicates |
| Allowed lateness | Grace for late events |
| Backpressure | Flow control when sink slows |
| Micro-batch | Stream as small batch jobs |
28. Cheat Sheet
TIME
Event time + watermarks + allowed lateness
SEMANTICS
At-most / at-least / exactly-once (sink matters!)
ENGINES
Batch: Spark | Stream: Flink, Kafka Streams
PATTERNS
Lambda (dual) | Kappa (replay log) | Hybrid reconciliation
OPS
Lag, checkpoint duration, savepoints, skew
29. Related Concepts
- Kafka Architecture — log-based messaging
- Message Delivery Semantics — broker guarantees
- Event-Driven Architecture — event backbone
- Data Lakehouse Architecture — sink targets
- Idempotency — duplicate handling
30. References
Primary sources
- Kreps, J. (2014). Questioning the Lambda Architecture. Confluent blog.
- Carbone, P., et al. (2015). Apache Flink: Stream and Batch Processing in a Single Engine. IEEE Data Eng. Bull.
- Apache Flink documentation — checkpoints, watermarks, state backends.
Related
- Kleppmann, M. DDIA — Ch. 11 Stream Processing.
- Zaharia, M., et al. — Spark Structured Streaming papers and docs.
Distinction
| Claim | Type |
|---|---|
| Checkpoint protocol | Flink implementation spec |
| End-to-end exactly-once | Requires sink—formal in Flink docs per connector |
| Lambda operational cost | Engineering experience—anecdotal |