Structure of the Instagram database in Firebase?

0

I want to recreate the structure of the Instagram database in Firebase.

For this, I use the example of Google Posts as an example:

- User structure: Collection where we save the data of a user, there are users with ID "U-001" and "U-002"

- Posts structure: Collection where we keep the data of a post, there is the post "P-001" created by "U-001" and the post "P-002" created by the user "U-002". A post can have a number of stars that indicate which users liked the post.

- Post List structure: Collection that defines the list of posts to show in the app, in the case of Instagram, the main window where we see the list of publications (the photos) of the users that we follow, in the list we will only show the title of each post .

  • The user "U-001" sees the post he has created and the user's post to which "U-002" follows.
  • On the other hand, the user "U-002" does not follow anyone so she only sees the post she has created.

. .

Imagine that the user "U-002" has 100 million followers.

This means that when the user "U-002" publishes a new post , she has to write in each list ( list_posts ) of each user that makes her > follower for this to be notified or when this opens the application will be loaded the new post of "U-002".

This is a small number of followers, nothing happens, but when you have 100 million followers, in Firebase I have to make a query to get those 100 million user IDs, and write in each list_post of each of those users and add the post created by the user "U-002"?

I find it absurd, there are many megas that are downloaded, many that are uploaded ... etc to perform that function.

    
asked by richi 28.05.2017 в 12:50
source

1 answer

2

Richi,

As you put it, having a reference of each post in the list of each follower is not scalable. Ideally, simply keep a list of followers (for each user) and at the time the user posts, notify all his followers.

One recommendation would be to use Firebase functions , which allows you to extend the logic of Firebase services using javascript in the Same serverless environment in which these services run. That way you could define for example a function that is called every time a post is created and send a notification to all its followers, without having to make changes to the database or downloads.

    
answered by 30.05.2017 в 17:16