I built a Telegram bot that allowed users to run a configurable script on my server.
Here is how it works:
- User contacts the bot
- User configures how he wants to run the script.
- User asks the bot to start it.
What happens when the user starts it is that I create a new thread running the script.
# (user configures) # (user asks the bot to start the script) # I do this: thread = threading.Thread(target=myscript.always_running_function, args=(user_id)) thread.start() # continue listening to config changes/other users
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 there is a huge load later? Should I run it on EC2 instances with load balancing enabled?
Another way I was thinking of making it work is like this:
- Running the bot on a separate EC 2 instance
- Running a web server on another instance with load balancing.
- 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.