Big Data 5 min read

How Kafka Achieves High Throughput: Sequential Writes, Zero‑Copy, Partitioning, and More

This article explains the key techniques Kafka uses to maximize throughput, including sequential disk writes with zero‑copy, partition‑based parallelism, batch processing with compression, and configurable asynchronous replication for balancing performance and reliability.

Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
How Kafka Achieves High Throughput: Sequential Writes, Zero‑Copy, Partitioning, and More

Sequential Writes and Zero‑Copy

Kafka appends messages to the log file of each partition using strictly sequential disk writes. Sequential I/O maximizes disk bandwidth and eliminates seek latency. Kafka relies on the operating‑system page cache: data is first written to memory pages, which the kernel later flushes to disk in large contiguous blocks, further improving throughput.

Zero‑copy is used when serving data to consumers. Instead of copying bytes from the file buffer to a user‑space buffer and then to the network socket, the kernel’s sendfile (or similar) system call transfers data directly from the file descriptor to the socket. This removes an extra memory copy, reduces CPU cycles and increases network throughput.

Partitioning and Parallel Processing

Each Kafka topic is split into a configurable number of partitions. A partition is an ordered, immutable sequence of records stored on a single broker. Because partitions are independent, producers can write to many partitions concurrently, and consumer groups can read different partitions in parallel. This natural parallelism enables linear scaling of throughput as the number of partitions (and brokers) grows.

Load balancing is achieved by assigning partitions to brokers based on the cluster’s partition‑assignment algorithm. Consumers in the same consumer group each own a subset of partitions, guaranteeing that each message is processed by only one consumer instance while the group as a whole can scale horizontally.

Batch Transfer and Compression

Both producers and consumers operate on batches of records. A producer aggregates multiple records into a single request (the produce batch) before sending it to the broker. The broker writes the entire batch to the log in one sequential operation, which reduces per‑message overhead such as request headers and network round‑trips.

Consumers request batches of records using the fetch API. The broker returns a batch that may contain many records from the same partition, allowing the consumer to process data with fewer network calls.

Kafka clients can optionally compress the batch before transmission. Supported algorithms are gzip, snappy, and lz4. Compression reduces the amount of data sent over the wire and stored on disk at the cost of additional CPU for (de)compression. The choice of algorithm is a trade‑off between compression ratio and CPU usage.

Asynchronous Replication and Configurable Persistence

Kafka replicates each partition to a set of follower brokers. The leader handles all reads and writes; followers continuously pull the leader’s log and stay in‑sync (ISR). Replication is asynchronous by default: the leader acknowledges a write after it is persisted to its local log, without waiting for followers to confirm.

The producer can control durability through the acks configuration: acks=0 – fire‑and‑forget; the producer does not wait for any acknowledgment. acks=1 – the leader’s acknowledgment is sufficient. acks=all (or -1) – the leader waits until all in‑sync replicas have written the record.

Higher acks values increase durability but add latency. Because writes are local log appends and replication proceeds in the background, Kafka can sustain high per‑node throughput while still offering strong consistency when required.

Batch ProcessingKafkazero-copyCompressionHigh ThroughputPartitioningAsync Replication
Mike Chen's Internet Architecture
Written by

Mike Chen's Internet Architecture

Over ten years of BAT architecture experience, shared generously!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.