00:00

Kafka Producer Acknowledgements (acks)

Last updated:

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:

ValueThe producer waits forCan an acknowledged record be lost?
acks=0Nothing. The record is considered sent once it is in the socket buffer.Yes, even without any failure being reported.
acks=1The 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).

Definition: 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.

When the leader acknowledges a write for each acks valueA producer sends a batch to the partition leader on broker 1. Followers on brokers 2 and 3 fetch the batch. With acks=0 the producer does not wait. With acks=1 the leader replies after its own write. With acks=all the leader replies only after every in-sync replica has the batch, and the write is rejected if the ISR is smaller than min.insync.replicas. Produceracks=? Broker 1: leader1. append to local log Broker 2: followerin ISR Broker 3: followerin ISR produce 2. fetch 2. fetch 3. response acks=0no response awaited acks=1after step 1 acks=allafter step 2 on every ISR member acks=all is rejected with NotEnoughReplicas when the ISR is smaller than min.insync.replicas
The response is sent at a different point for each 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

PropertyWhereDefault (Kafka 4.4)Purpose
acksProducerallAcknowledgements required: 0, 1 or all
min.insync.replicasTopic or broker1Minimum ISR size for acks=all writes
enable.idempotenceProducertruePrevents duplicates from retries; requires acks=all
delivery.timeout.msProducer120000 (2 minutes)Upper bound to report success or failure, including retries
request.timeout.msProducer30000How long to wait for one broker response
replication.factorTopicbroker defaultNumber of copies of each partition
Watch out: If you set 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.

Terminal
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.

PaymentEventProducer.java
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:

Output
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>:

application.yml
spring:
  kafka:
    bootstrap-servers: localhost:9092
    producer:
      acks: all
      properties:
        enable.idempotence: true
        delivery.timeout.ms: 120000
PaymentPublisher.java
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=1 can be acceptable when an occasional loss during a broker failure is tolerable and throughput matters more.
  • High-volume metrics or IoT telemetry: acks=0 only when newer readings replace older ones and losses do not matter.

7. Advantages and Limitations

acksAdvantagesLimitations
0Lowest latency, highest throughputSilent data loss, no retries, offset is always -1
1Fast, survives follower failuresLoses data if the leader fails before replication; idempotence off
allNo loss of acknowledged data while one ISR member survives; works with idempotence and transactionsSlightly higher latency; writes stop when the ISR is below min.insync.replicas

8. Common Mistakes

  • acks=all with min.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.replicas equal 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 set min.insync.replicas=2 on 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 means acks=all producers 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