Kafka: auto-commit commits on poll, not on success

The next poll commits the previous batch whether or not it was processed successfully.

Code
// enable.auto.commit=true, auto.commit.interval.ms=5000
var records = consumer.poll(...);   // may commit the PREVIOUS batch here
for (var r : records) {
    process(r);                     // throws on record 3 of 100
}
Output
Records 3 to 100 were never processed,
but their offsets are committed on the next poll and never 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