Skip to main content
InterviewHubPRO
Section Overview
Q25

Question 25 of 50

Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)

50%
Apache Kafka Streaming (50 Qs)•Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)

Kafka Storage Internals: How Segment Files (`.log`), Index Files (`.index`), and Time Indexes (`.timeindex`) work.

senior LevelMost AskedCode ExampleSystem DesignApache KafkaMicroservices

In Simple Words: Each partition directory on a broker disk contains segment files:

css
/var/lib/kafka/data/orders-0/
├── 00000000000000000000.log         # Raw message bytes
├── 00000000000000000000.index       # Offset-to-physical-byte-position index
├── 00000000000000000000.timeindex   # Timestamp-to-offset index
└── leader-epoch-checkpoint

Fast Offset Lookup Mechanics:

  1. Kafka does not index every single message (sparse indexing every 4KB via index.interval.bytes).
  2. When a consumer requests Offset 45,000:
    • Kafka performs a binary search on the memory-mapped .index file to find the nearest offset $\le 45,000$ (e.g., Offset 44,950 at byte position 1,245,000).
    • The OS seeks directly to byte position 1,245,000 in the .log file and scans sequentially until it reaches Offset 45,000.
    • Result: Lookup completes in sub-millisecond time even in multi-terabyte partitions.