Skip to content
Kafka Is FunProgress

IntermediateInternals

How does Kafka use sendfile() for zero-copy transfer?

Reference answer

Kafka uses Java NIO's FileChannel.transferTo() which maps to the OS-level sendfile() system call. For consumer fetch requests, Kafka reads the segment file and sends it directly to the network socket — WITHOUT copying data from kernel space to user space and back. This zero-copy transfer reduces CPU usage and memory bandwidth. Compression breaks zero-copy (data must be decompressed/recompressed), which is why network-based decompression is one reason to prefer broker-side decompression when consumers have diverse compression support.

Expected key concepts: sendfile(), zero-copy, FileChannel.transferTo(), kernel space, user space, network socket, CPU, compression, memory bandwidth