0
0
Kafkadevops~5 mins

Acknowledgment modes (acks=0, 1, all) in Kafka - Commands & Configuration

Choose your learning style9 modes available
Introduction
When sending messages to Kafka, the producer needs to know if the message was received successfully. Acknowledgment modes control how many Kafka servers must confirm the message before the producer considers it sent. This helps balance speed and safety.
When you want the fastest message sending without waiting for confirmation.
When you want a balance between speed and message delivery guarantee.
When you want the highest safety ensuring all servers have the message.
When you want to avoid losing messages even if some servers fail.
When you want to tune Kafka producer behavior for your application's needs.
Commands
Start a Kafka producer that sends messages without waiting for any acknowledgment from the server. This is the fastest mode but may lose messages if the server fails.
Terminal
kafka-console-producer --broker-list localhost:9092 --topic example-topic --producer-property acks=0
Expected OutputExpected
>
acks=0 - No acknowledgment required from Kafka brokers.
Start a Kafka producer that waits for acknowledgment from the leader broker only. This balances speed and reliability.
Terminal
kafka-console-producer --broker-list localhost:9092 --topic example-topic --producer-property acks=1
Expected OutputExpected
>
acks=1 - Wait for leader broker acknowledgment.
Start a Kafka producer that waits for acknowledgment from all in-sync replicas. This is the safest mode but slower.
Terminal
kafka-console-producer --broker-list localhost:9092 --topic example-topic --producer-property acks=all
Expected OutputExpected
>
acks=all - Wait for all in-sync replicas to acknowledge.
Consume the first 3 messages from the topic to verify messages were sent successfully.
Terminal
kafka-console-consumer --bootstrap-server localhost:9092 --topic example-topic --from-beginning --max-messages 3
Expected OutputExpected
message1 message2 message3
--from-beginning - Read messages from the start of the topic.
--max-messages 3 - Stop after reading 3 messages.
Key Concept

If you remember nothing else, remember: acks control how many Kafka servers confirm a message before the producer moves on, balancing speed and safety.

Common Mistakes
Setting acks=0 when message loss is unacceptable.
Messages may be lost if the broker fails before storing them.
Use acks=1 or acks=all to ensure message delivery.
Using acks=all without ensuring enough in-sync replicas.
Producer may wait indefinitely if replicas are not available.
Ensure your Kafka cluster has enough in-sync replicas before using acks=all.
Not verifying messages after sending with different acks settings.
You may not notice message loss or delays.
Use kafka-console-consumer to check messages were received.
Summary
Use acks=0 for fastest sending but no delivery guarantee.
Use acks=1 to wait for leader broker confirmation balancing speed and safety.
Use acks=all to wait for all in-sync replicas for highest safety.
Verify messages with kafka-console-consumer after producing.