Kafka: Retention deletes by time or size, not by consumption

A record is not removed because it was read; it is removed when the policy says so.

Code
# 7 days (default)
retention.ms=604800000
# or by size per partition
retention.bytes=1073741824
Output
A consumer offline for eight days on a 7-day topic
restarts to OffsetOutOfRangeException and jumps to auto.offset.reset.
Advertisement

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-08-11