Bird
0
0

Consider this code snippet for sending messages without keys:

medium📝 Debug Q14 of 15
Kafka - Producers

Consider this code snippet for sending messages without keys:

for i in range(4):
    producer.send("topic", value=f"msg{i}")

What is the likely issue if all messages end up in the same partition?

AMessages have keys that force same partition
BTopic has only one partition
CThe producer is not configured to use round-robin partitioning
DProducer is using a custom partitioner ignoring keys
Step-by-Step Solution
Solution:
  1. Step 1: Analyze message keys and partition count

    Messages have no keys, so default partitioner uses round-robin if multiple partitions exist.
  2. Step 2: Check topic partition count

    If all messages go to the same partition, likely the topic has only one partition.
  3. Final Answer:

    Topic has only one partition -> Option B
  4. Quick Check:

    Single partition topic = all messages same partition [OK]
Quick Trick: Single partition topic sends all messages there [OK]
Common Mistakes:
  • Assuming round-robin works with one partition
  • Thinking keys are present when they are not
  • Ignoring topic partition count

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes