0

I have been using websockets for only sending and receiving location updates, but now I am thinking of using them for other things like analytics, notifications, etc.

The way my implementation is set up (i'm using Go), I have a /ws/tracking websocket route where I can fire off updates to connected clients in a group when a group member updates their location and that the client also uses to send their updates to the server.

Should I create a bunch more routes, like /ws/analytics, /ws/notifications, etc. or should I re-do my implementation to have just one handler like /ws that can handle everything?

With more routes, this means my clients will have to open multiple connections potentially to each endpoint. With a single route, maybe I can have a key/identifier for the resource (ie. analytics, tracking, notification, etc.)?

No idea if this is the right path, so please let me know what the best practice is generally with websockets.

Thanks

user1354934
  • 8,139
  • 15
  • 50
  • 80
  • There's no reason to have multiple webSockets just to send different types of messages - that would just be a waste of server resources. You may want to go with the socket.io model where every packet has a message name (a string) and then you can send zillions of different types of packets just by using a different message name for each one. Or maybe you even just want to use socket.io which does this for you (on top of the webSocket transport). – jfriend00 Jun 23 '18 at 23:46
  • Possible duplicate of [Design/Architecture: web-socket one connection vs multiple connections](https://stackoverflow.com/questions/31134420/design-architecture-web-socket-one-connection-vs-multiple-connections) – Myst Jun 24 '18 at 13:13

1 Answers1

0

While having multiple routes seems to be more pretty, it might many have disadvantages too. First of all, you are using much more resources than single route. Second,you are using the bandwidth more than ever. The next thing you might want to consider is OS open-file limit. I suggest you go along with single route, unless you are thinking about distributed architecture or something like individual servers for each route.

Sepehr GH
  • 1,297
  • 1
  • 17
  • 39