LeetCode API Design
Learn to design a complex API for a coding platform like LeetCode. Understand how REST and GraphQL are combined to handle user registration, problem evaluations, contests, discussions, and interviews while meeting scalability, security, and low-latency requirements.
LeetCode API: Requirements and scope
LeetCode enables developers to sharpen programming skills by solving problems and verifying solution correctness. The API we design here covers problem-solving, code evaluation, programming contests with leaderboards, a discussion feature for sharing interview experiences and solutions, and an interview service for hiring.
Functional requirements
List questions: List practice problems filtered by difficulty level or topic.
Register for contests: Register for upcoming contests.
Submit code: Submit one or more solutions for evaluation during practice or contests.
Leaderboard: Fetch contest standings.
History: Track performance metrics, submitted solutions, and contest results.
Interviews: Conduct candidate interviews via the API.
Nonfunctional requirements
Availability: Must handle thousands of concurrent contest submissions.
Scalability: Support a growing user and contestant base.
Security: The primary concern is protecting the data processed by the API, not just transport-layer security. The API must accept only valid code payloads to prevent result manipulation.
Low latency: Minimize response times across all services.
Prerequisites
Several previously designed services serve as building blocks:
Search service: Enables topic/keyword-based problem search.
Comment service: Powers the discussion feature.
Pub-sub service: Drives discussion notifications and contest event propagation.
Zoom API: Integrated for scheduling and conducting interviews.
Design overview and decisions
With requirements established, the LeetCode API decomposes into five major services, each exposed as a direct endpoint. These services are interdependent: client requests for listing problems, registering for contests, submitting code, or commenting flow through an API gateway and fan out to the appropriate subservices. The following workflows detail each service's internal mechanics.
The components of the LeetCode service operate as follows:
Components and Services Details
Component or Service | Details |
User Service |
|
Problem Service |
|
Contest Service |
|
Interview Service |
|
Discuss Service |
|
Cache |
|