Reputation: 3272
I have a database with posts
, users
and other nodes like classic social-media app.
I'm continuing implementing best-practices to my application. And now I want to rewrite my news strip (posts of users, that I follow (like home tab in Instagram)).
I have read some info about fan-out
strategy and now I'm confused in how to do it properly.
So, I have 2 opportunities:
Like here: Every time user adds new post
, this post
with full information will be copied to users-timeline(users news strip)/UID/postId: FULL INFO
to all followers
of this user
. And every edit will edit each mention of this post
.
Every time user adds new post
, this postID
will be copied to user-timeline(users news strip)/UID/postId: true
to all followers
of this user
. And every edit will edit only source post.
Which logic is better with Firebase?
Upvotes: 6
Views: 3230
Reputation: 138999
I suggest you using David's East solution. As I see in his post, he uses Firebase denormalization and data flatten, which are the best common practices within Firebase.
I also recommend you reading NoSQL Data Modeling Techniques and Structuring your Firebase Data correctly for a Complex App for a better understanding.
If you have a SQL background, I recommend you seeing also David's East tutorial, The Firebase Database For SQL Developers.
Upvotes: 4