Challenge - 5 Problems
Kafka Static Group Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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());
Attempts:
2 left
💡 Hint
Static group membership allows the consumer to keep its partition assignments across restarts, avoiding rebalance delays.
✗ Incorrect
When a consumer uses static group membership with a fixed group.instance.id, Kafka recognizes it as the same member after restart. This prevents rebalancing and the consumer resumes from its last committed offsets. Therefore, after restart, it will not re-poll the same messages again, resulting in zero new records polled.
🧠 Conceptual
intermediate1:30remaining
Understanding static group membership benefits
Which of the following is a key benefit of using static group membership in Kafka consumer groups?
Attempts:
2 left
💡 Hint
Think about what happens when a consumer leaves and rejoins the group with the same ID.
✗ Incorrect
Static group membership assigns a fixed member ID to a consumer. When the consumer restarts with the same ID, Kafka treats it as the same member, avoiding unnecessary rebalances and improving stability.
🔧 Debug
advanced2: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?
Attempts:
2 left
💡 Hint
Static group membership requires unique member IDs per active consumer.
✗ Incorrect
Static group membership requires each active consumer to have a unique group.instance.id. If two consumers use the same ID at the same time, Kafka rejects the second with a member ID conflict error.
❓ Predict Output
advanced2: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));
Attempts:
2 left
💡 Hint
Static membership avoids unnecessary rebalances on restart.
✗ Incorrect
With static group membership, the consumer is recognized as the same member after restart. Kafka does not revoke partitions before restart and reassigns them immediately, so revoked partitions list is empty and assigned partitions are the same as before.
🧠 Conceptual
expert3: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?
Attempts:
2 left
💡 Hint
Think about how Kafka treats static members differently from dynamic members on unexpected leave.
✗ Incorrect
Kafka retains offsets for static group members longer because it expects the member to rejoin with the same group.instance.id. This reduces unnecessary offset deletions and rebalances.