Can consumer groups span multiple servers?

Viewed 504

When creating a consumer group in Kafka, does it create a pool of workers that run on the same JVM process or could a consumer group span multiple computers/nodes?

If it spans multiple computers then keeping track of offsets etc. will be hard.

2 Answers

"does it create a pool of workers that run on the same jvm process or could a consumer group span multiple computers/nodes?"

It depends on how many jvm processes you create for your consumer group. And, yes, it can span multiple computer/nodes. Kafka's group coordinator will then assign individual threads to a partition of a topic. Note that a single TopicPartition can be consumed at maximum by one consumer (jvm process) within the same consumer group.

"If it spans multiple computers then keeping track of offsets etc. will be hard."

Kafka makes this easy by centrally storing all meta information and progress of each consumer group within an internal topic called "__consumer_offsets" which is available across the entire cluster, if and only if all nodes belong to the same cluster.

First of all, you don't create consumer groups directly. You just create consumers and consumers that have same group.id will represent a consumer group. When multiple consumers are subscribed to a topic and belong to the same consumer group, each consumer in the group will receive messages from a different subset of the partitions in the topic. As shown in the image below:

Of course you can create these consumers in different servers and it is recommended approach for load balancing.

Kafka stores offsets for each consumer groups in topic named __consumer_offsets. So keeping track of the offsets is not that hard. You can check consumer offsets for a consumer groups with a command like this:

enter image description here

Related