Skip to content

shift0965/leetcode-clone

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation


LetsCode

Code Together, Code for Fun!

Welcome to our dynamic coding contest platform, where you can practice algorithms, compete with friends, and enjoy coding challenges. Join us to enhance your coding skills and experience the excitement of real-time contests!

Outline

How to Play?

πŸ‘‘ Game Host:

  1. Login first, then click "Create Game".
  2. Choose the problems for the game and set the time limit.
  3. Click "Create Game" to enter the game lobby, where players can join using the Game-Id.
  4. Click "Start Game" to observe all players' real-time code.
  5. Select any player to view their code for all problems and send them messages!
  6. When you're ready, click "Close Game" to reveal the winner!

πŸ₯³ Game Player:

  1. Click "Join Game" and enter the Game Id and your Player Name.
  2. Write down your solution, then click "Run" to execute example cases.
  3. Review the input, output, expected output, and console logs. You will also be notified if any errors are detected.
  4. Click "Submit" to execute all the hidden cases. If passed, see the leaderboard update!
  5. Once the time is up or the host closes the game, the final game results will be displayed.
Testing Account
Email [email protected]
Password test

Tech Stack

Server

Nodejs Express.js SocketIo Typescript

Client

React Tailwind Typescript

DataBase

Redis Mysql

Deployment And Test

Jest Github Action Docker

Structure

Features

Code Execution

  • Applied VM and child processes to securely execute user code and validate its output.
  • Implemented a separate worker server to handle heavy tasks, preventing overload on the express server.
  • Utilized a worker queue to efficiently manage traffic from the express server.
  • Built the worker server with Bun instead of Node.js, resulting in a three-fold increase in user capacity.
  • Implemented code error detection to notify users of any errors in their code, including excessively large output and potential infinite loops.

Contest

  • Enabled real-time code updates through Redis pub-sub and Socket.IO.
  • Stored game states in the database, providing players and hosts with a seamless experience by allowing them to refresh and reconnect effortlessly.
  • The host can watch the progress of every player's contest and interact with them through Bullet Screen.

CICD

  • Automated deployment and testing using GitHub Actions CI/CD and Docker on AWS.

Load Test

Identified Critical Area

After conducting load tests on APIs and Socket.IO with K6, a bottleneck was discovered in the process of executing users' code and validating the output.

The original load test for the run code API revealed the following metrics:

  • Maximum virtual users: 30
  • Request rate: 6 requests per second

The bottleneck appears to be occurring specifically during the execution and validation of user code.

Improvement

To address the bottleneck, several important improvements have been implemented:

  1. Bundling Functionality and Using an Independent Server:

    • Separated code execution functionality and hosted on an independent EC2 instance, preventing server blockage and ensuring smoother performance.
  2. Implementation of a Worker Queue:

    • Introduced a worker queue to efficiently manage incoming requests. If the queue reaches capacity, users will be advised to run their code later.
  3. Utilizing Bun JS for Faster Performance:

    • Switched to Bun from Node.js to significantly improved the execution speed.

Load Test Results:

  • Maximum virtual users: 100
  • Request rate: 20

End-to-End Game Test

Selenium Test:

  1. Host login and start a game.
  2. Player joins the game and submits a solution.
  3. Host observes real-time updates and sends messages.
  4. Close the game and verify results.
selenium_test.mp4

Acknowledgements

Give credit here.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published