For a full example answer with detailed architecture diagrams and deep dives, see our Design LeetCode guide.
Also review the Message Queues and Databases building blocks for background on asynchronous job processing and transactional storage patterns.
Design a competitive online coding platform where developers solve algorithmic challenges, submit solutions in multiple programming languages, and receive automated verdicts. The system compiles and executes untrusted user code inside secure sandboxes, runs it against hidden test suites, and reports results such as Accepted, Wrong Answer, Time Limit Exceeded, or Runtime Error. Users can practice individually or compete in timed contests with live leaderboards that update as verdicts arrive.
Your design must safely execute thousands of concurrent submissions during peak contest windows, deliver verdicts within seconds, prevent cheating through code-similarity detection, and maintain accurate rankings even when many participants solve the same problem simultaneously. The platform should support at least ten programming languages, enforce strict resource limits on every execution, and store a durable history of all submissions for replay and dispute resolution.
Based on real interview experiences, these are the areas interviewers probe most deeply:
Executing arbitrary user code is the single highest-risk component. Interviewers want to understand how you isolate untrusted programs, enforce resource limits, and prevent sandbox escapes or denial-of-service attacks against the judging infrastructure.
Hints to consider:
Compilation and test execution are too slow for synchronous request-response. Interviewers expect a queue-backed pipeline that decouples ingestion from evaluation and handles backpressure, retries, and partial failures gracefully.
Hints to consider:
During active contests, thousands of clients poll for ranking updates. Interviewers look for a design that avoids expensive database scans on every request while keeping scores fresh within seconds.
Hints to consider:
Competitive fairness requires preventing late submissions, detecting plagiarism, and ensuring identical test data for all participants. Interviewers want concrete mechanisms rather than vague policy statements.
Hints to consider:
Start by confirming scope with your interviewer. Ask how many concurrent users the system must support during peak contests and whether practice mode has different SLAs. Clarify which programming languages are required and whether custom libraries or large dependencies need support. Confirm acceptable verdict latency and whether partial credit (per-test-case scoring) exists. Ask about contest formats -- individual only, or team contests with shared submissions? Understanding anti-cheating priorities will shape your security design.
Sketch three tiers. The API layer serves problem content from cache, accepts submissions, authenticates users, and streams leaderboard data over WebSockets. The evaluation layer consists of stateless worker pools that pull submissions from a partitioned message queue, compile and execute code inside sandboxes with strict cgroups, and publish verdicts. The storage layer includes PostgreSQL for users, problems, contests, and submission records; Redis for live leaderboards and session state; S3 for archival of submission source code and test-case bundles; and Kafka as the durable message backbone connecting the API and evaluation layers.
Walk through a single submission end-to-end. A user submits code; the API server validates contest eligibility, assigns a UUID, persists the record as Pending, and publishes a message to Kafka partitioned by problem ID. A worker consumes the message, fetches the source and test-case bundle, spins up a Firecracker microVM with language-specific toolchain, compiles with a 10-second timeout, then runs each test case sequentially with per-case CPU and memory limits. The worker aggregates results, writes a verdict row, updates the user's contest score atomically in Redis, and publishes a score-change event to a WebSocket fan-out service. If the worker crashes, Kafka's consumer-group rebalance makes the message available to another worker after the visibility timeout. Discuss how partitioning by problem prevents a single popular problem from monopolizing all workers.
Cover monitoring: track submission queue depth, worker utilization, verdict latency percentiles, and sandbox failure rates. Explain database indexing on (contest_id, user_id) and (problem_id, status) for common query patterns. Discuss scaling strategy -- auto-scale the worker pool based on queue depth during contests, and drain gracefully by stopping new message consumption while finishing in-flight executions. Address data retention: archive old submissions to S3 with lifecycle policies, keep recent contest data in PostgreSQL with partitioned tables by contest date. Finally, mention rate limiting on the submission endpoint, CDN caching for problem statements, and read replicas for the problem catalog to handle browsing traffic independently of contest load.