Scrivio Interview library
ScenarioAdvanced6 min read · updated 13 November 2026

A bug in a projection service corrupted about 2 million rows over three days, and the service's own output topic fed three downstream services during that time.

Plan the repair using Kafka replay, including how to avoid repeating side effects and how to coordinate the downstream teams.

Fix the bug first, then choose the repair source: replay the input topic if retention still covers the three days, otherwise rebuild from the source system or a lake copy. Find per-partition start offsets with offsetsForTimes for the time the bug was deployed, and replay in a separate group (or with the live group paused) into a fresh projection or with idempotent upserts, suppressing emails, payments and other external calls in replay mode. Agree with the three downstream teams whether they want corrected events marked as corrections or their own replays, plus ordering and a cut-over time, and throttle the replay with quotas and verify it against the source with counts and checksums.

Why this question is asked

Repairing derived data is where event-driven systems are supposed to shine, because the input is still in Kafka and the projection can be rebuilt. But the bug's output also travelled to three other services for three days, so the repair is as much about coordination as about code. Interviewers ask this to see whether we can plan a replay that fixes the data without repeating side effects or surprising other teams. In this answer, we will recap what a projection and a replay are, then walk through choosing the source, finding the start, running the replay, handling side effects, coordinating downstream and verifying the result.

1A Quick Recap: Projections and Replays

A projection service reads events from an input topic and builds a read model, such as a table of current account balances. Here it also publishes its own output events to a topic that three downstream services consume. A replay means reading a range of the input topic again, from an earlier offset, and applying it once more.

The bug corrupted about 2 million rows over three days, and every corrupted row was probably also announced on the output topic. So there are two things to repair: our own table, and what we told the downstream services.

2Fix the Bug and Choose the Repair Source

Nothing is replayed until the fixed version is deployed and tested against a sample of the bad events; replaying through the buggy code would simply corrupt the data again. Then we check retention on the input topic. If it keeps at least the three days plus a margin, say 7 days, the input topic is the repair source. If not, we rebuild from the source system that produced the events, or from a lake copy of the topic written by a sink connector, because Kafka no longer has what we need.

If the replay will take a while, it is worth temporarily raising the input topic's retention so the data we need is not deleted halfway through the repair.

3Find Where to Start

The start is the deployment time of the bug, which we take from the deploy log, minus a small margin. offsetsForTimes() returns, per partition, the first offset whose timestamp is at or after that time.

Java
long bugDeployed = Instant.parse("2026-11-08T14:05:00Z").minus(Duration.ofMinutes(10)).toEpochMilli();
Map<TopicPartition, Long> query = consumer.partitionsFor("ledger-events").stream()
.collect(toMap(p -> new TopicPartition(p.topic(), p.partition()), p -> bugDeployed));
Map<TopicPartition, OffsetAndTimestamp> start = consumer.offsetsForTimes(query);
// {ledger-events-0=(offset=1840211, ts=...), ledger-events-1=(offset=1838730, ts=...), ...}

The ten-minute margin costs a few thousand extra events, which idempotent processing handles at no risk, and protects against clocks and timestamps that are slightly off.

4Run the Replay Without Disturbing Live Processing

There are two safe shapes. The cleaner one replays into a fresh projection: a new table, filled by a replay consumer in its own group from the start offsets up to the present, which then catches up with live traffic, after which we switch reads over and drop the old table. Nothing in the live path changes until the switch.

The simpler one repairs in place with idempotent upserts: a replay consumer in its own group re-applies events from the start offsets, overwriting rows keyed by entity id with a version check, while the live group keeps running, or is paused if the two would fight over the same rows. In both shapes, the replay uses its own group id, so the live group's offsets are untouched.

Step throughRepair plan
  1. Deploy and test the fixnever replay through the buggy code
  2. Does input retention cover 3 days plus margin?
    YesReplay the input topicNoRebuild from source or lake copy
  3. offsetsForTimes for the bug's deploy timeper-partition start offsets
  4. Replay in a separate group, replay mode onfresh projection, or idempotent upserts
  5. Publish corrections as agreed with downstream
  6. Verify counts and checksums, then cut over

