Maintain scores in an ordered structure#
Repeatedly sorting every player for every top 100 request becomes expensive. An ordered (score, user) structure supports score updates, Top-K ranges, and a user's rank. Redis sorted sets are one implementation, not the architecture itself.
| Leaderboard | Distinct access pattern |
|---|---|
| Global | Huge shared ranking and write contention |
| Regional | Partition and rank within region |
| Friends | Social graph intersection plus score lookup |
| Daily/weekly | Versioned windows and expiry |
Ties need deterministic policy. Sharded global Top-K can merge each shard's candidates, while user rank across shards is harder. Approximate heavy-hitter structures belong only when exactness is not required.
Related practice problems
Use the manifest-backed prompts below to apply this lesson in a complete design.
- Redis sorted setsRedis Documentation