← Home kafka-fundamentals
Slide 1 of 9 producers & consumers

Two sides of the stream

Every Kafka system has a producer that writes events and a consumer that reads them. They are just apps you already know.

who produces?

Any app that has events to share: web servers (signups, clicks), mobile apps, backend services, IoT devices, microservices.

who consumes?

Any app that needs those events: analytics dashboards, notification services, ML pipelines, audit logs, search indexers.

the catch

Producers and consumers don't talk to each other directly. There's a middleman in between. That's what the next slide introduces.

→ press right arrow to reveal
the actors
Producer the sender
Consumer the reader

...but where do messages go in between?

← Home kafka-fundamentals
Slide 2 of 9 the broker

Enter the broker

A broker is a server that stores messages between the producer and the consumer. The producer writes to it; the consumer reads from it.

what is a broker?

A Kafka broker is a long-running server process. You install Kafka, start a broker, and now producers can write to it and consumers can read from it.

what does it store?

Files on disk. Messages land in append-only log files. They sit there until the retention period expires (default: 7 days).

what's next?

A single broker is fine for dev. Production runs many brokers together — that's a cluster. More on that after we look at topics.

→ press right arrow to reveal
the middleman
Producer writes to
Broker stores messages
Consumer reads from

producer → broker → consumer — the producer never sees the consumer

← Home kafka-fundamentals
Slide 3 of 9 topics

A topic is just a named folder

The broker organizes messages into topics. A producer writes to a topic; a consumer reads from one. Think: a topic is a category of events.

what goes in a topic?

Related events. Examples: user-signups, order-events, page-views, audit-log. Pick a name that describes the event type.

who decides the topic?

The producer picks the topic name when sending. The consumer subscribes to whichever topics it cares about. Both must agree on the name.

one topic, many uses

The same topic can be read by many consumers independently. Analytics, notifications, and ML can all read from order-events at their own pace.

→ press right arrow to reveal
one broker, many topics
topic: user-signups
alice signed up
bob signed up
carol signed up
topic: order-events
order #42 created
order #42 paid
topic: page-views
GET /home
GET /pricing
← Home kafka-fundamentals
Slide 4 of 9 partitions

One topic, many parallel lanes

A topic is split into partitions — ordered, append-only log files. Each partition lives on one broker, but a topic's partitions can be spread across the cluster.

why split?

More partitions = more parallel writers = higher throughput. One big file is a bottleneck; many smaller files write in parallel.

partitions live on brokers

A topic is a name. The partitions under that name are files scattered across your cluster.

Topic A
P0
P1
P2
Broker 1
Broker 2
Broker 3
one topic, three partitions, scattered across the cluster
rule of thumb

Plan partition count from your peak load, not your current load. You can add partitions, but you can never reduce them.

→ press right arrow to reveal
topicuser-signups
Partition 0
Partition 1
Partition 2
try this →

Click Add Record a few times. Records round-robin across the three partitions. Within one partition, offsets are strict.

← Home kafka-fundamentals
Slide 5 of 9 consumer groups

One consumer per partition, always

A consumer group is a team sharing the work. Different groups read the same topic independently at their own pace.

how scaling works

Add consumers to a group → partitions rebalance → more parallel work. But: more active consumers than partitions = idle ones.

multiple groups, same topic

Group A (analytics) and Group B (notifications) read the same topic at their own pace. One crashing doesn't affect the other.

try this →

Add a 4th consumer to either group. It goes idle — you can never have more active consumers than partitions.

→ press right arrow to reveal
topicorders — 3 partitions
P0
Offset 0
Offset 3
P1
Offset 1
Offset 4
P2
Offset 2
Offset 5
Group A — Analytics
Consumer A1
P0, P1
Consumer A2
P2
Group B — Notifications
Consumer B1
P0
Consumer B2
P1
Consumer B3
P2
← Home kafka-fundamentals
Slide 6 of 9 keys & ordering

Pick the key, pick the lane

With a key, all events for one entity always land in the same partition — guaranteeing order for that entity.

no key = random

Producer round-robins across partitions. User 1's events can land in P0, P2, P1 — order is lost for that user.

