BLOGMessaging

XMPP - The Open Instant Messaging Protocol

xmpp-open-instant-messaging-protocol

Did you know that 41 million messages are sent via messaging apps every minute of every day?

Back in the 90’s, messaging services such as MSN and AOL messenger revolutionized the way we communicate by making free instant messaging available to anyone with an internet connection.

Fast forward 20+ years and you might be surprised to find that things haven’t changed too much in the way messaging apps are created and maintained - well, not in terms of the backend anyway.

In fact, the same open protocol that powered MSN and AOL all those years ago is still used today for the backend of some instant messaging apps, but in recent years other technologies have emerged that are more efficient and easier to apply. For instance, Chat APIs have emerged that implement a new type of technology to overcome the disadvantages of XMPP.

Whatsapp originally used XMPP, but has moved to its own proprietary binary protocol for reasons that will be discussed later in this article. But what is XMPP, exactly?

In this guide, we’ll answer the main question - “What is XMPP?”. We’ll also discuss how it works, what the benefits and downsides of using it are, and why Chat APIs are a better solution for in-app messaging.

A Brief History of XMPP

XMPP began life back in 1998 to provide the framework for Jabber. Jabber was an open-source instant messaging protocol and platform that was developed as a decentralized alternative to chat apps such as MSN Messenger.

Developer and Jabber open-source community member Jeremie Miller was the brains behind the Jabber protocol. Within a few years, the protocol came to be known as XMPP and was adopted by a variety of messaging service providers for use cases including group chat, instant messaging, user presence, in-app chat (for gaming and communities), and other real-time chat features.

What is XMPP?

XMPP stands for eXtensible Messaging and Presence Protocol. XMPP is an open standard chat protocol, which means it is publicly available without a license and can be used freely in commercial projects.

Over the years, there have been dozens of revisions and updates to the XMPP chat protocol. The latest versions are RFC 6120 (Core) and RFC 6121 (IM & Presence). Also, XMPP is extensible, hence the name, so there are plenty of extensions available in addition to the core protocol. The extensions are given the name XEP and offer extended functionality such as XEP-0045: Multi-user Chat (for group chats), XEP-0184: Message delivery receipts, and XEP-0012: Last Activity. For more details on protocols and extensions, visit this page.

XMPP has been designed specifically to power real-time chat and instant messaging by enabling the transfer of XML data across networks. In other words, it provides a way of sending text data to various network recipients, no matter what software or hardware they happen to be using.

xmpp-open-instant-messaging-protocol

In basic terms, XMPP enables users to send XML data between network endpoints using the standard internet Transmission Control Protocol (TCP). It achieves this by sending the XML data to an intermediary server which distributes the XML fragments to multiple endpoints, in a similar way to an email server.

What Does XMPP Do?

Now we have answered the question “What is XMPP?”, let’s take a look at what it does and how to use XMPP.

As mentioned earlier, XMPP is a messaging and presence protocol that handles XML data transfer. But what does that actually mean in terms of enabling chat and instant messaging features and functions?

The functions and features powered by XMPP include:

  • Transferring instant messages between two users
  • Multi-user chat between multiple users
  • Making and managing contact lists of users
  • Maintaining and displaying users’ presence status
  • Managing user permissions within a group channel
  • Message archive management
  • Message delivery receipts
  • Message typing indicator

How Does XMPP Work?

XMPP assigns a unique XMPP address to each client on the network, which acts in a similar way to an email address. The XMPP server then enables routing between the clients directly and in a multi-user chat, which means that different users can send and receive instant messages between each other and in a group.

Stream negotiation: In the diagram below a simple client/server negotiation and authentication process is shown. After establishing a TCP connection with the XMPP server, the stream negotiation and authentication process begins according to the chat protocol. As you can see, many packets need to be exchanged to establish a session. This adds extra latency just for connecting to a server and is one of the major downsides of XMPP.

xmpp-open-instant-messaging-protocol

The problem with XMPP is that there is a long process of stream negotiation with many round trips involved. This may bring some delays, especially in poor network conditions where the internet connection is not stable and there is not enough bandwidth.

Message sending: Once the session is successfully established between the client and the server, the client can now send and receive messages. Look at a simple message sent from Alice to Bob as an XMPP example.

<message type='chat' id='bea68aeb' to='bob@example.com'>
	<body>Hi. What is XMPP?</body>
</message>

Here you can see how much extra data, especially XML tags are included in each message just for sending a simple “Hi. What is XMPP?” message from Alice to Bob. This adds extra data overhead in any message exchanged between the client and server.

XMPP gateways can also be set up to bridge the gap between different domains and instant messaging protocols. The XMPP gateways also allow client-server sessions to be initiated and terminated. In other words, the XMPP protocol provides full control over the chat and messaging features within a platform.

There are some benefits to using an open-source chat protocol/standard like XMPP, which we’ll explain in a minute, but there are some downsides too. Although there are a large number of open-source client and server implementations of XMPP, none of them offer a complete solution and miss key chat features such as threaded replies, message reactions, votes, maximum number of participants in a channel, and many, many more.

Benefits of Using XMPP for Instant Messaging & Chat

There are several advantages of using the open-source XMPP protocol to build chat or instant messaging features.

Open-source: XMPP is free and open-source, which means you don’t need to pay any licence fees or subscriptions to use it commercially.

Decentralized: Using a similar method to email protocols such as SMTP, the XMPP method is decentralized, which means that it doesn’t rely on one single, central server. Anybody can set up and maintain an XMPP server that is owned by them. This gives the XMPP server owner much more control and flexibility over the instant messaging app or feature that they build.

Standardized: XMPP has been recognized and listed by the Internet Engineering Working Group (IETF) as a standardized XML streaming protocol for real-time messaging and presence protocol. XMPP specifications are available under RFC 6120 and RFC 6121.

Stability: XMPP has been around for over 20 years now with hundreds of developers working on the technology. It is a tried and tested model, with thousands of XMPP servers in operation and millions of people using XMPP-powered features daily.

Security: When you set up an XMPP protocol server, you can make it completely independent of any public XMPP networks. In other words, you can easily create an XMPP server for an internal business network that is not accessible from the outside. The XMPP technical specifications also include reliable and stable security technologies such as TLS and SASL.

Flexibility: XMPP can be applied in a wide variety of use-cases, including network management, collaboration tools, gaming, remote system monitoring, content feeds, live streaming, file sharing, etc.

Drawbacks of Using XMPP for Instant Messaging & Chat

As you would expect from an old technology, there are a few serious disadvantages if you decide to use the XMPP chat protocol to build in-app messaging features. Fortunately, there are alternatives, which we’ll discuss in the next section.

Overheads: Transferring the extra XML data in text, rather than using binary messaging protocols, incurs higher bandwidth costs as well as CPU power to parse XMLs. There is huge traffic for user presence as well which can bring increased overheads.

Scalability: In theory, XMPP allows you to add new servers within the existing architecture.This can be useful for businesses that expect high growth in the use of their chat or messaging features. However, if you decide to use open-source servers, they’re not designed to scale well to support the extra load. This is especially true when you’re dealing with hundreds of thousands, or even millions, of users.

Lack of extensibility: Although XMPP is extensible in theory, it is not easily extensible in practise. What this means is that it isn’t easy to add new features, functions, or capabilities to the protocol. With a Chat API you can request your developer to easily add new features and your app will automatically update to include the new features. This simply isn’t possible with XMPP and you will have to wait a long time for additions to become a standard.

Incomplete features: XMPP is not a full in-app chat or instant messaging solution. It merely defines how you should set up and implement the connections between client and server. As XMPP is an open standard, you can find some implementations of it that offer basic features, but none are ideal, especially not for in-app chat. For instance, most implementations miss out on message mentions, reactions, threaded replies, votes and polling, channel participant details, etc.

Time To Move Away From XMPP?

Now that you know the answer to “What is XMPP?” and some of the advantages and disadvantages of using it is a chat protocol, you may be wondering about alternatives.

All things considered, if you’re looking for versatile, easily-scalable, fully-featured instant messaging and chat features, you’re better off ditching XMPP and looking for another option.

Even ‘big name’ apps like Whatsapp have gotten rid of XMPP in the end. The reasons for this are that XMPP is too heavyweight, uses too much bandwidth, and is inflexible.

The Future of Instant Messaging - Chat APIs

On the whole, when you weigh up the pros and cons of the XMPP chat protocol, it becomes pretty clear that Chat APIs offer a more efficient, extensible, scalable, and cost-effective solution to adding messaging capabilities to an app or web app.

Yes, XMPP may be flexible, open, and free during the development stage, but it comes at a price when you actually deploy it within your app.

As they go through rigorous testing and quality control, with Chat APIs you can rest assured that the chat and messaging functions will all work correctly without glitches in the code.

Summary:

What is XMPP? XMPP is an open-source chat protocol that enables the transfer of XML data (messages) between multiple clients and servers. Unfortunately, XMPP can cause server overload and the data transfer costs can become prohibitive. XMPP was good for a long time, but since moving into the mobile age, the protocol doesn’t have the latency to keep up and uses far more data compared to binary protocols.

Chat APIs provide a better option for most companies that want to add chat and instant messaging features to their app. Chat APIs are fast - you can add chat functions within minutes, rather than waiting for weeks to build them from scratch using XMPP. You also avoid the drawbacks - server lag, inextensibility, and increased overheads.

To find out more about Sceyt’s Chat API and SDKs, get in touch today.

Let’s Talk