Responding in real time to profile updates on a facebook-like app

Consider the following:

  • I have a user profile.
  • I have 500 connected friends.
  • When one of those friends gets suspended, I want them to be removed instantly from my friends list.

Possible Strategy 1

  • FriendsList array on my User object. This array contains data for all of my friends (name, profilePhoto, isSuspended etc) so I can watch it for changes and respond when a friend gets suspended.

    Cons of this approach

  • I would have to duplicate data many times, as someone can be friends with many people.

  • When a friend changed their profile photo, it would require as many database writes as they had friends.

Possible Strategy 2

  • Make the Users collection a partition open to all users. Watch it for changes and respond on the frontend if the changed user is your friend.

    Cons of this approach

  • Users collection could have 500 million members, can’t sync that much data to a mobile app.

It would be super cool if I could store references to other User objects in User.FriendsList, and then be updated when the referenced User object changed. Like this

  • MyUser.FriendsList = [reference to Sam, reference to Bob]
  • Bob.FriendsList = [reference to Sam, reference to Me]
  • Sam gets suspended from the app. Sam’s User object gets updated with the field suspended: 1
  • Bob and MyUser both receive a change event, letting us know the Sam’s profile has been updated - without the need to update the FriendsList arrays for Bob and MyUser.

However I don’t think that is possible.

Is anyone able to suggest a solution that would allow for real time updates on my friends, without the need to update data in many places or to sync a massive open collection?

1 Like