My game app uses Vue frontend and Django backend with DRF. Several clients connect to same game session. Sometimes some user does something which has to be reflected also for other users. For that purpose server has to have means to request client to refresh data.
Django application is deployed on Elastic beanstalk. Typical game session has 10 players, update request is sent once in 15 seconds to the players and I don't believe we will for the foreseeable future have more than 50 simultaneous games, so the performance requirement is low.
I'm looking for a simple solution to push the update request message to the clients.
My current solution uses Redis server running on ec2. When on Django views something is changed, Django publishes update request to Redis:
r = redis.Redis(host=settings.REDIS_IP, port=6379, db=0)
r.publish(game_identifier, type)
"Type" contains information which kind of data should be updated.
In addition I've implemented a simple Node application. All clients connect to this app using Websocket. The app also subscribers to Redis, and whenever there is a notification it's emitted to subscribers using their game's identifier as channel. After this the clients refresh their state with REST. Node application is also run on Elastic Beanstalk.
Everything works but having one Elastic Beanstalk application and one ec2 instance just for sending simple notifications to clients seems like an overkill. I would love to hear ideas how to build this simple notification with less moving parts. If the backend was built using Node I could do this with just a few lines of code.
Some possibilities / questions:
You may be better of leaving the notification server on its own for modularity and scalability and reusability. But if you insist on going with a single server, you could use Django channels in place of the Node server and the Redis instance as the Channel layer so you can have it in the same code base as the DRF app. There are already a couple of libs integrating DRF and Channels out there. I use this one DjangoChannelsRestFramework
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With