Bird
0
0

You have a Kafka topic with 4 partitions. You want to ensure that all messages with the same customer ID go to the same partition to keep their order. Which approach should you use?

hard📝 Application Q15 of 15
Kafka - Topics and Partitions

You have a Kafka topic with 4 partitions. You want to ensure that all messages with the same customer ID go to the same partition to keep their order. Which approach should you use?

ACreate 4 separate topics, one per customer
BSend all messages to partition 0 manually
CUse a random key for each message
DUse the customer ID as the message key when producing messages
Step-by-Step Solution
Solution:
  1. Step 1: Understand how Kafka assigns partitions

    Kafka uses the message key to decide which partition a message goes to, ensuring order for messages with the same key.
  2. Step 2: Apply to customer ID ordering requirement

    Using the customer ID as the key ensures all messages for that customer go to the same partition and keep order.
  3. Step 3: Evaluate other options

    Sending all to partition 0 limits scalability; random keys break order; separate topics complicate management.
  4. Final Answer:

    Use the customer ID as the message key when producing messages -> Option D
  5. Quick Check:

    Key = customer ID for order [OK]
Quick Trick: Use customer ID as key to keep order in one partition [OK]
Common Mistakes:
  • Sending all messages to one partition reduces scalability
  • Using random keys breaks message order
  • Creating multiple topics is unnecessary and complex

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes