---
title: "Why your Kafka topic ignores retention.ms (and how to fix it)"
description: "A Kafka topic configured with retention.ms=43200000 (12 hours) retained messages for four days because the active log segment never rolled. Kafka retains data by deleting whole closed segments, not individual records, and an active segment remains writable and cannot be deleted. Segment rolling occurs when segment.bytes or segment.ms is reached; in this case, traffic was too modest to fill the 1-GiB segment and only four days had passed, short of the seven-day default. Once a segment closes, retention.ms is evaluated against its newest record, followed by the retention check interval and file.delete.delay.ms before physical deletion. The proposed fix is to set segment.ms to a fraction of the retention window (one hour for the 12-hour example), while tuning segment.bytes as needed; a smaller rolling cadence makes effective retention more predictable."
---

# Why your Kafka topic ignores retention.ms (and how to fix it)

[Red Hat](https://yomu.fyi/company/red-hat) · Rogerio Santos · Sep 16, 2026

**Type:** Tutorial

## Summary

A Kafka topic configured with retention.ms=43200000 (12 hours) retained messages for four days because the active log segment never rolled. Kafka retains data by deleting whole closed segments, not individual records, and an active segment remains writable and cannot be deleted. Segment rolling occurs when segment.bytes or segment.ms is reached; in this case, traffic was too modest to fill the 1-GiB segment and only four days had passed, short of the seven-day default. Once a segment closes, retention.ms is evaluated against its newest record, followed by the retention check interval and file.delete.delay.ms before physical deletion. The proposed fix is to set segment.ms to a fraction of the retention window (one hour for the 12-hour example), while tuning segment.bytes as needed; a smaller rolling cadence makes effective retention more predictable.

## Context

The post explains why Kafka retention can substantially exceed retention.ms when records remain in an active segment. It covers segment files, rolling thresholds, retention eligibility, cleanup timing, and a low-throughput topic whose 12-hour policy allowed messages to remain readable for four days.

## Approach / What changed

Make the active segment roll within the retention window by reducing segment.ms, optionally adjusting segment.bytes. The example reduced segment.ms to one hour for a 12-hour retention period, and a later demonstration changed it to two minutes for a 10-minute policy so closed segments could become eligible for deletion sooner.

## Takeaways

- Kafka deletes closed log segments rather than individual messages; records in the active segment cannot be deleted until that segment rolls.
- retention.ms is evaluated against the newest record in a closed segment, and physical deletion also waits for the retention check interval and file.delete.delay.ms.
- Set segment.ms to a fraction of the retention window when predictable expiry matters; the suitable value depends on the topic’s retention requirements and traffic.

## FAQ

### Why can records older than retention.ms remain readable?

Records can remain in the active segment, which Kafka never deletes. The segment must first roll because segment.bytes or segment.ms has been reached; only then can retention evaluate the closed file.

### Does retention.ms start from the oldest record in a segment?

No. Kafka evaluates retention against the timestamp of the segment’s newest record. After that record becomes old enough, the retention check interval and file.delete.delay.ms add further time before physical deletion.

### Why change segment.ms instead of lowering retention.ms?

In the described case, retention.ms was already correct; the segment simply had not rolled. Reducing segment.ms makes segments close within the desired retention window, allowing retention to act sooner without changing the policy.

**Tags:** [Kafka](https://yomu.fyi/topic/kafka)

- Source: [Red Hat](https://developers.redhat.com/articles/2026/09/16/why-your-kafka-topic-ignores-retentionms-and-how-fix-it)
- Source URL: https://developers.redhat.com/articles/2026/09/16/why-your-kafka-topic-ignores-retentionms-and-how-fix-it
- Ingested by Yomu: 2026-09-16T20:01:02.173Z

[Read original post](https://developers.redhat.com/articles/2026/09/16/why-your-kafka-topic-ignores-retentionms-and-how-fix-it)
