0

I am building a Pinterest-like website, and I need to store albums and their related photos in a database, so each User has Albums that have Photos, and each Photo has Pins

Since the data is flat, and I do not need complicated relations, I thought of storing the information in a NoSQL database such as MongoDB, so the main document is an album, and each album holds an object (list) of photos.

However , I'm not sure that this is a good architecture , as I need to query very fast Photos by title/description/user regardless of the album which contains it. Should I use relational Database instead? or it can be achieved in NoSql database with high performance?

Community
  • 1
  • 1
Yuvals
  • 3,094
  • 5
  • 32
  • 60

2 Answers2

0

Each NoSQL database solves a given problem: performance, resilience, scalabiilty... But it usually comes at a cost, which depends on the type of database: no transaction or limited transactions, limited querying capability... If you choose a NoSQL database, choose it because it solves a problem you effectively have. Otherwise, It's preferable to stick to relational, to avoid the limitations of NoSQL Databases

Edit If performance is you main concern, look this question

Community
  • 1
  • 1
Pascal Le Merrer
  • 5,883
  • 20
  • 35
  • My biggest concern is high performance of free-text querying. i.e., searching all photos by freetext (going over title, description, user name) – Yuvals Oct 18 '16 at 17:07
0

There are scenarios where you should use NoSQL and there are scenario in which you MUST not use NoSQL. If your application has to do with high level of transactions NoSQL is not a safe bet as you would miss the umbrella of transaction which relational DB provides.

Having said that MongoDB in particular would be good choice for your use-case, since MongoDB provides wide variety of query options unlike other NoSQL. All you need to do is use a well-thought (embedded) structure and provide proper indexing on the fields which you would be queried for. Maybe you would want to keep in mind multikey indexes and compound indexes beforehand.

MongoDB is supposed to provide atleast in theory seamless scalability. the schema free DB provides you the flexibility to add new features or enhancement without much hassle.

Rahul Kumar
  • 2,781
  • 1
  • 21
  • 29
  • "MongoDB provides wide variety of query options unlike other NoSQL" : there are other database which offers the same capabilities, and are much easier to use than Mongo's Aggregation framework (look at [ArangoDB](https://www.arangodb.com/) by example). – Pascal Le Merrer Oct 14 '16 at 19:11
  • Thank you very much for the answer. I do need high performance and scalability. Therefor I considered to user MongoDB, as most of the traffic will come from many real time search for photos (name/description) like Pinterest. In this case what is the best option to organize it ? the parent document should be ab Album, that contains photos, or the main object should be Photo , related to album and hold album ID/name, user details etc.? – Yuvals Oct 15 '16 at 08:11
  • @Yuvals there is no quick and easy answer to that as it depends on the type of the application and how you see it growing. Sometime design decisions are difficult without intricate details. Though the way I would proceed will be having a User Collection , inside User document we can have an array of albums with each album with a unique id and usual details. There would be one more Photos collection which will have all the metadata including album id, please note that for storing (heavy) image file I would probably use AWS S3 and just will have keys/paths in my document of Photos collection. – Rahul Kumar Oct 18 '16 at 11:25