Kafka: Offsets are committed by the consumer, not the broker

The broker never knows what you processed - only what you told it you processed.

Code
props.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, false);

while (true) {
    var records = consumer.poll(Duration.ofMillis(500));
    for (var r : records) process(r);
    consumer.commitSync();      // after processing
}
Output
Commit BEFORE processing -> at-most-once (crash = message lost)
Commit AFTER processing  -> at-least-once (crash = message redelivered)
Advertisement

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-08-11