Reputation: 3312
I have 5 different types of notifications A, B, C, D and E
to be sent to the user. There is no relationship among A, B, C, D, and E.
To give you an idea, A could be facebook like
, B could be new friend request
etc.
I would like to know if it is ok to use a single SSE connection for all these notifications or am I supposed to maintain a connection for every event type?
Can you share some best practices around this?
Upvotes: 2
Views: 2588
Reputation: 28968
Use a single SSE connection.
The normal limit on scaling are the socket that an SSE connection uses. So it is better that you have just a single connection. You won't end up with any more logic or complexity on the client-side: a single message handler that calls a function based on the message type (A/B/C/D/E), vs. five message handlers.
There are also some browser limits on having a lot of SSE connections open to the same domain, so a single connection avoids hitting any of them.
If using HTTP/2 you could argue that the multiplexing means there will actually only be a single socket connection. But in the absence of any strong reason to have multiple sockets, I would still always go with a single SSE connection, even over HTTP/2.
Upvotes: 3