Chat Architecture Everywhere
Till now Supertext is working on popular chat apps like Facebook Messenger, WhatsApp etc. Now we want to make our on hat app in which we will be having many customized experience. As in past everywhere I have seen the chat example, I thought it would be really simple to make a chat app as there will be a standard defined on web to make one. But on first glance I was swirled with number of awailber options to make the chat app. The only thing came to my mind was:
There were many things to thing off like Real Time using WebSockets / Long Polling / Server Sent Events / Comet / BOSH, Jabber Server + XMPP + socket.io, Firebase + Parse / Firechat, Slack / Telegram / Actor, stanza.io / Google Cloud Messaging / OneSignal, Quickblox / SupportKit. I will try to answer all these different questions in different posts.
Introduction
### Comet / BOSH Polling / Long Polling / SSE / WebSockets all lies under comet. WebSocket is the latest tech under the comet umbrellan which trying to solve the problem of real time communication by providing server push.
BOSH is bidirectional communication protocol written for the XMPP.
Jabber + XMPP + stanza.io
Extensible Messaging and Presence Protocol (XMPP) is a set of application protocol based on XML (Extensible Markup Language) for doing real-time chat (and many other things, for that matter) - it then has to be transported across the network somehow, so you need a transport binding.
XMPP used to be called Jabber initially. eJabber and OpenFire are two famous out of the box XMPP servers.
stanza.io Modern XMPP in the browser, with a JSON API
Firebase + Parse / Firechat
Firebase can power your app’s backend, including data storage, user authentication, static hosting, and more.
Parse Instantly add a powerful cloud database, push notification services, and analytics tracking to your app.
Firechat is an open-source, real-time chat widget built on Firebase.
Slack / Telegram / Actor
Slack is a messaging app for teams who are changing the world
Telegram is a cloud-based mobile and desktop messaging app with a focus on security and speed
Actor Including modern applications for Web, iOS, iPad, Android and SDK for building your own WhatsApp.
socket.io / Google Cloud Messaging / OneSignal
socket.io is the fastest and most reliable real-time engine. To understand how socket.io
works follow this.
Google Cloud Messaging (GCM) is a simple and reliable messaging to reach over a billion devices.
OneSignal is a high volume, cross platform push notification delivery.
There are also many other options to choose from like Pusher or PubNub.
Quickblox / SupportKit
Quickblox is ready-to-go modules add new functionality such as video calling, instant messaging and push notifications.
SupportKit is a mobile and web messaging API & SDKs for apps and businesses.
Solutions
So that now I have covered all the top techs which you can use to make chat application. Lets compare them. These are the some popular combinations I am comparing. You can find an alternative to any tech or tool mentioned here. I think from the birth of digital age people are making chat apps so there are so many tools & tech available out there.
Using XMPP lib
XMPP is just a protocol which brings a standard in chat servers so that a chat client/server can talk to any other chat/server. With XMPP you need a network binding ans server/client libs implementing XMPP using the selected network-binding.
You can find XMPP list of XMPP libs here, XMPP servers here and ready to use clients here. These different solutions uses different base tech underneath like network bindings: BOSH, long polling, websockets etc.
In this solution you have to setup a XMPP server, use server XMPP lib and client XMPP lib.
You might also want to consider Google moves away from the XMPP open-messaging standard.
Firebase + Parse
Firebase and Parse both are Backend as a Platform providers and both are real time. There are some differences as mentioned here & here.
There are many examples of making chat app using firebase: using ionic, using ember , firechat and you can find an example with any popular tech present out there. Parse example is here.
I am unable to find anyone implemented XMPP over Parse or Firebase. According to me that is also possible.
You might also want to consider Is it possible to use Parse.com for realtime chat (like Socket.io)?
Slack / Telegram / Actor
I don’t know ahy it not mentioned anywhere but according to me we can use slack /telegram or actor to implement the chat application.
With slack you get complete slack backend along with a REST and real time API.
With telegram you are getting everything you get with slack except the real time API but you get open source telegram implementations for all the major platforms which internally should be using real time techs to connect to telegram server. Though you might also face some problems as mentioned here.
Actor is another alternative to telegram but there are some improvements as mentioned here.
socket.io / Google Cloud Messaging / OneSignal
In case you want to have your own server but you only want a real time tech to communicate then you can choose any of socket.io / GCM etc. There are other alternatives too like Real-time framework.
Strophe.js and stanza.io are js lib which combines socket.io and XMPP.
Quickblox / SupportKit
Also you can use a third party services which does anything for you using any of the above techs but it will come with a price. There are many alternatives on web like Pepper Talk, Jiver, layer, buddy
Other considerations
Why XMPP is good
You can’t use just websockets or anything for chat - leaving XMPP. This really means is that you’re inventing your own application-layer protocol for chat, and the odds are you’re going to save a lot of time and headaches by taking advantage of the work that’s already gone into writing one with useful properties (security, identity, extensibility etc.) and for which there are existing libraries and servers by going XMPP instead.
Mobile battery usage considerations
As suggested in this SO answer Do not use sockets. That means you will need to keep a service running and maintain a connection at all times on each client device. That will drain the battery like crazy and no one will use it. What every-single-one of those apps use including WhatsApp, Hangout, Gmail, Facebook messenger is the Google cloud messaging (GCM). Follow this & this for more details.
Most of push services like OneSignal uses GCM underneath when used on mobile. So in most cases you are safe to go but do check for this.
XMPP BOSH vs COMET
This SO answer perfectly sums it up:
- BOSH and Comet are the same thing.
- The reason I say that they are the same thing, at a fundamental level, is that they both originally (see below) relied upon two HTTP connections. The first is a back channel which is either a long-held HTTP Streaming connection or use for HTTP Long-Polling. The second connection is short-lived and used for sending commands such as subscription requests. These two connections allowed for the bi-directional communication to be simulated.
- BOSH differs is it offers added detail within it’s protocol and was developed with XMPP in mind. Any Comet server could be developed to adhere to the standards defined in the BOSH spec.
- Existing technology stack mostly use WebSockets as they offer a standardised and efficient bi-directional communications mechanism.
References:
- Understanding WebSockets
- BOSH
- Extensible Messaging and Presence Protocol (XMPP)
- eJabber
- OpenFire
- Firebase
- Parse
- Firechat
- Slack
- Telegram
- Actor
- stanza.io
- socket.io
- Google Cloud Messaging (GCM)
- OneSignal
- Real time web - base technologies
- XMPP - Libraries
- XMPP - Servers
- XMPP - Libraries
- Cloud Services: How does Firebase differ from Parse?
- Which one is better to user between Parse, Firebase and AWS Cognito?
- Build a Real Time Hybrid App with Ionic & Firebase
- How to build a realtime chatting app with Firebase and EmberJS from Scratch
- Example: Full Featured Chat App With A Great Interface Using Parse For The Backend
- Firechat
- What’s Wrong With Open Source Telegram?
- Messaging Platform with Actors in its heart
- Strophe.js
- Google moves away from the XMPP open-messaging standard
- Is it possible to use Parse.com for realtime chat (like Socket.io)?
- Xmpp Vs Websocket
- XMPP, WebSocket, and other questions
- Websockets versus GCM under Android: battery usage?
- How does push notification technology work on Android?
- XMPP BOSH vs COMET
- An XMPP Subprotocol for WebSocket
- Real-time framework
- Pepper Talk
- Jiver
- layer
- buddy
- how does socket.io work?