Kafka Acknowledgment
Kafka Commit
Kafka Messaging
Distributed Systems
Stream Processing

Kafka acknowledgment (acks) vs offset commit: what's the difference?

Codemia Knowledge Hub ·

Acknowledgment and commit sit on opposite sides of Kafka. Acknowledgment (acks) is a producer setting that controls how many brokers must confirm a write before the send counts as successful, trading latency for durability. A commit is a consumer action that records the offset it has processed up to, so a replacement consumer knows where to resume after a failure.

Producer acknowledgments: acks=0, 1 and all

When a producer sends a message, it chooses how much acknowledgment it needs from the brokers:

  • acks=0: the producer does not wait for any acknowledgment. Lowest latency, highest risk of data loss.
  • acks=1 (the "leader ack"): the producer is acknowledged as soon as the leader replica has the message. A balance between latency and reliability.
  • acks=all (or acks=-1): every in-sync replica must acknowledge. Higher durability at the cost of higher latency.

A producer configuration using acks=all:

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

The producer waits for all in-sync replicas, increasing reliability at some cost to performance.

Consumer offset commits: automatic or manual

A consumer tracks which messages it has processed by committing offsets. The committed offset tells Kafka how far the group has consumed, so after a consumer failure the new instance starts from there.

  • Automatic commit: set enable.auto.commit to true and Kafka commits offsets every auto.commit.interval.ms.
  • Manual commit: gives you control over when a message counts as processed.
    • commitSync() commits the latest offset returned by poll() and blocks until the commit completes.
    • commitAsync() commits asynchronously without waiting for the broker's response.

A consumer set up for manual commits:

java
1Properties props = new Properties();
2props.put("bootstrap.servers", "localhost:9092");
3props.put("group.id", "test");
4props.put("enable.auto.commit", "false");
5props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
6props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
7
8try (KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props)) {
9    consumer.subscribe(List.of("test-topic"));
10    while (true) {
11        ConsumerRecords<String, String> records = consumer.poll(Duration.ofMillis(100));
12        for (ConsumerRecord<String, String> record : records) {
13            processRecord(record);
14        }
15        consumer.commitSync();
16    }
17}

Acknowledgment vs commit side by side

FeatureAcknowledgmentCommit
Relevant toProducersConsumers
PurposeEnsures message delivery reliabilityManages message consumption state
Settingsacks=0, acks=1, acks=allAutomatic (enable.auto.commit=true), Manual (commitSync(), commitAsync())
ImpactAffects data reliability and latencyEnsures messages are not reprocessed
ConfigurationProducer settingsConsumer settings

Whether you prioritize speed, durability or a balance of both decides how you configure each side.


Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design