While learning Java I have come across a lot of questions regarding how to program something ‘the best way’. An example is a chat program.
When a changes their status, display name, display picture or personal message it sends a request to the server and the server keeps all the server data in memory. My question is: Is it good practice to avoid database I/O and keep everything sync’d in memory. So if a user changes their display name should I update the users status in memory on the server AND update it in the database? Or wait till the user disconnects and then write their information to database?
I hope I am clear. This goes for all different kinds of programs, syncing settings ect..
I ask this because if the server crashes then all the data in memory wouldnt be saved in the database and user info would be rolled back.
Thanks guys.
For this question, there is no single “best practice”. at best, there are probably a handful of “best practices” covering a variety of more specific use cases. as already pointed out in the comments on the OP, there are various questions that come up, e.g.:
until you start answering these questions, no one can start giving concrete recommendations.