Delivery Guarantees: acks, Idempotence, At-least-once vs Exactly-once
Oct 2026 · 6 min read
Kafka delivery guarantees are demonstrated through the built-in CLI on a local broker, with no project needed. Readers see how acks and idempotence affect the producer, why a consumer that reads without committing reads the same messages again, and how to reprocess data via offset reset.
Full code: https://github.com/Sch39/java-spring-boot
Problem
A message being "sent" and a message being "processed" are often treated as one thing, even though the two are guaranteed by different mechanisms: the producer via acks and idempotence, the consumer via when the offset is committed. As a result, duplicates or lost messages only show up in production.
Producer configs depend on each other:
acksandenable.idempotencecannot be combined freely, and a wrong combination only becomes apparent when the producer is created.Commit determines repetition: a consumer that stops before committing reads the same messages again, so processing must be ready to accept duplicates.
Outcome
Readers can:
Distinguish
acks=0,acks=1, andacks=all, and know which combinations are rejected whenenable.idempotence=true.Demonstrate at-least-once behavior: without committing, the group reads the same messages again.
Reprocess data with
--reset-offsetsand read the results fromCURRENT-OFFSETandLAG.
Implementation
Setup
Kafka is installed locally, official guide: https://kafka.apache.org/quickstart. The commands below are run from the installation folder and assume the broker is already running on localhost:9092 (KRaft, single node).
cd ~/kafka_2.13-4.3.1The topic and group names are made unique (k0102-orders, k0102-g) so they don't clash with other data. Run the blocks in order; how to delete both is in Block 10.
Command Blocks
Block 1: Creating a single-partition topic
bin/kafka-topics.sh --bootstrap-server localhost:9092 --create --topic k0102-orders --partitions 1 --replication-factor 1Created topic k0102-orders.Goal: Set up a single-partition topic so sequential offsets are easy to read.
Block 2: Producer with acks=all and idempotence
printf '%s\n' order-1 order-2 order-3 order-4 order-5 \
| bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic k0102-orders \
--command-property acks=all --command-property enable.idempotence=true
bin/kafka-get-offsets.sh --bootstrap-server localhost:9092 --topic k0102-ordersk0102-orders:0:5Goal: Send 5 messages with the producer's strongest guarantee and prove all five are stored (final offset 5).
Block 3: Producer with acks=0
printf '%s\n' order-6 \
| bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic k0102-orders \
--command-property acks=0
bin/kafka-get-offsets.sh --bootstrap-server localhost:9092 --topic k0102-ordersk0102-orders:0:6Goal: Show that acks=0 doesn't wait for broker confirmation, so the producer has no way of knowing whether the message was actually stored.
Block 4: acks=1 rejected when idempotence is active
printf '%s\n' order-7 \
| bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic k0102-orders \
--command-property acks=1 --command-property enable.idempotence=true
bin/kafka-get-offsets.sh --bootstrap-server localhost:9092 --topic k0102-ordersorg.apache.kafka.common.config.ConfigException: Must set acks to all in order to use the idempotent producer. Otherwise we cannot guarantee idempotence.
at org.apache.kafka.clients.producer.ProducerConfig.postProcessAndValidateIdempotenceConfigs(ProducerConfig.java:613)
k0102-orders:0:6Goal: Prove that idempotence requires acks=all, and the message was not sent at all (final offset stays at 6).
Block 5: Consumer reads without committing
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic k0102-orders --group k0102-g \
--from-beginning --max-messages 3 --command-property enable.auto.commit=false \
--formatter-property print.offset=true
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group k0102-g...
Offset:0 order-1
Offset:1 order-2
Offset:2 order-3
Processed a total of 3 messages
Consumer group 'k0102-g' has no active members.Goal: Prove the consumer has read 3 messages but the group has no stored offset yet (no offset row in --describe).
Block 6: Reading again, the same messages come back
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic k0102-orders --group k0102-g \
--from-beginning --max-messages 3 --command-property enable.auto.commit=false \
--formatter-property print.offset=true...
Offset:0 order-1
Offset:1 order-2
Offset:2 order-3
Processed a total of 3 messagesGoal: Prove at-least-once: without committing, the same messages are read again by the same group.
Block 7: Reading with commit
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic k0102-orders --group k0102-g \
--from-beginning --max-messages 3 --formatter-property print.offset=true
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group k0102-g...
Offset:0 order-1
Offset:1 order-2
Offset:2 order-3
Processed a total of 3 messages
Consumer group 'k0102-g' has no active members.
GROUP TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAG CONSUMER-ID HOST CLIENT-ID
k0102-g k0102-orders 0 3 6 3 - - -Goal: Show that after committing, CURRENT-OFFSET becomes 3 and the remaining 3 messages appear as LAG.
Block 8: Reset offset to the beginning
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group k0102-g --topic k0102-orders \
--reset-offsets --to-earliest --dry-run
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group k0102-g --topic k0102-orders \
--reset-offsets --to-earliest --execute
GROUP TOPIC PARTITION NEW-OFFSET
k0102-g k0102-orders 0 0
GROUP TOPIC PARTITION NEW-OFFSET
k0102-g k0102-orders 0 0Goal: Move the group's offset back to 0, using --dry-run to see the result before --execute.
Block 9: Reprocessing after reset
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic k0102-orders --group k0102-g \
--max-messages 6 --timeout-ms 10000 --formatter-property print.offset=true
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group k0102-g...
Offset:0 order-1
Offset:1 order-2
Offset:2 order-3
Offset:3 order-4
Offset:4 order-5
Offset:5 order-6
Processed a total of 6 messages
Consumer group 'k0102-g' has no active members.
GROUP TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAG CONSUMER-ID HOST CLIENT-ID
k0102-g k0102-orders 0 6 6 0 - - -Goal: Prove all 6 messages are reprocessed from offset 0 without --from-beginning, and LAG is back to 0.
Block 10: Cleaning up the group and topic
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --delete --group k0102-g
bin/kafka-topics.sh --bootstrap-server localhost:9092 --delete --topic k0102-orders
bin/kafka-topics.sh --bootstrap-server localhost:9092 --listDeletion of requested consumer groups ('k0102-g') was successful.
__consumer_offsets
demo_java
k0101-ordersGoal: Delete the test group and topic after all blocks are done; run this last because both only exist after Block 1 and Block 7.
Why It Works
acks and idempotence: acks=0 doesn't wait for confirmation, acks=1 waits for the leader, acks=all waits for all in-sync replicas. Since Kafka 3.0, enable.idempotence defaults to true, and when active the broker gives the producer an ID and deduplicates via sequence numbers, so retries don't duplicate messages. That's why configs that weaken acks are rejected (Block 4). This guarantee only applies within a single producer session.
At-least-once: The consumer processes then stores its position. If it stops before the position is stored, the messages are read again (Block 6). That's why Kafka's default is at-least-once and processing must be idempotent.
Exactly-once: Only achieved when a transactional producer and a read_committed consumer are used for the read-process-write pattern inside Kafka. For other destination systems, cooperation from that system is needed. How to use it is covered in the article Kafka Transactions: Consume-Process-Produce with read_committed.
Edge Cases
acks=0 doesn't always lose messages: On a healthy broker, Block 3 is still stored. The risk appears when a failure occurs, and the producer gets no signal at all, so it can't be used for important data.
Resetting offsets on an active group: --reset-offsets can only be executed if the group has no active members. Stop the consumer first, and always run --dry-run before --execute.
Idempotence doesn't cover duplicates from the application: Resends at the application level (e.g., a user retrying a request) can't be deduplicated by the producer, since they're treated as new messages.
Trade-offs
Strategy | Pro | Con |
|---|---|---|
| Lowest latency | Messages can be lost undetected |
| Low latency, leader confirmation | Messages lost if the leader fails before replication |
| No loss and no duplicates from retries | Higher latency |
Best practice: Use acks=all with idempotence (Kafka 3.0+ default) for important data, then make the consumer idempotent because delivery to the consumer remains at-least-once by default.
Gotchas I Ran Into
enable.idempotence=truewithacks=1fails when the producer is created:ConfigException: Must set acks to all in order to use the idempotent producer. Otherwise we cannot guarantee idempotence.The message is not sent at all (final offset stays at 6).The console consumer without commit reads
order-1throughorder-3twice in a row, andkafka-consumer-groups.sh --describeonly printsConsumer group 'k0102-g' has no active members.with no offset row.Kafka 4.3.1 flags
--producer-propertyas deprecated (Use --command-property instead.), so the article uses--command-property.
Production Checklist
Does the producer use
acks=allandenable.idempotence=true? Keep the Kafka 3.0+ defaults and don't weakenacks.Is the consumer idempotent? Assume every message can arrive more than once and store the IDs of messages already processed.
Have offset resets been tried with
--dry-runfirst? Make sure the group is not active before--execute.
References
Apache Kafka, Design (Message Delivery Semantics): https://github.com/apache/kafka/blob/trunk/docs/design/design.md
Apache Kafka, KafkaProducer Javadoc (idempotent and transactional producer): https://github.com/apache/kafka/blob/trunk/clients/src/main/java/org/apache/kafka/clients/producer/KafkaProducer.java
Apache Kafka, Producer Configs (acks, enable.idempotence): https://kafka.apache.org/documentation/#producerconfigs
Apache Kafka, Quickstart: https://kafka.apache.org/quickstart