Skip to main content

Kafka Configurations

Broker Configurations

ConfigurationDescription
log.retention.hoursThe number of hours to keep a log file before deleting it (default is 168 hours / 7 days).
log.retention.bytesThe maximum size of the log before messages are deleted (applied per partition).
default.replication.factorThe default number of replicas created for automatically created topics.
num.partitionsThe default number of log partitions per topic if not specified at creation.
min.insync.replicasThe minimum number of replicas that must acknowledge a write for it to be considered successful (critical for durability).
auto.create.topics.enableIf true, enables automatic creation of topics when producers write to them (often set to false in production).
advertised.listenersThe hostname and port the broker advertises to clients (producers/consumers) to connect to.
log.segment.bytesThe maximum size of a single log file segment; once reached, a new segment is created.
unclean.leader.election.enableIndicates whether out-of-sync replicas can become leaders, trading data consistency for availability (default is false).

Producer Configurations

ConfigurationDescription
bootstrap.serversA list of host/port pairs to use for establishing the initial connection to the Kafka cluster.
acksDetermines how many partition replicas must acknowledge a record before the producer considers the write successful (0, 1, or all).
linger.msThe time (in milliseconds) the producer waits for more records to arrive to batch them together before sending.
batch.sizeThe maximum size (in bytes) of a batch of records sent to a partition.
compression.typeThe compression algorithm used for batches of data (e.g., gzip, snappy, lz4, zstd).
retriesThe number of times the producer will attempt to resend a message if the send fails transiently.
enable.idempotenceEnsures that messages are delivered exactly once to a partition in order, preventing duplicates.
buffer.memoryThe total bytes of memory the producer can use to buffer records waiting to be sent to the server.
max.request.sizeThe maximum size of a request in bytes; limits the size of the largest message or batch sent.
key.serializer(Required) The class used to convert the key object into bytes (e.g., StringSerializer).
value.serializer(Required) The class used to convert the value object into bytes.
max.in.flight.requests.per.connectionMax unacknowledged requests sent to a single broker; set to 1 for strict ordering (if enable.idempotence=false).
max.block.msHow long producer.send() blocks when the buffer is full or metadata is unavailable before throwing an exception.

Consumer Configurations

ConfigurationDescription
group.idA unique string that identifies the consumer group this consumer belongs to.
auto.offset.resetWhat to do when there is no initial offset in Kafka or if the current offset does not exist (earliest or latest).
enable.auto.commitIf true, the consumer's offset will be periodically committed in the background.
max.poll.recordsThe maximum number of records returned in a single call to poll().
session.timeout.msThe maximum time the broker waits for a heartbeat before considering the consumer dead and rebalancing the group.
heartbeat.interval.msThe expected time between heartbeats to the consumer coordinator (must be lower than session.timeout.ms).
fetch.min.bytesThe minimum amount of data the server should return for a fetch request (helps reduce request overhead).
isolation.levelControls how transactional messages are read (read_committed skips aborted transactions, read_uncommitted sees everything).

Common / Client Configurations

These settings apply to both Producers and Consumers (and Admin clients) to manage network connections and timeouts.

ConfigurationDescription
client.idA logical identifier string passed to the server to track the source of requests in logs and metrics.
request.timeout.msThe maximum time the client waits for a response from the broker before giving up and retrying (or failing).
receive.buffer.bytesThe size of the TCP receive buffer (SO_RCVBUF) to use when reading data.
send.buffer.bytesThe size of the TCP send buffer (SO_SNDBUF) to use when sending data.

Best Practices

Common Apache Kafka Mistakes to Avoid - YouTube

  • It's a problem to use multiple producers in a single service
  • The trade off between throughput and latency with batching
  • What is linger.ms
  • Enable compression
  • Define Producer Callbacks
  • One consumer per thread in a single service instance
  • Trogdor
  • Over Committing
  • Provide a ConsumerRebalanceListener
  • Undersized per Kafka Consumer instances