I am creating an application(Nuxtjs
) and am having troubles determining a good approach for sending data to the API(expressjs
) and retrieving real-time updates. It seems that i can create "bi-di" connections with both protocals [Server Sent Events(SSE
) and Axios
or Websocket(WS
)].
Both technologies work with most of the browsers, so i do not see a need to add additional libraries such as socket.io
- For those individuals that do not have a current browser (too bad).
The application is based on user input of form data/clicks. Other users are then notified/updated with the information. At which point, the user can respond and the chain goes on(Basic chat like flow some information will be exchanged quickly while some may not or ever).
In my experience, the user flow would rely more heavily on listening for changes than actually changing the data - hence why i'm considering SSE
. Unfortunately, both protocols have their flaws.
Websockets:
- Not all components will require a
WS
to get/post information as such it doesn't make sense to upgrade a basic http connection at the additional server expense. Therefore another method other thanWS
will be required(Axios/SSR
).Example: Checking to see if a user name exists
- Security firewalls may prevent
WS
for operating properly express-ws
makes sockets easy on the API end- I believe you can have more than 6 concurrent connections by one user (which may be pro and con)
Server Sent Events
- Seems like the technology is fading in favor of
WS
- Listening to the events seem to be as easy as listening to events for
WS
- No need to upgrade the connection but will have to use
node-spdy
within theexpressjs
API - This may also be a good implementation forWS
due to multiplexing - Little more backend code to setup
http2
and emit theSSE
s(Ugly code as well - so functions will be made) - Limited to HTTP limitations (6 concurrent connections) which is a problem as the users could easily max this out(ie. having multiple chat windows open)
TLDR
The application will be more "feed" orientated with occasional posting(which can be handled by Axios
). However, users will be listening to multiple "feeds" and the HTTP limitations will be a problem. I do not know what the solution would be because SSE
seem like the better option as i do not need to continually handshake. If this handshake is truly inconsequential(which from everything i have read isn't the case) than WS
is likely a better alternative. Unfortunately, there is soooo much conflicting information regarding the two.
Thoughts?