Quick revision
The short answer
The group's committed offsets were deleted while it was stopped. Once a consumer group has no members, Kafka keeps its committed offsets only for offsets.retention.minutes, which is 7 days by default, and the migration lasted longer than that. On restart the consumers found no committed offset, fell back to auto.offset.reset=earliest, and started from the oldest record still kept in the topic, which happened to be two days of events.
What to remember
In this answer, we saw that committed offsets of an empty group live only for offsets.retention.minutes, 7 days by default, so a week-long stop deleted them. On restart the consumers had no position, followed auto.offset.reset=earliest, and read everything the topic still held, which was two days because of the topic's retention. We can prevent it by keeping groups active, raising offset retention, or resetting offsets deliberately before a restart, and we make the consequences harmless with idempotent consumers.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
The group's committed offsets were deleted while it was stopped. Once a consumer group has no members, Kafka keeps its committed offsets only for offsets.retention.minutes, which is 7 days by default, and the migration lasted longer than that. On restart the consumers found no committed offset, fell back to auto.offset.reset=earliest, and started from the oldest record still kept in the topic, which happened to be two days of events.
Why this question is asked
This incident surprises teams because nothing in the consumer code changed. The service was simply stopped for a while, and when it came back it behaved as if it had never run before. Interviewers ask it because the answer shows whether we know where Kafka keeps a consumer's position, how long it keeps it, and what the consumer does when the position is gone. In this answer, we will recap how committed offsets work, follow the timeline of the incident step by step, see why exactly two days were replayed, and then go through the ways to prevent it and why idempotent consumers are needed anyway.
1A Quick Recap of Committed Offsets
Every record in a Kafka partition has an offset, a number that grows by one for each record. A consumer group, a set of consumers that share the work of reading a topic under one group.id, remembers how far it has read by committing offsets. A committed offset is simply the next offset the group should read in that partition, stored by the broker in the internal topic __consumer_offsets.
When a consumer starts and is assigned a partition, it asks the group coordinator, the broker responsible for the group, for the committed offset of that partition. If one exists, the consumer continues from there. If none exists, the consumer has to guess, and the property auto.offset.reset tells it how: latest means start from the end and read only new records, earliest means start from the oldest record the topic still has, and none means throw an exception and let us decide.
So the committed offset is the only thing that tells a restarted consumer where it stopped. If it disappears, the consumer is treated like a brand new group.
2How Long Kafka Keeps Committed Offsets
Kafka does not keep committed offsets forever. The broker setting offsets.retention.minutes controls how long they live, and its default has been 10080 minutes, which is 7 days, since Kafka 2.0.
Since Kafka 2.1 the clock works in a friendlier way. While the group has active members, its offsets do not expire at all, however old they are. The retention period starts counting only when the group becomes empty, meaning the last consumer has left. After the group has been empty for the full retention period, the coordinator deletes the group's offsets by writing tombstones to __consumer_offsets.
Notice what this means for our incident. The consumers were stopped for a week during the migration, so the group was empty for a week. The 7-day timer ran out, and the offsets were removed while nobody was watching.
- Consumer joins the grouppartition 3 is assigned to it
- Is there a committed offset for partition 3?YesContinue from the committed offsetNoLook at auto.offset.reset
- auto.offset.reset = earliest?YesSeek to the oldest retained recordNolatest: seek to the end; none: throw
- Start fetchingoffsets older than the topic's retention are already gone
4 steps in order. Play them, or step through them one at a time.
With the offsets expired, the second question answers no and the setting decides everything.
3Following the Incident Step by Step
We can now replay what happened. On day 0 the team stopped all consumers of the group for the migration, and the group became empty. On day 7 the broker's retention timer expired and the group's committed offsets were deleted. A few days later the migration finished and the consumers were started again.
Each consumer joined the group, was assigned its partitions, and asked for their committed offsets. There were none. The consumer then read auto.offset.reset, found earliest, and moved to the log start offset of each partition, the oldest offset the broker still keeps.
Notice the retention on the topic itself: retention.ms is 172800000 milliseconds, which is 48 hours. That is why the service reprocessed two days of events and not a week or a year. Earliest does not mean the first record ever written; it means the oldest record that has not yet been deleted by the topic's own retention. The consumers read everything still in the topic, which was exactly two days of data.
There is also a second, quieter loss here. Events written during the stop that are older than two days were deleted before anyone read them, so this group never processed them at all. The replay and the gap come from the same cause.
4How to Prevent It
The first fix is to keep the group from going empty for so long, or to raise the retention to cover the longest planned stop. offsets.retention.minutes is a broker setting, so raising it affects every group on the cluster, but 14 or 30 days costs very little storage.
The second fix is to treat a long stop as a planned operation. Before stopping, we record the group's current offsets with kafka-consumer-groups.sh --describe. Before restarting, we check whether the offsets still exist, and if they do not, we set them deliberately with --reset-offsets, for example to the offsets we recorded or to a timestamp, instead of letting auto.offset.reset guess.
A third option is auto.offset.reset=none, which makes the consumer fail with NoOffsetForPartitionException when the offsets are missing. That turns a silent replay into a loud alert that a person must handle, which is often the better outcome for a critical service.
5Why the Consumer Must Be Idempotent Anyway
Even with the right settings, Kafka consumers will see some records twice. A consumer that crashes after processing a record but before committing its offset will process that record again. A rebalance can do the same. Kafka's normal delivery promise is at-least-once, and a replay like this one is just a very large version of the same thing.
So the real protection is an idempotent consumer: processing the same event twice has the same effect as processing it once. Typical ways are an upsert keyed by the event id, a table of processed event ids written in the same database transaction as the change, or a unique constraint that rejects the duplicate insert. With that in place, this incident would have cost two days of extra CPU time and nothing else.
6Follow-up questions
Does a running group with very old offsets lose them too?
No. Since Kafka 2.1, offsets of a group that still has members never expire, even if the group has not committed for a long time. The retention clock starts only after the last member leaves.
Why not just set auto.offset.reset to latest everywhere?
Because latest hides data loss. Every event produced while the group had no offsets would be skipped without any error. For most business consumers, reprocessing with an idempotent consumer is recoverable, while silently skipped events are often found only weeks later in a reconciliation. If neither guess is acceptable, none forces a human decision.
7Conclusion
In this answer, we saw that committed offsets of an empty group live only for offsets.retention.minutes, 7 days by default, so a week-long stop deleted them. On restart the consumers had no position, followed auto.offset.reset=earliest, and read everything the topic still held, which was two days because of the topic's retention. We can prevent it by keeping groups active, raising offset retention, or resetting offsets deliberately before a restart, and we make the consequences harmless with idempotent consumers.
Open with
What happened is that the group's committed offsets expired. Kafka keeps the offsets of an empty consumer group for offsets.retention.minutes, which defaults to seven days, and the clock starts when the last member leaves.
Then, if they want more
The group was stopped for a week, so the broker deleted its offsets. When the consumers came back they had no committed position, so they used auto.offset.reset, which was earliest, and started at the log start offset of each partition.
That is the oldest record still retained, and the topic's retention was two days, so we replayed two days of events. It also means anything older than two days written during the stop was never processed.
To prevent it, I would raise offsets.retention.minutes above our longest planned outage, keep the group alive if possible, and make long stops a runbook step: save the offsets before stopping, check them before starting, and reset them deliberately with kafka-consumer-groups.sh if needed. For critical services I might even use auto.offset.reset=none so a missing position fails loudly.
And regardless of settings, the consumer must be idempotent, for example by recording processed event ids, because replays happen in normal operation too.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Kafka 2.1, Kafka 2.0
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Apache Kafka documentation, Spring for Apache Kafka reference
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "After a consumer restart, a service reprocessed two days of events. The consumer group...": https://scrivio-interview-library.netlify.app/spring-boot/kafka/00f3a4c397/