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

You can think of this as explaining β€œhow Kafka knows which door to use when someone wants to talk to it.”


🏠 1. Kafka is like a house with doorsπŸ”—

Kafka brokers are like houses, and to talk to a broker (send messages, get data, etc.), you need to know which door to knock on.

Each door has:

  • A name (like β€œPLAINTEXT” or β€œSSL”)
  • A street address (hostname or IP)
  • A door number (port)

πŸšͺ 2. listeners=PLAINTEXT://localhost:9092πŸ”—

This says:

β€œOpen a door called PLAINTEXT on address localhost, port 9092.”

That means:

  • Kafka will listen on port 9092
  • It will accept plain (unencrypted) connections
  • Clients and other brokers can connect through that door.

So if a producer or consumer wants to connect, it says:

bootstrap.servers=localhost:9092

β†’ They’re knocking on that door!

Think of this as the door Kafka listens at.


πŸ—£οΈ 3. inter.broker.listener.name=PLAINTEXTπŸ”—

Kafka brokers in the same cluster talk to each other β€” they need their own β€œprivate line.”

This setting says:

β€œWhen brokers talk to each other, use the PLAINTEXT door.”

So if you have multiple brokers:

  • Broker 1, Broker 2, and Broker 3
  • They’ll all use the PLAINTEXT channel to sync data and share cluster info.

This just tells Kafka:

β€œWhich of the doors we opened should the brokers use to chat among themselves?”


πŸ“’ 4. advertised.listeners=PLAINTEXT://localhost:9092πŸ”—

Imagine you live inside your house, and you tell your friends:

β€œHey, if you want to visit me, come to localhost:9092.”

That’s what this does.

Kafka uses advertised.listeners to tell clients and other brokers β€œthis is the address you should use to reach me.”

Why this matters:πŸ”—

If Kafka runs inside Docker, Kubernetes, or the cloud, the listeners address might be something internal (like 0.0.0.0), but the advertised.listeners should be the public or reachable hostname (like my-broker.company.com).

So:

  • listeners = the actual door inside Kafka.
  • advertised.listeners = the address label you give out to the world.

🧠 5. controller.listener.names=CONTROLLERπŸ”—

Kafka needs a β€œcontroller” β€” one special broker that coordinates the cluster (decides leaders, handles elections, etc.).

This line says:

β€œThe controller will use a listener called CONTROLLER to do its work.”

In Kafka’s new mode (called KRaft mode β€” Kafka without ZooKeeper), the controller uses its own special private door (CONTROLLER) for cluster management.

You can ignore this if you’re running a simple single-node Kafka β€” it’s just for internal communication between controller nodes.


πŸ” 6. listener.security.protocol.map=...πŸ”—

Now this is like a dictionary that tells Kafka:

β€œWhat kind of security each door uses.”

Here’s what it means:

CONTROLLER:PLAINTEXT
PLAINTEXT:PLAINTEXT
SSL:SSL
SASL_PLAINTEXT:SASL_PLAINTEXT
SASL_SSL:SASL_SSL

So:

  • Door named PLAINTEXT β†’ normal unencrypted connection
  • Door named SSL β†’ encrypted HTTPS-style connection
  • Door named SASL_SSL β†’ encrypted + username/password
  • Door named CONTROLLER β†’ internal plain connection for controller traffic

Basically, this says:

β€œEach door name matches its security type.”


🎯 7. Putting it all togetherπŸ”—

Config Think of it as What it does
listeners 🏠 The doors Kafka opens Where Kafka waits for connections
inter.broker.listener.name πŸ“ž The door brokers use to talk to each other Chooses which listener for broker-to-broker communication
advertised.listeners πŸ“’ The address Kafka tells others to use How clients and brokers find this broker
controller.listener.names 🧠 The private control door Used by the controller in KRaft mode
listener.security.protocol.map πŸ—ΊοΈ The security rulebook Maps each door to its security protocol

🧩 8. Simple example storyπŸ”—

Imagine:

  • You (Kafka broker) live in a house.
  • You have a few doors:

  • β€œFront door” (PLAINTEXT) β†’ anyone can visit

  • β€œBack door” (CONTROLLER) β†’ for your best friend (controller)
  • β€œSecret door” (SSL) β†’ only for trusted people with keys

You tell your friends:

β€œUse the front door at localhost:9092 to visit me!”

That’s:

advertised.listeners=PLAINTEXT://localhost:9092

And you decide that you and your best friend (another broker) will use the same door to talk:

inter.broker.listener.name=PLAINTEXT

βœ… 9. In short β€” the β€œkid” version:πŸ”—

  • listeners β†’ Kafka opens this door to listen.
  • advertised.listeners β†’ Kafka tells everyone, β€œHey! Knock on this door.”
  • inter.broker.listener.name β†’ Brokers talk to each other through this door.
  • controller.listener.names β†’ The controller uses this door to manage the cluster.
  • listener.security.protocol.map β†’ Explains which door uses which kind of lock (security).

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