Design a Social Game Score Leaderboard
Maintain per-game high scores, show exact global rank after a game, and find nearby global or friend scores under heavy skew.
Problem statement
For this exercise, assume a video-game leaderboard has players, games, friendships, and one accepted high score per player and game. When a player finishes a game, show the closest scores around that player's result across the requested comparison population, such as all players or the supplied current-friend set.
The dataset is large and range search is the key pressure. For this exercise, assume score submissions carry stable attempt IDs, only a player's maximum accepted score is ranked, friendship changes are versioned, and each response states the score and social-graph versions used.
Account privacy policy, anti-cheat review, messaging, and matchmaking are outside scope.
For this exercise, a game-completion response also reports the player’s exact ordinal global rank for that game.
Rank is one plus the number of ranked players strictly before that player in a total order: higher accepted high score first, then earlier server-recorded time when that high score was achieved, then player ID. Equal scores therefore have distinct ordinal ranks.
A lower or equal new attempt does not change the existing high score or its tie time. Return both submitted score and the high score being ranked so they are not confused. The rank and nearby window must describe the same declared ranking snapshot.
If an accepted improvement has not reached a view, return pending or an explicitly older result with its older high-score version, never an old index rank labeled as the new result. Friend comparisons retain their own declared graph version; global rank does not mean rank among friends.
Bind each game-completion result and standing lookup to its immutable attempt ID or completion receipt, so submittedScore identifies that exact attempt even when several attempts share one high-score version.
What to build
- A game service can idempotently submit a player's score and update the ranked high score only when it improves.
- A player can retrieve the closest lower and higher scores for one game across all eligible players. After game completion, the response also gives the exact ordinal global rank of the accepted high score at the same declared ranking snapshot, or an explicit pending/older-version outcome.
- A player can retrieve nearby scores restricted to the current friend comparison set.
- Responses identify ranking and friendship versions so clients can interpret bounded staleness.
At scale
- For this exercise, assume 500 million players, 100,000 games, 100,000 score submissions per second, and 1 million nearby-score reads per second.
- For this exercise, target 200 milliseconds p95 for nearby-score reads and two seconds p95 from accepted improved score to global ranking visibility. For this exercise, global-rank reads use the same 200 ms p95 target and cannot silently substitute an estimate.
- For this exercise, a player has up to 5,000 friends and friendship changes may lag friend-only ranking reads by up to 10 seconds.
- For this exercise, game traffic is highly skewed and one viral game may receive 30 percent of global load.