When do you stream an LLM answer over SSE, and when do you make it an async job?
Short answer
Stream over SSE when the user reads the text as it arrives and the whole call finishes in under about 30 s; use an async job when the task is long, needs the complete result (JSON) or is batch work. Short output: a plain synchronous call.
3 points to say:
- Streaming doesn't cut total time, it only gets the first words out early; retrying mid-way is hard once half a sentence is sent.
- Streaming traps: errors arrive after HTTP 200, you need a timeout between chunks, and Nginx needs
proxy_buffering off. - Collect chunks on the server, save history when the stream ends or is cut, and mark its status.
Keep reading the deep dive
Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.