Design a Multiplayer Game Leaderboard
easy 45 minKeep 250 million players in order while results arrive all the time, and tell any of them their place in milliseconds.
API and data
The contract first, then the data that serves it.
Interface
Calls
| Call | Who | Answer |
|---|---|---|
POST /v1/results | Game server | 202 and a result ID |
GET /v1/boards/{b}/top | Anyone | Rows with rank, player, score, movement |
GET /v1/boards/{b}/me | Player | Rank, score, percentile, neighbours |
GET /v1/boards/{b}/friends | Player | Friends in order, my place |
GET /v1/players/{id}/history | Player | Place at the end of each period |
WebSocket topic my-result | Player | Old place, new place, cause |
JSON
{ "match_id": "m_781", "player_id": "u_42", "mode": "battle", "region": "eu", "score": 48500, "ended_at": "2026-11-23T10:30:00Z", "stats": { "eliminations": 12, "place": 1, "seconds": 1800 }}What a place looks like
| Field | Example | Note |
|---|---|---|
| rank | 1,523 of 15,000,000 | One-based for people |
| percentile | top 0.01% | 1,523 / 15,000,000 |
| next milestone | rank 1,000 at 48,000 | 2,800 more points than 45,200 |
| as of | 10:30:02 | How old the answer is |
| movement | up 130 | 1,650 to 1,520 |
Data
What is stored
| Data | Where | Key |
|---|---|---|
| Result | PostgreSQL by day, then object storage | match, player |
| Best score | PostgreSQL | board, player |
| Order | Redis sorted set | board and period |
| Band counts | Redis hash | board, band |
| Frozen list | Object storage | board and period |
| Names and avatars | Profile service, cached for 5 minutes | player |
Text
ZADD board:battle:eu:w2968 GT 50856983975 u_42ZREVRANK board:battle:eu:w2968 u_42 place, from 0ZRANGE board:battle:eu:w2968 0 99 REV WITHSCORESZRANGE board:battle:eu:w2968 1514 1524 REV neighbours of rank 1520ZCARD board:battle:eu:w2968ZMSCORE board:battle:eu:w2968 u_7 u_9 u_11A result becomes a place