A loader bug corrupted three days of warehouse data — replay them from Kafka without duplicates
A bug in the orders-loader consumer group wrote wrong amounts into dwh.orders from 2026-11-05 00:00 until the fix was deployed today, 2026-11-08. The orders topic uses cleanup.policy=delete with the default retention.ms. The loader inserts each batch with a plain INSERT and commits offsets after it.
Constraints: re-read only this group, starting at 2026-11-05 00:00; preview the offset change before applying it; after the replay dwh.orders must hold each order exactly once with the fixed amount.
# 1. stop every member of the orders-loader group
# 2. move the group back to 2026-11-05 00:00 and check the result
# your code here
# 3. start the fixed loaderWrite the implementation, and say what must change in how the loader writes.
Stop the group, run kafka-consumer-groups.sh --reset-offsets --to-datetime 2026-11-05T00:00:00.000 — --dry-run plans, --execute applies. Retention caps how far back you go. The reload must replace rows from Nov 5 on (delete + insert or MERGE), or it appends duplicates.
- Resetting offsets while group members are still active, which the tool refuses for a live group
- Expecting
auto.offset.resetto rewind a group that already has committed offsets - Replaying into an append-only load and cleaning up only the broken days, while the replay re-reads everything up to now
- When would you replay into a new
group.idand a side table instead of rewinding the production group? - What does a replay from offset 0 return on a compacted topic, and why is that not the full history?
An offset reset works on one group at a time and only when that group has no active members, so first stop every orders-loader pod. Without --execute the command only prints the plan (--dry-run is the default). A datetime without a zone is read as UTC; for another zone add the offset, e.g. 2026-11-05T00:00:00.000+03:00. Default retention is 7 days, so Nov 5 is still in the topic; data older than retention cannot come back from Kafka.
# 2. plan: where each partition's offset will move
kafka-consumer-groups.sh --bootstrap-server kafka:9092 \
--group orders-loader --topic orders \
--reset-offsets --to-datetime 2026-11-05T00:00:00.000 --dry-run
# apply
kafka-consumer-groups.sh --bootstrap-server kafka:9092 \
--group orders-loader --topic orders \
--reset-offsets --to-datetime 2026-11-05T00:00:00.000 --execute
# check: CURRENT-OFFSET moved back, LAG grew
kafka-consumer-groups.sh --bootstrap-server kafka:9092 \
--describe --group orders-loaderThe replay runs from Nov 5 up to now, not just to Nov 7, so a plain INSERT would double every order since Nov 5. Before the restart, switch the loader to a write that replaces rows: MERGE / INSERT … ON CONFLICT (order_id) DO UPDATE — the fixed amount then overwrites the broken one. The alternative is to delete every dwh.orders row with order_ts >= '2026-11-05' in one transaction before the start and let the replay insert them again; the upsert is still needed, since the next crash causes another repeat. For a reload into a side table that leaves the production group alone, use a new group.id with auto.offset.reset=earliest — it reads everything retention still holds.