Server-Sent Events

In this chapter, we use server-sent events to stream an AI assistant’s replies in CourseChat, and then compare server-sent events with WebSockets.

After reading this chapter, you should be able to:

  • Contrast a conversation with an AI assistant with a chat room, and say why the conversation needs no server push
  • Estimate the requests that polling and long polling send for one reply, and say why a WebSocket also fits it poorly
  • Read a streamed response in the server-sent events format
  • Decide which errors get a status code and which are sent as an event
  • Identify what an open stream costs the server, and why a buffering proxy must be turned off for it
  • Compare streaming a reply in one request with streaming it in two: how each recovers from a dropped connection, and how each stops a reply
  • Choose between server-sent events and a WebSocket for a feature

Sections

  1. CourseChat
  2. Waiting for the Reply
  3. Server-Sent Events
  4. One Request or Two
  5. SSE or a WebSocket