Partitions: The Unit of Parallelism
- A topic is split into partitions, and partitions are spread over brokers
- Each partition is an ordered log. Order is guaranteed inside a partition only
- More partitions allow more consumers in a group to work in parallel (one partition is read by at most one consumer of the same group)
- More partitions also mean more open files, more replication work and longer recovery. Do not create thousands without a reason
Offsets
Every record in a partition gets a sequential number, its offset. Offsets are not reused and are unique only within one partition. A consumer remembers which offset it has processed. The group's progress is stored in an internal Kafka topic called __consumer_offsets.
How Data Is Stored on Disk
A partition is a folder of segment files. Kafka writes to the newest (active) segment and starts a new one when it reaches log.segment.bytes (default 1 GB) or log.roll.hours. Old segments are deleted as a whole file, which is very cheap.
Retention: How Long Data Is Kept
| Setting | Meaning | Default |
|---|---|---|
retention.ms (topic) / log.retention.hours (broker) | Delete segments older than this | 7 days |
retention.bytes | Delete oldest segments when a partition exceeds this size | unlimited |
segment.bytes | Size of one segment file | 1 GB |
cleanup.policy | delete (time or size based) or compact | delete |
Log Compaction
With cleanup.policy=compact, Kafka keeps at least the latest value for every key and removes older values of the same key. It behaves like a table that holds the current state.
Uses: current customer profiles, product catalogs, the changelog of a stream processing state store, __consumer_offsets.
Replication
- Each partition has one leader and zero or more followers. Producers and consumers talk to the leader
- Followers continuously fetch new data from the leader
- The ISR (in-sync replica set) is the leader plus followers that are caught up
- If the leader fails, one member of the ISR becomes the new leader (no data loss for acknowledged writes when configured correctly)
| Setting | Meaning | Typical production value |
|---|---|---|
replication.factor | Copies of each partition | 3 |
min.insync.replicas | Minimum ISR size needed to accept writes with acks=all | 2 |
unclean.leader.election.enable | Allow an out-of-sync replica to become leader (can lose data) | false |
Why Is Kafka So Fast?
- Sequential disk writes: appending to a log is much faster than random writes
- OS page cache: Kafka relies on the operating system cache instead of its own big cache, so restarts stay warm
- Zero-copy: data goes from disk or cache to the network without copying into application memory (
sendfile) - Batching and compression: producers and brokers handle batches of records
- Partitioning: work is spread over many brokers and disks
Quick Quiz
- Can two consumers of the same group read the same partition at the same time? (No)
- Can two consumers of different groups read the same partition? (Yes)
- Does reading a record delete it? (No, retention does)
- What happens to ordering if you add partitions? (Keys may map to new partitions, so order for a key can change over time)
Conclusion
Kafka stores each partition as an append-only log of segment files, keeps data by time or size (or latest per key with compaction), and replicates partitions to followers. Sequential IO, page cache and zero-copy make it fast.

