I am reading the following link to learn about system designs of various systems. https://www.educative.io/collection/page/5668639101419520/5649050225344512/5673385510043648 (This is a paid link, I am attaching all explanations below) In an attempt to explain the system design of Instagram the above link gives us the following requirements:
- Users should be able to upload/download/view photos.
- Users can perform searches based on photo/video titles.
- Users can follow other users.
- The system should be able to generate and display a user’s News Feed consisting of top photos from all the people the user follows
These schemas suit an RDBMS well.
The link says, if we want to scale up we need to tap into the benefits of NoSQL, and for this, we will need to create another table UserPhoto in which, the ‘key’ would be ‘UserID’ and the ‘value’ would be the list of ‘PhotoIDs’ the user owns, stored in different columns.
In the link, they have suggested the use of Cassandra NoSQL database for this use case.
To fulfill the requirement of Generating a user's newsfeed by aggregating the top 100 photos of all the users followed by the current user, the link suggests us to have our PhotoID comprise of a number and timestamp of photo upload (epoch time) because we have a primary index on photo Id in Photo table. This is the point where it got confusing for me.
How will we use the above schema to get 100 latest photos of all the users followed by the current user in a NoSQL database?