Search code examples
c#botframeworkmicrosoft-teams

Sending Multiple Proactive Messages in MS teams, using Bot framework, at the exact same time


We are sending the notification to all users using a web job. but the problem is not everyone is receiving the notification at the same time. Suppose if we have to send a notification to 3000 users then the time gap between first and last user will be more than an hour.

Is there a better solution where I can send a notification to everyone at the same time just like how "QBot" is doing in Teams.

Thanks.


Solution

  • If you have to send notifications one by one, then it is not possible to send them to all users at the same time. However, you can reduce the gap, but this may or may not be an easy task depending on the number of users you have.

    Throttling

    Of course, you need to take throttling into consideration. Like @Nikitha-MSFT said in the comments, you will start getting HTTP 429 errors as soon as the rate limiting is hit. And you need to properly handle them and retry failed notifications.

    Correct level of parallelism

    You need a scalable webjob. That is, your webjob could be triggered and process multiple batches simultaneously. For example, change your webjob to message queue triggered (if it is not), so that it could process multiple queue messages each containing one or multiple notifications at the same time.

    For example, you could have two webjobs:

    WebJob A - triggered by timer / HTTP request, find all users need to notify and create queue message for each user found

    WebJob B - triggered by queue, process message and send notification

    Each job host could process 32 queue messages as the maximum asynchronously. So in theory, you could send 32 batches of notifications at the same time per job host.

    Assuming you still not hit the throttling limit by far, you could then start considering increasing resources:

    Scale out

    You have one webjob host per app service. You could scale out your app service to have multiple instances to gain more job host instances. The more instances you have, the quicker you could clear the messages in the queue, therefore the quicker you could send notifications out.

    Scale up

    It is also possible, that you might hit bottleneck of your app service plan like this post did. At which point, you need to consider upgrade your plan to another tier to get more power, e.g. CPU.