Backend Development 6 min read

Choosing and Optimizing IM Protocols and Servers: A Practical Guide

This article reviews common instant‑messaging protocols, compares popular IM servers such as Openfire, Tigase and Ejabberd, and proposes practical improvements to XMPP handling, server performance, and mobile IM challenges, while also evaluating third‑party services and offering deployment time estimates.

Art of Distributed System Architecture Design
Art of Distributed System Architecture Design
Art of Distributed System Architecture Design
Choosing and Optimizing IM Protocols and Servers: A Practical Guide

1. Common IM Protocols

2. Choosing an IM Server

After researching online, the currently popular IM servers are Openfire, Tigase, and Ejabberd.

3. Issues and Improvements for XMPP Protocol

1) Login handshake improvement Xmpp QuickStart

2) Heartbeat improvement Original XMPP Ping/Pong used >40 bytes; the improvement uses a one‑way white‑space ping of only 4 bytes. In private protocols, a two‑way ping of 2 bytes is sufficient.

3) File transfer - XMPP originally used peer‑to‑peer transfer; the improvement uploads files to a server via HTTP. - Voice and video are compressed before upload. - Images are downloaded as thumbnails by default.

4) Presence In mobile environments, users are assumed always online to avoid reconnection storms caused by network changes (e.g., Wi‑Fi to 3G, subway, edge Wi‑Fi).

5) MUC (Multi‑User Chat) rooms At the business layer, messages are broadcast to all users regardless of their online status.

4. Improvements Based on Openfire Server

1) Message receipt Maintain a server‑side message queue and delete messages when client acknowledgments are received.

2) Performance improvement Avoid using the built‑in database; store VCard and friend‑list data in Redis.

3) Large‑scale message storage Use Kafka for message persistence, coordinate with database clusters via scheduled pulls, employ Zookeeper for distributed locks, and use LVS for front‑end load balancing.

5. Pitfalls of Mobile IM

1) Long connections Android clients must maintain a persistent connection to the server. Reconnection should be delayed slightly after disconnection to prevent storms in poor network areas.

2) Heartbeat packets (GGSN) Maintain the mobile network GGSN for reliable heartbeats.

3) Message acknowledgment handling (Ack) Mobile networks easily lose packets; both sending and receiving sides should implement acknowledgment processing.

4) Voice and image transmission optimization Large data is split into multiple packets, each roughly 10 bytes.

6. Third‑Party IM Services

1) Huanxin (环信) Founded in April 2013, claims 60 million registered users and over 1 000 apps using the service.

2) LeanCloud Since its release in September 2013, it has attracted nearly ten thousand mobile applications and developers.

7. Conclusion

If you build an IM framework from scratch:

Basic functionality: ~3 months

Well‑polished product: 9 months to 1 year

WeChat‑level quality: 2 years

When using existing IM servers, considering performance, maintenance, and hiring costs, the ranking is: Tigase > Openfire > Ejabberd.

backendInstant MessagingXMPPServer SelectionTigaseOpenfire
Art of Distributed System Architecture Design
Written by

Art of Distributed System Architecture Design

Introductions to large-scale distributed system architectures; insights and knowledge sharing on large-scale internet system architecture; front-end web architecture overviews; practical tips and experiences with PHP, JavaScript, Erlang, C/C++ and other languages in large-scale internet system development.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.