Design coding platform with global leaderboard
MetaSoftware Engineer · OnsiteLast updated
This question tests the ability to design a high-throughput, real-time leaderboard system that balances strong consistency for rankings with the scalability required for a global user base.
System Design: Global Leaderboard for a Coding Platform
Design a global leaderboard system for a coding platform that hosts millions of daily active users. Users earn points for solving coding problems, and their global rank is updated in real-time.
Functional Requirements
POST /submit-score: Record a score update for a user.GET /leaderboard: Retrieve the top 100 users.GET /rank/{userId}: Retrieve the current rank of a specific user.GET /neighbor-rank/{userId}: Retrieve a user's rank along with the 50 users immediately above and below them.
Non-Functional Requirements
- Scale: 10 million concurrent users, 50,000 score updates per second.
- Latency: Leaderboard fetches should be sub-100ms.
- Consistency: Users expect their points to reflect accurately within seconds (eventual consistency for global rank is acceptable, but individual score updates should be durable).
Scope of Response
- Describe your high-level architecture, including choice of databases and caching layers.
- Define the data model (schema design).
- Explain how you would handle the "hot partition" problem if many top-ranked users update their scores simultaneously.
- Discuss strategies to ensure anti-cheat mechanisms (e.g., verifying submission timestamps) do not bottleneck the ingestion pipeline.
Hints
Hint 1
Consider using an in-memory sorted data structure, like a Redis Sorted Set (ZSET), to store user scores and ranks efficiently.
Hint 2
For high-volume updates, a write-behind pattern using a message queue can decouple the submission ingestion from the leaderboard processing.
Hint 3
Think about how to shard the leaderboard data if the number of users grows beyond the memory capacity of a single machine.
Follow-up questions
- How would you modify your design to support seasonal leaderboards that reset every month without affecting historical data?
- If we introduce 'country-based' leaderboards, how does this impact your database partitioning and query complexity?
- How would you implement an observability strategy to detect spikes in latency or potential rate-limiting issues for the submission endpoint?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.