Groups and fetching
Learn more about how consumer groups fetch messages.
Kafka consumers are usually assigned to a group. This happens statically by setting the
group.id
configuration property in the consumer configuration. Consuming
with groups will result in the consumers balancing the load in the group. That means each
consumer will have their fair share of partitions. Also it can never be more consumers than
partitions as that way there would be idling consumers.
As shown in the figure below, both consumer groups share the partitions and each partition multicasts messages to both consumer groups. The consumers pull messages from the broker instead of the broker periodically pushing what is available. This helps the consumer as it won’t be overloaded and it can query the broker at its own speed. Furthermore, to avoid tight looping, it uses a so called “long-poll”. The consumer sends a fetch request to poll for data and receives a reply only when enough data accumulates on the broker.