Skip to content

Commit

Permalink
[chore] readme updated
Browse files Browse the repository at this point in the history
  • Loading branch information
MridulDhiman committed Jan 4, 2025
1 parent 63019c4 commit 5ea8917
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

### Overview

It is an implementation of a scalable socket.io server for allowing realtime collaboration in browser based code editor with built-in frontend templates support like react, vue, svelte, vanillajs, angular nextjs page router etc. Each template comes up with multiple files and leverages importing certain version of packages as dependencies and dev dependencies in the browser itself. Socket.io server creates a bidirectional communication channel for realtime communiation between client and server. When the user joins a collaborative project workspace, he/she is added to a room in the socket.io server. When the first user joins the room, we populate the redis cache with all the project's files, which will be storing the latest state of our application. Realtime code updates are propagated to the server having file path and latest code changes made in that file. Those changes are written in memory to redis along with the timestamp. A Bullmq based background job is also configured to handle 3 jobs concurrently(at this point) and max. of 10 jobs in the time frame of 10 seconds with exponential backoff based fallback mechanism. Each job is executed in a separate node.js worker thread, so that it does not block the main thread from accepting the incoming requests from the client. The job's task is to periodically sync the project's state from the redis to the database. For each project, we have a `last_sync_timestamp` field in the database, which tells the last time the sync was done. For each sync operation, it finds out all the keys which were updated since the last sync occurred, and flush only those keys to the database. Then, the `last_sync_timestamp` is updated to current timestamp for next sync job. In the end, when the last user leaves the room, we again depopulate the cache by deleting all the keys from the redis.
It is an implementation of a scalable socket.io server for allowing realtime collaboration in browser based code editor with built-in frontend templates support like react, vue, svelte, vanillajs, angular nextjs page router etc. Each template comes up with multiple files and leverages importing certain version of packages as dependencies and dev dependencies in the browser itself. Socket.io server creates a bidirectional communication channel for realtime communiation between client and server. It uses redis pub/sub for scaling the websockets. When the user joins a collaborative project workspace, he/she is added to a room in the socket.io server. When the first user joins the room, we populate the redis cache with all the project's files, which will be storing the latest state of our application. Realtime code updates are propagated to the server having file path and latest code changes made in that file. Those changes are written in memory to redis along with the timestamp. A Bullmq based background job is also configured to handle 3 jobs concurrently(at this point) and max. of 10 jobs in the time frame of 10 seconds with exponential backoff based fallback mechanism. Each job is executed in a separate node.js worker thread, so that it does not block the main thread from accepting the incoming requests from the client. The job's task is to periodically sync the project's state from the redis to the database. For each project, we have a `last_sync_timestamp` field in the database, which tells the last time the sync was done. For each sync operation, it finds out all the keys which were updated since the last sync occurred, and flush only those keys to the database. Then, the `last_sync_timestamp` is updated to current timestamp for next sync job. In the end, when the last user leaves the room, we again depopulate the cache by deleting all the keys from the redis.


### Components
Expand Down

0 comments on commit 5ea8917

Please sign in to comment.