apache-kafkakafka-consumer-api

Is Consumer Offset managed at Consumer group level or at the individual consumer inside that consumer group?


I am trying to find out is there any offsets at consumer group level as well. Is Consumer Offset is at Consumer group level or at the individual consumer inside that consumer group in Kafka ?


Solution

  • Offsets are tracked at ConsumerGroup level.

    Imagine you have 4 consumer threads in one ConsumerGroup consuming from one topic with 4 partitions. If you now stop all 4 threads and restart just a single one with the same group the one threads will know where all 4 threads left off consuming and continue from there.


    "you are saying one offset (basically a shared int/long value) will be shared/updated by all the consumers in a consumer group?"

    Yes, this is correct. Remember that a single partition of a topic can be read only by one consumer thread within a group. Two consumer threads of the same ConsumerGroup will never consume a single topic partition at the same time. The offsets of the consumers groups are stored in an internal Kafka topic called __consumer_offsets. In this topic you basically have a key/value pair, where your key is the concatenation of

    and your value is the offset. This internal __consumer_offsets topic is available to all consumers so the information is shared.