Video in progress

When does the auto.offset.reset setting apply, and what's the difference between earliest and latest?

It only applies when no committed offset is found for the consumer group: a new group, or an offset that has been deleted by retention. earliest starts from the beginning of the partition, latest only from messages that arrive from now on.

📖 Answer

People get this wrong in interviews all the time: "if I set earliest, it will read from the beginning on every restart". No. If the group has a committed offset, the consumer continues from there and auto.offset.reset isn't looked at at all.

spring:
  kafka:
    consumer:
      group-id: invoice-service
      auto-offset-reset: earliest

Which one to choose:

  • earliest — for business data (orders, payments). A new service sees everything in the topic the first time it starts.
  • latest — for real-time things where old messages are useless (a live dashboard, for example).
  • none — throws an error if there's no offset. Rare, but useful where you're afraid of a "silent failure".

The default is latest. Starting a new service without knowing this and "losing" the first messages is a classic.