Multi-service Web/AJAX-based instant messaging system


1. Goal

Create an multi-service instant messaging AJAX-based web application with internal accounting.

2. Main problem

We need to connect to IM servers from HTTP client (browser).
HTTP is a stateless protocol. This means that, theoretically, each HTTP request is being proccessed by separate http daemon proccess.
Once request proccessed (data sent to client), server fogets about client.

All IM services protocols are stateful.
When client connects to IM server, socket connection being created and connection much remain open for succesfull communication.

3. Proposed solutions

3.1. Jabber/punjab way
Jabber is open-source IM solution, which is based on XMPP standart (was standartized in 2004) . Google uses XMPP.

There are transports (external libraries) from Jabberd (jabber server) to other protocols/services, such as AIM/ICQ, YIM, MSN, IRC etc.
Solution involves deployed Jabberd server with transports to AIM, YIM and MSN transports.

Once jabberd with tarnsports deployed, we now can talk to external IM services using XMPP protocol.
In other words, we can talk to another IM service users like if they would be Jabber clients.

To use stateful protocols within stateless protocol, some kind of intermediate layer should be created which will handle a pool of connections to our Jabberd and serve incoming stateless queries.
There is an open source interface which looks like exacty what we need: http://punjab.sourceforge.net/ Its a python/twisted application which provides Jabber connection on one side and SOAP on another.




Image 1. Jabber/punjab way



Pros:
1. Ease of server-side implementation.

Cons:
1. In some cases, Jabberd transports can be quite unstable and falling down from time to time.
2. Some extended features of external IM services will not be supported, although they are unlikely going to be implemented in our system.


3.1. Custom server

Second approach is to code own daemon which will accept SOAP requests from web server side and talk to IM services directly.
Internally, it will fork a separate dedicated proccess for each new logged in user. Once user logged out (or idle during some time), proccess will be killed.
Core daemon will route incoming SOAP connections to child proccess based on some internal SOAP session identifier.




Image 2. Custom server way



Pros:
1. Stability
2. Performance

Cons:
1. Custom connection pooling daemon is a quite complex application.
2. Most likely, windows server will be needed, since there are more stable IM libraries implementation for windows rather than unix and SOAP layer will be easier to implement.




Alex Kovalyov @ Webta Labs