System Design Problem

Design an Online Judge System (Leetcode)

Commonly Asked By:LeetCodeHackerRankGoogleMeta

  • View Problems: Users can browse and view coding problems, including descriptions, constraints, and public test cases.
  • Code Submission: Users can write and submit code in multiple programming languages (e.g., Python, Java, C++).
  • Code Execution: The system evaluates submitted code against hidden test cases.
  • Results Reporting: Return execution results (Accepted, Wrong Answer, Time Limit Exceeded (TLE), Memory Limit Exceeded (MLE), Runtime Error).
  • Leaderboard: Rank users based on problems solved and competition ratings.

The architecture is split between a standard web tier for browsing problems and a specialized async execution pipeline for running untrusted code. We can break this down into three distinct layers:

Loading...
  • API / Gateway Layer: Handles SSL termination, rate limiting, and authenticates the user's JWT. It routes read requests to the standard web tier, and pushes code submissions directly to the message broker.
  • Service Layer: Consists of the Submission Service (validates constraints), the Execution Fleet (spawns secure Firecracker MicroVM sandboxes to run user code), and the Result Aggregator (listens for execution results and streams them back to the user via SSE).
  • Data / Storage Layer: Relies on Kafka for durable async queueing of submissions, AWS S3 for storing massive test case files and raw user code, and PostgreSQL for managing user metadata and problem schemas.