Skip to main content
InterviewHubPRO
Section Overview
Q16

Question 16 of 50

Part 2: Core Architecture & Implementation (Mid-Level)

32%
Apache Kafka Streaming (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)

How does Consumer Offset Management work, and what are the trade-offs of Auto-Commit vs. Manual Commit?

senior LevelSystem Design

In Simple Words: Kafka consumers store their current progress as offsets in an internal compacted topic named __consumer_offsets.

  • Auto-Commit (enable.auto.commit=true):
    • Commits offsets periodically (default every 5s via auto.commit.interval.ms).
    • Risk: If your application crashes after auto-committing but before finishing database writes, records are lost. If it crashes before auto-commit, records are re-processed.
  • Manual Commit (enable.auto.commit=false):
    • commitSync(): Synchronously commits offsets. Blocks until the broker confirms. Safe, but degrades throughput.
    • commitAsync(): Asynchronously commits offsets without blocking. High throughput, but does not retry on commit failure to prevent committing an older offset over a newer one.
    • Best Practice: Use commitAsync() during the processing loop, and call commitSync() in a finally block during consumer shutdown.