When Kafka send acknowledgement if acksall and all replicas are healthy?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Understanding Kafka Acknowledgments with acks=all
Apache Kafka is a distributed streaming platform that is widely acclaimed for its high-throughput, fault-tolerant, and scalable architecture. One of the essential components that make Kafka reliable is its acknowledgment mechanism, allowing producers to receive confirmation that messages have been successfully replicated across multiple nodes in a Kafka cluster. This article delves into Kafka's acknowledgment settings, focusing on the acks=all configuration, especially when all replicas are healthy.
Kafka Acknowledgment Mechanism Overview
When a Kafka producer sends a message to a broker, it awaits an acknowledgment to ensure the message is successfully written. The acknowledgment setting determines the durability and availability trade-offs for message delivery. Kafka provides three primary types of acknowledgments:
acks=0: The producer does not wait for any acknowledgment from the broker. This provides the highest throughput but risks data loss.acks=1: The leader node sends an acknowledgment once it writes the message to its local log. This ensures basic message durability but doesn't account for replica failures.acks=all: The leader waits for all replicas to acknowledge before sending an acknowledgment to the producer. This ensures maximum durability and fault-tolerance.
How acks=all Works
When the acks=all setting is used, the producer requires confirmation from all in-sync replicas (ISRs) for a message to be acknowledged. This setup provides a higher guarantee that the message will not be lost, even in the event of server or network failures.
Here's a step-by-step breakdown of the acks=all mechanism:
- Message Sent: The producer sends a message to the leader replica of a partition.
- ISR Communication: The leader replica writes the message to its local log and communicates with all other replicas in the ISR.
- Replica Acknowledgment: Each ISR member, upon writing the message to its local log, sends an acknowledgment back to the leader.
- Producer Acknowledgment: Once the leader receives acknowledgments from all ISRs, it sends a final acknowledgment to the producer.
- Message Commit: The message is now considered committed and fully durable against node failures.
Technical Explanation of ISRs
In Kafka, an ISR is a dynamic set of broker nodes that are fully synchronized with the leader replica. For a replica to be part of the ISR, it must:
- Stay in-sync with the leader by replicating messages in real-time.
- Report its status to ZooKeeper, which tracks broker states and ISR membership.
The list of ISRs can change dynamically. For a partition with replication.factor=N, the ISR size could vary between 1 (only the leader) to N (all replicas in-sync). With an acks=all configuration, the key requirement is that the message must be written across all ISRs.
Example Scenario
Suppose there's a Kafka topic with a partition configured with a replication factor of 3. The following illustrates the functioning of acks=all:
- Producers: A producer sends a message to the leader node.
- Replicas:
- Leader Node: Writes the message to its log.
- Replica 1 & 2: Both in-sync replicas immediately replicate the message.
- Replication Confirmation:
- Replica 1 & 2 send acknowledgment to the leader after writing the message.
- Producer Acknowledgment:
- Leader sends acknowledgment to the producer upon receiving confirmations from all in-sync replicas.
This mechanism guarantees that even if one of the replicas crashes after acknowledging but before committing (appending the message to its log), the data will not be lost.
Key Considerations
When opting for acks=all, consider the following:
- Latency vs. Durability: While you gain maximum durability, this setting might introduce additional latency since acknowledgments depend on all ISRs.
- Cluster Configuration: Optimal configurations of ISR, such as sufficient hardware and network capacity, are essential to avoid performance bottlenecks.
- Failure Handling: Be prepared to handle scenarios where ISR shrinks due to node failures. This can impact the acknowledgment process and result in temporary stalls.
Summary Table
| Ack Level | Description | Durability | Latency | Typical Use Case |
acks=0 | No ack needed Right after send | Low | Low | Logging, non-critical data |
acks=1 | Ack from leader after write | Medium | Medium | When balancing speed and safety |
acks=all | Ack from all ISRs before send | High | High | Critical data requiring durability |
Conclusion
The acks=all setting in Kafka serves as a cornerstone for applications requiring high data durability and fault tolerance. By waiting for acknowledgments from all in-sync replicas before confirming message delivery to the producer, acks=all ensures that data is safely stored across the distributed system. However, this comes at the cost of increased latency, making it crucial to balance application needs between speed and reliability.
Understanding these settings allows you to make informed decisions that align with your specific data handling requirements in a Kafka cluster.

