A scalable microservices-based backend system for running and evaluating code submissions, similar to LeetCode. Built with Node.js, TypeScript, and Docker.
This system consists of three main microservices:
| Service | Port | Description | Database |
|---|---|---|---|
| Problem Service | 3001 | Manages coding problems, test cases, and problem metadata | MongoDB |
| Submission Service | 3002 | Handles code submissions, user data, and submission status | MongoDB |
| Evaluation Service | 3003 | Executes code in isolated containers and evaluates results | None (stateless) |
- MongoDB: Primary database for problem and submission data
- Redis: Message queue and caching layer (BullMQ)
- Docker-in-Docker: Isolated code execution environment
- Winston: Structured logging with daily rotation
- Multi-language Support: Execute code in JavaScript, C++, and Python
- Isolated Execution: Secure code execution using Docker containers
- Asynchronous Processing: Queue-based job processing with BullMQ
- Comprehensive Logging: Structured logging with correlation IDs
- Health Checks: Service health monitoring and dependency management
- Scalable Architecture: Designed for horizontal scaling
| Language | Timeout | Docker Image | Description |
|---|---|---|---|
| JavaScript | 10 seconds | Node.js | JavaScript/Node.js code execution |
| C++ | 10 seconds | GCC | C++ code compilation and execution |
| Python | 40 seconds | Python 3 | Python code execution |
- Docker & Docker Compose
-
Clone the repository
git clone https://github.com/Abhi-wolf/leetcode_node_backend cd leetcode_node_backend -
Start all services
# Production build docker-compose up -d # Development with hot reload docker-compose -f compose-dev.yaml up -d
-
Verify services are running
curl http://localhost:3001/api/v1/health # Problem Service curl http://localhost:3002/api/v1/health # Submission Service curl http://localhost:3003/api/v1/health # Evaluation Service
GET /api/v1/problems/search- List all problems and search by queryGET /api/v1/problems/:id- Get problem by IDPOST /api/v1/problems- Create new problemPUT /api/v1/problems/:id- Update problemDELETE /api/v1/problems/:id- Delete problemGET /api/v1/health- Health check
POST /api/v1/submissions- create new submissionGET /api/v1/submissions/:id- Get submission detailsGET /api/v1/health- Health check
GET /api/v1/health- Health check
Environment variables can be set in .env files or Docker Compose:
Language-specific settings are configured in evaluation_service/src/config/language.config.ts:
- JavaScript: 20 second execution timeout
- C++: 10 second execution timeout
- Python: 40 second execution timeout
- Winston Logger: Structured logging with daily rotation
- Correlation IDs: Request tracking across services
- Health Checks:
/api/v1/healthendpoints - Morgan Middleware: HTTP request logging
- Queue Monitoring: BullMQ job status and metrics
# View service logs
docker-compose logs problem-service
docker-compose logs submission-service
docker-compose logs evaluation-service
# View all logs
docker-compose logs -f