Bird
0
0

Given a Kafka topic with 3 partitions, what partition will a message with hash(key)=7 be assigned to if the partitioner uses hash(key) % partition_count?

medium📝 Predict Output Q4 of 15
Kafka - Performance Tuning
Given a Kafka topic with 3 partitions, what partition will a message with hash(key)=7 be assigned to if the partitioner uses hash(key) % partition_count?
APartition 0
BPartition 1
CPartition 2
DPartition 3
Step-by-Step Solution
Solution:
  1. Step 1: Calculate hash(key) % 3

    hash(key)=7 % 3 = 1.
  2. Step 2: Apply modulo operation

    hash(key) % 3 = 1 means message goes to partition 1.
  3. Final Answer:

    Partition 1 -> Option B
  4. Quick Check:

    Partition = hash(key) % count = 1 [OK]
Quick Trick: Partition = hash(key) mod partition count [OK]
Common Mistakes:
MISTAKES
  • Choosing partition 3 which does not exist (index starts at 0)
  • Ignoring modulo operation
  • Assuming random partition assignment

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes