Skip to content

Leetcode Clone Turborepo with server, worker and frontend. Dockerfile of apps and Packages with deployment using Helm Chart

Notifications You must be signed in to change notification settings

dollysingh3192/leetcode_turborepo

Repository files navigation

LeetCode Clone Application

This repository contains two core services:

  • Server: Handles client requests and interacts with the database.
  • Worker: Processes code submissions and updates the database with Accepted/Rejected status.

Both services are built using Node.js and TypeScript.

Interface App

Located in the interface folder, this app is responsible for rendering the UI and handling user interactions. It includes:

  • /problems route: Displays a list of problems.
  • /problems/:id route: Allows code submission for specific problems.

When code is submitted, it is sent to the worker service for processing. The worker updates the database based on the results.

Common Package

A shared package between the server and worker services, containing the Prisma schema for database connectivity.

Kubernetes Deployment with Helm

We have set up a Helm chart to deploy the application in a Kubernetes cluster. This chart includes:

  • RabbitMQ as a dependency, with its own service and replicaset.
  • Backend service with a corresponding replicaset.
  • Worker service replicaset (which waits for RabbitMQ to be ready).

Upcoming Features

  • KEDA: To enable scaling of the worker replicaset based on the size of the RabbitMQ queue.
  • Prometheus: For monitoring the application.

Getting Started

Clone the repository

  • Install dependencies => npm install
  • Do the build => npm run build
  • Run the server => npm run dev

LeetCode Clone: Deployment and Management Commands

Note: All resources are deployed in a namespace called leetcode.

Note: In this application all resources are deployed in a namespace called leetcode

Docker Commands

docker tag leetcode/worker:latest dollysingh3192/leetcode-worker:v1
docker push dollysingh3192/leetcode-worker:v1
docker pull  dollysingh3192/leetcode-worker:v1
docker run -it --entrypoint /bin/sh dollysingh3192/leetcode-worker:v1
docker run --name my-backend-container -p 3000:3000 my-backend-app
docker run --name my-backend-container -d --rm -p 3000:3000 my-backend-app
docker ps
docker stop <id of the container>

Kubernetes Commands
kubectl get namespaces
kubectl create namespace leetcode
kubectl delete namespace leetcode
kubectl get pods
kubectl get all
kubectl get pods,svc -n leetcode

Check the logs of the backend pod
kubectl logs <backend-pod-name> --namespace leetcode

List env in pods
printenv

Port forwarding to backend service
kubectl port-forward svc/backend-service 3000:3000 --namespace leetcode

Port forwarding to rabbitmq service
kubectl port-forward svc/rabbitmq 15672:15672 -n leetcode
then simply access rabbitmq management console at http://localhost:15672

HELM Commands

helm create leetcode-chart
helm dependency build
helm dependency update
helm install leetcode leetcode-chart (first time)
helm upgrade leetcode leetcode-chart (updates)
//inside chart folder
helm install leetcode . --values ./values.yaml
helm install leetcode . --values ./values-prod.yaml
helm list
helm upgrade leetcode1 leetcode-chart --namespace leetcode --debug --dry-run (shows error when trying to upgrade)
helm history leetcode
helm uninstall leetcode
helm status leetcode


Run below command from root of repository
docker build -f apps/server/Dockerfile -t your-image-name .

List image content
docker run -it --entrypoint /bin/sh IMAGE_NAME

//Inside the cluster the hostname is rabbitmq.leetcode.svc.cluster.local these settings are overridden in the helm chart using the fullnameOverride and namespaceOverride values respectively.
amqp://myuser:[email protected]:5672
                        @<service-name>.<namespace>.svc.cluster.local:<port>

minikube start
minikube stop
docker container prune
docker image rm leetcode/worker


From within the RabbitMQ pod shell, run:
rabbitmqctl list_queues
rabbitmqctl list_connections
rabbitmq-plugins list
rabbitmq-plugins enable rabbitmq_management
kubectl port-forward svc/<rabbitmq-service-name> 15672:15672 -n <namespace>
kubectl port-forward svc/rabbitmq 15672:15672 -n leetcode
http://localhost:15672

"amqp://{{ .Values.rabbitmq.auth.username }}:{{ .Values.rabbitmq.auth.password }}@{{ .Values.rabbitmq.fullnameOverride }}.{{ .Values.rabbitmq.namespaceOverride }}.svc.cluster.local:5672"
"amqp://myuser:[email protected]:5672"

kubectl patch scaledobject.keda.sh worker-scaledobject -n leetcode --type merge -p '{"metadata":{"finalizers":[]}}'
kubectl patch triggerauthentication.keda.sh keda-trigger-auth-rabbitmq-conn -n leetcode --type merge -p '{"metadata":{"finalizers":[]}}'
kubectl get triggerauthentication.keda.sh -n leetcode
kubectl logs deployment/keda-operator -n keda
kubectl get scaledobjects -n leetcode
kubectl port-forward svc/rabbitmq 15672:15672 -n leetcode
kubectl get hpa -n leetcode
kubectl get deployments -n leetcode
kubectl get pods -n leetcode

echo -n "amqp://myuser:[email protected]:5672" | base64

Helpful github links
https://github.com/dollysingh3192/docker-development-youtube-series

FOR KEDA:  https://github.com/kedacore/sample-go-rabbitmq/tree/main

           +----------------------+
           | External Metrics      |
           | (RabbitMQ queue size) |
           +----------------------+
                    ↑
                    | KEDA monitors
                    ↓
           +----------------------+
           |       KEDA             |
           | Creates HPA Resource   |
           +----------------------+
                    ↑
                    | Sends scaling triggers
                    ↓
           +----------------------+
           |       HPA              |
           |  Adjusts replicas in   |
           |  Worker Deployment     |
           +----------------------+
                    ↑
                    | Modifies replica count
                    ↓
           +----------------------+
           |   Worker Deployment   |
           | Runs worker pods      |
           +----------------------+

About

Leetcode Clone Turborepo with server, worker and frontend. Dockerfile of apps and Packages with deployment using Helm Chart

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published