Part 2 of 4 — Apache Kafka Engineering Notes

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.

  1. Producer configs depend on each other: acks and enable.idempotence cannot be combined freely, and a wrong combination only becomes apparent when the producer is created.

  2. 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, and acks=all, and know which combinations are rejected when enable.idempotence=true.

  • Demonstrate at-least-once behavior: without committing, the group reads the same messages again.

  • Reprocess data with --reset-offsets and read the results from CURRENT-OFFSET and LAG.

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

bash
cd ~/kafka_2.13-4.3.1

The 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

bash
bin/kafka-topics.sh --bootstrap-server localhost:9092 --create --topic k0102-orders --partitions 1 --replication-factor 1
text
Created 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

bash
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-orders
text
k0102-orders:0:5

Goal: Send 5 messages with the producer's strongest guarantee and prove all five are stored (final offset 5).

Block 3: Producer with acks=0

bash
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-orders
text
k0102-orders:0:6

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

bash
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-orders
text
org.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:6

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

bash
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
text
...
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

bash
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
text
...
Offset:0	order-1
Offset:1	order-2
Offset:2	order-3
Processed a total of 3 messages

Goal: Prove at-least-once: without committing, the same messages are read again by the same group.

Block 7: Reading with commit

bash
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
text
...
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

bash
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
text

GROUP           TOPIC           PARTITION  NEW-OFFSET
k0102-g         k0102-orders    0          0

GROUP           TOPIC           PARTITION  NEW-OFFSET
k0102-g         k0102-orders    0          0

Goal: Move the group's offset back to 0, using --dry-run to see the result before --execute.

Block 9: Reprocessing after reset

bash
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
text
...
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

bash
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 --list

plaintext
Deletion of requested consumer groups ('k0102-g') was successful.
__consumer_offsets
demo_java
k0101-orders

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

acks=0

Lowest latency

Messages can be lost undetected

acks=1

Low latency, leader confirmation

Messages lost if the leader fails before replication

acks=all + idempotence

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=true with acks=1 fails 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-1 through order-3 twice in a row, and kafka-consumer-groups.sh --describe only prints Consumer group 'k0102-g' has no active members. with no offset row.

  • Kafka 4.3.1 flags --producer-property as deprecated (Use --command-property instead.), so the article uses --command-property.

Production Checklist

  • Does the producer use acks=all and enable.idempotence=true? Keep the Kafka 3.0+ defaults and don't weaken acks.

  • 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-run first? Make sure the group is not active before --execute.

References