Skip to content

Kafka Broker Properties

Broker Properties in KafkaπŸ”—

broker.idπŸ”—

image

listenersπŸ”—

image

Example Config

# The address the socket server listens on. If not configured, the host name will be equal to the value of
# java.net.InetAddress.getCanonicalHostName(), with PLAINTEXT listener name, and port 9092.
#   FORMAT:
#     listeners = listener_name://host_name:port
#   EXAMPLE:
#     listeners = PLAINTEXT://your.host.name:9092
listeners=PLAINTEXT://localhost:9092

# Name of listener used for communication between brokers.
inter.broker.listener.name=PLAINTEXT

# Listener name, hostname and port the broker will advertise to clients.
# If not set, it uses the value for "listeners".
advertised.listeners=PLAINTEXT://localhost:9092

# A comma-separated list of the names of the listeners used by the controller.
# This is required if running in KRaft mode. On a node with `process.roles=broker`, only the first listed listener will be used by the broker.
controller.listener.names=CONTROLLER

# Maps listener names to security protocols, the default is for them to be the same. See the config documentation for more details
listener.security.protocol.map=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL

zookeeper.connectπŸ”—

image

log.dirsπŸ”—

image

num.recovery.thread.per.data.dirπŸ”—

image

Alright, let’s simplify this πŸ‘‡


πŸ“ What’s happening?πŸ”—

  • Kafka stores messages on disk in log segments (files).
  • When a broker starts or shuts down, it needs to open, check, or close all these log files.
  • To do this work, Kafka uses a pool of threads.

πŸ”‘ Where threads are used:πŸ”—

  1. Normal startup β†’ open each partition’s log files.
  2. Startup after a crash β†’ carefully check + truncate log files (takes longer).
  3. Shutdown β†’ close log files properly.

βš™οΈ Default settingπŸ”—

  • By default, Kafka uses 1 thread per log directory.
  • Example: if you have 3 log directories β†’ 3 threads total.

πŸš€ Why increase threads?πŸ”—

  • If you have many partitions and a broker crashed, recovery can take hours with just 1 thread per directory.
  • Increasing threads allows parallel recovery β†’ much faster startup.

πŸ“Œ Important noteπŸ”—

The config is called:

num.recovery.threads.per.data.dir
  • If you set it to 8 and you have 3 log.dirs, total = 8 Γ— 3 = 24 threads.
  • More threads β†’ faster startup/recovery.

πŸ‘‰ Layman analogy: Imagine you have 10,000 books (partitions) to put back on shelves after a storm (broker crash).

  • With 1 librarian per shelf (default), it takes hours.
  • With 8 librarians per shelf (more threads), all books are sorted much faster.

Why Truncate Log Segments?πŸ”—

Great question πŸ‘ Let’s break it down simply.


πŸ“ Why truncation is needed after a crashπŸ”—

  • Kafka writes data to disk in log segments.
  • Each segment has an ordered sequence of messages.
  • When a broker crashes (power cut, OOM, kill -9, etc.), some data may have been partially written (corrupted, incomplete).

πŸ”Ž What happens after restartπŸ”—

  1. Kafka reopens the log files.
  2. It checks the last segment for incomplete or corrupted records.
  3. If it finds bad records at the end of the file β†’ it truncates (cuts off) the broken part so only valid data remains.

βœ… Why this is importantπŸ”—

  • Ensures data consistency: no half-written messages are exposed to consumers.
  • Keeps the log index aligned with the actual data.
  • Avoids strange errors like β€œmessage length mismatch” or β€œinvalid checksum.”

πŸ“Œ ExampleπŸ”—

Imagine writing messages to a notebook:

Page 1: OK
Page 2: OK
Page 3: crash halfway through sentence...

When you reopen, Kafka erases the half-written sentence on Page 3, so the notebook only contains complete entries.


πŸ”’ Safety netπŸ”—

  • Kafka only truncates data that wasn’t fully acknowledged (not committed).
  • So producers/consumers won’t lose confirmed messages β€” only the garbage left behind by the crash.

πŸ‘‰ In short: Truncation after a crash = clean up the mess at the end of the log so the broker can continue safely.

auto.create.topics.enableπŸ”—

image

auto.leader.rebalance.enableπŸ”—

image

delete.topic.enableπŸ”—

image