0
0
Kafkadevops~7 mins

Static group membership in Kafka - Commands & Configuration

Choose your learning style9 modes available
Introduction
Static group membership in Kafka helps keep consumer group membership stable even if consumers disconnect temporarily. This avoids costly rebalances and improves performance by assigning fixed members to the group.
When you have consumers that may restart or disconnect briefly but want to keep their assigned partitions without triggering a rebalance.
When running stateful stream processing applications that need stable partition assignments to avoid state loss.
When you want to reduce the overhead of frequent consumer group rebalances in a high-availability setup.
When you want to assign specific consumers to fixed partitions for better control and predictability.
When you want to improve consumer group stability in environments with unstable network connections.
Config File - consumer.properties
consumer.properties
group.id=my-static-group
bootstrap.servers=localhost:9092
partition.assignment.strategy=org.apache.kafka.clients.consumer.RangeAssignor
static.group.instance.id=consumer-1
key.deserializer=org.apache.kafka.common.serialization.StringDeserializer
value.deserializer=org.apache.kafka.common.serialization.StringDeserializer
enable.auto.commit=false

group.id: Identifies the consumer group name.

bootstrap.servers: Kafka broker addresses to connect.

partition.assignment.strategy: Strategy to assign partitions to consumers.

static.group.instance.id: Unique static identifier for this consumer instance to enable static membership.

key.deserializer and value.deserializer: How to convert message bytes to strings.

enable.auto.commit: Disables automatic offset commits for manual control.

Commands
Starts a Kafka consumer with a static group instance ID to join the group with stable membership.
Terminal
kafka-console-consumer --bootstrap-server localhost:9092 --topic my-topic --group my-static-group --consumer-property static.group.instance.id=consumer-1 --from-beginning
Expected OutputExpected
Subscribed to topic(s): my-topic [Consumer is ready and consuming messages from the beginning]
--group - Specifies the consumer group name.
--consumer-property static.group.instance.id=consumer-1 - Sets the static group instance ID for stable membership.
--from-beginning - Consumes messages from the start of the topic.
Shows the current state and partition assignments of the static consumer group.
Terminal
kafka-consumer-groups --bootstrap-server localhost:9092 --describe --group my-static-group
Expected OutputExpected
GROUP TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAG CONSUMER-ID HOST CLIENT-ID my-static-group my-topic 0 15 15 0 consumer-1-12345-67890-abcde /127.0.0.1 consumer-1
--describe - Displays detailed information about the consumer group.
--group - Specifies the consumer group to describe.
Starts a second static consumer with a different static group instance ID to join the same group without triggering a rebalance.
Terminal
kafka-console-consumer --bootstrap-server localhost:9092 --topic my-topic --group my-static-group --consumer-property static.group.instance.id=consumer-2 --from-beginning
Expected OutputExpected
Subscribed to topic(s): my-topic [Second consumer is ready and consuming messages]
--consumer-property static.group.instance.id=consumer-2 - Unique static ID for the second consumer instance.
Verifies that both static consumers are part of the group with stable partition assignments.
Terminal
kafka-consumer-groups --bootstrap-server localhost:9092 --describe --group my-static-group
Expected OutputExpected
GROUP TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAG CONSUMER-ID HOST CLIENT-ID my-static-group my-topic 0 15 15 0 consumer-1-12345-67890-abcde /127.0.0.1 consumer-1 my-static-group my-topic 1 10 10 0 consumer-2-12345-67890-fghij /127.0.0.1 consumer-2
--describe - Shows detailed group membership.
Key Concept

If you remember nothing else from this pattern, remember: static group membership uses unique instance IDs to keep consumers assigned without triggering rebalances on temporary disconnects.

Common Mistakes
Not setting the static.group.instance.id property for each consumer instance.
Without this ID, Kafka treats consumers as dynamic members causing rebalances on disconnects.
Always set a unique static.group.instance.id for each consumer to enable static membership.
Using the same static.group.instance.id for multiple consumer instances.
This causes conflicts and unstable group membership.
Assign a unique static.group.instance.id to each consumer instance.
Not verifying group membership with kafka-consumer-groups after starting consumers.
You might miss issues with partition assignments or membership stability.
Use kafka-consumer-groups --describe to check group state and assignments.
Summary
Configure each Kafka consumer with a unique static.group.instance.id to enable static group membership.
Start consumers with the static ID to join the group without triggering rebalances on disconnects.
Use kafka-consumer-groups --describe to verify stable membership and partition assignments.