Symptoms
- The topic's disk usage drops sharply on every broker within minutes.
- Lagging consumers log
OffsetOutOfRangeExceptionor "Resetting offset for partition ...". Then they jump toearliest(skipping deleted data) orlatest(skipping everything), depending onauto.offset.reset. - Consumers with
auto.offset.reset=nonestop with an error instead. - The log start offset for the topic's partitions has moved up to, or close to, the end offset.
- A change ticket, a Terraform plan or a
kafka-configs --alterrecently touchedretention.ms,retention.bytesorcleanup.policyon this topic. Sometimes the cause is a units mistake: seconds entered where milliseconds were expected.
The broker's retention check runs every log.retention.check.interval.ms (default 5 minutes). It deletes whole segments whose newest record is older than the retention. After one or two checks, most of the topic can be gone.
Caution
Kafka has no undo for deleted segments. Every minute the wrong value stays in place, more data is deleted. Revert the config first, then investigate.
1. Revert the retention override now
See what is set on the topic:
kafka-configs.sh --bootstrap-server $BS --entity-type topics --entity-name orders --describe
If the original value was the broker default, delete the override:
kafka-configs.sh --bootstrap-server $BS --entity-type topics --entity-name orders \
--alter --delete-config retention.ms
If the topic had its own value, put it back explicitly, for example 7 days:
kafka-configs.sh --bootstrap-server $BS --entity-type topics --entity-name orders \
--alter --add-config retention.ms=604800000
Also check retention.bytes. On a size-based policy it removes old segments just as fast. Confirm with --describe that the change applied.
Warning
If the topic is managed by Terraform, Strimzi
KafkaTopicor another operator, also fix the value in code, or pause the reconciler. Otherwise it re-applies the bad value at its next sync.
Check whether the same change hit other topics. A bulk script usually touches more than one:
kafka-configs.sh --bootstrap-server $BS --entity-type topics --describe --all \
| grep -B1 -E "retention\.(ms|bytes)=.*DYNAMIC_TOPIC_CONFIG"
2. Protect the consumers
Pause consumer groups that act on data (billing, notifications, CDC sinks) before they reset to latest and skip records. Stop the deployment, or scale it to zero:
kubectl scale deployment billing-consumer --replicas=0 -n payments
Consumers that already reset need their offsets corrected after replay (step 5). Note which groups reset and when. The application logs show the reset with the old and new offset.
3. Size the gap
Compare the current earliest offsets with what consumers had committed:
# Earliest available offset per partition (-2 = earliest, -1 = latest)
kafka-get-offsets.sh --bootstrap-server $BS --topic orders --time -2
kafka-get-offsets.sh --bootstrap-server $BS --topic orders --time -1
# Committed offsets and lag per group
kafka-consumer-groups.sh --bootstrap-server $BS --describe --group billing
For each partition, records between a group's committed offset (before reset) and the new log start offset were deleted before that group read them. Records the group had already processed are gone from Kafka but were delivered.
| Group state | Impact |
|---|---|
| Lag was zero when retention dropped | No data lost for this group |
Lagging, auto.offset.reset=earliest | Skipped deleted records, then carried on |
Lagging, auto.offset.reset=latest | Skipped deleted records and all remaining backlog |
auto.offset.reset=none | Stopped with an error; offsets untouched; skipped nothing yet |
Find when the change happened and who made it. With an authorizer and request logging, look for AlterConfigs or IncrementalAlterConfigs on the topic:
grep -E "IncrementalAlterConfigs|AlterConfigs" /var/log/kafka/kafka-authorizer.log | grep orders | tail
On MSK, use CloudTrail for control-plane changes. Topic config changes made through the Kafka API show up only in broker logs, if you deliver them.
4. Recover the deleted records
Use the best source you have:
| Source | How |
|---|---|
| MirrorMaker 2 replica on another cluster | Check that the mirror topic kept its own retention (MM2 can sync topic configs, so the bad value may have spread). Replay the gap back with a consumer-producer job. |
| Sink copy (S3, ADLS, a database via Kafka Connect) | Re-publish the gap window in key order, or reprocess downstream directly from the sink |
| Upstream source (CDC, outbox table, files) | Replay or re-snapshot the window from the source |
| Tiered storage | Remote segments are deleted by the same retention rules, so check before relying on them |
| Nothing | Record the gap per partition and tell consumers |
Example replay of a bounded window from a mirror cluster with kcat, keeping keys:
kcat -C -b $MIRROR_BS -t primary.orders -K: -e \
-o s@1794556800000 -o e@1794560400000 \
| kcat -P -b $BS -t orders -K:
s@ and e@ are start and end timestamps in milliseconds. Replayed records get new offsets and, by default, new timestamps. Use a small producer program if headers or original timestamps matter.
Caution
Replay produces duplicates for any group that had already processed part of the window. Confirm downstream deduplication by event ID before you restart non-idempotent consumers.
5. Fix consumer offsets and restart
Point each paused or reset group to where it should resume. Preview first:
kafka-consumer-groups.sh --bootstrap-server $BS --group billing --topic orders \
--reset-offsets --to-datetime 2026-11-13T07:50:00.000 --dry-run
kafka-consumer-groups.sh --bootstrap-server $BS --group billing --topic orders \
--reset-offsets --to-datetime 2026-11-13T07:50:00.000 --execute
The group must have no active members when you reset. If replayed records carry new timestamps, --to-datetime will not find them by their original time. Use --to-offset per partition (--topic orders:3) based on where the replay landed.
Then scale consumers back up and watch lag fall.
6. Verify recovery
--describeon the topic shows the intended retention, and the reconciler or IaC agrees.- The log start offset stops moving, apart from normal retention.
- Consumer groups are stable, lag is falling, and there are no new offset-out-of-range resets.
- Downstream record counts for the incident window match the source or the mirror.
Communicate
Give each consumer team the deleted range per partition (or per time window), whether it was replayed, and whether duplicates are possible. Data that could not be recovered goes in the incident report with the exact window.
Prevent it next time
- Manage topic configs in code with review. Add a policy check that rejects
retention.msbelow a floor on production topics. - Restrict
AlterConfigson topics with ACLs, so only the provisioning principal can change them. - Set
auto.offset.reset=noneon consumers where skipping data is worse than stopping. - Alert on sudden drops in topic size and on jumps in the log start offset (JMX
kafka.log:type=Log,name=LogStartOffset). - Keep a mirror or sink of critical topics. See recovering a deleted Kafka topic for the full replay pattern.
Get the weekly HubDatAI email
One email a week with everything new: posts, learning sessions and videos. Free, no spam, unsubscribe in one click. What you get