Nginx · The edge of your stack

How do you stream responses such as SSE through Nginx?

HardstreamingssebufferingUpdated Oct 2026
Quiz this track

Short answer

Disable proxy buffering and caching for the streaming location, keep the upstream connection open with long timeouts, and avoid gzip. Do this only for streaming endpoints because buffering otherwise improves throughput.

By default Nginx buffers upstream responses so it can free the backend connection quickly and send at the client's pace. For Server-Sent Events or long-lived streams, buffering delays events and can make the UI appear frozen.

nginx
location /events/ {
    proxy_pass http://backend;
    proxy_http_version 1.1;
    proxy_set_header Connection "";

    proxy_buffering off;
    proxy_cache off;
    gzip off;

    proxy_read_timeout 3600s;
    proxy_send_timeout 3600s;
}
Only the streaming location disables buffering; ordinary API and asset locations keep it.

Where streams break

  • An intermediate CDN or load balancer may buffer even when Nginx does not
  • Compression can hold data until a buffer fills, so disable gzip on the stream
  • Too short an idle timeout closes the connection between events
  • HTTP/1.1 chunked transfer is required for a response of unknown length
  • Long streams consume a worker connection for their lifetime, affecting capacity planning
X-Accel-Buffering: no is a response header an upstream can send to tell Nginx to disable buffering. Adding it with add_header does not change Nginx's own buffering; the proxy_buffering directive does that.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1Why does buffering delay Server-Sent Events?
  2. 2How do you stop a load balancer from buffering the stream?
  3. 3Why disable gzip for SSE?
  4. 4What capacity impact do long-lived streams have?

Say it in the interview

For SSE I disable proxy buffering and caching and turn off gzip in that specific location, then raise read and send timeouts so idle periods do not kill the connection. I keep buffering on everywhere else because it protects the backend and improves throughput. I also check the CDN and load balancer, since they can buffer independently of Nginx. Long streams consume connections, so I account for that in capacity planning.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Nginx mock interview and get scored feedback on depth, clarity and confidence.