Bird
Raised Fist0
Nginxdevops~10 mins

Streaming and chunked transfer in Nginx - Step-by-Step Execution

Choose your learning style10 modes available
Process Flow - Streaming and chunked transfer
Client sends HTTP request
↓
Nginx receives request
↓
Nginx starts processing response
↓
Response data generated in chunks
↓
Nginx sends each chunk immediately
↓
Client receives chunks progressively
↓
Last chunk sent with zero size
↓
Client knows response is complete
Nginx receives a request and sends the response in small pieces called chunks immediately as they are ready, letting the client start using data before the full response is done.
Execution Sample
Nginx
location /stream {
  proxy_pass http://backend;
  proxy_buffering off;
  chunked_transfer_encoding on;
}
Nginx config to stream response from backend to client using chunked transfer encoding without buffering.
Process Table
StepActionNginx StateData Sent to ClientNotes
1Client sends request to /streamWaiting for backend responseNoneRequest received, no data sent yet
2Nginx forwards request to backendWaiting for backend responseNoneProxying request
3Backend starts sending first chunkReceived first chunkChunk 1 dataNginx sends chunk immediately
4Backend sends second chunkReceived second chunkChunk 1 data + Chunk 2 dataStreaming continues
5Backend sends third chunkReceived third chunkChunks 1-3 dataData sent progressively
6Backend sends last zero-length chunkReceived last chunkAll chunks + zero-length chunkIndicates end of response
7Nginx closes connectionResponse completeFull response received by clientStreaming finished
💡 Last zero-length chunk signals end of streaming, so nginx stops sending data.
Status Tracker
VariableStartAfter Step 3After Step 4After Step 5After Step 6Final
Nginx bufferemptyChunk 1 dataChunk 1+2 dataChunk 1+2+3 dataFull data + zero-length chunkempty after send
Client received datanoneChunk 1 dataChunk 1+2 dataChunk 1+2+3 dataFull responseFull response
Key Moments - 3 Insights
Why does nginx send data in chunks instead of waiting for the full response?
Because proxy_buffering is off and chunked_transfer_encoding is on, nginx streams data immediately to reduce delay, as shown in steps 3-5 where chunks are sent progressively.
How does the client know when the response is complete?
The client detects the last zero-length chunk sent in step 6, which signals the end of the streamed response.
What happens if proxy_buffering is on instead?
Nginx would wait to collect more data before sending, so chunks would not be sent immediately, delaying client reception (not shown in this trace).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what data has the client received after step 4?
AChunk 1 data only
BChunk 1 and Chunk 2 data
CAll chunks including last zero-length chunk
DNo data yet
💡 Hint
Check the 'Data Sent to Client' column at step 4 in the execution table.
At which step does nginx send the last zero-length chunk to signal the end of the response?
AStep 6
BStep 5
CStep 3
DStep 7
💡 Hint
Look for the step mentioning 'last zero-length chunk' in the 'Action' column.
If proxy_buffering was enabled, how would the 'Data Sent to Client' column change at step 3?
AChunk 1 data would be sent immediately
BAll chunks would be sent at once
CNo data would be sent yet
DZero-length chunk sent first
💡 Hint
Recall that proxy_buffering off allows immediate sending; enabling it delays sending.
Concept Snapshot
Streaming and chunked transfer in nginx:
- proxy_buffering off disables buffering
- chunked_transfer_encoding on sends data in chunks
- Nginx forwards chunks immediately as backend sends
- Client receives data progressively
- Last zero-length chunk signals end of response
Full Transcript
When a client requests data from nginx configured for streaming and chunked transfer, nginx forwards the request to the backend server. As the backend generates data, it sends it in small pieces called chunks. Nginx immediately forwards each chunk to the client without waiting for the full response, because proxy_buffering is turned off and chunked_transfer_encoding is enabled. The client receives these chunks progressively, allowing it to start processing data sooner. When the backend finishes, it sends a last zero-length chunk, which nginx forwards to signal the end of the response. This method reduces latency and improves user experience for large or slow responses.

Practice

(1/5)
1. What is the main purpose of enabling chunked transfer encoding in nginx streaming?
easy
A. To block the client from receiving partial data
B. To compress all data before sending it to the client
C. To send data in smaller parts so the client can start processing early
D. To cache the entire response before sending it

Solution

  1. Step 1: Understand chunked transfer encoding

    Chunked transfer encoding breaks the response into smaller pieces called chunks.
  2. Step 2: Identify the benefit in streaming

    This allows the client to start receiving and processing data immediately without waiting for the full response.
  3. Final Answer:

    To send data in smaller parts so the client can start processing early -> Option C
  4. Quick Check:

    Chunked transfer = send data in parts [OK]
Hint: Chunked transfer means sending data in parts, not all at once [OK]
Common Mistakes:
  • Thinking chunked transfer compresses data
  • Assuming chunked transfer caches full response
  • Believing chunked transfer blocks partial data
2. Which nginx directive disables response buffering to enable streaming with chunked transfer?
easy
A. proxy_buffering off;
B. chunked_transfer on;
C. streaming_enable yes;
D. buffer_response off;

Solution

  1. Step 1: Identify the directive for buffering control

    In nginx, proxy_buffering controls whether responses are buffered.
  2. Step 2: Find the correct syntax to disable buffering

    Setting proxy_buffering off; disables buffering, allowing streaming.
  3. Final Answer:

    proxy_buffering off; -> Option A
  4. Quick Check:

    Disable buffering = proxy_buffering off [OK]
Hint: Disable buffering with 'proxy_buffering off;' in nginx config [OK]
Common Mistakes:
  • Using non-existent directives like chunked_transfer
  • Confusing buffering with streaming_enable
  • Wrong syntax like buffer_response off
3. Given this nginx config snippet:
location /stream {
  proxy_pass http://backend;
  proxy_buffering off;
  chunked_transfer_encoding on;
}

What will happen when a client requests /stream?
medium
A. Client receives the full response only after backend finishes sending
B. Client receives data in chunks as backend sends it
C. Client connection will be refused due to syntax error
D. Client receives compressed data without chunking

Solution

  1. Step 1: Analyze proxy_buffering off;

    This disables buffering, so nginx forwards data immediately.
  2. Step 2: Analyze chunked_transfer_encoding on;

    This enables chunked transfer encoding, sending data in parts.
  3. Final Answer:

    Client receives data in chunks as backend sends it -> Option B
  4. Quick Check:

    Buffering off + chunked on = streaming chunks [OK]
Hint: Buffering off + chunked on means streaming chunks to client [OK]
Common Mistakes:
  • Assuming full response is buffered before sending
  • Thinking config has syntax errors
  • Confusing chunked transfer with compression
4. You configured nginx with:
proxy_buffering off;
chunked_transfer_encoding off;

But streaming is slow and client waits for full response. What is the likely issue?
medium
A. Missing gzip on directive slows down streaming
B. proxy_buffering off causes buffering and delays streaming
C. proxy_pass directive is missing, so no backend connection
D. chunked_transfer_encoding off disables chunked streaming, causing delay

Solution

  1. Step 1: Understand effect of chunked_transfer_encoding off;

    Disabling chunked transfer means data is sent as one block, not in parts.
  2. Step 2: Analyze impact on streaming

    Without chunked transfer, client waits for full response before receiving data, causing delay.
  3. Final Answer:

    chunked_transfer_encoding off disables chunked streaming, causing delay -> Option D
  4. Quick Check:

    Chunked off = no streaming chunks [OK]
Hint: Chunked transfer must be on for streaming, else client waits [OK]
Common Mistakes:
  • Thinking proxy_buffering off causes buffering
  • Assuming gzip affects chunked streaming
  • Ignoring missing proxy_pass as cause
5. You want to stream a live video feed through nginx using chunked transfer. Which combination of directives correctly enables streaming with chunked transfer and disables buffering?
hard
A. proxy_buffering off; chunked_transfer_encoding on;
B. proxy_buffering on; chunked_transfer_encoding off;
C. proxy_buffering off; chunked_transfer_encoding off;
D. proxy_buffering on; chunked_transfer_encoding on;

Solution

  1. Step 1: Disable buffering for immediate data forwarding

    Set proxy_buffering off; to prevent nginx from waiting to buffer full response.
  2. Step 2: Enable chunked transfer encoding for partial data sending

    Set chunked_transfer_encoding on; to send data in chunks to the client.
  3. Final Answer:

    proxy_buffering off; chunked_transfer_encoding on; -> Option A
  4. Quick Check:

    Disable buffering + enable chunked = streaming [OK]
Hint: Disable buffering and enable chunked transfer for streaming [OK]
Common Mistakes:
  • Enabling buffering blocks streaming
  • Disabling chunked transfer stops chunked sending
  • Mixing buffering and chunked transfer settings incorrectly
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard