Skip to main content

Question 29 of 50

What's the difference between Auto Commit and Manual Commit?

SeniorTech Lead

Question

"What's the practical difference between Auto Commit and Manual Commit, and when would you use each?"

What the interviewer wants to assess

Whether you understand that the choice between auto and manual commit isn't about code convenience, but about which risk (loss or duplication) the system is willing to accept.

Resposta rápida

Auto commit (enable.auto.commit=true) makes the client automatically commit offsets on a periodic interval, with no direct relation to when processing finishes — it can commit a message whose processing is still in progress or even failed. Manual commit (enable.auto.commit=false with AckMode.MANUAL) requires the application to explicitly call acknowledgment.acknowledge(), typically only after processing finished successfully.

Resposta nível Sênior

The real difference is in the risk each approach accepts. Auto commit tends toward the message-loss scenario: if the consumer crashes between the automatic commit (which already happened) and the actual end of processing, that message is considered processed by Kafka without having actually been processed successfully. Manual commit, done strategically after processing confirms success, eliminates that loss risk — but still allows duplication: if the consumer crashes between the end of processing and the commit itself, the message will be redelivered on the next startup. That's why, in financial systems, I always prefer manual commit combined with idempotent processing (Chapter 11) — accepting controlled duplication instead of risking silent loss.

In-depth explanation

See "The risks of each approach" in Chapter 7.

Exemplo financeiro

A consumer with auto commit processing payments, if it crashes right after an automatic commit but before persisting the result to the database, silently loses that payment — with no error log, no exception, because from Kafka's point of view the message was already processed.

"Auto commit is simpler, so it is the safe default choice"

Code simplicity isn't synonymous with data safety. For any flow where message loss is unacceptable, manual commit (with idempotent processing) is the correct choice, even if it requires more code.

Pode vir a seguir

Likely follow-ups: "what is Retention Period?" and "how would you avoid duplicate processing?".

Related chapters