Bird
0
0

Given a Kafka topic with 3 partitions, if messages with keys "key1", "key2", and "key1" are sent in that order, which partition will the second "key1" message go to?

medium📝 Predict Output Q13 of 15
Kafka - Topics and Partitions

Given a Kafka topic with 3 partitions, if messages with keys "key1", "key2", and "key1" are sent in that order, which partition will the second "key1" message go to?

APartition 1
BSame partition as the first <code>"key1"</code> message
CPartition 0
DA random partition different from the first <code>"key1"</code> message
Step-by-Step Solution
Solution:
  1. Step 1: Understand key-based partitioning

    Kafka uses the message key to decide the partition. Messages with the same key always go to the same partition.
  2. Step 2: Apply to the given keys

    Since both messages have key "key1", the second message will go to the same partition as the first "key1" message.
  3. Final Answer:

    Same partition as the first "key1" message -> Option B
  4. Quick Check:

    Same key = same partition [OK]
Quick Trick: Same keys always go to the same partition [OK]
Common Mistakes:
  • Assuming keys distribute randomly each time
  • Thinking second message goes to a different partition
  • Ignoring key-based partitioning

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes