12 min readUpdated Oct 12, 2023

How to build a chat app like WhatsApp

How to build a chat app like WhatsApp
AblyAbly

When was the last time you WhatsApped someone?

In all likelihood, the answer is probably not that long ago.

First released in 2009, WhatsApp quickly became the default setting for instant messaging in much of the world. By 2014, it defined the market so much that it was acquired by Facebook – and it has pretty much remained a leader in the chat space ever since.

So widespread is the app’s popularity that it has now created its own verb – and so common is that verb that you probably didn’t even think twice when you read it in the first sentence of this article.

Long story short: WhatsApp is a pretty big deal. So, how do you go about building a chat app like WhatsApp?

Core features of chat apps like WhatsApp

In many ways, WhatsApp’s stratospheric success comes down to one simple fact: it was first to the party. Now, the features it helped popularize are commonplace across its chief competitors, like Messenger, iMessage, Telegram, and others.

But the fact that these features are so commonplace means it’s difficult to stand out. To be competitive, it’s important to consider how you can use core features as differentiators (e.g. can you be more reliable?), how you can apply them to a more specific, tailored audience, or how you can win - like WhatsApp - by getting to market faster.

However you’re planning to compete in the market, one thing is clear: these WhatsApp-inspired features are now considered a must-have:

1. Low latency messaging

Low latency is the key to realtime chat. If your customers perceive any kind of lag in their conversation, they’ll quickly start looking for a competitor. The quality and capacity of your infrastructure make a huge difference to the latency you can offer.

2. Channels and private messages

The ability to break out into self-contained groups or private channels is another big draw of chat apps like WhatsApp. Your goal should be to put the user in control, giving them the tools to easily choose who and how many people to send messages to.

3. Typing indicators

Typing indicators help replace unspoken conversational cues, whether that’s the iMessage animated dots or WhatsApp’s ‘contact name is typing’. After seeing a typing indicator, users might decide to wait a few minutes before sending a follow-up, making the conversation smoother, less fragmented, and more cordial on both sides.

4. Read receipts

Read receipts help users understand whether to follow up or wait for a response. WhatsApp has three standard settings here: sent, received, and read. All of these give valuable context about when (or whether) users can expect a reply.

5. Emoji reactions

Emojis are part and parcel of online communication and are now even standard practice in workplace tools like Slack. They help add depth and color to a conversation that plain text just can’t quite manage.

Unlike other features on this list, this wasn’t pioneered by WhatsApp and was instead added in 2021, after other competitors like Messenger had rolled the feature out as early as 2017.

6. Multimedia file sharing

The days of chat being all about words are long behind us. Images, documents, videos, and more are now commonly shared through chat apps. The challenge here is that multimedia files require vastly more storage than their text-based counterparts, so you’ll need to think carefully about how to enable these without affecting latency.

7. Targeted messages

Targeted messages, or @messages, are particularly helpful in group chat settings, where users want to differentiate between messages targeted to individuals and the whole group. It’s a helpful way of nudging somebody to provide a response.

8. Push notifications

Push notifications are still hugely popular, with 60% of smartphone users opting in to some form of notification. They also help bring users back to the app, ensuring they can read messages even if they’re not constantly checking for updates. It’s important not to overuse push notifications, however, and to offer a range of choices for how many notifications users will get and how often.

9. Phone and video calls

Phone and video calls are another key feature that makes WhatsApp tick. They played a huge role in attracting users already accustomed to phone calls when the app first launched. Now, they help maintain the active user base, since customers don’t have to go elsewhere for their phone call and video chat needs.

10. Compatibility

Compatibility is one of the benefits of WhatsApp and its key competitors like Messenger, Signal, and Telegram. It ensures the majority of people will be able to access the app, whether they’re using Android, iOS, or another platform. These customers can use one app for all their contacts, regardless of the tech they’re accessing it through.

11. Onboarding

Smooth onboarding plays a crucial role in attracting and sustaining users. The goal here is to make it as easy as possible to get started – as too much friction in these early stages can put potential customers off for good. For WhatsApp, that involves downloading the app, adding your phone number, and verifying. This can be completed in a matter of seconds and plays a crucial role in attracting and activating new users.

12. Security

In a world of increasing concerns about privacy and data protection, security features are also paramount. For WhatsApp, that involves end-to-end encryption, multi-factor authentication, and the ability to block and report users.

Find out more about chat and messaging application features in our complete guide.

What are the biggest challenges when building a chat app like WhatsApp?

With traditional tools like email or SMS, users don’t generally expect an instant reply - but chat apps are almost exclusively a realtime medium. That might seem like a subtle distinction, but it makes a huge difference to the challenges you’ll face when building your app.

Here are some of the most important challenges you’ll need to consider when planning your realtime chat infrastructure:

1. Responding to sudden surges in usage

Demand for chat apps is inherently unpredictable: users will send messages how, when, and where they like. Delayed or missing messages just aren’t an option, even during unpredictable surges.

But how do you plan for these peaks, without wasting resources during quiet periods? Here are two key options:

  • Microservices architecture breaks your application into smaller components, so they can operate independently and avoid relying on a single point of failure.
  • Horizontal scaling allows you to tailor the number of instances you’re running to current demand, so you can scale both resources and their costs up and down as needed.

2. Avoiding downtime and outages

Surges aren’t the only threat you need to protect against. Downtime and outages can be profoundly frustrating to users and damaging to your reputation. Even WhatsApp isn’t immune to this challenge, as we discovered last year.

There are plenty of reasons downtime might occur, including DDOS attacks, fires, power outages, and more. To be prepared for the worst, you need redundancy – and lots of it. If a single virtual machine (VM) or instance goes offline, you need to be sure that there’s an instance elsewhere that can both pick up the load and be entirely unaffected by whatever caused the issue.

3. Achieving near-instant message delivery

The further apart your users are, the harder it is to guarantee realtime message delivery, wherever your customers are in the world. And yet, you’ll need to offer incredibly low delivery speeds for users to perceive them as instant. If you’re building your own infrastructure, you’ll need to ensure every part of your tech stack is carefully chosen to prioritize latency and global reach.

4. Delivering the right messages in the right order

Sometimes users can’t connect to the internet when they want to send a message. But as far as they’re concerned, that’s not an excuse for it to disappear entirely – so you need to ensure it can be queued and sent when they’re back online.

To do that, you need guaranteed message delivery to log each user’s stream of messages and replay them when the device connects. You’ll also need to have a clear chat history in the backend and ensure that matches up with the order in which the messages were sent. That all requires a scalable and robust database.

Find out more about the challenge of chat apps in our recent blog: “Scalable chat architecture: How to get it right first time.”

Architecture considerations when building a chat app like WhatsApp

If you’re building a chat app from scratch, you’ll need to think carefully about how you guarantee scalability, availability, and latency. Put simply, this isn’t optional - it’s the bare minimum of what you’ll need to offer in a very competitive market. But that doesn’t mean it’s simple or easy to achieve.

Here’s a look through some of the back-end technologies you’ll have to consider, as well as the decisions that WhatsApp took along the way.

1. Programming language

In what will become a running theme in this section, WhatsApp’s choice of programming language is a little out of the ordinary. When building the platform, the creators chose Erlang, which is now widely considered to be a specialist chat app language – and it’s a big part of how the app works at the scale it does.

The language prioritizes scalability, reliability, and high numbers of concurrent users. The way it’s designed allows it to quickly scale horizontally with new VMs or vertically with more cores, making it ideal for responding to quick surges without wasting resources.

2. Protocol

Protocols allow apps to transfer data between different parties in realtime. The technology you choose will play a huge role in deciding how quickly and reliably messages can be delivered.

WhatsApp uses the XMPP protocol on an Ejabberd server, a cross-platform tool that works across Web, Android, and iOS. As a transmission control protocol (TCP), it was specifically designed to prioritize reliability and guaranteed message delivery. In this sense, it’s similar to WebSockets, another protocol often used to support realtime chat.

WhatsApp’s highly-modified XMPP allows messages to be stored on a central server until the recipient connects, at which point the message is delivered, deleted from the server, and a confirmation sent to the sender. This essentially acts like a ‘digital handshake’, ensuring guaranteed delivery of messages in the right order.

3. Database

The database is where a user’s persistent data will be stored. This includes things like credentials, meta information, yet-to-be-delivered messages, and more.

For WhatsApp’s part, the choice here was a fairly easy one: Mnesia, which is the default database of Erlang. The tight integration between the two allows code to run quicker and be more explicit.

That means, taken together, Mnesia and Erlang are pretty outstanding when it comes to latency, with data objects being quickly retrievable in just a few microseconds.

4. Operating system

WhatsApp’s operating system, FreeBSD, is another left-field choice. In fact, the decision is so distinct that the founders were directly questioned about it in a Wired interview some years back.

According to their response, FreeBSD was chosen over more conventional tools like Linux, due to sheer “raw performance, especially in regards to system load per packet. No other operating system can beat FreeBSD.”

5. Virtual machine

WhatsApp’s virtual machine, BEAM, was specifically chosen and designed for use alongside Erlang. The tool is scalable and resistant to failures, as it distributes processes across separate cores. This creates an in-built redundancy and allows for concurrent processes – helping to avoid hold-ups and outages.

If you’ve made it this far, you’ve probably got the gist by now – every constituent piece of WhatsApp’s architecture is carefully chosen and customized for the absolute best performance of speed and reliability.

Building a chat app: What are your options?

Guaranteeing a smooth, realtime experience requires carefully choosing, building, and optimizing the infrastructure to power it. If we’ve learned anything from WhatsApp’s example, it’s that building this from scratch is trickier than it might first seem.

In our recent report, we set out to discover what it really takes to build your own realtime experiences:

  • 48% of realtime experiences take 3-6 months to build, with a further 21% taking over 6 months.
  • Realtime projects require an average of 4-10 engineers to deliver.
  • 53% of respondents said it took more time than expected to build the first version of their realtime infrastructure.
  • 65% of those who built their infrastructure in-house experienced outages in the past 12-18 months.
  • 51% of self-built infrastructure requires upkeep costs of $100K-$200K a year.

So building a realtime infrastructure from scratch can be a real challenge. But it’s not the only option. In fact, there are multiple ways to approach the task:

1. Build yourself - This gives you the maximum amount of control and customization, but is expensive, time-consuming, and unpredictable.

2. Use SaaS products – Software-as-a-service (SaaS) products are quicker and cheaper to implement, but often struggle to scale and respond to surges. They also give you little to no control over the features you offer or the technology that powers them.

3. PaaS – Platform-as-a-service products like Ably offer the best of both worlds: all the speed and low costs of a SaaS platform and the guaranteed quality of service you’d expect from a chat app like WhatsApp. (See how Ably compares to other realtime PaaS providers)

Build scalable chat applications with Ably

Unlike out-of-the-box SaaS products, Ably doesn’t lock you into a specific setup. We provide the SDKs and APIs you need to integrate our fully-managed realtime infrastructure into your existing tech stack.

That means you can guarantee your live chat works, delivering the right messages in the right order – wherever your users are in the world. Get seamless scalability, 99.999% uptime, and the world’s lowest latency, without the stress of building it yourself.

Ready to get started? Follow these instructions:

  1. Sign up for a free Ably account
  2. Follow our tutorial: How to build a scalable chat app
  3. Check out our tutorials and reference guides to explore further features



Join the Ably newsletter today

1000s of industry pioneers trust Ably for monthly insights on the realtime data economy.
Enter your email