Bird
0
0

Given a Kafka topic with 4 partitions, if you send messages with keys "user1", "user2", "user1", which partitions will the messages with key "user1" be routed to?

medium📝 Predict Output Q4 of 15
Kafka - Topics and Partitions
Given a Kafka topic with 4 partitions, if you send messages with keys "user1", "user2", "user1", which partitions will the messages with key "user1" be routed to?
AKafka throws an error for duplicate keys
BThey go to different partitions randomly
CBoth messages with key "user1" go to the same partition
DOne goes to partition 0, the other to partition 1
Step-by-Step Solution
Solution:
  1. Step 1: Understand key-based partitioning

    Kafka hashes the key to decide the partition, so same keys map to the same partition.
  2. Step 2: Apply to given keys

    Both messages with "user1" key will be routed to the same partition consistently.
  3. Final Answer:

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

    Same key = same partition [OK]
Quick Trick: Same key always routes to same partition [OK]
Common Mistakes:
  • Assuming keys route randomly each time
  • Thinking Kafka errors on duplicate keys
  • Believing keys map to fixed partitions by order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes