How to Build a Real-Time Chat for Web and Mobile With a Hosted Messaging Service

Messaging apps are gaining in popularity: within the last eight years, we’ve seen the establishment of messaging giants including WhatsApp, Viber, LINE, Kik, and Slack.

According to Statista, the number of mobile phone messaging app users was around 2.52 billion in 2019. This number is predicted to reach the 3 billion mark by 2022.

Number of mobile phone messaging app users from 2018 to 2022

It seems that people prefer instant messaging apps because they provide a nice alternative to outdated SMS technology and include advanced features like media sharing, group chats, voice and video calls, and even voice and video messages. Recently, however, we’ve been witnessing the emergence of chat functionality in web and mobile products other than chat-based apps.

In 2017, for example, Uber integrated instant messaging functionality for “greater convenience and privacy.” The new chat feature lets drivers and riders exchange instant messages right within the app, substituting the previous mechanism that required a phone call or text message.

Web applications like Twitch have enabled in-app group chats to establish strong relationships between users and to provide a sense of community on their platforms. There are also a number of live streaming apps (Periscope, Meerkat, and YouNow) and social apps (Instagram and Twitter) that integrate chat functionality, letting users directly communicate with other participants in real time. Moreover, real time chats are considered one of the core features of most dating apps (including Tinder, Grindr, and Pure).

Instagram Direct

Today, we’ll discuss how to build a real-time chat application, what third-party SaaS real-time chat solutions exist, and how to choose the right real-time hosted messaging service for your app.

About hosted and self-hosted chat services

Luckily for developers, there are numerous realtime messaging SDKs and chat APIs out there that allow for embedding in-app messaging into web and mobile apps. With APIs, developers don’t have to reinvent the wheel and build complex chat solutions from the ground up. These SaaS platforms can be divided into two groups: hosted and self-hosted.

Let’s find out how these differ and consider the advantages and disadvantages of each type.

  • Hosted real-time messaging services

Hosted services are ready-made solutions that offer a quick and easy way to add messaging capabilities to your app using just a few lines of code.

Essentially, a hosted messaging solution is a locked ecosystem that your web or mobile clients (and sometimes servers) connect to via SDKs and APIs in order to become chat-enabled – all you need to do is place a special code snippet in an app via an SDK and your users will be able to exchange text, voice, and video messages and share files.

The idea behind paid messaging services is to simplify what would otherwise be a complex development process. Implementing a turnkey messaging solution allows businesses to focus on what makes their app different from others (unique features or style) while a messaging service provider takes care of the messaging. Examples of messaging service providers are Layer, PubNub, Pusher, Quickblox, and Applozic.

By using a ready-made third-party messaging service, developers don’t have to worry about deploying code, supporting and maintaining code, fixing bugs, configuring servers, and so on – this all is carried out by the hosted messaging service provider.

One of the drawbacks of hosted messaging services, however, is that developers don’t have full control over the system and configure their chat functionality as the system isn't customizable enough. Any changes to the design and configuration are impossible without involving the service provider. And, of course, to make these changes you need to pay additional money.

Moreover, the more actively your users communicate on your platform, the more costly the service will be. On huge projects, the monthly price tag can sometimes reach around $1,000 since these services are commonly priced based on an app’s monthly active users (we’ll get back to this later).

We usually recommend hosted messaging solutions for small and medium-sized projects that don’t have a lot users (up to 50,000).

“Is there any alternative to a hosted service that will give me more control over my chat solution?” you may ask. Sure there is. The alternative is a self-hosted real-time messaging service.

  • Self-hosted real-time messaging services

Roughly speaking, a self-hosted solution is something between a chat project developed from scratch and a ready-made solution provided by a third-party platform. A self-hosted messaging service offers source code that you can buy and deploy on your own servers, which allows for superior accessibility for customizing the features and style of your chat.

However, along with the better customization opportunities that self-hosted messaging solutions provide comes greater responsibility – for example, your developers will be responsible for deploying server-side code and configuring servers. They will also need to constantly support and maintain your real-time chat application. This implies spending more time, effort, and resources – for example, you’ll need a separate team of engineers to support your chat solution. In special cases (when a new chat update arrives, for example), developers may spend more time and effort figuring out how to deal with the system. Moreover, you’ll also need to spend money to host your project on a server.

