Structured Streaming
27 in-depth lessons. Learn streaming from the first question, whether you need a stream at all, to running one in production. Every lesson starts in plain words: sources, triggers and checkpoints, Kafka from topics to Kafka 4, windows and late data, exactly-once from end to end, ordering and bad records, joins and custom state, backpressure, recovery, and the same ideas on Google Cloud.
Bronze
Module 1: First streams
Decide whether data needs a stream, start one from a replayable source, and pick a trigger for it.
- Batch, micro-batch or streaming? · Bronze · 6 min read. Three ways to process data, what fresher data costs, and a checklist for choosing in a system design interview.
- Structured Streaming basics · Bronze · 8 min read. Streams as an unbounded table: sources, sinks, triggers, output modes and checkpoints.
- Sources and sinks · Bronze · 8 min read. Which sources can replay data, how Kafka and file sources track their position, and which sinks are exactly-once.
- foreachBatch: write a stream anywhere · Bronze · 7 min read. Hand each micro-batch to your own code as a normal DataFrame, and the four rules that keep the writes correct.
- Triggers · Bronze · 7 min read. When micro-batches run, what happens when one overruns, and availableNow for scheduled incremental jobs.
Module 2: Output modes and checkpoints
Say what a query writes after each batch, and what its checkpoint holds.
- Output modes: append, update, complete · Bronze · 6 min read. What each mode writes after a batch, which queries allow which mode, and what the sink must support.
- Checkpoints and state stores · Bronze · 7 min read. What a checkpoint holds, how state is partitioned and stored, RocksDB, and reading state as a table.
Module 3: Kafka basics
Explain what Kafka stores, how readers share a topic, and where Spark keeps its position.
- Kafka in plain words · Bronze · 8 min read. Topics, partitions, offsets, brokers and retention: why Kafka is a log that keeps messages, not a queue that deletes them.
- Consumer groups and offsets · Bronze · 7 min read. How a group shares partitions, rebalances, committed offsets and lag, and why Spark keeps its offsets in the checkpoint instead.
Silver
Module 4: Stateful streams
Aggregate by event time in windows, deduplicate, and bound state with a watermark.
- Watermarks and late data · Silver · 8 min read. Event time vs processing time, how watermarks bound state, and what happens to late rows.
- Event-time windows · Silver · 7 min read. Tumbling, sliding and session windows, what they cost in state, and when a window is final.
- Deduplicating a stream · Silver · 7 min read. Where duplicates come from, dropDuplicatesWithinWatermark, and deduplicating at the sink.
Module 5: Streams into the lakehouse
Stream into and out of Delta tables, and ingest new files exactly once.
- Streaming into Delta tables · Silver · 7 min read. Write a stream into a Delta table exactly once, and read a Delta table as a stream.
- Incremental file ingestion · Silver · 7 min read. Load each new file exactly once: the streaming file source, Auto Loader, COPY INTO, schema drift and backfills.
Module 6: Kafka in depth
Write to Kafka safely and fast, and change message schemas without breaking readers.
- Kafka producers: acks, retries and batching · Silver · 7 min read. How the key picks a partition, what acks and the idempotent producer protect against, batching and compression, and writing to Kafka from Spark.
- Schemas and Schema Registry · Silver · 7 min read. JSON, Avro or Protobuf, compatibility modes and who upgrades first, and decoding registry messages in Spark.
Module 7: Correct results end to end
Say what a pipeline guarantees from producer to reader, keep events in the order that matters, and set bad records aside without stopping.
- Delivery guarantees end to end · Silver · 9 min read. At-most-once, at-least-once and exactly-once, why most hops are at-least-once, and how idempotent sinks and event ids give exactly-once results.
- Ordering and out-of-order events · Silver · 7 min read. What order Kafka really guarantees, why global order is expensive, and how event time and sequence numbers put events back in order.
- Bad records and dead-letter queues · Silver · 10 min read. Split valid and invalid rows in foreachBatch, keep bad ones with the reason they failed, alert on the rate and replay them after a fix.
Gold
Module 8: Joins and custom state
Join streams with bounded state, and write custom stateful logic with timers.
- Stream joins · Gold · 7 min read. Stream-static enrichment, stream-stream joins bounded by watermarks, and why outer joins emit late.
- Custom state with transformWithState · Gold · 6 min read. Typed state per key, timers and TTL for rules that windows and joins cannot express.
Module 9: Running streams in production
Monitor a stream, deploy changes to it, and reprocess safely.
- Monitoring streams · Gold · 6 min read. The progress report, the four signals worth an alert, listeners and the Spark UI.
- Backpressure and rate limits · Gold · 8 min read. When data arrives faster than a stream processes it: measuring lag, catch-up arithmetic, rate limits per source, and what to scale.
- Restarts, query changes and reprocessing · Gold · 7 min read. Which changes a checkpoint accepts, how to rebuild a stateful query safely, and source schema changes.
Module 10: Kafka in production
Configure Kafka not to lose data, size partitions, and explain what Kafka 4 changed.
- Kafka in production · Gold · 7 min read. Replication, min.insync.replicas and acks=all, choosing a partition count, compacted topics, and transactions with read_committed.
- Kafka 4: KRaft, new rebalances and queues · Gold · 6 min read. ZooKeeper removed, the broker-driven consumer rebalance protocol, share groups, and what changed for Spark jobs.
Module 11: Streaming beyond Spark
Answer streaming design questions for Google Cloud: Pub/Sub, Dataflow and BigQuery.
- Streaming on Google Cloud · Gold · 8 min read. Pub/Sub, Dataflow (Apache Beam) and BigQuery, mapped to the Spark ideas: windows, watermarks, allowed lateness, triggers, exactly-once, dead letters and ordering.