Ask HN: What is the best architecture for a bot running background service
Here is how it works:
1. User contacts the bot 2. Configures how he wants to run the script. 3. User asks the bot to start it.
What happens when the user starts it is that I create a new thread running the script. The script involves listening from updates from another API so I thought running it as a thread would be a good choice.
Now what happens is that some users tell me that the script stops working after a while. Perhaps the thread gets killed by the OS after a while?
I am trying to understand what is a good architecture for such an application.
Right now, there are 10 people who use the bot so it handles it effectively. What if I run it on EC2 instances with load balancing enabled?
Another way I was thinking of making it work is like this: 1. Running the bot on a separate EC 2 instance 2. Running a web server on another instance with load balancing. 3. Now when a user asks the bot to run it, the bot calls the web server and runs a new process/thread there.
I wonder what would be the implications when load balancing comes into the picture.
Another question: thread vs new process. Different processes did not work properly the last time I tested so I want to know whether it is my mistake or running a different process IS a wrong way of doing it.
8 comments
[ 0.24 ms ] story [ 27.9 ms ] threadThe Telegram bot is written using a async-based library (telethon).
I should have also explained this in the post that when the user asks the bot to run the script, I do a `thread.start()`
Do you have any recommendations to where I should learn more about using it? (I am checking the docs to get a basic understanding rn)
If you need to just keep polling, I'd recommend using a managed background task service like SWF on AWS or Cloud Tasks on GCP. Not worth the trouble of debugging to build it yourself these days
I will check out SWF, thanks for the help!