Scrivio Interview library
ConceptFoundations7 min read · updated 13 November 2026

On a broker you list the directory /var/kafka/data/orders-3 and see files such as 00000000000005120000.log, .index, .timeindex and .snapshot, plus leader-epoch-checkpoint and partition.metadata.

What is each file for, and what does the long number in the file names mean?

The directory orders-3 holds partition 3 of the topic orders, and its log is split into segments. Each segment has a .log file with the record batches, an .index file that maps offsets to byte positions, a .timeindex file that maps timestamps to offsets, and possibly a .snapshot of producer state and a .txnindex of aborted transactions. The long number is the segment's base offset, the offset of its first record, padded to 20 digits, so 00000000000005120000 starts at offset 5,120,000. leader-epoch-checkpoint records where each leader epoch started, and partition.metadata stores the topic id.

Why this question is asked

When a broker misbehaves, sooner or later we end up looking at its data directory: to find which segment holds an offset, to see why retention is not deleting anything, or to understand a recovery after a crash. Interviewers ask this because naming each file and its job shows that we understand how Kafka stores data rather than treating it as a black box. In this answer, we will recap partitions and segments, decode the file names, go through each file type and its purpose, and see why only one segment is ever written to.

1A Quick Recap of Partitions and Segments

A Kafka topic is split into partitions, and each partition is an append-only log: records get increasing offsets, 0, 1, 2 and so on, and are never changed in place. On disk, every partition replica that a broker hosts gets its own directory under one of the broker's log.dirs, named topic-partition. So /var/kafka/data/orders-3 is partition 3 of orders.

Keeping a partition in one huge file would make deleting old data expensive, because we would have to rewrite the file. So Kafka splits the log into segments, each a set of files covering a range of offsets. Deleting old data then means deleting old segment files, which is cheap. A new segment starts, or rolls, when the current one reaches segment.bytes (1 GiB by default) or segment.ms (7 days by default).

2Decoding the File Names

Every file that belongs to a segment is named after the segment's base offset, the offset of the first record in it, padded with zeros to 20 digits. The padding makes the names sort correctly as text, so a directory listing shows segments in offset order.

Shell
$ ls /var/kafka/data/orders-3
00000000000004800000.index 00000000000005120000.index
00000000000004800000.log 00000000000005120000.log
00000000000004800000.timeindex 00000000000005120000.timeindex
00000000000005120000.snapshot leader-epoch-checkpoint
partition.metadata
# segment 1 covers offsets 4,800,000 .. 5,119,999
# segment 2 starts at 5,120,000 and is the active segment

Notice that the base offset of one segment tells us where the previous one ended. If we look for offset 5,000,000, it must be in the segment starting at 4,800,000, because the next one starts at 5,120,000. The broker uses exactly this rule to find data, as we will see.

The .snapshot file has the same naming style, but its number is the offset the producer state was taken at, not a segment start, although in practice snapshots are taken when a segment rolls, so the numbers often match.

3The Data and Index Files

The .log file holds the actual data: record batches in Kafka's v2 batch format, written exactly as producers sent them (after the broker assigned offsets). Everything else in the directory exists to find things in this file quickly or to recover correctly.

The .index file is the offset index. It maps an offset, stored relative to the base offset to save space, to a byte position in the .log file. It is sparse: it has an entry only every index.interval.bytes of log data (4096 bytes by default), not for every record. To find an offset, the broker binary-searches the index for the closest entry at or below it and scans forward from there.

The .timeindex file is the time index. It maps a timestamp to the first offset at or after it. Two features need it: lookups by time, such as resetting a consumer group to a point in time, and time-based retention, which must know how old the newest record in a segment is.

Files in a partition directory
FileHoldsUsed for
NNN.logrecord batchesthe data itself
NNN.indexrelative offset -> byte position (sparse)finding an offset quickly
NNN.timeindextimestamp -> offsettime lookups, time retention
NNN.snapshotproducer ids, epochs, sequencesidempotence after restart
NNN.txnindexaborted transaction rangesread_committed consumers
leader-epoch-checkpointepoch -> start offsetsafe truncation after leader change
partition.metadatatopic iddetecting a recreated topic

4Producer State, Transactions and Epochs

