Lesson 2 of 9 · 24m
Offsets, Retention, and Replay as First-Class Features
Learn how consumer offsets differ from record positions, how retention deletes data independently of consumption, and how replay changes application design.
The most expensive Kafka misunderstanding I see is treating offsets like queue acknowledgements. They are not acknowledgements. An offset is a bookmark in a durable log. Kafka may retain the record for seven days, seven years, or forever depending on topic policy, regardless of whether your consumer read it. That difference is the reason replay is powerful — and the reason data can vanish while everyone swears the consumer "acked" it.
Two offsets that people constantly confuse
Each record has an offset in its partition. Each consumer group tracks a committed position for that partition:
partition 3: records at 81200..81204; group committed=81202; next poll=81203
log-end/high watermark=81209Committing 81202 means records through offset 81202 are considered processed by that group. It does not delete them and does not prove your database transaction succeeded unless you engineered that relationship.
Retention is time, size, or compaction policy
Inspect the effective topic configuration before making promises:
kafka-configs.sh --bootstrap-server kafka-1:9092 --entity-type topics --entity-name payments.authorized --describeTypical output includes keys like:
retention.ms=604800000 retention.bytes=-1 cleanup.policy=delete
segment.ms=604800000 min.insync.replicas=2Seven days is 604800000 milliseconds. If your deployment pipeline breaks for ten days, Kafka does not care that your consumer was down; eligible segments may be gone. Replay is bounded by retention.
Replay means your application must tolerate repetition
Resetting a group is ordinary operational work:
kafka-consumer-groups.sh --bootstrap-server kafka-1:9092 --group invoice-projector --topic payments.authorized --reset-offsets --to-earliest --executeThat single command can reprocess millions of records. If the consumer sends email, creates charges, or mutates state blindly, replay becomes an incident generator. Build idempotent handlers. Store deterministic event IDs. Upsert projections instead of blindly appending side effects.
insert into invoice_projection (event_id, invoice_id, state, updated_at)
values ($1, $2, $3, $4) on conflict (event_id) do nothing;Compaction changes the meaning of the log
A compacted topic retains at least the latest record for each key within active log segments. This is excellent for state restoration and terrible if you expect every historical mutation to survive forever:
kafka-topics.sh --bootstrap-server kafka-1:9092 --create --topic customer-profiles --partitions 12 --replication-factor 3 --config cleanup.policy=compact --config min.insync.replicas=2Tombstones — records with a key and null value — eventually remove prior state for that key. Compaction is not instantaneous; it is a retention process, not a transactional delete.
Field notes
- A committed consumer offset is per group; two groups can read the same partition at completely different positions.
- Lag is measured against log-end offset, not against "messages waiting in a queue."
- Resetting offsets affects the whole group. Test with a small consumer group or paused side effects first.
- Record timestamps can be producer-controlled depending on topic and producer settings; do not blindly trust them as event time.
- Retention is a storage contract. If compliance or recovery requires thirty days, configure and verify thirty days.
Was this lesson helpful?