Search⌘ K
AI Features

LeetCode API Design

Explore the design of a LeetCode API that supports practice problems, contests, code evaluation, leaderboards, discussions, and interviews. Understand how REST and GraphQL services work together, and how containerization and pub-sub architectures meet scalability, availability, 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.

Functional and nonfunctional requirements of LeetCode API design
Functional and nonfunctional requirements of LeetCode API design

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:

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.

Working architecture of a LeetCode service
Working architecture of a LeetCode service

The components of the ...