Bird
Raised Fist0

You want to implement a Kafka consumer that commits offsets only after successfully processing a batch of messages, ensuring no duplicates on restart. Which strategy should you use?

hard🚀 Application Q8 of Q15
Kafka - Message Delivery Semantics
You want to implement a Kafka consumer that commits offsets only after successfully processing a batch of messages, ensuring no duplicates on restart. Which strategy should you use?
AEnable auto commit and rely on default commit timing.
BEnable auto commit with a short commit interval.
CDisable auto commit and call commitSync() after processing each batch.
DUse commitAsync() without callback after processing each message.
Step-by-Step Solution
Solution:
  1. Step 1: Identify requirement for precise commit control

    To avoid duplicates, commit offsets only after processing batch successfully.
  2. Step 2: Choose commit method

    Disabling auto commit and using commitSync() after batch ensures commit success before next batch.
  3. Final Answer:

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

    Manual sync commit after batch = no duplicates [OK]
Quick Trick: Manual sync commit after batch ensures exactly-once processing [OK]
Common Mistakes:
MISTAKES
  • Relying on auto commit for precise control
  • Using async commit without error handling
  • Committing after each message instead of batch

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes