Kafka - ProducersTo 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.Check Answer
Step-by-Step SolutionSolution:Step 1: Understand Kafka partitioningKafka uses the message key's hash to determine the partition for ordering guarantees.Step 2: Analyze optionsSetting the key to customer ID ensures all messages with that ID go to the same partition.Step 3: Evaluate other optionsValue is not used for partitioning. Manually setting partition is possible but not scalable. Null key causes random distribution.Final Answer:Set the message key to the customer ID, so Kafka partitions messages by key hash. -> Option DQuick 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 partitioningManually assigning partitions unnecessarilyRelying on null keys for grouping
Master "Producers" in Kafka9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Kafka Quizzes Kafka Basics and Event Streaming - Kafka installation and setup - Quiz 14medium Kafka Cluster Architecture - Leader election - Quiz 4medium Kafka Cluster Architecture - Broker nodes - Quiz 4medium Kafka Cluster Architecture - Replication factor - Quiz 4medium Producers - Acknowledgment modes (acks=0, 1, all) - Quiz 15hard Producers - Batching and linger configuration - Quiz 1easy Producers - Batching and linger configuration - Quiz 4medium Producers - Compression (gzip, snappy, lz4) - Quiz 2easy Topics and Partitions - Partition ordering guarantees - Quiz 8hard Topics and Partitions - Why topics organize messages - Quiz 14medium