Quick revision
The short answer
We stop all consumers of that one group, move the group's committed offsets back six hours with kafka-consumer-groups.sh --reset-offsets (first with --dry-run, then with --execute), and start the consumers again. Because offsets are stored per group, every other group keeps reading from where it was. The one thing we must check first is that the consumer's side effects are idempotent, so the replay does not apply the same change twice.
What to remember
In this answer, we saw that offsets belong to one consumer group, so rewinding one group leaves all others untouched. The safe procedure is to stop the group's consumers, run kafka-consumer-groups.sh --reset-offsets --to-datetime with --dry-run, check the result, run it with --execute and restart. Spring Kafka can do the same seek through ConsumerSeekAware, as long as we guard against seeking again on every rebalance. Above all, we check that every side effect of the consumer is idempotent before replaying.
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.
We stop all consumers of that one group, move the group's committed offsets back six hours with kafka-consumer-groups.sh --reset-offsets (first with --dry-run, then with --execute), and start the consumers again. Because offsets are stored per group, every other group keeps reading from where it was. The one thing we must check first is that the consumer's side effects are idempotent, so the replay does not apply the same change twice.
Why this question is asked
Reprocessing after a bug fix is one of the most useful things Kafka can do, because the events are still there and we can read them again. It is also easy to get wrong: resetting the wrong group, resetting while consumers are running, or replaying into a consumer that sends emails twice. Interviewers ask it to see whether we understand that offsets belong to a group and how to move them safely. In this answer, we will recap why groups are independent, walk through the command-line reset with a dry run, look at doing the same seek from Spring Kafka code, and then cover the safety checks around side effects.
1Why One Group Can Rewind Without Touching Others
A Kafka topic is a log. Reading a record does not remove it; the record stays until the topic's retention deletes it. Each consumer group keeps its own position in that log as committed offsets, stored by group id. Two groups reading the same topic are like two readers with their own bookmarks in the same book.
So rewinding the bookmark of the billing-projector group has no effect on the fraud-checker group or the search-indexer group. They keep their committed offsets and never see the replay. The only shared limit is retention: we can only go back six hours if the topic still holds six hours of data, which we should confirm with the topic's retention.ms before we start.
| Group | Before the reset | After the reset |
|---|---|---|
| billing-projector | 981,400 | 954,120 (six hours ago) |
| fraud-checker | 981,395 | 981,395 (unchanged) |
| search-indexer | 980,010 | 980,010 (unchanged) |
2Stop the Group's Consumers
Kafka refuses to reset the offsets of a group that has active members. The reason is simple: a running consumer keeps its position in memory and commits it regularly, so it would overwrite our reset within seconds. The tool protects us by checking that the group is empty and failing otherwise.
So we scale the service's consumers to zero, or stop just the listener if the same application has other work to do. With Spring Kafka we can stop one listener container through KafkaListenerEndpointRegistry, for example from an admin endpoint, while the rest of the application keeps serving requests. Then we confirm the group is empty before going on.
3Reset the Offsets With a Dry Run First
The tool can move offsets in several ways. --to-datetime moves each partition to the first offset whose record timestamp is at or after the given time. --by-duration PT6H does the same relative to now. --shift-by -5000 moves back a fixed number of records per partition. For our case, time is what matters, so we use a timestamp from just before the buggy version was deployed.
- Confirm topic retention covers six hours
retention.mson the topic - Stop the group's consumersthe tool refuses an active group
- Run --reset-offsets with --dry-runcheck new offsets per partition
- Do the new offsets look right?YesRun the same command with --executeNoFix the time or scope and dry-run again
- Start the consumersthey resume from six hours ago
- Watch lag fall back to normalthe replay is done when lag is near zero
6 steps in order. Play them, or step through them one at a time.
Notice that we always name both --group and --topic. Leaving out the topic with --all-topics would rewind every topic the group reads, which is rarely what we want. The dry run is our chance to compare the new offsets with the current ones and confirm the jump is about six hours of traffic, not six days. Also check the time zone: the tool interprets the timestamp in the local zone unless we add an offset such as Z, so writing the time in UTC with an explicit zone avoids a nasty surprise.
After --execute, we start the consumers again. They find the new committed offsets and begin reading from six hours ago.
4Doing the Same Seek From Spring Kafka
Sometimes we want the application itself to do the rewind, for example behind an admin endpoint or on startup when a property is set. Spring Kafka lets a listener seek by implementing ConsumerSeekAware. When partitions are assigned, Spring gives us a callback that can seek each partition to a timestamp.
This version has one catch: onPartitionsAssigned runs on every rebalance, not just once. If the property stays set, every rebalance would rewind again. So we remove the property after the replay, or remember in code that the seek has already happened. For a one-off operation, the command-line tool is usually simpler and leaves an audit trail in the terminal history; the code approach suits replays that are a regular, tested feature.
5Making the Replay Safe for Side Effects
Moving offsets is the easy part. The hard question is what the consumer does with each event. If it writes a projection with upserts keyed by the payment id, reprocessing simply overwrites rows with corrected values, which is exactly what the bug fix needs. If it sends emails, charges cards or publishes new events, a replay would repeat all of those.
So before resetting, we read the listener's code path and check each side effect. Database writes should be upserts or guarded by a processed-events table. External calls should carry an idempotency key, such as the event id, that the downstream service uses to ignore repeats. Events the consumer publishes should carry the same id so that their consumers can deduplicate too. If some side effect cannot be made idempotent, we can switch it off with a flag during the replay. It also helps to replay first in a staging environment against a copy of the data.
6Follow-up questions
What if we need to replay only some partitions?
kafka-consumer-groups.sh accepts a topic with a partition list, for example --topic payments:0,2, so only those partitions move. The rest keep their committed offsets. This is useful when the bug affected only keys that hash to certain partitions, though in practice a time-based reset of the whole topic is easier to reason about.
Can we replay without stopping the production consumers at all?
Yes, by using a new group id. A separate group, for example billing-projector-replay, starts from a timestamp and processes the six hours in parallel while the main group keeps running. This avoids downtime but means two instances write to the same target, so it only works when the writes are idempotent and ordering between the two does not matter.
How do we know the replay has finished?
Watch the group's lag. Right after the reset, lag jumps by six hours of records; as the consumers catch up it falls back to its normal level. When lag is back near zero on every partition, the replayed range has been processed.
7Conclusion
In this answer, we saw that offsets belong to one consumer group, so rewinding one group leaves all others untouched. The safe procedure is to stop the group's consumers, run kafka-consumer-groups.sh --reset-offsets --to-datetime with --dry-run, check the result, run it with --execute and restart. Spring Kafka can do the same seek through ConsumerSeekAware, as long as we guard against seeking again on every rebalance. Above all, we check that every side effect of the consumer is idempotent before replaying.
Open with
First I would confirm the topic still retains at least six hours of data, and check what the consumer does with each event, because the replay is only safe if the side effects are idempotent: upserts keyed by event id, or idempotency keys on external calls.
Then, if they want more
Anything that cannot be repeated, like emails, I would switch off for the replay. Then I would stop all consumers of that one group, because Kafka refuses to reset offsets for a group with active members, and a running consumer would overwrite the reset anyway.
Next I run kafka-consumer-groups.sh with --reset-offsets --to-datetime for a time just before the bad deployment, naming the group and the topic explicitly, and with --dry-run first so I can compare the new offsets with the current ones. If they look like six hours of traffic, I run the same command with --execute and restart the consumers.
Other groups are not affected at all, because each group keeps its own committed offsets. If I need the application to do it, Spring Kafka's ConsumerSeekAware can call seekToTimestamp in onPartitionsAssigned, but I would make sure it does not rewind again on the next rebalance. Finally I watch lag drop back to normal to know the replay is done.
About this answer
- Last updated
- 12 November 2026
- 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 "You need to reprocess the last six hours of events for one consumer group after a bug...": https://scrivio-interview-library.netlify.app/spring-boot/kafka/67f817f07b/