Skip to main content

> CHAPTER 03 // INITIAL // 24 MIN READ

Log-Centric Streaming: Partitioning, Zero-Copy I/O & Consumer Group Protocols

Architecture of high-throughput distributed commit logs: sequential disk access mechanics, Linux kernel sendfile() zero-copy network transfer, partition key hashing, and cooperative rebalances.

Back to Manuals Library (10 Chapters)📜 Jay Kreps (The Log 2013) / Apache Kafka Architecture
CHAPTER 0324 min readJay Kreps (The Log 2013) / Apache Kafka Architecture

Log-Centric Streaming: Partitioning, Zero-Copy I/O & Consumer Group Protocols

Architecture of high-throughput distributed commit logs: sequential disk access mechanics, Linux kernel sendfile() zero-copy network transfer, partition key hashing, and cooperative rebalances.

Core Concepts:Commit Log InternalsZero-Copy sendfile()Partition Key HashingCooperative Sticky AssignorKRaft Quorum

Log-Centric Streaming: Partitioning, Zero-Copy I/O & Consumer Group Protocols

Executive Summary

Modern distributed streaming platforms discard volatile in-memory queues in favor of persistent, append-only commit logs. By modeling data streams as immutable, totally ordered sequences of events written sequentially to disk, systems like Apache Kafka and Redpanda achieve millions of messages per second with deterministic replayability.

1. The Zero-Copy Kernel Transfer Advantage

Traditional message brokers transfer data by copying bytes through multiple user-space buffers: $$\text{Disk} \rightarrow \text{OS PageCache} \rightarrow \text{App User Buffer} \rightarrow \text{Socket Buffer} \rightarrow \text{NIC}$$ This involves 4 context switches and 3 redundant memory copies.

Kafka utilizes the Linux `sendfile()` system call (Zero-Copy), bypassing user-space completely:

ARCHITECTURE FLOWCHARTLog-Centric Streaming: Partitioning, Zero-Copy I/O & Consumer Group Protocols
⚡ TinyCTO.tv

Result: CPU overhead drops by 80%, and network egress saturates 100 Gbps Ethernet interfaces directly from OS disk cache.

2. Partition Key Hashing & Total Ordering

A Kafka topic is composed of $P$ physical partitions. Strict total ordering is guaranteed only within a single partition. Messages with identical partition keys are deterministically mapped to the same partition using MurmurHash2: $$\text{Partition ID} = |\text{MurmurHash2}(\text{key})| \pmod P$$

3. Cooperative Sticky Consumer Group Rebalance

Legacy consumer group rebalance protocols (Eager Rebalance) forced all consumers in a group to revoke all assigned partitions before reallocating, causing massive latency spikes (stop-the-world rebalance storms). The Cooperative Sticky Assignor protocol resolves this:

  1. Revokes only the specific partitions that must migrate to new consumers.
  2. Unaffected consumers continue processing their existing partitions without interruption.