AlgoViz

Server-sent events

easy 27 min

Server-sent events (SSE) is one ordinary HTTP answer that does not end.

Where it shows up

The same pattern appears across everyday software.

  • Wikimedia EventStreams

    Edits of Wikipedia and its sister projects as a public SSE stream, backed by Kafka. The Last-Event-ID carries the place in the log, and because connections are ended after 15 minutes, clients resume all the time.

  • Language model APIs

    Anthropic's and OpenAI's APIs stream answers as server-sent events. The question is a POST, so clients use fetch or a library.

  • Model Context Protocol

    Its Streamable HTTP transport uses POST and GET, and a server may answer with an SSE stream to send several messages.

  • FastAPI

    The Python framework has SSE built in since version 0.135.0, with a response class for events and a guide to resuming.

  • Build logs

    The page shows each line when it is written. The line number is the id, so a reload continues at the right place.

  • Live scores

    A goal is one small event to very many readers. A delay of a second is fine, and nobody needs to send.