basementdevs / twitch-better-profile

Twitch Better Profile - A new way to first interact with users on Twitch.
55 stars 14 forks source link

feat: presence api #57

Closed DanielHe4rt closed 2 months ago

DanielHe4rt commented 2 months ago

Motivation

Under the new features to be implemented, we want to know in real time which streamer and category is under your top ranking.

My initial approach would be using ScyllaDB Counters to make it work and update the data later on:

create table user_counter_statistics(
  user_id: int,
  watch_time_in_minutes: counter,
  messages_count: counter,
  PRIMARY(user_id)
)

create table user_statistics_by_stream (
    user_id: int,
    channel_id: int
    watch_time_in_minutes: counter,
    messages_count: counter,
    PRIMARY((user_id, channel_id))
);

create table user_statistics_by_category (
    user_id: int,
    category_id: text
    watch_time_in_minutes: counter,
    messages_count: counter,
    PRIMARY((user_id, category_id))
);

create table user_most_watched_streams_leaderboard (
    user_id: int,
    channel_id: int, 
    minutes_watched: int,
    PRIMARY(user_id, minutes_watched, channel_id)
) WITH CLUSTERING ORDER BY (minutes_watched DESC, channel_id ASC);

create table user_most_watched_category_leaderboard (
    user_id: int,
    channel_id: int, 
    minutes_watched: int,
    PRIMARY(user_id, minutes_watched, channel_id)
) WITH CLUSTERING ORDER BY (minutes_watched DESC, channel_id ASC);

For every minute, the browser would be sending a "heartbeat" to the tbp-consumer which will process all the information once.

The problem is: how to sync with tbp-platform in a healthy way? But this can be done later.