However, for huge projects (with over 100,000 users), a self-hosted solution is typically cheaper than a ready-made solution that charges for your users’ every move inside the ecosystem.

What hosted and self-hosted services we use to integrate live chat into apps

Our customers often ask us what third-party messaging solutions we use to integrate chat functionality into our projects. So we decided to prepare a list of the reliable solutions we typically use to build chat-based apps and chat blocks for web and mobile applications. Let’s see what’s on it.


The first solution is Layer, a popular messaging platform with hosted infrastructure and services that lets developers easily add chat capabilities to their iOS, Android, and web apps. Layer provides client and server APIs and SDKs and an impressive UI toolkit (Atlas) that enables developers to build rich and engaging messaging experiences that are “on par with iMessage and Facebook Messenger.”

Layer is fully managed and HIPAA-compliant (which means it’s perfectly suited for enabling chat functionality in healthcare applications). The platform powers a wide range of products across both person-to-person and business-to-consumer use cases. Layer’s customers include Trunk Club, Staples, and Udacity. Moreover, the company recently partnered with Microsoft to integrate messaging with instant translation capabilities into the official app of the World Economic Forum in Davos.


Pusher is a hosted service that provides realtime communication and collaboration APIs (supported by easy-to-integrate SDKs for web, mobile, and backend) and cloud infrastructure that lets developers power their apps with real-time functionality such as instant messaging and push notifications.

According to the company, Pusher serves as a real-time layer between an app’s server and its clients. This layer enables stable connections to clients (over WebSockets, which we’ll get back to a bit later); if your servers have new data they need to push to clients, they can do it in no time using Pusher.

Pusher's architecture

Pusher offers libraries that can be integrated into some of the most popular languages and frameworks, including PHP, Ruby, Python, Java, .NET, Go, and Node on the server side and JavaScript, Objective-C (iOS), and Java (Android) on the client side.

In 2017, Pusher rolled out a new product called Chatkit. This kit makes it easier to build powerful chat blocks with features including typing indicators, online user presence, public and private rooms, and message storage. The company is also planning to add rich media support and message delivery statuses.

Pusher powers a number of popular products that some of us use regularly, including  GitHub, MailChimp, CodeShip, The Financial Times, and QuizUp.


Founded in 2010, PubNub is a real-time infrastructure-as-a-service company that provides a super secure and reliable two-way data network (the PubNub Data Stream Network, or simply DSN) for apps and other services that rely on regular and small signalling messages to work – from dating apps with integrated instant messaging blocks to smart IoT devices that communicate with each other in real time. Some of PubNub’s most prominent clients are Yelp, eBay, GetTaxi, and Pocket Gems.

PubNub data stream network scheme

Just like Layer and Pusher, PubNub provides a set of powerful and robust APIs and SDKs to build fully functional, reliable, and secure web and mobile chat-based apps and in-app chat blocks that include features like typing indicators, online presence monitoring, emoji, push notifications, message history, and even chatbots (all these tools are united under the name ChatEngine).

Moreover, PubNub provides point-to-point TLS network encryption and end-to-end AES message encryption and is HIPAA and EU-US Privacy Shield compliant, meaning that the service is perfect for building chat blocks for all kinds of apps from dating to delivery to healthcare.


Unlike Layer, Pusher, and PubNub, MongooseIM is a self-hosted massively scalable messaging platform that we also actively use for building chat functionality in our projects. MongooseIM is enterprise-oriented, meaning that it’s typically used to build large, high-performance, stable chat solutions (according to the company, MongooseIM can successfully withstand a total of 1,000 to 100,000 active users).

First of all, MongooseIM is an open-source messaging platform. It was released under the GNU General Public License vol. 2 and can be used at any volume without license fees. Moreover, thanks to its clean and modular design, it can be integrated easily with existing solutions within a company.

Even though the MongooseIM platform is open-source, it has a dedicated support team ready to help you install, run, and scale it (for a price, of course).

When it comes to configuring your chat, custom features can be developed in a private repository by a support team (which gives you sole access to them) or as open features that are maintained and expanded by the community.

MongooseIM architecture scheme

The MongooseIM team has contributed to a number of open-source, third-party libraries such as Smack for Android, the XMPPFramework for iOS, and Mongoose Push for the server side, which allows for more convenient integration with clients and servers.

All in all, MongooseIM is a stable, reliable, and easily integrated self-hosted platform that’s perfect for building large and high-performance messaging solutions.

What to consider when choosing a messaging service

Now that you have a basic understanding of what third-party messaging platforms exist, it’s time to find out what we (developers) and you (the business owner) should take into account when choosing a third-party chat solution.

1. Protocol independence

A number of real-time communication protocols – such as WebSockets, MQTT, XMPP, BOSH, COMET, and long polling – are used to enable instant data exchange between an app’s clients and its server. At the end of the day, however, each protocol has its limitations (WebSockets, for example, is only supported by 77 percent of browsers and faces problems bypassing proxy servers that block it). Moreover, the landscape of mobile devices, browsers, and protocols is constantly changing.

What this means is that modern businesses and developers need to choose a solution that can easily adapt to the stream of ever-changing environments and technologies.

Such protocol-independent solutions include PubNub and MongooseIM, which provide support for the most popular real-time communication protocols and are able to work in every network environment.

2. Cross-application support

Living in times of immense device diversity, it’s important to choose a solution that provides support for as many runtimes and frameworks as possible. PubNub, for example, has over 70 SDKs for different client-side and server-side languages including Xamarin, React, Python, Go, Erlang, and Cocoa.

Pusher provides a number of its own libraries for a variety of platforms as well as a number of libraries developed and supported by members of the Pusher Channels Developer Community.

3. Rich media content support

Modern users no longer send bold text messages. They love using emoji and stickers, audio, video, images, contacts, and locations – what’s called rich media. That’s why it’s important to give your users the opportunity to spice up their conversations with rich content.

Most instant messaging platforms support rich media: Layer, for instance, has a feature called Rich Content that allows you to upload rich media files (up to 2GB each) and track their sending progress, while PubNub offers a number of chat plugins including the Emoji Plugin that lets users input emojis into their chat messages.

4. Pricing and business models

On the whole, hosted messaging solutions like PubNub and Layer offer a free tier that allows developers to build prototype apps, then push the app to market and check if it resonates with the audience. PubNub offers a Free Forever plan for up to 100 devices and 1 million messages a month to get your app up and running. It also includes basic support to handle some minor challenges.

Both PubNub and Layer are priced based on an app’s monthly active users, meaning the more users use your app and exchange messages, the more you pay. On its official website, PubNub let businesses calculate approximately how much they will pay for a certain number of messages exchanged.

Other services, like Pusher, offer a number of predefined subscription packages that contain different features depending on the price you pay.

Yalantis also provides our own pre-built messaging solution based on the Elixir language that runs on the Erlang virtual machine. The main advantages of the Elixir are scalability and fault tolerance, which are very important features when it comes to building high-load systems.

While creating our realtime messaging platform, we also used an Elixir-based framework called Phoenix, which allows for building a reliable realtime chat app faster with minimum effort. Phoenix provides the Channel feature (useful for building real-time messaging functionality), a layered system with a number of components that follows the Publish-subscribe pattern to broadcast messages to one or many receivers. The technology uses either the WebSockets or the Long Polling technology for enabling real-time interactivity in apps.

Thanks to our tutorial, now you know a bit more about what messaging solutions exist and what services and tech stack we at Yalantis prefer to use in our project.

Want to know how much it may cost to build a realtime messaging app? Drop us a message.

4.8/ 5.0
Article rating
Remember those Facebook reactions? Well, we aren't Facebook but we love reactions too. They can give us valuable insights on how to improve what we're doing. Would you tell us how you feel about this article?

We use cookies to personalize our service and to improve your experience on the website and its subdomains. We also use this information for analytics.