database design - Model a Q & A site in mongoDB -
i need model q & site stackoverflow in mongodb, here main issues.
i have 2 main objects - questions , users (just forget others answers etc...).
users ask questions. need display user question always. possible search questions , browse questions. safer user ask less 1000 questions.
users have reputation updated , current reputation should shown question time.
solution 1 : embed users inside questions -
no need perform join when users reputation changes, relevant questions should updated. , not easy display single users
solution 2 : model users , question separate collection (just in rdbms) -
now updating reputation not issue need join between users , question every time question retrieved. in rdbms. furthermore mongodb doesn't have joins , join 2 calls - 1 question , 1 user, if there 100 questions retrieve there'll 100 calls 100 separate users - not good.
soluion 3 : embed users inside questions , have separate collection users too
when updating, update user collection , embedded users, when displaying user - use users
so 1 should use ? or else best solved rdbms mysql ?. , how fast field updates in mongodb ?
i'd love use mongo because of speed , easiness route read requests replicas , sharding (if site grew out of single server unlikely anyway ;( )
solution 1 sonunds me incompleted because in way should have storage of users.
solution 2 can solution, , it's better rdbms because in document database can't make 'real' join , that's means can easy scale system.
in case if system not big so, choose solution #2.
solution 3 no need embedd within question user info, embed information need display.
so best solution high scalable system be:
users
- primary store of user related info, in addition here can have questions count, reputation, answers count , statistic data need
questions {shortuserinfo {username, reputation, goldbadgetscount, ...} }
- store questions user related info need display
answers
particular question should embedded within question. , contais shortuserinfo
(or so).
solution #3 give ability easy scale system , make super fast. when user update profile(or reputation) should update information within each question/answer, can work async, in case information can stale time, it's okay. can change profile , see user name can still old on questions/answers.
hope you.
Comments
Post a Comment