Streaming Fundamentals
Messages in motion, continuously
Streaming moves messages continuously — producers publish, a broker buffers and fans them out to consumers. Freshness, ordering, replay and delivery semantics are the four things to get right.
What you will learn
- Describe producer → broker → consumer architecture
- Name the four properties streams trade off: freshness, ordering, replay, delivery
- Explain what an offset is and why replay matters
What is this?
Streaming is the continuous movement of small pieces of data (messages, events) from producers to consumers through a broker that buffers and delivers them. Unlike batch, there is no fixed window: events arrive and are consumed in near real-time. The core abstractions are topics (named channels), offsets (position in a topic), and the delivery semantics between producer and consumer.
Why do you need it?
- Streaming meets freshness: sub-second reaction to events (fraud, alerts, live dashboards).
- Brokers decouple producers from consumers — neither blocks on the other's speed.
- Replay lets you re-read historical events to rebuild state or re-run logic.
- Modern stacks push freshness where batch simply can't follow (updates to products, telemetry).
Mental model
A mailroom between senders and departments
A message broker
Send a letter (event) to the mailroom (topic). Then every department subscribed (consumer) can read it; the mailroom keeps a copy for re-delivery (replay), and each department tracks which letters it has read (offset).
How it works
- Producers publish events to a topic — a partitioned log with an append-based sequence.
- The broker stores the events durably and serves them to consumers on demand.
- Consumers read a stream of events (pull-based in Kafka) and track an offset per partition.
- Groups of consumers share a topic's partitions so throughput scales horizontally.
- Ordering holds within a partition; delivery can be at-least-once, exactly-once or at-most-once.
Producer → broker → consumer flow.
In production
- Clickstream events are published to Kafka and consumed by analytics, dashboards and ML features all from one topic.
- Order messages go through a stream so inventory, shipping and finance each react asynchronously to the same event.
- A monitoring pipeline streams server metrics and triggers alerts within a second of an anomaly.
Best practices
- Keep the broker a fast buffer: move heavy transforms out of the streaming path or into consumers.
- Always replay first when debugging — reprocessing a topic is the universal truth-check.
- Set retention (time or size) so replay windows match you recovery SLAs, not laziness.
- Design events as small, schema-versioned records — not blobs.
Common mistakes
- Publishing enormous payloads, then wondering why the broker is the bottleneck.
- Treating the topic as a queue to delete after consumption, losing the ability to replay.
- Ignoring ordering guarantees and building 'ordered calculations' on cross-partition data.
- Using exactly-once as a blanket requirement when at-least-once + idempotent sinks suffices.
Common issues
Consumers lag and data gets staleConsumers slower than producers, or too few partition-readers
Scale the consumer group's instances and parallelism to match production rate.
Duplicates appear downstream on restartAt-least-once replay after a consumer crash
Make sinks idempotent (dedupe by event key) or use exactly-once processing.
Ordering broken across eventsRelated events landed on different partitions
Hash-produce related events to the same partition via a consistent key (user_id, order_id).
Debugging tips
- Check consumer lag (end offset minus consumer offset) first — it tells you who's falling behind.
- Compare producer timestamps and consumer timestamps to isolate end-to-end latency.
- Replay a window of the topic and recalc totals — if results match, upstream logic is fine.
- Inspect a single event's schema and content before blaming the pipeline for wrong metrics.
Interview checkpoint
Hands-on lab
- Start a Kafka broker and create a topic
- Publish events from the CLI and consume them
- Demonstrate offsets, groups and replay
Run a Local Kafka and Publish-Consume
40 min · beginner
Quick quiz
Replay is possible in a streaming system because...
Producer and consumer must operate at the same speed or the stream breaks.