Bird
0
0

How should you handle partition keys to maintain message order for valid IDs and avoid errors?

hard📝 Application Q15 of 15
Kafka - Topics and Partitions
You want to ensure that messages related to the same customer ID always go to the same partition, but your customer IDs sometimes are null or empty strings. How should you handle partition keys to maintain message order for valid IDs and avoid errors?
AUse the customer ID as key only if it is non-empty; otherwise, assign a default fixed key
BAlways send messages with null keys to let Kafka distribute randomly
CConvert null or empty IDs to random UUIDs as keys
DIgnore keys and rely on Kafka's default partitioning
Step-by-Step Solution
Solution:
  1. Step 1: Identify the problem with null or empty keys

    Null or empty keys cause Kafka to distribute messages randomly, breaking order.
  2. Step 2: Use a default fixed key for missing IDs

    Assigning a fixed key for missing IDs groups those messages in one partition, preserving order for them.
  3. Step 3: Keep valid customer IDs as keys

    Valid IDs remain keys to ensure their messages go to the same partition.
  4. Final Answer:

    Use the customer ID as key only if it is non-empty; otherwise, assign a default fixed key -> Option A
  5. Quick Check:

    Non-empty key or default fixed key = A [OK]
Quick Trick: Use default key for missing IDs to keep order [OK]
Common Mistakes:
  • Sending null keys causing random partitioning
  • Using random UUIDs breaking message grouping
  • Ignoring keys and losing message order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes