Data Engineering Reference/Stream Processing

Spark Structured Streaming & Flink

Micro-batch vs true streaming, Structured Streaming output modes, Flink's state and checkpoint model — when to pick which engine.

4/5Overview: 30m

Spark Structured Streaming

Model: treat a stream as an unbounded table — append micro-batches on a trigger interval.

Output modes:

ModeBehavior
AppendOnly new rows (no aggregations)
CompleteFull result table each trigger (small aggregates)
UpdateChanged rows only (aggregates with state)

Triggers: processingTime (fixed interval), once (batch-like), continuous (experimental low-latency).

State store: RocksDB on executor for aggregations — checkpoint to durable storage for recovery.

Good for: teams already on Spark, micro-batch latency (seconds–minutes), lakehouse sinks (Delta).

Apache Flink

True streaming — record-by-record with checkpoint barriers.

Strengths:

  • Low latency (sub-second)
  • Sophisticated event-time and state
  • Exactly-once end-to-end with Kafka + checkpointed sinks

Complexity: separate ops model, state backend tuning, savepoint upgrades.

Decision matrix

FactorSpark Structured StreamingFlink
Latency targetSeconds+Sub-second to seconds
Team skillsAlready use SparkDedicated stream team
State complexityModerateHeavy (CEP, large state)
EcosystemDelta, Hive, batch unityKafka-native, Kappa

Google internal: FlumeJava / Dataflow (Beam) — same Dataflow model as Flink conceptually.

Exactly-once (preview)

Requires:

  • Idempotent or transactional sink
  • Checkpointed source offsets
  • Two-phase commit sinks (Kafka, Delta with careful config)

Deep dive on Flink checkpoints in Topic 9 (Deep Cuts). Delivery semantics theory in Distributed Systems.

AI boundary

Real-time feature pipelines for ML may use these engines — but embedding/RAG ingestion specifics stay in AI Systems.

Interview answer template

"Sub-minute latency with complex sessionization — Flink. Five-minute dashboard refresh on the same lake stack as batch — Structured Streaming to Delta with 1-minute trigger. Same medallion sink, different engine by SLA."

Further Reading

Hands-On Tasks (Optional)

Pipeline design drills and whiteboard exercises — DAG sketches, partition plans, backfill strategies. Assumes Databases and SQL fundamentals are in place.

  • Spark Streaming vs Flink

    Scenario: 10k events/sec, 5-minute tumbling aggregates, occasional 2-hour-late events, need exactly-once sink to Delta. Argue for Spark Structured Streaming or Flink and what config matters.

    20m