0
0
Kafkadevops~20 mins

Message broker architecture in Kafka - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Kafka Message Broker Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Kafka consumer code snippet?

Consider a Kafka consumer configured to read from a topic with 3 partitions. The consumer group has 2 consumers. What will be the number of partitions assigned to each consumer?

Kafka
from kafka import KafkaConsumer

consumer = KafkaConsumer(
    'my_topic',
    group_id='my_group',
    bootstrap_servers=['localhost:9092']
)

consumer.poll(timeout_ms=1000)

partitions = consumer.assignment()
print(len(partitions))
A1
B3
C2
D0
Attempts:
2 left
💡 Hint

Partitions are distributed among consumers in a group as evenly as possible.

🧠 Conceptual
intermediate
1:30remaining
What is the role of a Kafka broker in message broker architecture?

Choose the best description of what a Kafka broker does in the message broker architecture.

AIt stores and manages messages in topics and handles client requests.
BIt produces messages to topics on behalf of producers.
CIt consumes messages from topics and processes them.
DIt acts as a load balancer for network traffic.
Attempts:
2 left
💡 Hint

Think about where messages are stored and how clients interact with Kafka.

🔧 Debug
advanced
2:30remaining
Why does this Kafka producer code raise a serialization error?

Examine the Kafka producer code below. It raises a serialization error when sending a message. What is the cause?

Kafka
from kafka import KafkaProducer

producer = KafkaProducer(bootstrap_servers='localhost:9092')

message = {'key': 'value'}
producer.send('my_topic', message)
producer.flush()
AThe bootstrap_servers parameter is incorrectly formatted.
BThe topic 'my_topic' does not exist on the broker.
CThe producer is missing the group_id parameter.
DThe message must be bytes, but a dict was sent without serialization.
Attempts:
2 left
💡 Hint

Kafka producers require messages in a specific format before sending.

📝 Syntax
advanced
1:30remaining
Which Kafka consumer code snippet correctly commits offsets automatically?

Identify the code snippet that enables automatic offset commits in a Kafka consumer.

Aconsumer = KafkaConsumer('topic', group_id='group', bootstrap_servers='localhost:9092', enable_auto_commit=True)
Bconsumer = KafkaConsumer('topic', group_id='group', bootstrap_servers='localhost:9092', auto_commit=True)
Cconsumer = KafkaConsumer('topic', group_id='group', bootstrap_servers='localhost:9092', commit_auto=True)
Dconsumer = KafkaConsumer('topic', group_id='group', bootstrap_servers='localhost:9092', auto_commit_offsets=True)
Attempts:
2 left
💡 Hint

Check the exact parameter name for enabling auto commit in KafkaConsumer.

🚀 Application
expert
2:00remaining
How many partitions will be in the topic after this Kafka topic creation command?

You run the following command to create a Kafka topic:

kafka-topics.sh --create --topic orders --partitions 5 --replication-factor 3 --bootstrap-server localhost:9092

How many partitions will the topic orders have?

A3
B5
C8
D15
Attempts:
2 left
💡 Hint

The --partitions flag sets the number of partitions.