Logo

dev-resources.site

for different kinds of informations.

Making a Chess.com clone - 1

Published at
7/23/2024
Categories
websockets
buildinpublic
sideprojects
learning
Author
jay818
Author
6 person written this
jay818
open
Making a Chess.com clone - 1

We are going to built a chess.com clone to get some practice around webSockets.

You can read this article to learn about -
Websockets

Our App will have these features

  • User can play with other users in realtime.
  • All the Data is stored in the DB
  • If one user left the game accidently. He/She can again join the game using the gameId.
  • Have User Authentication
  • Have Proper Game Logic
  • User can see all the Moves

Schema Design

Schema Design
we will be having 3 tables - Games, Moves, Users.
Games table will store the individual games each game having their own unique ID [primary key] , playerIDs[foreign key], startTime, Result & one to many relationship to the Moves table.

Moves table will have GameId [ foreign Key ] , to , from , playedAt.

User table will have id(Primary key),name,email(unique),gameAsWhite : Game, gameAsBlack : Game[]

System design

System Design

Your server has to be stateless. But in this case we are using in-memory object Game[]. Why?
Due to latency issues. That's why we also storing in Server also.

It also has recovery mechanism in case a server dies then we can get the data from the DB.
When user make a move it got updated on the server side then sent to other node and after that stored in DB.

In case DB is down, we push that in a in-memory array, failedDBMoves and try to add that after some time.

Scaling

1.By Sharding
What we can do is we can increase the number of server to scale our application, but we have to make sure the players which are playing to each other are connected to the same server.
Sharding

Problem -1
But isn't it will be best if user can connect to their nearby server.
Problem -2
Let's suppose a server can handle only a 1000 ws connections , what if our game has more than 1000 spectators then what we will do.

  1. Using Pub-Sub if there are many people then using a pubsub will make more sense. User Makes the move and it got published and reached to the server that has subscribed for that. Also user can connect from any available server.

Pub-sub

websockets Article's
30 articles in total
Favicon
Real-Time Voice Interactions with the WebSocket Audio Adapter
Favicon
Boosting WebSocket Scalability through a Python Proxy
Favicon
Q: How can I implement a real-time order book using WebSockets in a cryptocurrency exchange?
Favicon
Unveiling Real-Time Communication: WebSockets and You
Favicon
SockManage — 🔌 Manage single active WebSocket connections per user with Redis-powered persistence
Favicon
Creating a Live Collaborative Editor with Next.js and Sockets.IO
Favicon
webSockets to access websites
Favicon
Scaling Web-Socket to million users
Favicon
Building Real-Time Web Applications with WebSockets and Other Technologies
Favicon
Getting server time via WebSockets and displaying It in Angular application
Favicon
SignalR vs WebSockets: Which One is Better for Real-Time Communication?
Favicon
Building a Real-Time Chat Application with WebSockets
Favicon
Building a Chat App with Websockets and JavaScript Using FastAPI.
Favicon
ProjectEvent
Favicon
ProBook
Favicon
Synchronous and Asynchronous Programming in Python: Key Concepts and Applications
Favicon
WebSockets vs. Real-Time Rivals: A Deep Dive into SSE, Long-Polling, MQTT, and XMPP
Favicon
Enterprise Management System with Real-time Notifications and WebSocket Chat
Favicon
Making a Chess.com clone - 1
Favicon
Building Real-Time Applications with WebSockets and Reactive Streams
Favicon
Build a real-time voting app with WebSockets, React & TypeScript 🔌⚡️
Favicon
Unveiling the Power of WebSockets in Node.js
Favicon
Real-time Magic: Unveiling WebSockets and Firebase
Favicon
Understanding WebSocket and creating from Scratch with JavaScript
Favicon
WebSockets
Favicon
Capture Real-Time Forex Data in Excel with Python and WebSockets!
Favicon
Simple Go Chat Application in under 100 lines of code - Part 1
Favicon
Leveraging Zoom WebSockets with Postman for Real-Time Interactivity - POSTCON 2024
Favicon
Build Real-Time Apps with Eezze
Favicon
Setting up a WebSocket server in Node.js

Featured ones: