Overview
Kafka deletes data one log segment at a time, using time and size policies. Time-based retention (retention.ms) is judged on record timestamps: the largest timestamp in a segment sets the retention time for the whole segment, so a segment is deleted only when all of its records are older than the threshold. Size-based retention (retention.bytes) is enforced per partition: the oldest segments are deleted until the partition is back within the limit. If both policies are configured, a segment that is eligible under either is deleted.
Key configuration
retention.ms=604800000 — 7 days, the default (broker: log.retention.ms, falling back to log.retention.hours = 168)
retention.bytes=-1 — no size limit, the default (broker: log.retention.bytes)
cleanup.policy=delete — the default (broker: log.cleanup.policy)Production tip
Check yourself
A segment's oldest message is past retention.ms but its newest is not. What happens to it?
Sources
- Log implementation (4.2 documentation) (opens in a new tab)
- Topic configs (4.2 documentation) (opens in a new tab)
- Broker configs (4.2 documentation) (opens in a new tab)
- Design (4.2 documentation) (opens in a new tab)
Checked against Kafka 4.2 documentation on Oct 2026. Draft: not yet reviewed by a Kafka specialist. Releases move on, so confirm against the current documentation before you act on a number.