post system design question
I am aiming to build a scalable infrastructure (for fun) for a user posting system where timelines exist, such as a feed system. Feeds would include posts of a users followings.
Anyways, the current approach is this.
1.
UserA
follows UserB
2. Save the follows relationship in the DB
3. Create a redis list <userBiD-followers> -> [userAid, ...]
4. UserB creates a post
5. Save that post into the DB
6. Push the <postId> into their Redis list <userId-posts> -> [postId1, postId2, postId3, ...]
Now since UserA has a feed redis list <userAid-feed> -> [postId1, postId2, ...]
7. I essentially iterate over UserB followings, and push UserBs new post into all of their timelines. (fan-out)
Is this the right approach? Anything better I can do?
Another question of mine is, is it much faster to retrieve a redis list of postIds, and pass them into Prisma to get the actual posts than doing queries with just Prisma?
Example below.
The alternative would be to find by user, do potential other joins, etc, rather than knowing the exact postId which belongs to a user.2 Replies