Producers and Producer Settings
Harry
· 13 Sep 2026
· 1 views
Producer Basics
A producer sends records to topics. The mandatory configuration is bootstrap.servers and key/value serializers. A record carries a topic, key, value, headers and an optional timestamp.
Keys and Partitioning
Records with the same key go to the same partition, preserving per-key order - e.g., all events for user 42 land in one partition. Without a key, producers round-robin across partitions.
Config: acks
acks=all # strongest durability, wait for ISR
acks=1 # leader confirms alone
acks=0 # fire and forgetacks=all is the recommended default for production systems that cannot afford lost records.
Retries and Idempotence
retries=5
enable.idempotence=true # prevents duplicates on retry
compression.type=lz4Idempotent producers tag records so retries never duplicate precise offsets; compression lowers network bytes.
Producer Code Shape
// Java-style pseudocode
ProducerConfig acks = all; enable.idempotence = true;
producer.send(new ProducerRecord<>("orders", key, value), callback);Key Points
- Keys guarantee per-partition order.
- acks controls the durability/throughput trade.
- Idempotence removes duplicate emissions.
- Serializers drive the record format.