Design a game leaderboard service
RedditSoftware Engineer · OnsiteLast updated
This question tests the ability to design a high-throughput, low-latency leaderboard service capable of handling frequent rank updates and read requests for millions of active users.
Problem: Designing a Global Game Leaderboard
Design a backend service that maintains a real-time leaderboard for a competitive mobile game. The game has millions of active players who play matches daily. A player's score increases or decreases after every match.
Requirements
Functional Requirements:
- Update a player's score after a match.
- Fetch the top K players globally.
- Fetch a player's relative rank (e.g., the top 100 players above and below the current user).
Non-Functional Requirements:
- Low latency for both read and write operations.
- High availability and durability.
- The system should scale to handle millions of requests per second during peak hours.
Expectations
Your design should cover:
- API Design: Define the endpoints for updating scores and retrieving leaderboard slices.
- Data Model: Choose appropriate storage technologies (e.g., SQL, NoSQL, In-memory caches) and explain the schema choices.
- Scaling Strategy: Explain how to handle high write volume and read traffic across multiple regions.
- Consistency: Discuss the trade-off between strong consistency (accuracy) and eventual consistency (performance) in this context.
- Edge Cases: How do you handle leaderboard refreshes, seasonal resets, or 'cheating' detection (rapid score inflation)?
Hints
Hint 1
Consider using sorted data structures or skip-lists that provide O(log N) operations for insertions and rank lookups.
Hint 2
Caching frequently requested top K rankings can significantly reduce database load, but consider how to invalidate the cache during frequent score updates.
Hint 3
Think about sharding the data by game region or user ID if the global leaderboard becomes too large for a single node.
Follow-up questions
- How would you handle a 'Seasonal' leaderboard requirement where scores reset every month?
- If the leaderboard needs to display millions of players, how do you handle pagination effectively without re-scanning the entire list?
- How would you integrate an asynchronous event-driven system to process match result updates to keep the write path fast?
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.