0
0
Kafkadevops~20 mins

Static group membership in Kafka - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Kafka Static Group Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Static group membership with fixed member IDs
Given the following Kafka consumer group configuration with static membership, what will be the output when the consumer restarts with the same member ID?
Kafka
consumerProps.put("group.id", "my-group");
consumerProps.put("group.instance.id", "consumer-1");

// Consumer subscribes and polls messages
consumer.subscribe(Collections.singletonList("my-topic"));
ConsumerRecords<String, String> records = consumer.poll(Duration.ofSeconds(1));
System.out.println("Polled records count: " + records.count());

// Consumer closes and restarts with same group.instance.id
consumer.close();
consumer = new KafkaConsumer<>(consumerProps);
consumer.subscribe(Collections.singletonList("my-topic"));
records = consumer.poll(Duration.ofSeconds(1));
System.out.println("Polled records count after restart: " + records.count());
A
Polled records count: 0
Polled records count after restart: 10
B
Polled records count: 10
Polled records count after restart: 10
C
Polled records count: 10
Polled records count after restart: 0
D
Polled records count: 0
Polled records count after restart: 0
Attempts:
2 left
💡 Hint
Static group membership allows the consumer to keep its partition assignments across restarts, avoiding rebalance delays.
🧠 Conceptual
intermediate
1:30remaining
Understanding static group membership benefits
Which of the following is a key benefit of using static group membership in Kafka consumer groups?
AIt allows consumers to dynamically change their group.instance.id during runtime.
BIt automatically increases the number of partitions in the topic.
CIt eliminates the need for consumers to commit offsets manually.
DIt reduces consumer group rebalances when a consumer restarts with the same member ID.
Attempts:
2 left
💡 Hint
Think about what happens when a consumer leaves and rejoins the group with the same ID.
🔧 Debug
advanced
2:00remaining
Debugging static group membership error
A Kafka consumer configured with static group membership fails to join the group and throws an error: "Member ID consumer-1 is already in use." What is the most likely cause?
AThe consumer did not commit offsets before restarting.
BTwo consumers are running simultaneously with the same group.instance.id.
CThe topic has fewer partitions than consumers.
DThe consumer group ID is missing in the configuration.
Attempts:
2 left
💡 Hint
Static group membership requires unique member IDs per active consumer.
Predict Output
advanced
2:30remaining
Effect of static group membership on rebalance listeners
Consider a Kafka consumer with a RebalanceListener that logs partition assignments. The consumer uses static group membership and restarts with the same group.instance.id. What will the listener output after restart?
Kafka
consumerProps.put("group.id", "my-group");
consumerProps.put("group.instance.id", "consumer-42");

consumer.subscribe(Collections.singletonList("my-topic"), new ConsumerRebalanceListener() {
    public void onPartitionsRevoked(Collection<TopicPartition> partitions) {
        System.out.println("Partitions revoked: " + partitions);
    }
    public void onPartitionsAssigned(Collection<TopicPartition> partitions) {
        System.out.println("Partitions assigned: " + partitions);
    }
});

consumer.poll(Duration.ofSeconds(1));
consumer.close();

// Restart consumer with same group.instance.id
consumer = new KafkaConsumer<>(consumerProps);
consumer.subscribe(Collections.singletonList("my-topic"), new ConsumerRebalanceListener() {
    public void onPartitionsRevoked(Collection<TopicPartition> partitions) {
        System.out.println("Partitions revoked: " + partitions);
    }
    public void onPartitionsAssigned(Collection<TopicPartition> partitions) {
        System.out.println("Partitions assigned: " + partitions);
    }
});
consumer.poll(Duration.ofSeconds(1));
A
Partitions revoked: []
Partitions assigned: [my-topic-0, my-topic-1]
B
Partitions revoked: [my-topic-0, my-topic-1]
Partitions assigned: [my-topic-0, my-topic-1]
C
Partitions revoked: []
Partitions assigned: []
DNo output from rebalance listener after restart
Attempts:
2 left
💡 Hint
Static membership avoids unnecessary rebalances on restart.
🧠 Conceptual
expert
3:00remaining
Static group membership and offset retention
How does static group membership affect the retention of consumer group offsets in Kafka when a consumer leaves the group unexpectedly?
AOffsets are retained longer because Kafka waits for the static member to rejoin before removing offsets.
BOffsets are immediately deleted when the consumer leaves, regardless of static membership.
COffsets are never deleted for static members, even if they never rejoin.
DStatic group membership has no effect on offset retention policies.
Attempts:
2 left
💡 Hint
Think about how Kafka treats static members differently from dynamic members on unexpected leave.