Practice/Meta/Design Top K Trends Service
Design Top K Trends Service
Product DesignOptional
Problem Statement
Design a global leaderboard system for a mobile gaming platform that tracks and displays player rankings in real-time. The system must handle millions of concurrent players across different games, each with their own scoring mechanics. Players should be able to view their current rank, see the top N players globally or within their region, and receive near-instant updates when their position changes. The system needs to support multiple leaderboard types (global, regional, friends-only) and handle both casual games with frequent score updates and competitive tournaments with strict accuracy requirements.
Your solution should account for the massive write volume from score submissions, the read-heavy nature of leaderboard queries, and the challenge of maintaining consistency across distributed data centers while providing low-latency responses to users worldwide.
Key Requirements
Functional
- Score Submission -- players can submit scores after completing game sessions, with validation to prevent cheating
- Real-Time Ranking -- system calculates and displays current player rank among all participants within seconds
- Top-N Queries -- users can retrieve top K players globally, regionally, or from their friend list
- Historical Snapshots -- maintain leaderboard state at specific points in time for tournaments and seasons
- Multiple Leaderboard Types -- support different ranking algorithms (highest score, fastest time, cumulative points)
Non-Functional
- Scalability -- handle 10 million concurrent players with 50,000 score updates per second during peak hours
- Reliability -- ensure 99.95% uptime with no data loss for score submissions
- Latency -- score updates reflected in rankings within 5 seconds; leaderboard queries respond in under 200ms
- Consistency -- eventual consistency acceptable for global rankings; strong consistency required for tournament final standings
What Interviewers Focus On
Based on real interview experiences, these are the areas interviewers probe most deeply:
1. Data Structure Selection for Ranking
The choice of data structure fundamentally determines system performance and scalability. Interviewers want to see you reason through tradeoffs between different approaches for maintaining sorted rankings.
Hints to consider:
- Sorted sets in Redis provide O(log N) insertion but may not scale to hundreds of millions of players
- Approximate algorithms like Count-Min Sketch can trade accuracy for memory efficiency
- Sharding strategies for distributed sorted structures and how to merge results
- Consider bucketing players into tiers (e.g., top 1000, next 10K, everyone else) with different storage strategies
2. Write Amplification and Hot Key Problems
Score updates create significant write pressure, especially for popular games where many players compete simultaneously. The system must handle both the volume and the hot key problem when updating a single leaderboard.
Hints to consider:
- Batch score updates and process them asynchronously to reduce write load
- Use write-behind caching patterns to buffer updates before persisting
- Implement rate limiting per player to prevent abuse and excessive writes
- Consider separating the write path (score ingestion) from the read path (leaderboard queries) entirely
3. Handling Global vs Regional vs Social Leaderboards
Different leaderboard scopes require different architectural approaches. A friends-only leaderboard has different access patterns and scale constraints than a global one.
Hints to consider:
- Pre-compute friend leaderboards or compute them on-demand based on friend list size
- Regional leaderboards can be independently maintained and don't require global coordination
- Use a lambda architecture approach with both real-time and batch-computed views
- Consider the fanout problem when a player's score changes and multiple leaderboards must update
4. Anti-Cheat and Score Validation
Ensuring legitimate scores is critical for player trust, but validation adds latency and complexity to the submission pipeline.
Hints to consider:
- Server-side game session validation vs client-reported scores
- Statistical anomaly detection to flag suspicious score patterns
- Rate limiting and duplicate submission detection
- Delayed visibility of scores while validation occurs in the background