Kafka Explained Like You're 5: Events, Partitions, and Consumer Groups
How does a large application process millions of events every day?
Picture a food-delivery app at dinner time. Customers place orders, restaurants accept them, riders get assigned, payments go through, users get alerts, and analytics teams measure everything—at the same time.
If each service had to call every other service directly, the app would become slow, fragile, and hard to grow. Apache Kafka gives every service a shared, reliable way to announce what happened and let the right systems react.
This guide explains Kafka through four ideas: events → topics → partitions → consumer groups.
Why systems need event streaming
Small apps often use request-response calls:
Checkout service → Payment service → Notification service
As the product grows, checkout may also need inventory, delivery assignment, fraud checks, analytics, email, SMS, and recommendations. Now it depends on all of them. That is tight coupling.
With event streaming, checkout only announces a fact: “An order was created.” Every interested service can react independently.
flowchart LR
A[Checkout] -->|Order created| K[Kafka]
K --> P[Payment]
K --> N[Notifications]
K --> I[Inventory]
K --> X[Analytics]
What is Kafka?
Apache Kafka is a distributed event-streaming platform. Think of it as a durable shared diary where applications write events and other applications read them.
Unlike a basic queue, Kafka retains events for a configured period. Several applications can read the same event stream, and an application can replay older events when needed.
Common uses include analytics pipelines, payment events, notifications, activity tracking, fraud detection, and communication between microservices.
Events: the smallest Kafka unit
An event is a record that says something happened.
{
"eventType": "OrderCreated",
"orderId": "ORD-1042",
"customerId": "CUS-79",
"createdAt": "2026-07-29T17:30:00Z"
}
- A producer sends an event.
- Kafka stores it.
- A consumer reads and processes it.
For an order, the flow might be: a user places an order → the Order service produces OrderCreated → Kafka stores it → payment, inventory, notifications, and analytics consume it independently.
Topics: organized streams
A topic is a named stream of related events—like a labelled shelf in the event diary.
| Topic | Example events |
|---|---|
orders |
created, cancelled, delivered |
payments |
initiated, completed, failed |
user-activity |
login, click, search |
notifications |
email, SMS, push requests |
Multiple producers may write to one topic, and multiple consumers may read from it.
Partitions: how Kafka scales
One busy topic is split into partitions. Each partition is an ordered, append-only log.
flowchart TB
P[Producer] --> T[orders topic]
T --> A[Partition 0]
T --> B[Partition 1]
T --> C[Partition 2]
Partitions enable parallel processing and let Kafka spread work across brokers. Kafka guarantees order inside one partition, not across every partition in a topic.
Use a key such as orderId when related events must stay ordered. Events with the same key go to the same partition, preserving sequences like:
OrderCreated → PaymentCompleted → RiderAssigned → OrderDelivered
Why Kafka is fast
Kafka is designed for high throughput:
- New events are written sequentially.
- Partitions are append-only logs.
- Sequential disk work is efficient.
- Kafka batches reads and writes to reduce overhead.
This is why Kafka can handle large, continuous streams without treating every event like a slow, isolated database operation.
Consumer groups: teamwork without duplicate work
A consumer group is a team of consumers reading the same topic. In one group, each partition is assigned to only one consumer at a time.
flowchart LR
P0[Partition 0] --> C1[Consumer 1]
P1[Partition 1] --> C2[Consumer 2]
P2[Partition 2] --> C3[Consumer 3]
This means a Billing service can run several instances without processing each order repeatedly. A separate Analytics consumer group can still read every order independently.
If a consumer fails, Kafka reassigns its partitions to healthy consumers. This is called rebalancing. Consumer groups track their reading position using offsets, so they can continue from the correct point.
More consumers than partitions do not increase active parallelism. A topic with three partitions can have at most three active consumers in one group.
Kafka architecture
| Component | Purpose |
|---|---|
| Producer | Publishes events |
| Broker | Kafka server that stores data |
| Topic | Named event stream |
| Partition | Ordered, scalable slice of a topic |
| Consumer | Reads events |
| Consumer group | Shares partitions across consumers |
flowchart LR
PR[Producers] --> B[Kafka brokers]
B --> TP[Topic partitions]
TP --> CG[Consumer groups]
CG --> CO[Consumers]
Kafka vs traditional queues
| Capability | Traditional queue | Kafka |
|---|---|---|
| Main model | Give a job to a worker | Store a stream of facts |
| After reading | Often removed | Retained for a period |
| Replay | Usually limited | Built in with offsets |
| Multiple apps reading | Needs extra routing | Each group reads independently |
| Scaling | Add workers | Add partitions and consumers |
Kafka can behave like a queue inside one consumer group, while still allowing other groups to consume the same retained data.
Real-world Kafka applications
- E-commerce: order, inventory, shipment, and payment events.
- Analytics: clicks, searches, and product views flowing into dashboards.
- Notifications: emails and push messages triggered by business events.
- Payments: reconciliation and fraud checks after payment events.
- Recommendations: likes, views, and purchases becoming model signals.
- Social platforms: posts, comments, follows, and feed activity.
For example, a PaymentCompleted event can trigger warehouse packing, a customer notification, revenue analytics, and a loyalty-points update—without the Payment service calling each system directly.
The five-year-old summary
Imagine a school notice board:
- An event is a new notice: “Lunch is ready!”
- A topic is the “Cafeteria” part of the board.
- Partitions are several columns so many notices can be handled quickly.
- A consumer group is a team of helpers, where each helper reads a different column.
- Different teams can read the same notices for their own jobs.
Final takeaway
Kafka is a foundation for reliable, scalable event-driven systems:
Events describe what happened. Topics organize them. Partitions scale them. Consumer groups distribute the work.
What would you build with Kafka first—an order pipeline, notifications, analytics, or user activity tracking?
Top comments (0)