Building a Secure, Real-Time Judge System for Code Relay Competitions
Competitive programming is often an individual sport, but the Code Relay format transforms it into an exciting team-based challenge. I built the Code Relay Judge System, a full-stack application designed specifically to host these dynamic competitions. It’s a complete platform that handles everything from secure, multi-language code execution to real-time leaderboards and the unique team rotation mechanic that defines the event.
The Challenge: More Than a Standard Judge
Unlike typical programming contests, a Code Relay has unique requirements. The challenge was to build a system that could not only judge code but also manage the specific rules of the game:
- Team & Time Management: The system needed a built-in timer to enforce the fixed coding window for each team member and manage automatic rotation.
- Security & Isolation: With teams submitting code in multiple languages (Python, Java, C++, etc.), executing untrusted code without risking the server's integrity was the top priority.
- Real-Time Feedback: To capture the high-energy, competitive nature of a relay, the submission statuses and team rankings had to update instantly for all participants.
Interface Previews
Figure: Main interface:-
Figure: Problems page:-
Figure: Team management:-
Figure: Submission results:-
System Architecture Diagram
The system is built on a robust, asynchronous architecture designed for security and real-time updates. The core components work together to manage the flow from code submission to leaderboard update.
The Technical Deep Dive: Key Components
- The Core Backend & Submission Queue
The server is built with Node.js and Express.js, handling all HTTP requests for submissions, status checks, and leaderboard data. A critical piece of the architecture is the in-memory submission queue, which processes code evaluations one by one. This sequential approach prevents resource contention and ensures that every submission is judged fairly and reliably, even under load.
- Secure, Multi-Language Code Execution
This is the heart of the judge. To solve the challenge of running untrusted code, every submission is executed inside an isolated Docker container.
The Code Runner module is responsible for:
- Creating a new Docker container for each submission.
- Mounting the submitted code file and the relevant test case inputs into the container.
- Running the code and comparing its output against the expected results.
- Calculating the score and tearing down the container.
This architecture provides rock-solid security and supports a wide range of languages, including Python, Java, C++, C, and JavaScript.
- Real-Time User Interface
The frontend is designed to create a live, competitive atmosphere. It features a real-time timer for the team member rotation and a live-updating leaderboard that reflects scoring changes instantly. This is powered by a simple but effective file-based database that stores submission results, leaderboard data, and the overall competition state.
Key Technical Challenges and Solutions
Problem: Executing Untrusted Code Safely
Solution: Docker containerization. By executing every submission in a sandboxed environment, the judge is protected from malicious code. The container has no access to the host filesystem or network, making it a safe execution environment.
Problem: Managing Concurrent Submissions Fairly
Solution: An in-memory submission queue. This design ensures that submissions are processed sequentially, preventing resource contention and providing a fair, first-in-first-out evaluation system.
Problem: Creating a Live Competition Feel
Solution: The frontend was built to poll the backend for status and leaderboard updates, ensuring that all participants see real-time changes as they happen.
Conclusion
The Code Relay Judge System is more than just a tool for checking code; it's a complete platform that brings the unique, high-energy format of team-based code relays to life. It successfully solves the core challenges of security through Docker, resource management through a robust queueing system, and engagement through a real-time frontend. This project was a fascinating dive into building secure, scalable, and interactive web applications.