Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase fan-out structure for news feed

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:

  1. 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.

  2. 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?

like image 654
Vlad Pulichev Avatar asked Jul 14 '17 10:07

Vlad Pulichev


1 Answers

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.

like image 153
Alex Mamo Avatar answered Sep 28 '22 21:09

Alex Mamo