Scrivio Interview library
DebuggingFoundations7 min read · updated 13 November 2026

At 02:00 an alert reports that /var/kafka/data on four of nine brokers is 88 percent full and rising about 2 percent an hour. Yesterday a team released a change that doubled its message size.

Which commands and metrics do you use to find what is growing, what do you do in the next hour, and what must you not do?

First we find which topics grew, with kafka-log-dirs.sh on the four brokers and the per-topic BytesInPerSec metric, which will point to the team whose message size doubled. With 12 percent left at 2 percent an hour we have about six hours, so we decide quickly whether the owning team can roll back or we must act, and the usual relief is lowering retention.ms on that topic, which frees closed segments within minutes. If retention cannot be cut we add disk or move partitions with a throttled reassignment, and we never delete segment files by hand or restart brokers to free space.

Why this question is asked

A filling disk is one of the few Kafka problems with a deadline we can calculate. When a broker cannot write to its log directory, the partitions on it go offline, and if the same thing happens on several brokers at once, whole topics stop. The alert came at 02:00, so we are probably alone, and the temptation is to do something drastic. Interviewers want to see us stay methodical rather than drastic. In this answer, we will recap how Kafka uses disk, find what is growing, estimate the time we have, apply short-term relief, look at what to do when retention cannot be cut, and finish with what we must not do.

1A Quick Recap: How Kafka Uses Disk

Each partition replica is a directory of segment files. New records are appended to the active segment; when it reaches segment.bytes (1 GB by default) or segment.ms, Kafka closes it and starts a new one. Retention then deletes whole closed segments that are older than retention.ms (7 days by default) or that push the partition over retention.bytes. The active segment is never deleted by retention, however old its first record is.

This explains the growth we see. If a team doubles its message size, the bytes written per hour double, and for the next 7 days, until retention catches up with the change, disk use grows every hour. Because of replication factor 3, each produced byte lands on three brokers, which is why four of nine brokers are filling at the same time: they hold the replicas of the busy partitions.

2Finding What Is Growing

Two tools answer the question from different sides. kafka-log-dirs.sh reports the size of every replica on the brokers we name, so it tells us who is using the space. The per-topic BytesInPerSec metric tells us whose write rate changed, which tells us who is causing the growth.

Java
kafka-log-dirs.sh --bootstrap-server kafka-1:9092 --describe --broker-list 1,4,6,8 > dirs.json
# JSON: brokers -> logDirs -> partitions with "partition" and "size"; summed per topic:
# 2140.3 GB clickstream.events <- the topic of the team that changed message size
# 410.8 GB orders.v2
# 220.1 GB payments.ledger
# Per-topic write rate (MBean, via JMX or the exporter):
# kafka.server:type=BrokerTopicMetrics,name=BytesInPerSec,topic=clickstream.events
# yesterday 18 MB/s -> today 37 MB/s

Notice that the size list and the rate change point to the same topic, which matches yesterday's release. If they did not agree, for example if a topic were large but its rate had not changed, the cause might be a retention change or a stuck consumer of a compacted topic instead, and we would look there.

3How Long Do We Have?

Before deciding anything, we estimate time to full. The disks are 88 percent full and grow about 2 percent an hour, so 12 percent remains and we have roughly 12 / 2 = 6 hours. In practice we should act earlier than 100 percent, since a broker in trouble near full disk may already struggle with log rolls and index files, so the real budget is closer to four or five hours.

That budget decides who acts. Six hours is enough to wake the owning team's on-call and ask for a rollback or agreement to lose older data, which is the best outcome because they own the data. If they cannot be reached in, say, an hour, we act alone, with a step that is safe and reversible enough to defend in the morning.

Step throughThe first hour
  1. Identify the growing topiclog-dirs sizes and BytesInPerSec
  2. Estimate time to full12% left at 2%/h = about 6 h
  3. Owning team reachable?
    YesAgree rollback and retention changeNoAct alone with a safe step
  4. Lower retention on that topicfrees closed segments in minutes
  5. Retention cannot be cut?
    YesAdd disk or throttled reassignmentNoWatch disk fall, write up

5 steps in order. Play them, or step through them one at a time.

4Short-Term Relief: Lowering Retention

The quickest safe relief is to keep less history on the offending topic. Retention is a dynamic topic config, so we change it without restarting anything.

