Kafka Acks 0 vs 1 vs all: Key Differences and Usage
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.
| Feature | acks=0 | acks=1 | acks=all |
|---|---|---|---|
| Acknowledgment Required | None | Leader only | All in-sync replicas |
| Message Durability | No guarantee | Moderate | Strong guarantee |
| Latency | Lowest | Medium | Highest |
| Risk of Data Loss | High | Medium | Low |
| Use Case | High throughput, no durability | Balanced reliability | Critical 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.
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();
acks=all Equivalent
Example Kafka producer configuration using acks=all to ensure all in-sync replicas confirm the message.
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();
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.acks=0 for high throughput with risk, acks=1 for balanced needs, and acks=all for critical data safety.