3 ms·
I've only professionally used WebSockets with Spring Boot and React and I must say: they're perfectly fine? That is, if you use WS to simply asynchronously com
by jeroenhd 5y ago
I've only professionally used WebSockets with Spring Boot and React and I must say: they're perfectly fine?
That is, if you use WS to simply asynchronously communicate events and do out-of-band message passing, they operate quickly, easily and efficiently. I wouldn't use them to send binary blobs back and forth or rely on them to keep a perfect state match, but for notifications and push events they're a delight to work with. Plus, their long-term connectivity gives them an edge above plain HTTP because you can actually store a little state in sockets rather than deriving state from session cookies and the like.
Yes, WebSockets don't fit well within the traditional "one request, one response, one operation" workflow that the web was built upon, but that model is arguably one of the worst problems you encounter when you use HTTP for web applications (not websites, though; for websites, HTTP works perfectly!). Most backend frameworks have layers upon layers of processing and securty mitigations exactly because HTTP has no inherent state
WebSockets aren't some magical protocol that will make all of your problems go away but if used efficiently, they can be a huge benefit to many web applications. I've never used (or even heard of) Adama, so I can totally believe that websockets are a terrible match for whatever use case this language has, but that doesn't mean they deserve to get such a bad rep. You just have to be aware of your limitations when you use them, the same way you need to be aware of the limitations of HTTP.
- superice 5y agoAbsolutely right, until you have multiple instances of backends you need to deal with and synchronize, which is a pain in the behind. The OPs main issue seems to be with that problem, which is the tough component of using something stateful like websockets anyways. The impedance mismatch of ‘something happened in the database’ to ‘send event over websocket’ is painful in a multi backend instance environment. Case in point: dossier locking in the product we both worked on. Hi Jeroen! Always nice to find an old colleague on here :)
- jeroenhd 5y agoHa, hey there! Nice username :) You're totally right, of course; for shared states between different backend instances you'll need a different solution, like database locking or complicated inter-backend API calls, or even a separate (set of) microservice(s) to deal purely with websockets while other backend operate on the database. That way you can apply scaling without data consistency issues, if you want to go for a really (unnecessarily) complicated solution. It all depends on your problem space. If you want to make a little icon go green on a forum because someone commented on your post, I think websockets are perfect, much better than the long-lived HTTP polls of yore. I think the OP is using websockets to synchronize game state across different clients, which can be quite tricky even without having to deal with scaling or asynchronous connections. You can use websockets for that, but manual HTTP syncs/websocket reconnects after a period of radio silence would not go amiss. Hell, if it's real-time games this is about, you might even want a custom protocol on top of WebRTC to get complete control over data ad state with much better performance.
- jayd16 5y agoA stream isn't "one request, one response" but you can still write your websocket endpoints to be stateless. Once you realize that, its not so hard to work with.