Bird
0
0

You have a Kafka topic with 5 partitions. You want to send messages with keys but ensure that messages with null keys are evenly distributed across partitions. How should you configure the producer?

hard📝 Application Q9 of 15
Kafka - Producers
You have a Kafka topic with 5 partitions. You want to send messages with keys but ensure that messages with null keys are evenly distributed across partitions. How should you configure the producer?
AUse a custom partitioner that assigns null keys randomly across partitions
BSet all null keys to a fixed string to force same partition
CAvoid sending messages with null keys
DSet the value as the key for null keys
Step-by-Step Solution
Solution:
  1. Step 1: Understand default partitioning behavior

    By default, null keys are assigned partitions in a round-robin fashion, but custom behavior may be needed.
  2. Step 2: Choose configuration to distribute null keys evenly

    A custom partitioner can assign null keys randomly or evenly across partitions.
  3. Final Answer:

    Use a custom partitioner that assigns null keys randomly across partitions -> Option A
  4. Quick Check:

    Custom partitioner controls null key distribution [OK]
Quick Trick: Custom partitioner needed for null key distribution [OK]
Common Mistakes:
  • Forcing null keys to fixed string
  • Avoiding null keys unnecessarily
  • Using value as key for null keys

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes