π 28 Jul 2025
View on Github βToday I completed a full Follow/Unfollow feature for DevFlow β simulating how apps like Twitter manage social relationships.
Feature | Status |
---|---|
β Follow a user | β Done |
β Unfollow a user | β Done |
π Get followers list | β Done |
π Get followings list | β Done |
π§ Prevent duplicate follows | β Handled |
Each user document includes:
{
_id: ObjectId,
username: "sangam",
followers: [ObjectId], // who follows you
following: [ObjectId], // who you follow
}
π Updates are atomic using $addToSet
(no duplicates) and $pull
to remove.
Follow:
currentUser.following
targetUser.followers
Unfollow:
POST /api/v1/users/:id/follow
DELETE /api/v1/users/:id/unfollow
GET /api/v1/users/:id/followers
GET /api/v1/users/:id/followings
followers
and following
fields for faster queriesThis may seem like a small feature, but it's core to any social app. I learned how to handle:
βSocial graphs are just arrays β until you scale them.β