Bird
0
0

You have this Kafka producer code snippet:

medium📝 Debug Q14 of 15
Kafka - Topics and Partitions
You have this Kafka producer code snippet:
producer.send(new ProducerRecord<>("topic", null, "msg1"));
producer.send(new ProducerRecord<>("topic", null, "msg2"));

Why might message order not be preserved?
ABecause the topic has only one partition.
BBecause Kafka always reorders messages regardless of keys.
CBecause messages with null keys can go to different partitions, losing order.
DBecause the producer is synchronous.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze key usage in ProducerRecord

    Null keys mean Kafka uses round-robin or default partitioner, sending messages to different partitions.
  2. Step 2: Understand ordering impact

    Messages in different partitions have no ordering guarantee, so order may be lost.
  3. Final Answer:

    Because messages with null keys can go to different partitions, losing order. -> Option C
  4. Quick Check:

    Null key = no partition order guarantee [OK]
Quick Trick: Null keys cause messages to spread partitions, breaking order [OK]
Common Mistakes:
  • Thinking Kafka always orders messages
  • Assuming one partition means no order loss
  • Confusing synchronous with ordering guarantee

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes