Skip to content
Kafka Is Fun

Lesson 3 of 5

Message Retention

1 min read

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

Topic-level settings (broker names in parentheses)properties
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

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.

Browse all troubleshooting entries