Integration / Apache Kafka Interview questions
What is a Kafka producer?
A producer is the client application that publishes (writes) records to one or more Kafka topics. It's responsible for serializing the record's key and value, deciding (directly or via a partitioner) which partition a record goes to, batching records for efficiency, and handling the broker's acknowledgment according to its configured durability guarantee.
Properties props = new Properties(); props.put("bootstrap.servers", "localhost:9092"); props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer"); props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer"); KafkaProducer<String, String> producer = new KafkaProducer<>(props); producer.send(new ProducerRecord<>("orders", "order-123", "{\"status\":\"created\"}")); producer.close();
A key producer setting is acks, which controls how much durability the producer waits for before considering a send successful — acks=0 (fire and forget), acks=1 (leader only), or acks=all (the full in-sync replica set), trading off latency against the risk of data loss on a broker failure.
More Related questions...