Messaging

Kafka Internals: The Storage Layer, Zero-Copy, and High Throughput

How does Kafka hit 1M+ messages per second? A technical deep dive into Log-Structured Storage, Zero-Copy optimization, and the OS Page Cache.

Sachin Sarawgi·April 20, 2026·2 min read
#kafka#internals#zero-copy#performance#storage#distributed-systems

Kafka Internals: The Quest for 10M msg/sec

Apache Kafka is often described as a distributed streaming platform, but its heart is a Distributed Commit Log. Its ability to handle massive throughput with sub-millisecond latency is due to several ingenious architectural choices.

1. Mechanical Sympathy: Sequential I/O

Kafka treats every partition as a strictly append-only Log File. Random disk access is 1000x slower than sequential access. By only appending to the end of files, Kafka hits the physical hardware limits of the disk.

2. The Zero-Copy Revolution

In a traditional system, sending a file to a socket involves multiple context switches and data copies between kernel space and application space.

The Zero-Copy Path: Kafka uses the sendfile() system call. It tells the kernel to move data directly from the OS Page Cache to the NIC Buffer, skipping the application space entirely. This frees up the CPU and dramatically reduces memory bandwidth usage.

![Diagram comparing the standard 4-copy data flow vs. the Zero-Copy 2-copy flow]

3. Relying on the OS Page Cache

Kafka doesn't try to manage its own memory cache. Instead, it relies on the Operating System.

  • The Secret: If you have 64GB of RAM and Kafka is only using 4GB, the OS will automatically use the remaining 60GB to cache the log segments.
  • Reboot Resilience: If the Kafka process restarts, the cache remains in the OS kernel, making recovery near-instant.

4. ISR and Replication

Kafka ensure durability through the ISR (In-Sync Replicas) set.

  • acks=all: Maximum safety. The write is only acknowledged once all members of the ISR have confirmed it.
  • High Watermark (HW): This is the offset of the last message that was successfully replicated to all ISR members. Consumers can only read up to the HW.

![Log structure diagram showing Segment files (.log) and their companion Index files (.index)]

Summary

Kafka’s performance isn't magic; it's a result of respecting the hardware and the operating system. By prioritizing sequential I/O and leveraging Zero-Copy, Kafka remains the gold standard for high-throughput messaging.


Next: Mastering Kafka Consumer Groups Previous: The Transactional Outbox Pattern: Reliability Guide


Related Guides

📚

Recommended Resources

Designing Data-Intensive ApplicationsBest Seller

The definitive guide to building scalable, reliable distributed systems by Martin Kleppmann.

View on Amazon
Kafka: The Definitive GuideEditor's Pick

Real-time data and stream processing by Confluent engineers.

View on Amazon
Apache Kafka Series on Udemy

Hands-on Kafka course covering producers, consumers, Kafka Streams, and Connect.

View Course

Practical engineering notes

Get the next backend guide in your inbox

One useful note when a new deep dive is published: system design tradeoffs, Java production lessons, Kafka debugging, database patterns, and AI infrastructure.

No spam. Just practical notes you can use at work.

Sachin Sarawgi

Written by

Sachin Sarawgi

Engineering Manager and backend engineer with 10+ years building distributed systems across fintech, enterprise SaaS, and startups. CodeSprintPro is where I write practical guides on system design, Java, Kafka, databases, AI infrastructure, and production reliability.

Found this useful? Share it: