What Is Consuming Messages in Kafka?
The other half of every Kafka story: how a program actually reads events back out, keeps track of its own progress, and shares the work with others, without ever stepping on anyone else's toes.
Imagine a large newspaper archive room, open to the public, where every article ever published sits on numbered shelves in the exact order it was written. A historian visiting today can start reading from the very first shelf, taking notes page by page. A journalist checking today’s headlines only cares about the newest shelf, ignoring everything older. Both are reading the same archive, at their own pace, for their own reasons, and neither one disturbs the other’s progress or the shelves themselves. This is precisely how consuming works in Kafka: reading events back out, on your own terms, without changing anything for anyone else.
1The Big Picture: What Does Consuming Mean?
Consuming is simply the act of a program reading events from a Kafka topic and doing something useful with them.
A program that reads messages from Kafka is called a consumer. Where a producer’s job is to create and send events, a consumer’s job is the mirror image: connect to Kafka, ask for events from a particular topic, and process each one as it arrives, perhaps updating a database, sending a notification, or feeding a chart on a live dashboard.
Crucially, reading an event from Kafka does not remove it or change it in any way. Unlike a letter taken out of a mailbox, an event stays exactly where it is, in the log, after a consumer has read it. This means many different consumers, doing completely different jobs, can all read the very same event, each entirely unaware of the others.
Reading a message in Kafka is more like watching a recorded broadcast than answering a phone call. Picking up a phone call removes the opportunity for anyone else to answer it. Watching a recording changes nothing about the recording itself, and a hundred other viewers can watch the exact same recording, each pausing and resuming wherever they like.
2Why Consuming Works This Way
Kafka’s approach to reading data is deliberately different from older messaging systems, and that difference unlocks real power.
In many traditional queue-based systems, once a message is read and confirmed, it is deleted, gone for good. This works fine when only one system ever needs that piece of information. But modern applications are rarely so simple: the same “order placed” event might matter to billing, to inventory, to fraud detection, and to analytics, all at once, and possibly to a brand-new service built next year that did not even exist when the event was first created.
By never deleting an event just because someone read it, Kafka lets every one of these interested parties consume the same data independently, at their own pace, without needing the producer to send the same information multiple times or coordinate with every possible reader in advance.
Many Independent Readers
Different services can read the same topic for completely different purposes, without interfering with each other.
Read at Your Own Pace
A slower consumer never blocks or affects a faster one reading the very same data.
New Consumers Can Join Anytime
A service built long after an event was written can still read it, as long as retention has not expired.
Replay Is Always an Option
A consumer can revisit older events at will, useful for debugging, recovery, or reprocessing.
3Core Vocabulary Around Consuming
A handful of terms describe how consumers relate to topics, partitions, and each other. Knowing them makes the rest of this guide much clearer.
Consumer
A program reading events from one or more Kafka topics.
Consumer Group
A named team of consumers working together to read a topic, sharing its partitions between them.
Poll
The action of a consumer actively asking the broker, “do you have any new events for me?”
Offset
The position number of an event within a partition, used to track exactly how far a consumer has read.
Committed Offset
The saved position a consumer group has confirmed as fully processed, used to resume correctly after a restart.
Partition Assignment
Which specific partitions of a topic a given consumer within a group is currently responsible for reading.
Rebalance
The process of reassigning partitions among a group’s consumers, triggered when one joins or leaves.
Consumer Lag
How far behind the newest available event a consumer group currently is.
A consumer group is like a team of librarians assigned to reshelve books from a single delivery cart, with each librarian responsible for a specific section, so no two of them ever duplicate the same task.
4How Consuming Actually Works, Step by Step
Reading a stream of events is not a single instant action; it is an ongoing, repeating cycle.
Consumer connects and subscribes
It tells Kafka which topic, or topics, it is interested in reading from.
Partitions are assigned
Kafka decides which specific partitions this consumer, as part of its group, is responsible for reading.
Consumer polls for new events
It actively asks the broker for the next batch of events, starting from wherever it last left off.
Events are processed
The consumer runs its own logic on each event, such as updating a record or triggering a notification.
Offset is committed
Once processing succeeds, the consumer saves its new position, so it can resume correctly if it ever restarts.
sequenceDiagram
participant C as Consumer
participant B as Broker
C->>B: Subscribe to topic
B-->>C: Assign partitions
loop Continuous polling
C->>B: Poll for new events
B-->>C: Deliver available events
C->>C: Process events
C->>B: Commit offset
end
Unlike some systems where the broker actively pushes data to a receiver, Kafka consumers actively pull data by polling. This gives the consumer full control over its own pace, never being overwhelmed faster than it can handle.
5Consumer Groups: Sharing the Work
A single consumer can only read so fast. Consumer groups let many consumers share the reading workload of one topic.
When several consumers join the same named consumer group, Kafka automatically divides the topic’s partitions among them, so that each partition is read by exactly one consumer within that group at any given time. If a topic has six partitions and the group has three consumers, each one typically ends up responsible for two partitions.
flowchart LR
T[Topic: orders, 6 partitions] --> C1["Consumer A
Partitions 0, 1"]
T --> C2["Consumer B
Partitions 2, 3"]
T --> C3["Consumer C
Partitions 4, 5"]
This sharing means the group as a whole can process events far faster than any single consumer could alone, while still guaranteeing that no two members of the group accidentally process the very same event. If more processing power is needed later, adding more consumers, up to the total number of partitions, increases the group’s overall throughput.
Adding more consumers to a group than the topic has partitions. Any extra consumer beyond that number will simply sit idle, since a partition can only be actively read by one consumer in a group at a time.
6Multiple Independent Consumer Groups
While consumers within one group divide the work, entirely different groups reading the same topic never interfere with each other at all.
A billing service, a fraud-detection service, and an analytics pipeline can each form their own separate consumer group, all reading from the exact same topic. Each group gets its own complete, independent view of every event, with every partition delivered in full to every group, not divided up as it is within a single group.
flowchart TD
T[Topic: orders] --> G1[Consumer Group: Billing]
T --> G2[Consumer Group: Fraud Detection]
T --> G3[Consumer Group: Analytics]
Picture three separate classrooms, each watching the same recorded lecture on their own screen, at their own pace. Meanwhile, inside just one of those classrooms, the students take turns answering different questions from the lecture, splitting up that classroom’s work among themselves. The classrooms do not interfere with each other; only the students within one classroom divide their own workload.
7Committing Offsets: Remembering Your Place
Reading an event and officially saving your progress through it are two separate steps, and the gap between them matters.
After processing an event, a consumer must explicitly commit its offset, telling Kafka “everything up to and including this point has been handled.” Kafka durably stores this committed offset, so if the consumer crashes or restarts, it can resume from exactly the right spot instead of guessing or starting over from the very beginning.
| Commit Timing | What It Means | Risk |
|---|---|---|
| Commit before processing | Offset is saved immediately upon receiving the event | A crash during processing can leave the event marked done but never actually handled |
| Commit after processing | Offset is saved only once the work is genuinely complete | A crash before the commit may cause the event to be processed again on restart |
| Automatic periodic commit | Kafka saves progress on a timer, without an explicit signal | A crash between commits can reprocess a small batch of already-handled events |
Because of these small, honest risk windows, consumers should generally be written to safely handle occasionally receiving the same event more than once, a property called being idempotent.
8Rebalancing: When the Team Changes
Consumer groups are not fixed in stone. Kafka automatically reshuffles work whenever the team’s membership changes.
Whenever a consumer joins a group, leaves it, or is detected as having failed, Kafka triggers a rebalance: the partitions of the topic are reassigned among whichever consumers are currently active in the group. This ensures that all partitions are always being read by someone, and that a fair, sensible share of the workload is maintained automatically.
A change is detected
A new consumer joins the group, or an existing one stops responding and is presumed gone.
Partitions are reassigned
Kafka redistributes the topic’s partitions among the consumers now considered active in the group.
Consumers resume from their committed offsets
Whoever now owns a partition picks up reading from wherever the group’s last committed offset for it was left.
Assuming a consumer will always keep reading the same partitions forever. A rebalance can hand a partition to a different consumer at any time, so processing logic should never depend on a fixed, permanent assignment.
9Where a Consumer Can Start Reading From
A consumer is not limited to always reading forward from wherever it last stopped; it can be pointed anywhere along the topic’s history.
Earliest Available Offset
Useful for a brand-new consumer that needs to process a topic’s entire retained history from the very beginning.
Latest Offset
Useful when only new events matter going forward, and everything older should simply be skipped, such as a live status board.
A Specific Committed Offset
The normal, everyday behavior: resuming exactly where the consumer group last left off.
A Chosen Timestamp
Useful for targeted debugging or replay, letting a consumer jump directly to “everything from around 3 PM yesterday.”
Deliberately moving a consumer’s starting point like this is called seeking, and it does not change any data in the topic itself; it only changes where that one consumer will begin reading next.
10Consumer Lag: Are You Keeping Up?
Because reading and committing progress are tracked so precisely, Kafka can tell you exactly how far behind a consumer group currently is.
Consumer lag is the gap between the newest event actually written to a partition and the offset a consumer group has confirmed processing. A small, steady lag is completely normal, since a consumer rarely processes an event the exact instant it is written. A lag that keeps growing, however, is a clear signal that a consumer cannot keep pace with incoming events.
Consumer lag is like the gap between how many episodes of a long-running show have aired and how many episodes you have actually watched. A small gap is normal for anyone with a life outside the show; a rapidly growing gap means you are falling further and further behind.
11Real-World and Industry Examples
Consuming is where all of Kafka’s stored data finally turns into real, useful work.
E-commerce Order Fulfillment
A consumer group dedicated to inventory management reads order events and updates stock counts, sharing the load across several consumers during a big sale.
Fraud Detection Systems
A separate consumer group watches the very same transaction stream a payments service uses, independently scoring each event for suspicious activity.
Real-Time Dashboards
A lightweight consumer seeks to the latest offset and displays only fresh, incoming events, ignoring the topic’s older history entirely.
Data Warehousing Pipelines
A consumer group steadily reads an entire topic’s history and loads it into long-term storage for future reporting and analysis.
Notification Services
A consumer group listens for specific event types, such as “order shipped,” and triggers an SMS or email the moment each one arrives.
12Advantages, Disadvantages and Trade-offs
Kafka’s approach to consuming is powerful, but it asks consumer applications to be built with a certain amount of care.
Advantages
- Many independent services can read the same data without any conflict.
- Work can be shared across multiple consumers to scale processing speed.
- Failures and restarts recover cleanly using saved committed offsets.
- Historical data can be replayed on demand, whenever it is actually needed.
Disadvantages / Trade-offs
- Consumers must be designed to safely handle occasional duplicate processing.
- Rebalances can briefly pause processing while partitions are reassigned.
- Choosing the wrong commit timing can lead to skipped or repeated work.
- Monitoring lag and group health adds an ongoing operational responsibility.
13Security Considerations
Consumers are where stored data actually leaves Kafka and reaches other systems, making this a meaningful point to secure carefully.
Authentication
A consumer should prove its identity to the broker before being allowed to read anything at all.
Authorization
Even an authenticated consumer should only be able to read from the specific topics it genuinely needs, nothing more.
Encryption in Transit
Data flowing from broker to consumer should be encrypted, protecting it from being read if intercepted along the way.
Careful Downstream Handling
Once data leaves Kafka through a consumer, the receiving system inherits responsibility for protecting it just as carefully.
Granting overly broad read access to a topic full of sensitive data means every consumer with that access could potentially replay its entire history, not just newly arriving events. Access should be scoped as narrowly as the actual need requires.
14Monitoring Consumers
A handful of clear signals reveal almost everything about whether a consumer group is healthy.
Consumer Lag
The most important signal: how far behind the latest data a group currently sits.
Processing Time per Event
How long the consumer’s own logic takes for each event, a common root cause of rising lag.
Rebalance Frequency
How often the group’s partitions are being reshuffled, since frequent rebalances can disrupt smooth, steady progress.
Commit Failure Rate
How often offset commits themselves are failing, which can silently cause reprocessing on the next restart.
Watch lag as a trend over time, not a single reading. A brief spike during a burst of traffic is normal; a lag that climbs steadily for many minutes deserves real investigation.
15Design Patterns and Anti-patterns
A few consistent habits separate consumers that behave predictably from ones that cause quiet, hard-to-diagnose trouble later.
Helpful patterns
- Idempotent processing — designing consumer logic so handling the same event twice causes no real harm.
- Commit after successful processing — saving progress only once the actual work is genuinely complete.
- Right-sized consumer groups — matching the number of consumers to the number of partitions for efficient parallelism.
- Dedicated groups per use case — giving each independent service its own consumer group rather than sharing one across unrelated purposes.
Problem
Writing consumer logic that assumes every event will always be processed exactly once, with no protection against duplicates.
Why It’s Harmful
Reprocessing, caused by a crash, a retry, or a rebalance, can then cause real side effects to happen twice, such as sending a customer the same email multiple times.
Correct Approach
Design processing logic to be idempotent, so handling the same event more than once produces the exact same result as handling it once.
Problem
Letting a consumer group’s committed offset fall so far behind that it drifts past the topic’s retention window.
Why It’s Harmful
The events the group still needed to read may have already been deleted, forcing an unplanned jump to the earliest or latest available offset, potentially skipping real, unprocessed data.
Correct Approach
Monitor consumer lag continuously and alert well before a group’s downtime approaches the retention period.
16Best Practices and Common Mistakes
A short checklist for building consumers with confidence.
Best Practices
- Design every consumer to safely tolerate occasional duplicate processing.
- Commit offsets only after the corresponding work is genuinely finished.
- Match the number of consumers in a group to the number of partitions available.
- Give each independent use case its own dedicated consumer group.
- Continuously monitor consumer lag as a primary health signal.
Common Mistakes
- Assuming events always arrive exactly once, with no plan for duplicates.
- Adding far more consumers to a group than the topic has partitions.
- Ignoring steadily rising lag until it becomes a customer-visible problem.
- Sharing one consumer group across unrelated services that should read independently.
17Frequently Asked Questions
No. Unlike many traditional queues, Kafka does not remove a message simply because it was read. It stays in the log until the topic’s retention policy eventually removes it.
No, within one consumer group, each partition is assigned to exactly one consumer at a time, ensuring the group’s work is never duplicated.
As long as the offset was not yet committed, the event will be delivered again, either to the same consumer once it recovers, or to another consumer in the group after a rebalance.
Yes, as long as the relevant data has not already been removed by retention, a new consumer can seek to the earliest available offset and read everything from the very start.
Common causes include a sudden spike in incoming traffic, slower-than-usual processing logic, or one of the group’s consumers becoming unavailable and its partitions temporarily going unread.
Within a single partition, no, events are always delivered in the exact order they were written. Across different partitions of the same topic, there is no such guarantee.
A new consumer joining the group, an existing one leaving cleanly, or one being detected as failed or unresponsive, all trigger Kafka to reassign the group’s partitions.
18Summary and Key Takeaways
We began in a shared newspaper archive and ended inside the careful, repeating cycle a Kafka consumer follows every single day. Consuming is the act of reading events from a topic without ever deleting or altering them, letting many different, independent services each read the same data at their own pace. Consumer groups let related consumers share a topic’s workload without duplicating effort, offsets let every reader remember exactly where it stopped, and rebalances quietly keep everything fair and covered as the team of readers changes over time. Understanding how consuming truly works is what turns a pile of stored events into real, reliable, ongoing work.
Key Takeaways
- Consuming never deletes data — reading an event leaves it untouched for every other reader.
- Consumer groups share the workload — partitions are split among a group’s members so work is never duplicated within it.
- Independent groups never interfere — separate services can each read the full topic on their own terms.
- Offsets track exact progress — committing them lets a consumer resume correctly after any restart.
- Rebalancing keeps things fair automatically — partitions are reshuffled whenever the group’s membership changes.
- Seeking unlocks flexible reading — a consumer can start from the earliest offset, the latest, or any point in between.
- Lag is the key health signal — the gap between the newest data and a group’s progress reveals whether it is truly keeping up.