Quick revision
The short answer
segment.ms=60000 makes every partition roll a new segment every minute, and with one-hour retention each partition keeps about 60 segments, each with a .log, an .index and a .timeindex file, and the index files are memory-mapped. Across 6,000 partitions and their replicas that becomes hundreds of thousands of open files and memory maps per cluster, which exhausts the process open-file limit and vm.max_map_count, on top of constant rolling and deletion work. Retention only needs segments that are small relative to the retention, so segment.ms of 5 to 15 minutes would do; the guardrails are topic config policies, OS limits with headroom, and alerts on file descriptors and segment counts.
What to remember
In this answer, we followed a chain from segment.ms=60000 to failing brokers: about 60 segments per partition, three files per segment and memory-mapped indexes, multiplied by thousands of replicas, exhausting the open-file limit and vm.max_map_count while adding constant roll and delete work. We fixed it by setting segment.ms to 5 to 15 minutes, which keeps retention precise enough, and by raising OS limits with headroom, and we added topic config policies and alerts on file descriptors, maps and segment counts so one team's setting cannot break shared brokers again.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
segment.ms=60000 makes every partition roll a new segment every minute, and with one-hour retention each partition keeps about 60 segments, each with a .log, an .index and a .timeindex file, and the index files are memory-mapped. Across 6,000 partitions and their replicas that becomes hundreds of thousands of open files and memory maps per cluster, which exhausts the process open-file limit and vm.max_map_count, on top of constant rolling and deletion work. Retention only needs segments that are small relative to the retention, so segment.ms of 5 to 15 minutes would do; the guardrails are topic config policies, OS limits with headroom, and alerts on file descriptors and segment counts.
Why this question is asked
This is a typical platform incident: a reasonable-sounding change on one team's topics quietly multiplies a resource that nobody was watching, and a week later brokers start failing in confusing ways. Interviewers use it to see whether we can trace a chain of cause and effect from a topic setting to operating system limits, and whether we fix the system so it cannot happen again, not just the one topic. In this answer, we will recap why the team touched segment.ms, count what it created, see which limits break, fix it, and put guardrails in place.
1A Quick Recap of Segments and Retention
A partition's log is split into segments, and retention deletes whole segments, never single records. A segment can only be deleted when it is closed and the newest record in it is older than retention.ms. The active segment, the one being written, is never deleted.
So with the default segment.ms of 7 days, a topic with retention.ms of one hour might keep data much longer than an hour, because its active segment stays open for days on a quiet partition, or for as long as it takes to reach segment.bytes on a busy one. The team wanted retention to be precise, so they made segments roll every minute. The intent was good; the size of the fix was not.
2Counting What segment.ms=60000 Created
Rolling every minute with one hour of retention keeps about 60 closed segments per partition, plus the active one. Each segment has at least three files: .log, .index and .timeindex. The broker keeps the .log files open, and the index files are memory-mapped when used, and retention checks read every segment's time index to find its newest timestamp, so in practice they are mapped too.
Let us count for one broker. 6,000 partitions with replication factor 3 are 18,000 replicas; spread over, say, 12 brokers that is 1,500 replicas per broker on top of its existing 2,500 or so from the other 30,000.
Notice that the existing 2,500 replicas with large default segments contributed only a few thousand files. The new setting multiplied the new topics' footprint by about 60. The failures can appear days later because the count grows as partitions receive traffic and roll, and because a broker restart opens every segment at once and hits the limit hardest.
3Why the Brokers Fail and Not Just Slow Down
Each limit breaks something different. When the process reaches its open-file limit, the broker cannot open a new segment file, accept a new client connection (sockets are file descriptors too) or open a file during log loading, and these errors often stop the log directory or the broker. When the number of memory maps reaches vm.max_map_count, mapping a new index fails, typically surfacing as an out-of-memory error mentioning map failed, even though the heap is fine.
Even before the limits, the cost was showing. Every partition rolls a segment every minute, which means 6,000 rolls per minute across the cluster, each creating and preallocating index files, plus a matching stream of deletions. That is constant metadata work on the file system and extra page cache churn, for no benefit to anyone reading the data.
- segment.ms lowered to 1 minuteintent: precise one-hour retention
- About 60 segments per partitiontimes thousands of replicas per broker
- Hundreds of thousands of files and mapsplus constant rolls and deletes
- Limit reached?YesToo many open files, map failedNoSlow growth until the next restart
- Broker or log directory goes offline
5 steps in order. Play them, or step through them one at a time.
A per-topic choice consumed a per-broker resource.
4Fixing It Without Losing Precision
Retention precision only needs segments that are small compared with the retention period. With segment.ms of 10 minutes and retention of one hour, data is deleted between 60 and about 70 minutes after it was written, plus up to the 5-minute retention check interval. That is precise enough for almost any purpose, and it keeps about 7 segments per partition instead of 61, roughly a ninth of the files.
So we change segment.ms to something between 5 and 15 minutes on the affected topics. Retention will remove the extra small segments within the hour, and the file count falls on its own. In the meantime, if brokers are failing, we raise the operating system limits to get them stable: nofile to a few hundred thousand and vm.max_map_count well above the expected number of maps, for example 262,144 or more, keeping headroom for growth.
5Guardrails for the Platform
The real failure is that a single team could set a value that is dangerous for shared brokers. Kafka supports a server-side topic policy: a class named in create.topic.policy.class.name validates topic creation, and one named in alter.config.policy.class.name validates config changes. A policy can reject segment.ms below, say, five minutes, or require it to be at least a tenth of retention.ms. If topics are managed as code through a pipeline, the same rules belong in its validation step, with a clear error message that explains the reason.
Then we measure what we just learned to care about. Alert on open file descriptors per broker as a percentage of the limit, on memory map count against vm.max_map_count, and on segment count per broker and per topic. Those alerts would have fired days before the first failure.
6Follow-up questions
Why does a restart hurt more than steady state?
On startup the broker loads every partition, opening every segment and often its indexes, all at once. In steady state some indexes are mapped lazily or unmapped, so the count can sit just below the limit and only cross it when everything is touched together during a restart.
Would segment.bytes have been a better lever?
Not for this goal. A small segment.bytes rolls by size, so busy partitions get many segments and quiet ones still keep an open segment for days. segment.ms rolls by time, which is what retention by time needs, as long as the value is moderate.
Is there any downside to raising vm.max_map_count a lot?
Each map costs a little kernel memory, so very large values are not free, but values in the hundreds of thousands are common for Kafka and search systems. The limit is a safety net; the real fix is not creating so many segments.
7Conclusion
In this answer, we followed a chain from segment.ms=60000 to failing brokers: about 60 segments per partition, three files per segment and memory-mapped indexes, multiplied by thousands of replicas, exhausting the open-file limit and vm.max_map_count while adding constant roll and delete work. We fixed it by setting segment.ms to 5 to 15 minutes, which keeps retention precise enough, and by raising OS limits with headroom, and we added topic config policies and alerts on file descriptors, maps and segment counts so one team's setting cannot break shared brokers again.
Open with
The chain starts with the team's reasonable goal. Retention deletes whole closed segments, so with default segments the data lived much longer than an hour, and they set segment.ms to one minute.
Then, if they want more
That makes every partition roll every minute, so with one-hour retention each partition keeps about 60 segments.
Each segment has a .log, an .index and a .timeindex file, the log files stay open, and the index files are memory-mapped, so with thousands of replicas per broker we get hundreds of thousands of open files and more memory maps than the Linux default vm.max_map_count of 65,530.
Brokers then fail with too many open files or map failed errors, often when they restart and open everything at once, and before that they were already doing thousands of segment rolls and deletions every minute.
The fix is that precision only needs segments small relative to retention, so segment.ms of 5 to 15 minutes gives retention within a few minutes of an hour with a ninth of the files. I would change that on the affected topics, let retention clean up, and raise nofile and vm.max_map_count with headroom to stabilise the brokers.
Then I would add guardrails: a create and alter topic config policy that rejects tiny segment.ms values, the same rule in our topics-as-code pipeline, and alerts on file descriptors, map count and segments per broker.
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 "Explain the chain of cause and effect, and the platform guardrails you would put in place.": https://scrivio-interview-library.netlify.app/spring-boot/kafka-internals/7990f0dba0/