Video in progress

A bug in a consumer produced wrong calculations for two weeks. How do you organize the reprocessing of events?

First I identify which effects the reprocessing would repeat: are the DB writes idempotent, are there external calls (email, payments). Then, often with a separate consumer group or a separate "replay" deployment, I read from the required time without stopping the main consumer, compare the results, and swap afterwards.

📖 Answer

Rushing a --reset-offsets --to-datetime is dangerous: when the consumer re-reads, customers get another SMS for orders from two weeks ago, and the warehouse gets another "ship it" command.

Here's how I usually plan it:

  1. Map the effects. What does the consumer do: does it only write to its own DB (recomputing is safe), or does it emit events and call external APIs? The second kind of effects is turned off in "replay mode" or protected with an idempotency key.

  2. Check retention. Is the two weeks of data still in the topic? If not, the source is somewhere else (a data lake, an outbox archive).

  3. Read separately. Replay instances with a new group.id:

kafka-consumer-groups.sh --bootstrap-server kafka:9092 --group billing-replay-2026-11 \
  --topic orders --reset-offsets --to-datetime 2026-10-15T00:00:00.000 --execute

I write the result to a separate table (invoice_recalc). The main service keeps running as usual.

  1. Compare and swap. The difference between the old and new results is reviewed with the business. That difference is, for example, the amounts to be refunded to customers. Then, in a single transaction or migration, the correct values go into the main table.

  2. The crossover of the two streams. When the replay catches up to "now", the main consumer must already be running the fixed code. Set an exact cutoff time and apply it on both sides.

This case teaches a lesson for architecture: design consumers to be "replayable" from the start. Side effects are idempotent, calculations are deterministic (the time comes from the event's occurredAt, not now()), and configuration depends on the event time, not the read time.