Build an online platform where developers participate in timed programming contests by solving algorithmic challenges. Users submit code in multiple programming languages, which must be compiled, executed against hidden test cases, and scored in real time. The system needs to safely execute untrusted code, maintain fair contest rules, and display live rankings that update as submissions are evaluated.
Your design must handle thousands of concurrent participants submitting solutions during peak contest hours, ensure no malicious code can compromise infrastructure, deliver verdicts within seconds, and maintain leaderboard accuracy even when many users solve problems simultaneously. The platform should support multiple programming languages, enforce contest time windows, prevent cheating through duplicate detection, and provide a smooth user experience for both practice mode and competitive events.
Based on real interview experiences, these are the areas interviewers probe most deeply:
Executing arbitrary user code is the highest security and reliability risk. Interviewers want to see how you prevent resource exhaustion, sandbox escapes, and cascading failures from malicious or buggy submissions.
Hints to consider:
Compilation and test execution are too slow and resource-intensive for synchronous request-response. Interviewers expect a robust async pipeline that handles retries, failures, and backpressure gracefully.
Hints to consider:
During active contests, leaderboards must reflect new scores within seconds while supporting thousands of readers. Interviewers look for designs that avoid expensive database queries on every page load.
Hints to consider:
Competitive integrity requires preventing late submissions, detecting plagiarism, and ensuring all users are judged by identical test cases. Interviewers want to see how you enforce rules at scale.
Hints to consider:
Start by confirming the scale and scope with your interviewer. Ask how many concurrent users the system must support during peak contests and whether practice mode has different requirements. Clarify which programming languages are required and whether custom libraries or dependencies need support. Confirm expectations around verdict latency and whether partial credit exists for test cases. Ask about contest formats -- are there team competitions, different scoring rules, or special features like hacking others' solutions? Understanding anti-cheating priorities will guide your security design.
Sketch a system with three main tiers. The API layer handles user requests, serves problem content from cache, accepts submissions, and queries leaderboard state. The evaluation layer consists of worker pools that pull submissions from a queue, compile code in sandboxes, execute test cases with resource limits, and publish verdicts. The storage layer includes a relational database for users, problems, submissions, and contests; a cache for problem statements and user sessions; and an in-memory data structure for live leaderboards. Connect these tiers with a message queue for submission events and a pub-sub channel for real-time verdict notifications to clients.
Walk through the lifecycle of a single submission. When a user submits code, the API server validates contest eligibility, assigns a unique submission ID, persists the record with "pending" status, and publishes a message to the evaluation queue partitioned by problem or priority. A worker claims the message, pulls the code and test cases, spins up an isolated container with CPU and memory cgroups, compiles the code with a timeout, and runs it against each test case sequentially. Each test execution is time-boxed and monitored for illegal system calls. The worker aggregates results (accepted, wrong answer, time limit exceeded), updates the submission record, calculates the user's new score based on contest rules, and atomically updates the leaderboard. If compilation fails or tests timeout, the worker marks the submission accordingly without retrying. Discuss how partitioning the queue by problem allows fair resource allocation and prevents one problem from starving others.
Cover how you'll implement the live leaderboard. Use a sorted set in Redis keyed by contest ID, with user IDs as members and composite scores as values. When a verdict completes, atomically increment the user's score and re-sort. For reads, fetch top-N using range queries and find a user's rank with rank lookup operations, both O(log N). Discuss caching strategies for problem statements and how to invalidate them when admins update content. Explain database schema choices -- normalize users, contests, problems, and submissions with foreign keys for referential integrity and indexes on contest_id and user_id for common queries. Address monitoring by logging submission rates, queue depths, worker utilization, and leaderboard update latencies. Mention rate limiting on submissions per user to prevent abuse and how you'd handle dispute resolution by storing complete test outputs for admin review.