0

So I want to develop a chat system based on nodejs and socket.io, I have made a prototype and it works, the only thing that is stuck in my mind is how to store the chat messages in the database.

I guess is not a good idea to store a message when a user hits the enter button, because this is live chat you could have 1000 just from a user in 30-60 min.

The question is WHEN to store the data in the database, because I don't think that storing right away when the user hits enter will work on the long term?

The chat works on the same idea as facebook.

2
  • Why not just cache your data in memory, then store it every minute, and clear the cache ? Commented Aug 7, 2013 at 14:24
  • Well this will be basicly the same thing, you will do a tone of inserts every minute, the idea I guess is to spread it over different periods of time. Commented Aug 7, 2013 at 14:26

1 Answer 1

2

If you are not saving the messages at the moment, how do you plan to save them when you want to?

The messages sent have been delivered to the client and your server no longer has them, and you can't use the client to store them in a database.

You need to store the messages as the user sends them.

Sign up to request clarification or add additional context in comments.

4 Comments

Good point right here, my only worry is about the server if this could be done, but I guess you speak from a point of experience, do you think facebook stores them in the DB right away or any other big sites? I don't know how they do it on these big sites, so that's why I am asking
I would guess that Facebook does store the messages instantly. Go send a message to your friend, quickly close the browser, clear cookies & cache, log back in and you'll see your message still there.
I don't think MySQL will die on you. But if your lucky enough to have so many inserts happening per second, then you can start to load balance your MySQL databases.
@Uffo If you need high scalability database you should try cassandra.apache.org

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.