Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to scale a slack bot to 1000's of teams

To implement a slack bot, i need to deal with 'Real Time Messaging API' of slack. It is a WebSocket-based API that allows you to receive events from Slack in real time and send messages as user. more info: https://api.slack.com/rtm

To create a bot for only one team, i need to open one websocket connection and listen it for events.

To make available the slack bot for another team. I need to open a new websocket connection. So,

  • 1 team => 1 websocket connection
  • 2 teams => 2 websocket connections
  • N teams => N websocket connections

what should i do to scale my websocket connections for endless teams?

What kind of architecture can handle autoscaling of 1000’s of websockets connections?

like image 316
Kerem Avatar asked Apr 04 '16 22:04

Kerem


People also ask

How do I program a Slack bot?

Go to api.slack.com/apps, click Create an App, enter a name for your app, and select the correct Slack account where you want to use the new Slack bot. Slack will then show some options to add features to your app. You can add bot users, interactive messages, and more—but each of those requires coding.

How do Slack bots make money?

Acting as a direct sales channel. These bots integrate with project management software, CRMs and a variety of other processes used to close sales. They also improve visibility between sales, marketing, customer care, and product design, which allows everyone to work towards a common goal.

How do I edit Slack bots?

Click the Slackbot tab, and you'll see an option to add new responses (provided your Slack administrator allows everyone to add new ones). You can put any text you like on the input side (what you type in a message) and output side (how Slackbot will respond).


1 Answers

With slack sockets, you have lots of things to scale:

  • Number of sockets. This is easy because even cheap servers can handle thousands of sockets, like more than 50k. But each socket represents a couple other types of load, listed next.
  • Amount of memory used per team, which depends on your own server implementation. If you are trying to keep a large amount of message history in memory, you will hit your server's limit faster than if your message processing code is somewhat stateless.
  • Amount of I/O, which might make you want to offload any image serving to a separate load balancer.

The other thing to consider is fault-tolerance. Let's say you did sticky load balancing and one of your servers is handling 50 teams. That server is the only one handling those 50 teams so if it goes down then all 50 bots go offline. Alternatively, you can open up multiple sockets per team on separate servers and use a message handling queue so that each message is only responded to once.

So the architecture I would propose is a thin, redundant load balancer for RTM sockets as a first layer, and a reliable message queue underneath that.

like image 115
HK JR Avatar answered Nov 05 '22 06:11

HK JR