Bird
0
0

To guarantee that all messages with the same customer ID are sent to the same Kafka partition, which message attribute should be set and why?

hard📝 Application Q8 of 15
Kafka - Producers
To guarantee that all messages with the same customer ID are sent to the same Kafka partition, which message attribute should be set and why?
AUse a null key and rely on Kafka's default partitioner to group messages.
BSet the message value to the customer ID, so Kafka can filter messages by value.
CSet the partition number manually for each message to the same partition.
DSet the message key to the customer ID, so Kafka partitions messages by key hash.
Step-by-Step Solution
Solution:
  1. Step 1: Understand Kafka partitioning

    Kafka uses the message key's hash to determine the partition for ordering guarantees.
  2. Step 2: Analyze options

    Setting the key to customer ID ensures all messages with that ID go to the same partition.
  3. Step 3: Evaluate other options

    Value is not used for partitioning. Manually setting partition is possible but not scalable. Null key causes random distribution.
  4. Final Answer:

    Set the message key to the customer ID, so Kafka partitions messages by key hash. -> Option D
  5. Quick Check:

    Key controls partitioning for ordering [OK]
Quick Trick: Use key for partitioning to maintain message order [OK]
Common Mistakes:
  • Using value instead of key for partitioning
  • Manually assigning partitions unnecessarily
  • Relying on null keys for grouping

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes