Why Streaming Feels Faster Than Waiting: A Simple Guide to SSE
A simple guide to Server-Sent Events (SSE) and why streaming makes AI applications feel much faster.
Have you ever clicked "send" and then just... waited? A spinner turns. Nothing shows up. Then, all of a sudden, a big block of text appears at once.
That wait is annoying. There's a better way. You've already seen it — every time ChatGPT or Claude types out an answer word by word, like someone typing live. That's not a trick. It's a real technology called Server-Sent Events, or SSE.
Let's break down how it works, in plain words.
The Old Way: Wait, Then Get Everything
Most apps work like this:
- You ask the server for something.
- The server does all the work.
- When it's fully done, it sends back the whole answer at once.
- You finally see something.
If the job takes 10 seconds, you wait 10 seconds and see nothing. Then everything shows up at once. This is fine for small, fast tasks. But for anything that takes a while — like an AI writing a long answer — it feels slow and broken.
You: "Give me an answer"
[waiting... waiting... waiting...]
Server: [dumps the whole answer at once]The New Way: Show Progress As It Happens
With SSE, the server doesn't wait until everything is ready. It sends small pieces of the answer as soon as each piece is done.
You: "Give me an answer" Server: "The" Server: " quick" Server: " brown" Server: " fox..."
The total time might be the same. But now you see something right away. It feels much faster, even if it isn't.
How SSE Works, Simply
Good news: SSE is not some fancy new tech. It's just normal HTTP — the same thing your browser uses to load web pages. The only difference is the server keeps the connection open and keeps sending small updates, instead of closing it after one big reply.
The server sends messages like this, one after another:
data: {"token": "The"}
data: {"token": " quick"}
data: {"token": " brown"}
data: [DONE]Each line starting with data: is one small update. The browser reads these as they arrive.
A Simple Server Example (Node.js)
app.get('/stream', (req, res) => {
res.setHeader('Content-Type', 'text/event-stream');
res.setHeader('Cache-Control', 'no-cache');
res.setHeader('Connection', 'keep-alive');
const words = ['The', 'quick', 'brown', 'fox', 'jumps'];
let i = 0;
const interval = setInterval(() => {
if (i >= words.length) {
res.write('data: [DONE]\n\n');
clearInterval(interval);
return res.end();
}
res.write(`data: ${JSON.stringify({ token: words[i] })}\n\n`);
i++;
}, 300);
});A Simple Client Example (Browser)
const evtSource = new EventSource('/stream');
evtSource.onmessage = (event) => {
if (event.data === '[DONE]') {
evtSource.close();
return;
}
const { token } = JSON.parse(event.data);
document.getElementById('output').textContent += token;
};That's the whole thing. No extra tools needed.
SSE vs Polling vs WebSockets
People often get confused between these three. Here's the simple version:
| Polling | SSE | WebSockets | |
|---|---|---|---|
| How it works | Client keeps asking again and again | Server sends updates on its own | Both sides can send anytime |
| Setup | Very simple | Simple | More complex |
| Reconnects on its own | No | Yes | No |
| Best for | Rare updates | One-way updates (AI text, live logs) | Chat apps, games |
Simple rule: If only the server needs to send updates, use SSE. If both sides need to talk back and forth a lot, use WebSockets.
Why This Matters for AI Apps
If you're building anything with AI, streaming is expected now. Here's why:
- It feels faster. Seeing words appear one by one feels quicker than waiting for a big block of text.
- You can stop early. If the user has read enough, they can cancel — saving time and cost.
- Long answers don't feel painful. No one likes staring at a blank screen for 15 seconds.
Most AI APIs, including Anthropic's, support this. You just turn on stream: true in your request.
When You Don't Need SSE
Streaming adds some extra work. Skip it when:
- The task finishes in under a second anyway.
- It's a small, simple request.
- There's nothing useful to show until the whole answer is ready.
Only use streaming when showing progress actually helps the user.
The Simple Takeaway
Don't think of your answer as one big package you deliver at the end. Think of it as small pieces you deliver as soon as they're ready. SSE is the easiest way to do that. It's just HTTP, it works everywhere, and it turns "please wait" into "watch it happen."