WebSocket client and auto scaling

33 views
Skip to first unread message

Bao Le Duc

unread,
Sep 22, 2020, 10:52:49 AM9/22/20
to Google App Engine
Hi,

I'm using AppEngine Flexible for a Discord bot. The application needs to keep one Web Socket connection to Discord Web Socket server. So, when the application starts, it opens a Web Socket connection and keep connected with Discord Web Socket server. 

When the application is scaling up and running multiple instances at the same time, it also establish multiple Web Socket connections to Discord Web Socket server. In the result, the bot receive same events on multiple instances and replies multiple identical messages.

How can I make sure that the bot establish only one Web Socket connection to Discord Web Socket server? 

Best,
Bao 

manu

unread,
Sep 24, 2020, 9:23:05 AM9/24/20
to Google App Engine
Hi,

you could use another GAE service with maximum scaling = 1, which would act as a proxy to Discord for a new GAE bot service, which would continue scaling as before. The proxy service would just take the connection functionality from the old bot service and modify it minimally to forward the connections from the new bot service to discord using just one socket, and it shouldn't have much of an issue with workload even if the number of requests is considerable, as it is just relaying the information. The new bot service would have the connectivity logic adapted to this new setting.

You could also use a GCE instance instead of a GAE service for the proxy.

Best regards

Reply all
Reply to author
Forward
0 new messages