Design a Real-Time Gaming Leaderboard
1. Problem Statement & Scope Clarification
System Mission
Design an ultra-low-latency, real-time gaming leaderboard service (similar to Xbox Live, PlayStation Network, and competitive esports platforms) capable of processing hundreds of thousands of score updates per second, maintaining exact global rankings across tens of millions of players, and delivering Top- and surrounding rank windows in under 5 milliseconds.
Functional Requirements
- Score Submission (
SubmitScore): Ingest and atomically update a player's score for a specific game and season, recalculating their global rank in real time. - Top- Global Leaderboard (
GetTopRankings): Retrieve the current top players (e.g., Top 100) with ranks, usernames, avatars, and verified scores. - Surrounding Player Window (
GetSurroundingRanks): Retrieve a specific player's exact rank along with players directly above and below them (relative ranking window). - Deterministic Tie-Breaking: Automatically break score ties by awarding the higher rank to the player who achieved the score earlier in time.
- Periodic & Seasonal Reset: Support daily, weekly, and seasonal leaderboard archival and zero-downtime rollover.
Non-Functional Requirements (SLAs & SLOs)
- Availability: uptime SLA.
- Latency:
- Read Latency (Top- and Relative Window): .
- Write Latency (Score Ingest & Rank Calculation): .
- Throughput: Support during global live gaming events.
- Accuracy: linearizable rank precision for top-tier competitive play (no stale or skipped ranks).
2. Capacity & Scale Estimation (Back-of-the-Envelope Math)
Player Base & Ingest QPS
- Total Registered Players: ().
- Daily Active Players (DAU): ().
- Average Ingest QPS:
- Peak Ingest QPS ( spike factor during esports tournaments):
- Read QPS (Top- views from game menus):
Memory Footprint Derivation (Redis Sorted Set)
A Redis ZSET uses a dual-structure: a SkipList (for range scans) and a Hash Table (for score lookups):
- Member ID (
usr_998124): - Score (
float64IEEE-754 double precision): - SkipList Node pointers (forward/backward pointers, level spans):
- Hash Table dictionary entry:
- Jemalloc memory alignment overhead:
- Total per Player Record: .
With 3x Redis replication and multiple game modes (10 game modes ), a cluster of 3 cache.r6g.xlarge nodes (26.32 GiB RAM each) easily holds the entire state in memory.
3. High-Level Architecture & AWS Component Mapping
Interactive Architecture DiagramSynthesizing vector architecture diagram...
4. API Interface Design & Tie-Breaking Score Math
1. Deterministic Microsecond Tie-Breaking Formula
If Player A and Player B both achieve a score of , standard Redis ZSET orders members lexicographically by their user_id. To guarantee that the player who scored first gets the higher rank, we encode epoch milliseconds into the fractional decimal bits:
Where is the millisecond timestamp when the score was achieved. Since grows monotonically, an earlier timestamp yields a slightly larger fractional value, guaranteeing deterministic first-achiever precedence:
textScore A (at t=1000): 50000 + (1 - 0.000000001000) = 50000.999999999000 Score B (at t=2000): 50000 + (1 - 0.000000002000) = 50000.999999998000 -> Score A > Score B (Player A is ranked higher)
2. gRPC Interface Specification (leaderboard.proto)
protobufsyntax = "proto3"; package hispeeddesign.leaderboard.v1; service LeaderboardService { rpc SubmitScore (SubmitScoreRequest) returns (SubmitScoreResponse); rpc GetTopRankings (GetTopRankingsRequest) returns (GetTopRankingsResponse); rpc GetSurroundingRanks (GetSurroundingRanksRequest) returns (GetSurroundingRanksResponse); } message SubmitScoreRequest { string game_id = 1; string season_id = 2; string user_id = 3; double raw_score = 4; string match_verification_token = 5; } message SubmitScoreResponse { int64 global_rank = 1; double verified_score = 2; bool is_new_high_score = 3; } message GetTopRankingsRequest { string game_id = 1; string season_id = 2; int32 top_n = 3; // Default: 100 } message LeaderboardEntry { int64 rank = 1; string user_id = 2; string username = 3; string avatar_url = 4; double score = 5; } message GetTopRankingsResponse { repeated LeaderboardEntry entries = 1; int64 total_participants = 2; int64 last_updated_epoch_ms = 3; } message GetSurroundingRanksRequest { string game_id = 1; string season_id = 2; string user_id = 3; int32 radius = 4; // e.g. 5 (fetches 5 above and 5 below) } message GetSurroundingRanksResponse { int64 user_rank = 1; repeated LeaderboardEntry surrounding_entries = 2; }
Unlock Complete Architecture & Production Runbooks
You have explored the free architectural preview (~44%). Spend 1 Coin to unlock the remaining 7 production deep-dive sections for a full 24 hours.