- Apollo server can be setup with subscriptions from 'subscriptions-transport-ws'
- React offers the useSubscription hook
- Apollo client offers the WebSocket Link
- Neo4j 4.X offers reactive sessions
- Google pubsub can be used to handle subscriptions in a multi-servers situation when the kubernetes cluster scales the pod. I'd like to avoid adding a new element like Redis or Kafka to the already complex stack that is GRANDstack on Kubernetes.
Right now, I'm hesitating between 2 options:
-
Keep it simple on the server. 2 subscriptions
userOnline
anduserOffline
, and each client must update a local array of online users via a cache merge type policy. Not sure how to re-render the cached array data when one of the subscriptions gets new data. -
Keep it simple on the client. A single subscription
usersOnline
returning the list of users, and the client only needs to compare previous and new data to figure out who's just logged in and who's just logged out. On the server side, the subscription triggers a reactive session transaction to toggle aUser.isOnline
boolean, and returns the list of all Users matching isOnline=true.
Which way would you choose for such a feature? Or do you have an alternative suggestion that might be simpler/more efficient?