Implement Server-Sent Events

text/event-stream framing

Challenge 4 of Networking & ProtocolsIntermediate~45 min

Push updates to a browser over one long-lived HTTP response, no WebSocket handshake required. Implement the text/event-stream wire format: serialize events with data, event, and id fields, then parse a raw stream back into structured events, handling multi-line payloads, comments, and reconnection ids. The transport behind live dashboards, notifications, and token-by-token AI streaming.

4 steps

  1. 1Serializing an Event
  2. 2Fields: event, id, retry
  3. 3Parsing a Stream
  4. 4Comments and Round-Tripping
Start step 1