Configuration best practices in Kafka - Commands & Configuration
broker.id=1 listeners=PLAINTEXT://:9092 log.dirs=/var/lib/kafka-logs num.network.threads=3 num.io.threads=8 socket.send.buffer.bytes=102400 socket.receive.buffer.bytes=102400 socket.request.max.bytes=104857600 log.retention.hours=168 log.segment.bytes=1073741824 log.retention.check.interval.ms=300000 zookeeper.connect=localhost:2181 num.partitions=3 auto.create.topics.enable=false log.cleaner.enable=true log.cleaner.threads=2 log.cleaner.dedupe.buffer.size=134217728 log.cleaner.io.max.bytes.per.second=1048576 log.cleaner.backoff.ms=15000
broker.id: Unique ID for each Kafka broker.
listeners: Network address Kafka listens on.
log.dirs: Where Kafka stores data logs.
num.network.threads and num.io.threads: Threads for handling network and disk I/O.
socket.*: Buffer sizes for network communication.
log.retention.hours: How long logs are kept before deletion.
log.segment.bytes: Size of each log file segment.
zookeeper.connect: Address of ZooKeeper managing Kafka cluster.
num.partitions: Default number of partitions per topic.
auto.create.topics.enable: Prevents automatic topic creation to avoid mistakes.
log.cleaner.*: Settings for log compaction to save space and keep latest data.
kafka-server-start.sh /opt/kafka/config/server.properties
kafka-topics.sh --bootstrap-server localhost:9092 --list--bootstrap-server - Specifies the Kafka server address to connect to.kafka-configs.sh --bootstrap-server localhost:9092 --entity-type brokers --entity-name 1 --describe
--entity-type - Defines the type of entity to describe, here a broker.--entity-name - Specifies the broker ID to show configuration for.If you remember nothing else from this pattern, remember: carefully setting Kafka's configuration file ensures reliable, secure, and efficient message streaming.
Practice
Solution
Step 1: Understand Kafka configuration goals
Kafka configs are designed to improve performance, safety, and reliability.Step 2: Evaluate each option
Only Improved speed, safety, and reliability of Kafka clusters correctly states the benefits of good Kafka configs.Final Answer:
Improved speed, safety, and reliability of Kafka clusters -> Option DQuick Check:
Kafka config benefits = Improved speed, safety, reliability [OK]
- Thinking configs generate code automatically
- Assuming configs remove need for monitoring
- Believing Kafka works offline without network
Solution
Step 1: Recall Kafka config file syntax
Kafka uses key=value pairs in properties files.Step 2: Match syntax to options
Only bootstrap.servers = localhost:9092 uses the correct key=value format.Final Answer:
bootstrap.servers = localhost:9092 -> Option AQuick Check:
Kafka config syntax = key=value [OK]
- Using colon instead of equals sign
- Using arrow symbols
- Omitting the equals sign
acks used by the producer?
acks=all retries=3 linger.ms=5
Solution
Step 1: Understand the meaning of acks=all
In Kafka, acks=all means leader waits for all replicas to confirm the message.Step 2: Check options against this meaning
"all" meaning the leader waits for all replicas to acknowledge correctly describes acks=all behavior.Final Answer:
"all" meaning the leader waits for all replicas to acknowledge -> Option AQuick Check:
acks=all means wait for all replicas [OK]
- Confusing acks=all with acks=0 or acks=1
- Thinking 'all' is invalid
- Assuming no acknowledgments are needed
log.retention.hours=168 in your Kafka broker config, but logs are not retained for 7 days as expected. What is a likely cause?Solution
Step 1: Understand retention config interaction
Kafka retention can be limited by time or size; size limit can override time.Step 2: Analyze options
Thelog.retention.bytessetting is limiting retention by size correctly identifies size limit as a possible cause.Final Answer:
The log.retention.bytes setting is limiting retention by size -> Option BQuick Check:
Retention limited by size overrides time [OK]
- Assuming retention.hours must be in minutes
- Believing Kafka ignores retention settings
- Forgetting to restart broker (not always needed)
Solution
Step 1: Understand safe config update practices
Updating one broker at a time avoids cluster downtime and data loss.Step 2: Evaluate options for safety and availability
Update configs on one broker at a time, restart it, then move to next follows the best practice of rolling updates with restarts.Final Answer:
Update configs on one broker at a time, restart it, then move to next -> Option CQuick Check:
Rolling updates = safer config changes [OK]
- Restarting all brokers simultaneously causing downtime
- Stopping entire cluster unnecessarily
- Changing configs without backups or restarts
Ready to prove it?
Pass the test and this pattern moves unknown
