In Next.js App Router, Route Handlers can stream responses using the Web Streams API via ReadableStream or TransformStream. This allows data to be sent to the client progressively — chunk by chunk — instead of waiting for the entire response to be ready.
Streaming is useful when you have long-running operations like AI text generation, large data exports, or real-time logs. Instead of the client waiting for the full response, it starts receiving and rendering data immediately as chunks arrive.
AI/LLM responses — stream tokens as they are generated (e.g. ChatGPT-style)
Large data exports — stream CSV/JSON rows without loading all data into memory
Real-time logs — stream server logs or job progress to the client
Long-running computations — send partial results as they become available
Server-Sent Events (SSE) — push updates from server to client over HTTP
Always set 'Cache-Control: no-cache' for streaming responses to prevent buffering
Use 'Transfer-Encoding: chunked' for plain streams and 'text/event-stream' for SSE
Always call controller.close() when done — leaving streams open causes memory leaks
Edge Runtime supports streaming natively and has lower latency than Node.js runtime
Node.js runtime may buffer small chunks — use flush() or increase chunk size if needed
ReadableStream is a Web API — available in both Edge and Node.js runtimes in Next.js 13+
For AI streaming, Vercel AI SDK abstracts all of this with useChat and useCompletion hooks
ReadableStream — one-time large response, file downloads, AI completions
SSE (text/event-stream) — server pushing multiple updates over time, live feeds, notifications
WebSocket — full duplex, both client and server send messages, chat apps, collaboration tools
We need to send a large CSV file to the client using a Next.js route handler. How would you set up the handler to stream the file instead of loading it all into memory?
If you forget to set the correct headers when streaming a response, what behavior would the browser exhibit?
You added a streaming response to an API route, but the client sometimes receives a truncated response under load. Walk me through how you'd debug this.
Explain the trade‑offs between using Next.js Edge Functions versus Node.js route handlers for streaming large JSON payloads.
Our service streams video chunks from an external service through a Next.js route. How would you design the handler to handle back‑pressure and ensure low latency at scale?
What considerations would you make for caching and CDN when serving streamed responses from Next.js, and how would you configure them?
We plan to migrate several legacy monolith endpoints to Next.js with streaming responses. How would you structure the architecture to minimize impact on existing services and allow incremental rollout?
Discuss the long‑term maintenance implications of using streaming responses in a micro‑frontend architecture that shares a Next.js app across teams.