Design an Online Coding Competition Platform
NubankSoftware Engineer · Technical ScreenLast updated
Design a scalable online coding contest platform capable of securely executing untrusted user code, producing deterministic scores, and maintaining both a real-time top-100 leaderboard and exact rank lookups.
Scenario
You are tasked with designing the backend for an online coding competition platform (similar to LeetCode Contests or Codeforces). During scheduled live contests, tens of thousands of software engineers submit code solutions in various programming languages (e.g., Python, Java, C++, Go) against hidden test suites. The platform must execute code securely, calculate scores based on correctness and execution time/penalties, and update a live global leaderboard.
Requirements
Functional Requirements
- Code Submission & Evaluation: Users submit code against a problem. The platform runs the solution against pre-configured test cases within resource limits (CPU, memory, time) and returns results (Accepted, Wrong Answer, TLE, MLE, Runtime Error).
- Sandboxed Execution: Untrusted user code must be executed in an isolated environment with zero network access and strict resource boundaries to protect infrastructure.
- Deterministic Scoring: Each user's score reflects solved problems, execution metrics, and penalty points for incorrect attempts.
- Leaderboard:
- Top-100 public leaderboard updated with near-real-time latency (< 2 seconds).
- Exact personal rank lookup for any active participant (e.g., "You are ranked #14,520 out of 85,000").
Non-Functional Requirements & Scale
- Contest Scale: 100,000 concurrent active contest participants.
- Peak Submission Throughput: 5,000 submissions/second during contest start and final minutes.
- Execution Constraints: Max execution time per test case is 2 seconds; average total evaluation time is under 10 seconds.
- High Availability & Fault Tolerance: Worker failures must not lose submission state or corrupt contest results.
Key Areas to Cover
- High-Level Architecture: End-to-end data flow from user submission to queue, worker pool, result aggregation, and client notification (e.g., WebSockets, polling).
- Sandboxing & Worker Orchestration: Isolation mechanisms (e.g., gVisor, Firecracker, Docker with cgroups/seccomp), container pooling/pre-warming, and scheduling strategy.
- Leaderboard & Rank Architecture: Data structures and storage engines suitable for both top-K retrieval and arbitrary exact-rank lookups at high write loads (e.g., Redis Sorted Sets, specialized tree indices, write-behind caching).
- Data Model: Core entities including Contest, Problem, Submission, and ParticipantScore.
- Edge Cases & Failure Modes: Worker crashes mid-run, malicious exploits (fork bombs, system call abuse), and rejudging problems mid-contest.
Hints
Hint 1
Decouple the submission ingestion API from evaluation using a distributed message broker (such as Kafka or RabbitMQ) to smooth out traffic spikes during contest starts.
Hint 2
For sandboxing, isolate untrusted execution using kernel-level sandboxes like gVisor or lightweight microVMs like Firecracker, explicitly revoking network privileges and mounting the file system as read-only.
Hint 3
A Redis Sorted Set (ZSET) supports both O(log N) exact rank lookups via ZREVRANK and O(log N + M) top-100 queries via ZREVRANGE, but you must consider sharding or write-batching if update throughput saturates a single primary node.
Follow-up questions
- How would you prevent malicious submissions attempting fork bombs, unauthorized syscalls, or side-channel timing attacks?
- If millions of participants join a global contest, a single Redis instance cannot handle the write throughput for real-time rank updates. How would you partition or approximate rank calculations while keeping the top 100 strictly accurate?
- How would you design the system to handle a re-judge scenario if a test case is updated mid-contest without starving new live submissions?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.