r/Backend • u/viciousvatsal • 14h ago
Websocket or REST?
I am building a real time app that also has a group chat. I will need a websocket connection for this, which introduces complexity at the system level for scaling, but that's not the point of this post.
From what I've read, websocket gives low latency bidirectional byte channel between a client and server with no protocol. REST gives you a request response protocol with status codes and integration with infra that has been using it for a long time.
I will have to open a websocket connection for my app to work. So I am tempted to use websocket for CRUD operations on my app as well that are outside of the group chat. Like when user changes settings or changes profile picture I might as well send a websocket message which has lower latency compared to an HTTP request which will create a new connection on each request. For some reason I think this is not the best practice. Do other apps do it this way? I see apps like reddit or insta where when you change your user settings they are instant, like toggling a setting on/off. It doesn't look like a POST request.