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)

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