<aside> 🎙️
Date: Wednesday, October 21, 2026 · Week 4, Day 24 · Type: Build Day + Live Session 7 (7:30 PM IST, 90 min)
</aside>
24.1 The User Experience of Latency — why waiting 10 seconds for a full paragraph feels broken, while streaming words immediately feels instantaneous.
24.2 Server-Sent Events (SSE) — how HTTP streaming works over a single persistent connection.
24.3 Python Generators — using yield to stream tokens asynchronously from an LLM API to a web browser.
Add a streaming endpoint GET /stream?prompt=... to your FastAPI application that streams tokens in real time using Server-Sent Events (SSE) so words appear one by one as they are generated.
+---------------+ +--------------------+ +-------------------+ +------------------+
| Web Browser | <-- | SSE Event Stream | <-- | FastAPI Generator | <-- | LLM Token Stream |
+---------------+ +--------------------+ +-------------------+ +------------------+
Problem 24. Write an asynchronous Python generator function fake_token_stream(text: str) that splits a string into words and yields them one by one formatted as Server-Sent Events (data: {"token": "word"}\n\n) with a 50ms simulated delay between tokens.
Data Structure: Async Generator Stream Buffer.
Mechanics: Coroutine-based iterator yielding data chunks without blocking the main event loop.
Real-World Production Use: Standard streaming response architecture used in Vercel AI SDK, OpenAI API, and FastAPI streaming responses.