Skip to content

AxonOps — AI-Native Control Plane for Open Source Data Platforms

Kafka Producer Configuration

This document provides a comprehensive reference for all Kafka producer configuration options, organized by functional area.


These settings must be specified for every producer.

ConfigurationTypeDescription
bootstrap.serverslistComma-separated list of host:port pairs for initial connection
key.serializerclassSerializer class for record keys
value.serializerclassSerializer class for record values
bootstrap.servers=kafka1:9092,kafka2:9092,kafka3:9092
key.serializer=org.apache.kafka.common.serialization.StringSerializer
value.serializer=org.apache.kafka.common.serialization.StringSerializer

Settings that control delivery guarantees and durability.

ConfigurationDefaultRangeDescription
acksall0, 1, allNumber of acknowledgments required
ValueBehavior
0Producer does not wait for acknowledgment
1Leader writes to local log before acknowledging
all / -1Leader waits for full ISR acknowledgment
ConfigurationDefaultRangeDescription
retries2147483647≥ 0Number of retry attempts for failed sends
retry.backoff.ms100≥ 0Time between retry attempts
retry.backoff.max.ms1000≥ 0Maximum retry backoff
delivery.timeout.ms120000≥ 0Upper bound on time to report success/failure
Retry backoff sequence bounded by delivery.timeout.msRetry backoff sequence bounded by delivery.timeout.msRetry TimingFirst SendRetry 1(+100ms)Retry 2(+200ms)Retry 3(+400ms)...Timeout(delivery.timeout.ms)Exponential backoffup to retry.backoff.max.msfailfailfailfailexpire
ConfigurationDefaultDescription
enable.idempotencetrue (3.0+)Enable idempotent producer
transactional.idnullUnique identifier for transactional producer
transaction.timeout.ms60000Transaction timeout

Idempotence Requirements

When enable.idempotence=true:

  • acks must be all
  • retries must be > 0
  • max.in.flight.requests.per.connection must be ≤ 5

Settings that affect throughput and latency.

ConfigurationDefaultRangeDescription
batch.size16384≥ 0Maximum batch size in bytes
linger.ms0≥ 0Time to wait for batch to fill
buffer.memory33554432≥ 0Total memory for buffering
max.block.ms60000≥ 0Time to block when buffer full
Batch send triggered by batch.size or linger.msBatch send triggered by batch.size or linger.msBatch TriggersBatch Ready Whenbatch.size bytes accumulatedORlinger.ms elapsedWhichever occurs firsttriggers batch send
ConfigurationDefaultRangeDescription
max.in.flight.requests.per.connection5≥ 1Max unacknowledged requests per connection
max.request.size1048576≥ 0Maximum size of a request
request.timeout.ms30000≥ 0Time to wait for request response
ConfigurationDefaultRangeDescription
send.buffer.bytes131072≥ -1TCP send buffer size (-1 = OS default)
receive.buffer.bytes32768≥ -1TCP receive buffer size (-1 = OS default)
connections.max.idle.ms540000≥ 0Close idle connections after this time
reconnect.backoff.ms50≥ 0Initial reconnection backoff
reconnect.backoff.max.ms1000≥ 0Maximum reconnection backoff

ConfigurationDefaultOptionsDescription
compression.typenonenone, gzip, snappy, lz4, zstdCompression codec
TypeCompression RatioCPU UsageLatency Impact
none1.0xNoneNone
gzip~0.3-0.5xHighModerate
snappy~0.5-0.7xLowLow
lz4~0.5-0.7xLowLowest
zstd~0.4-0.6xMediumLow

Compression ratios are workload-dependent and should be validated with representative data.


ConfigurationDefaultDescription
partitioner.classDefaultPartitionerPartitioner implementation
partitioner.ignore.keysfalseIgnore keys for partitioning (sticky only)
partitioner.adaptive.partitioning.enabletrueEnable adaptive partitioning
partitioner.availability.timeout.ms0Timeout for partition availability check
Default partitioner behavior by key and Kafka versionDefault partitioner behavior by key and Kafka versionKey is null?yesnoKafka 2.4+?yesnoStay on partitionuntil batch fullSticky PartitioningRound-robinmurmur2(key) mod partitions

