yashkundu / rhime

Rhime is a social media music recommendation application built using event-driven architectural patterns as a combination of multiple decoupled microservices with asynchronous communication between them.

Home Page:http://rhime.ga

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

🎸 Rhime

Rhime is a social media application to recommend music to friends with similar taste.

MIT License

More Info

Built With


NodeJS

TypeScript

Express.js

MongoDB

drawing

Redis

Docker

Kubernetes

drawing


Azure

Jest

Git

Next JS

TailwindCSS


Running Locally

Using Docker

Docker and docker-compose should be installed in the system.

Make these three files in the rhime root directory of the project.

authSecrets.env

    ACCESS_TOKEN_SECRET=<your_secret>
    SIGNED_COOKIE_SECRET=<your_secret>

awsSecrets.env

    AWS_ACCESS_KEY_ID=<your_keyId>
    AWS_SECRET_ACCESS_KEY=<your_access_key>

spotifySecrets.env

    SPOTIFY_CLIENT_KEY=<your_key>
    SPOTIFY_CLIENT_SECRET=<your_secret>

After that run :

    docker compose up

Kubernetes should be installed on the system.

Create Kubernetes secret of the three files mentioned in the Using docker section.

Go to /infra/k8s directory and build all the configuration yaml files using :

    kubectl build 

Or

    kubectl apply

But it will be very complicated, So if you want to run a K8 cluster use next method.

Running Kubernetes cluster using Helm charts

Create Kubernetes secret of the three files mentioned in the Using docker section.

Helm is a Kubernetes package manager which makes it very simple to run kubernetes applications.

rhimeChart is a Helm chart which can be easily installed to the local Kubernetes cluster.

Just run :

    helm install myChart rhimeChart

Basic Architecture


It follows event-driven architecture by utilizing asynchronous events to communicate between components.

The application is made up of multiple decoupled microservices which have specific responsibilities and are independent of each other.

These services communicate with each other using asynchronous events (or messages) using NATS as an event bus (or message streaming, similar to message brokers). NATS was used because it provides lightweight persistent message streaming using JetStream.

MongoDB is used as the primary database for the services. Each service has their own database and services cannot interact with other service's database according to the architectural design patterns of microservices.

Redis is used in multiple services as a cache to store timeline posts, as a data store for task queue, etc.

BullMQ is used as job queue to schedule tasks that fetch user data and improve recommendations at regular bases.

A Cron Job is also used in a service to periodically update a database.

Microservices overview

Visit any service to know about the detailed architectural design of that service.

  • Auth Service : This service handles the authentication for the application by issuing JWT(JSON Web Tokens) and handlers the basic SigIn, SignUp, SignOut functionalities.
  • User Service : This service handles information about the user's profile like getting or updating profile info, updating profile image.
  • Post Service : This service handles creation and fetching of posts.
  • Comment Service : This service handles creation and fetching of comments on user posts.
  • Like Service : This service handles the likes and dislikes on posts and comments. This functionality is implemented as a combination of below mentioned services:
    • Like Service : This service is responsibe for toggling likes and checking if a user has liked a particular item or not.
    • Like Updater Service : This service is responsible for asynchronously updating the persistent database which stores likes. This is done asynchronously to make the liking scalable for higher no. of users.
    • Like Batch Updater Service : This service is responsible for updating the like count on items (posts and comments) in batches, which is much more efficient than updating count in stream.
    • Like Count Service : This service is responsible for getting the like count on a particular post or comment.
  • User Graph Service : This service is responsible for maintaining user-graph that is who follows who and provides functionalites like, following or unfollowing a user, getting the no. of followers(minions) of followees(messiahs), checking if a user is a follower or not, etc.
  • User Graph View Service : This service is not used by external clients, but it used by other internal services to get user graph. It implements rpc (remote procedure call) api instead of REST(because it's logical for inter-service communication and faster than REST). GRPC framework is used to implement RPC.
  • Feed Service : This service is responsible for fetching the home timeline and profile timeline for users. It also fan outs the posts to user timeline and cache recent timeline posts, and do some other stuff.
  • Spotify Service : This service is responsible for connecting user's spotify account, getting user's top tracks, top items and top artists, and also fetches the recommended friends for a user and their similarity stats.
  • Recommendation Service : When the user initially connects spotify account, this service is responsible for fetching initial music data and creating initial recommendations for user. This service also periodically fetches the user's data to update their music taste and updates their recommended friends.
  • Gateway Service : This is a reverse-proxy which acts as an api gateway and routes the traffic to their respective microservices. The gateway also does the authentication and discards unauthenticated requests and proxies the authenticated ones.

Architectures of the services


Shared modules

  • Discovery module : Implements a service registry (like a local dns system) in which services will register and service names are resolved to their ip. Etcd is used to implement service registry, which also tracks the health of the service and provide information to the gateway server. Docker and kubernetes implements automatic dns out of the box.
  • Events module : Implements the interface of events through which different microservices communicate with each other.
  • Common module : Contains the common middleares and utilities for all services.

Build using NextJs, and utilizes both server-side and client-side rendering.

About

Rhime is a social media music recommendation application built using event-driven architectural patterns as a combination of multiple decoupled microservices with asynchronous communication between them.

http://rhime.ga

License:MIT License


Languages

Language:TypeScript 58.7%Language:JavaScript 38.8%Language:PowerShell 0.9%Language:Dockerfile 0.7%Language:Batchfile 0.5%Language:CSS 0.4%