What if your users could start watching videos instantly without waiting for the whole file to download?
Why Streaming and chunked transfer in Nginx? - Purpose & Use Cases
Imagine you have a large video file on your server and users want to watch it online. If you try to send the whole file at once, users must wait a long time before anything starts playing.
Sending the entire file in one go means slow start times and high memory use on the server. If the connection breaks, users must restart from the beginning. This wastes time and resources.
Streaming with chunked transfer lets the server send data in small pieces as they are ready. Users start receiving and using data immediately, improving speed and reducing memory load.
proxy_pass http://backend; proxy_buffering on;
proxy_pass http://backend; proxy_buffering off; chunked_transfer_encoding on;
It enables smooth, fast delivery of large or live content without waiting for the full data to be ready.
Watching a live sports event online where the video streams continuously without pauses or delays.
Manual full-file transfer causes delays and wastes resources.
Chunked transfer sends data in small parts as ready.
This improves user experience and server efficiency.
Practice
Solution
Step 1: Understand chunked transfer encoding
Chunked transfer encoding breaks the response into smaller pieces called chunks.Step 2: Identify the benefit in streaming
This allows the client to start receiving and processing data immediately without waiting for the full response.Final Answer:
To send data in smaller parts so the client can start processing early -> Option CQuick Check:
Chunked transfer = send data in parts [OK]
- Thinking chunked transfer compresses data
- Assuming chunked transfer caches full response
- Believing chunked transfer blocks partial data
Solution
Step 1: Identify the directive for buffering control
In nginx,proxy_bufferingcontrols whether responses are buffered.Step 2: Find the correct syntax to disable buffering
Settingproxy_buffering off;disables buffering, allowing streaming.Final Answer:
proxy_buffering off; -> Option AQuick Check:
Disable buffering = proxy_buffering off [OK]
- Using non-existent directives like chunked_transfer
- Confusing buffering with streaming_enable
- Wrong syntax like buffer_response off
location /stream {
proxy_pass http://backend;
proxy_buffering off;
chunked_transfer_encoding on;
}What will happen when a client requests
/stream?Solution
Step 1: Analyze proxy_buffering off;
This disables buffering, so nginx forwards data immediately.Step 2: Analyze chunked_transfer_encoding on;
This enables chunked transfer encoding, sending data in parts.Final Answer:
Client receives data in chunks as backend sends it -> Option BQuick Check:
Buffering off + chunked on = streaming chunks [OK]
- Assuming full response is buffered before sending
- Thinking config has syntax errors
- Confusing chunked transfer with compression
proxy_buffering off; chunked_transfer_encoding off;
But streaming is slow and client waits for full response. What is the likely issue?
Solution
Step 1: Understand effect of chunked_transfer_encoding off;
Disabling chunked transfer means data is sent as one block, not in parts.Step 2: Analyze impact on streaming
Without chunked transfer, client waits for full response before receiving data, causing delay.Final Answer:
chunked_transfer_encoding off disables chunked streaming, causing delay -> Option DQuick Check:
Chunked off = no streaming chunks [OK]
- Thinking proxy_buffering off causes buffering
- Assuming gzip affects chunked streaming
- Ignoring missing proxy_pass as cause
Solution
Step 1: Disable buffering for immediate data forwarding
Setproxy_buffering off;to prevent nginx from waiting to buffer full response.Step 2: Enable chunked transfer encoding for partial data sending
Setchunked_transfer_encoding on;to send data in chunks to the client.Final Answer:
proxy_buffering off; chunked_transfer_encoding on; -> Option AQuick Check:
Disable buffering + enable chunked = streaming [OK]
- Enabling buffering blocks streaming
- Disabling chunked transfer stops chunked sending
- Mixing buffering and chunked transfer settings incorrectly
Ready to prove it?
Pass the test and this pattern moves unknown
