Harfeur / TwitchAlerts

This bot allows you to display an alert during a Twitch live, and to update the message frequently. Messages and language are customizable.
MIT License
5 stars 5 forks source link

Suggestion: future architecture for scale and efficiency #8

Open iamdadmin opened 8 months ago

iamdadmin commented 8 months ago

Hi,

Bit busy to reach out in Discord at the moment, but wanted to share my thoughts on how to scale the bot and make it more efficient.

I'd suggest using pm2 to scale the threads and breaking it up into three microservices, this diagram explains my thoughts. We'll use a sticky session technology on the web-ui workers so we don't have to do full sessions since the website isn't all that busy in comparison to the events and discord stacks. It can be scaled by adding more workers, one per vcpu.

You could possibly combine the web-ui with one of the other microservices. Logically speaking it would make sense to do that with the discord, as it'd remove the need for the internal alert api, however that's also the one likely to experience the most load/scaling issues, so possibly best to avoid that.

I've also excluded a database table for "currently live" streamers, however a simple async started when a online is received which checks the database every 15(?) minutes for changes to category or title until an offline is received would handle that.

twitch-alerts-bot-suggested-architecture drawio

Harfeur commented 8 months ago

Hi, I'm currently using PM2 but only with one process. Take note that Discord requires to have shards for every group of 2000 servers. So we can use that to have Discord workers (currently I have three shards). I also want to keep the web server as it's more flexible than Discord (for example, I use Discord's Modal for /setup but they don't support checkboxes). Currently the alert is updated every ~2 minutes, so if the streamer change his game, it's updated asap on Discord.

In the future, I want to have only EventSub connection with Twitch. So when a user changes the stream title or game, Twitch send the bot a message using this event.

iamdadmin commented 8 months ago

In terms of approach, here's a few random bulletpoints that I can expand on for anything interesting.

I just saw your reply come in as well so few more thoughts before hitting submit :)

iamdadmin commented 8 months ago

Also