Bird
0
0

Given a Kafka topic with 4 partitions, what will be the partition number for a message with key hash % 4 = 2?

medium📝 Predict Output Q13 of 15
Kafka - Performance Tuning
Given a Kafka topic with 4 partitions, what will be the partition number for a message with key hash % 4 = 2?
APartition 0
BPartition 1
CPartition 2
DPartition 3
Step-by-Step Solution
Solution:
  1. Step 1: Understand partition assignment by key hash

    Kafka assigns messages to partitions by taking the key hash modulo the number of partitions.
  2. Step 2: Calculate partition number

    Given key hash % 4 = 2, the message goes to partition 2 (zero-based indexing).
  3. Final Answer:

    Partition 2 -> Option C
  4. Quick Check:

    Key hash % partitions = partition number [OK]
Quick Trick: Partition = key hash modulo partition count [OK]
Common Mistakes:
  • Confusing modulo result with partition index
  • Assuming partitions start at 1 instead of 0
  • Ignoring key hash in partition calculation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes