Kafka Producer Acknowledgements (acks)
Kafka producer acknowledgements, configured with the acks setting, decide when a producer treats a write as successful. They are the main switch between speed and durability: with the wrong value, a perfectly healthy cluster can still lose messages after a single broker failure.
This tutorial explains the three acks values, how they work together with in-sync replicas (ISR) and min.insync.replicas, what changed in recent Kafka versions, and how to configure acknowledgements in plain Java and in Spring Boot.
1. What Is a Producer Acknowledgement?
A producer acknowledgement is the response a partition leader sends back to the producer after a write. The acks property tells the producer how many replicas must have stored the record before that response counts as success:
| Value | The producer waits for | Can an acknowledged record be lost? |
|---|---|---|
acks=0 | Nothing. The record is considered sent once it is in the socket buffer. | Yes, even without any failure being reported. |
acks=1 | The leader writing the record to its own log. | Yes, if the leader fails before followers copy it. |
acks=all (or -1) | Every replica currently in the ISR. | No, as long as at least one in-sync replica survives. |
Since Kafka 3.0 the default is acks=all, together with the idempotent producer (enable.idempotence=true).
acks controls producer-side durability: the number of in-sync replica acknowledgements the leader must collect before it confirms a produce request.2. Why Acknowledgements Matter
Kafka replicates every partition to several brokers, but replication happens after the leader writes the record. The acknowledgement setting decides whether the producer waits for that replication. Without waiting, a leader crash right after the write can remove records the application believes were saved, such as payments or orders. With waiting, each write costs a little more latency, because the slowest in-sync follower must fetch the record first.
3. How Acknowledgements Work
For a topic with replication factor 3, the leader on broker 1 receives a batch, appends it to its log and then answers according to acks. Followers on brokers 2 and 3 continuously fetch new data from the leader; they do not receive pushes.
acks value. Only acks=all waits until the in-sync followers have fetched the batch.3.1 What acks=all really waits for
acks=all waits for all replicas currently in the ISR, not for all assigned replicas. If two followers fall out of the ISR, the ISR is only the leader, and acks=all would succeed after a single write. The broker or topic setting min.insync.replicas closes that gap: when the ISR is smaller than this number, the leader rejects acks=all writes with NotEnoughReplicasException, which the producer retries until delivery.timeout.ms expires.
3.2 When records become visible to consumers
Acknowledgement and visibility are separate. Consumers can read a record only after it is below the partition's high watermark. In Kafka 4.x the documentation states that, regardless of the acks value, records become visible only after they are replicated to all in-sync replicas and the min.insync.replicas condition is met. So acks=1 makes the producer faster, not the data visible sooner.
4. Configuration
| Property | Where | Default (Kafka 4.4) | Purpose |
|---|---|---|---|
acks | Producer | all | Acknowledgements required: 0, 1 or all |
min.insync.replicas | Topic or broker | 1 | Minimum ISR size for acks=all writes |
enable.idempotence | Producer | true | Prevents duplicates from retries; requires acks=all |
delivery.timeout.ms | Producer | 120000 (2 minutes) | Upper bound to report success or failure, including retries |
request.timeout.ms | Producer | 30000 | How long to wait for one broker response |
replication.factor | Topic | broker default | Number of copies of each partition |
acks=1 and do not set enable.idempotence, the producer silently disables idempotence. If you set enable.idempotence=true together with acks=1, the producer fails at startup with a ConfigException.For durable topics, combine acks=all with replication factor 3 and min.insync.replicas=2. The topic then accepts writes with one broker down and never confirms a write that exists on only one broker.
kafka-topics.sh --bootstrap-server localhost:9092 --create --topic payments \
--partitions 6 --replication-factor 3 --config min.insync.replicas=2
5. Java Example: Durable Producer with Callbacks
The producer below uses explicit durable settings and checks the result of every send. The callback is the only place where a failed write becomes visible to your code.
package com.javabytechie.kafka;
import java.util.Properties;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.common.serialization.StringSerializer;
public class PaymentEventProducer {
public static void main(String[] args) {
Properties props = new Properties();
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
props.put(ProducerConfig.ACKS_CONFIG, "all"); // wait for all in-sync replicas
props.put(ProducerConfig.ENABLE_IDEMPOTENCE_CONFIG, true); // safe retries, no duplicates
props.put(ProducerConfig.DELIVERY_TIMEOUT_MS_CONFIG, 120_000); // give up after 2 minutes
try (KafkaProducer<String, String> producer = new KafkaProducer<>(props)) {
ProducerRecord<String, String> record =
new ProducerRecord<>("payments", "PAY-1001", "{\"amount\":250.00,\"currency\":\"EUR\"}");
producer.send(record, (metadata, exception) -> {
if (exception != null) {
// retries are exhausted or the error is not retriable
System.err.println("Payment event not stored: " + exception.getMessage());
} else {
System.out.printf("Stored in %s-%d at offset %d%n",
metadata.topic(), metadata.partition(), metadata.offset());
}
});
} // close() flushes buffered records and waits for their callbacks
}
}
Running it against a three-broker cluster with the payments topic above prints a line such as:
Stored in payments-1 at offset 0
The key PAY-1001 always hashes to partition 1 of the six partitions, and this was the first record written there. If two of the three brokers are down, the ISR is smaller than min.insync.replicas: the leader keeps rejecting the write with the retriable NotEnoughReplicasException, and after delivery.timeout.ms the callback receives a TimeoutException and prints Payment event not stored: .... The record is reported as failed instead of being lost silently.
5.1 Spring Boot configuration
With Spring Boot (4.2, which manages Spring for Apache Kafka 4.2 and Kafka clients 4.4), the same settings go into application.yml, and KafkaTemplate.send() returns a CompletableFuture<SendResult>:
spring:
kafka:
bootstrap-servers: localhost:9092
producer:
acks: all
properties:
enable.idempotence: true
delivery.timeout.ms: 120000
package com.javabytechie.kafka;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;
@Service
public class PaymentPublisher {
private final KafkaTemplate<String, String> kafkaTemplate;
public PaymentPublisher(KafkaTemplate<String, String> kafkaTemplate) {
this.kafkaTemplate = kafkaTemplate;
}
public void publish(String paymentId, String json) {
kafkaTemplate.send("payments", paymentId, json)
.whenComplete((result, ex) -> {
if (ex != null) {
// store the event for a later retry, or raise an alert
System.err.println("Failed to publish " + paymentId + ": " + ex.getMessage());
}
});
}
}
6. Choosing acks for Real Workloads
- Payments, orders, account changes:
acks=all, replication factor 3,min.insync.replicas=2. Losing one acknowledged event is not acceptable. - Clickstream and application logs:
acks=1can be acceptable when an occasional loss during a broker failure is tolerable and throughput matters more. - High-volume metrics or IoT telemetry:
acks=0only when newer readings replace older ones and losses do not matter.
7. Advantages and Limitations
| acks | Advantages | Limitations |
|---|---|---|
0 | Lowest latency, highest throughput | Silent data loss, no retries, offset is always -1 |
1 | Fast, survives follower failures | Loses data if the leader fails before replication; idempotence off |
all | No loss of acknowledged data while one ISR member survives; works with idempotence and transactions | Slightly higher latency; writes stop when the ISR is below min.insync.replicas |
8. Common Mistakes
acks=allwithmin.insync.replicas=1: the leader alone can satisfy the request after followers drop out, so a single failure can still lose data.- Setting
min.insync.replicasequal to the replication factor: with RF 3 and min ISR 3, any single broker restart blocks all writes. - Ignoring send results:
send()is asynchronous; without a callback or checking the future, failures after retries are lost unnoticed. - Lowering acks for speed first: batching (
linger.ms,batch.size) and compression usually give more throughput than weaker durability.
9. Best Practices
- Keep the defaults (
acks=all, idempotence on) for business data and setmin.insync.replicas=2on topics with RF 3. - Spread replicas across availability zones with
broker.rack, so one zone failure cannot remove the whole ISR. - Handle failures explicitly in callbacks: log, store for retry, or fail the request.
- Monitor
UnderMinIsrPartitionCount: any value above zero meansacks=allproducers are failing for those partitions.
10. Conclusion
acks decides when a producer trusts a write. acks=all waits for every in-sync replica and, combined with replication factor 3 and min.insync.replicas=2, survives a broker failure without losing acknowledged data; it is also required for idempotent and transactional producers. Use acks=1 or acks=0 only for data you can afford to lose, and always check send results. Continue with Kafka Producer Retries to see what happens after a failed acknowledgement, and Kafka ISR for how the in-sync set changes.
11. References
Kafka Producer Acknowledgement Interview Questions and Answers
Common interview questions on Kafka Producer Acknowledgement, from basic to scenario-based, with short answers you can explain in your own words.
Basic questions
Q. What are the possible values of acks, and what does each guarantee?
Answer: acks=0 does not wait for any response, so records can be lost without an error. acks=1 waits until the leader has written the record, so it is lost if the leader fails before followers copy it. acks=all (same as -1) waits for every in-sync replica and guarantees no loss of acknowledged records while at least one in-sync replica survives. It is the default since Kafka 3.0.
Q. Does acks=all mean all replicas of the partition must acknowledge?
Answer: No. It means all replicas currently in the ISR. If followers have fallen out of the ISR, fewer replicas acknowledge, possibly only the leader. That is why acks=all must be combined with min.insync.replicas, typically 2 for replication factor 3.
Intermediate questions
Q. How does the acks setting affect latency and throughput?
Answer: With acks=0 the producer does not wait at all, so latency is lowest. With acks=1 it waits for the leader's local write. With acks=all it also waits until all in-sync followers have fetched the batch, so latency depends on the slowest ISR member. Throughput can stay high with any setting, because the producer keeps up to five requests in flight per connection and batches records; the main cost of acks=all is added latency per batch.
Q. Why does the idempotent producer require acks=all?
Answer: Idempotence relies on the broker tracking producer ID and sequence numbers for the partition so it can reject duplicate retries. With acks=1, a leader failover could lose records that were acknowledged, and the new leader's sequence state would not match what the producer thinks was written. Requiring acks=all ensures acknowledged batches exist on all in-sync replicas, so sequence tracking stays correct across leader changes.
Tricky and scenario questions
Q. Does acks=1 make records available to consumers faster?
Answer: Not in current Kafka versions. Consumers only read up to the high watermark, which advances when all in-sync replicas have the record, and the Kafka 4.4 documentation states that records are not visible until they are replicated to all in-sync replicas and min.insync.replicas is met, regardless of acks. acks=1 only shortens how long the producer waits.
Q. One application sends payment events and debug logs. Would you use the same acks setting for both?
Answer: Not necessarily. acks is a producer setting, so an application that needs different guarantees uses two producers: one with acks=all and idempotence for payments, written to a topic with replication factor 3 and min.insync.replicas=2, and one with acks=1 and compression for high-volume logs, where losing a few records during a leader failover is acceptable. Mixing both in one producer forces the weaker or the slower setting on everything.