6 steps in order. Play them, or step through them one at a time.

5Separate State Changes From Side Effects

A projection usually does more than write rows: it may send a notification, call a payment service or emit a webhook. Those already happened once during the three days, some of them wrongly. A replay must not do them again blindly. The service needs a replay mode in which it updates state but suppresses external calls, or every external call must be idempotent by event id, so a provider that already received event 7731 ignores it.

Where the bug caused wrong side effects, for example a wrong email, the fix is a separate, deliberate action, such as a correction email to the affected customers, decided with the business, not an accidental by-product of the replay.

6Coordinate the Downstream Teams

The three downstream services consumed our wrong output for three days, and each may have built its own state from it. We meet their owners early and agree on what each needs. Usually there are two options: we publish corrected events on the output topic, marked as corrections with a header or field and carrying the entity's latest version, so consumers that keep only the latest state simply overwrite; or a team replays its own input from our topic after we have rewritten it, or rebuilds from our repaired table.

We also agree on ordering, since corrections for an entity must not be overtaken by older events, on a cut-over time, and on who verifies what. A shared timeline, with the replay start, expected finish and checkpoints, keeps everyone aligned.

7Throttle and Verify

A replay of three days of events can read far faster than live traffic and swamp the brokers or the database. We throttle it with a consumer byte-rate quota on the replay client id, and with modest batch sizes, and watch the live group's latency throughout.

Finally, we verify against the source of truth, not against our own replay. Row counts per day, checksums over key columns, and a sample of entities compared field by field with the source system tell us whether the 2 million rows are now right. Only then do we cut over, close the incident, and send the downstream teams the final confirmation.

8Follow-up questions

What if retention no longer covers the three days?

Then Kafka cannot be the repair source. We rebuild from the source system, for example by re-exporting the affected entities, or from a lake copy of the topic, publishing the rebuilt state as correction events. That is a strong argument for keeping a lake copy of important topics.

Why not just reset the live group to the start and let it reprocess?

Because the live group would also redo every side effect and republish every output event for three days, mixed with live traffic, with no replay mode and no throttle. A separate replay consumer lets us control the speed, suppress side effects, and leave live processing untouched.

9Conclusion

In this answer, we planned the repair in steps: fix and test the bug first, choose the input topic as the source only if retention covers the three days, find start offsets with offsetsForTimes, and replay in a separate group into a fresh projection or with idempotent upserts. Replay mode suppresses emails and payments, downstream teams agree in advance on correction events or their own replays, ordering and a cut-over time, and the replay is throttled with quotas and verified against the source with counts and checksums before cut-over.

What to say in the interviewAbout 90 seconds aloud

Open with

First I would make sure the bug is fixed and tested on a sample of the bad events, because replaying through the old code just corrupts everything again.

Then, if they want more

Then I would pick the repair source: if the input topic's retention still covers the three days plus a margin, replay from Kafka, and I might temporarily extend retention so it does not expire during the repair. If not, I would rebuild from the source system or a lake copy.

To find the start, I would call offsetsForTimes with the bug's deploy time minus a few minutes and get a start offset per partition.

The replay runs in its own consumer group, either into a fresh projection table that I switch to when it has caught up, or as idempotent upserts with version checks while the live group keeps running or is paused.

The important part is separating state from side effects: in replay mode the service updates rows but does not send emails or call payment APIs, or those calls are idempotent by event id.

For the three downstream services, I would agree with their owners up front whether we publish corrected events marked as corrections or they replay themselves, plus ordering and a cut-over time, and share a timeline. Finally I would throttle the replay with a quota and verify against the source with counts and checksums before calling it done.

About this answer

Last updated
13 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
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 "Plan the repair using Kafka replay, including how to avoid repeating side effects and...": https://scrivio-interview-library.netlify.app/spring-boot/kafka-clients-in-depth/b14b168516/