with key = strict order

Producer hashes the key. All events with user_id=42 always go to the same partition — strictly ordered for that user.

try this →

Send User 1 three times in No Key mode — events scatter. Switch to User ID Key — all three cluster in one partition, in order.

→ press right arrow to reveal
Mode: No Key (Round-Robin)
topicuser-events
Partition 0
Partition 1
Partition 2
the rule

Pick the key by what needs ordering — e.g. user_id, account_id, order_id. One key → one partition → strict order.

← Home kafka-fundamentals
Slide 7 of 9 retention & compaction

Kafka forgets on purpose

The log keeps appending forever — your disk doesn't. Two cleanup strategies, both running in the background: time retention deletes by age, log compaction keeps only the latest value per key.

why does this matter?

A topic is an append-only log. Every record is appended, never updated. Without cleanup, the log grows forever until the disk fills up. You pick a cleanup policy per topic.

time retention

Default. Kafka deletes records older than N days (e.g. 7) or beyond a size limit. For long-term storage, sink to a database or data lake.

log compaction

For "current state" topics (user profiles, config). Kafka keeps only the latest record per key. New consumers get the current state instantly — no replay needed.

→ press right arrow to reveal
Time Retention (5 days)
today — Day 7
6 days ago: user=Alice, login
5 days ago: user=Bob, click
4 days ago: user=Alice, logout
3 days ago: user=Bob, login
2 days ago: user=Alice, click

Anything older than 5 days is deleted

Log Compaction
keep only the latest event per user
Alice
6 days ago — login older, dropped
4 days ago — logout older, dropped
2 days ago — click latest — kept
Bob
5 days ago — click older, dropped
3 days ago — login latest — kept

The log now holds the current state: Alice = click, Bob = login.

When does cleanup happen? Continuously, in the background. As soon as a log segment is closed (default 1 GB or 7 days), the broker checks the topic's cleanup policy and removes eligible records. Producers and consumers never block on it.

rule of thumb

Kafka remembers the recent past. For long-term history, sink to a database. For "current state only" topics, use log compaction.

← Home kafka-fundamentals
Slide 8 of 9 kafka vs rabbitmq

Sticky notes, not bulletin boards

RabbitMQ is a task board — take a sticky note, do the task, throw it away. Kafka is an archive — everyone can read the same record, and it stays put.

the model difference

RabbitMQ = queue, delete on consume. Kafka = log, retain on consume. They are not the same category of tool.

5 reasons to pick Kafka

Replay (rewind any consumer). Multi-consumer (groups read independently). Order at scale (per partition). Event sourcing. Throughput (millions/sec).

when rabbitmq wins

Simple background jobs (PDF, email, thumbnails). Rich routing. Low operational complexity. Workloads in the thousands, not millions.

→ press right arrow to reveal

head-to-head

Dimension RabbitMQ Kafka
ModelQueue (delete on read)Log (retain on read)
Throughput / node~10k–50k msg/s~100k–1M msg/s
ReplayNoYes
Multi-consumer readingFanout exchange (extra setup)Native — every group is independent
RoutingRich (topic, headers, fanout)Simple (topic + key)
Operational complexityLower (single binary)Higher (ZooKeeper/Kraft, tuning)
← Home kafka-fundamentals
Slide 9 of 9 when to use each

Start simple. Upgrade when numbers demand it.

A queue is enough for most background jobs. Kafka is for timelines that many systems need to read.

Scenario Use Why
Background job: generate PDF report Queue One-time task, no replay needed, simple retry is enough
Click tracking: 10M events/day, analytics + ML + dashboard Kafka Multiple consumers, high throughput, replay for reprocessing
Send welcome email after signup Queue Simple one-time task, low volume, no history needed
Order events: payment, shipping, delivery for audit trail Kafka Event sourcing — the timeline is the business record
Image thumbnail generation Queue One-time processing, serverless-friendly, no replay needed
Activity feed: recs + notifications + analytics Kafka Three independent consumer groups reading the same events
rule of thumb

Kafka is for timelines many systems need to read. A queue is for tasks one worker should do once. If you can't name why you need replay or multiple consumers — start with a queue.