'Should inbox messages be stored in a database, or are there more effecient alternatives?
I am working on a chat website where users can create rooms, invite others and chat together. I have a lot of the core infrastructure for the website in place, including most of the server and half of the website itself, but I have come across a decision I have to make.
Each user can receive messages to their inbox, for example, they receieved an invite request to join another user's room, or a more general alert relating to their account.
Question: should I store these inbox messages in a database, and what are the alternatives?
Inbox messages typically last for a couple of days, so they are quite ephemeral pieces of data. If I was to store it in a database, this is a rough idea on how the entity would look:
| accountId | message | type |
|-----------|---------------------------------------------------------|-----------------|
| 59 | user3 requested you to join 'hangouts' | invite_request |
| 24 | dialto accepted your request to join 'study group' | invite_response |
| 67 | please confirm your email address to claim your account | account_alert |
On the website, I would create an interface where they can view their inbox messages, and they can discard them if they want. If they discard an inbox message, then it is deleted in the database.
Is this the best solution for this problem, in terms of effieciency? Are there alternatives?
I don't know if this will help but here is my tech stack for this application:
- Database: MySQL
- Backend: NodeJS | Graphql
- Frontend: React | Graphql
Thanks a bunch.
[ I might take around 6-8 hours to respond as I am about the leave for school = 7:48 AM, sorry :) ]
Solution 1:[1]
There are no good alternatives for persistence of structured data.
There are many different databases which are optimised for different purposes, no one size fits all..
As a thumb rule, when you start a project, you keep it simple and avoid complexity at all cost.
When you get some real scale, then you start doing optimizations and looking at access patterns, horizontal scaling/partitioning(distributed systems), in memory stores, etc..
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | KafKafOwn |