ConfigurationDefaultDescription
key.serializer-Key serializer class (required)
value.serializer-Value serializer class (required)
SerializerClassUse Case
Stringorg.apache.kafka.common.serialization.StringSerializerText data
Bytesorg.apache.kafka.common.serialization.ByteArraySerializerBinary data
Integerorg.apache.kafka.common.serialization.IntegerSerializerInteger keys
Longorg.apache.kafka.common.serialization.LongSerializerLong keys
JSONCustom or libraryStructured data
Avroio.confluent.kafka.serializers.KafkaAvroSerializerSchema Registry
Protobufio.confluent.kafka.serializers.protobuf.KafkaProtobufSerializerSchema Registry

ConfigurationDefaultDescription
security.protocolPLAINTEXTProtocol: PLAINTEXT, SSL, SASL_PLAINTEXT, SASL_SSL
ssl.truststore.location-Truststore file path
ssl.truststore.password-Truststore password
ssl.keystore.location-Keystore file path
ssl.keystore.password-Keystore password
ssl.key.password-Private key password
ssl.endpoint.identification.algorithmhttpsHostname verification algorithm
ConfigurationDefaultDescription
sasl.mechanismGSSAPISASL mechanism: PLAIN, SCRAM-SHA-256, SCRAM-SHA-512, GSSAPI, OAUTHBEARER
sasl.jaas.config-JAAS configuration
sasl.client.callback.handler.class-Callback handler class
sasl.kerberos.service.name-Kerberos service name
# SASL/SCRAM example
security.protocol=SASL_SSL
sasl.mechanism=SCRAM-SHA-256
sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required \
username="producer" \
password="secret";

ConfigurationDefaultDescription
interceptor.classes-Comma-separated list of interceptor classes
public class MetricsInterceptor implements ProducerInterceptor<String, String> {
@Override
public ProducerRecord<String, String> onSend(ProducerRecord<String, String> record) {
// Add timestamp header, track metrics
record.headers().add("send_time",
Long.toString(System.currentTimeMillis()).getBytes());
return record;
}
@Override
public void onAcknowledgement(RecordMetadata metadata, Exception exception) {
// Track delivery metrics
}
}

ConfigurationDefaultRangeDescription
metadata.max.age.ms300000≥ 0Max age of cached metadata
metadata.max.idle.ms300000≥ 5000Remove metadata for unused topics

ConfigurationDefaultDescription
client.id-Client identifier for logging and metrics
metric.reporters-Comma-separated list of metric reporter classes
metrics.num.samples2Number of samples for metrics
metrics.sample.window.ms30000Metrics sample window
metrics.recording.levelINFOMetrics recording level: INFO, DEBUG

# Minimize latency
acks=1
linger.ms=0
batch.size=16384
compression.type=lz4
max.in.flight.requests.per.connection=5
# Maximize throughput
acks=all
linger.ms=50
batch.size=131072
buffer.memory=67108864
compression.type=zstd
max.in.flight.requests.per.connection=5
# Maximum durability
acks=all
enable.idempotence=true
retries=2147483647
delivery.timeout.ms=300000
max.in.flight.requests.per.connection=5
# Exactly-once semantics
acks=all
enable.idempotence=true
transactional.id=my-app-instance-1
transaction.timeout.ms=60000
max.in.flight.requests.per.connection=5

CheckRequirement
Idempotenceacks=all, retries > 0, max.in.flight <= 5
Transactionsenable.idempotence=true, transactional.id set
Orderingmax.in.flight.requests.per.connection=1 OR enable.idempotence=true
// Configuration validation example
Properties props = new Properties();
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "kafka:9092");
props.put(ProducerConfig.ENABLE_IDEMPOTENCE_CONFIG, true);
// Validate before creating producer
try {
new KafkaProducer<>(props);
} catch (ConfigException e) {
log.error("Invalid configuration: {}", e.getMessage());
}