1👍
✅
Just create a table for the messages and make sure one of the columns is the chatroom name or id so you can query last 10 messages on subscribing to chatroom.
So when rendering the page, you get the last messages from database and the next ones come from socket.
If you don’t want the messages saved for long just truncate the table periodically to cleanup.
Source:stackexchange.com