Skip to content

LoadBalancingUpdater - Possibility to have multiple Bots using the same Dispatcher #1016

@JosXa

Description

@JosXa

With the Bot API rate limiting, it can be of great value to employ multiple bots in order to balance the user requests between them. The best example of this would be @MasterTagAlertBot, which uses 10 additional bots and redirects users to the other ones if the load on one is too high:

image

It would be nice to have native support for this, as bots built with the library start to exceed the 10k MAU threshold and the flood criteria of Telegram are kind of odd.

Therefore, in a very simple 20-minute prototype hack, I managed to implement a LoadBalancingUpdater that takes a list of tokens or bots, and a BotSelector instance with an abstract method select_best_candidate (random.choice(available_bots) per default) which is passed to the job_queue and the dispatcher. Not many changes were required for this, and the added value is great from what I can tell by discussions with @thegasta (MTABot developer).

Things to consider:

  • Responding to updates from the "correct" bot, i.e. the one the user has actually interacted with.
  • Border cases of polling and webhooks that I haven't considered so far

Naming for everything is WIP and suggestions are appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions