Scrivio Interview library
DebuggingFoundations7 min read · updated 12 November 2026

After a consumer restart, a service reprocessed two days of events. The consumer group had been stopped for a week during a migration and auto.offset.reset is earliest. Explain what happened.

Try it yourself

Consumer group: who reads which partition

Change the number of partitions and consumers, and see who owns what, who is idle, and where ordering holds.

Read this example as text

Who reads which partition

  1. 3 partitions, 2 consumers. C0 reads P0, P1; C1 reads P2.
  2. 4 partitions, 2 consumers. C0 reads P0, P1; C1 reads P2, P3.
  3. 3 partitions, 3 consumers. C0 reads P0; C1 reads P1; C2 reads P2.
  4. 6 partitions, 4 consumers. C0 reads P0, P1; C1 reads P2, P3; C2 reads P4; C3 reads P5.
  5. 2 partitions, 4 consumers. C0 reads P0; C1 reads P1; C2 is idle; C3 is idle.

A partition has exactly one reader in the group. A consumer beyond the number of partitions is idle.

Six records with 3 partitions and 2 consumers

  1. Record A1. Key A goes to P0, read by C0.
  2. Record B1. Key B goes to P1, read by C0.
  3. Record A2. Key A goes to P0, read by C0.
  4. Record C1. Key C goes to P2, read by C1.
  5. Record B2. Key B goes to P1, read by C0.
  6. Record A3. Key A goes to P0, read by C0.

A1, A2 and A3 sit in one partition and are read in that order. Nothing orders a record in one partition against a record in another.

What this example leaves out
  • One topic, and Kafka's range assignor, the first in the default list. Other assignors spread partitions differently.
  • A, B and C stand for key hashes 0, 1 and 2. The real client hashes the key bytes; the rule shown, same key to the same partition, is the same.
  • A rebalance is shown as instant. In a real group, consumers stop briefly while partitions move.

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.

Step throughWhat a consumer does when it is assigned a partition
  1. Consumer joins the grouppartition 3 is assigned to it
  2. Is there a committed offset for partition 3?
    YesContinue from the committed offsetNoLook at auto.offset.reset
  3. auto.offset.reset = earliest?
    YesSeek to the oldest retained recordNolatest: seek to the end; none: throw
  4. 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.

Text
# Before the restart, the group looks unknown to the broker
kafka-consumer-groups.sh --bootstrap-server localhost:9092 \
--describe --group order-service
# Consumer group 'order-service' does not exist.
# Topic retention decides how far back 'earliest' goes
kafka-configs.sh --bootstrap-server localhost:9092 \
--describe --entity-type topics --entity-name orders
# retention.ms=172800000 <- 2 days

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.

Java
# Before the stop: save the current position
kafka-consumer-groups.sh --bootstrap-server localhost:9092 \
--describe --group order-service > order-service-offsets.txt
# Before the restart: set the position on purpose (group must be inactive)
kafka-consumer-groups.sh --bootstrap-server localhost:9092 \
--group order-service --topic orders \
--reset-offsets --to-datetime 2026-10-30T09:00:00.000 --dry-run
# shows the new offset per partition, changes nothing
# then repeat with --execute instead of --dry-run

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.

Java
@KafkaListener(topics = "orders", groupId = "order-service")
@Transactional
public void onOrder(OrderEvent e) {
int inserted = jdbc.update(
"INSERT INTO processed_event(event_id) VALUES (?) ON CONFLICT DO NOTHING", e.id());
if (inserted == 0) return; // 0: seen before, skip the side effect
orders.apply(e); // runs once per event id
}

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.

What to say in the interviewAbout 80 seconds aloud

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.
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/