Scrivio Interview library
ScenarioIntermediate7 min read · updated 12 November 2026

You need to reprocess the last six hours of events for one consumer group after a bug fix, without affecting other groups. How would you do it safely?

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.

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.

Committed offsets for topic payments, partition 0
GroupBefore the resetAfter the reset
billing-projector981,400954,120 (six hours ago)
fraud-checker981,395981,395 (unchanged)
search-indexer980,010980,010 (unchanged)
Only the group we name moves its bookmark; the log itself is untouched.

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.

Text
kafka-consumer-groups.sh --bootstrap-server localhost:9092 \
--describe --group billing-projector --members
# Consumer group 'billing-projector' has no active members.

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.

Java
# 1. Preview: prints the new offset per partition, changes nothing
kafka-consumer-groups.sh --bootstrap-server localhost:9092 \
--group billing-projector --topic payments \
--reset-offsets --to-datetime 2026-11-05T06:00:00.000 --dry-run
# GROUP TOPIC PARTITION NEW-OFFSET
# billing-projector payments 0 954120
# billing-projector payments 1 953877
# 2. Apply exactly the same command
kafka-consumer-groups.sh --bootstrap-server localhost:9092 \
--group billing-projector --topic payments \
--reset-offsets --to-datetime 2026-11-05T06:00:00.000 --execute
Step throughSafe reset of one group
  1. Confirm topic retention covers six hoursretention.ms on the topic
  2. Stop the group's consumersthe tool refuses an active group
  3. Run --reset-offsets with --dry-runcheck new offsets per partition
  4. Do the new offsets look right?
    YesRun the same command with --executeNoFix the time or scope and dry-run again
  5. Start the consumersthey resume from six hours ago
  6. 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.

Java
@Component
class BillingListener extends AbstractConsumerSeekAware {
@Value("${replay.from:}") // e.g. 2026-11-05T06:00:00Z, empty = no replay
private String replayFrom;
@Override
public void onPartitionsAssigned(Map<TopicPartition, Long> assignments,
ConsumerSeekCallback callback) {
super.onPartitionsAssigned(assignments, callback);
if (!replayFrom.isEmpty()) {
long ts = Instant.parse(replayFrom).toEpochMilli();
callback.seekToTimestamp(assignments.keySet(), ts); // each partition -> first offset at ts
}
}
@KafkaListener(id = "billing", topics = "payments", groupId = "billing-projector")
void on(PaymentEvent e) { projector.apply(e); }
}

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.

What to say in the interviewAbout 80 seconds aloud

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