0

How do you keep track of the fan-out paths?
I'm not sure if I should call it a relationship. Anyway...
I'll take the following structure as an example. Say we have some form of social app. In which every user adds their friend and gives nicknames.

  "friends": {
    "user2": {
      "user1": {
        "nickname": "wife",
        "uid": "user1"
      }
    },
    "user3": {
      "user1": {
        "nickname": "bff",
        "uid": "user1"
      }
    }
  }
  "users": {
    "user1": {
        "name": "Rubia Castangia",
        "gender": "Female",
        "age": 22
    },
    "user2": {
        "name": "Roxy Brightling",
        "gender": "Male",
        "age": 23
    },
    "user3":{
        "name": "Carole Delgardillo",
        "gender": "Female",
        "age": 35
    }
  }

Let's say we add timeline & followers feature to the app with the following structure

"timeline": {
    "user2": {
        "post1234": {
            "text": "Feeling bored",
            "author_nick": "wife",
            "uid": "user1"
        }
    },
    "user3": {
        "post1235": {
            "text": "Feeling bored",
            "author_nickname": "bff",
            "uid": "user1"
        }
    }
},
"followers": {
    "user1": {
        "user2": true,
        "user3": true
    }
}

So after that we add another feature.... and it goes on.
So the relationships are e.g: /timeline/userId/postId/author_nick must be updated when user2 updates the nickname for friendId here: /friends/userId/friendId/nickname

As the app becomes more complex, I tend to forget which paths must I fan-out. Is there any specific tools are you people using to keep track of the relations between paths to fan-out?

Atu
  • 917
  • 1
  • 11
  • 20
  • @AtifAbbAsi the above isn't my real structure. Just came up with that for the sake of the question. – Atu May 17 '17 at 08:11
  • if you Post Your Database Structure on Form of picture would be easy fro me to help you @Atu http://stackoverflow.com/questions/38181973/firebase-database-the-fan-out-technique?rq=1 – Atif AbbAsi May 17 '17 at 10:12

1 Answers1

1

No tools are needed - just model your database structure according to your needs and keep it denormalized and as flat as possible.

How about something like this:

users
  user1
    *user_data*
  user2
    *user_data*
    following
      user1: true
  user3
    *user_data*

nicknames
  user2
    user1: wife 
    user4: friendo
  user3
    user1: bff 

posts
   user1
     post1
       text: "bla"

And roughly this is what you can do:

  • user2 logs in
  • fetch the user object
  • fetch the nickname map for that user
  • for every person in the "following" map: fetch that user's posts
  • When displaying a post content, search for a nickname mapping, otherwise display the username

Simple enough?

Itai Hanski
  • 8,540
  • 5
  • 45
  • 65