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.
- Architecture Overview
- Key Features
- Tech Stack
- System Architecture
- Prerequisites
- Installation
- Running the Application
- API Documentation
- How It Works
- Project Structure
- Testing
- Configuration
- Future Enhancements
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.
- 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
- 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
- React.js - UI framework
- Socket.IO Client - WebSocket client library
- Redis Server - Message queue and pub/sub broker
-
Client (Browser)
- React-based frontend
- Establishes WebSocket connection
- Submits code via REST API
- Receives real-time results
-
Express Backend (Server.js)
- REST API endpoint
/submit
- Pushes submissions to Redis queue
- Validates user input
- REST API endpoint
-
Workers (Worker.js)
- Poll submissions from Redis queue using
BRPOP
- Process code submissions
- Publish results to Redis Pub/Sub channel
processed
- Poll submissions from Redis queue using
-
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
-
Redis
- Queue: Stores pending submissions
- Pub/Sub: Broadcasts processed results to all WebSocket servers
- Node.js (v16 or higher)
- npm or yarn
- Redis server running locally or via Docker