Architecture & High-Performance Ranking:
- Goal: Track scores for 10 million active players, update scores in real-time, and return global top-100 and surrounding player ranks in <20ms.
1. Core Data Structure: Redis Sorted Sets:
- Redis Sorted Sets (ZSET) are backed by a Skip List and Hash Map, offering O(log N) score insertion, rank calculation, and range extraction.
- Update Score: ZADD leaderboard or ZINCRBY leaderboard .
- Get Top 100: ZREVRANGE leaderboard 0 99 WITHSCORES.
- Get Player Rank & Nearby Peers: ZREVRANK leaderboard followed by ZREVRANGE leaderboard .
2. Partitioning at Extreme Scale:
- If player volume exceeds single-node Redis RAM or write throughput, partition leaderboards by geographic region, league tier (Bronze, Silver, Gold), or time window (Weekly, Monthly).
3. Persistence & Durability:
- Dual-write pattern: Update Redis Sorted Set for immediate ranking while asynchronously publishing score events to Kafka.
- Batch persistence consumers write score updates to PostgreSQL/Cassandra for historical auditing.
4. Real-Time UI Delivery:
- Broadcast leaderboard position changes to connected clients via WebSockets or Server-Sent Events (SSE).