Bird
0
0

Given a Kafka topic with 4 partitions, if a producer sends messages with keys "A", "B", "A", and "C", which partitions will the messages with key "A" go to?

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

Given a Kafka topic with 4 partitions, if a producer sends messages with keys "A", "B", "A", and "C", which partitions will the messages with key "A" go to?

AEach message with key "A" goes to a different partition
BBoth messages with key "A" go to the same partition
CMessages with key "A" go to partition 0 only
DMessages with key "A" are sent to all partitions
Step-by-Step Solution
Solution:
  1. Step 1: Understand key-based partitioning

    Kafka hashes the key to assign a partition, so same keys map to the same partition.
  2. Step 2: Apply this to messages with key "A"

    Both messages with key "A" will go to the same partition to maintain order.
  3. Final Answer:

    Both messages with key "A" go to the same partition -> Option B
  4. Quick Check:

    Same key = same partition [OK]
Quick Trick: Same key always maps to same partition [OK]
Common Mistakes:
  • Assuming keys distribute randomly
  • Thinking same keys go to different partitions
  • Believing messages go to all partitions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes