Reputation: 323
I'm currently building a community based on firebase which has timelines and posts similar to Facebook. When a users creates a post it should automatically popup in the timelines of his or her followers.
Google suggest doing this via fanout updates: https://firebase.googleblog.com/2015/10/client-side-fan-out-for-data-consistency_73.html
But I wonder: If a user has - let's say - 20k followers, I would first have to download a list of all his followers (even with an index like { <user-id>: true }
this would be quite large) and then update each of those users timelines with the fanout approach like so:
// followers = { <user-id-1>: true, <user-id-2>: true, ... }
const fanout = {};
const post = { text: 'foo', timestamp: firebase.database.ServerValue.TIMESTAMP };
Object.keys(followers).map((key) => {
fanout[`timeline/${key}/${postId}`] = post;
});
firebase.database().ref().update(fanout);
This will also be tough for security rules to figure out which timeline the user is allowed to update.
My approach is a server which watches the global posts ref. If there is an update or an added child, it looks for the followers of the post creator and updates the timelines accordingly. This way I don't have to fiddle with security rules and the client has much less work to do.
Am I wrong?
Upvotes: 0
Views: 541
Reputation: 598847
If you are willing to run fan-out on a server, by all means do. It will indeed remove a potential bottle neck when the amount of data to be fanned out becomes too large for running on a client.
But the vast majority of projects will never reach that level, and early on in their project's life-cycle many developers are unwilling to running servers, even if only for fanning out data. So client-side fan-out is a great option for those developers.
Upvotes: 2