-
Notifications
You must be signed in to change notification settings - Fork 4
Leetcode Client
We have a Leetcode client that interfaces with leetcode.com's GraphQL API to fetch question data, user submissions, and other information. It handles authentication by automatically stealing session cookies via Playwright.
The main client can be found at LeetcodeClientImpl.java, though we only use ThrottledLeetcodeClient.java to avoid rate-limiting.
The LeetcodeClient.java interface provides these methods:
-
findQuestionBySlug- Gets full question details including title, difficulty, acceptance rate, and topic tags -
findSubmissionsByUsername- Fetches recent accepted submissions for a user -
findSubmissionDetailBySubmissionId- Gets detailed submission info (runtime, memory, code) -
getPotd- Gets the Problem of the Day -
getUserProfile- Fetches user profile data (ranking, avatar, bio) -
getAllTopicTags- Returns all available question topic tags
Warning
This list of methods may not be up to date. Instead, check LeetcodeClient.java
We have a scheduled task at LeetcodeAuthStealer.java that:
- Runs every 30 minutes to refresh session cookies
- Uses Playwright to automate GitHub OAuth login flow
- Stores the
LEETCODE_SESSIONcookie in our database - Falls back to email alerts if authentication fails
This is necessary because leetcode.com requires authenticated requests for most API calls.
We have a class called ThrottledLeetcodeClient.java (impl) that wraps the main client with rate limiting:
- Uses bucket4j for token bucket rate limiting
- Configured for 1 request per 100ms to avoid getting blocked
- Automatically queues requests when rate limit is hit
All API calls use GraphQL queries stored in the queries package:
-
SelectProblemQuery- Get question details by slug -
SelectAcceptedSubmisisonsQuery- Get user's accepted submissions -
GetSubmissionDetails- Get submission runtime/memory details -
GetPotd- Get daily challenge question -
GetUserProfile- Get user profile info -
GetTopics- Get all topic tags
Warning
This list of methods may not be up to date. Instead, check queries/
The client throws RuntimeException for:
- HTTP status codes other than 200
- JSON parsing errors
- Network timeouts
- Authentication failures
All errors bubble up to the calling services which handle them appropriately.
The client is used throughout the app for:
- Fetching question data when users submit solutions
- Getting user profiles for leaderboards
- Syncing topic tags with our database
- Calculating scores based on submission details
- Daily challenge notifications
- Home
- Setup
- Developer Commands
- Secrets
- Technical Docs
- Feature Docs
- CI Commands
- Contributing
- Codebloom ↗
- Codebloom - Swagger Documentation ↗
- Codebloom - Staging ↗
- Codebloom - Staging - Swagger Documentation ↗
- Codebloom - Local - Swagger Documentation ↗
- Codebloom - Local - Prometheus Metrics ↗
- Grafana Dashboard - Separate domain
- Public Taskboard (Read-only) ↗