Bird
0
0

A Kafka consumer processes messages in batches and wants to commit offsets only after the entire batch is processed. Which approach is best?

hard📝 Application Q9 of 15
Kafka - Consumers
A Kafka consumer processes messages in batches and wants to commit offsets only after the entire batch is processed. Which approach is best?
ADisable auto-commit and call commitSync() after batch processing
BEnable auto-commit with a very short interval
CCall commitAsync() after each message in the batch
DDo not commit offsets and rely on consumer restart
Step-by-Step Solution
Solution:
  1. Step 1: Understand batch processing offset commit

    To commit offsets after batch processing, manual control is needed to commit once after all messages are processed.
  2. Step 2: Select commit method

    Disabling auto-commit and calling commitSync() after batch ensures offsets are saved only after full batch success.
  3. Final Answer:

    Disable auto-commit and call commitSync() after batch processing -> Option A
  4. Quick Check:

    Batch commit = manual sync commit after batch [OK]
Quick Trick: Commit offsets manually after batch to avoid partial commits [OK]
Common Mistakes:
  • Using auto-commit which commits offsets too early
  • Calling commitAsync() per message causing overhead
  • Skipping commits and risking duplicates

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes