Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Structure of chat application and required technologies

I'm planning to build website with chat functionality. Users will have profiles (like in a social network) and each of them should be able to open a new chat room with another user. I need to be able to save chat history and also I need to know which user is currently online.

Below is a diagram of structure which I made for this project:

diagram

I'm planning to have a server running Apache to host my website. It will communicate with a DB server and a Node.js server running Socket.io. For each user which is currently logged in I will create a socket and this I'll know who is online by the socket status (open/closed). For each chat room I will create another socket for sending and receiving messages. In order to save the history everything need to pass through the Node.js server.

Is this approach correct?
Are other technologies needed and what is the best way to create chat between two users and save the history onto a database?

like image 728
nikitz Avatar asked Mar 11 '14 14:03

nikitz


Video Answer


1 Answers

I believe your architecture is one of the best possible for such application.

I would like to state a few corrections, though.

You only need one socket with each client to monitor their online status and to transfer messages through it.

Something important you'll have to consider is security. You will certainly need an SSL certificate and encrypted communication, especially for messages. Thus you will have to consider very carefully how you are going to transfer messages and probably use an asymmetric encryption on both your servers and clients. (Note that to make you client side MITM resistant, the JavaScript that which encrypts and signs messages will have to be transferred over a secure connection - HTTPS).

The XMPP Protocol is a good idea (I give credit to @Schwertfisch), but might not be easy to implement. Fortunately there are JavaScript libraries available that implement it like Strophe.js which I guess will make things simpler.

Another thing you will have to consider is your database. While a relational model could serve well enough for such purpose it will most surely fail you if you have more traffic. I would recommend using NoSQL database engine like MongoDB or you might use the PaaS-like DynamoDB.
A well designed NoSQL storage will certainly boost your application's performance. Using DynamoDB will also discard the poor configuration and maintenance factors.

Also if you are planning to get big at some point of time you will have to make each of your application components scalable. Consider carefully all kinds of caching, storing data and etc. especially for the Node.js servers. You will have to make a backbone network to transfer messages between Node.js instances if for example two users are connected to different Node.js instances.

Client A > Chat Server 1 > Chat Server 2 > Client B

You can use protocols like MPI or a Message Queue to handle this backbone communication.

I would like to summarise that what you are planning is not that easy task. I know that there can be an easier implementation, but note that if you choose it, at some point of time not only you might have to rewrite everything, but also you might experience instability issues and that may turn down users.

Just one last piece of advice: Use the Latest and Greatest Technologies available out there and you might just do better than Facebook.

This sounds like a big system and an ambiguous project, so Good Luck and consider everything.

like image 64
Itay Grudev Avatar answered Sep 30 '22 14:09

Itay Grudev