Next.js Discord

Discord Forum

Build a feed system in Supabase (POSTGRESQL)

Unanswered
Pacific herring posted this in #help-forum
Open in Discord
Pacific herringOP
Hello ! Im building a NextJS app using Supabase. Now I wanna create a feed system for each user based on the activity of their people they follow. What the best idea to be a little bit scalable ?

The problem is I have multiple table for multiple action from the user. He can like a movie, review it, add rating, set as watched, .... all in differente table. So I have to aggregate all data into one table like user_activity where I store all activity for each user. My first idea was to set the table like this :
- id: int8
- user_id: UUID,
- table: string // Exemple where the activity was made : film_like, film_watch, review...
- activity_id: int8 // The id inside the concerned table
- eventType: string // INSERT, UPDATE or DELETE

So this is a normalized system. Ive see an article that say if ur using Redis (like Supabase), its probably better to use Normalized approaches rather than Denormalized because u will need more storage (because u store all the activity data in JSON column).

So with this kinda system a friend just has to query the user_activity table depending of user_id of person he follows and that's it. But is it scalable ? Its a Fan Out Read system right ? The other solution is making a Fan Out Write system but can be difficult to maintain if someone has a lot of followers (because u need to write inside a table feed each activity for all your followers).

The final idea is to make a hybrid system. Like read activity if the user u want is famous, and write activity when user isnt famous. But my question is simple, how can u aggregate the result (client side, like in my NextJS app) of the Fan Out Read feed for your friend who has little amount of follower and the Fan Out Write feed for your friend who is famous ? And also, if its Fan Out Write, if u follow a user the 5 April for example, but this user has liked a movie the 1 April, isnt gonna appear in ur feed ?

Well Im kinda lost, if someone can help me 😅

0 Replies