Server-Sent Events

Software development patterns | assess

Server-Sent Events (SSE) is a one-way communication method allowing the server to send the data to the client, without the client having to make a request. It doesn't offer the client-to-server communication possibility as Web Sockets, but that is completely fine in many use cases such as stock level updates, push notifications, or live results.

Even when bidirectional communication is not required, there are some caveats to keep in mind

  • SSE doesn't support binary data, only UTF-8 encoded characters.
  • There is a limit to the maximum number of open connections per browser, although the limit when using HTTP/2 is 100 by default, so it shouldn't be a problem in most scenarios.

SSE is much easier to set up and offers some advantages over Web Sockets such as built-in reconnection possibility or the use of the HTTP protocol and all its benefits—such as compression or multiplexing. We think it makes Server-Sent Events a viable alternative to Web Sockets when two-way communication is not required.

assess

Software development patterns