Skip to content
BENIBIX Learn

Kafka Consumer

Also known as Consumer (Kafka), Kafka Consumer Client

A program that reads events from Kafka in order. An offset marks its place.

Think of it like

It is like reading a long book with a bookmark. You stop, and later you go on where you left off.

Example

Two apps read the orders topic: one loads the warehouse and one sends emails. Each has its own group, so each gets every order.

Why it matters

Reading does not delete, so a new app can replay old events. That is how a new report gets its history.

Definition

A Kafka consumer is a program that reads events from a Kafka topic. It reads each partition in order, from oldest to newest. It keeps its place with an offset, which it saves as it goes. Reading does not delete anything, so many consumers can read the same events. Consumers that share a group split the partitions between them. That lets them read a busy topic faster.

Example code

console
$ bin/kafka-console-consumer.sh --topic orders --from-beginning --bootstrap-server localhost:9092
order 1001 placed
order 1002 placed
Read the topic from its first event. Every order is still there after it was read.
The consumers are on the right. Each reads its own partitions and keeps its place with an offset.

Common mistake

Thinking an event is gone once it is read. It stays until the topic's retention time runs out.

Key takeaways

  1. 1
    In order. Per partition, oldest first.
  2. 2
    Keeps its place. The offset is its bookmark.
  3. 3
    Reads, never deletes. Others can read the same events.