Saturday 1 April 2017

How can I prevent data loss when saving web socket messages to mysql?

I am trying to implement a websocket realtime chat system in nodejs. I already have a login system in place and the websocket chat system. The only thing I'm suck on is saving the messages to MySQL so that the user can access their chat history. The problem is that I don't want to send a web socket message to the recipient then have the MySQL insert fail for whatever reason.

A possible solution: The obvious solution is to save the message data in MySQL then send the web socket message to the recipient. If there is an error, send that instead of the message to let the user know. Wouldn't this defeat the purpose of web sockets though, if the server has to wait for a MySQL insert success confirmation?



via LearnSomeMore

No comments:

Post a Comment