QA
Senior LevelSystem Design & Architecture

How does Zero-Copy File Streaming (`sendfile`) eliminate CPU context switches in web servers?

❓ Interview Prompt: Explain Zero-Copy file streaming, OS `sendfile()` system call, bypassing user-space buffer copies, and high-speed static asset serving.

Standard file serving reads file bytes into a user-space application buffer before writing them back to a network socket buffer, requiring 4 CPU context switches and 4 data copies:

'sendfile()' Zero-Copy Solution:

The OS kernel transfers file data bytes directly from the Page Cache to the Network Card (NIC) buffer:

β€’
Zero user-space CPU context switches and zero memory copying! Used by NGINX and Kafka to achieve maximum network throughput.

Code Implementation Example

bash
# Inspecting NGINX sendfile zero-copy configuration:
# sendfile on; # Enables OS kernel-level zero-copy file streaming
πŸ’‘Enabling kernel-level zero-copy file streaming in NGINX.
🎯 Interview Key Takeaway

Use sendfile zero-copy kernel APIs in high-throughput file servers to eliminate user-space memory copying.

#System Design#Zero-Copy#sendfile#Kernel#Senior
Back to all System Design & Architecture Questions→

More System Design & Architecture Interview Questions

Beginner LevelSystem Design & Architecture

Explain the CAP Theorem and PACELC Theorem with real-world database examples.

Beginner LevelSystem Design & Architecture

What is Vertical Scaling (Scale Up) vs Horizontal Scaling (Scale Out)?

Beginner LevelSystem Design & Architecture

How do Load Balancers distribute traffic (Round Robin, Least Connections, IP Hash)?