Design an Online Code Judge (LeetCode)
HardReal World SystemsCode ExecutionSandboxingTest CasesSubmission QueueConcurrency
Problem Statement
Design an online coding platform like LeetCode where users solve programming problems, submit code, the system executes it against test cases in a sandboxed environment, and results are returned with performance metrics.
Requirements
Functional Requirements
- Problem catalog: title, description, difficulty, constraints, sample test cases, hints, editorial
- User authentication and progress tracking (solved problems, submission history)
- Code editor: submit code in multiple languages (Java, Python, C++, JavaScript)
- Submission pipeline: code → queue → judge → result
- Judge evaluates: compile errors, runtime errors, wrong answer, time limit exceeded, memory limit exceeded, accepted
- Test cases: hidden test cases run in addition to sample cases
- Leaderboard: users ranked by problems solved and submission speed
- Discussion forum per problem
- Contest mode: timed contests with real-time leaderboard
Non-Functional Requirements
- Async submission processing via queue
- Isolated execution sandbox per submission
- Thread-safe submission queue
Key Entities
- Problem: id, title, description, difficulty, constraints, testCases, timelimit, memoryLimit, editorial
- TestCase: input, expectedOutput, hidden
- Submission: id, userId, problemId, language, code, status, executionTime, memoryUsed, submittedAt
- SubmissionResult: submissionId, verdict, failedTestCase, executionTime, memoryUsed
- JudgeService: executes code against test cases in isolation
- SubmissionQueue: async queue feeding workers
Constraints
- Time limit per submission: problem-defined (default 2 seconds)
- Memory limit per submission: problem-defined (default 256 MB)
- Sandbox isolation prevents file system and network access
- Queue-based execution: max K concurrent judges
!Constraints
- Each submission runs in an isolated sandbox with time and memory limits
- Hidden test cases are never exposed to users
- Async processing: submission returns immediately with submission ID; user polls for result
- Partial evaluation: show which test case failed without revealing hidden test case input
- Thread-safe submission queue with bounded concurrency (K workers)
Output
Run or submit your code to see output here.