Skip to content

sandeeprepala/leetcode-architecture-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚀 Scalable Real-Time Collaborative Code Submission System

A distributed, real-time code submission and processing system built with Node.js, Redis, WebSockets, and React. This architecture demonstrates horizontal scalability with multiple WebSocket servers synchronized via Redis Pub/Sub.


📋 Table of Contents


🏗️ Architecture Overview

This system enables multiple users to submit code for processing while receiving real-time results through WebSocket connections. The architecture supports horizontal scaling with multiple WebSocket servers that communicate through Redis Pub/Sub.

Architecture Diagram

Architecture Diagram


✨ Key Features

  • Real-Time Communication: Instant result delivery via WebSocket connections
  • Horizontal Scalability: Multiple WebSocket servers handle concurrent connections
  • Distributed Architecture: Redis Pub/Sub synchronizes events across all servers
  • Queue-Based Processing: Workers poll from Redis queue for reliable processing
  • Multi-User Support: Each user gets isolated, real-time updates
  • Load Distribution: Clients automatically distributed across WebSocket servers
  • Session Persistence: Tab-specific user sessions with unique IDs

🛠️ Tech Stack

Backend

  • Node.js - Runtime environment
  • Express.js - HTTP server framework
  • Socket.IO - WebSocket library for real-time communication
  • Redis - Message broker (Pub/Sub) and queue storage

Frontend

  • React.js - UI framework
  • Socket.IO Client - WebSocket client library

Infrastructure

  • Redis Server - Message queue and pub/sub broker

🎯 System Architecture

Components

  1. Client (Browser)

    • React-based frontend
    • Establishes WebSocket connection
    • Submits code via REST API
    • Receives real-time results
  2. Express Backend (Server.js)

    • REST API endpoint /submit
    • Pushes submissions to Redis queue
    • Validates user input
  3. Workers (Worker.js)

    • Poll submissions from Redis queue using BRPOP
    • Process code submissions
    • Publish results to Redis Pub/Sub channel processed
  4. WebSocket Servers (Multiple Instances)

    • Handle WebSocket connections on ports 4000, 4001, 4002
    • Subscribe to Redis processed channel
    • Deliver results to specific users via Socket.IO rooms
  5. Redis

    • Queue: Stores pending submissions
    • Pub/Sub: Broadcasts processed results to all WebSocket servers

📦 Prerequisites

  • Node.js (v16 or higher)
  • npm or yarn
  • Redis server running locally or via Docker

🔧 Installation

1. Clone the Repository

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published