I’m building a simple chat server in java , where users can have private conversations with each other. I want to save those conversation at a server level(not on client side) so I can list them to the users as a conversation log service.
I’m also using MySQL as a database in my software.
What I’m looking is an optimized way to save those conversations and also a fast way to list them later.
So far I’ve thought on 2 implementations.
-
using the MySQL database and
a) save the conversation in a row as a text, but the problem is that some conversations are very huge(lots of chars) and I might have problems saving the entire conversation
b) save every line of the conversation in a row, but this way speed problems can appear when I want to list the entire conversation
-
saving every conversation in a separated text file, but I’m afraid read/write problems can appear, especially when the users(clients) are writing(sending text) very fast.
Thanks
This is big architectural problem, you know. Companies like facebook and twitter spent lots of time and money to solve your problem in robust way. If your chat server is simple (As you’ve written), use 1.b way, but make an abstraction layer (something like
saveConversation,getConversation). If in future speed wouldn’t satisfy you, think about more efficient representation, like NoSQL database (LevelDB or something like this). Don’t think about performance now, make a prototype with good abstraction and pluggable architecture.