0
0
KafkaComparisonBeginner · 4 min read

Kafka Acks 0 vs 1 vs all: Key Differences and Usage

In Kafka, acks=0 means the producer sends messages without waiting for any broker acknowledgment, offering low latency but no delivery guarantee. acks=1 waits for the leader broker to confirm the write, balancing latency and reliability. acks=all waits for all in-sync replicas to confirm, ensuring maximum durability but with higher latency.
⚖️

Quick Comparison

This table summarizes the key differences between acks=0, acks=1, and acks=all in Kafka.

Featureacks=0acks=1acks=all
Acknowledgment RequiredNoneLeader onlyAll in-sync replicas
Message DurabilityNo guaranteeModerateStrong guarantee
LatencyLowestMediumHighest
Risk of Data LossHighMediumLow
Use CaseHigh throughput, no durabilityBalanced reliabilityCritical data durability
⚖️

Key Differences

acks=0 means the producer sends the message and does not wait for any acknowledgment from the Kafka broker. This results in the lowest latency but risks message loss if the broker fails before storing the message.

With acks=1, the producer waits for the leader broker to confirm the message is written to its local log. This provides a balance between speed and reliability but can still lose data if the leader crashes before replicating to followers.

acks=all (or -1) requires all in-sync replicas to acknowledge the message. This ensures the highest durability and data safety but increases latency because the producer waits for multiple confirmations.

⚖️

Code Comparison

Example Kafka producer configuration using acks=0 for fastest sending without waiting for confirmation.

java
Properties props = new Properties();
props.put("bootstrap.servers", "localhost:9092");
props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
props.put("acks", "0");

KafkaProducer<String, String> producer = new KafkaProducer<>(props);
producer.send(new ProducerRecord<>("my-topic", "key1", "message with acks=0"));
producer.close();
Output
Message sent immediately without waiting for broker acknowledgment.
↔️

acks=all Equivalent

Example Kafka producer configuration using acks=all to ensure all in-sync replicas confirm the message.

java
Properties props = new Properties();
props.put("bootstrap.servers", "localhost:9092");
props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
props.put("acks", "all");

KafkaProducer<String, String> producer = new KafkaProducer<>(props);
producer.send(new ProducerRecord<>("my-topic", "key1", "message with acks=all"));
producer.close();
Output
Message sent after all in-sync replicas acknowledge, ensuring durability.
🎯

When to Use Which

Choose acks=0 when you need the fastest throughput and can tolerate some message loss, such as in logging or metrics where occasional loss is acceptable.

Choose acks=1 for a good balance between latency and reliability, suitable for most applications where some data loss is tolerable but speed matters.

Choose acks=all when data durability is critical, such as financial transactions or important event processing, where losing messages is unacceptable despite higher latency.

Key Takeaways

acks=0 offers lowest latency but no delivery guarantee.
acks=1 waits for leader acknowledgment, balancing speed and reliability.
acks=all waits for all in-sync replicas, ensuring highest durability.
Use acks=0 for high throughput with risk, acks=1 for balanced needs, and acks=all for critical data safety.