Leveraging Server-Sent Events (SSE) for Efficient Data Streaming in UI Development
How does ChatGPT stream responses so quickly? The answer is a classic web technology that's making a major comeback.
#1about 6 minutes
The core problem of long-running HTTP requests
A simple demo illustrates poor user experience when a backend operation takes several seconds to complete, leaving the UI unresponsive.
#2about 6 minutes
Manually streaming data with HTTP chunks
Learn how to send partial responses from a Node.js server using `response.write` and process them on the client with `ReadableStream` and `TextDecoder`.
#3about 7 minutes
Introducing the Server-Sent Events protocol
The SSE protocol simplifies streaming by using a `data:` prefix and the browser's built-in `EventSource` API, which also handles automatic retries.
#4about 4 minutes
Using named events for structured messages
The SSE protocol supports sending named events using the `event:` key, allowing for more structured communication handled by specific event listeners on the client.
#5about 5 minutes
Ensuring reliable delivery with message IDs
Implement robust streaming by using the `id:` field in SSE messages, which enables the client to automatically send a `Last-Event-ID` header upon reconnecting.
#6about 7 minutes
Why SSE is relevant again because of OpenAI
OpenAI's streaming API uses Server-Sent Events extensively, leading to a resurgence of the technology for building real-time AI applications.
#7about 6 minutes
Building a streaming client for the OpenAI API
A practical demo shows how to use the OpenAI SDK, which abstracts SSE into a `for await` loop, and then stream the results from your server to the client using SSE.
#8about 12 minutes
Q&A on SSE implementation and best practices
Discussion covers topics like connection timeouts, keep-alive messages, server scalability for many connections, and use cases beyond text streaming.
Related jobs
Jobs that call for the skills explored in this talk.
Matching moments
05:56 MIN
Streaming data to web clients with SSE
Development of reactive applications with Quarkus
02:14 MIN
Comparing SSE, WebSockets, and polling for real-time data
Streaming AI Responses in Real-Time with SSE in Next.js & NestJS
01:24 MIN
Understanding SSE limitations and its key benefits
Streaming AI Responses in Real-Time with SSE in Next.js & NestJS
02:16 MIN
Implementing an SSE endpoint in NestJS for AI streaming
Streaming AI Responses in Real-Time with SSE in Next.js & NestJS
03:58 MIN
A full-stack architecture for streaming AI responses
Streaming AI Responses in Real-Time with SSE in Next.js & NestJS
02:15 MIN
Consuming SSE streams in Next.js with EventSource
Streaming AI Responses in Real-Time with SSE in Next.js & NestJS
02:18 MIN
Scaling SSE applications for thousands of concurrent users
Streaming AI Responses in Real-Time with SSE in Next.js & NestJS
The Best Upcoming IT WebinarsNow that you already know what IT webinars are and how they can help you level up your professional appeal, you might want actually to get into one. Live tech webinars are one of the best ways to stay on top of the latest trends and tools because eit...
Gerry Schneider
I have a stream! Why it’s definitely worth speaking at tech conferences.Giving talks at certain events is a longed-for goal for many developers. For a good reason: it is the perfect opportunity to share your expertise and passion for a specific topic, help others learn from your mistakes, drive awareness of your solution...
Chris Heilmann
WeAreDevelopers LIVE days are changing - get ready to take partStarting with this week's Web Dev Day edition of WeAreDevelopers LIVE Days, we changed the the way we run these online conferences. The main differences are:Shorter talks (half an hour tops)More interaction in Q&AA tips and tricks "Did you know" sect...
Chris Heilmann
All the videos of Halfstack London 2024!Last month was Halfstack London, a conference about the web, JavaScript and half a dozen other things. We were there to deliver a talk, but also to record all the sessions and we're happy to share them with you. It took a bit as we had to wait for th...
From learning to earning
Jobs that call for the skills explored in this talk.