0
0
Kafkadevops~20 mins

Partition count strategy in Kafka - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Kafka Partition 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 partition assignment code?

Consider a Kafka topic with 3 partitions and 2 consumers in a consumer group. Given the following partition assignment logic, what partitions will each consumer receive?

Kafka
partitions = [0, 1, 2]
consumers = ['consumer1', 'consumer2']
assignment = {c: [] for c in consumers}
for i, p in enumerate(partitions):
    assignment[consumers[i % len(consumers)]].append(p)
print(assignment)
A{'consumer1': [0], 'consumer2': [1, 2]}
B{'consumer1': [1, 2], 'consumer2': [0]}
C{'consumer1': [0, 2], 'consumer2': [1]}
D{'consumer1': [0, 1, 2], 'consumer2': []}
Attempts:
2 left
💡 Hint

Partitions are assigned in a round-robin way based on the index modulo the number of consumers.

🧠 Conceptual
intermediate
1:30remaining
How does increasing partition count affect Kafka topic throughput?

Which statement best describes the effect of increasing the number of partitions in a Kafka topic on throughput?

AIncreasing partitions always decreases throughput due to overhead.
BIncreasing partitions can increase throughput by allowing more parallelism.
CPartition count has no effect on throughput.
DIncreasing partitions reduces throughput because consumers get fewer messages.
Attempts:
2 left
💡 Hint

Think about how partitions allow multiple consumers to read in parallel.

🔧 Debug
advanced
2:00remaining
Identify the error in this partition assignment code snippet

What error will this Kafka partition assignment code raise?

Kafka
partitions = [0, 1, 2]
consumers = ['c1', 'c2']
assignment = {c: [] for c in consumers}
for i in range(len(partitions)+1):
    assignment[consumers[i % len(consumers)]].append(partitions[i])
print(assignment)
AIndexError: list index out of range
BKeyError: 'c3'
CTypeError: unsupported operand type(s)
DNo error, prints assignment correctly
Attempts:
2 left
💡 Hint

Check the loop range and how it accesses the partitions list.

📝 Syntax
advanced
1:30remaining
Which option correctly defines a Kafka topic with 5 partitions using Kafka CLI?

Choose the correct Kafka CLI command to create a topic named 'logs' with 5 partitions.

Akafka-topics.sh --create --topic logs --partitions-count 5 --bootstrap-server localhost:9092
Bkafka-topics.sh --create --topic logs --partition-count 5 --bootstrap-server localhost:9092
Ckafka-topics.sh --create --topic logs --num-partitions 5 --bootstrap-server localhost:9092
Dkafka-topics.sh --create --topic logs --partitions 5 --bootstrap-server localhost:9092
Attempts:
2 left
💡 Hint

Check the exact option name for partitions in Kafka CLI.

🚀 Application
expert
2:30remaining
Calculate the number of partitions needed for a target throughput

You want to achieve a throughput of 1 million messages per second. Each partition can handle 100,000 messages per second. How many partitions should your Kafka topic have at minimum?

A10
B100
C1,000
D100,000
Attempts:
2 left
💡 Hint

Divide the target throughput by the capacity per partition.