Streaming
Beginner 13 min read Streaming

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.

streamingkafkamessage brokerproducerconsumeroffsetlatency
Prerequisites: Batch vs Streaming
Before we start

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
Introduction

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.

Motivation

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).
Think about it

Mental model

Imagine

A mailroom between senders and departments

Think of

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).

Mechanics

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.

Producers
Topic (log)
Consumer group
Commit offsets
Downstream
Real world

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.
Guidelines

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.
Watch out

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.
Root cause analysis

Common issues

Error
Consumers lag and data gets stale
Root cause

Consumers slower than producers, or too few partition-readers

Fix

Scale the consumer group's instances and parallelism to match production rate.

Error
Duplicates appear downstream on restart
Root cause

At-least-once replay after a consumer crash

Fix

Make sinks idempotent (dedupe by event key) or use exactly-once processing.

Error
Ordering broken across events
Root cause

Related events landed on different partitions

Fix

Hash-produce related events to the same partition via a consistent key (user_id, order_id).

When things break

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.
Interviews

Interview checkpoint

Practice

Hands-on lab

Run a Local Kafka and Publish-Consume
40 min · beginner
In progress
Objectives
  • 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

0/5 steps
0%
sandbox · Linux sandbox
$
Try these commands
Test yourself

Quick quiz

0/2
1

Replay is possible in a streaming system because...

2

Producer and consumer must operate at the same speed or the stream breaks.

Go deeper

Official documentation