Static group membership in Kafka - Commands & Configuration
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=falsegroup.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.
kafka-console-consumer --bootstrap-server localhost:9092 --topic my-topic --group my-static-group --consumer-property static.group.instance.id=consumer-1 --from-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.kafka-consumer-groups --bootstrap-server localhost:9092 --describe --group my-static-group--describe - Displays detailed information about the consumer group.--group - Specifies the consumer group to describe.kafka-console-consumer --bootstrap-server localhost:9092 --topic my-topic --group my-static-group --consumer-property static.group.instance.id=consumer-2 --from-beginning--consumer-property static.group.instance.id=consumer-2 - Unique static ID for the second consumer instance.kafka-consumer-groups --bootstrap-server localhost:9092 --describe --group my-static-group--describe - Shows detailed group membership.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.
Practice
What is the main purpose of using group.instance.id in Kafka consumer groups?
Solution
Step 1: Understand the role of
This configuration assigns a unique and stable identity to a Kafka consumer within a group.group.instance.idStep 2: Connect stable identity to static group membership
With a stable identity, Kafka can avoid unnecessary rebalances when a consumer restarts briefly, improving stability.Final Answer:
To assign a stable identity to a consumer and enable static group membership -> Option DQuick Check:
Stable consumer identity = static group membership [OK]
- Confusing
group.instance.idwith partition count - Thinking it controls offset commit frequency
- Assuming it encrypts messages
Which of the following is the correct way to set group.instance.id in a Kafka consumer configuration?
Properties props = new Properties();
props.put("bootstrap.servers", "localhost:9092");
// What is the correct line to set static membership?Solution
Step 1: Recall the exact property name for static membership
The correct property to set a static consumer ID isgroup.instance.id.Step 2: Match the correct syntax in Java Properties
Usingprops.put("group.instance.id", "consumer-1")correctly sets the static ID.Final Answer:
props.put("group.instance.id", "consumer-1"); -> Option AQuick Check:
Correct property name = group.instance.id [OK]
- Swapping words in the property name
- Using incomplete or incorrect property keys
- Confusing with group.id
Consider this Kafka consumer group with static membership enabled using group.instance.id. If a consumer with group.instance.id = "consumer-1" disconnects briefly and reconnects, what happens?
Solution
Step 1: Understand static membership behavior on brief disconnect
Static membership keeps the consumer identity stable, so brief disconnects do not cause rebalances.Step 2: Identify the effect on partition assignment
The consumer resumes with the same partitions without triggering a rebalance, improving latency and stability.Final Answer:
The consumer resumes without triggering a rebalance -> Option CQuick Check:
Static membership avoids rebalance on brief disconnect [OK]
- Assuming every disconnect triggers rebalance
- Thinking consumer is removed permanently
- Believing new ID is required on reconnect
Given this Kafka consumer config snippet, identify the error preventing static group membership:
props.put("group.id", "my-group");
props.put("group.instance.id", "consumer-1");
props.put("session.timeout.ms", "10000");
// Missing property?Solution
Step 1: Check required properties for static membership
Static membership requiresgroup.protocol.typeto be set toconsumerexplicitly in some Kafka versions.Step 2: Identify missing property in config
The snippet lacksgroup.protocol.type, which can prevent static membership from working properly.Final Answer:
Missinggroup.protocol.typeset toconsumer-> Option AQuick Check:
Static membership needs group.protocol.type=consumer [OK]
- Assuming auto commit affects static membership
- Confusing client.id with group.instance.id
- Ignoring group.protocol.type requirement
You have a Kafka consumer group with 3 consumers using static membership via group.instance.id. One consumer crashes and restarts quickly with the same group.instance.id. What is the expected behavior and why is static membership important here?
Solution
Step 1: Analyze static membership effect on consumer restart
Static membership keeps the consumer identity stable, so a quick restart does not cause a rebalance.Step 2: Understand impact on group processing
Because no rebalance occurs, partition assignments remain unchanged, allowing smooth and low-latency processing.Final Answer:
The group avoids a rebalance, so processing continues smoothly with minimal delay -> Option BQuick Check:
Static membership prevents rebalance on quick restart [OK]
- Expecting rebalance on every consumer restart
- Thinking new ID is required after crash
- Assuming group pauses automatically
Ready to prove it?
Pass the test and this pattern moves unknown
