August 22, 2012

Online chat with database – Fastest way?

Question by krtek

Hello I’m going to create a web based chatting program.
All chats are private, no groupboxes.

I need to keep a log of all the chats.
My idea is to push all messages to a mysql database and then check this database every half a second for incoming messages.

Is this the best way for creating the web app? The site should support 2000 users chatting simultaneously.

Are there maybe better options? I’ve seen people talking about multiple databases, text files, a combination of TCP/IP (IRC) and SQL, etc.

Answer by Starx

MySQL is capable of handling large amount concurrent request at a time, but how you manage and maintain the database is a main point.

Perfectly maintained and indexed table should show no problem. Keep the table’s structure as simple as possible. Something like

+----------------+--------------+-----------------
|    from        |     to       |   message      |
+----------------+--------------+-----------------

And, there is no perfect way to create a chat program. Depends on lots of other factors like

  • Request Type: AJAX or Comet or WebSocket
  • Application Coding: No garbage Coding, Clean OO codes following one of more Design pattens
  • Caching: Cache most of the static information as possible.
  • Data Archiving or Transaction Handling
  • Query What do you fetch together with the message (may be those things could be cached before. These things include names, avatar etc)

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!