Here is some additional information for choosing between webhooks and websockets.
Server-to-server communications over websockets has become popular with a new generation of chatbot apps. Now, many chatbots run over websockets with provide a primary advantage of not requiring a public facing URL for internal, private bots. In this environment the following are some guidelines on when to consider using webhooks vs. websockets.
Websockets
- If your app is a browser app, use websockets because your app cannot receive webhooks.
- If your app is a server app receiving messages from a service over the Internet and you do not want to open your firewall, consider websockets. Some companies require information security review before opening such connections.
Webhooks
- If your server app app needs to make many subscriptions, either be prepared to handle the volume of open websocket connections to your sever (see this article for 1M websocket connections), or switch to webhooks. Some popular chatbots have moved from websockets to webhooks to improve scalability.
- If your server app runs as a cloud function on (AWS Lambda, Google Cloud Functions, etc.), use webhooks because your app will not keep the websocket connection open.
- If your server app is running on the Heroku free tier, use webhooks because your Dyno will go to sleep and must sleep for 6 hours per day, unless you manually instruct your server to sleep.