I have a mysql database containing tables like User, playlist, videos, tags.
Based on this I would like to collect the user activity on the application. the example use cases may be :
a.) (user) joined (app) on (date)
b.) (user) created playlist (playlist) on (date)
c.) (user) added (video(s)) to playlist (playlist)
d.) (user) added tags (tag(s)) to video in playlist (playlist)
Given such data, which would be better alternative to design a user activity schema? relational(I am using MySQL) or NoSQL(non-relational, like MongoDB)
Favoring NoSQL
a.) The other thing is since activity lit will be huge, retrieving data should be fast, I read Document Oriented database performs well in such scenarios since no joining between the tables is needed
b.) Since the activity log may contain no,one,many variables depending upon the activity happening, a relational schema might not be a good solution.
I would like to learn more about it, please share the knowledge :)
Thank you
NoSQL seems to work better on both unstructured and unrelated data. The better solutions are the crossover databases that have elements of both NoSQL and SQL. RDBMSs that use SQL are schema–oriented which means the structure of the data should be known in advance to ensure that the data adheres to the schema.
Storing capacity of large volumes of unstructured data: A NoSQL database can store unlimited sets of data with any types. Moreover, it has the user flexibility to change the data type on the go. It is a document based database. Hence, no need to define the data type in advance.
They lack support for complex queries such as joins across tables. While relational databases rely heavily on normalization and referential integrity, NoSQL databases are not strictly normalized. Generally, NoSQL databases do not implement multi-key transactions.
As for speed, NoSQL is generally faster than SQL, especially for key-value storage in our experiment; On the other hand, NoSQL database may not fully support ACID transactions, which may result data inconsistency.
You are correct, main problem in any relational database is join.
So, you can create tracking system in mongodb or in mysql, just avoid joins:
So structure will be like this:
id
activity_type - int
user_id
date
field1
field2
filed3
where activity_type (Signup = 1, CreatedPlaylist =2, ...)
To avoid join with user table you should add some user related data (data, that you need display, like first_name, last_name) to each activity row.
With provided above solution you can stay with mysql, and speed will same. Mongodb will be faster when you embedd in document many things, that you need join in relational database.
As a long-time Relational user, it seems to me the decision hinges on whether or not you have financial transactions or the tracking of physical goods. The "money and stuff" is what Relational was invented for. It is extremely good at it and maintains a very high standard of correctness.
However, when you do not have to balance books, or make sure you don't accidentally sell more widgets than you have, then use what you are comfortable with. Mongo, Couch, whatever.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With