A consumer group is a set of consumers that work together to read data from Kafka topics. Each consumer in the group reads from a unique set of partitions, allowing parallel processing.
Click to reveal answer
intermediate
How does Kafka ensure that messages are processed only once within a consumer group?
Kafka assigns each partition to only one consumer in the group at a time, so messages from a partition are processed by only one consumer, preventing duplicate processing within the group.
Click to reveal answer
intermediate
What happens if a consumer in a consumer group fails?
Kafka automatically reassigns the partitions of the failed consumer to other consumers in the group, ensuring continuous message processing without data loss.
Click to reveal answer
beginner
Can multiple consumer groups read from the same Kafka topic independently?
Yes, each consumer group reads independently from the topic. This allows multiple applications or services to consume the same data without interfering with each other.
Click to reveal answer
intermediate
What is the role of partition assignment in a consumer group?
Partition assignment decides which consumer reads from which partition. It balances the load and ensures each partition is read by only one consumer in the group at a time.
Click to reveal answer
What does a Kafka consumer group do?
ACreates new topics automatically
BDuplicates messages to all consumers
CStores messages permanently
DDistributes partitions among consumers for parallel processing
✗ Incorrect
A consumer group divides partitions among its consumers so they can process messages in parallel without overlap.
If a consumer leaves a consumer group, what happens to its partitions?
AThey stop producing messages
BThey are deleted
CThey are reassigned to other consumers in the group
DThey remain unassigned forever
✗ Incorrect
Kafka reassigns partitions from the leaving consumer to others to keep processing continuous.
Can two consumers in the same group read the same partition at the same time?
AOnly if the topic has one partition
BNo, only one consumer reads a partition at a time
COnly if they are on different machines
DYes, always
✗ Incorrect
Kafka ensures exclusive partition assignment within a consumer group to avoid duplicate processing.
Multiple consumer groups reading the same topic means:
AEach group reads independently without affecting others
BThey share the same offsets
CMessages are deleted after one group reads them
DOnly one group can read at a time
✗ Incorrect
Each consumer group maintains its own offset and reads independently from the topic.
What is the main benefit of using consumer groups?
AScalable and fault-tolerant message consumption
BFaster message production
CAutomatic topic creation
DMessage encryption
✗ Incorrect
Consumer groups allow multiple consumers to share the load and handle failures gracefully.
Explain how Kafka consumer groups help in scaling message consumption.
Think about how work is divided among friends to finish faster.
You got /4 concepts.
Describe what happens when a consumer in a consumer group crashes.
Imagine a team member leaves and others pick up their tasks.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of a consumer group in Kafka?
easy
A. To allow multiple consumers to share the work of reading messages
B. To store messages permanently in Kafka
C. To produce messages to Kafka topics
D. To encrypt messages during transmission
Solution
Step 1: Understand consumer group role
A consumer group lets multiple consumers work together to read messages from a topic.
Step 2: Compare other options
Storing messages, producing messages, and encrypting are not roles of consumer groups.
Final Answer:
To allow multiple consumers to share the work of reading messages -> Option A
Quick Check:
Consumer group = share reading work [OK]
Hint: Consumer groups split message reading among consumers [OK]
Common Mistakes:
Confusing consumer groups with producers
Thinking consumer groups store messages
Assuming consumer groups encrypt data
2. Which of the following is the correct way to specify a consumer group ID in Kafka consumer configuration?
easy
A. "groupName" : "my-group"
B. "group.id" : "my-group"
C. "consumer.group" : "my-group"
D. "consumerId" : "my-group"
Solution
Step 1: Recall Kafka consumer config keys
The correct key to set the consumer group is "group.id".
Step 2: Check other options
Other keys like "consumer.group", "groupName", or "consumerId" are incorrect or do not exist.
Final Answer:
"group.id" : "my-group" -> Option B
Quick Check:
Consumer group ID key = "group.id" [OK]
Hint: Remember Kafka uses "group.id" for consumer groups [OK]
Common Mistakes:
Using incorrect config keys
Confusing consumer ID with group ID
Misspelling the key name
3. Given a Kafka topic with 4 partitions and a consumer group with 2 consumers, how many partitions will each consumer read from?
medium
A. Each consumer reads from 2 partitions
B. Each consumer reads from 4 partitions
C. Each consumer reads from 1 partition
D. Each consumer reads from 0 partitions
Solution
Step 1: Understand partition assignment
Partitions are divided among consumers in a group. With 4 partitions and 2 consumers, partitions split evenly.
Step 2: Calculate partitions per consumer
4 partitions / 2 consumers = 2 partitions per consumer.
Final Answer:
Each consumer reads from 2 partitions -> Option A
Quick Check:
Partitions per consumer = total partitions / consumers = 2 [OK]
Hint: Partitions divide evenly among consumers in a group [OK]
Common Mistakes:
Assuming each consumer reads all partitions
Thinking partitions are not shared
Ignoring partition count
4. What is wrong with this Kafka consumer group code snippet?