35. Design a Leaderboard (Top-K)
1
The interview prompt2
35.1 What do you ask first?3
35.2 How big is this, really?4
35.3 What are the doors?5
35.4 What do we store?6
35.5 What does the whole system look like?7
35.6 How do sorted sets work for this?8
35.7 How do you handle real-time updates?9
35.8 How do you handle ties?10
35.9 How do you shard a leaderboard?11
35.10 What would you say in the last five minutes?12
Score yourself13
Variations to practise14
Sources15
Code lab35. Design a Leaderboard (Top-K)
35.3 What are the doors?
3 min read+10 XP
Step 3: API and data model (10 minutes)
GET /v1/contests/{id}/leaderboard?limit=100
returns: { "updated_at": "...", "entries": [ {"rank": 1, "team": "...", "points": 578.0}, ... ] }
GET /v1/contests/{id}/me
returns: { "rank": 2346, "points": 412.5, "percentile": "top 12%", "updated_at": "..." }
(internal) POST /v1/match/{id}/events { "player": "p0", "event": "six", "points": 6 }
Both reads return updated_at so the app can say "updated 12 s ago" honestly.