0
0
Kafkadevops~20 mins

Resource planning and capacity in Kafka - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Kafka Resource Planning Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Partition assignment output in Kafka consumer group
What is the output of the following Kafka consumer group partition assignment code snippet?
Kafka
from kafka import KafkaConsumer

consumer = KafkaConsumer(
    'topic1',
    group_id='group1',
    bootstrap_servers=['localhost:9092'],
    enable_auto_commit=False
)

partitions = consumer.partitions_for_topic('topic1')
print(sorted(partitions))
ANone
B[0, 1, 2]
Cset()
D['partition0', 'partition1', 'partition2']
Attempts:
2 left
💡 Hint
Check what partitions_for_topic returns and how to convert it to a list.
Predict Output
intermediate
1:30remaining
Calculating consumer lag from offsets
Given the following code to calculate consumer lag, what is the value of `lag` after execution?
Kafka
end_offsets = {0: 150, 1: 200}
committed_offsets = {0: 140, 1: 180}
lag = sum(end_offsets[p] - committed_offsets[p] for p in end_offsets)
print(lag)
A50
BNone
C20
D30
Attempts:
2 left
💡 Hint
Calculate the difference for each partition and sum them.
🔧 Debug
advanced
1:00remaining
Identify the error in Kafka producer throughput calculation
What error will the following code raise when calculating throughput?
Kafka
messages_sent = 1000
elapsed_time = 0
throughput = messages_sent / elapsed_time
print(f'Throughput: {throughput} msgs/sec')
AZeroDivisionError
BTypeError
CNameError
DNo error, prints 'Throughput: 1000 msgs/sec'
Attempts:
2 left
💡 Hint
Check the value of elapsed_time before division.
Predict Output
advanced
1:30remaining
Result of consumer assignment after rebalance
What will be the output of the following code snippet simulating consumer assignment after rebalance?
Kafka
consumer_assignment = {0: 'consumer1', 1: 'consumer2', 2: 'consumer1'}
from collections import Counter
count = Counter(consumer_assignment.values())
print(count['consumer1'])
A2
B1
C3
DKeyError
Attempts:
2 left
💡 Hint
Count how many partitions are assigned to 'consumer1'.
🧠 Conceptual
expert
2:30remaining
Maximum throughput calculation with partition and consumer limits
Given a Kafka topic with 12 partitions and 4 consumers in a group, each consumer can process 500 messages per second. What is the maximum total throughput achievable assuming perfect load balancing?
A6000 messages per second
B3000 messages per second
C2000 messages per second
D4000 messages per second
Attempts:
2 left
💡 Hint
Each consumer processes 500 msgs/sec. Total throughput is consumers * per consumer rate.