'How to implement follow feature in firebase firestore?

I'm trying to implement Follow/Unfollow option for my users similar to Twitter. I'm thinking along the lines of below architecture for a collection named follow_map

userA

-- following : [userC, userD ...]

-- followedBy : [userC]

userC

-- following : [userA]

-- followedBy : [userA, userB ....]

I'll be using usernames instead of direct IDs maybe. Is there a better way to implement Follow/Unfollow option with firestore? If yes, plz let me know

Also I just thought of this and I'm new to Firebase so I'm not sure if I'll implement the optimal firestore rules so if possible plz let me know how to implement firestore rules for this architecture

For example I'm not sure how to allow only userA to modify only his username in the followedBy of userC.

or is it better to go about with kind of architecture mentioned here Making a follow system with firestore and cloud functions



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source