Design a Top-K Leaderboard
Quick Overview
Design a real-time leaderboard system that shows top-K users by score. Cover efficient ranking data structures, handling frequent score updates, and scaling to millions of users with sub-second query latency.
Meta
0
Design a real-time leaderboard system that shows top-K users by score. Cover efficient ranking data structures, handling frequent score updates, and scaling to millions of users with sub-second query latency.
Meta asks leaderboard design in system design rounds because games, fitness challenges and creator rankings across its apps all need live rankings at huge scale. The interviewer is checking whether you pick a ranking structure such as a Redis sorted set, plan for write-heavy score updates, and know how to shard while keeping top-K queries fast.
What the Interviewer Expects
- Pin down requirements: top-K, a user's own rank, update rate and freshness target
- Choose a sorted structure (Redis ZSET or skip list) and give its O(log n) costs
- Separate the write path (score events) from the read path (cached top-K)
- Explain sharding and how to merge per-shard top-K into a global top-K
- Address hot keys, ties and exact vs approximate rank for users far down the list
- Cover durability: rebuilding the in-memory ranking from an event log
Key Topics to Cover
How to Approach This
- Start by clarifying functional and non-functional requirements with the interviewer.
- Estimate the scale: QPS, storage, bandwidth. This drives your design decisions.
- Draw a high-level architecture first, then deep dive into 1-2 critical components.
- Discuss trade-offs explicitly (e.g., consistency vs availability, SQL vs NoSQL).
- Address failure scenarios, monitoring, and how the system handles 10x traffic spikes.
Possible Follow-up Questions
- How do you return the exact rank of a user ranked 40 millionth?
- How would you support daily, weekly and all-time leaderboards at once?
- What happens if one Redis shard fails during a live event?
- How would you build friends-only leaderboards for each user?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
- Functional Requirements:
- Display the top-K users by score in real-time with a refresh rate of <= 1 second.
- Allow users to submit score updates, which should reflect in the leaderbo...
Capacity Estimation
- User Base: Assume 10 million active users.
- Score Updates: If each user updates their score an average of 5 times per hour, that results in 50 million updates per hour or approximately 13...