liveBook · Manning

Consumer group

As explained in Apache Kafka in Action

A consumer group is a set of consumers that collaboratively consume topic partitions, with each partition assigned to one consumer in the group.

Suppose an online shop needs to update displayed prices while a separate service analyzes how prices affect sales. Both services can read the same Kafka topic without interfering with each other: each uses its own consumer group and tracks its own reading position. If price updates arrive faster than one service instance can process them, that service can add consumers to its group to share the work. section 6.1.1 section 9.4.1

A consumer group consists of one or more consumers with the same group ID. Kafka assigns whole topic partitions among its members, as evenly as possible. Within a group, each partition goes to one consumer, preserving that partition’s message order. Different groups can consume the same partitions independently. Kafka stores group offsets, so a stopped consumer can resume from its recorded position. section 4.2.2 section 6.1.1

Try a group at the command line

Run `kafka-console-consumer.sh --from-beginning --topic products.prices.changelog.multi-partitions-keys --group products --bootstrap-server localhost:9092`. On its first run, the consumer reads available records. After stopping and rerunning it with the same group ID, it reports zero processed messages if nothing new has arrived: the group’s offsets record its progress. Run two consumers with `--group products` in separate terminals, then produce more records. In the shown example, records for cola appear in one consumer window and records for energy drink in the other because their partitions have been divided between the consumers. section 4.2.2

Figure 4.8 Consumer groups allow us to split the processing of multiple partitions between different instances of the same service. Often, several consumer groups, not just one, consume the data from a topic. Consumer groups are isolated from each other and don’t influence one another.
A group of colorful rectangular objects

AI-generated content may be incorrect.

The diagram shows the key distinction: partitions are divided within a group, while separate groups read independently. section 4.2.2

Scaling has a boundary: work is distributed by partition, not by individual message, and Kafka does not guarantee order across partitions. Kafka brokers help coordinate group membership and partition assignment through the Kafka Rebalance Protocol. A change in membership or topic partitions, or a consumer failure, can trigger a rebalance; remaining members can take over failed consumers’ work. Range Assignor and Round Robin Assignor offer different assignment strategies, while static membership and Cooperative Sticky Assignor address rebalance behavior. section 6.1.1 section 9.5 section 9.4.1

How Apache Kafka in Action covers it

How deep it goes
Explains group IDs, whole-partition assignment, stored offsets, coordination, rebalance triggers, and assignment options without detailing the protocol’s steps.
Examples
Demonstrates a console consumer restarting with saved progress and two consumers splitting price-change records by partition.
What it assumes
Builds on topics, partitions, and offsets, then introduces group membership through a console-consumer example.
What you can do after
Operate/configure it by setting a group ID, adding consumer instances, and recognizing partition-level scaling and rebalance trade-offs.
How it connects
Connects topic partitions and offsets to message ordering, horizontal scaling, the Kafka Rebalance Protocol, and partition assignors.

Also explained in

Compare how 4 books explain consumer group →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Apache Kafka in Action. The section links point to the parts of the book it draws on.