InterviewSolution
| 1. |
What is a producer in Kafka? What are the different types of Kafka producer APIs? How does Kafka producer write data to a topic containing multiple partitions? |
|
Answer» A producer publishes messages to one or more Kafka topics. The message contains information related to what topic and partition should the message be published to. There are three DIFFERENT types of producer APIs –
Kafka messages are key-value pairs. The key is used for partitioning messages being sent to the topic. When writing a message to a topic, the producer has an option to provide the message key. This key determines which partition of the topic the message goes to. If the key is not specified, then the messages are sent to partitions of the topic in round robin fashion. Note that Kafka orders messages only inside a partition, hence choosing the right partition key is an important factor in application design. |
|