Incidents & Postmortems Bug Report Paid

Kafka consumer offline past retention: data deleted and auto.offset.reset skipped the rest

A consumer paused for nine days lost two days of events to retention, then auto.offset.reset=latest skipped the seven days that still existed. Expired group offsets, retention.ms and a silent default combined. Recovery steps and the alerting that prevents it.

Grace Liu Grace Liu @graceliu · December 02, 2026 · 7 min read · 19 Views
658-kafka-retention-deleted-unconsumed-data

During a database migration we paused the ledger-sync consumer, which copies account-transactions events into the finance reporting warehouse. The migration ran long, and the consumer stayed scaled to zero for nine days. When we scaled it back up, it started instantly, reported zero lag within seconds, and looked healthy.

Three weeks later finance found that reports for the nine-day window were missing about 4.1 million transactions. Not just the first two days, which would have been explained by the topic's 7-day retention, but all nine days.

The consumer log on restart had the clue, at INFO level:

INFO [Consumer clientId=ledger-sync-0, groupId=ledger-sync] Found no committed offset for partition account-transactions-0
INFO [Consumer clientId=ledger-sync-0, groupId=ledger-sync] Resetting offset for partition account-transactions-0 to position FetchPosition{offset=88412907, offsetEpoch=Optional.empty, currentLeader=LeaderAndEpoch{leader=Optional[broker2:9092 (id: 2 rack: null)], epoch=14}}.

"Found no committed offset" meant the group had forgotten its position entirely.

Reproducing it

On a test cluster with shortened timers:

# broker: offsets.retention.minutes=5 ; topic: retention.ms=600000 (10 min)
kafka-console-consumer.sh --bootstrap-server broker1:9092 --topic tx --group sync --max-messages 10
# stop the consumer, keep producing for 15 minutes, then start it again
kafka-console-consumer.sh --bootstrap-server broker1:9092 --topic tx --group sync

The restarted consumer prints only records produced after it started, even though the last ten minutes of records are still in the topic.

What we ruled out

  • Topic retention alone. Retention explains the oldest two days being deleted, not the skipping of the remaining seven.

  • A bug in the sink. The warehouse loader showed no errors; it never received the records.

  • Someone resetting offsets. Audit logs for admin operations showed no --reset-offsets command.

Root cause

Three settings lined up:

  1. Topic retention (retention.ms) of 7 days deleted the first two days of events while the consumer was off.

  2. Committed offsets expire. When a consumer group has no active members, the broker keeps its committed offsets for offsets.retention.minutes, 7 days by default. After nine days, the group's offsets were gone.

  3. auto.offset.reset=latest (the default) decides where a consumer starts when it has no valid committed offset. "Latest" means "skip everything currently in the topic and wait for new records". So the seven days of events that still existed were skipped.

What is happening under the hood

A consumer group's position is a committed offset per partition, stored in the internal __consumer_offsets topic. On startup the consumer fetches its committed offset. Two situations make it fall back to auto.offset.reset:

  • No committed offset: the group is new, or its offsets expired after the group was empty for longer than offsets.retention.minutes.

  • Offset out of range: the committed offset is older than the partition's log start offset because retention deleted those records. The consumer logs that the fetch position is out of range and resets.

The reset policies:

Value

Behaviour

Risk

latest (default)

Start at the end

Silently skips everything retained

earliest

Start at the oldest retained record

Reprocesses everything retained; can be days of work

none

Throw an exception

Consumer fails loudly; needs a human or automation

Newer clients also offer a duration-based reset (KIP-1106, added in Kafka 4.0) that starts from a point in time in the past; check that your client version supports it before relying on it.

Environment

Component

Version / value

Apache Kafka

3.9.0, KRaft, 6 brokers

Topic account-transactions

12 partitions, retention.ms=604800000 (7 days)

Broker offsets.retention.minutes

10080 (default, 7 days)

Consumer

Java client 3.9.0, auto.offset.reset=latest (default)

Lag alert

records-lag-max > 100000, only while the consumer is running

The lag alert never fired: with zero running consumers there is no consumer-side metric to alert on, and when the consumer restarted it reported zero lag because it had jumped to the end.

Who is affected

  • Any consumer that can be stopped for days (batch jobs, migrations, disabled features, seasonal services).

  • Consumers relying on the default auto.offset.reset=latest for data that must not be skipped.

  • Teams that alert on consumer-side lag metrics only.

This is a paid story

Subscribe to read the full content, access all paid stories, and support the authors.

Add a label

#kafka #offsets #consumer-lag #retention #auto-offset-reset
Written by
Grace Liu @graceliu

I am an application and cloud security engineer. Most of my day is spent with development teams: reviewing designs, untangling IAM policies, hardening AWS accounts and making security checks fast enough that nobody wants to skip them. I believe security works best when it is concrete. Instead of long lists of best practices, my posts look at one decision at a time: a policy that granted more than intended, a design reviewed before the first line of code, a deletion that did not delete. Each one ends with checks you can run on your own systems.

Advertisement

Comments

0

No comments yet. Be the first to comment!

Sign In to post a comment.