DevOps & CI/CD Bug Report Paid

Kafka broker died on a full disk: retention.bytes per partition and capacity math

A marketing campaign tripled clickstream volume and a Kafka broker shut itself down with No space left on device. Time-based retention alone cannot protect a disk. How we recovered, sized retention.bytes per partition and added alerts that fire days earlier.

Daniel Tran Daniel Tran @fun_dev · December 02, 2026 · 7 min read · 16 Views
655-kafka-broker-disk-full-retention-bytes-planning

On a Saturday afternoon broker 2 in our analytics Kafka cluster stopped. Ten minutes later broker 3 followed. Producers for the clickstream topic started failing with NotEnoughReplicasException, and consumer lag on every topic that had leaders on those brokers climbed. The first page said "broker 2 down"; the broker's own log said why:

ERROR Error while appending records to clickstream-31 in dir /var/lib/kafka/data
java.io.IOException: No space left on device
...
ERROR [ReplicaManager broker=2] Stopping serving replicas in dir /var/lib/kafka/data
...
ERROR Shutdown broker because all log dirs in /var/lib/kafka/data have failed

Each broker had a single 2 TB data volume, so one failed log directory meant the whole broker shut down.

Reproducing it

The trigger was traffic, not a bug. A marketing campaign launched on Friday tripled clickstream events from about 6 MB/s to 18 MB/s. clickstream had retention.ms=604800000 (7 days) and no retention.bytes. Retention by time alone meant Kafka would keep 7 days of whatever arrived, however much that was.

A smaller reproduction: create a topic with only time retention on a broker with a small volume, produce faster than the volume can hold for that period, and the broker will fail the log directory once the disk fills.

What we ruled out

  • Retention not running. The log cleaner thread for deletion (log.retention.check.interval.ms, 5 minutes) was running; it deleted segments older than 7 days as expected. Nothing was older than 7 days.

  • Stuck consumer holding data. Kafka does not keep data because consumers are behind; retention is independent of consumption.

  • A single giant partition. kafka-log-dirs.sh showed size spread evenly across the 48 clickstream partitions.

kafka-log-dirs.sh --bootstrap-server broker1:9092 --describe --broker-list 1 \
  | tail -1 | jq -r '.brokers[].logDirs[].partitions[] | "\(.size) \(.partition)"' \
  | sort -rn | head

Root cause

Disk usage is ingest rate times retention time times replication factor, divided across brokers. With 18 MB/s, 7 days and RF 3 on 6 brokers:

18 MB/s * 604800 s * 3 / 6 brokers  ≈  5.4 TB per broker

We had 2 TB per broker. At the old 6 MB/s the same math gave about 1.8 TB per broker: already 90 percent of the disk, with no margin for anything. The topic had no size cap, and no alert looked at the growth rate, only at a fixed 85 percent threshold that fired too late on a weekend.

What is happening under the hood

Kafka stores each partition as segment files. Retention never deletes individual records: it deletes whole closed segments when they are entirely older than retention.ms or when the partition is larger than retention.bytes. The active segment is never deleted. Checks run every log.retention.check.interval.ms.

Two consequences:

  • retention.bytes is per partition, not per topic. A topic with 48 partitions, RF 3 and retention.bytes=10 GB can use up to 48 * 3 * 10 GB = 1.44 TB across the cluster, plus slack.

  • Actual size overshoots the limit by up to one segment. The partition can grow to roughly retention.bytes + segment.bytes before the oldest segment is removed, plus whatever arrives during one check interval.

When a write fails with an I/O error, the broker marks the whole log directory as offline. With multiple log directories (JBOD), it keeps serving the others; with one, it shuts down. Leadership moves to other brokers, which then receive more traffic and, in our case, filled up next.

Environment

Component

Version / value

Apache Kafka

3.9.0, KRaft, 6 brokers

Storage

1 x 2 TB gp3 volume per broker, XFS

clickstream

48 partitions, RF 3, retention.ms=604800000, no retention.bytes

segment.bytes

1 GiB (default)

Ingest

6 MB/s normal, 18 MB/s during campaign

Alerting

Disk used > 85 percent only

Who is affected

  • Any topic with time-only retention and variable traffic.

  • Clusters where one topic dominates disk and has no size cap.

  • Single-volume brokers, where one full disk means a full broker outage.

  • Teams that alert on percentage used instead of time to full.

This is a paid story

Subscribe to read the full content, access all paid stories, and support the authors.

Add a label

#disk-space #kafka #capacity-planning #retention #tiered-storage
Written by
Daniel Tran @fun_dev

I have spent most of my career on the side of software that pages people at night: payment integrations, web platforms with real traffic, CI/CD pipelines, Kubernetes clusters and the databases underneath them. Somewhere along the way I started keeping a notebook of every bug that cost more than an hour — the exact error, what we ruled out, the real root cause and how we proved the fix. Hibug is where those notes live. Every post follows the same path: Investigate, Explain, Fix, Verify — with the environment spelled out, the fix tested, and the security angle checked.

Advertisement

Comments

0

No comments yet. Be the first to comment!

Sign In to post a comment.