The .snapshot files store producer state: for each active producer id, its epoch and the sequence number of its last batches. An idempotent producer tags each batch with these, and the broker rejects duplicates by comparing them. If the broker lost this state on restart, it could not recognise a retry of a batch written just before the crash. Loading the latest snapshot and replaying the log after it rebuilds the state quickly.

A .txnindex file appears for segments that contain aborted transactions. It lists the ranges of offsets that belong to aborted transactions, so a consumer with isolation.level=read_committed can be told which records to skip without the broker rewriting the log.

leader-epoch-checkpoint is a small text file with one line per leader epoch: the epoch number and the first offset written in that epoch. After a leader change, a replica uses it to work out exactly where its log stops matching the new leader's log and truncates only the divergent tail. partition.metadata stores the topic's unique id, so if someone deletes orders and creates a new orders, a broker with a leftover directory can tell that the old data belongs to a different topic.

Shell
$ cat leader-epoch-checkpoint
0 # version
3 # number of entries
5 4100000 # epoch 5 started at offset 4,100,000
6 4955310
7 5120044

5Why Only the Active Segment Is Written

Only the newest segment, the active segment, receives appends. When it rolls, it becomes immutable: its files are never changed again, apart from the index files being trimmed to their real size. That immutability is what makes the rest cheap. Retention can delete a whole old segment by unlinking its files. Compaction can build a cleaned copy of old segments and swap it in. Reads from old segments can be served from the page cache or sent with zero-copy, without coordinating with writers.

There is one consequence that surprises people: the active segment is never deleted by retention and never compacted. A quiet topic whose active segment stays open for days keeps its old records for days, which is a common reason why data outlives retention.ms.

6Follow-up questions

Why is the offset in the index stored relative to the base offset?

Because a relative offset fits in four bytes while an absolute offset needs eight. Each index entry is then just eight bytes, a four-byte relative offset and a four-byte position, which keeps the index small enough to stay memory-mapped. This also limits a segment to about two billion offsets, far more than any real segment holds.

Can I delete old segment files by hand to free disk?

We should not. The broker tracks segments in memory and in checkpoint files, and deleting files under it can cause errors or a failed log recovery. To free space, lower retention.ms or retention.bytes on the topic, or move partitions with a reassignment, and let the broker delete segments itself.

What are the .deleted and .cleaned suffixes I sometimes see?

They are temporary states. When retention removes a segment, the broker first renames its files with a .deleted suffix and deletes them after file.delete.delay.ms, so readers still using the files can finish. The log cleaner writes compacted output to .cleaned files and swaps them in with a .swap step. They normally disappear on their own.

7Conclusion

In this answer, we saw that a partition directory holds the partition's log split into segments, each named by its 20-digit base offset. The .log file holds the record batches, the sparse .index and the .timeindex find data by offset and by time, .snapshot files preserve producer state for idempotence, .txnindex tracks aborted transactions, leader-epoch-checkpoint guides truncation after leader changes, and partition.metadata identifies the topic. Only the active segment is written; older ones are immutable until retention or compaction removes or rewrites them.

What to say in the interviewAbout 80 seconds aloud

Open with

The directory name orders-3 means partition 3 of the orders topic on this broker. The partition's log is split into segments so old data can be deleted by removing whole files.

Then, if they want more

Every segment file is named by its base offset, the first offset in that segment, padded to 20 digits, so 00000000000005120000 starts at offset 5,120,000, and the previous segment ends just before it. For each segment, the .log file holds the record batches themselves.

The .index file is a sparse map from relative offset to byte position, with an entry every 4 KB or so, which the broker binary-searches before scanning forward. The .timeindex maps timestamps to offsets, which is used for time-based lookups like resetting a group to a timestamp and for time-based retention.

The .snapshot files store producer state, meaning producer ids, epochs and last sequence numbers, so idempotent deduplication survives a restart, and a .txnindex, if present, lists aborted transactions for read_committed consumers. leader-epoch-checkpoint records the start offset of each leader epoch, which a replica uses to truncate correctly after a leader change, and partition.metadata holds the topic id.

Only the newest segment, the active one, receives writes; older segments are immutable until retention deletes them or compaction rewrites them.

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 "What is each file for, and what does the long number in the file names mean?": https://scrivio-interview-library.netlify.app/spring-boot/kafka-internals/2540864912/