My app let user sell and buy products that other users posted.
I have a general recent post fragment where i show the most recent post of all users no matter if you follow them or not. So with this aproach(table below), getting the last 30 posts ordered by timestamp is very fast because of indexing in firestore.
users(collection){
user1(document){
username: rocky
following:[user2,user3....] // or subcollection with users as documents
}
user2(document){
username: paul
following:[user2,user5....] // or subcollection with users as documents
}
}
posts(collection){
post1(document){
author:user1
timestamp:...
imageurl:...
...
}
post2(document){
author: user55
timestamp:...
imageurl:...
...
}
}
But i also have a feed fragment that works exactly like instagram's feed, it shows the post of the people i follow ordered by date.
I was thinking i can store the users that a user follow inside a list or create a subcollection in every user, then when i load the app get that list of ids of users and here is where i dont know how to procced.
So lets say i get a list of 5k ids, now i have to search for all the posts that contain every id, get the posts and order them by date.
I would have to make 5k reads and some more to read the posts. Is there an efficient way of doing that?
I reasearched a bit and found that a good way is to denormalize the data and add a new collection like this:
feed(collection):{
user1(document){
posts(collection){
post1(document){
//post info
}
post2(document)
//post info
}
}
}
But like in instagram the main focus of the app is to create post and have people see it. So most of the users will create many posts per day.
So if i have 100 users with 10k followeers and those 100 users create 3 post a day i would have like 3 millon writes just for that 100 users plus a few more if they edit that post in the future and that sounds scary!!
Is there a better way of doing this?
Maybe im thinking this the wrong way, if i have 100 users with 10k followers this means my app is very active so i should be able to generate revenue to cover that cost.
Sorry fot the long post. Any help is appreciated.