Hello,
I’m designing a bidirectional friendship system where I store the data in a single dynamodb “Users” table.
For the record I only store one side of the relationship and use a GSI to get the edges.
Each user could have between 1 and 1000 friends or more, and I could have 30_000 or more users joining the app at the same time.
I want to develop a feature where when any user who joins the app, he can quickly sees his friends that are online.
Obviously that involves querying friends for every single users joining and also probably caching them (:ets ?).
Each user joining is tracked using Phoenix.track() against his channel(“user:*”) so that I know whether someone is online or not. Their status is stored in an ETS table.
My initial idea is to fetch users’s friends and filter them with what is stored in the ETS table mentioned just before, to know whether one user is online or not.
Obviously the complexity here is that I have to fetch a lot of data at the same time, it represents a lot of queries, so I thought about using genstage or broadway…
May be I can also get away querying less…
For example if user 1, 2 and 3 are friends and the first query executed is for user 1,
I would already get his relationship with 2 and 3, that I could cache !?
May be store in an ETS table each relationship for each user !?
1 => 2
1 => 3
2 => 1
2 => 3
…
Then before querying friends, for users 2 and 3, I can already notify them that user 1 is online.
If anyone could provide some guidance to set up something scalable.
cheers
Cheers