Skip to content

Zero-Copy

Medium — good to knowBackend

ELI5 - The Vibe Check

Normally, sending a file over the network means the OS copies its bytes from disk into your program's memory, then your program hands it to the OS again to copy into the network buffer, the same data gets duplicated over and over for no real reason. Zero-copy is the trick of skipping those pointless in-between copies entirely, letting the kernel move data straight from the disk cache to the network card without your program's memory ever touching it.

Real Talk

Zero-copy refers to I/O techniques that eliminate unnecessary copying of data between kernel space and user space buffers, typically by using operating system calls like sendfile or splice that let the kernel transfer data directly between a file descriptor and a socket. It significantly reduces CPU usage and memory bandwidth consumption for I/O-heavy workloads like serving static files or proxying data at scale.

Show Me The Code

// Linux sendfile: kernel copies file data straight to the socket,
// skipping the userspace round trip
ssize_t n = sendfile(socket_fd, file_fd, &offset, count);

When You'll Hear This

"Nginx uses sendfile for zero-copy static file serving." / "We cut CPU usage in half on the proxy by switching to zero-copy transfers."

Made with passive-aggressive love by manoga.digital. Powered by Claude.