Junior — Middle
Can you explain how auto-commit works in Apache Kafka?
sobes.tech AI
Answer from AI
In Apache Kafka, auto-commit is a mechanism for automatically acknowledging (committing) message offsets that the consumer has already processed.
When auto-commit is enabled (usually with the parameter enable.auto.commit=true), the Kafka client periodically (configured by auto.commit.interval.ms) sends information to the server indicating that messages up to a certain offset have been successfully processed. This allows the consumer to resume reading from the last committed offset after a restart.
Advantages:
- Simplifies offset management.
Disadvantages:
- There is a risk of message loss or reprocessing if acknowledgment occurs before actual processing.
Example configuration in Java:
Properties props = new Properties();
props.put("enable.auto.commit", "true");
props.put("auto.commit.interval.ms", "1000");