1

Say we have an app that allows people to like or dislike pictures.

This looks like a data-intensive application, as you would expect a huge amount of (dis)like requests, so say we chose Node.js for it.

As we don't want people to vote more than once, we need a way of relating the picId and userId. This could be done:

  • with a relational database, by using a table where picId and userId are keys,
  • with NoSQL, by creating a 'file' for each user and storing there all the picIds she voted... or the other way around, creating a file for each picture and storing there all the userIds that have voted the pic.

This part of the DB will be intensively read and written, as for every vote you first need to check if the user has already voted and then write the new vote, plus updating the total vote count of the pic.

Which is the best option (based ONLY on technical reasons)?

2
  • There is also UPSERT option. Commented Aug 13, 2016 at 13:18
  • My logic would be "when you have relations, you pick relational database". Commented Aug 13, 2016 at 13:18

1 Answer 1

1

Say you use MongoDB (NoSQL document-oriented DB) and you have unique usernames. You can do that :

  • Create a Model ImageModel (mongoose model) for the images and UserModel for your users
  • Store the images into the database (you can use references to find them)
  • In your ImageModel, you have a like and dislike array containing the usernames of the users who will like or dislike your picture

With that, the number of like/dislike will be the length of the array and you will be able to find out easily what your users like or dislike.

Nevertheless, if you want to create a social-network application, document-oriented DB aren't the best choices because they don't implements relations and it will be difficult for you to link informations and users. SQL DB aren't good either because they don't offer enough performance for big apps, so I suggest you to take a look at NoSQL Graph or Graph-Document DB like OrientDB or Neo4j

I hope it could help you and sry for my english (feel free to correct me) ;)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.