Java
kafka-configs.sh --bootstrap-server kafka-1:9092 --alter \
--entity-type topics --entity-name clickstream.events \
--add-config retention.ms=86400000 # keep 1 day instead of 7
# Completed updating config for topic clickstream.events.
kafka-configs.sh --bootstrap-server kafka-1:9092 --describe \
--entity-type topics --entity-name clickstream.events
# retention.ms=86400000 sensitive=false synonyms={DYNAMIC_TOPIC_CONFIG:retention.ms=86400000, ...}

Brokers check retention every log.retention.check.interval.ms, 5 minutes by default, so within a few minutes the closed segments older than one day are deleted and disk use drops. There is a catch: the cost is that consumers can no longer read data older than one day, and any consumer that was further behind will skip ahead according to its auto.offset.reset. That is a business decision, which is why we prefer the owning team to agree. Later, once the disks are healthy, we can raise retention again; the deleted data does not come back, but new data is kept for longer.

5When Retention Cannot Be Cut

Sometimes the data must be kept, for example because a downstream job needs to replay a week. Then we add space or move load. On cloud brokers we can often grow the volume online. Otherwise we move some partitions from the four full brokers to brokers with free space using kafka-reassign-partitions.sh with a throttle, so the copy traffic does not starve producers. Moving data briefly uses more space on the target and network on both sides, so we start early and move the largest partitions of the busy topic first.

In parallel we ask the team to fix the cause: roll back the message size change, or enable producer compression. Setting compression.type=zstd or lz4 on the producer typically shrinks text-like payloads such as JSON events by a factor of three to five, which would more than undo a doubled message size and also reduce network traffic. Because compression happens in the producer, no broker change is needed.

6What We Must Not Do

Two shortcuts look tempting at 02:00 and both make things worse. The first is deleting segment files by hand in /var/kafka/data. The broker keeps its own view of each log's segments, indexes and offsets; removing files behind its back leaves that view inconsistent, which can corrupt the log, break followers that fetch those offsets, and force a long recovery when the broker next starts.

The second is restarting a broker to free space. A restart does not delete data, and a broker that starts on a nearly full disk must recover its logs and rebuild indexes, which needs space; if it fails, its partitions stay offline and the remaining replicas carry the load of an already stressed cluster. Retention changes, reassignment and producer fixes are slower, but they are the steps that keep the data safe.

7Follow-up questions

Why did the disk usage drop only a few minutes after we changed retention.ms?

Because retention runs as a periodic check, every log.retention.check.interval.ms, which is 5 minutes by default. At the next check, the broker deletes closed segments older than the new limit. The active segment stays until it rolls, so a partition that rolls rarely may keep more data than expected.

Could we use retention.bytes instead of retention.ms?

Yes. retention.bytes caps the size per partition, not per topic, so with 24 partitions a limit of 20 GB keeps up to 480 GB of one replica set, times the replication factor on disk. It is useful for topics with unpredictable volume, because it bounds disk use even if the rate jumps again.

8Conclusion

In this answer, we saw that disk grows because retention deletes only closed segments after the retention time, so a doubled message size keeps adding bytes for days. We found the topic with kafka-log-dirs.sh and per-topic BytesInPerSec, estimated about six hours to full, and lowered retention.ms on that topic as the quickest safe relief. When data must be kept, we add disk or reassign partitions with a throttle while the team rolls back or enables compression. We never delete segment files by hand or restart brokers to free space.

What to say in the interviewAbout 90 seconds aloud

Open with

First I would find what is growing. kafka-log-dirs.sh describe on brokers 1, 4, 6 and 8 gives the size of each replica, and summing per topic shows the biggest one; the per-topic BytesInPerSec metric shows whose write rate changed.

Then, if they want more

I would expect both to point to the topic of the team that doubled message size yesterday. Then I estimate the time: 12 percent left at 2 percent an hour is about six hours, really four or five to be safe, so I try to reach the owning team, but I am prepared to act alone.

The quickest relief is lowering retention.ms on that topic with kafka-configs.sh alter; the broker checks retention every five minutes by default, so closed segments go soon after. The cost is losing older data, which I would record and ideally agree with the team.

If the data has to be kept, I grow the volumes or move partitions to brokers with free space using a throttled reassignment, and ask the team to roll back or turn on zstd or lz4 compression in the producer.

What I must not do is delete segment files by hand, which corrupts the logs, or restart brokers to free space, because a restart frees nothing and a broker starting on a full disk can leave partitions offline. Afterwards I would add alerts on time to full, not just percentage.

About this answer

Last updated
13 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Apache Kafka documentation
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Which commands and metrics do you use to find what is growing, what do you do in the...": https://scrivio-interview-library.netlify.app/spring-boot/kafka-operations/782acdf4c9/