System Design Problems
Design Leaderboard
Leaderboards are used in gaming, fitness apps, and competitive platforms. This design covers sorted data structures, real-time updates, and efficient rank queries for 100M+ users.
- Scale â 100M+ users, 1M score updates/second
- Latency â Rank query < 10ms
- Real-time â Score updates visible within 1 second
Leaderboards are deceptively simple: maintain a sorted set of scores and answer rank queries efficiently at scale.
Requirements Clarification
Functional Requirements
- Submit and update user scores
- Query user rank and score
- Query top-N users (global and friends)
- Query users around a given rank (neighborhood)
- Reset leaderboard periodically (daily/weekly)
- Anti-cheat score validation
Non-Functional Requirements
- Availability: 99.99% uptime
- Latency: Rank query < 10ms
- Consistency: Strong for score submissions
- Scale: 100M users, 1M updates/second
Back-of-the-Envelope Estimation
High-Level Architecture
Redis Sorted Set Operations
Sharded Leaderboard
Anti-Cheat: Score Validation
Data Model
Practice Exercises
- Design: How would you implement a "friends leaderboard" showing only the user's friends' ranks?
- Scale: Design a leaderboard that handles 10M score updates per second.
- History: How would you implement historical leaderboards (last 30 days) without consuming too much memory?
- Anti-cheat: Design a score validation system that catches 99% of cheaters with < 1% false positives.
What to Learn Next
-> Design Twitter Real-time feeds and fan-out.
-> Design Instagram Social media at scale.
-> Caching Strategies Redis and distributed caching.
-> Back Pressure Managing write-heavy workloads.
-> Idempotency Handling duplicate score submissions.
-> Retry Patterns Resilient score submissions.